OmniSciDB  baf940c279
com.mapd.parser.server.ExtensionFunctionSignatureParser Class Reference
+ Collaboration diagram for com.mapd.parser.server.ExtensionFunctionSignatureParser:

Static Package Functions

static Map< String, ExtensionFunctionparse (final String file_path) throws IOException
 
static Map< String, ExtensionFunctionparseUdfAst (final String file_path) throws IOException
 
static Map< String, ExtensionFunctionparseFromString (final String udf_string) throws IOException
 
static Map< String, ExtensionFunctionparseFromString (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

◆ deserializeType()

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

Definition at line 154 of file ExtensionFunctionSignatureParser.java.

References com.mapd.parser.server.ExtensionFunction.ExtArgumentType.ArrayBool, com.mapd.parser.server.ExtensionFunction.ExtArgumentType.ArrayDouble, com.mapd.parser.server.ExtensionFunction.ExtArgumentType.ArrayFloat, com.mapd.parser.server.ExtensionFunction.ExtArgumentType.ArrayInt16, com.mapd.parser.server.ExtensionFunction.ExtArgumentType.ArrayInt32, com.mapd.parser.server.ExtensionFunction.ExtArgumentType.ArrayInt64, com.mapd.parser.server.ExtensionFunction.ExtArgumentType.ArrayInt8, com.mapd.parser.server.ExtensionFunction.ExtArgumentType.Bool, com.mapd.parser.server.ExtensionFunction.ExtArgumentType.ColumnDouble, com.mapd.parser.server.ExtensionFunction.ExtArgumentType.ColumnFloat, com.mapd.parser.server.ExtensionFunction.ExtArgumentType.ColumnInt16, com.mapd.parser.server.ExtensionFunction.ExtArgumentType.ColumnInt32, com.mapd.parser.server.ExtensionFunction.ExtArgumentType.ColumnInt64, com.mapd.parser.server.ExtensionFunction.ExtArgumentType.ColumnInt8, com.mapd.parser.server.ExtensionFunction.ExtArgumentType.Cursor, com.mapd.parser.server.ExtensionFunction.ExtArgumentType.Double, com.mapd.parser.server.ExtensionFunction.ExtArgumentType.Float, com.mapd.parser.server.ExtensionFunction.ExtArgumentType.GeoLineString, com.mapd.parser.server.ExtensionFunction.ExtArgumentType.GeoMultiPolygon, com.mapd.parser.server.ExtensionFunction.ExtArgumentType.GeoPoint, com.mapd.parser.server.ExtensionFunction.ExtArgumentType.GeoPolygon, com.mapd.parser.server.ExtensionFunction.ExtArgumentType.Int16, com.mapd.parser.server.ExtensionFunction.ExtArgumentType.Int32, com.mapd.parser.server.ExtensionFunction.ExtArgumentType.Int64, com.mapd.parser.server.ExtensionFunction.ExtArgumentType.Int8, com.mapd.parser.server.ExtensionFunctionSignatureParser.pointerType(), and com.mapd.parser.server.ExtensionFunction.ExtArgumentType.Void.

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")) {
189  return ExtensionFunction.ExtArgumentType.Double;
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("Cursor")) {
245  return ExtensionFunction.ExtArgumentType.Cursor;
246  }
247  if (type_name.equals("GeoPoint")) {
248  return ExtensionFunction.ExtArgumentType.GeoPoint;
249  }
250  if (type_name.equals("GeoLineString")) {
251  return ExtensionFunction.ExtArgumentType.GeoLineString;
252  }
253  if (type_name.equals("GeoPolygon")) {
254  return ExtensionFunction.ExtArgumentType.GeoPolygon;
255  }
256  if (type_name.equals("GeoMultiPolygon")) {
257  return ExtensionFunction.ExtArgumentType.GeoMultiPolygon;
258  }
259 
260  MAPDLOGGER.info(
261  "ExtensionfunctionSignatureParser::deserializeType: unknown type_name=`"
262  + type_name + "`");
263  // TODO: Return void for convenience. Consider sanitizing functions for supported
264  // types before they reach Calcite
265  return ExtensionFunction.ExtArgumentType.Void;
266  }
static ExtensionFunction.ExtArgumentType pointerType(final ExtensionFunction.ExtArgumentType targetType)
static ExtensionFunction.ExtArgumentType deserializeType(final String type_name)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ join()

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

Definition at line 291 of file ExtensionFunctionSignatureParser.java.

Referenced by com.mapd.parser.server.ExtensionFunctionSignatureParser.signaturesToJson(), and com.mapd.parser.server.ExtensionFunction.toJson().

291  {
292  StringBuilder sb = new StringBuilder();
293  if (strs.isEmpty()) {
294  return "";
295  }
296  sb.append(strs.get(0));
297  for (int i = 1; i < strs.size(); ++i) {
298  sb.append(sep).append(strs.get(i));
299  }
300  return sb.toString();
301  }
+ Here is the caller graph for this function:

◆ parse()

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().

Referenced by com.mapd.parser.server.CalciteServerHandler.CalciteServerHandler().

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  }
name
Definition: setup.py:35
static ExtensionFunction toSignature(final String ret, final String cs_param_list, final boolean has_variable_name)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ parseFromString() [1/2]

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)

◆ parseFromString() [2/2]

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  }
name
Definition: setup.py:35
static ExtensionFunction toSignature(final String ret, final String cs_param_list, final boolean has_variable_name)
+ Here is the call graph for this function:

◆ parseUdfAst()

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().

Referenced by com.mapd.parser.server.CalciteServerHandler.CalciteServerHandler().

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  }
name
Definition: setup.py:35
static ExtensionFunction toSignature(final String ret, final String cs_param_list, final boolean has_variable_name)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ pointerType()

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

Definition at line 268 of file ExtensionFunctionSignatureParser.java.

References Bool, Double, Int16, Int32, Int64, Int8, com.mapd.parser.server.ExtensionFunction.ExtArgumentType.PBool, com.mapd.parser.server.ExtensionFunction.ExtArgumentType.PDouble, com.mapd.parser.server.ExtensionFunction.ExtArgumentType.PFloat, com.mapd.parser.server.ExtensionFunction.ExtArgumentType.PInt16, com.mapd.parser.server.ExtensionFunction.ExtArgumentType.PInt32, com.mapd.parser.server.ExtensionFunction.ExtArgumentType.PInt64, and com.mapd.parser.server.ExtensionFunction.ExtArgumentType.PInt8.

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

269  {
270  switch (targetType) {
271  case Bool:
272  return ExtensionFunction.ExtArgumentType.PBool;
273  case Int8:
274  return ExtensionFunction.ExtArgumentType.PInt8;
275  case Int16:
276  return ExtensionFunction.ExtArgumentType.PInt16;
277  case Int32:
278  return ExtensionFunction.ExtArgumentType.PInt32;
279  case Int64:
280  return ExtensionFunction.ExtArgumentType.PInt64;
281  case Float:
282  return ExtensionFunction.ExtArgumentType.PFloat;
283  case Double:
284  return ExtensionFunction.ExtArgumentType.PDouble;
285  default:
286  assert false;
287  return null;
288  }
289  }
+ Here is the caller graph for this function:

◆ signaturesToJson()

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().

Referenced by com.mapd.parser.server.CalciteServerHandler.CalciteServerHandler(), and com.mapd.parser.server.CalciteServerHandler.setRuntimeExtensionFunctions().

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:
+ Here is the caller graph for this function:

◆ toSignature() [1/2]

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:

◆ toSignature() [2/2]

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 com.mapd.parser.server.ExtensionFunction.ExtArgumentType.Void.

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  }
static ExtensionFunction.ExtArgumentType deserializeType(final String type_name)
+ Here is the call graph for this function:

Member Data Documentation

◆ MAPDLOGGER

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: