OmniSciDB  a5dc49c757
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CalciteServerHandler.java
Go to the documentation of this file.
1 /*
2  * Copyright 2022 HEAVY.AI, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.mapd.parser.server;
18 
19 import static com.mapd.calcite.parser.HeavyDBParser.CURRENT_PARSER;
20 
25 
29 import org.apache.calcite.runtime.CalciteContextException;
30 import org.apache.calcite.sql.SqlNode;
31 import org.apache.calcite.sql.parser.SqlParseException;
32 import org.apache.calcite.sql.type.SqlTypeName;
33 import org.apache.calcite.sql.validate.SqlMoniker;
34 import org.apache.calcite.sql.validate.SqlMonikerType;
35 import org.apache.calcite.tools.RelConversionException;
36 import org.apache.calcite.tools.ValidationException;
37 import org.apache.calcite.util.Pair;
38 import org.apache.commons.pool.PoolableObjectFactory;
39 import org.apache.commons.pool.impl.GenericObjectPool;
40 import org.apache.thrift.TException;
41 import org.apache.thrift.server.TServer;
42 import org.slf4j.Logger;
43 import org.slf4j.LoggerFactory;
44 
45 import java.io.IOException;
46 import java.util.ArrayList;
47 import java.util.Arrays;
48 import java.util.HashMap;
49 import java.util.List;
50 import java.util.Map;
51 import java.util.stream.Collectors;
52 
53 import ai.heavy.thrift.calciteserver.CalciteServer;
54 import ai.heavy.thrift.calciteserver.InvalidParseRequest;
55 import ai.heavy.thrift.calciteserver.TAccessedQueryObjects;
56 import ai.heavy.thrift.calciteserver.TCompletionHint;
57 import ai.heavy.thrift.calciteserver.TCompletionHintType;
58 import ai.heavy.thrift.calciteserver.TExtArgumentType;
59 import ai.heavy.thrift.calciteserver.TFilterPushDownInfo;
60 import ai.heavy.thrift.calciteserver.TOptimizationOption;
61 import ai.heavy.thrift.calciteserver.TPlanResult;
62 import ai.heavy.thrift.calciteserver.TQueryParsingOption;
63 import ai.heavy.thrift.calciteserver.TRestriction;
64 import ai.heavy.thrift.calciteserver.TUserDefinedFunction;
65 import ai.heavy.thrift.calciteserver.TUserDefinedTableFunction;
66 
67 public class CalciteServerHandler implements CalciteServer.Iface {
68  final static Logger HEAVYDBLOGGER = LoggerFactory.getLogger(CalciteServerHandler.class);
69  private TServer server;
70 
71  private final int dbPort;
72 
73  private volatile long callCount;
74 
75  private final GenericObjectPool parserPool;
76 
78 
79  private final String extSigsJson;
80 
81  private final String udfSigsJson;
82 
83  private String udfRTSigsJson = "";
84  Map<String, ExtensionFunction> udfRTSigs = null;
85 
86  Map<String, ExtensionFunction> udtfSigs = null;
87 
89  private Map<String, ExtensionFunction> extSigs = null;
90  private String dataDir;
91 
92  // TODO MAT we need to merge this into common code base for these functions with
93  // CalciteDirect since we are not deprecating this stuff yet
95  String dataDir,
96  String extensionFunctionsAstFile,
98  String udfAstFile) {
99  this.dbPort = dbPort;
100  this.dataDir = dataDir;
101 
102  Map<String, ExtensionFunction> udfSigs = null;
103 
104  try {
105  extSigs = ExtensionFunctionSignatureParser.parse(extensionFunctionsAstFile);
106  } catch (IOException ex) {
107  HEAVYDBLOGGER.error(
108  "Could not load extension function signatures: " + ex.getMessage(), ex);
109  }
110  extSigsJson = ExtensionFunctionSignatureParser.signaturesToJson(extSigs);
111 
112  try {
113  if (!udfAstFile.isEmpty()) {
114  udfSigs = ExtensionFunctionSignatureParser.parseUdfAst(udfAstFile);
115  }
116  } catch (IOException ex) {
117  HEAVYDBLOGGER.error(
118  "Could not load udf function signatures: " + ex.getMessage(), ex);
119  }
120  udfSigsJson = ExtensionFunctionSignatureParser.signaturesToJson(udfSigs);
121 
122  // Put all the udf functions signatures in extSigs so Calcite has a view of
123  // extension functions and udf functions
124  if (!udfAstFile.isEmpty()) {
125  extSigs.putAll(udfSigs);
126  }
127 
128  calciteParserFactory = new CalciteParserFactory(dataDir, extSigs, dbPort, skT);
129 
130  // GenericObjectPool::setFactory is deprecated
131  this.parserPool = new GenericObjectPool(calciteParserFactory);
132  }
133 
134  @Override
135  public void ping() throws TException {
136  HEAVYDBLOGGER.debug("Ping hit");
137  }
138 
139  @Override
140  public TPlanResult process(String user,
141  String session,
142  String catalog,
143  String queryText,
144  TQueryParsingOption queryParsingOption,
145  TOptimizationOption optimizationOption,
146  List<TRestriction> trestrictions) throws InvalidParseRequest, TException {
147  long timer = System.currentTimeMillis();
148  callCount++;
149 
151  try {
152  parser = (HeavyDBParser) parserPool.borrowObject();
153  parser.clearMemo();
154  } catch (Exception ex) {
155  String msg = "Could not get Parse Item from pool: " + ex.getMessage();
156  HEAVYDBLOGGER.error(msg, ex);
157  throw new InvalidParseRequest(-1, msg);
158  }
159  List<Restriction> rests = null;
160  if (trestrictions != null && !trestrictions.isEmpty()) {
161  rests = new ArrayList<>();
162  for (TRestriction trestriction : trestrictions) {
163  Restriction rest = null;
164  rest = new Restriction(trestriction.database,
165  trestriction.table,
166  trestriction.column,
167  trestriction.values);
168  rests.add(rest);
169  }
170  }
171  HeavyDBUser dbUser = new HeavyDBUser(user, session, catalog, dbPort, rests);
172  HEAVYDBLOGGER.debug("process was called User: " + user + " Catalog: " + catalog
173  + " sql: " + queryText);
174  parser.setUser(dbUser);
175  CURRENT_PARSER.set(parser);
176 
177  // this code path is introduced to execute a query for intel-modin project
178  // they appended a special prefix "execute calcite" to distinguish their usage
179  boolean buildRATreeFromRAString = false;
180  if (queryText.startsWith("execute calcite")) {
181  queryText = queryText.replaceFirst("execute calcite", "");
182  buildRATreeFromRAString = true;
183  }
184 
185  // need to trim the sql string as it seems it is not trimed prior to here
186  queryText = queryText.trim();
187  // remove last charcter if it is a ;
188  if (queryText.length() > 0 && queryText.charAt(queryText.length() - 1) == ';') {
189  queryText = queryText.substring(0, queryText.length() - 1);
190  }
191  String jsonResult;
192  SqlIdentifierCapturer capturer;
193  TAccessedQueryObjects primaryAccessedObjects = new TAccessedQueryObjects();
194  TAccessedQueryObjects resolvedAccessedObjects = new TAccessedQueryObjects();
195  try {
196  final List<HeavyDBParserOptions.FilterPushDownInfo> filterPushDownInfo =
197  new ArrayList<>();
198  for (final TFilterPushDownInfo req : optimizationOption.filter_push_down_info) {
199  filterPushDownInfo.add(new HeavyDBParserOptions.FilterPushDownInfo(
200  req.input_prev, req.input_start, req.input_next));
201  }
202  HeavyDBParserOptions parserOptions = new HeavyDBParserOptions(filterPushDownInfo,
203  queryParsingOption.legacy_syntax,
204  queryParsingOption.is_explain,
205  queryParsingOption.is_explain_detail,
206  optimizationOption.is_view_optimize,
207  optimizationOption.enable_watchdog,
208  optimizationOption.distributed_mode);
209 
210  if (!buildRATreeFromRAString) {
211  Pair<String, SqlIdentifierCapturer> res;
212  SqlNode node;
213 
214  res = parser.process(queryText, parserOptions);
215  jsonResult = res.left;
216  capturer = res.right;
217 
218  primaryAccessedObjects.tables_selected_from = new ArrayList<>(capturer.selects);
219  primaryAccessedObjects.tables_inserted_into = new ArrayList<>(capturer.inserts);
220  primaryAccessedObjects.tables_updated_in = new ArrayList<>(capturer.updates);
221  primaryAccessedObjects.tables_deleted_from = new ArrayList<>(capturer.deletes);
222 
223  // also resolve all the views in the select part
224  // resolution of the other parts is not
225  // necessary as these cannot be views
226  resolvedAccessedObjects.tables_selected_from =
227  new ArrayList<>(parser.resolveSelectIdentifiers(capturer));
228  resolvedAccessedObjects.tables_inserted_into = new ArrayList<>(capturer.inserts);
229  resolvedAccessedObjects.tables_updated_in = new ArrayList<>(capturer.updates);
230  resolvedAccessedObjects.tables_deleted_from = new ArrayList<>(capturer.deletes);
231 
232  } else {
233  // exploit Calcite's query optimization rules for RA string
234  jsonResult =
235  parser.buildRATreeAndPerformQueryOptimization(queryText, parserOptions);
236  }
237  } catch (SqlParseException ex) {
238  String msg = "SQL Error: " + ex.getMessage();
239  HEAVYDBLOGGER.error(msg);
240  throw new InvalidParseRequest(-2, msg);
241  } catch (org.apache.calcite.tools.ValidationException ex) {
242  String msg = "SQL Error: " + ex.getMessage();
243  if (ex.getCause() != null
244  && (ex.getCause().getClass() == CalciteContextException.class)) {
245  msg = "SQL Error: " + ex.getCause().getMessage();
246  }
247  HEAVYDBLOGGER.error(msg);
248  throw new InvalidParseRequest(-3, msg);
249  } catch (CalciteContextException ex) {
250  String msg = ex.getMessage();
251  HEAVYDBLOGGER.error(msg);
252  throw new InvalidParseRequest(-6, msg);
253  } catch (RelConversionException ex) {
254  String msg = "Failed to generate relational algebra for query " + ex.getMessage();
255  HEAVYDBLOGGER.error(msg, ex);
256  throw new InvalidParseRequest(-5, msg);
257  } catch (Throwable ex) {
258  HEAVYDBLOGGER.error(ex.getClass().toString());
259  String msg = ex.getMessage();
260  HEAVYDBLOGGER.error(msg, ex);
261  throw new InvalidParseRequest(-4, msg);
262  } finally {
263  CURRENT_PARSER.set(null);
264  try {
265  // put parser object back in pool for others to use
266  parserPool.returnObject(parser);
267  } catch (Exception ex) {
268  String msg = "Could not return parse object: " + ex.getMessage();
269  HEAVYDBLOGGER.error(msg, ex);
270  throw new InvalidParseRequest(-7, msg);
271  }
272  }
273 
274  TPlanResult result = new TPlanResult();
275  result.primary_accessed_objects = primaryAccessedObjects;
276  result.resolved_accessed_objects = resolvedAccessedObjects;
277  result.plan_result = jsonResult;
278  result.execution_time_ms = System.currentTimeMillis() - timer;
279 
280  return result;
281  }
282 
283  @Override
284  public void shutdown() throws TException {
285  // received request to shutdown
286  HEAVYDBLOGGER.debug("Shutdown calcite java server");
287  server.stop();
288  }
289 
290  @Override
292  return this.extSigsJson;
293  }
294 
295  @Override
297  return this.udfSigsJson;
298  }
299 
300  @Override
302  return this.udfRTSigsJson;
303  }
304 
305  void setServer(TServer s) {
306  server = s;
307  }
308 
309  // TODO: Add update type parameter to API.
310  @Override
311  public void updateMetadata(String catalog, String table) throws TException {
312  HEAVYDBLOGGER.debug(
313  "Received invalidation from server for " + catalog + " : " + table);
314  long timer = System.currentTimeMillis();
315  callCount++;
317  try {
318  parser = (HeavyDBParser) parserPool.borrowObject();
319  } catch (Exception ex) {
320  String msg = "Could not get Parse Item from pool: " + ex.getMessage();
321  HEAVYDBLOGGER.error(msg, ex);
322  return;
323  }
324  CURRENT_PARSER.set(parser);
325  try {
326  parser.updateMetaData(catalog, table);
327  } finally {
328  CURRENT_PARSER.set(null);
329  try {
330  // put parser object back in pool for others to use
331  HEAVYDBLOGGER.debug("Returning object to pool");
332  parserPool.returnObject(parser);
333  } catch (Exception ex) {
334  String msg = "Could not return parse object: " + ex.getMessage();
335  HEAVYDBLOGGER.error(msg, ex);
336  }
337  }
338  }
339 
340  @Override
341  public List<TCompletionHint> getCompletionHints(String user,
342  String session,
343  String catalog,
344  List<String> visible_tables,
345  String sql,
346  int cursor) throws TException {
347  callCount++;
349  try {
350  parser = (HeavyDBParser) parserPool.borrowObject();
351  } catch (Exception ex) {
352  String msg = "Could not get Parse Item from pool: " + ex.getMessage();
353  HEAVYDBLOGGER.error(msg, ex);
354  throw new TException(msg);
355  }
356  HeavyDBUser dbUser = new HeavyDBUser(user, session, catalog, dbPort, null);
357  HEAVYDBLOGGER.debug("getCompletionHints was called User: " + user
358  + " Catalog: " + catalog + " sql: " + sql);
359  parser.setUser(dbUser);
360  CURRENT_PARSER.set(parser);
361 
362  HeavyDBPlanner.CompletionResult completion_result;
363  try {
364  completion_result = parser.getCompletionHints(sql, cursor, visible_tables);
365  } catch (Exception ex) {
366  String msg = "Could not retrieve completion hints: " + ex.getMessage();
367  HEAVYDBLOGGER.error(msg, ex);
368  return new ArrayList<>();
369  } finally {
370  CURRENT_PARSER.set(null);
371  try {
372  // put parser object back in pool for others to use
373  parserPool.returnObject(parser);
374  } catch (Exception ex) {
375  String msg = "Could not return parse object: " + ex.getMessage();
376  HEAVYDBLOGGER.error(msg, ex);
377  throw new InvalidParseRequest(-4, msg);
378  }
379  }
380  List<TCompletionHint> result = new ArrayList<>();
381  for (final SqlMoniker hint : completion_result.hints) {
382  result.add(new TCompletionHint(hintTypeToThrift(hint.getType()),
383  hint.getFullyQualifiedNames(),
384  completion_result.replaced));
385  }
386  return result;
387  }
388 
389  @Override
390  public void setRuntimeExtensionFunctions(List<TUserDefinedFunction> udfs,
391  List<TUserDefinedTableFunction> udtfs,
392  boolean isruntime) {
393  if (isruntime) {
394  // Clean up previously defined Runtime UDFs
395  if (udfRTSigs != null) {
396  for (String name : udfRTSigs.keySet()) extSigs.remove(name);
397  udfRTSigsJson = "";
398  udfRTSigs.clear();
399  } else {
400  udfRTSigs = new HashMap<String, ExtensionFunction>();
401  }
402 
403  for (TUserDefinedFunction udf : udfs) {
404  udfRTSigs.put(udf.name, toExtensionFunction(udf, isruntime));
405  }
406 
407  for (TUserDefinedTableFunction udtf : udtfs) {
408  udfRTSigs.put(udtf.name, toExtensionFunction(udtf, isruntime));
409  }
410 
411  // Avoid overwritting compiled and Loadtime UDFs:
412  for (String name : udfRTSigs.keySet()) {
413  if (extSigs.containsKey(name)) {
414  HEAVYDBLOGGER.error("Extension function `" + name
415  + "` exists. Skipping runtime extenension function with the same name.");
416  udfRTSigs.remove(name);
417  }
418  }
419  // udfRTSigsJson will contain only the signatures of UDFs:
420  udfRTSigsJson = ExtensionFunctionSignatureParser.signaturesToJson(udfRTSigs);
421  // Expose RT UDFs to Calcite server:
422  extSigs.putAll(udfRTSigs);
423  } else {
424  // currently only LoadTime UDTFs can be registered via calcite thrift interface
425  if (udtfSigs == null) {
426  udtfSigs = new HashMap<String, ExtensionFunction>();
427  }
428 
429  for (TUserDefinedTableFunction udtf : udtfs) {
430  udtfSigs.put(udtf.name, toExtensionFunction(udtf, isruntime));
431  }
432 
433  extSigs.putAll(udtfSigs);
434  }
435 
436  calciteParserFactory.updateOperatorTable();
437  }
438 
440  TUserDefinedFunction udf, boolean isruntime) {
441  List<ExtensionFunction.ExtArgumentType> args =
442  new ArrayList<ExtensionFunction.ExtArgumentType>();
443  for (TExtArgumentType atype : udf.argTypes) {
444  final ExtensionFunction.ExtArgumentType arg_type = toExtArgumentType(atype);
445  if (arg_type != ExtensionFunction.ExtArgumentType.Void) {
446  args.add(arg_type);
447  }
448  }
449  return new ExtensionFunction(args, toExtArgumentType(udf.retType), udf.annotations);
450  }
451 
453  TUserDefinedTableFunction udtf, boolean isruntime) {
454  int sqlInputArgIdx = 0;
455  int inputArgIdx = 0;
456  int outputArgIdx = 0;
457  List<String> names = new ArrayList<String>();
458  List<ExtensionFunction.ExtArgumentType> args = new ArrayList<>();
459  Map<String, List<ExtensionFunction.ExtArgumentType>> cursor_field_types =
460  new HashMap<>();
461  Map<String, Comparable<?>> default_values = new HashMap<>();
462  for (TExtArgumentType atype : udtf.sqlArgTypes) {
463  args.add(toExtArgumentType(atype));
464  Map<String, String> annot = udtf.annotations.get(sqlInputArgIdx);
465  String name = annot.getOrDefault("name", "inp" + sqlInputArgIdx);
466  if (atype == TExtArgumentType.Cursor) {
467  String field_names_annot = annot.getOrDefault("fields", "");
468  List<ExtensionFunction.ExtArgumentType> field_types = new ArrayList<>();
469  if (field_names_annot.length() > 0) {
470  String[] field_names =
471  field_names_annot.substring(1, field_names_annot.length() - 1)
472  .split(",");
473  for (int i = 0; i < field_names.length; i++) {
474  field_types.add(
475  toExtArgumentType(udtf.getInputArgTypes().get(inputArgIdx++)));
476  }
477  } else {
478  if (!isruntime) {
479  field_types.add(
480  toExtArgumentType(udtf.getInputArgTypes().get(inputArgIdx++)));
481  }
482  }
483  name = name + field_names_annot;
484  cursor_field_types.put(name, field_types);
485  } else {
486  String default_value_annot = annot.getOrDefault("default", null);
487  if (default_value_annot != null) {
488  Comparable<?> default_val = getDefaultValueForAnnot(default_value_annot, atype);
489  if (default_val != null) {
490  default_values.put(name, default_val);
491  }
492  }
493  inputArgIdx++;
494  }
495  names.add(name);
496  sqlInputArgIdx++;
497  }
498 
499  List<ExtensionFunction.ExtArgumentType> outs = new ArrayList<>();
500  for (TExtArgumentType otype : udtf.outputArgTypes) {
501  outs.add(toExtArgumentType(otype));
502  Map<String, String> annot = udtf.annotations.get(sqlInputArgIdx);
503  names.add(annot.getOrDefault("name", "out" + outputArgIdx));
504  sqlInputArgIdx++;
505  outputArgIdx++;
506  }
507  return new ExtensionFunction(args,
508  outs,
509  names,
510  udtf.annotations.get(udtf.annotations.size() - 1),
511  cursor_field_types,
512  default_values);
513  }
514 
515  private static Comparable<?> getDefaultValueForAnnot(
516  String annot, TExtArgumentType input_type) {
517  switch (input_type) {
518  case Int8:
519  return new Byte(annot);
520  case Int16:
521  return new Short(annot);
522  case Int32:
523  return new Integer(annot);
524  case Int64:
525  return new Long(annot);
526  case Float:
527  return new Float(annot);
528  case Double:
529  return new Double(annot);
530  case Bool:
531  return new Boolean(annot);
532  case TextEncodingNone:
533  return annot;
534  default:
535  HEAVYDBLOGGER.error("Unsupported type in UDTF 'default' annotation: "
536  + input_type.toString());
537  return null;
538  }
539  }
540 
541  private static ExtensionFunction.ExtArgumentType toExtArgumentType(
542  TExtArgumentType type) {
543  switch (type) {
544  case Int8:
545  return ExtensionFunction.ExtArgumentType.Int8;
546  case Int16:
547  return ExtensionFunction.ExtArgumentType.Int16;
548  case Int32:
549  return ExtensionFunction.ExtArgumentType.Int32;
550  case Int64:
551  return ExtensionFunction.ExtArgumentType.Int64;
552  case Float:
553  return ExtensionFunction.ExtArgumentType.Float;
554  case Double:
556  case Void:
557  return ExtensionFunction.ExtArgumentType.Void;
558  case PInt8:
559  return ExtensionFunction.ExtArgumentType.PInt8;
560  case PInt16:
561  return ExtensionFunction.ExtArgumentType.PInt16;
562  case PInt32:
563  return ExtensionFunction.ExtArgumentType.PInt32;
564  case PInt64:
565  return ExtensionFunction.ExtArgumentType.PInt64;
566  case PFloat:
567  return ExtensionFunction.ExtArgumentType.PFloat;
568  case PDouble:
569  return ExtensionFunction.ExtArgumentType.PDouble;
570  case PBool:
571  return ExtensionFunction.ExtArgumentType.PBool;
572  case Bool:
573  return ExtensionFunction.ExtArgumentType.Bool;
574  case ArrayInt8:
575  return ExtensionFunction.ExtArgumentType.ArrayInt8;
576  case ArrayInt16:
577  return ExtensionFunction.ExtArgumentType.ArrayInt16;
578  case ArrayInt32:
579  return ExtensionFunction.ExtArgumentType.ArrayInt32;
580  case ArrayInt64:
581  return ExtensionFunction.ExtArgumentType.ArrayInt64;
582  case ArrayFloat:
583  return ExtensionFunction.ExtArgumentType.ArrayFloat;
584  case ArrayDouble:
585  return ExtensionFunction.ExtArgumentType.ArrayDouble;
586  case ArrayBool:
587  return ExtensionFunction.ExtArgumentType.ArrayBool;
589  return ExtensionFunction.ExtArgumentType.ArrayTextEncodingDict;
590  case ColumnInt8:
591  return ExtensionFunction.ExtArgumentType.ColumnInt8;
592  case ColumnInt16:
593  return ExtensionFunction.ExtArgumentType.ColumnInt16;
594  case ColumnInt32:
595  return ExtensionFunction.ExtArgumentType.ColumnInt32;
596  case ColumnInt64:
597  return ExtensionFunction.ExtArgumentType.ColumnInt64;
598  case ColumnFloat:
599  return ExtensionFunction.ExtArgumentType.ColumnFloat;
600  case ColumnDouble:
601  return ExtensionFunction.ExtArgumentType.ColumnDouble;
602  case ColumnBool:
603  return ExtensionFunction.ExtArgumentType.ColumnBool;
605  return ExtensionFunction.ExtArgumentType.ColumnTextEncodingDict;
606  case ColumnTimestamp:
607  return ExtensionFunction.ExtArgumentType.ColumnTimestamp;
608  case GeoPoint:
610  case GeoMultiPoint:
612  case GeoLineString:
614  case GeoMultiLineString:
616  case Cursor:
617  return ExtensionFunction.ExtArgumentType.Cursor;
618  case GeoPolygon:
620  case GeoMultiPolygon:
622  case TextEncodingNone:
623  return ExtensionFunction.ExtArgumentType.TextEncodingNone;
624  case TextEncodingDict:
625  return ExtensionFunction.ExtArgumentType.TextEncodingDict;
626  case Timestamp:
627  return ExtensionFunction.ExtArgumentType.Timestamp;
628  case ColumnListInt8:
629  return ExtensionFunction.ExtArgumentType.ColumnListInt8;
630  case ColumnListInt16:
631  return ExtensionFunction.ExtArgumentType.ColumnListInt16;
632  case ColumnListInt32:
633  return ExtensionFunction.ExtArgumentType.ColumnListInt32;
634  case ColumnListInt64:
635  return ExtensionFunction.ExtArgumentType.ColumnListInt64;
636  case ColumnListFloat:
637  return ExtensionFunction.ExtArgumentType.ColumnListFloat;
638  case ColumnListDouble:
639  return ExtensionFunction.ExtArgumentType.ColumnListDouble;
640  case ColumnListBool:
641  return ExtensionFunction.ExtArgumentType.ColumnListBool;
643  return ExtensionFunction.ExtArgumentType.ColumnListTextEncodingDict;
644  case ColumnArrayInt8:
645  return ExtensionFunction.ExtArgumentType.ColumnArrayInt8;
646  case ColumnArrayInt16:
647  return ExtensionFunction.ExtArgumentType.ColumnArrayInt16;
648  case ColumnArrayInt32:
649  return ExtensionFunction.ExtArgumentType.ColumnArrayInt32;
650  case ColumnArrayInt64:
651  return ExtensionFunction.ExtArgumentType.ColumnArrayInt64;
652  case ColumnArrayFloat:
653  return ExtensionFunction.ExtArgumentType.ColumnArrayFloat;
654  case ColumnArrayDouble:
655  return ExtensionFunction.ExtArgumentType.ColumnArrayDouble;
656  case ColumnArrayBool:
657  return ExtensionFunction.ExtArgumentType.ColumnArrayBool;
659  return ExtensionFunction.ExtArgumentType.ColumnArrayTextEncodingDict;
660  case ColumnListArrayInt8:
661  return ExtensionFunction.ExtArgumentType.ColumnListArrayInt8;
663  return ExtensionFunction.ExtArgumentType.ColumnListArrayInt16;
665  return ExtensionFunction.ExtArgumentType.ColumnListArrayInt32;
667  return ExtensionFunction.ExtArgumentType.ColumnListArrayInt64;
669  return ExtensionFunction.ExtArgumentType.ColumnListArrayFloat;
671  return ExtensionFunction.ExtArgumentType.ColumnListArrayDouble;
672  case ColumnListArrayBool:
673  return ExtensionFunction.ExtArgumentType.ColumnListArrayBool;
675  return ExtensionFunction.ExtArgumentType.ColumnListArrayTextEncodingDict;
676  case DayTimeInterval:
677  return ExtensionFunction.ExtArgumentType.DayTimeInterval;
679  return ExtensionFunction.ExtArgumentType.YearMonthTimeInterval;
680  case ColumnGeoPoint:
681  return ExtensionFunction.ExtArgumentType.ColumnGeoPoint;
682  case ColumnGeoLineString:
683  return ExtensionFunction.ExtArgumentType.ColumnGeoLineString;
684  case ColumnGeoPolygon:
685  return ExtensionFunction.ExtArgumentType.ColumnGeoPolygon;
686  case ColumnGeoMultiPoint:
687  return ExtensionFunction.ExtArgumentType.ColumnGeoMultiPoint;
689  return ExtensionFunction.ExtArgumentType.ColumnGeoMultiLineString;
691  return ExtensionFunction.ExtArgumentType.ColumnGeoMultiPolygon;
692  case ColumnListGeoPoint:
693  return ExtensionFunction.ExtArgumentType.ColumnListGeoPoint;
695  return ExtensionFunction.ExtArgumentType.ColumnListGeoLineString;
697  return ExtensionFunction.ExtArgumentType.ColumnListGeoPolygon;
699  return ExtensionFunction.ExtArgumentType.ColumnListGeoMultiPoint;
701  return ExtensionFunction.ExtArgumentType.ColumnListGeoMultiLineString;
703  return ExtensionFunction.ExtArgumentType.ColumnListGeoMultiPolygon;
705  return ExtensionFunction.ExtArgumentType.ArrayTextEncodingNone;
707  return ExtensionFunction.ExtArgumentType.ColumnTextEncodingNone;
709  return ExtensionFunction.ExtArgumentType.ColumnListTextEncodingNone;
711  return ExtensionFunction.ExtArgumentType.ColumnArrayTextEncodingNone;
713  return ExtensionFunction.ExtArgumentType.ColumnListArrayTextEncodingNone;
714  default:
715  HEAVYDBLOGGER.error("toExtArgumentType: unknown type " + type);
716  return null;
717  }
718  }
719 
720  private static TCompletionHintType hintTypeToThrift(final SqlMonikerType type) {
721  switch (type) {
722  case COLUMN:
723  return TCompletionHintType.COLUMN;
724  case TABLE:
725  return TCompletionHintType.TABLE;
726  case VIEW:
727  return TCompletionHintType.VIEW;
728  case SCHEMA:
729  return TCompletionHintType.SCHEMA;
730  case CATALOG:
731  return TCompletionHintType.CATALOG;
732  case REPOSITORY:
733  return TCompletionHintType.REPOSITORY;
734  case FUNCTION:
735  return TCompletionHintType.FUNCTION;
736  case KEYWORD:
737  return TCompletionHintType.KEYWORD;
738  default:
739  return null;
740  }
741  }
742 }
struct GeoLineStringStruct GeoLineString
Definition: heavydbTypes.h:999
static Comparable<?> getDefaultValueForAnnot(String annot, TExtArgumentType input_type)
struct GeoPointStruct GeoPoint
Definition: heavydbTypes.h:963
Simplified core of GeoJSON Polygon coordinates definition.
CalciteServerHandler(int dbPort, String dataDir, String extensionFunctionsAstFile, SockTransportProperties skT, String udfAstFile)
void setRuntimeExtensionFunctions(List< TUserDefinedFunction > udfs, List< TUserDefinedTableFunction > udtfs, boolean isruntime)
Simplified core of GeoJSON MultiPolygon coordinates definition.
static ExtensionFunction.ExtArgumentType toExtArgumentType(TExtArgumentType type)
void updateMetadata(String catalog, String table)
std::string toString(const Executor::ExtModuleKinds &kind)
Definition: Execute.h:1703
struct GeoMultiPointStruct GeoMultiPoint
Definition: heavydbTypes.h:981
Map< String, ExtensionFunction > udfRTSigs
struct GeoMultiLineStringStruct GeoMultiLineString
static TCompletionHintType hintTypeToThrift(final SqlMonikerType type)
final List< Map< String, String > > annotations
static ExtensionFunction toExtensionFunction(TUserDefinedFunction udf, boolean isruntime)
static ExtensionFunction toExtensionFunction(TUserDefinedTableFunction udtf, boolean isruntime)
struct GeoMultiPolygonStruct GeoMultiPolygon
string name
Definition: setup.in.py:72
struct GeoPolygonStruct GeoPolygon
TPlanResult process(String user, String session, String catalog, String queryText, TQueryParsingOption queryParsingOption, TOptimizationOption optimizationOption, List< TRestriction > trestrictions)
List< TCompletionHint > getCompletionHints(String user, String session, String catalog, List< String > visible_tables, String sql, int cursor)