OmniSciDB  c07336695a
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

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 getRuntimeUserDefinedFunctionWhitelist ()
 
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 setRuntimeUserDefinedFunction (String udfString)
 

Package Functions

 CalciteServerHandler (int mapdPort, String dataDir, String extensionFunctionsAstFile, SockTransportProperties skT, String udfAstFile)
 
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 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 56 of file CalciteServerHandler.java.

Constructor & Destructor Documentation

◆ CalciteServerHandler()

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

Definition at line 79 of file CalciteServerHandler.java.

References com.mapd.parser.server.CalciteServerHandler.dataDir, com.mapd.parser.server.CalciteServerHandler.mapdPort, com.mapd.parser.server.ExtensionFunctionSignatureParser.parse(), and com.mapd.parser.server.ExtensionFunctionSignatureParser.signaturesToJson().

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

Member Function Documentation

◆ getCompletionHints()

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 283 of file CalciteServerHandler.java.

References com.mapd.calcite.parser.MapDParser.getCompletionHints(), com.mapd.parser.server.CalciteServerHandler.hintTypeToThrift(), run-benchmark-import.parser, run-benchmark-import.result, session, com.mapd.calcite.parser.MapDParser.setUser(), sql(), Experimental.String, and anonymous_namespace{DBObjectPrivilegesTest.cpp}.user.

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

◆ getExtensionFunctionWhitelist()

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

◆ getRuntimeUserDefinedFunctionWhitelist()

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

◆ getUserDefinedFunctionWhitelist()

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

◆ hintTypeToThrift()

static TCompletionHintType com.mapd.parser.server.CalciteServerHandler.hintTypeToThrift ( final SqlMonikerType  type)
inlinestaticprivate

Definition at line 360 of file CalciteServerHandler.java.

References TABLE.

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

360  {
361  switch (type) {
362  case COLUMN:
363  return TCompletionHintType.COLUMN;
364  case TABLE:
365  return TCompletionHintType.TABLE;
366  case VIEW:
367  return TCompletionHintType.VIEW;
368  case SCHEMA:
369  return TCompletionHintType.SCHEMA;
370  case CATALOG:
371  return TCompletionHintType.CATALOG;
372  case REPOSITORY:
373  return TCompletionHintType.REPOSITORY;
374  case FUNCTION:
375  return TCompletionHintType.FUNCTION;
376  case KEYWORD:
377  return TCompletionHintType.KEYWORD;
378  default:
379  return null;
380  }
381  }
+ Here is the caller graph for this function:

◆ ping()

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

Definition at line 119 of file CalciteServerHandler.java.

119  {
120  MAPDLOGGER.debug("Ping hit");
121  }

◆ process()

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 124 of file CalciteServerHandler.java.

References com.mapd.calcite.parser.MapDParser.captureIdentifiers(), org.apache.calcite.prepare.SqlIdentifierCapturer.deletes, com.mapd.calcite.parser.MapDParser.getRelAlgebra(), org.apache.calcite.prepare.SqlIdentifierCapturer.inserts, run-benchmark-import.parser, com.mapd.calcite.parser.MapDParser.resolveSelectIdentifiers(), run-benchmark-import.result, org.apache.calcite.prepare.SqlIdentifierCapturer.selects, session, com.mapd.calcite.parser.MapDParser.setUser(), Experimental.String, org.apache.calcite.prepare.SqlIdentifierCapturer.updates, and anonymous_namespace{DBObjectPrivilegesTest.cpp}.user.

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

◆ setRuntimeUserDefinedFunction()

void com.mapd.parser.server.CalciteServerHandler.setRuntimeUserDefinedFunction ( String  udfString)
inline

Definition at line 332 of file CalciteServerHandler.java.

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

332  {
333  // Clean up previously defined Runtime UDFs
334  if (udfRTSigs != null) {
335  for (String name : udfRTSigs.keySet()) extSigs.remove(name);
336  udfRTSigsJson = "";
337  }
338 
339  if (!udfString.isEmpty()) {
340  try {
341  udfRTSigs = ExtensionFunctionSignatureParser.parseFromString(udfString);
342  } catch (IOException ex) {
343  MAPDLOGGER.error(
344  "Could not parse extension function signatures: " + ex.getMessage());
345  }
346  // Avoid overwritting compiled and Loadtime UDFs:
347  for (String name : udfRTSigs.keySet()) {
348  if (extSigs.containsKey(name)) {
349  MAPDLOGGER.error("Extension function `" + name
350  + "` exists. Skipping Runtime UDF with the same name.");
351  udfRTSigs.remove(name);
352  }
353  }
354  udfRTSigsJson = ExtensionFunctionSignatureParser.signaturesToJson(udfRTSigs);
355  // Expose RT UDFs to Calcite server:
356  extSigs.putAll(udfRTSigs);
357  }
358  }
Map< String, ExtensionFunction > udfRTSigs
+ Here is the call graph for this function:

◆ setServer()

void com.mapd.parser.server.CalciteServerHandler.setServer ( TServer  s)
inlinepackage

Definition at line 249 of file CalciteServerHandler.java.

Referenced by com.mapd.parser.server.CalciteServerWrapper.startServer().

+ Here is the caller graph for this function:

◆ shutdown()

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

Definition at line 228 of file CalciteServerHandler.java.

228  {
229  // received request to shutdown
230  MAPDLOGGER.debug("Shutdown calcite java server");
231  server.stop();
232  }

◆ updateMetadata()

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

Definition at line 254 of file CalciteServerHandler.java.

References run-benchmark-import.parser, Experimental.String, and com.mapd.calcite.parser.MapDParser.updateMetaData().

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

Member Data Documentation

◆ callCount

volatile long com.mapd.parser.server.CalciteServerHandler.callCount
private

Definition at line 62 of file CalciteServerHandler.java.

◆ dataDir

String com.mapd.parser.server.CalciteServerHandler.dataDir
private

◆ extSigs

Map<String, ExtensionFunction> com.mapd.parser.server.CalciteServerHandler.extSigs = null
private

Definition at line 74 of file CalciteServerHandler.java.

◆ extSigsJson

final String com.mapd.parser.server.CalciteServerHandler.extSigsJson
private

◆ MAPDLOGGER

final Logger com.mapd.parser.server.CalciteServerHandler.MAPDLOGGER = LoggerFactory.getLogger(CalciteServerHandler.class)
staticpackage

Definition at line 57 of file CalciteServerHandler.java.

◆ mapdPort

final int com.mapd.parser.server.CalciteServerHandler.mapdPort
private

◆ parserPool

final GenericObjectPool com.mapd.parser.server.CalciteServerHandler.parserPool
private

Definition at line 64 of file CalciteServerHandler.java.

◆ server

TServer com.mapd.parser.server.CalciteServerHandler.server
private

Definition at line 58 of file CalciteServerHandler.java.

◆ skT

SockTransportProperties com.mapd.parser.server.CalciteServerHandler.skT
private

Definition at line 73 of file CalciteServerHandler.java.

◆ udfRTSigs

Map<String, ExtensionFunction> com.mapd.parser.server.CalciteServerHandler.udfRTSigs = null
package

Definition at line 71 of file CalciteServerHandler.java.

◆ udfRTSigsJson

String com.mapd.parser.server.CalciteServerHandler.udfRTSigsJson = ""
private

◆ udfSigsJson

final String com.mapd.parser.server.CalciteServerHandler.udfSigsJson
private

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