OmniSciDB  a5dc49c757
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
org.apache.calcite.prepare.HeavyDBSqlAdvisor Class Reference
+ Inheritance diagram for org.apache.calcite.prepare.HeavyDBSqlAdvisor:
+ Collaboration diagram for org.apache.calcite.prepare.HeavyDBSqlAdvisor:

Public Member Functions

 HeavyDBSqlAdvisor (HeavyDBSqlAdvisorValidator validator, SqlParser.Config parserConfig)
 
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

HeavyDBSqlAdvisorValidator permissionsAwareValidator
 

Detailed Description

Definition at line 28 of file HeavyDBSqlAdvisor.java.

Constructor & Destructor Documentation

org.apache.calcite.prepare.HeavyDBSqlAdvisor.HeavyDBSqlAdvisor ( HeavyDBSqlAdvisorValidator  validator,
SqlParser.Config  parserConfig 
)
inline

Definition at line 29 of file HeavyDBSqlAdvisor.java.

30  {
31  super(validator, parserConfig);
32  this.permissionsAwareValidator = validator;
33  }

Member Function Documentation

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

Definition at line 127 of file HeavyDBSqlAdvisor.java.

References org.apache.calcite.prepare.HeavyDBSqlAdvisor.permissionsAwareValidator, and org.apache.calcite.prepare.HeavyDBSqlAdvisorValidator.tableViolatesPermissions().

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

128  {
129  List<SqlMoniker> completionHintsWithPermissions = new ArrayList<>();
130  for (final SqlMoniker hint : completionHints) {
131  if (hint.getType() == SqlMonikerType.TABLE) {
132  // Database was stripped in previous step.
133  assert hint.getFullyQualifiedNames().size() == 1;
134  // Don't return tables which aren't visible per the permissions.
136  continue;
137  } else {
138  completionHintsWithPermissions.add(hint);
139  }
140  } else {
141  completionHintsWithPermissions.add(hint);
142  }
143  }
144  return completionHintsWithPermissions;
145  }
HeavyDBSqlAdvisorValidator permissionsAwareValidator

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Definition at line 36 of file HeavyDBSqlAdvisor.java.

References org.apache.calcite.prepare.HeavyDBSqlAdvisor.applyPermissionsToTableHints(), org.apache.calcite.prepare.HeavyDBSqlAdvisorValidator.hasViolatedTablePermissions(), org.apache.calcite.prepare.HeavyDBSqlAdvisor.permissionsAwareValidator, run_benchmark_import.result, and org.apache.calcite.prepare.HeavyDBSqlAdvisor.stripDatabaseFromTableHints().

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

+ Here is the call graph for this function:

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

Definition at line 112 of file HeavyDBSqlAdvisor.java.

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

113  {
114  List<SqlMoniker> strippedCompletionHints = new ArrayList<>();
115  for (final SqlMoniker hint : completionHints) {
116  if (hint.getType() == SqlMonikerType.TABLE
117  && hint.getFullyQualifiedNames().size() == 2) {
118  final String tableName = hint.getFullyQualifiedNames().get(1);
119  strippedCompletionHints.add(new SqlMonikerImpl(tableName, SqlMonikerType.TABLE));
120  } else {
121  strippedCompletionHints.add(hint);
122  }
123  }
124  return strippedCompletionHints;
125  }

+ Here is the caller graph for this function:

Member Data Documentation

HeavyDBSqlAdvisorValidator org.apache.calcite.prepare.HeavyDBSqlAdvisor.permissionsAwareValidator
private

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