OmniSciDB  7bf56492aa
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros 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 151 of file ExtensionFunctionSignatureParser.java.

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

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

152  {
153  final String const_prefix = "const ";
154  final String std_namespace_prefix = "std::";
155 
156  if (type_name.startsWith(const_prefix)) {
157  return deserializeType(type_name.substring(const_prefix.length()));
158  }
159  if (type_name.startsWith(std_namespace_prefix)) {
160  return deserializeType(type_name.substring(std_namespace_prefix.length()));
161  }
162 
163  if (type_name.equals("bool") || type_name.equals("_Bool")) {
164  return ExtensionFunction.ExtArgumentType.Bool;
165  }
166  if (type_name.equals("int8_t") || type_name.equals("char")
167  || type_name.equals("int8")) {
168  return ExtensionFunction.ExtArgumentType.Int8;
169  }
170  if (type_name.equals("int16_t") || type_name.equals("short")
171  || type_name.equals("int16")) {
172  return ExtensionFunction.ExtArgumentType.Int16;
173  }
174  if (type_name.equals("int32_t") || type_name.equals("int")
175  || type_name.equals("int32")) {
176  return ExtensionFunction.ExtArgumentType.Int32;
177  }
178  if (type_name.equals("int64_t") || type_name.equals("size_t")
179  || type_name.equals("int64") || type_name.equals("long")) {
180  return ExtensionFunction.ExtArgumentType.Int64;
181  }
182  if (type_name.equals("float") || type_name.equals("float32")) {
183  return ExtensionFunction.ExtArgumentType.Float;
184  }
185  if (type_name.equals("double") || type_name.equals("float64")) {
187  }
188  if (type_name.isEmpty() || type_name.equals("void")) {
189  return ExtensionFunction.ExtArgumentType.Void;
190  }
191  if (type_name.endsWith(" *")) {
192  return pointerType(deserializeType(type_name.substring(0, type_name.length() - 2)));
193  }
194  if (type_name.endsWith("*")) {
195  return pointerType(deserializeType(type_name.substring(0, type_name.length() - 1)));
196  }
197  if (type_name.equals("Array<bool>")) {
198  return ExtensionFunction.ExtArgumentType.ArrayBool;
199  }
200  if (type_name.equals("Array<int8_t>") || type_name.equals("Array<char>")) {
201  return ExtensionFunction.ExtArgumentType.ArrayInt8;
202  }
203  if (type_name.equals("Array<int16_t>") || type_name.equals("Array<short>")) {
204  return ExtensionFunction.ExtArgumentType.ArrayInt16;
205  }
206  if (type_name.equals("Array<int32_t>") || type_name.equals("Array<int>")) {
207  return ExtensionFunction.ExtArgumentType.ArrayInt32;
208  }
209  if (type_name.equals("Array<int64_t>") || type_name.equals("Array<size_t>")
210  || type_name.equals("Array<long>")) {
211  return ExtensionFunction.ExtArgumentType.ArrayInt64;
212  }
213  if (type_name.equals("Array<float>")) {
214  return ExtensionFunction.ExtArgumentType.ArrayFloat;
215  }
216  if (type_name.equals("Array<double>")) {
217  return ExtensionFunction.ExtArgumentType.ArrayDouble;
218  }
219  if (type_name.equals("Cursor")) {
220  return ExtensionFunction.ExtArgumentType.Cursor;
221  }
222  if (type_name.equals("GeoPoint")) {
223  return ExtensionFunction.ExtArgumentType.GeoPoint;
224  }
225  if (type_name.equals("GeoLineString")) {
226  return ExtensionFunction.ExtArgumentType.GeoLineString;
227  }
228  if (type_name.equals("GeoPolygon")) {
229  return ExtensionFunction.ExtArgumentType.GeoPolygon;
230  }
231  if (type_name.equals("GeoMultiPolygon")) {
232  return ExtensionFunction.ExtArgumentType.GeoMultiPolygon;
233  }
234 
235  MAPDLOGGER.info(
236  "ExtensionfunctionSignatureParser::deserializeType: unknown type_name=`"
237  + type_name + "`");
238  // TODO: Return void for convenience. Consider sanitizing functions for supported
239  // types before they reach Calcite
240  return ExtensionFunction.ExtArgumentType.Void;
241  }
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:

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

Definition at line 266 of file ExtensionFunctionSignatureParser.java.

References File_Namespace.append().

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

266  {
267  StringBuilder sb = new StringBuilder();
268  if (strs.isEmpty()) {
269  return "";
270  }
271  sb.append(strs.get(0));
272  for (int i = 1; i < strs.size(); ++i) {
273  sb.append(sep).append(strs.get(i));
274  }
275  return sb.toString();
276  }
size_t append(FILE *f, const size_t size, int8_t *buf)
Appends the specified number of bytes to the end of the file f from buf.
Definition: File.cpp:135

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

References assert(), Bool, Double, Float, Int16, Int32, Int64, and Int8.

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

244  {
245  switch (targetType) {
246  case Bool:
247  return ExtensionFunction.ExtArgumentType.PBool;
248  case Int8:
249  return ExtensionFunction.ExtArgumentType.PInt8;
250  case Int16:
251  return ExtensionFunction.ExtArgumentType.PInt16;
252  case Int32:
253  return ExtensionFunction.ExtArgumentType.PInt32;
254  case Int64:
255  return ExtensionFunction.ExtArgumentType.PInt64;
256  case Float:
257  return ExtensionFunction.ExtArgumentType.PFloat;
258  case Double:
259  return ExtensionFunction.ExtArgumentType.PDouble;
260  default:
261  assert false;
262  return null;
263  }
264  }
int64_t const int32_t sz assert(dest)

+ Here is the call graph for this function:

+ 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  json_sigs.add(sig.getValue().toJson(sig.getKey()));
111  }
112  }
113  return "[" + join(json_sigs, ",") + "]";
114  }
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 116 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().

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

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

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