OmniSciDB  cecceef8da
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
com.mapd.parser.server.CalciteServerHandler Class Reference
+ Inheritance diagram for com.mapd.parser.server.CalciteServerHandler:
+ Collaboration diagram for com.mapd.parser.server.CalciteServerHandler:

Public Member Functions

 CalciteServerHandler (int mapdPort, String dataDir, String extensionFunctionsAstFile, SockTransportProperties skT, String udfAstFile)
 
void ping () throws TException
 
TPlanResult process (String user, String session, String catalog, String sqlText, java.util.List< TFilterPushDownInfo > thriftFilterPushDownInfo, boolean legacySyntax, boolean isExplain, boolean isViewOptimize) throws InvalidParseRequest, TException
 
void shutdown () throws TException
 
String getExtensionFunctionWhitelist ()
 
String getUserDefinedFunctionWhitelist ()
 
String getRuntimeExtensionFunctionWhitelist ()
 
void updateMetadata (String catalog, String table) throws TException
 
List< TCompletionHint > getCompletionHints (String user, String session, String catalog, List< String > visible_tables, String sql, int cursor) throws TException
 
void setRuntimeExtensionFunctions (List< TUserDefinedFunction > udfs, List< TUserDefinedTableFunction > udtfs)
 

Package Functions

void setServer (TServer s)
 

Package Attributes

Map< String, ExtensionFunctionudfRTSigs = null
 

Static Package Attributes

static final Logger MAPDLOGGER = LoggerFactory.getLogger(CalciteServerHandler.class)
 

Static Private Member Functions

static ExtensionFunction toExtensionFunction (TUserDefinedFunction udf)
 
static ExtensionFunction toExtensionFunction (TUserDefinedTableFunction udtf)
 
static
ExtensionFunction.ExtArgumentType 
toExtArgumentType (TExtArgumentType type)
 
static TCompletionHintType hintTypeToThrift (final SqlMonikerType type)
 

Private Attributes

TServer server
 
final int mapdPort
 
volatile long callCount
 
final GenericObjectPool parserPool
 
final String extSigsJson
 
final String udfSigsJson
 
String udfRTSigsJson = ""
 
SockTransportProperties skT
 
Map< String, ExtensionFunctionextSigs = null
 
String dataDir
 

Detailed Description

Author
michael

Definition at line 60 of file CalciteServerHandler.java.

Constructor & Destructor Documentation

com.mapd.parser.server.CalciteServerHandler.CalciteServerHandler ( int  mapdPort,
String  dataDir,
String  extensionFunctionsAstFile,
SockTransportProperties  skT,
String  udfAstFile 
)
inline

Definition at line 83 of file CalciteServerHandler.java.

References com.mapd.parser.server.CalciteServerHandler.dataDir, com.mapd.parser.server.CalciteServerHandler.extSigs, com.mapd.parser.server.CalciteServerHandler.extSigsJson, com.mapd.parser.server.CalciteServerHandler.mapdPort, and com.mapd.parser.server.CalciteServerHandler.udfSigsJson.

87  {
88  this.mapdPort = mapdPort;
89  this.dataDir = dataDir;
90 
91  Map<String, ExtensionFunction> udfSigs = null;
92 
93  try {
94  extSigs = ExtensionFunctionSignatureParser.parse(extensionFunctionsAstFile);
95  } catch (IOException ex) {
96  MAPDLOGGER.error(
97  "Could not load extension function signatures: " + ex.getMessage(), ex);
98  }
99  extSigsJson = ExtensionFunctionSignatureParser.signaturesToJson(extSigs);
100 
101  try {
102  if (!udfAstFile.isEmpty()) {
103  udfSigs = ExtensionFunctionSignatureParser.parseUdfAst(udfAstFile);
104  }
105  } catch (IOException ex) {
106  MAPDLOGGER.error("Could not load udf function signatures: " + ex.getMessage(), ex);
107  }
108  udfSigsJson = ExtensionFunctionSignatureParser.signaturesToJson(udfSigs);
109 
110  // Put all the udf functions signatures in extSigs so Calcite has a view of
111  // extension functions and udf functions
112  if (!udfAstFile.isEmpty()) {
113  extSigs.putAll(udfSigs);
114  }
115 
116  PoolableObjectFactory parserFactory =
117  new CalciteParserFactory(dataDir, extSigs, mapdPort, skT);
118  // GenericObjectPool::setFactory is deprecated
119  this.parserPool = new GenericObjectPool(parserFactory);
120  }

Member Function Documentation

List<TCompletionHint> com.mapd.parser.server.CalciteServerHandler.getCompletionHints ( String  user,
String  session,
String  catalog,
List< String >  visible_tables,
String  sql,
int  cursor 
) throws TException
inline

Definition at line 289 of file CalciteServerHandler.java.

References com.mapd.parser.server.CalciteServerHandler.callCount, com.mapd.parser.server.CalciteServerHandler.hintTypeToThrift(), com.mapd.parser.server.CalciteServerHandler.mapdPort, run_benchmark_import.parser, com.mapd.parser.server.CalciteServerHandler.parserPool, run_benchmark_import.result, and Experimental.String.

294  {
295  callCount++;
296  MapDParser parser;
297  try {
298  parser = (MapDParser) parserPool.borrowObject();
299  } catch (Exception ex) {
300  String msg = "Could not get Parse Item from pool: " + ex.getMessage();
301  MAPDLOGGER.error(msg, ex);
302  throw new TException(msg);
303  }
304  MapDUser mapDUser = new MapDUser(user, session, catalog, mapdPort);
305  MAPDLOGGER.debug("getCompletionHints was called User: " + user
306  + " Catalog: " + catalog + " sql: " + sql);
307  parser.setUser(mapDUser);
308  CURRENT_PARSER.set(parser);
309 
310  MapDPlanner.CompletionResult completion_result;
311  try {
312  completion_result = parser.getCompletionHints(sql, cursor, visible_tables);
313  } catch (Exception ex) {
314  String msg = "Could not retrieve completion hints: " + ex.getMessage();
315  MAPDLOGGER.error(msg, ex);
316  return new ArrayList<>();
317  } finally {
318  CURRENT_PARSER.set(null);
319  try {
320  // put parser object back in pool for others to use
321  parserPool.returnObject(parser);
322  } catch (Exception ex) {
323  String msg = "Could not return parse object: " + ex.getMessage();
324  MAPDLOGGER.error(msg, ex);
325  throw new InvalidParseRequest(-4, msg);
326  }
327  }
328  List<TCompletionHint> result = new ArrayList<>();
329  for (final SqlMoniker hint : completion_result.hints) {
330  result.add(new TCompletionHint(hintTypeToThrift(hint.getType()),
331  hint.getFullyQualifiedNames(),
332  completion_result.replaced));
333  }
334  return result;
335  }
static TCompletionHintType hintTypeToThrift(final SqlMonikerType type)

+ Here is the call graph for this function:

String com.mapd.parser.server.CalciteServerHandler.getExtensionFunctionWhitelist ( )
inline

Definition at line 241 of file CalciteServerHandler.java.

241  {
242  return this.extSigsJson;
243  }
String com.mapd.parser.server.CalciteServerHandler.getRuntimeExtensionFunctionWhitelist ( )
inline

Definition at line 251 of file CalciteServerHandler.java.

251  {
252  return this.udfRTSigsJson;
253  }
String com.mapd.parser.server.CalciteServerHandler.getUserDefinedFunctionWhitelist ( )
inline

Definition at line 246 of file CalciteServerHandler.java.

246  {
247  return this.udfSigsJson;
248  }
static TCompletionHintType com.mapd.parser.server.CalciteServerHandler.hintTypeToThrift ( final SqlMonikerType  type)
inlinestaticprivate

Definition at line 445 of file CalciteServerHandler.java.

References TABLE.

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

445  {
446  switch (type) {
447  case COLUMN:
448  return TCompletionHintType.COLUMN;
449  case TABLE:
450  return TCompletionHintType.TABLE;
451  case VIEW:
452  return TCompletionHintType.VIEW;
453  case SCHEMA:
454  return TCompletionHintType.SCHEMA;
455  case CATALOG:
456  return TCompletionHintType.CATALOG;
457  case REPOSITORY:
458  return TCompletionHintType.REPOSITORY;
459  case FUNCTION:
460  return TCompletionHintType.FUNCTION;
461  case KEYWORD:
462  return TCompletionHintType.KEYWORD;
463  default:
464  return null;
465  }
466  }

+ Here is the caller graph for this function:

void com.mapd.parser.server.CalciteServerHandler.ping ( ) throws TException
inline

Definition at line 123 of file CalciteServerHandler.java.

123  {
124  MAPDLOGGER.debug("Ping hit");
125  }
TPlanResult com.mapd.parser.server.CalciteServerHandler.process ( String  user,
String  session,
String  catalog,
String  sqlText,
java.util.List< TFilterPushDownInfo >  thriftFilterPushDownInfo,
boolean  legacySyntax,
boolean  isExplain,
boolean  isViewOptimize 
) throws InvalidParseRequest, TException
inline

Definition at line 128 of file CalciteServerHandler.java.

References com.mapd.parser.server.CalciteServerHandler.callCount, com.mapd.parser.server.CalciteServerHandler.mapdPort, run_benchmark_import.parser, com.mapd.parser.server.CalciteServerHandler.parserPool, run_benchmark_import.result, and Experimental.String.

135  {
136  long timer = System.currentTimeMillis();
137  callCount++;
138 
139  MapDParser parser;
140  try {
141  parser = (MapDParser) parserPool.borrowObject();
142  parser.clearMemo();
143  } catch (Exception ex) {
144  String msg = "Could not get Parse Item from pool: " + ex.getMessage();
145  MAPDLOGGER.error(msg, ex);
146  throw new InvalidParseRequest(-1, msg);
147  }
148  MapDUser mapDUser = new MapDUser(user, session, catalog, mapdPort);
149  MAPDLOGGER.debug("process was called User: " + user + " Catalog: " + catalog
150  + " sql: " + sqlText);
151  parser.setUser(mapDUser);
152  CURRENT_PARSER.set(parser);
153 
154  // need to trim the sql string as it seems it is not trimed prior to here
155  sqlText = sqlText.trim();
156  // remove last charcter if it is a ;
157  if (sqlText.length() > 0 && sqlText.charAt(sqlText.length() - 1) == ';') {
158  sqlText = sqlText.substring(0, sqlText.length() - 1);
159  }
160  String jsonResult;
161  SqlIdentifierCapturer capturer;
162  TAccessedQueryObjects primaryAccessedObjects = new TAccessedQueryObjects();
163  TAccessedQueryObjects resolvedAccessedObjects = new TAccessedQueryObjects();
164  try {
165  final List<MapDParserOptions.FilterPushDownInfo> filterPushDownInfo =
166  new ArrayList<>();
167  for (final TFilterPushDownInfo req : thriftFilterPushDownInfo) {
168  filterPushDownInfo.add(new MapDParserOptions.FilterPushDownInfo(
169  req.input_prev, req.input_start, req.input_next));
170  }
171  try {
172  MapDParserOptions parserOptions = new MapDParserOptions(
173  filterPushDownInfo, legacySyntax, isExplain, isViewOptimize);
174  jsonResult = parser.processSql(sqlText, parserOptions);
175  } catch (ValidationException ex) {
176  String msg = "Validation: " + ex.getMessage();
177  MAPDLOGGER.error(msg, ex);
178  throw ex;
179  } catch (RelConversionException ex) {
180  String msg = " RelConversion failed: " + ex.getMessage();
181  MAPDLOGGER.error(msg, ex);
182  throw ex;
183  }
184  capturer = parser.captureIdentifiers(sqlText, legacySyntax);
185 
186  primaryAccessedObjects.tables_selected_from = new ArrayList<>(capturer.selects);
187  primaryAccessedObjects.tables_inserted_into = new ArrayList<>(capturer.inserts);
188  primaryAccessedObjects.tables_updated_in = new ArrayList<>(capturer.updates);
189  primaryAccessedObjects.tables_deleted_from = new ArrayList<>(capturer.deletes);
190 
191  // also resolve all the views in the select part
192  // resolution of the other parts is not
193  // necessary as these cannot be views
194  resolvedAccessedObjects.tables_selected_from =
195  new ArrayList<>(parser.resolveSelectIdentifiers(capturer));
196  resolvedAccessedObjects.tables_inserted_into = new ArrayList<>(capturer.inserts);
197  resolvedAccessedObjects.tables_updated_in = new ArrayList<>(capturer.updates);
198  resolvedAccessedObjects.tables_deleted_from = new ArrayList<>(capturer.deletes);
199 
200  } catch (SqlParseException ex) {
201  String msg = "Parse failed: " + ex.getMessage();
202  MAPDLOGGER.error(msg, ex);
203  throw new InvalidParseRequest(-2, msg);
204  } catch (CalciteContextException ex) {
205  String msg = "Validate failed: " + ex.getMessage();
206  MAPDLOGGER.error(msg, ex);
207  throw new InvalidParseRequest(-3, msg);
208  } catch (Throwable ex) {
209  String msg = "Exception occurred: " + ex.getMessage();
210  MAPDLOGGER.error(msg, ex);
211  throw new InvalidParseRequest(-4, msg);
212  } finally {
213  CURRENT_PARSER.set(null);
214  try {
215  // put parser object back in pool for others to use
216  parserPool.returnObject(parser);
217  } catch (Exception ex) {
218  String msg = "Could not return parse object: " + ex.getMessage();
219  MAPDLOGGER.error(msg, ex);
220  throw new InvalidParseRequest(-4, msg);
221  }
222  }
223 
224  TPlanResult result = new TPlanResult();
225  result.primary_accessed_objects = primaryAccessedObjects;
226  result.resolved_accessed_objects = resolvedAccessedObjects;
227  result.plan_result = jsonResult;
228  result.execution_time_ms = System.currentTimeMillis() - timer;
229 
230  return result;
231  }
void com.mapd.parser.server.CalciteServerHandler.setRuntimeExtensionFunctions ( List< TUserDefinedFunction >  udfs,
List< TUserDefinedTableFunction >  udtfs 
)
inline

Definition at line 338 of file CalciteServerHandler.java.

References com.mapd.parser.server.CalciteServerHandler.extSigs, Experimental.String, com.mapd.parser.server.CalciteServerHandler.toExtensionFunction(), com.mapd.parser.server.CalciteServerHandler.udfRTSigs, and com.mapd.parser.server.CalciteServerHandler.udfRTSigsJson.

339  {
340  // Clean up previously defined Runtime UDFs
341  if (udfRTSigs != null) {
342  for (String name : udfRTSigs.keySet()) extSigs.remove(name);
343  udfRTSigsJson = "";
344  udfRTSigs.clear();
345  } else {
346  udfRTSigs = new HashMap<String, ExtensionFunction>();
347  }
348 
349  for (TUserDefinedFunction udf : udfs) {
350  udfRTSigs.put(udf.name, toExtensionFunction(udf));
351  }
352 
353  for (TUserDefinedTableFunction udtf : udtfs) {
354  udfRTSigs.put(udtf.name, toExtensionFunction(udtf));
355  }
356 
357  // Avoid overwritting compiled and Loadtime UDFs:
358  for (String name : udfRTSigs.keySet()) {
359  if (extSigs.containsKey(name)) {
360  MAPDLOGGER.error("Extension function `" + name
361  + "` exists. Skipping runtime extenension function with the same name.");
362  udfRTSigs.remove(name);
363  }
364  }
365 
366  udfRTSigsJson = ExtensionFunctionSignatureParser.signaturesToJson(udfRTSigs);
367  // Expose RT UDFs to Calcite server:
368  extSigs.putAll(udfRTSigs);
369  }
Map< String, ExtensionFunction > udfRTSigs
static ExtensionFunction toExtensionFunction(TUserDefinedFunction udf)

+ Here is the call graph for this function:

void com.mapd.parser.server.CalciteServerHandler.setServer ( TServer  s)
inlinepackage
void com.mapd.parser.server.CalciteServerHandler.shutdown ( ) throws TException
inline

Definition at line 234 of file CalciteServerHandler.java.

234  {
235  // received request to shutdown
236  MAPDLOGGER.debug("Shutdown calcite java server");
237  server.stop();
238  }
static ExtensionFunction.ExtArgumentType com.mapd.parser.server.CalciteServerHandler.toExtArgumentType ( TExtArgumentType  type)
inlinestaticprivate

Definition at line 392 of file CalciteServerHandler.java.

References ArrayDouble, ArrayFloat, ArrayInt16, ArrayInt32, ArrayInt64, ArrayInt8, Bool, Cursor, Double, Float, Int16, Int32, Int64, Int8, PDouble, PFloat, PInt16, PInt32, PInt64, PInt8, run_benchmark_import.type, and Void.

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

393  {
394  switch (type) {
395  case Int8:
396  return ExtensionFunction.ExtArgumentType.Int8;
397  case Int16:
398  return ExtensionFunction.ExtArgumentType.Int16;
399  case Int32:
400  return ExtensionFunction.ExtArgumentType.Int32;
401  case Int64:
402  return ExtensionFunction.ExtArgumentType.Int64;
403  case Float:
404  return ExtensionFunction.ExtArgumentType.Float;
405  case Double:
407  case Void:
408  return ExtensionFunction.ExtArgumentType.Void;
409  case PInt8:
410  return ExtensionFunction.ExtArgumentType.PInt8;
411  case PInt16:
412  return ExtensionFunction.ExtArgumentType.PInt16;
413  case PInt32:
414  return ExtensionFunction.ExtArgumentType.PInt32;
415  case PInt64:
416  return ExtensionFunction.ExtArgumentType.PInt64;
417  case PFloat:
418  return ExtensionFunction.ExtArgumentType.PFloat;
419  case PDouble:
420  return ExtensionFunction.ExtArgumentType.PDouble;
421  case Bool:
422  return ExtensionFunction.ExtArgumentType.Bool;
423  case ArrayInt8:
424  return ExtensionFunction.ExtArgumentType.ArrayInt8;
425  case ArrayInt16:
426  return ExtensionFunction.ExtArgumentType.ArrayInt16;
427  case ArrayInt32:
428  return ExtensionFunction.ExtArgumentType.ArrayInt32;
429  case ArrayInt64:
430  return ExtensionFunction.ExtArgumentType.ArrayInt64;
431  case ArrayFloat:
432  return ExtensionFunction.ExtArgumentType.ArrayFloat;
433  case ArrayDouble:
434  return ExtensionFunction.ExtArgumentType.ArrayDouble;
435  case GeoPoint:
436  return ExtensionFunction.ExtArgumentType.GeoPoint;
437  case Cursor:
438  return ExtensionFunction.ExtArgumentType.Cursor;
439  default:
440  MAPDLOGGER.error("toExtArgumentType: unknown type " + type);
441  return null;
442  }
443  }

+ Here is the caller graph for this function:

static ExtensionFunction com.mapd.parser.server.CalciteServerHandler.toExtensionFunction ( TUserDefinedFunction  udf)
inlinestaticprivate

Definition at line 371 of file CalciteServerHandler.java.

References run_benchmark_import.args, and com.mapd.parser.server.CalciteServerHandler.toExtArgumentType().

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

371  {
372  List<ExtensionFunction.ExtArgumentType> args =
373  new ArrayList<ExtensionFunction.ExtArgumentType>();
374  for (TExtArgumentType atype : udf.argTypes) {
375  final ExtensionFunction.ExtArgumentType arg_type = toExtArgumentType(atype);
376  if (arg_type != ExtensionFunction.ExtArgumentType.Void) {
377  args.add(arg_type);
378  }
379  }
380  return new ExtensionFunction(args, toExtArgumentType(udf.retType), true);
381  }
static ExtensionFunction.ExtArgumentType toExtArgumentType(TExtArgumentType type)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static ExtensionFunction com.mapd.parser.server.CalciteServerHandler.toExtensionFunction ( TUserDefinedTableFunction  udtf)
inlinestaticprivate

Definition at line 383 of file CalciteServerHandler.java.

References run_benchmark_import.args, and com.mapd.parser.server.CalciteServerHandler.toExtArgumentType().

383  {
384  List<ExtensionFunction.ExtArgumentType> args =
385  new ArrayList<ExtensionFunction.ExtArgumentType>();
386  for (TExtArgumentType atype : udtf.sqlArgTypes) {
387  args.add(toExtArgumentType(atype));
388  }
389  return new ExtensionFunction(args, ExtensionFunction.ExtArgumentType.Void, false);
390  }
static ExtensionFunction.ExtArgumentType toExtArgumentType(TExtArgumentType type)

+ Here is the call graph for this function:

void com.mapd.parser.server.CalciteServerHandler.updateMetadata ( String  catalog,
String  table 
) throws TException
inline

Definition at line 260 of file CalciteServerHandler.java.

References com.mapd.parser.server.CalciteServerHandler.callCount, run_benchmark_import.parser, com.mapd.parser.server.CalciteServerHandler.parserPool, and Experimental.String.

260  {
261  MAPDLOGGER.debug("Received invalidation from server for " + catalog + " : " + table);
262  long timer = System.currentTimeMillis();
263  callCount++;
264  MapDParser parser;
265  try {
266  parser = (MapDParser) parserPool.borrowObject();
267  } catch (Exception ex) {
268  String msg = "Could not get Parse Item from pool: " + ex.getMessage();
269  MAPDLOGGER.error(msg, ex);
270  return;
271  }
272  CURRENT_PARSER.set(parser);
273  try {
274  parser.updateMetaData(catalog, table);
275  } finally {
276  CURRENT_PARSER.set(null);
277  try {
278  // put parser object back in pool for others to use
279  MAPDLOGGER.debug("Returning object to pool");
280  parserPool.returnObject(parser);
281  } catch (Exception ex) {
282  String msg = "Could not return parse object: " + ex.getMessage();
283  MAPDLOGGER.error(msg, ex);
284  }
285  }
286  }

Member Data Documentation

String com.mapd.parser.server.CalciteServerHandler.dataDir
private
Map<String, ExtensionFunction> com.mapd.parser.server.CalciteServerHandler.extSigs = null
private
final String com.mapd.parser.server.CalciteServerHandler.extSigsJson
private
final Logger com.mapd.parser.server.CalciteServerHandler.MAPDLOGGER = LoggerFactory.getLogger(CalciteServerHandler.class)
staticpackage

Definition at line 61 of file CalciteServerHandler.java.

final GenericObjectPool com.mapd.parser.server.CalciteServerHandler.parserPool
private
TServer com.mapd.parser.server.CalciteServerHandler.server
private
SockTransportProperties com.mapd.parser.server.CalciteServerHandler.skT
private

Definition at line 77 of file CalciteServerHandler.java.

Map<String, ExtensionFunction> com.mapd.parser.server.CalciteServerHandler.udfRTSigs = null
package
String com.mapd.parser.server.CalciteServerHandler.udfRTSigsJson = ""
private
final String com.mapd.parser.server.CalciteServerHandler.udfSigsJson
private

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