OmniSciDB  085a039ca4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
com.mapd.parser.server.ExtensionFunctionSignatureParser Class Reference
+ Collaboration diagram for com.mapd.parser.server.ExtensionFunctionSignatureParser:

Static Package Functions

static Map< String,
ExtensionFunction
parse (final String file_path) throws IOException
 
static Map< String,
ExtensionFunction
parseUdfAst (final String file_path) throws IOException
 
static Map< String,
ExtensionFunction
parseFromString (final String udf_string) throws IOException
 
static Map< String,
ExtensionFunction
parseFromString (final String udf_string, final boolean is_row_func) throws IOException
 
static String signaturesToJson (final Map< String, ExtensionFunction > sigs)
 
static String join (final List< String > strs, final String sep)
 

Static Package Attributes

static final Logger HEAVYDBLOGGER
 

Static Private Member Functions

static boolean isWindows ()
 
static ExtensionFunction toSignature (final String ret, final String cs_param_list, final boolean has_variable_name)
 
static ExtensionFunction toSignature (final String ret, final String cs_param_list, final boolean has_variable_name, final boolean is_row_func)
 
static
ExtensionFunction.ExtArgumentType 
deserializeType (final String type_name)
 
static
ExtensionFunction.ExtArgumentType 
pointerType (final ExtensionFunction.ExtArgumentType targetType)
 

Static Private Attributes

static String OS = System.getProperty("os.name").toLowerCase()
 

Detailed Description

Author
alex

Definition at line 37 of file ExtensionFunctionSignatureParser.java.

Member Function Documentation

static ExtensionFunction.ExtArgumentType com.mapd.parser.server.ExtensionFunctionSignatureParser.deserializeType ( final String  type_name)
inlinestaticprivate

Definition at line 159 of file ExtensionFunctionSignatureParser.java.

References Double, com.mapd.parser.server.ExtensionFunctionSignatureParser.isWindows(), and com.mapd.parser.server.ExtensionFunctionSignatureParser.pointerType().

Referenced by com.mapd.parser.server.ExtensionFunctionSignatureParser.toSignature().

160  {
161  final String const_prefix = "const ";
162  final String std_namespace_prefix = "std::";
163 
164  if (type_name.startsWith(const_prefix)) {
165  return deserializeType(type_name.substring(const_prefix.length()));
166  }
167  if (type_name.startsWith(std_namespace_prefix)) {
168  return deserializeType(type_name.substring(std_namespace_prefix.length()));
169  }
170 
171  if (type_name.equals("bool") || type_name.equals("_Bool")) {
172  return ExtensionFunction.ExtArgumentType.Bool;
173  }
174  if (type_name.equals("int8_t") || type_name.equals("char")
175  || type_name.equals("int8")) {
176  return ExtensionFunction.ExtArgumentType.Int8;
177  }
178  if (type_name.equals("int16_t") || type_name.equals("short")
179  || type_name.equals("int16")) {
180  return ExtensionFunction.ExtArgumentType.Int16;
181  }
182  if (type_name.equals("int32_t") || type_name.equals("int")
183  || type_name.equals("int32") || (isWindows() && type_name.equals("long"))) {
184  return ExtensionFunction.ExtArgumentType.Int32;
185  }
186  if (type_name.equals("int64_t") || type_name.equals("size_t")
187  || type_name.equals("int64")) {
188  return ExtensionFunction.ExtArgumentType.Int64;
189  }
190  if ((!isWindows() && type_name.equals("long"))
191  || (isWindows() && type_name.equals("long long"))) {
192  return ExtensionFunction.ExtArgumentType.Int64;
193  }
194  if (type_name.equals("float") || type_name.equals("float32")) {
195  return ExtensionFunction.ExtArgumentType.Float;
196  }
197  if (type_name.equals("double") || type_name.equals("float64")) {
199  }
200  if (type_name.isEmpty() || type_name.equals("void")) {
201  return ExtensionFunction.ExtArgumentType.Void;
202  }
203  if (type_name.endsWith(" *")) {
204  return pointerType(deserializeType(type_name.substring(0, type_name.length() - 2)));
205  }
206  if (type_name.endsWith("*")) {
207  return pointerType(deserializeType(type_name.substring(0, type_name.length() - 1)));
208  }
209  if (type_name.equals("Array<bool>")) {
210  return ExtensionFunction.ExtArgumentType.ArrayBool;
211  }
212  if (type_name.equals("Array<int8_t>") || type_name.equals("Array<char>")) {
213  return ExtensionFunction.ExtArgumentType.ArrayInt8;
214  }
215  if (type_name.equals("Array<int16_t>") || type_name.equals("Array<short>")) {
216  return ExtensionFunction.ExtArgumentType.ArrayInt16;
217  }
218  if (type_name.equals("Array<int32_t>") || type_name.equals("Array<int>")) {
219  return ExtensionFunction.ExtArgumentType.ArrayInt32;
220  }
221  if (type_name.equals("Array<int64_t>") || type_name.equals("Array<size_t>")
222  || type_name.equals("Array<long>")) {
223  return ExtensionFunction.ExtArgumentType.ArrayInt64;
224  }
225  if (type_name.equals("Array<float>")) {
226  return ExtensionFunction.ExtArgumentType.ArrayFloat;
227  }
228  if (type_name.equals("Array<double>")) {
229  return ExtensionFunction.ExtArgumentType.ArrayDouble;
230  }
231  if (type_name.equals("Array<bool>")) {
232  return ExtensionFunction.ExtArgumentType.ArrayBool;
233  }
234  if (type_name.equals("Timestamp")) {
235  return ExtensionFunction.ExtArgumentType.Timestamp;
236  }
237  if (type_name.equals("Column<int8_t>") || type_name.equals("Column<char>")) {
238  return ExtensionFunction.ExtArgumentType.ColumnInt8;
239  }
240  if (type_name.equals("Column<int16_t>") || type_name.equals("Column<short>")) {
241  return ExtensionFunction.ExtArgumentType.ColumnInt16;
242  }
243  if (type_name.equals("Column<int32_t>") || type_name.equals("Column<int>")) {
244  return ExtensionFunction.ExtArgumentType.ColumnInt32;
245  }
246  if (type_name.equals("Column<int64_t>") || type_name.equals("Column<size_t>")
247  || type_name.equals("Column<long>")) {
248  return ExtensionFunction.ExtArgumentType.ColumnInt64;
249  }
250  if (type_name.equals("Column<float>")) {
251  return ExtensionFunction.ExtArgumentType.ColumnFloat;
252  }
253  if (type_name.equals("Column<double>")) {
254  return ExtensionFunction.ExtArgumentType.ColumnDouble;
255  }
256  if (type_name.equals("Column<TextEncodingDict>")) {
257  return ExtensionFunction.ExtArgumentType.ColumnTextEncodingDict;
258  }
259  if (type_name.equals("Column<Timestamp>")) {
260  return ExtensionFunction.ExtArgumentType.ColumnTimestamp;
261  }
262  if (type_name.equals("Cursor")) {
263  return ExtensionFunction.ExtArgumentType.Cursor;
264  }
265  if (type_name.equals("GeoPoint")) {
266  return ExtensionFunction.ExtArgumentType.GeoPoint;
267  }
268  if (type_name.equals("GeoLineString")) {
269  return ExtensionFunction.ExtArgumentType.GeoLineString;
270  }
271  if (type_name.equals("GeoPolygon")) {
272  return ExtensionFunction.ExtArgumentType.GeoPolygon;
273  }
274  if (type_name.equals("GeoMultiPolygon")) {
275  return ExtensionFunction.ExtArgumentType.GeoMultiPolygon;
276  }
277  if (type_name.equals("ColumnList<int8_t>") || type_name.equals("ColumnList<char>")) {
278  return ExtensionFunction.ExtArgumentType.ColumnListInt8;
279  }
280  if (type_name.equals("ColumnList<int16_t>")
281  || type_name.equals("ColumnList<short>")) {
282  return ExtensionFunction.ExtArgumentType.ColumnListInt16;
283  }
284  if (type_name.equals("ColumnList<int32_t>") || type_name.equals("ColumnList<int>")) {
285  return ExtensionFunction.ExtArgumentType.ColumnListInt32;
286  }
287  if (type_name.equals("ColumnList<int64_t>") || type_name.equals("ColumnList<size_t>")
288  || type_name.equals("ColumnList<long>")) {
289  return ExtensionFunction.ExtArgumentType.ColumnListInt64;
290  }
291  if (type_name.equals("ColumnList<float>")) {
292  return ExtensionFunction.ExtArgumentType.ColumnListFloat;
293  }
294  if (type_name.equals("ColumnList<double>")) {
295  return ExtensionFunction.ExtArgumentType.ColumnListDouble;
296  }
297  if (type_name.equals("ColumnList<TextEncodingDict>")) {
298  return ExtensionFunction.ExtArgumentType.ColumnListTextEncodingDict;
299  }
300  HEAVYDBLOGGER.info(
301  "ExtensionfunctionSignatureParser::deserializeType: unknown type_name=`"
302  + type_name + "`");
303  // TODO: Return void for convenience. Consider sanitizing functions for supported
304  // types before they reach Calcite
305  return ExtensionFunction.ExtArgumentType.Void;
306  }
static ExtensionFunction.ExtArgumentType pointerType(final ExtensionFunction.ExtArgumentType targetType)
static ExtensionFunction.ExtArgumentType deserializeType(final String type_name)
constexpr auto type_name() noexcept

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static boolean com.mapd.parser.server.ExtensionFunctionSignatureParser.isWindows ( )
inlinestaticprivate

Definition at line 42 of file ExtensionFunctionSignatureParser.java.

References com.mapd.parser.server.ExtensionFunctionSignatureParser.OS.

Referenced by com.mapd.parser.server.ExtensionFunctionSignatureParser.deserializeType().

42  {
43  return (OS.indexOf("win") >= 0);
44  }

+ Here is the caller graph for this function:

static String com.mapd.parser.server.ExtensionFunctionSignatureParser.join ( final List< String >  strs,
final String  sep 
)
inlinestaticpackage

Definition at line 331 of file ExtensionFunctionSignatureParser.java.

References File_Namespace.append().

Referenced by com.mapd.parser.server.ExtensionFunctionSignatureParser.signaturesToJson().

331  {
332  StringBuilder sb = new StringBuilder();
333  if (strs.isEmpty()) {
334  return "";
335  }
336  sb.append(strs.get(0));
337  for (int i = 1; i < strs.size(); ++i) {
338  sb.append(sep).append(strs.get(i));
339  }
340  return sb.toString();
341  }
size_t append(FILE *f, const size_t size, const int8_t *buf)
Appends the specified number of bytes to the end of the file f from buf.
Definition: File.cpp:168

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static Map<String, ExtensionFunction> com.mapd.parser.server.ExtensionFunctionSignatureParser.parse ( final String  file_path) throws IOException
inlinestaticpackage

Definition at line 46 of file ExtensionFunctionSignatureParser.java.

References parse_ast.line, setup.name, and com.mapd.parser.server.ExtensionFunctionSignatureParser.toSignature().

46  {
47  File file = new File(file_path);
48  FileReader fileReader = new FileReader(file);
49  BufferedReader bufferedReader = new BufferedReader(fileReader);
50  String line;
51  Pattern s = Pattern.compile("\\| ([\\` ]|used)+ ([\\w]+) '([\\w<>]+) \\((.*)\\)'");
52  Map<String, ExtensionFunction> sigs = new HashMap<String, ExtensionFunction>();
53  while ((line = bufferedReader.readLine()) != null) {
54  Matcher m = s.matcher(line);
55  if (m.find()) {
56  final String name = m.group(2);
57  final String ret = m.group(3);
58  final String cs_param_list = m.group(4);
59  sigs.put(name, toSignature(ret, cs_param_list, false));
60  }
61  }
62  return sigs;
63  }
tuple line
Definition: parse_ast.py:10
static ExtensionFunction toSignature(final String ret, final String cs_param_list, final boolean has_variable_name)
string name
Definition: setup.in.py:72

+ Here is the call graph for this function:

static Map<String, ExtensionFunction> com.mapd.parser.server.ExtensionFunctionSignatureParser.parseFromString ( final String  udf_string) throws IOException
inlinestaticpackage

Definition at line 88 of file ExtensionFunctionSignatureParser.java.

89  {
90  return parseFromString(udf_string, true);
91  }
static Map< String, ExtensionFunction > parseFromString(final String udf_string)
static Map<String, ExtensionFunction> com.mapd.parser.server.ExtensionFunctionSignatureParser.parseFromString ( final String  udf_string,
final boolean  is_row_func 
) throws IOException
inlinestaticpackage

Definition at line 93 of file ExtensionFunctionSignatureParser.java.

References parse_ast.line, setup.name, and com.mapd.parser.server.ExtensionFunctionSignatureParser.toSignature().

94  {
95  StringReader stringReader = new StringReader(udf_string);
96  BufferedReader bufferedReader = new BufferedReader(stringReader);
97  String line;
98  Pattern r = Pattern.compile("([\\w]+)\\s+'([\\w]+)\\s*\\((.*)\\)'");
99  Map<String, ExtensionFunction> sigs = new HashMap<String, ExtensionFunction>();
100  while ((line = bufferedReader.readLine()) != null) {
101  Matcher m = r.matcher(line);
102  if (m.find()) {
103  final String name = m.group(1);
104  final String ret = m.group(2);
105  final String cs_param_list = m.group(3);
106  sigs.put(name, toSignature(ret, cs_param_list, is_row_func));
107  }
108  }
109  return sigs;
110  }
tuple line
Definition: parse_ast.py:10
static ExtensionFunction toSignature(final String ret, final String cs_param_list, final boolean has_variable_name)
string name
Definition: setup.in.py:72

+ Here is the call graph for this function:

static Map<String, ExtensionFunction> com.mapd.parser.server.ExtensionFunctionSignatureParser.parseUdfAst ( final String  file_path) throws IOException
inlinestaticpackage

Definition at line 65 of file ExtensionFunctionSignatureParser.java.

References parse_ast.line, setup.name, and com.mapd.parser.server.ExtensionFunctionSignatureParser.toSignature().

66  {
67  File file = new File(file_path);
68  FileReader fileReader = new FileReader(file);
69  BufferedReader bufferedReader = new BufferedReader(fileReader);
70  String line;
71  Pattern s = Pattern.compile("([<>:\\w]+) ([:\\w]+)(?:\\(\\))?\\((.*)\\)");
72  Map<String, ExtensionFunction> sigs = new HashMap<String, ExtensionFunction>();
73  while ((line = bufferedReader.readLine()) != null) {
74  Matcher m = s.matcher(line);
75  if (m.find()) {
76  final String name = m.group(2);
77  final String ret = m.group(1);
78  final String cs_param_list = m.group(3);
79  if (cs_param_list.isEmpty()) {
80  continue;
81  }
82  sigs.put(name, toSignature(ret, cs_param_list, true));
83  }
84  }
85  return sigs;
86  }
tuple line
Definition: parse_ast.py:10
static ExtensionFunction toSignature(final String ret, final String cs_param_list, final boolean has_variable_name)
string name
Definition: setup.in.py:72

+ Here is the call graph for this function:

static ExtensionFunction.ExtArgumentType com.mapd.parser.server.ExtensionFunctionSignatureParser.pointerType ( final ExtensionFunction.ExtArgumentType  targetType)
inlinestaticprivate

Definition at line 308 of file ExtensionFunctionSignatureParser.java.

References Bool, Double, Float, Int16, Int32, Int64, and Int8.

Referenced by com.mapd.parser.server.ExtensionFunctionSignatureParser.deserializeType().

309  {
310  switch (targetType) {
311  case Bool:
312  return ExtensionFunction.ExtArgumentType.PBool;
313  case Int8:
314  return ExtensionFunction.ExtArgumentType.PInt8;
315  case Int16:
316  return ExtensionFunction.ExtArgumentType.PInt16;
317  case Int32:
318  return ExtensionFunction.ExtArgumentType.PInt32;
319  case Int64:
320  return ExtensionFunction.ExtArgumentType.PInt64;
321  case Float:
322  return ExtensionFunction.ExtArgumentType.PFloat;
323  case Double:
324  return ExtensionFunction.ExtArgumentType.PDouble;
325  default:
326  assert false;
327  return null;
328  }
329  }

+ Here is the caller graph for this function:

static String com.mapd.parser.server.ExtensionFunctionSignatureParser.signaturesToJson ( final Map< String, ExtensionFunction sigs)
inlinestaticpackage

Definition at line 111 of file ExtensionFunctionSignatureParser.java.

References com.mapd.parser.server.ExtensionFunctionSignatureParser.join().

111  {
112  List<String> json_sigs = new ArrayList<String>();
113  if (sigs != null) {
114  for (Map.Entry<String, ExtensionFunction> sig : sigs.entrySet()) {
115  if (sig.getValue().isRowUdf()) {
116  json_sigs.add(sig.getValue().toJson(sig.getKey()));
117  }
118  }
119  }
120  return "[" + join(json_sigs, ",") + "]";
121  }
static String join(final List< String > strs, final String sep)

+ Here is the call graph for this function:

static ExtensionFunction com.mapd.parser.server.ExtensionFunctionSignatureParser.toSignature ( final String  ret,
final String  cs_param_list,
final boolean  has_variable_name 
)
inlinestaticprivate

Definition at line 123 of file ExtensionFunctionSignatureParser.java.

Referenced by com.mapd.parser.server.ExtensionFunctionSignatureParser.parse(), com.mapd.parser.server.ExtensionFunctionSignatureParser.parseFromString(), and com.mapd.parser.server.ExtensionFunctionSignatureParser.parseUdfAst().

124  {
125  return toSignature(ret, cs_param_list, has_variable_name, true);
126  }
static ExtensionFunction toSignature(final String ret, final String cs_param_list, final boolean has_variable_name)

+ Here is the caller graph for this function:

static ExtensionFunction com.mapd.parser.server.ExtensionFunctionSignatureParser.toSignature ( final String  ret,
final String  cs_param_list,
final boolean  has_variable_name,
final boolean  is_row_func 
)
inlinestaticprivate

Definition at line 128 of file ExtensionFunctionSignatureParser.java.

References run_benchmark_import.args, com.mapd.parser.server.ExtensionFunctionSignatureParser.deserializeType(), and split().

131  {
132  String[] params = cs_param_list.split(",");
133  List<ExtensionFunction.ExtArgumentType> args =
134  new ArrayList<ExtensionFunction.ExtArgumentType>();
135  for (final String param : params) {
136  ExtensionFunction.ExtArgumentType arg_type;
137  if (has_variable_name) {
138  String[] full_param = param.trim().split("\\s+");
139  if (full_param.length > 0) {
140  if (full_param[0].trim().compareTo("const") == 0) {
141  assert full_param.length > 1;
142  arg_type = deserializeType((full_param[1]).trim());
143  } else {
144  arg_type = deserializeType((full_param[0]).trim());
145  }
146  } else {
147  arg_type = deserializeType(full_param[0]);
148  }
149  } else {
150  arg_type = deserializeType(param.trim());
151  }
152  if (arg_type != ExtensionFunction.ExtArgumentType.Void) {
153  args.add(arg_type);
154  }
155  }
156  assert is_row_func;
157  return new ExtensionFunction(args, deserializeType(ret));
158  }
std::vector< std::string > split(std::string_view str, std::string_view delim, std::optional< size_t > maxsplit)
split apart a string into a vector of substrings
static ExtensionFunction.ExtArgumentType deserializeType(final String type_name)

+ Here is the call graph for this function:

Member Data Documentation

final Logger com.mapd.parser.server.ExtensionFunctionSignatureParser.HEAVYDBLOGGER
staticpackage
Initial value:
=
LoggerFactory.getLogger(ExtensionFunctionSignatureParser.class)

Definition at line 38 of file ExtensionFunctionSignatureParser.java.

String com.mapd.parser.server.ExtensionFunctionSignatureParser.OS = System.getProperty("os.name").toLowerCase()
staticprivate

The documentation for this class was generated from the following file: