OmniSciDB  04ee39c94c
com.mapd.parser.server.ExtensionFunctionSignatureParser Class Reference

Static Package Functions

static Map< String, ExtensionFunctionparse (final String file_path) throws IOException
 
static Map< String, ExtensionFunctionparseFromString (final String udf_string) throws IOException
 
static String signaturesToJson (final Map< String, ExtensionFunction > sigs)
 
static String join (final List< String > strs, final String sep)
 

Static Private Member Functions

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

Detailed Description

Author
alex

Definition at line 34 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 97 of file ExtensionFunctionSignatureParser.java.

References com.mapd.parser.server.ExtensionFunction.ExtArgumentType.Bool, com.mapd.parser.server.ExtensionFunction.ExtArgumentType.Double, com.mapd.parser.server.ExtensionFunction.ExtArgumentType.Float, 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(), Experimental.String, and com.mapd.parser.server.ExtensionFunction.ExtArgumentType.Void.

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

98  {
99  final String const_prefix = "const ";
100  if (type_name.startsWith(const_prefix)) {
101  return deserializeType(type_name.substring(const_prefix.length()));
102  }
103  if (type_name.equals("bool") || type_name.equals("_Bool")) {
104  return ExtensionFunction.ExtArgumentType.Bool;
105  }
106  if (type_name.equals("int8_t") || type_name.equals("char")
107  || type_name.equals("int8")) {
108  return ExtensionFunction.ExtArgumentType.Int8;
109  }
110  if (type_name.equals("int16_t") || type_name.equals("short")
111  || type_name.equals("int16")) {
112  return ExtensionFunction.ExtArgumentType.Int16;
113  }
114  if (type_name.equals("int32_t") || type_name.equals("int")
115  || type_name.equals("int32")) {
116  return ExtensionFunction.ExtArgumentType.Int32;
117  }
118  if (type_name.equals("int64_t") || type_name.equals("size_t")
119  || type_name.equals("int64") || type_name.equals("long")) {
120  return ExtensionFunction.ExtArgumentType.Int64;
121  }
122  if (type_name.equals("float") || type_name.equals("float32")) {
123  return ExtensionFunction.ExtArgumentType.Float;
124  }
125  if (type_name.equals("double") || type_name.equals("float64")) {
126  return ExtensionFunction.ExtArgumentType.Double;
127  }
128  if (type_name.isEmpty() || type_name.equals("void")) {
129  return ExtensionFunction.ExtArgumentType.Void;
130  }
131  if (type_name.endsWith(" *")) {
132  return pointerType(deserializeType(type_name.substring(0, type_name.length() - 2)));
133  }
134  if (type_name.endsWith("*")) {
135  return pointerType(deserializeType(type_name.substring(0, type_name.length() - 1)));
136  }
137  assert false;
138  return null;
139  }
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 162 of file ExtensionFunctionSignatureParser.java.

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

162  {
163  StringBuilder sb = new StringBuilder();
164  if (strs.isEmpty()) {
165  return "";
166  }
167  sb.append(strs.get(0));
168  for (int i = 1; i < strs.size(); ++i) {
169  sb.append(sep).append(strs.get(i));
170  }
171  return sb.toString();
172  }
+ 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 35 of file ExtensionFunctionSignatureParser.java.

References Experimental.String, and com.mapd.parser.server.ExtensionFunctionSignatureParser.toSignature().

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

35  {
36  File file = new File(file_path);
37  FileReader fileReader = new FileReader(file);
38  BufferedReader bufferedReader = new BufferedReader(fileReader);
39  String line;
40  Pattern r = Pattern.compile("([\\w]+) '([\\w]+) \\((.*)\\)'");
41  Map<String, ExtensionFunction> sigs = new HashMap<String, ExtensionFunction>();
42  while ((line = bufferedReader.readLine()) != null) {
43  Matcher m = r.matcher(line);
44  if (m.find()) {
45  final String name = m.group(1);
46  final String ret = m.group(2);
47  final String cs_param_list = m.group(3);
48  sigs.put(name, toSignature(ret, cs_param_list));
49  }
50  }
51  return sigs;
52  }
static ExtensionFunction toSignature(final String ret, final String cs_param_list)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ parseFromString()

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

Definition at line 54 of file ExtensionFunctionSignatureParser.java.

References Experimental.String, and com.mapd.parser.server.ExtensionFunctionSignatureParser.toSignature().

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

55  {
56  StringReader stringReader = new StringReader(udf_string);
57  BufferedReader bufferedReader = new BufferedReader(stringReader);
58  String line;
59  Pattern r = Pattern.compile("([\\w]+)\\s+'([\\w]+)\\s*\\((.*)\\)'");
60  Map<String, ExtensionFunction> sigs = new HashMap<String, ExtensionFunction>();
61  while ((line = bufferedReader.readLine()) != null) {
62  Matcher m = r.matcher(line);
63  if (m.find()) {
64  final String name = m.group(1);
65  final String ret = m.group(2);
66  final String cs_param_list = m.group(3);
67  sigs.put(name, toSignature(ret, cs_param_list));
68  }
69  }
70  return sigs;
71  }
static ExtensionFunction toSignature(final String ret, final String cs_param_list)
+ 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 141 of file ExtensionFunctionSignatureParser.java.

References Double, Float, Int16, Int32, Int64, Int8, 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().

142  {
143  switch (targetType) {
144  case Int8:
145  return ExtensionFunction.ExtArgumentType.PInt8;
146  case Int16:
147  return ExtensionFunction.ExtArgumentType.PInt16;
148  case Int32:
149  return ExtensionFunction.ExtArgumentType.PInt32;
150  case Int64:
151  return ExtensionFunction.ExtArgumentType.PInt64;
152  case Float:
153  return ExtensionFunction.ExtArgumentType.PFloat;
154  case Double:
155  return ExtensionFunction.ExtArgumentType.PDouble;
156  default:
157  assert false;
158  return null;
159  }
160  }
+ 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 73 of file ExtensionFunctionSignatureParser.java.

References com.mapd.parser.server.ExtensionFunctionSignatureParser.join(), and Experimental.String.

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

73  {
74  List<String> json_sigs = new ArrayList<String>();
75  if (sigs != null) {
76  for (Map.Entry<String, ExtensionFunction> sig : sigs.entrySet()) {
77  json_sigs.add(sig.getValue().toJson(sig.getKey()));
78  }
79  }
80  return "[" + join(json_sigs, ",") + "]";
81  }
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()

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

Definition at line 83 of file ExtensionFunctionSignatureParser.java.

References run-benchmark-import.args, com.mapd.parser.server.ExtensionFunctionSignatureParser.deserializeType(), Experimental.String, and com.mapd.parser.server.ExtensionFunction.ExtArgumentType.Void.

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

84  {
85  String[] params = cs_param_list.split(",");
86  List<ExtensionFunction.ExtArgumentType> args =
87  new ArrayList<ExtensionFunction.ExtArgumentType>();
88  for (final String param : params) {
89  final ExtensionFunction.ExtArgumentType arg_type = deserializeType(param.trim());
90  if (arg_type != ExtensionFunction.ExtArgumentType.Void) {
91  args.add(arg_type);
92  }
93  }
94  return new ExtensionFunction(args, deserializeType(ret));
95  }
static ExtensionFunction.ExtArgumentType deserializeType(final String type_name)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

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