OmniSciDB  471d68cefb
 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 MAPDLOGGER
 

Static Private Member Functions

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)
 

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 154 of file ExtensionFunctionSignatureParser.java.

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

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

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

Definition at line 316 of file ExtensionFunctionSignatureParser.java.

References File_Namespace.append(), and i.

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

316  {
317  StringBuilder sb = new StringBuilder();
318  if (strs.isEmpty()) {
319  return "";
320  }
321  sb.append(strs.get(0));
322  for (int i = 1; i < strs.size(); ++i) {
323  sb.append(sep).append(strs.get(i));
324  }
325  return sb.toString();
326  }
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:159

+ 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 41 of file ExtensionFunctionSignatureParser.java.

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

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

+ 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 83 of file ExtensionFunctionSignatureParser.java.

84  {
85  return parseFromString(udf_string, true);
86  }
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 88 of file ExtensionFunctionSignatureParser.java.

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

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

+ 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 60 of file ExtensionFunctionSignatureParser.java.

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

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

+ 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 293 of file ExtensionFunctionSignatureParser.java.

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

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

294  {
295  switch (targetType) {
296  case Bool:
297  return ExtensionFunction.ExtArgumentType.PBool;
298  case Int8:
299  return ExtensionFunction.ExtArgumentType.PInt8;
300  case Int16:
301  return ExtensionFunction.ExtArgumentType.PInt16;
302  case Int32:
303  return ExtensionFunction.ExtArgumentType.PInt32;
304  case Int64:
305  return ExtensionFunction.ExtArgumentType.PInt64;
306  case Float:
307  return ExtensionFunction.ExtArgumentType.PFloat;
308  case Double:
309  return ExtensionFunction.ExtArgumentType.PDouble;
310  default:
311  assert false;
312  return null;
313  }
314  }

+ 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 106 of file ExtensionFunctionSignatureParser.java.

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

106  {
107  List<String> json_sigs = new ArrayList<String>();
108  if (sigs != null) {
109  for (Map.Entry<String, ExtensionFunction> sig : sigs.entrySet()) {
110  if (sig.getValue().isRowUdf()) {
111  json_sigs.add(sig.getValue().toJson(sig.getKey()));
112  }
113  }
114  }
115  return "[" + join(json_sigs, ",") + "]";
116  }
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 118 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().

119  {
120  return toSignature(ret, cs_param_list, has_variable_name, true);
121  }
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 123 of file ExtensionFunctionSignatureParser.java.

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

126  {
127  String[] params = cs_param_list.split(",");
128  List<ExtensionFunction.ExtArgumentType> args =
129  new ArrayList<ExtensionFunction.ExtArgumentType>();
130  for (final String param : params) {
131  ExtensionFunction.ExtArgumentType arg_type;
132  if (has_variable_name) {
133  String[] full_param = param.trim().split("\\s+");
134  if (full_param.length > 0) {
135  if (full_param[0].trim().compareTo("const") == 0) {
136  assert full_param.length > 1;
137  arg_type = deserializeType((full_param[1]).trim());
138  } else {
139  arg_type = deserializeType((full_param[0]).trim());
140  }
141  } else {
142  arg_type = deserializeType(full_param[0]);
143  }
144  } else {
145  arg_type = deserializeType(param.trim());
146  }
147  if (arg_type != ExtensionFunction.ExtArgumentType.Void) {
148  args.add(arg_type);
149  }
150  }
151  assert is_row_func;
152  return new ExtensionFunction(args, deserializeType(ret));
153  }
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.MAPDLOGGER
staticpackage
Initial value:
=
LoggerFactory.getLogger(ExtensionFunctionSignatureParser.class)

Definition at line 38 of file ExtensionFunctionSignatureParser.java.


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