OmniSciDB  04ee39c94c
org.apache.calcite.prepare.MapDSqlAdvisor Class Reference
+ Inheritance diagram for org.apache.calcite.prepare.MapDSqlAdvisor:
+ Collaboration diagram for org.apache.calcite.prepare.MapDSqlAdvisor:

Public Member Functions

 MapDSqlAdvisor (MapDSqlAdvisorValidator validator)
 
List< SqlMoniker > getCompletionHints (String sql, int cursor, String[] replaced)
 

Private Member Functions

List< SqlMoniker > applyPermissionsToTableHints (final List< SqlMoniker > completionHints)
 

Static Private Member Functions

static List< SqlMoniker > stripDatabaseFromTableHints (final List< SqlMoniker > completionHints)
 

Private Attributes

MapDSqlAdvisorValidator permissionsAwareValidator
 

Detailed Description

Definition at line 27 of file MapDSqlAdvisor.java.

Constructor & Destructor Documentation

◆ MapDSqlAdvisor()

org.apache.calcite.prepare.MapDSqlAdvisor.MapDSqlAdvisor ( MapDSqlAdvisorValidator  validator)
inline

Definition at line 28 of file MapDSqlAdvisor.java.

References org.apache.calcite.prepare.MapDSqlAdvisor.permissionsAwareValidator.

28  {
29  super(validator);
30  this.permissionsAwareValidator = validator;
31  }
MapDSqlAdvisorValidator permissionsAwareValidator

Member Function Documentation

◆ applyPermissionsToTableHints()

List<SqlMoniker> org.apache.calcite.prepare.MapDSqlAdvisor.applyPermissionsToTableHints ( final List< SqlMoniker >  completionHints)
inlineprivate

Definition at line 125 of file MapDSqlAdvisor.java.

References org.apache.calcite.prepare.MapDSqlAdvisor.permissionsAwareValidator, and org.apache.calcite.prepare.MapDSqlAdvisorValidator.tableViolatesPermissions().

Referenced by org.apache.calcite.prepare.MapDSqlAdvisor.getCompletionHints().

126  {
127  List<SqlMoniker> completionHintsWithPermissions = new ArrayList<>();
128  for (final SqlMoniker hint : completionHints) {
129  if (hint.getType() == SqlMonikerType.TABLE) {
130  // Database was stripped in previous step.
131  assert hint.getFullyQualifiedNames().size() == 1;
132  // Don't return tables which aren't visible per the permissions.
134  continue;
135  } else {
136  completionHintsWithPermissions.add(hint);
137  }
138  } else {
139  completionHintsWithPermissions.add(hint);
140  }
141  }
142  return completionHintsWithPermissions;
143  }
MapDSqlAdvisorValidator permissionsAwareValidator
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getCompletionHints()

List<SqlMoniker> org.apache.calcite.prepare.MapDSqlAdvisor.getCompletionHints ( String  sql,
int  cursor,
String []  replaced 
)
inline

Definition at line 34 of file MapDSqlAdvisor.java.

References org.apache.calcite.prepare.MapDSqlAdvisor.applyPermissionsToTableHints(), org.apache.calcite.prepare.MapDSqlAdvisorValidator.hasViolatedTablePermissions(), org.apache.calcite.prepare.MapDSqlAdvisor.permissionsAwareValidator, run-benchmark-import.result, Experimental.String, and org.apache.calcite.prepare.MapDSqlAdvisor.stripDatabaseFromTableHints().

34  {
35  // search backward starting from current position to find a "word"
36  int wordStart = cursor;
37  boolean quoted = false;
38  while (wordStart > 0 && Character.isJavaIdentifierPart(sql.charAt(wordStart - 1))) {
39  --wordStart;
40  }
41  if ((wordStart > 0) && (sql.charAt(wordStart - 1) == '"')) {
42  quoted = true;
43  --wordStart;
44  }
45 
46  if (wordStart < 0) {
47  return java.util.Collections.emptyList();
48  }
49 
50  // Search forwards to the end of the word we should remove. Eat up
51  // trailing double-quote, if any
52  int wordEnd = cursor;
53  while (wordEnd < sql.length()
54  && Character.isJavaIdentifierPart(sql.charAt(wordEnd))) {
55  ++wordEnd;
56  }
57  if (quoted && (wordEnd < sql.length()) && (sql.charAt(wordEnd) == '"')) {
58  ++wordEnd;
59  }
60 
61  // remove the partially composed identifier from the
62  // sql statement - otherwise we get a parser exception
63  String word = replaced[0] = sql.substring(wordStart, cursor);
64  if (wordStart < wordEnd) {
65  sql = sql.substring(0, wordStart) + sql.substring(wordEnd, sql.length());
66  }
67 
68  // The table hints come from validator with a database prefix,
69  // which is inconsistent with how tables are used in the query.
70  List<SqlMoniker> completionHints =
71  stripDatabaseFromTableHints(getCompletionHints0(sql, wordStart));
72 
74  return new ArrayList<>();
75  }
76 
77  completionHints = applyPermissionsToTableHints(completionHints);
78 
79  // If cursor was part of the way through a word, only include hints
80  // which start with that word in the result.
81  final List<SqlMoniker> result;
82  if (word.length() > 0) {
83  result = new java.util.ArrayList<SqlMoniker>();
84  if (quoted) {
85  // Quoted identifier. Case-sensitive match.
86  word = word.substring(1);
87  for (SqlMoniker hint : completionHints) {
88  String cname = hint.toString();
89  if (cname.startsWith(word)) {
90  result.add(hint);
91  }
92  }
93  } else {
94  // Regular identifier. Case-insensitive match.
95  for (SqlMoniker hint : completionHints) {
96  String cname = hint.toString();
97  if ((cname.length() >= word.length())
98  && cname.substring(0, word.length()).equalsIgnoreCase(word)) {
99  result.add(hint);
100  }
101  }
102  }
103  } else {
104  result = completionHints;
105  }
106 
107  return result;
108  }
static List< SqlMoniker > stripDatabaseFromTableHints(final List< SqlMoniker > completionHints)
auto sql(const std::string &sql_stmts)
List< SqlMoniker > applyPermissionsToTableHints(final List< SqlMoniker > completionHints)
MapDSqlAdvisorValidator permissionsAwareValidator
+ Here is the call graph for this function:

◆ stripDatabaseFromTableHints()

static List<SqlMoniker> org.apache.calcite.prepare.MapDSqlAdvisor.stripDatabaseFromTableHints ( final List< SqlMoniker >  completionHints)
inlinestaticprivate

Definition at line 110 of file MapDSqlAdvisor.java.

References Experimental.String.

Referenced by org.apache.calcite.prepare.MapDSqlAdvisor.getCompletionHints().

111  {
112  List<SqlMoniker> strippedCompletionHints = new ArrayList<>();
113  for (final SqlMoniker hint : completionHints) {
114  if (hint.getType() == SqlMonikerType.TABLE
115  && hint.getFullyQualifiedNames().size() == 2) {
116  final String tableName = hint.getFullyQualifiedNames().get(1);
117  strippedCompletionHints.add(new SqlMonikerImpl(tableName, SqlMonikerType.TABLE));
118  } else {
119  strippedCompletionHints.add(hint);
120  }
121  }
122  return strippedCompletionHints;
123  }
+ Here is the caller graph for this function:

Member Data Documentation

◆ permissionsAwareValidator


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