update new parser
This commit is contained in:
parent
6eda025e39
commit
93125a715a
@ -98,3 +98,4 @@ hive,impala语法解析文件来自[Hue](https://github.com/cloudera/hue)
|
||||
- 1.1.9 添加函数的中括号语法支持( split(nameList)[0] )
|
||||
- 1.2.0 添加 ts,添加测试
|
||||
- 2.0.0 添加flinksql语法检查
|
||||
- 3.0.0 拆分hive,impala,集成最新 `HUE` 方案
|
@ -165,7 +165,7 @@ module.exports = {
|
||||
|
||||
// A map from regular expressions to paths to transformers
|
||||
transform: {
|
||||
'^.+\\.tsx?$': 'ts-jest'
|
||||
'^.+\\.(t|j)sx?$': 'ts-jest'
|
||||
},
|
||||
|
||||
// An array of regexp pattern strings that are matched against all source file paths, matched files will skip transformation
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "dt-sql-parser",
|
||||
"version": "2.0.11",
|
||||
"version": "3.0.0",
|
||||
"description": "sql,hive,parser ",
|
||||
"keywords": [
|
||||
"hive",
|
||||
|
3578
src/core/parse/generic/genericAutocompleteParser.js
Normal file
3578
src/core/parse/generic/genericAutocompleteParser.js
Normal file
File diff suppressed because one or more lines are too long
3539
src/core/parse/generic/genericSyntaxParser.js
Normal file
3539
src/core/parse/generic/genericSyntaxParser.js
Normal file
File diff suppressed because one or more lines are too long
2221
src/core/parse/generic/sqlParseSupport.js
Normal file
2221
src/core/parse/generic/sqlParseSupport.js
Normal file
File diff suppressed because it is too large
Load Diff
5883
src/core/parse/hive/hiveAutocompleteParser.js
Normal file
5883
src/core/parse/hive/hiveAutocompleteParser.js
Normal file
File diff suppressed because one or more lines are too long
5812
src/core/parse/hive/hiveSyntaxParser.js
Normal file
5812
src/core/parse/hive/hiveSyntaxParser.js
Normal file
File diff suppressed because one or more lines are too long
2471
src/core/parse/hive/sqlParseSupport.js
Normal file
2471
src/core/parse/hive/sqlParseSupport.js
Normal file
File diff suppressed because it is too large
Load Diff
5382
src/core/parse/impala/impalaAutocompleteParser.js
Normal file
5382
src/core/parse/impala/impalaAutocompleteParser.js
Normal file
File diff suppressed because one or more lines are too long
5330
src/core/parse/impala/impalaSyntaxParser.js
Normal file
5330
src/core/parse/impala/impalaSyntaxParser.js
Normal file
File diff suppressed because one or more lines are too long
2545
src/core/parse/impala/sqlParseSupport.js
Normal file
2545
src/core/parse/impala/sqlParseSupport.js
Normal file
File diff suppressed because it is too large
Load Diff
4951
src/core/parse/sqlFunctions.js
Normal file
4951
src/core/parse/sqlFunctions.js
Normal file
File diff suppressed because it is too large
Load Diff
74
src/core/parse/sqlParserRepository.js
Normal file
74
src/core/parse/sqlParserRepository.js
Normal file
@ -0,0 +1,74 @@
|
||||
// Licensed to Cloudera, Inc. under one
|
||||
// or more contributor license agreements. See the NOTICE file
|
||||
// distributed with this work for additional information
|
||||
// regarding copyright ownership. Cloudera, Inc. licenses this file
|
||||
// to you under the Apache License, Version 2.0 (the
|
||||
// "License"); you may not use this file except in compliance
|
||||
// with the License. You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
/* eslint-disable */
|
||||
/**
|
||||
* AUTOCOMPLETE_MODULES and SYNTAX_MODULES are generated, do not edit manually, see tools/jison/generateParsers.js
|
||||
*/
|
||||
const AUTOCOMPLETE_MODULES = {
|
||||
calcite: require("calcite/calciteAutocompleteParser"),
|
||||
druid: require("druid/druidAutocompleteParser"),
|
||||
elasticsearch: require("elasticsearch/elasticsearchAutocompleteParser"),
|
||||
flink: require("flink/flinkAutocompleteParser"),
|
||||
generic: require("generic/genericAutocompleteParser"),
|
||||
hive: require("hive/hiveAutocompleteParser"),
|
||||
impala: require("impala/impalaAutocompleteParser"),
|
||||
ksql: require("ksql/ksqlAutocompleteParser"),
|
||||
phoenix: require("phoenix/phoenixAutocompleteParser"),
|
||||
presto: require("presto/prestoAutocompleteParser")
|
||||
};
|
||||
const SYNTAX_MODULES = {
|
||||
calcite: require("calcite/calciteSyntaxParser"),
|
||||
druid: require("druid/druidSyntaxParser"),
|
||||
elasticsearch: require("elasticsearch/elasticsearchSyntaxParser"),
|
||||
flink: require("flink/flinkSyntaxParser"),
|
||||
generic: require("generic/genericSyntaxParser"),
|
||||
hive: require("hive/hiveSyntaxParser"),
|
||||
impala: require("impala/impalaSyntaxParser"),
|
||||
ksql: require("ksql/ksqlSyntaxParser"),
|
||||
phoenix: require("phoenix/phoenixSyntaxParser"),
|
||||
presto: require("presto/prestoSyntaxParser")
|
||||
};
|
||||
/* eslint-enable */
|
||||
|
||||
class SqlParserRepository {
|
||||
constructor() {
|
||||
this.modulePromises = {};
|
||||
}
|
||||
|
||||
async getParser(sourceType, parserType) {
|
||||
if (!this.modulePromises[sourceType + parserType]) {
|
||||
const modules = parserType === 'Autocomplete' ? AUTOCOMPLETE_MODULES : SYNTAX_MODULES;
|
||||
this.modulePromises[sourceType + parserType] = new Promise((resolve, reject) => {
|
||||
const targetModule = modules[sourceType] || modules.generic;
|
||||
resolve(targetModule);
|
||||
});
|
||||
}
|
||||
return this.modulePromises[sourceType + parserType];
|
||||
}
|
||||
|
||||
async getAutocompleter(sourceType) {
|
||||
return this.getParser(sourceType, 'Autocomplete');
|
||||
}
|
||||
|
||||
async getSyntaxParser(sourceType) {
|
||||
return this.getParser(sourceType, 'Syntax');
|
||||
}
|
||||
}
|
||||
|
||||
const sqlParserRepository = new SqlParserRepository();
|
||||
|
||||
export default sqlParserRepository;
|
77
src/core/parse/stringDistance.js
Normal file
77
src/core/parse/stringDistance.js
Normal file
@ -0,0 +1,77 @@
|
||||
// Licensed to Cloudera, Inc. under one
|
||||
// or more contributor license agreements. See the NOTICE file
|
||||
// distributed with this work for additional information
|
||||
// regarding copyright ownership. Cloudera, Inc. licenses this file
|
||||
// to you under the Apache License, Version 2.0 (the
|
||||
// "License"); you may not use this file except in compliance
|
||||
// with the License. You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
/**
|
||||
* Calculates the Optimal String Alignment distance between two strings. Returns 0 when the strings are equal and the
|
||||
* distance when not, distances is less than or equal to the length of the longest string.
|
||||
*
|
||||
* @param strA
|
||||
* @param strB
|
||||
* @param [ignoreCase]
|
||||
* @returns {number} The similarity
|
||||
*/
|
||||
const stringDistance = function(strA, strB, ignoreCase) {
|
||||
if (ignoreCase) {
|
||||
strA = strA.toLowerCase();
|
||||
strB = strB.toLowerCase();
|
||||
}
|
||||
|
||||
// TODO: Consider other algorithms for performance
|
||||
const strALength = strA.length;
|
||||
const strBLength = strB.length;
|
||||
if (strALength === 0) {
|
||||
return strBLength;
|
||||
}
|
||||
if (strBLength === 0) {
|
||||
return strALength;
|
||||
}
|
||||
|
||||
const distances = new Array(strALength);
|
||||
|
||||
let cost, deletion, insertion, substitution, transposition;
|
||||
for (let i = 0; i <= strALength; i++) {
|
||||
distances[i] = new Array(strBLength);
|
||||
distances[i][0] = i;
|
||||
for (let j = 1; j <= strBLength; j++) {
|
||||
if (!i) {
|
||||
distances[0][j] = j;
|
||||
} else {
|
||||
cost = strA[i - 1] === strB[j - 1] ? 0 : 1;
|
||||
deletion = distances[i - 1][j] + 1;
|
||||
insertion = distances[i][j - 1] + 1;
|
||||
substitution = distances[i - 1][j - 1] + cost;
|
||||
if (deletion <= insertion && deletion <= substitution) {
|
||||
distances[i][j] = deletion;
|
||||
} else if (insertion <= deletion && insertion <= substitution) {
|
||||
distances[i][j] = insertion;
|
||||
} else {
|
||||
distances[i][j] = substitution;
|
||||
}
|
||||
|
||||
if (i > 1 && j > 1 && strA[i] === strB[j - 1] && strA[i - 1] === strB[j]) {
|
||||
transposition = distances[i - 2][j - 2] + cost;
|
||||
if (transposition < distances[i][j]) {
|
||||
distances[i][j] = transposition;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return distances[strALength][strBLength];
|
||||
};
|
||||
|
||||
export default stringDistance;
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
0
src/jison/autocomplete_footer.jison
Executable file → Normal file
0
src/jison/autocomplete_footer.jison
Executable file → Normal file
0
src/jison/autocomplete_header.jison
Executable file → Normal file
0
src/jison/autocomplete_header.jison
Executable file → Normal file
@ -1,10 +0,0 @@
|
||||
ColumnIdentifier
|
||||
UnsignedValueSpecification #各种非负数字和普通字符串常量bool值
|
||||
UnsignedLiteral #各种非负数字和普通字符串常量bool值
|
||||
ExactNumericLiteral #非负数字和小数
|
||||
ApproximateNumericLiteral #带有E的非负数字
|
||||
GeneralLiteral #普通字符串常量/bool值
|
||||
RegularIdentifier #常规标识符
|
||||
RegularOrBacktickedIdentifier #标识符
|
||||
NonReservedKeyword #非保留关键字
|
||||
ColumnIdentifier #标识符和各种对象数组写法
|
0
src/jison/globalSearchParser.jison
Executable file → Normal file
0
src/jison/globalSearchParser.jison
Executable file → Normal file
0
src/jison/solrFormulaParser.jison
Executable file → Normal file
0
src/jison/solrFormulaParser.jison
Executable file → Normal file
0
src/jison/solrQueryParser.jison
Executable file → Normal file
0
src/jison/solrQueryParser.jison
Executable file → Normal file
@ -1,36 +0,0 @@
|
||||
#!/bin/bash
|
||||
# Licensed to Cloudera, Inc. under one
|
||||
# or more contributor license agreements. See the NOTICE file
|
||||
# distributed with this work for additional information
|
||||
# regarding copyright ownership. Cloudera, Inc. licenses this file
|
||||
# to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance
|
||||
# with the License. You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
echo "Make sure you install jison first (npm install jison -g)"
|
||||
echo ""
|
||||
echo "Generating parser..."
|
||||
|
||||
pushd jison
|
||||
|
||||
# For quick version of just SELECT statements without value expressions
|
||||
# cat autocomplete_header.jison sql_main.jison autocomplete_footer.jison > sqlAutocompleteParser.jison
|
||||
cat autocomplete_header.jison sql_main.jison sql_valueExpression.jison sql_error.jison sql_alter.jison sql_analyze.jison sql_create.jison sql_drop.jison sql_grant.jison sql_insert.jison sql_load.jison sql_set.jison sql_show.jison sql_update.jison sql_use.jison autocomplete_footer.jison > sqlAutocompleteParser.jison
|
||||
|
||||
echo "Creating SQL autocomplete parser..."
|
||||
jison sqlAutocompleteParser.jison sql.jisonlex
|
||||
# grunt uglify:sqlAutocompleteParser
|
||||
cat sqlParseSupport.js sqlAutocompleteParser.js > ../core/sqlAutoCompleteParser.js
|
||||
rm sqlAutocompleteParser.jison
|
||||
rm sqlAutocompleteParser.js
|
||||
|
||||
popd
|
||||
echo "Done!"
|
@ -1,37 +0,0 @@
|
||||
#!/bin/bash
|
||||
# Licensed to Cloudera, Inc. under one
|
||||
# or more contributor license agreements. See the NOTICE file
|
||||
# distributed with this work for additional information
|
||||
# regarding copyright ownership. Cloudera, Inc. licenses this file
|
||||
# to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance
|
||||
# with the License. You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
echo "Make sure you install jison first (npm install jison -g)"
|
||||
echo ""
|
||||
echo "Generating parser..."
|
||||
|
||||
pushd jison
|
||||
# === Syntax parser ===
|
||||
cat syntax_header.jison sql_main.jison sql_valueExpression.jison sql_alter.jison sql_analyze.jison sql_create.jison sql_drop.jison sql_grant.jison sql_insert.jison sql_load.jison sql_set.jison sql_show.jison sql_update.jison sql_use.jison syntax_footer.jison > sqlSyntaxParser.jison
|
||||
|
||||
echo "Creating SQL syntax parser..."
|
||||
jison sqlSyntaxParser.jison sql.jisonlex
|
||||
# Workaround for a parser bug where it reports the location of the previous token on error (pull-request submitted for jison)
|
||||
# We're also adding a ruleId to the parser error composed of the last two stack ID's and used for suppressing errors in the UI
|
||||
sed -i '' 's/loc: yyloc,/loc: lexer.yylloc, ruleId: stack.slice(stack.length - 2, stack.length).join(''),/' sqlSyntaxParser.js
|
||||
# grunt uglify:sqlSyntaxParser
|
||||
cat sqlParseSupport.js sqlSyntaxParser.js > ../core/sqlSyntaxParser.js
|
||||
rm sqlSyntaxParser.jison
|
||||
rm sqlSyntaxParser.js
|
||||
|
||||
popd
|
||||
echo "Done!"
|
244
src/jison/sql.jisonlex
Executable file → Normal file
244
src/jison/sql.jisonlex
Executable file → Normal file
@ -62,8 +62,10 @@
|
||||
<hive>'REFERENCES' { return '<hive>REFERENCES'; }
|
||||
<hive>'REVOKE' { return '<hive>REVOKE'; }
|
||||
<hive>'ROLLUP' { return '<hive>ROLLUP'; }
|
||||
<hive>'SYNC' { return '<hive>SYNC'; }
|
||||
<hive>'TABLE' { return '<hive>TABLE'; }
|
||||
<hive>'TIMESTAMP' { return '<hive>TIMESTAMP'; }
|
||||
<hive>'UTC_TIMESTAMP' { return '<hive>UTC_TIMESTAMP'; }
|
||||
<hive>'USER' { return '<hive>USER'; }
|
||||
<hive>'USING' { return '<hive>USING'; }
|
||||
<hive>'VIEWS' { return '<hive>VIEWS'; }
|
||||
@ -125,6 +127,7 @@
|
||||
<hive>'INPUTFORMAT' { return '<hive>INPUTFORMAT'; }
|
||||
<hive>'ITEMS' { return '<hive>ITEMS'; }
|
||||
<hive>'JAR' { return '<hive>JAR'; }
|
||||
<hive>'JSONFILE' { return '<hive>JSONFILE'; }
|
||||
<hive>'KEY' { return '<hive>KEY'; }
|
||||
<hive>'KEYS' { return '<hive>KEYS'; }
|
||||
<hive>'LINES' { return '<hive>LINES'; }
|
||||
@ -193,6 +196,7 @@
|
||||
<hive>'TEXTFILE' { return '<hive>TEXTFILE'; }
|
||||
<hive>'TINYINT' { return '<hive>TINYINT'; }
|
||||
<hive>'TOUCH' { return '<hive>TOUCH'; }
|
||||
<hive>'TRANSACTIONAL' { return '<hive>TRANSACTIONAL'; }
|
||||
<hive>'TRANSACTIONS' { return '<hive>TRANSACTIONS'; }
|
||||
<hive>'UNARCHIVE' { return '<hive>UNARCHIVE'; }
|
||||
<hive>'UNIONTYPE' { return '<hive>UNIONTYPE'; }
|
||||
@ -201,6 +205,7 @@
|
||||
<hive>'WAIT' { return '<hive>WAIT'; }
|
||||
<hive>'WEEK' { return '<hive>WEEK'; }
|
||||
<hive>'WINDOW' { return '<hive>WINDOW'; }
|
||||
<hive>'WITH' { parser.determineCase(yytext); parser.addStatementTypeLocation('WITH', yylloc); return '<hive>WITH'; }
|
||||
<hive>'YEAR' { return '<hive>YEAR'; }
|
||||
|
||||
<hive>'.' { return '<hive>.'; }
|
||||
@ -210,68 +215,228 @@
|
||||
// Reserved Keywords
|
||||
<impala>'ADD' { return '<impala>ADD'; }
|
||||
<impala>'AGGREGATE' { return '<impala>AGGREGATE'; }
|
||||
<impala>'ALLOCATE' { return '<impala>ALLOCATE'; }
|
||||
<impala>'ANALYTIC' { return '<impala>ANALYTIC'; }
|
||||
<impala>'ANTI' { return '<impala>ANTI'; }
|
||||
<impala>'ANY' { return '<impala>ANY'; }
|
||||
<impala>'ARE' { return '<impala>ARE'; }
|
||||
<impala>'ARRAY_AGG' { return '<impala>ARRAY_AGG'; }
|
||||
<impala>'ARRAY_MAX_CARDINALITY' { return '<impala>ARRAY_MAX_CARDINALITY'; }
|
||||
<impala>'ASENSITIVE' { return '<impala>ASENSITIVE'; }
|
||||
<impala>'ASYMMETRIC' { return '<impala>ASYMMETRIC'; }
|
||||
<impala>'AT' { return '<impala>AT'; }
|
||||
<impala>'ATOMIC' { return '<impala>ATOMIC'; }
|
||||
<impala>'AUTHORIZATION' { return '<impala>AUTHORIZATION'; }
|
||||
<impala>'AVRO' { return '<impala>AVRO'; }
|
||||
<impala>'BEGIN_FRAME' { return '<impala>BEGIN_FRAME'; }
|
||||
<impala>'BEGIN_PARTITION' { return '<impala>BEGIN_PARTITION'; }
|
||||
<impala>'BLOB' { return '<impala>BLOB'; }
|
||||
<impala>'BLOCK_SIZE' { return '<impala>BLOCK_SIZE'; }
|
||||
<impala>'BOTH' { return '<impala>BOTH'; }
|
||||
<impala>'CACHED' { return '<impala>CACHED'; }
|
||||
<impala>'CALLED' { return '<impala>CALLED'; }
|
||||
<impala>'CARDINALITY' { return '<impala>CARDINALITY'; }
|
||||
<impala>'CASCADE' { return '<impala>CASCADE'; }
|
||||
<impala>'CASCADED' { return '<impala>CASCADED'; }
|
||||
<impala>'CHANGE' { return '<impala>CHANGE'; }
|
||||
<impala>'CHARACTER' { return '<impala>CHARACTER'; }
|
||||
<impala>'CLOB' { return '<impala>CLOB'; }
|
||||
<impala>'CLOSE_FN' { return '<impala>CLOSE_FN'; }
|
||||
<impala>'COLLATE' { return '<impala>COLLATE'; }
|
||||
<impala>'COLLECT' { return '<impala>COLLECT'; }
|
||||
<impala>'COLUMN' { return '<impala>COLUMN'; }
|
||||
<impala>'COLUMNS' { return '<impala>COLUMNS'; }
|
||||
<impala>'COMMENT' { parser.determineCase(yytext); return '<impala>COMMENT'; }
|
||||
<impala>'COMMIT' { return '<impala>COMMIT'; }
|
||||
<impala>'COMPRESSION' { return '<impala>COMPRESSION'; }
|
||||
<impala>'COMPUTE' { parser.determineCase(yytext); return '<impala>COMPUTE'; }
|
||||
<impala>'CONDITION' { return '<impala>CONDITION'; }
|
||||
<impala>'CONNECT' { return '<impala>CONNECT'; }
|
||||
<impala>'CONSTRAINT' { return '<impala>CONSTRAINT'; }
|
||||
<impala>'CONTAINS' { return '<impala>CONTAINS'; }
|
||||
<impala>'CONVERT' { return '<impala>CONVERT'; }
|
||||
<impala>'COPY' { return '<impala>COPY'; }
|
||||
<impala>'CORR' { return '<impala>CORR'; }
|
||||
<impala>'CORRESPONDING' { return '<impala>CORRESPONDING'; }
|
||||
<impala>'COVAR_POP' { return '<impala>COVAR_POP'; }
|
||||
<impala>'COVAR_SAMP' { return '<impala>COVAR_SAMP'; }
|
||||
<impala>'CREATE' { parser.determineCase(yytext); parser.addStatementTypeLocation('CREATE', yylloc, yy.lexer.upcomingInput()); return '<impala>CREATE'; }
|
||||
<impala>'CUBE' { return '<impala>CUBE'; }
|
||||
<impala>'CURRENT' { return '<impala>CURRENT'; }
|
||||
<impala>'CURRENT_DATE' { return '<impala>CURRENT_DATE'; }
|
||||
<impala>'CURRENT_DEFAULT_TRANSFORM_GROUP' { return '<impala>CURRENT_DEFAULT_TRANSFORM_GROUP'; }
|
||||
<impala>'CURRENT_PATH' { return '<impala>CURRENT_PATH'; }
|
||||
<impala>'CURRENT_ROLE' { return '<impala>CURRENT_ROLE'; }
|
||||
<impala>'CURRENT_ROW' { return '<impala>CURRENT_ROW'; }
|
||||
<impala>'CURRENT_SCHEMA' { return '<impala>CURRENT_SCHEMA'; }
|
||||
<impala>'CURRENT_TIME' { return '<impala>CURRENT_TIME'; }
|
||||
<impala>'CURRENT_TRANSFORM_GROUP_FOR_TYPE' { return '<impala>CURRENT_TRANSFORM_GROUP_FOR_TYPE'; }
|
||||
<impala>'CURSOR' { return '<impala>CURSOR'; }
|
||||
<impala>'CYCLE' { return '<impala>CYCLE'; }
|
||||
<impala>'DATA' { return '<impala>DATA'; }
|
||||
<impala>'DATABASES' { return '<impala>DATABASES'; }
|
||||
<impala>'DEALLOCATE' { return '<impala>DEALLOCATE'; }
|
||||
<impala>'DEC' { return '<impala>DEC'; }
|
||||
<impala>'DECFLOAT' { return '<impala>DECFLOAT'; }
|
||||
<impala>'DECLARE' { return '<impala>DECLARE'; }
|
||||
<impala>'DEFINE' { return '<impala>DEFINE'; }
|
||||
<impala>'DELETE' { return '<impala>DELETE'; }
|
||||
<impala>'DELIMITED' { return '<impala>DELIMITED'; }
|
||||
<impala>'DEREF' { return '<impala>DEREF'; }
|
||||
<impala>'DESCRIBE' { parser.determineCase(yytext); parser.addStatementTypeLocation('DESCRIBE', yylloc); return '<impala>DESCRIBE'; }
|
||||
<impala>'DETERMINISTIC' { return '<impala>DETERMINISTIC'; }
|
||||
<impala>'DISCONNECT' { return '<impala>DISCONNECT'; }
|
||||
<impala>'DYNAMIC' { return '<impala>DYNAMIC'; }
|
||||
<impala>'EACH' { return '<impala>EACH'; }
|
||||
<impala>'ELEMENT' { return '<impala>ELEMENT'; }
|
||||
<impala>'EMPTY' { return '<impala>EMPTY'; }
|
||||
<impala>'ENCODING' { return '<impala>ENCODING'; }
|
||||
<impala>'END_FRAME' { return '<impala>END_FRAME'; }
|
||||
<impala>'END_PARTITION' { return '<impala>END_PARTITION'; }
|
||||
<impala>'EQUALS' { return '<impala>EQUALS'; }
|
||||
<impala>'ESCAPE' { return '<impala>ESCAPE'; }
|
||||
<impala>'ESCAPED' { return '<impala>ESCAPED'; }
|
||||
<impala>'EVERY' { return '<impala>EVERY'; }
|
||||
<impala>'EXCEPT' { return '<impala>EXCEPT'; }
|
||||
<impala>'EXEC' { return '<impala>EXEC'; }
|
||||
<impala>'EXECUTE' { return '<impala>EXECUTE'; }
|
||||
<impala>'EXPLAIN' { parser.determineCase(yytext); parser.addStatementTypeLocation('EXPLAIN', yylloc); return '<impala>EXPLAIN'; }
|
||||
<impala>'EXTERNAL' { return '<impala>EXTERNAL'; }
|
||||
<impala>'EXTENDED' { return '<impala>EXTENDED'; }
|
||||
<impala>'EXTERNAL' { return '<impala>EXTERNAL'; }
|
||||
<impala>'FETCH' { return '<impala>FETCH'; }
|
||||
<impala>'FIELDS' { return '<impala>FIELDS'; }
|
||||
<impala>'FILEFORMAT' { return '<impala>FILEFORMAT'; }
|
||||
<impala>'FILES' { return '<impala>FILES'; }
|
||||
<impala>'FILTER' { return '<impala>FILTER'; }
|
||||
<impala>'FINALIZE_FN' { return '<impala>FINALIZE_FN'; }
|
||||
<impala>'FIRST' { return '<impala>FIRST'; }
|
||||
<impala>'FOR' { return '<impala>FOR'; }
|
||||
<impala>'FOREIGN' { return '<impala>FOREIGN'; }
|
||||
<impala>'FORMAT' { return '<impala>FORMAT'; }
|
||||
<impala>'FORMATTED' { return '<impala>FORMATTED'; }
|
||||
<impala>'FRAME_ROW' { return '<impala>FRAME_ROW'; }
|
||||
<impala>'FREE' { return '<impala>FREE'; }
|
||||
<impala>'FUNCTION' { return '<impala>FUNCTION'; }
|
||||
<impala>'FUNCTIONS' { return '<impala>FUNCTIONS'; }
|
||||
<impala>'FUSION' { return '<impala>FUSION'; }
|
||||
<impala>'GET' { return '<impala>GET'; }
|
||||
<impala>'GLOBAL' { return '<impala>GLOBAL'; }
|
||||
<impala>'GRANT' { parser.determineCase(yytext); parser.addStatementTypeLocation('GRANT', yylloc); return '<impala>GRANT'; }
|
||||
<impala>'GROUP' { return '<impala>GROUP'; }
|
||||
<impala>'GROUPING' { return '<impala>GROUPING'; }
|
||||
<impala>'GROUPS' { return '<impala>GROUPS'; }
|
||||
<impala>'HASH' { return '<impala>HASH'; }
|
||||
<impala>'HOLD' { return '<impala>HOLD'; }
|
||||
<impala>'IGNORE' { return '<impala>IGNORE'; }
|
||||
<impala>'ILIKE' { return '<impala>ILIKE'; }
|
||||
<impala>'INCREMENTAL' { return '<impala>INCREMENTAL'; }
|
||||
<impala>'INSERT' { parser.determineCase(yytext); parser.addStatementTypeLocation('INSERT', yylloc); return '<impala>INSERT'; }
|
||||
<impala>'INTERVAL' { return '<impala>INTERVAL'; }
|
||||
<impala>'INTERMEDIATE' { return '<impala>INTERMEDIATE'; }
|
||||
<impala>'INDICATOR' { return '<impala>INDICATOR'; }
|
||||
<impala>'INIT_FN' { return '<impala>INIT_FN'; }
|
||||
<impala>'INVALIDATE' { parser.determineCase(yytext); parser.addStatementTypeLocation('INVALIDATE', yylloc, yy.lexer.upcomingInput()); return '<impala>INVALIDATE'; }
|
||||
<impala>'INITIAL' { return '<impala>INITIAL'; }
|
||||
<impala>'INOUT' { return '<impala>INOUT'; }
|
||||
<impala>'INPATH' { this.begin('hdfs'); return '<impala>INPATH'; }
|
||||
<impala>'INSENSITIVE' { return '<impala>INSENSITIVE'; }
|
||||
<impala>'INSERT' { parser.determineCase(yytext); parser.addStatementTypeLocation('INSERT', yylloc); return '<impala>INSERT'; }
|
||||
<impala>'INTERMEDIATE' { return '<impala>INTERMEDIATE'; }
|
||||
<impala>'INTERSECT' { return '<impala>INTERSECT'; }
|
||||
<impala>'INTERSECTION' { return '<impala>INTERSECTION'; }
|
||||
<impala>'INTERVAL' { return '<impala>INTERVAL'; }
|
||||
<impala>'INVALIDATE' { parser.determineCase(yytext); parser.addStatementTypeLocation('INVALIDATE', yylloc, yy.lexer.upcomingInput()); return '<impala>INVALIDATE'; }
|
||||
<impala>'IREGEXP' { return '<impala>IREGEXP'; }
|
||||
<impala>'JSON_ARRAY' { return '<impala>JSON_ARRAY'; }
|
||||
<impala>'JSON_ARRAYAGG' { return '<impala>JSON_ARRAYAGG'; }
|
||||
<impala>'JSON_EXISTS' { return '<impala>JSON_EXISTS'; }
|
||||
<impala>'JSON_OBJECT' { return '<impala>JSON_OBJECT'; }
|
||||
<impala>'JSON_OBJECTAGG' { return '<impala>JSON_OBJECTAGG'; }
|
||||
<impala>'JSON_QUERY' { return '<impala>JSON_QUERY'; }
|
||||
<impala>'JSON_TABLE' { return '<impala>JSON_TABLE'; }
|
||||
<impala>'JSON_TABLE_PRIMITIVE' { return '<impala>JSON_TABLE_PRIMITIVE'; }
|
||||
<impala>'JSON_VALUE' { return '<impala>JSON_VALUE'; }
|
||||
<impala>'KEY' { return '<impala>KEY'; }
|
||||
<impala>'KUDU' { return '<impala>KUDU'; }
|
||||
<impala>'LARGE' { return '<impala>LARGE'; }
|
||||
<impala>'LAST' { return '<impala>LAST'; }
|
||||
<impala>'LATERAL' { return '<impala>LATERAL'; }
|
||||
<impala>'LEADING' { return '<impala>LEADING'; }
|
||||
<impala>LIKE\s+PARQUET { this.begin('hdfs'); return '<impala>LIKE_PARQUET'; }
|
||||
<impala>'LIKE_REGEX' { return '<impala>LIKE_REGEX'; }
|
||||
<impala>'LIMIT' { return '<impala>LIMIT'; }
|
||||
<impala>'LINES' { return '<impala>LINES'; }
|
||||
<impala>'LISTAGG' { return '<impala>LISTAGG'; }
|
||||
<impala>'LOAD' { parser.determineCase(yytext); parser.addStatementTypeLocation('LOAD', yylloc, yy.lexer.upcomingInput()); return '<impala>LOAD'; }
|
||||
<impala>'LOCAL' { return '<impala>LOCAL'; }
|
||||
<impala>'LOCALTIMESTAMP' { return '<impala>LOCALTIMESTAMP'; }
|
||||
<impala>'LOCATION' { this.begin('hdfs'); return '<impala>LOCATION'; }
|
||||
<impala>'MATCH' { return '<impala>MATCH'; }
|
||||
<impala>'MATCH_NUMBER' { return '<impala>MATCH_NUMBER'; }
|
||||
<impala>'MATCH_RECOGNIZE' { return '<impala>MATCH_RECOGNIZE'; }
|
||||
<impala>'MATCHES' { return '<impala>MATCHES'; }
|
||||
<impala>'MERGE' { return '<impala>MERGE'; }
|
||||
<impala>'MERGE_FN' { return '<impala>MERGE_FN'; }
|
||||
<impala>'METADATA' { return '<impala>METADATA'; }
|
||||
<impala>'METHOD' { return '<impala>METHOD'; }
|
||||
<impala>'MODIFIES' { return '<impala>MODIFIES'; }
|
||||
<impala>'MULTISET' { return '<impala>MULTISET'; }
|
||||
<impala>'NATIONAL' { return '<impala>NATIONAL'; }
|
||||
<impala>'NATURAL' { return '<impala>NATURAL'; }
|
||||
<impala>'NCHAR' { return '<impala>NCHAR'; }
|
||||
<impala>'NCLOB' { return '<impala>NCLOB'; }
|
||||
<impala>'NO' { return '<impala>NO'; }
|
||||
<impala>'NONE' { return '<impala>NONE'; }
|
||||
<impala>'NORMALIZE' { return '<impala>NORMALIZE'; }
|
||||
<impala>'NTH_VALUE' { return '<impala>NTH_VALUE'; }
|
||||
<impala>'NULLS' { return '<impala>NULLS'; }
|
||||
<impala>'NUMERIC' { return '<impala>NUMERIC'; }
|
||||
<impala>'OCCURRENCES_REGEX' { return '<impala>OCCURRENCES_REGEX'; }
|
||||
<impala>'OCTET_LENGTH' { return '<impala>OCTET_LENGTH'; }
|
||||
<impala>'OF' { return '<impala>OF'; }
|
||||
<impala>'OFFSET' { return '<impala>OFFSET'; }
|
||||
<impala>'OMIT' { return '<impala>OMIT'; }
|
||||
<impala>'ONE' { return '<impala>ONE'; }
|
||||
<impala>'ONLY' { return '<impala>ONLY'; }
|
||||
<impala>'ORC' { return '<impala>ORC'; }
|
||||
<impala>'OUT' { return '<impala>OUT'; }
|
||||
<impala>'OVER' { return '<impala>OVER'; }
|
||||
<impala>'OVERLAPS' { return '<impala>OVERLAPS'; }
|
||||
<impala>'OVERLAY' { return '<impala>OVERLAY'; }
|
||||
<impala>'OVERWRITE' { return '<impala>OVERWRITE'; }
|
||||
<impala>'PARQUET' { return '<impala>PARQUET'; }
|
||||
<impala>PARTITION\s+VALUE\s { return '<impala>PARTITION_VALUE'; }
|
||||
<impala>'PARTITIONED' { return '<impala>PARTITIONED'; }
|
||||
<impala>'PARTITIONS' { return '<impala>PARTITIONS'; }
|
||||
<impala>'PATTERN' { return '<impala>PATTERN'; }
|
||||
<impala>'PER' { return '<impala>PER'; }
|
||||
<impala>'PERCENT' { return '<impala>PERCENT'; }
|
||||
<impala>'PERCENTILE_CONT' { return '<impala>PERCENTILE_CONT'; }
|
||||
<impala>'PERCENTILE_DISC' { return '<impala>PERCENTILE_DISC'; }
|
||||
<impala>'PORTION' { return '<impala>PORTION'; }
|
||||
<impala>'POSITION' { return '<impala>POSITION'; }
|
||||
<impala>'POSITION_REGEX' { return '<impala>POSITION_REGEX'; }
|
||||
<impala>'PRECEDES' { return '<impala>PRECEDES'; }
|
||||
<impala>'PREPARE' { return '<impala>PREPARE'; }
|
||||
<impala>'PREPARE_FN' { return '<impala>PREPARE_FN'; }
|
||||
<impala>'PRIMARY' { return '<impala>PRIMARY'; }
|
||||
<impala>'RCFILE' { return '<impala>RCFILE'; }
|
||||
<impala>'PROCEDURE' { return '<impala>PROCEDURE'; }
|
||||
<impala>'PTF' { return '<impala>PTF'; }
|
||||
<impala>'RANGE' { return '<impala>RANGE'; }
|
||||
<impala>'RCFILE' { return '<impala>RCFILE'; }
|
||||
<impala>'READS' { return '<impala>READS'; }
|
||||
<impala>'REAL' { return '<impala>REAL'; }
|
||||
<impala>'RECOVER' { return '<impala>RECOVER'; }
|
||||
<impala>'RECURSIVE' { return '<impala>RECURSIVE'; }
|
||||
<impala>'REF' { return '<impala>REF'; }
|
||||
<impala>'REFERENCES' { return '<impala>REFERENCES'; }
|
||||
<impala>'REFERENCING' { return '<impala>REFERENCING'; }
|
||||
<impala>'REFRESH' { parser.determineCase(yytext); parser.addStatementTypeLocation('REFRESH', yylloc); return '<impala>REFRESH'; }
|
||||
<impala>'REGR_AVGX' { return '<impala>REGR_AVGX'; }
|
||||
<impala>'REGR_AVGY' { return '<impala>REGR_AVGY'; }
|
||||
<impala>'REGR_COUNT' { return '<impala>REGR_COUNT'; }
|
||||
<impala>'REGR_INTERCEPT' { return '<impala>REGR_INTERCEPT'; }
|
||||
<impala>'REGR_R2REGR_SLOPE' { return '<impala>REGR_R2REGR_SLOPE'; }
|
||||
<impala>'REGR_SXX' { return '<impala>REGR_SXX'; }
|
||||
<impala>'REGR_SXY' { return '<impala>REGR_SXY'; }
|
||||
<impala>'REGR_SYY' { return '<impala>REGR_SYY'; }
|
||||
<impala>'RELEASE' { return '<impala>RELEASE'; }
|
||||
<impala>'RENAME' { return '<impala>RENAME'; }
|
||||
<impala>'REPEATABLE' { return '<impala>REPEATABLE'; }
|
||||
<impala>'REPLACE' { return '<impala>REPLACE'; }
|
||||
@ -279,45 +444,85 @@
|
||||
<impala>'RESTRICT' { return '<impala>RESTRICT'; }
|
||||
<impala>'RETURNS' { return '<impala>RETURNS'; }
|
||||
<impala>'REVOKE' { parser.determineCase(yytext); parser.addStatementTypeLocation('REVOKE', yylloc); return '<impala>REVOKE'; }
|
||||
<impala>'ROLE' { return '<impala>ROLE'; }
|
||||
<impala>'ROLES' { return '<impala>ROLES'; }
|
||||
<impala>'ROLLBACK' { return '<impala>ROLLBACK'; }
|
||||
<impala>'ROLLUP' { return '<impala>ROLLUP'; }
|
||||
<impala>'RUNNING' { return '<impala>RUNNING'; }
|
||||
<impala>'SAVEPOINT' { return '<impala>SAVEPOINT'; }
|
||||
<impala>'SCHEMAS' { return '<impala>SCHEMAS'; }
|
||||
<impala>'SCOPE' { return '<impala>SCOPE'; }
|
||||
<impala>'SCROLL' { return '<impala>SCROLL'; }
|
||||
<impala>'SEARCH' { return '<impala>SEARCH'; }
|
||||
<impala>'SEEK' { return '<impala>SEEK'; }
|
||||
<impala>'SENSITIVE' { return '<impala>SENSITIVE'; }
|
||||
<impala>'SEQUENCEFILE' { return '<impala>SEQUENCEFILE'; }
|
||||
<impala>'SERDEPROPERTIES' { return '<impala>SERDEPROPERTIES'; }
|
||||
<impala>'SCHEMAS' { return '<impala>SCHEMAS'; }
|
||||
<impala>'SERIALIZE_FN' { return '<impala>SERIALIZE_FN'; }
|
||||
<impala>'SERVER' { return '<impala>SERVER'; }
|
||||
<impala>'SIMILAR' { return '<impala>SIMILAR'; }
|
||||
<impala>'SKIP' { return '<impala>SKIP'; }
|
||||
<impala>'SOME' { return '<impala>SOME'; }
|
||||
<impala>'SORT' { return '<impala>SORT'; }
|
||||
<impala>'SPECIFIC' { return '<impala>SPECIFIC'; }
|
||||
<impala>'SPECIFICTYPE' { return '<impala>SPECIFICTYPE'; }
|
||||
<impala>'SQLEXCEPTION' { return '<impala>SQLEXCEPTION'; }
|
||||
<impala>'SQLSTATE' { return '<impala>SQLSTATE'; }
|
||||
<impala>'SQLWARNING' { return '<impala>SQLWARNING'; }
|
||||
<impala>'STATIC' { return '<impala>STATIC'; }
|
||||
<impala>'STATS' { return '<impala>STATS'; }
|
||||
<impala>'STORED' { return '<impala>STORED'; }
|
||||
<impala>'STRAIGHT_JOIN' { return '<impala>STRAIGHT_JOIN'; }
|
||||
<impala>'SUBMULTISET' { return '<impala>SUBMULTISET'; }
|
||||
<impala>'SUBSET' { return '<impala>SUBSET'; }
|
||||
<impala>'SUBSTRING_REGEX' { return '<impala>SUBSTRING_REGEX'; }
|
||||
<impala>'SUCCEEDS' { return '<impala>SUCCEEDS'; }
|
||||
<impala>'SYMBOL' { return '<impala>SYMBOL'; }
|
||||
<impala>'SYMMETRIC' { return '<impala>SYMMETRIC'; }
|
||||
<impala>'SYSTEM_TIME' { return '<impala>SYSTEM_TIME'; }
|
||||
<impala>'SYSTEM_USER' { return '<impala>SYSTEM_USER'; }
|
||||
<impala>'TABLE' { return '<impala>TABLE'; }
|
||||
<impala>'TABLES' { return '<impala>TABLES'; }
|
||||
<impala>'TABLESAMPLE' { return '<impala>TABLESAMPLE'; }
|
||||
<impala>'TBLPROPERTIES' { return '<impala>TBLPROPERTIES'; }
|
||||
<impala>'TERMINATED' { return '<impala>TERMINATED'; }
|
||||
<impala>'TEXTFILE' { return '<impala>TEXTFILE'; }
|
||||
<impala>'TIMEZONE_HOUR' { return '<impala>TIMEZONE_HOUR'; }
|
||||
<impala>'TIMEZONE_MINUTE' { return '<impala>TIMEZONE_MINUTE'; }
|
||||
<impala>'TRAILING' { return '<impala>TRAILING'; }
|
||||
<impala>'TRANSLATE_REGEX' { return '<impala>TRANSLATE_REGEX'; }
|
||||
<impala>'TRANSLATION' { return '<impala>TRANSLATION'; }
|
||||
<impala>'TREAT' { return '<impala>TREAT'; }
|
||||
<impala>'TRIGGER' { return '<impala>TRIGGER'; }
|
||||
<impala>'TRIM_ARRAY' { return '<impala>TRIM_ARRAY'; }
|
||||
<impala>'UESCAPE' { return '<impala>UESCAPE'; }
|
||||
<impala>'UNCACHED' { return '<impala>UNCACHED'; }
|
||||
<impala>'UNIQUE' { return '<impala>UNIQUE'; }
|
||||
<impala>'UNKNOWN' { return '<impala>UNKNOWN'; }
|
||||
<impala>'UNNEST' { return '<impala>UNNEST'; }
|
||||
<impala>'UPDATE_FN' { return '<impala>UPDATE_FN'; }
|
||||
<impala>'UPSERT' { parser.determineCase(yytext); parser.addStatementTypeLocation('UPSERT', yylloc); return '<impala>UPSERT'; }
|
||||
<impala>'URI' { return '<impala>URI'; }
|
||||
<impala>'USER' { return '<impala>USER'; }
|
||||
<impala>'USING' { return '<impala>USING'; }
|
||||
<impala>PARTITION\s+VALUE\s { return '<impala>PARTITION_VALUE'; }
|
||||
<impala>'VALUE_OF' { return '<impala>VALUE_OF'; }
|
||||
<impala>'VARBINARY' { return '<impala>VARBINARY'; }
|
||||
<impala>'VARCHAR' { return '<impala>VARCHAR'; }
|
||||
<impala>'VARYING' { return '<impala>VARYING'; }
|
||||
<impala>'VERSIONING' { return '<impala>VERSIONING'; }
|
||||
<impala>'WHENEVER' { return '<impala>WHENEVER'; }
|
||||
<impala>'WIDTH_BUCKET' { return '<impala>WIDTH_BUCKET'; }
|
||||
<impala>'WINDOW' { return '<impala>WINDOW'; }
|
||||
<impala>'WITH' { parser.determineCase(yytext); parser.addStatementTypeLocation('WITH', yylloc); return '<impala>WITH'; }
|
||||
<impala>'WITHIN' { return '<impala>WITHIN'; }
|
||||
<impala>'WITHOUT' { return '<impala>WITHOUT'; }
|
||||
|
||||
// Non-reserved Keywords
|
||||
<impala>'ANALYTIC' { return '<impala>ANALYTIC'; }
|
||||
<impala>'ANTI' { return '<impala>ANTI'; }
|
||||
<impala>'ARRAY' { return 'ARRAY'; }
|
||||
<impala>'BLOCK_SIZE' { return '<impala>BLOCK_SIZE'; }
|
||||
<impala>'COMPRESSION' { return '<impala>COMPRESSION'; }
|
||||
<impala>'CURRENT' { return '<impala>CURRENT'; }
|
||||
<impala>'DEFAULT' { return '<impala>DEFAULT'; }
|
||||
<impala>'ENCODING' { return '<impala>ENCODING'; }
|
||||
<impala>'GRANT' { return '<impala>GRANT'; }
|
||||
<impala>'MAP' { return 'MAP'; }
|
||||
<impala>'RECOVER' { return '<impala>RECOVER'; }
|
||||
<impala>'ROLE' { return '<impala>ROLE'; }
|
||||
<impala>'ROLES' { return '<impala>ROLES'; }
|
||||
<impala>'OWNER' { return '<impala>OWNER'; }
|
||||
<impala>'STRUCT' { return 'STRUCT'; }
|
||||
<impala>'UNKNOWN' { return '<impala>UNKNOWN'; }
|
||||
<impala>\[BROADCAST\] { return '<impala>BROADCAST'; }
|
||||
<impala>\[NOSHUFFLE\] { return '<impala>NOSHUFFLE'; }
|
||||
<impala>\[SHUFFLE\] { return '<impala>SHUFFLE'; }
|
||||
@ -330,7 +535,6 @@
|
||||
<between>'AND' { this.popState(); return 'BETWEEN_AND'; }
|
||||
|
||||
// Reserved Keywords
|
||||
'LIFECYCLE' { return 'LIFECYCLE'; }
|
||||
'ALL' { return 'ALL'; }
|
||||
'ALTER' { parser.determineCase(yytext); parser.addStatementTypeLocation('ALTER', yylloc, yy.lexer.upcomingInput()); return 'ALTER'; }
|
||||
'AND' { return 'AND'; }
|
||||
|
4
src/jison/license.txt → src/jison/sql/calcite/autocomplete_footer.jison
Executable file → Normal file
4
src/jison/license.txt → src/jison/sql/calcite/autocomplete_footer.jison
Executable file → Normal file
@ -13,3 +13,7 @@
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
%%
|
||||
|
||||
SqlParseSupport.initSqlParser(parser);
|
29
src/jison/sql/calcite/autocomplete_header.jison
Normal file
29
src/jison/sql/calcite/autocomplete_header.jison
Normal file
@ -0,0 +1,29 @@
|
||||
// Licensed to Cloudera, Inc. under one
|
||||
// or more contributor license agreements. See the NOTICE file
|
||||
// distributed with this work for additional information
|
||||
// regarding copyright ownership. Cloudera, Inc. licenses this file
|
||||
// to you under the Apache License, Version 2.0 (the
|
||||
// "License"); you may not use this file except in compliance
|
||||
// with the License. You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
%left 'AND' 'OR'
|
||||
%left 'BETWEEN'
|
||||
%left 'NOT' '!' '~'
|
||||
%left '=' '<' '>' 'COMPARISON_OPERATOR'
|
||||
%left '-' '*' 'ARITHMETIC_OPERATOR'
|
||||
|
||||
%left ';' ','
|
||||
%nonassoc 'CURSOR' 'PARTIAL_CURSOR'
|
||||
%nonassoc 'IN' 'IS' 'LIKE' 'RLIKE' 'REGEXP' 'EXISTS' NEGATION
|
||||
|
||||
%start SqlAutocomplete
|
||||
|
||||
%%
|
226
src/jison/sql/calcite/sql.jisonlex
Normal file
226
src/jison/sql/calcite/sql.jisonlex
Normal file
@ -0,0 +1,226 @@
|
||||
// Licensed to Cloudera, Inc. under one
|
||||
// or more contributor license agreements. See the NOTICE file
|
||||
// distributed with this work for additional information
|
||||
// regarding copyright ownership. Cloudera, Inc. licenses this file
|
||||
// to you under the Apache License, Version 2.0 (the
|
||||
// "License"); you may not use this file except in compliance
|
||||
// with the License. You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
%options case-insensitive flex
|
||||
%s between
|
||||
%x hdfs doubleQuotedValue singleQuotedValue backtickedValue
|
||||
%%
|
||||
|
||||
\s { /* skip whitespace */ }
|
||||
'--'.* { /* skip comments */ }
|
||||
[/][*][^*]*[*]+([^/*][^*]*[*]+)*[/] { /* skip comments */ }
|
||||
|
||||
'\u2020' { parser.yy.partialCursor = false; parser.yy.cursorFound = yylloc; return 'CURSOR'; }
|
||||
'\u2021' { parser.yy.partialCursor = true; parser.yy.cursorFound = yylloc; return 'PARTIAL_CURSOR'; }
|
||||
|
||||
<between>'AND' { this.popState(); return 'BETWEEN_AND'; }
|
||||
|
||||
// Reserved Keywords
|
||||
'ALL' { return 'ALL'; }
|
||||
'ALTER' { parser.determineCase(yytext); parser.addStatementTypeLocation('ALTER', yylloc, yy.lexer.upcomingInput()); return 'ALTER'; }
|
||||
'AND' { return 'AND'; }
|
||||
'AS' { return 'AS'; }
|
||||
'ASC' { return 'ASC'; }
|
||||
'BETWEEN' { this.begin('between'); return 'BETWEEN'; }
|
||||
'BIGINT' { return 'BIGINT'; }
|
||||
'BOOLEAN' { return 'BOOLEAN'; }
|
||||
'BY' { return 'BY'; }
|
||||
'CASCADE' { return 'CASCADE'; }
|
||||
'CASE' { return 'CASE'; }
|
||||
'CHAR' { return 'CHAR'; }
|
||||
'COMMENT' { return 'COMMENT'; }
|
||||
'CREATE' { parser.determineCase(yytext); return 'CREATE'; }
|
||||
'CROSS' { return 'CROSS'; }
|
||||
'CURRENT' { return 'CURRENT'; }
|
||||
'DATABASE' { return 'DATABASE'; }
|
||||
'DECIMAL' { return 'DECIMAL'; }
|
||||
'DESC' { return 'DESC'; }
|
||||
'DISTINCT' { return 'DISTINCT'; }
|
||||
'DIV' { return 'ARITHMETIC_OPERATOR'; }
|
||||
'DOUBLE' { return 'DOUBLE'; }
|
||||
'DROP' { parser.determineCase(yytext); parser.addStatementTypeLocation('DROP', yylloc, yy.lexer.upcomingInput()); return 'DROP'; }
|
||||
'ELSE' { return 'ELSE'; }
|
||||
'END' { return 'END'; }
|
||||
'EXISTS' { parser.yy.correlatedSubQuery = true; return 'EXISTS'; }
|
||||
'FALSE' { return 'FALSE'; }
|
||||
'FLOAT' { return 'FLOAT'; }
|
||||
'FOLLOWING' { return 'FOLLOWING'; }
|
||||
'FROM' { parser.determineCase(yytext); return 'FROM'; }
|
||||
'FULL' { return 'FULL'; }
|
||||
'GROUP' { return 'GROUP'; }
|
||||
'HAVING' { return 'HAVING'; }
|
||||
'IF' { return 'IF'; }
|
||||
'IN' { return 'IN'; }
|
||||
'INNER' { return 'INNER'; }
|
||||
'INSERT' { return 'INSERT'; }
|
||||
'INT' { return 'INT'; }
|
||||
'INTO' { return 'INTO'; }
|
||||
'IS' { return 'IS'; }
|
||||
'JOIN' { return 'JOIN'; }
|
||||
'LEFT' { return 'LEFT'; }
|
||||
'LIKE' { return 'LIKE'; }
|
||||
'LIMIT' { return 'LIMIT'; }
|
||||
'NOT' { return 'NOT'; }
|
||||
'NULL' { return 'NULL'; }
|
||||
'ON' { return 'ON'; }
|
||||
'OPTION' { return 'OPTION'; }
|
||||
'OR' { return 'OR'; }
|
||||
'ORDER' { return 'ORDER'; }
|
||||
'OUTER' { return 'OUTER'; }
|
||||
'PARTITION' { return 'PARTITION'; }
|
||||
'PRECEDING' { return 'PRECEDING'; }
|
||||
'PURGE' { return 'PURGE'; }
|
||||
'RANGE' { return 'RANGE'; }
|
||||
'REGEXP' { return 'REGEXP'; }
|
||||
'RIGHT' { return 'RIGHT'; }
|
||||
'RLIKE' { return 'RLIKE'; }
|
||||
'ROW' { return 'ROW'; }
|
||||
'ROLE' { return 'ROLE'; }
|
||||
'ROWS' { return 'ROWS'; }
|
||||
'SCHEMA' { return 'SCHEMA'; }
|
||||
'SELECT' { parser.determineCase(yytext); parser.addStatementTypeLocation('SELECT', yylloc); return 'SELECT'; }
|
||||
'SEMI' { return 'SEMI'; }
|
||||
'SET' { parser.determineCase(yytext); parser.addStatementTypeLocation('SET', yylloc); return 'SET'; }
|
||||
'SHOW' { parser.determineCase(yytext); parser.addStatementTypeLocation('SHOW', yylloc); return 'SHOW'; }
|
||||
'SMALLINT' { return 'SMALLINT'; }
|
||||
'STRING' { return 'STRING'; }
|
||||
'TABLE' { return 'TABLE'; }
|
||||
'THEN' { return 'THEN'; }
|
||||
'TIMESTAMP' { return 'TIMESTAMP'; }
|
||||
'TINYINT' { return 'TINYINT'; }
|
||||
'TO' { return 'TO'; }
|
||||
'TRUE' { return 'TRUE'; }
|
||||
'TRUNCATE' { parser.determineCase(yytext); parser.addStatementTypeLocation('TRUNCATE', yylloc, yy.lexer.upcomingInput()); return 'TRUNCATE'; }
|
||||
'UNBOUNDED' { return 'UNBOUNDED'; }
|
||||
'UNION' { return 'UNION'; }
|
||||
'UPDATE' { parser.determineCase(yytext); return 'UPDATE'; }
|
||||
'USE' { parser.determineCase(yytext); parser.addStatementTypeLocation('USE', yylloc); return 'USE'; }
|
||||
'VALUES' { return 'VALUES'; }
|
||||
'VARCHAR' { return 'VARCHAR'; }
|
||||
'VIEW' { return 'VIEW'; }
|
||||
'WHEN' { return 'WHEN'; }
|
||||
'WHERE' { return 'WHERE'; }
|
||||
'WITH' { parser.determineCase(yytext); parser.addStatementTypeLocation('WITH', yylloc); return 'WITH'; }
|
||||
|
||||
// Non-reserved Keywords
|
||||
'OVER' { return 'OVER'; }
|
||||
'ROLE' { return 'ROLE'; }
|
||||
|
||||
// --- UDFs ---
|
||||
AVG\s*\( { yy.lexer.unput('('); yytext = 'avg'; parser.addFunctionLocation(yylloc, yytext); return 'AVG'; }
|
||||
CAST\s*\( { yy.lexer.unput('('); yytext = 'cast'; parser.addFunctionLocation(yylloc, yytext); return 'CAST'; }
|
||||
COUNT\s*\( { yy.lexer.unput('('); yytext = 'count'; parser.addFunctionLocation(yylloc, yytext); return 'COUNT'; }
|
||||
MAX\s*\( { yy.lexer.unput('('); yytext = 'max'; parser.addFunctionLocation(yylloc, yytext); return 'MAX'; }
|
||||
MIN\s*\( { yy.lexer.unput('('); yytext = 'min'; parser.addFunctionLocation(yylloc, yytext); return 'MIN'; }
|
||||
STDDEV_POP\s*\( { yy.lexer.unput('('); yytext = 'stddev_pop'; parser.addFunctionLocation(yylloc, yytext); return 'STDDEV_POP'; }
|
||||
STDDEV_SAMP\s*\( { yy.lexer.unput('('); yytext = 'stddev_samp'; parser.addFunctionLocation(yylloc, yytext); return 'STDDEV_SAMP'; }
|
||||
SUM\s*\( { yy.lexer.unput('('); yytext = 'sum'; parser.addFunctionLocation(yylloc, yytext); return 'SUM'; }
|
||||
VAR_POP\s*\( { yy.lexer.unput('('); yytext = 'var_pop'; parser.addFunctionLocation(yylloc, yytext); return 'VAR_POP'; }
|
||||
VAR_SAMP\s*\( { yy.lexer.unput('('); yytext = 'var_samp'; parser.addFunctionLocation(yylloc, yytext); return 'VAR_SAMP'; }
|
||||
VARIANCE\s*\( { yy.lexer.unput('('); yytext = 'variance'; parser.addFunctionLocation(yylloc, yytext); return 'VARIANCE'; }
|
||||
|
||||
// Analytical functions
|
||||
CUME_DIST\s*\( { yy.lexer.unput('('); yytext = 'cume_dist'; parser.addFunctionLocation(yylloc, yytext); return 'ANALYTIC'; }
|
||||
DENSE_RANK\s*\( { yy.lexer.unput('('); yytext = 'dense_rank'; parser.addFunctionLocation(yylloc, yytext); return 'ANALYTIC'; }
|
||||
FIRST_VALUE\s*\( { yy.lexer.unput('('); yytext = 'first_value'; parser.addFunctionLocation(yylloc, yytext); return 'ANALYTIC'; }
|
||||
LAG\s*\( { yy.lexer.unput('('); yytext = 'lag'; parser.addFunctionLocation(yylloc, yytext); return 'ANALYTIC'; }
|
||||
LAST_VALUE\s*\( { yy.lexer.unput('('); yytext = 'last_value'; parser.addFunctionLocation(yylloc, yytext); return 'ANALYTIC'; }
|
||||
LEAD\s*\( { yy.lexer.unput('('); yytext = 'lead'; parser.addFunctionLocation(yylloc, yytext); return 'ANALYTIC'; }
|
||||
RANK\s*\( { yy.lexer.unput('('); yytext = 'rank'; parser.addFunctionLocation(yylloc, yytext); return 'ANALYTIC'; }
|
||||
ROW_NUMBER\s*\( { yy.lexer.unput('('); yytext = 'row_number'; parser.addFunctionLocation(yylloc, yytext); return 'ANALYTIC'; }
|
||||
|
||||
[0-9]+ { return 'UNSIGNED_INTEGER'; }
|
||||
[0-9]+(?:[YSL]|BD)? { return 'UNSIGNED_INTEGER'; }
|
||||
[0-9]+E { return 'UNSIGNED_INTEGER_E'; }
|
||||
[A-Za-z0-9_]+ { return 'REGULAR_IDENTIFIER'; }
|
||||
|
||||
<hdfs>'\u2020' { parser.yy.cursorFound = true; return 'CURSOR'; }
|
||||
<hdfs>'\u2021' { parser.yy.cursorFound = true; return 'PARTIAL_CURSOR'; }
|
||||
<hdfs>\s+['"] { return 'HDFS_START_QUOTE'; }
|
||||
<hdfs>[^'"\u2020\u2021]+ { parser.addFileLocation(yylloc, yytext); return 'HDFS_PATH'; }
|
||||
<hdfs>['"] { this.popState(); return 'HDFS_END_QUOTE'; }
|
||||
<hdfs><<EOF>> { return 'EOF'; }
|
||||
|
||||
'&&' { return 'AND'; }
|
||||
'||' { return 'OR'; }
|
||||
|
||||
'=' { return '='; }
|
||||
'<' { return '<'; }
|
||||
'>' { return '>'; }
|
||||
'!=' { return 'COMPARISON_OPERATOR'; }
|
||||
'<=' { return 'COMPARISON_OPERATOR'; }
|
||||
'>=' { return 'COMPARISON_OPERATOR'; }
|
||||
'<>' { return 'COMPARISON_OPERATOR'; }
|
||||
'<=>' { return 'COMPARISON_OPERATOR'; }
|
||||
|
||||
'-' { return '-'; }
|
||||
'*' { return '*'; }
|
||||
'+' { return 'ARITHMETIC_OPERATOR'; }
|
||||
'/' { return 'ARITHMETIC_OPERATOR'; }
|
||||
'%' { return 'ARITHMETIC_OPERATOR'; }
|
||||
'|' { return 'ARITHMETIC_OPERATOR'; }
|
||||
'^' { return 'ARITHMETIC_OPERATOR'; }
|
||||
'&' { return 'ARITHMETIC_OPERATOR'; }
|
||||
|
||||
',' { return ','; }
|
||||
'.' { return '.'; }
|
||||
':' { return ':'; }
|
||||
';' { return ';'; }
|
||||
'~' { return '~'; }
|
||||
'!' { return '!'; }
|
||||
|
||||
'(' { return '('; }
|
||||
')' { return ')'; }
|
||||
'[' { return '['; }
|
||||
']' { return ']'; }
|
||||
|
||||
\$\{[^}]*\} { return 'VARIABLE_REFERENCE'; }
|
||||
|
||||
\` { this.begin('backtickedValue'); return 'BACKTICK'; }
|
||||
<backtickedValue>[^`]+ {
|
||||
if (parser.handleQuotedValueWithCursor(this, yytext, yylloc, '`')) {
|
||||
return 'PARTIAL_VALUE';
|
||||
}
|
||||
return 'VALUE';
|
||||
}
|
||||
<backtickedValue>\` { this.popState(); return 'BACKTICK'; }
|
||||
|
||||
\' { this.begin('singleQuotedValue'); return 'SINGLE_QUOTE'; }
|
||||
<singleQuotedValue>(?:\\\\|\\[']|[^'])+ {
|
||||
if (parser.handleQuotedValueWithCursor(this, yytext, yylloc, '\'')) {
|
||||
return 'PARTIAL_VALUE';
|
||||
}
|
||||
return 'VALUE';
|
||||
}
|
||||
<singleQuotedValue>\' { this.popState(); return 'SINGLE_QUOTE'; }
|
||||
|
||||
\" { this.begin('doubleQuotedValue'); return 'DOUBLE_QUOTE'; }
|
||||
<doubleQuotedValue>(?:\\\\|\\["]|[^"])+ {
|
||||
if (parser.handleQuotedValueWithCursor(this, yytext, yylloc, '"')) {
|
||||
return 'PARTIAL_VALUE';
|
||||
}
|
||||
return 'VALUE';
|
||||
}
|
||||
<doubleQuotedValue>\" { this.popState(); return 'DOUBLE_QUOTE'; }
|
||||
|
||||
<<EOF>> { return 'EOF'; }
|
||||
|
||||
. { /* To prevent console logging of unknown chars */ }
|
||||
<between>. { }
|
||||
<hdfs>. { }
|
||||
<backtickedValue>. { }
|
||||
<singleQuotedValue>. { }
|
||||
<doubleQuotedValue>. { }
|
109
src/jison/sql/calcite/sql_alter.jison
Normal file
109
src/jison/sql/calcite/sql_alter.jison
Normal file
@ -0,0 +1,109 @@
|
||||
// Licensed to Cloudera, Inc. under one
|
||||
// or more contributor license agreements. See the NOTICE file
|
||||
// distributed with this work for additional information
|
||||
// regarding copyright ownership. Cloudera, Inc. licenses this file
|
||||
// to you under the Apache License, Version 2.0 (the
|
||||
// "License"); you may not use this file except in compliance
|
||||
// with the License. You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
DataDefinition
|
||||
: AlterStatement
|
||||
;
|
||||
|
||||
DataDefinition_EDIT
|
||||
: AlterStatement_EDIT
|
||||
;
|
||||
|
||||
AlterStatement
|
||||
: AlterTable
|
||||
| AlterView
|
||||
;
|
||||
|
||||
AlterStatement_EDIT
|
||||
: AlterTable_EDIT
|
||||
| AlterView_EDIT
|
||||
| 'ALTER' 'CURSOR'
|
||||
{
|
||||
parser.suggestKeywords(['TABLE', 'VIEW']);
|
||||
}
|
||||
;
|
||||
|
||||
AlterTable
|
||||
: AlterTableLeftSide PartitionSpec
|
||||
;
|
||||
|
||||
AlterTable_EDIT
|
||||
: AlterTableLeftSide_EDIT
|
||||
| AlterTableLeftSide_EDIT PartitionSpec
|
||||
| AlterTableLeftSide 'CURSOR'
|
||||
| AlterTableLeftSide PartitionSpec 'CURSOR'
|
||||
;
|
||||
|
||||
AlterTableLeftSide
|
||||
: 'ALTER' 'TABLE' SchemaQualifiedTableIdentifier
|
||||
{
|
||||
parser.addTablePrimary($3);
|
||||
}
|
||||
;
|
||||
|
||||
AlterTableLeftSide_EDIT
|
||||
: 'ALTER' 'TABLE' SchemaQualifiedTableIdentifier_EDIT
|
||||
{
|
||||
if (parser.yy.result.suggestTables) {
|
||||
parser.yy.result.suggestTables.onlyTables = true;
|
||||
}
|
||||
}
|
||||
| 'ALTER' 'TABLE' 'CURSOR'
|
||||
{
|
||||
parser.suggestTables({ onlyTables: true });
|
||||
parser.suggestDatabases({ appendDot: true });
|
||||
}
|
||||
;
|
||||
|
||||
AlterView
|
||||
: AlterViewLeftSide 'AS' QuerySpecification
|
||||
;
|
||||
|
||||
AlterView_EDIT
|
||||
: AlterViewLeftSide_EDIT
|
||||
| AlterViewLeftSide 'CURSOR'
|
||||
{
|
||||
parser.suggestKeywords(['AS']);
|
||||
}
|
||||
| AlterViewLeftSide 'SET' 'CURSOR'
|
||||
| AlterViewLeftSide 'AS' 'CURSOR'
|
||||
{
|
||||
parser.suggestKeywords(['SELECT']);
|
||||
}
|
||||
| AlterViewLeftSide 'AS' QuerySpecification_EDIT
|
||||
;
|
||||
|
||||
|
||||
AlterViewLeftSide
|
||||
: 'ALTER' 'VIEW' SchemaQualifiedTableIdentifier
|
||||
{
|
||||
parser.addTablePrimary($3);
|
||||
}
|
||||
;
|
||||
|
||||
AlterViewLeftSide_EDIT
|
||||
: 'ALTER' 'VIEW' SchemaQualifiedTableIdentifier_EDIT
|
||||
{
|
||||
if (parser.yy.result.suggestTables) {
|
||||
parser.yy.result.suggestTables.onlyViews = true;
|
||||
}
|
||||
}
|
||||
| 'ALTER' 'VIEW' 'CURSOR'
|
||||
{
|
||||
parser.suggestTables({ onlyViews: true });
|
||||
parser.suggestDatabases({ appendDot: true });
|
||||
}
|
||||
;
|
615
src/jison/sql/calcite/sql_create.jison
Normal file
615
src/jison/sql/calcite/sql_create.jison
Normal file
@ -0,0 +1,615 @@
|
||||
// Licensed to Cloudera, Inc. under one
|
||||
// or more contributor license agreements. See the NOTICE file
|
||||
// distributed with this work for additional information
|
||||
// regarding copyright ownership. Cloudera, Inc. licenses this file
|
||||
// to you under the Apache License, Version 2.0 (the
|
||||
// "License"); you may not use this file except in compliance
|
||||
// with the License. You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
DataDefinition
|
||||
: CreateStatement
|
||||
;
|
||||
|
||||
DataDefinition_EDIT
|
||||
: CreateStatement_EDIT
|
||||
;
|
||||
|
||||
CreateStatement
|
||||
: DatabaseDefinition
|
||||
| TableDefinition
|
||||
| ViewDefinition
|
||||
| RoleDefinition
|
||||
;
|
||||
|
||||
CreateStatement_EDIT
|
||||
: DatabaseDefinition_EDIT
|
||||
| TableDefinition_EDIT
|
||||
| ViewDefinition_EDIT
|
||||
| 'CREATE' 'CURSOR'
|
||||
{
|
||||
parser.suggestKeywords(['DATABASE', 'ROLE', 'SCHEMA', 'TABLE', 'VIEW']);
|
||||
}
|
||||
;
|
||||
|
||||
DatabaseDefinition
|
||||
: 'CREATE' DatabaseOrSchema OptionalIfNotExists
|
||||
| 'CREATE' DatabaseOrSchema OptionalIfNotExists RegularIdentifier DatabaseDefinitionOptionals
|
||||
{
|
||||
parser.addNewDatabaseLocation(@4, [{ name: $4 }]);
|
||||
}
|
||||
;
|
||||
|
||||
DatabaseDefinition_EDIT
|
||||
: 'CREATE' DatabaseOrSchema OptionalIfNotExists 'CURSOR'
|
||||
{
|
||||
if (!$3) {
|
||||
parser.suggestKeywords(['IF NOT EXISTS']);
|
||||
}
|
||||
}
|
||||
| 'CREATE' DatabaseOrSchema OptionalIfNotExists_EDIT
|
||||
| 'CREATE' DatabaseOrSchema OptionalIfNotExists 'CURSOR' RegularIdentifier
|
||||
{
|
||||
if (!$3) {
|
||||
parser.suggestKeywords(['IF NOT EXISTS']);
|
||||
}
|
||||
parser.addNewDatabaseLocation(@5, [{ name: $5 }]);
|
||||
}
|
||||
| 'CREATE' DatabaseOrSchema OptionalIfNotExists_EDIT RegularIdentifier
|
||||
{
|
||||
parser.addNewDatabaseLocation(@4, [{ name: $4 }]);
|
||||
}
|
||||
| 'CREATE' DatabaseOrSchema OptionalIfNotExists RegularIdentifier DatabaseDefinitionOptionals 'CURSOR'
|
||||
{
|
||||
parser.addNewDatabaseLocation(@4, [{ name: $4 }]);
|
||||
}
|
||||
;
|
||||
|
||||
DatabaseDefinitionOptionals
|
||||
: OptionalComment
|
||||
{
|
||||
if (!$1) {
|
||||
parser.suggestKeywords(['COMMENT']);
|
||||
}
|
||||
}
|
||||
;
|
||||
|
||||
DatabaseDefinitionOptionals_EDIT
|
||||
: OptionalComment_INVALID
|
||||
;
|
||||
|
||||
OptionalComment
|
||||
:
|
||||
| Comment
|
||||
;
|
||||
|
||||
Comment
|
||||
: 'COMMENT' QuotedValue
|
||||
;
|
||||
|
||||
OptionalComment_INVALID
|
||||
: Comment_INVALID
|
||||
;
|
||||
|
||||
Comment_INVALID
|
||||
: 'COMMENT' SINGLE_QUOTE
|
||||
| 'COMMENT' DOUBLE_QUOTE
|
||||
| 'COMMENT' SINGLE_QUOTE VALUE
|
||||
| 'COMMENT' DOUBLE_QUOTE VALUE
|
||||
;
|
||||
|
||||
TableDefinition
|
||||
: 'CREATE' 'TABLE' OptionalIfNotExists TableDefinitionRightPart
|
||||
;
|
||||
|
||||
TableDefinition_EDIT
|
||||
: 'CREATE' 'TABLE' OptionalIfNotExists TableDefinitionRightPart_EDIT
|
||||
| 'CREATE' 'TABLE' OptionalIfNotExists 'CURSOR'
|
||||
{
|
||||
if (!$3) {
|
||||
parser.suggestKeywords(['IF NOT EXISTS']);
|
||||
}
|
||||
}
|
||||
| 'CREATE' 'TABLE' OptionalIfNotExists_EDIT
|
||||
;
|
||||
|
||||
TableDefinitionRightPart
|
||||
: TableIdentifierAndOptionalColumnSpecification OptionalPartitionedBy OptionalAsSelectStatement
|
||||
;
|
||||
|
||||
TableDefinitionRightPart_EDIT
|
||||
: TableIdentifierAndOptionalColumnSpecification_EDIT OptionalPartitionedBy OptionalAsSelectStatement
|
||||
| TableIdentifierAndOptionalColumnSpecification PartitionedBy_EDIT OptionalAsSelectStatement
|
||||
| TableIdentifierAndOptionalColumnSpecification OptionalPartitionedBy OptionalAsSelectStatement_EDIT
|
||||
| TableIdentifierAndOptionalColumnSpecification OptionalPartitionedBy 'CURSOR'
|
||||
{
|
||||
var keywords = [];
|
||||
if (!$1 && !$2) {
|
||||
keywords.push({ value: 'LIKE', weight: 1 });
|
||||
} else {
|
||||
if (!$2) {
|
||||
keywords.push({ value: 'PARTITIONED BY', weight: 12 });
|
||||
}
|
||||
keywords.push({ value: 'AS', weight: 1 });
|
||||
}
|
||||
|
||||
if (keywords.length > 0) {
|
||||
parser.suggestKeywords(keywords);
|
||||
}
|
||||
}
|
||||
;
|
||||
|
||||
TableIdentifierAndOptionalColumnSpecification
|
||||
: SchemaQualifiedIdentifier OptionalColumnSpecificationsOrLike
|
||||
{
|
||||
parser.addNewTableLocation(@1, $1, $2);
|
||||
$$ = $2;
|
||||
}
|
||||
;
|
||||
|
||||
TableIdentifierAndOptionalColumnSpecification_EDIT
|
||||
: SchemaQualifiedIdentifier OptionalColumnSpecificationsOrLike_EDIT
|
||||
| SchemaQualifiedIdentifier_EDIT OptionalColumnSpecificationsOrLike
|
||||
;
|
||||
|
||||
OptionalColumnSpecificationsOrLike
|
||||
:
|
||||
| ParenthesizedColumnSpecificationList
|
||||
| 'LIKE' SchemaQualifiedTableIdentifier -> []
|
||||
;
|
||||
|
||||
OptionalColumnSpecificationsOrLike_EDIT
|
||||
: ParenthesizedColumnSpecificationList_EDIT
|
||||
| 'LIKE' 'CURSOR'
|
||||
{
|
||||
parser.suggestTables();
|
||||
parser.suggestDatabases({ appendDot: true });
|
||||
}
|
||||
| 'LIKE' SchemaQualifiedTableIdentifier_EDIT
|
||||
;
|
||||
|
||||
ParenthesizedColumnSpecificationList
|
||||
: '(' ColumnSpecificationList ')' -> $2
|
||||
;
|
||||
|
||||
ParenthesizedColumnSpecificationList_EDIT
|
||||
: '(' ColumnSpecificationList_EDIT RightParenthesisOrError
|
||||
;
|
||||
|
||||
ColumnSpecificationList
|
||||
: ColumnSpecification -> [$1]
|
||||
| ColumnSpecificationList ',' ColumnSpecification -> $1.concat($3)
|
||||
;
|
||||
|
||||
ColumnSpecificationList_EDIT
|
||||
: ColumnSpecification_EDIT
|
||||
| ColumnSpecification_EDIT ',' ColumnSpecificationList
|
||||
| ColumnSpecificationList ',' ColumnSpecification_EDIT
|
||||
| ColumnSpecificationList ',' ColumnSpecification_EDIT ',' ColumnSpecificationList
|
||||
| ColumnSpecification 'CURSOR'
|
||||
{
|
||||
parser.checkForKeywords($1);
|
||||
}
|
||||
| ColumnSpecification 'CURSOR' ',' ColumnSpecificationList
|
||||
{
|
||||
parser.checkForKeywords($1);
|
||||
}
|
||||
| ColumnSpecificationList ',' ColumnSpecification 'CURSOR'
|
||||
{
|
||||
parser.checkForKeywords($3);
|
||||
}
|
||||
| ColumnSpecificationList ',' ColumnSpecification 'CURSOR' ',' ColumnSpecificationList
|
||||
{
|
||||
parser.checkForKeywords($3);
|
||||
}
|
||||
;
|
||||
|
||||
ColumnSpecification
|
||||
: ColumnIdentifier ColumnDataType OptionalColumnOptions
|
||||
{
|
||||
$$ = $1;
|
||||
$$.type = $2;
|
||||
var keywords = [];
|
||||
if (!$3['comment']) {
|
||||
keywords.push('COMMENT');
|
||||
}
|
||||
if (keywords.length > 0) {
|
||||
$$.suggestKeywords = keywords;
|
||||
}
|
||||
}
|
||||
;
|
||||
|
||||
ColumnSpecification_EDIT
|
||||
: ColumnIdentifier 'CURSOR' OptionalColumnOptions
|
||||
{
|
||||
parser.suggestKeywords(parser.getColumnDataTypeKeywords());
|
||||
}
|
||||
| ColumnIdentifier ColumnDataType_EDIT OptionalColumnOptions
|
||||
| ColumnIdentifier ColumnDataType ColumnOptions_EDIT
|
||||
;
|
||||
|
||||
OptionalColumnOptions
|
||||
: -> {}
|
||||
| ColumnOptions
|
||||
;
|
||||
|
||||
ColumnOptions
|
||||
: ColumnOption
|
||||
{
|
||||
$$ = {};
|
||||
$$[$1] = true;
|
||||
}
|
||||
| ColumnOptions ColumnOption
|
||||
{
|
||||
$1[$2] = true;
|
||||
}
|
||||
;
|
||||
|
||||
ColumnOptions_EDIT
|
||||
: ColumnOption_EDIT
|
||||
| ColumnOption_EDIT ColumnOptions
|
||||
| ColumnOptions ColumnOption_EDIT
|
||||
| ColumnOptions ColumnOption_EDIT ColumnOptions
|
||||
;
|
||||
|
||||
ColumnOption
|
||||
: 'NOT' 'NULL' -> 'null'
|
||||
| 'NULL' -> 'null'
|
||||
| Comment -> 'comment'
|
||||
;
|
||||
|
||||
ColumnOption_EDIT
|
||||
: 'NOT' 'CURSOR'
|
||||
{
|
||||
parser.suggestKeywords(['NULL']);
|
||||
}
|
||||
;
|
||||
|
||||
ColumnDataType
|
||||
: PrimitiveType
|
||||
| ArrayType
|
||||
| MapType
|
||||
| StructType
|
||||
| ArrayType_INVALID
|
||||
| MapType_INVALID
|
||||
| StructType_INVALID
|
||||
;
|
||||
|
||||
ColumnDataType_EDIT
|
||||
: ArrayType_EDIT
|
||||
| MapType_EDIT
|
||||
| StructType_EDIT
|
||||
;
|
||||
|
||||
ArrayType
|
||||
: 'ARRAY' '<' ColumnDataType '>'
|
||||
;
|
||||
|
||||
ArrayType_INVALID
|
||||
: 'ARRAY' '<' '>'
|
||||
;
|
||||
|
||||
ArrayType_EDIT
|
||||
: 'ARRAY' '<' AnyCursor GreaterThanOrError
|
||||
{
|
||||
parser.suggestKeywords(parser.getColumnDataTypeKeywords());
|
||||
}
|
||||
| 'ARRAY' '<' ColumnDataType_EDIT GreaterThanOrError
|
||||
;
|
||||
|
||||
MapType
|
||||
: 'MAP' '<' PrimitiveType ',' ColumnDataType '>'
|
||||
;
|
||||
|
||||
MapType_INVALID
|
||||
: 'MAP' '<' '>'
|
||||
;
|
||||
|
||||
MapType_EDIT
|
||||
: 'MAP' '<' PrimitiveType ',' ColumnDataType_EDIT GreaterThanOrError
|
||||
| 'MAP' '<' AnyCursor GreaterThanOrError
|
||||
{
|
||||
parser.suggestKeywords(parser.getTypeKeywords());
|
||||
}
|
||||
| 'MAP' '<' PrimitiveType ',' AnyCursor GreaterThanOrError
|
||||
{
|
||||
parser.suggestKeywords(parser.getColumnDataTypeKeywords());
|
||||
}
|
||||
| 'MAP' '<' ',' AnyCursor GreaterThanOrError
|
||||
{
|
||||
parser.suggestKeywords(parser.getColumnDataTypeKeywords());
|
||||
}
|
||||
;
|
||||
|
||||
StructType
|
||||
: 'STRUCT' '<' StructDefinitionList '>'
|
||||
;
|
||||
|
||||
StructType_INVALID
|
||||
: 'STRUCT' '<' '>'
|
||||
;
|
||||
|
||||
StructType_EDIT
|
||||
: 'STRUCT' '<' StructDefinitionList_EDIT GreaterThanOrError
|
||||
;
|
||||
|
||||
StructDefinitionList
|
||||
: StructDefinition
|
||||
| StructDefinitionList ',' StructDefinition
|
||||
;
|
||||
|
||||
StructDefinitionList_EDIT
|
||||
: StructDefinition_EDIT
|
||||
| StructDefinition_EDIT Commas
|
||||
| StructDefinition_EDIT Commas StructDefinitionList
|
||||
| StructDefinitionList ',' StructDefinition_EDIT
|
||||
| StructDefinitionList ',' StructDefinition_EDIT Commas StructDefinitionList
|
||||
;
|
||||
|
||||
StructDefinition
|
||||
: RegularOrBacktickedIdentifier ':' ColumnDataType OptionalComment
|
||||
;
|
||||
|
||||
StructDefinition_EDIT
|
||||
: Commas RegularOrBacktickedIdentifier ':' ColumnDataType 'CURSOR'
|
||||
{
|
||||
parser.suggestKeywords(['COMMENT']);
|
||||
}
|
||||
| Commas RegularOrBacktickedIdentifier ':' AnyCursor
|
||||
{
|
||||
parser.suggestKeywords(parser.getColumnDataTypeKeywords());
|
||||
}
|
||||
| Commas RegularOrBacktickedIdentifier ':' ColumnDataType_EDIT
|
||||
| RegularOrBacktickedIdentifier ':' ColumnDataType 'CURSOR'
|
||||
{
|
||||
parser.suggestKeywords(['COMMENT']);
|
||||
}
|
||||
| RegularOrBacktickedIdentifier ':' AnyCursor
|
||||
{
|
||||
parser.suggestKeywords(parser.getColumnDataTypeKeywords());
|
||||
}
|
||||
| RegularOrBacktickedIdentifier ':' ColumnDataType_EDIT
|
||||
;
|
||||
|
||||
ColumnDataTypeList
|
||||
: ColumnDataType
|
||||
| ColumnDataTypeList ',' ColumnDataType
|
||||
;
|
||||
|
||||
ColumnDataTypeList_EDIT
|
||||
: ColumnDataTypeListInner_EDIT
|
||||
| ColumnDataTypeListInner_EDIT Commas
|
||||
| ColumnDataTypeList ',' ColumnDataTypeListInner_EDIT
|
||||
| ColumnDataTypeListInner_EDIT Commas ColumnDataTypeList
|
||||
| ColumnDataTypeList ',' ColumnDataTypeListInner_EDIT Commas ColumnDataTypeList
|
||||
;
|
||||
|
||||
ColumnDataTypeListInner_EDIT
|
||||
: Commas AnyCursor
|
||||
{
|
||||
parser.suggestKeywords(parser.getColumnDataTypeKeywords());
|
||||
}
|
||||
| Commas ColumnDataType_EDIT
|
||||
| AnyCursor
|
||||
{
|
||||
parser.suggestKeywords(parser.getColumnDataTypeKeywords());
|
||||
}
|
||||
| ColumnDataType_EDIT
|
||||
;
|
||||
|
||||
GreaterThanOrError
|
||||
: '>'
|
||||
| error
|
||||
;
|
||||
|
||||
OptionalPartitionedBy
|
||||
:
|
||||
| PartitionedBy
|
||||
;
|
||||
|
||||
PartitionedBy
|
||||
: 'PARTITION' 'BY' RangeClause
|
||||
;
|
||||
|
||||
PartitionedBy_EDIT
|
||||
: 'PARTITION' 'CURSOR'
|
||||
{
|
||||
parser.suggestKeywords(['BY']);
|
||||
}
|
||||
| 'PARTITION' 'BY' 'CURSOR'
|
||||
{
|
||||
parser.suggestKeywords(['RANGE']);
|
||||
}
|
||||
| 'PARTITION' 'BY' RangeClause_EDIT
|
||||
;
|
||||
|
||||
RangeClause
|
||||
: 'RANGE' ParenthesizedColumnList ParenthesizedPartitionValuesList
|
||||
;
|
||||
|
||||
RangeClause_EDIT
|
||||
: 'RANGE' 'CURSOR'
|
||||
| 'RANGE' ParenthesizedColumnList_EDIT
|
||||
| 'RANGE' ParenthesizedColumnList 'CURSOR'
|
||||
| 'RANGE' ParenthesizedColumnList ParenthesizedPartitionValuesList_EDIT
|
||||
| 'RANGE' ParenthesizedColumnList_EDIT ParenthesizedPartitionValuesList
|
||||
;
|
||||
|
||||
ParenthesizedPartitionValuesList
|
||||
: '(' PartitionValueList ')'
|
||||
;
|
||||
|
||||
ParenthesizedPartitionValuesList_EDIT
|
||||
: '(' 'CURSOR' RightParenthesisOrError
|
||||
{
|
||||
parser.suggestKeywords(['PARTITION']);
|
||||
}
|
||||
|'(' PartitionValueList_EDIT RightParenthesisOrError
|
||||
;
|
||||
|
||||
PartitionValueList
|
||||
: PartitionValue
|
||||
| PartitionValueList ',' PartitionValue
|
||||
;
|
||||
|
||||
PartitionValueList_EDIT
|
||||
: PartitionValue_EDIT
|
||||
| PartitionValueList ',' 'CURSOR'
|
||||
{
|
||||
parser.suggestKeywords(['PARTITION']);
|
||||
}
|
||||
| PartitionValueList ',' 'CURSOR' ',' PartitionValueList
|
||||
{
|
||||
parser.suggestKeywords(['PARTITION']);
|
||||
}
|
||||
| PartitionValueList ',' PartitionValue_EDIT
|
||||
| PartitionValueList ',' PartitionValue_EDIT ',' PartitionValueList
|
||||
;
|
||||
|
||||
PartitionValue
|
||||
: 'PARTITION' ValueExpression LessThanOrEqualTo 'VALUES' LessThanOrEqualTo ValueExpression
|
||||
| 'PARTITION' 'VALUES' LessThanOrEqualTo ValueExpression
|
||||
| 'PARTITION' ValueExpression LessThanOrEqualTo 'VALUES'
|
||||
;
|
||||
|
||||
PartitionValue_EDIT
|
||||
: 'PARTITION' 'CURSOR'
|
||||
{
|
||||
parser.suggestKeywords(['VALUE', 'VALUES']);
|
||||
}
|
||||
| 'PARTITION' ValueExpression_EDIT
|
||||
{
|
||||
if ($2.endsWithLessThanOrEqual) {
|
||||
parser.suggestKeywords(['VALUES']);
|
||||
}
|
||||
}
|
||||
| 'PARTITION' ValueExpression 'CURSOR'
|
||||
{
|
||||
parser.suggestKeywords(['<', '<=']);
|
||||
}
|
||||
| 'PARTITION' ValueExpression LessThanOrEqualTo 'CURSOR'
|
||||
{
|
||||
parser.suggestKeywords(['VALUES']);
|
||||
}
|
||||
| 'PARTITION' ValueExpression_EDIT LessThanOrEqualTo 'VALUES'
|
||||
| 'PARTITION' ValueExpression LessThanOrEqualTo 'VALUES' 'CURSOR'
|
||||
{
|
||||
parser.suggestKeywords(['<', '<=']);
|
||||
}
|
||||
| 'PARTITION' ValueExpression LessThanOrEqualTo 'VALUES' LessThanOrEqualTo 'CURSOR'
|
||||
{
|
||||
parser.suggestFunctions();
|
||||
}
|
||||
| 'PARTITION' ValueExpression LessThanOrEqualTo 'VALUES' LessThanOrEqualTo ValueExpression_EDIT
|
||||
| 'PARTITION' 'VALUES' 'CURSOR'
|
||||
{
|
||||
parser.suggestKeywords(['<', '<=']);
|
||||
}
|
||||
| 'PARTITION' 'VALUES' LessThanOrEqualTo 'CURSOR'
|
||||
{
|
||||
parser.suggestFunctions();
|
||||
}
|
||||
| 'PARTITION' 'VALUES' LessThanOrEqualTo ValueExpression_EDIT
|
||||
;
|
||||
|
||||
LessThanOrEqualTo
|
||||
: '<'
|
||||
| 'COMPARISON_OPERATOR' // This is fine for autocompletion
|
||||
;
|
||||
|
||||
OptionalAsSelectStatement
|
||||
:
|
||||
| 'AS' CommitLocations QuerySpecification
|
||||
;
|
||||
|
||||
OptionalAsSelectStatement_EDIT
|
||||
: 'AS' CommitLocations 'CURSOR'
|
||||
{
|
||||
parser.suggestKeywords(['SELECT']);
|
||||
}
|
||||
| 'AS' CommitLocations QuerySpecification_EDIT
|
||||
;
|
||||
|
||||
CommitLocations
|
||||
: /* empty */
|
||||
{
|
||||
parser.commitLocations();
|
||||
}
|
||||
;
|
||||
|
||||
ViewDefinition
|
||||
: 'CREATE' 'VIEW' OptionalIfNotExists SchemaQualifiedIdentifier OptionalParenthesizedViewColumnList OptionalComment 'AS' QuerySpecification
|
||||
;
|
||||
|
||||
ViewDefinition_EDIT
|
||||
: 'CREATE' 'VIEW' OptionalIfNotExists 'CURSOR'
|
||||
{
|
||||
if (!$3) {
|
||||
parser.suggestKeywords(['IF NOT EXISTS']);
|
||||
}
|
||||
parser.suggestDatabases({ appendDot: true });
|
||||
}
|
||||
| 'CREATE' 'VIEW' OptionalIfNotExists 'CURSOR' SchemaQualifiedIdentifier OptionalParenthesizedViewColumnList OptionalComment 'AS' QuerySpecification
|
||||
{
|
||||
if (!$3) {
|
||||
parser.suggestKeywords(['IF NOT EXISTS']);
|
||||
}
|
||||
}
|
||||
| 'CREATE' 'VIEW' OptionalIfNotExists_EDIT
|
||||
| 'CREATE' 'VIEW' OptionalIfNotExists SchemaQualifiedIdentifier ParenthesizedViewColumnList_EDIT OptionalComment
|
||||
| 'CREATE' 'VIEW' OptionalIfNotExists SchemaQualifiedIdentifier OptionalParenthesizedViewColumnList OptionalComment 'CURSOR'
|
||||
{
|
||||
var keywords = [{value: 'AS', weight: 1 }];
|
||||
if (!$6) {
|
||||
keywords.push({ value: 'COMMENT', weight: 3 });
|
||||
}
|
||||
parser.suggestKeywords(keywords);
|
||||
}
|
||||
| 'CREATE' 'VIEW' OptionalIfNotExists SchemaQualifiedIdentifier OptionalParenthesizedViewColumnList OptionalComment 'AS' 'CURSOR'
|
||||
{
|
||||
parser.suggestKeywords(['SELECT']);
|
||||
}
|
||||
| 'CREATE' 'VIEW' OptionalIfNotExists SchemaQualifiedIdentifier OptionalParenthesizedViewColumnList OptionalComment 'AS' QuerySpecification_EDIT
|
||||
| 'CREATE' 'VIEW' OptionalIfNotExists SchemaQualifiedIdentifier_EDIT OptionalParenthesizedViewColumnList OptionalComment 'AS' QuerySpecification
|
||||
;
|
||||
|
||||
OptionalParenthesizedViewColumnList
|
||||
:
|
||||
| ParenthesizedViewColumnList
|
||||
;
|
||||
|
||||
ParenthesizedViewColumnList
|
||||
: '(' ViewColumnList ')'
|
||||
;
|
||||
|
||||
ParenthesizedViewColumnList_EDIT
|
||||
: '(' ViewColumnList_EDIT RightParenthesisOrError
|
||||
{
|
||||
if (!$2) {
|
||||
parser.suggestKeywords(['COMMENT']);
|
||||
}
|
||||
}
|
||||
;
|
||||
|
||||
ViewColumnList
|
||||
: ColumnReference OptionalComment
|
||||
| ViewColumnList ',' ColumnReference OptionalComment
|
||||
;
|
||||
|
||||
ViewColumnList_EDIT
|
||||
: ColumnReference OptionalComment 'CURSOR' -> $2
|
||||
| ColumnReference OptionalComment 'CURSOR' ',' ViewColumnList -> $2
|
||||
| ViewColumnList ',' ColumnReference OptionalComment 'CURSOR' -> $4
|
||||
| ViewColumnList ',' ColumnReference OptionalComment 'CURSOR' ',' ViewColumnList -> $4
|
||||
;
|
||||
|
||||
RoleDefinition
|
||||
: 'CREATE' 'ROLE' RegularIdentifier
|
||||
;
|
184
src/jison/sql/calcite/sql_drop.jison
Normal file
184
src/jison/sql/calcite/sql_drop.jison
Normal file
@ -0,0 +1,184 @@
|
||||
// Licensed to Cloudera, Inc. under one
|
||||
// or more contributor license agreements. See the NOTICE file
|
||||
// distributed with this work for additional information
|
||||
// regarding copyright ownership. Cloudera, Inc. licenses this file
|
||||
// to you under the Apache License, Version 2.0 (the
|
||||
// "License"); you may not use this file except in compliance
|
||||
// with the License. You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
DataDefinition
|
||||
: DropStatement
|
||||
;
|
||||
|
||||
DataDefinition_EDIT
|
||||
: DropStatement_EDIT
|
||||
;
|
||||
|
||||
DropStatement
|
||||
: DropDatabaseStatement
|
||||
| DropRoleStatement
|
||||
| DropTableStatement
|
||||
| DropViewStatement
|
||||
| TruncateTableStatement
|
||||
;
|
||||
|
||||
DropStatement_EDIT
|
||||
: DropDatabaseStatement_EDIT
|
||||
| DropTableStatement_EDIT
|
||||
| DropViewStatement_EDIT
|
||||
| TruncateTableStatement_EDIT
|
||||
| 'DROP' 'CURSOR'
|
||||
{
|
||||
parser.suggestKeywords(['DATABASE', 'ROLE', 'SCHEMA', 'TABLE', 'VIEW']);
|
||||
}
|
||||
;
|
||||
|
||||
DropDatabaseStatement
|
||||
: 'DROP' DatabaseOrSchema OptionalIfExists RegularOrBacktickedIdentifier OptionalCascade
|
||||
;
|
||||
|
||||
DropDatabaseStatement_EDIT
|
||||
: 'DROP' DatabaseOrSchema OptionalIfExists
|
||||
| 'DROP' DatabaseOrSchema OptionalIfExists_EDIT
|
||||
| 'DROP' DatabaseOrSchema OptionalIfExists 'CURSOR'
|
||||
{
|
||||
if (!$3) {
|
||||
parser.suggestKeywords(['IF EXISTS']);
|
||||
}
|
||||
parser.suggestDatabases();
|
||||
}
|
||||
| 'DROP' DatabaseOrSchema OptionalIfExists RegularOrBacktickedIdentifier 'CURSOR'
|
||||
{
|
||||
parser.suggestKeywords(['CASCADE']);
|
||||
}
|
||||
| 'DROP' DatabaseOrSchema OptionalIfExists_EDIT RegularOrBacktickedIdentifier OptionalCascade
|
||||
| 'DROP' DatabaseOrSchema OptionalIfExists 'CURSOR' RegularOrBacktickedIdentifier OptionalCascade
|
||||
{
|
||||
if (!$3) {
|
||||
parser.suggestKeywords(['IF EXISTS']);
|
||||
}
|
||||
}
|
||||
;
|
||||
DropRoleStatement
|
||||
: 'DROP' 'ROLE' RegularIdentifier
|
||||
;
|
||||
|
||||
DropTableStatement
|
||||
: 'DROP' 'TABLE' OptionalIfExists SchemaQualifiedTableIdentifier OptionalPurge
|
||||
{
|
||||
parser.addTablePrimary($4);
|
||||
}
|
||||
;
|
||||
|
||||
DropTableStatement_EDIT
|
||||
: 'DROP' 'TABLE' OptionalIfExists_EDIT
|
||||
| 'DROP' 'TABLE' OptionalIfExists 'CURSOR'
|
||||
{
|
||||
if (!$3) {
|
||||
parser.suggestKeywords(['IF EXISTS']);
|
||||
}
|
||||
parser.suggestTables({ onlyTables: true });
|
||||
parser.suggestDatabases({
|
||||
appendDot: true
|
||||
});
|
||||
}
|
||||
| 'DROP' 'TABLE' OptionalIfExists SchemaQualifiedTableIdentifier_EDIT OptionalPurge
|
||||
{
|
||||
if (parser.yy.result.suggestTables) {
|
||||
parser.yy.result.suggestTables.onlyTables = true;
|
||||
}
|
||||
}
|
||||
| 'DROP' 'TABLE' OptionalIfExists_EDIT SchemaQualifiedTableIdentifier OptionalPurge
|
||||
| 'DROP' 'TABLE' OptionalIfExists SchemaQualifiedTableIdentifier OptionalPurge 'CURSOR'
|
||||
{
|
||||
parser.addTablePrimary($4);
|
||||
if (!$5) {
|
||||
parser.suggestKeywords(['PURGE']);
|
||||
}
|
||||
}
|
||||
;
|
||||
|
||||
OptionalPurge
|
||||
:
|
||||
| 'PURGE'
|
||||
;
|
||||
|
||||
DropViewStatement
|
||||
: 'DROP' 'VIEW' OptionalIfExists SchemaQualifiedTableIdentifier
|
||||
{
|
||||
parser.addTablePrimary($4);
|
||||
}
|
||||
;
|
||||
|
||||
DropViewStatement_EDIT
|
||||
: 'DROP' 'VIEW' OptionalIfExists 'CURSOR'
|
||||
{
|
||||
if (!$3) {
|
||||
parser.suggestKeywords(['IF EXISTS']);
|
||||
}
|
||||
parser.suggestTables({ onlyViews: true });
|
||||
parser.suggestDatabases({ appendDot: true });
|
||||
}
|
||||
| 'DROP' 'VIEW' OptionalIfExists 'CURSOR' SchemaQualifiedTableIdentifier
|
||||
{
|
||||
parser.addTablePrimary($5);
|
||||
if (!$3) {
|
||||
parser.suggestKeywords(['IF EXISTS']);
|
||||
}
|
||||
}
|
||||
| 'DROP' 'VIEW' OptionalIfExists_EDIT
|
||||
| 'DROP' 'VIEW' OptionalIfExists_EDIT SchemaQualifiedTableIdentifier
|
||||
{
|
||||
parser.addTablePrimary($4);
|
||||
}
|
||||
| 'DROP' 'VIEW' OptionalIfExists SchemaQualifiedTableIdentifier_EDIT
|
||||
{
|
||||
if (parser.yy.result.suggestTables) {
|
||||
parser.yy.result.suggestTables.onlyViews = true;
|
||||
}
|
||||
}
|
||||
;
|
||||
|
||||
TruncateTableStatement
|
||||
: 'TRUNCATE' 'TABLE' OptionalIfExists SchemaQualifiedTableIdentifier
|
||||
{
|
||||
parser.addTablePrimary($4);
|
||||
}
|
||||
;
|
||||
|
||||
TruncateTableStatement_EDIT
|
||||
: 'TRUNCATE' 'CURSOR'
|
||||
{
|
||||
parser.suggestKeywords(['TABLE']);
|
||||
}
|
||||
| 'TRUNCATE' 'TABLE' OptionalIfExists 'CURSOR'
|
||||
{
|
||||
parser.suggestTables();
|
||||
parser.suggestDatabases({ appendDot: true });
|
||||
if (!$3) {
|
||||
parser.suggestKeywords(['IF EXISTS']);
|
||||
}
|
||||
}
|
||||
| 'TRUNCATE' 'TABLE' OptionalIfExists_EDIT
|
||||
| 'TRUNCATE' 'TABLE' OptionalIfExists SchemaQualifiedTableIdentifier_EDIT
|
||||
| 'TRUNCATE' 'TABLE' OptionalIfExists SchemaQualifiedTableIdentifier 'CURSOR'
|
||||
{
|
||||
parser.addTablePrimary($4);
|
||||
}
|
||||
| 'TRUNCATE' 'TABLE' OptionalIfExists 'CURSOR' SchemaQualifiedTableIdentifier
|
||||
{
|
||||
parser.addTablePrimary($4);
|
||||
if (!$3) {
|
||||
parser.suggestKeywords(['IF EXISTS']);
|
||||
}
|
||||
}
|
||||
| 'TRUNCATE' 'TABLE' OptionalIfExists_EDIT SchemaQualifiedTableIdentifier OptionalPartitionSpec
|
||||
;
|
132
src/jison/sql/calcite/sql_error.jison
Normal file
132
src/jison/sql/calcite/sql_error.jison
Normal file
@ -0,0 +1,132 @@
|
||||
// Licensed to Cloudera, Inc. under one
|
||||
// or more contributor license agreements. See the NOTICE file
|
||||
// distributed with this work for additional information
|
||||
// regarding copyright ownership. Cloudera, Inc. licenses this file
|
||||
// to you under the Apache License, Version 2.0 (the
|
||||
// "License"); you may not use this file except in compliance
|
||||
// with the License. You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
SqlStatements
|
||||
: error
|
||||
| NonStartingToken error // Having just ': error' does not work for some reason, jison bug?
|
||||
;
|
||||
|
||||
SqlStatement_EDIT
|
||||
: AnyCursor error
|
||||
{
|
||||
parser.suggestDdlAndDmlKeywords();
|
||||
}
|
||||
;
|
||||
|
||||
SelectStatement
|
||||
: 'SELECT' OptionalAllOrDistinct SelectList_ERROR TableExpression
|
||||
| 'SELECT' OptionalAllOrDistinct SelectList TableExpression_ERROR
|
||||
;
|
||||
|
||||
SelectStatement_EDIT
|
||||
: 'SELECT' OptionalAllOrDistinct SelectList_ERROR_EDIT TableExpression
|
||||
{
|
||||
parser.selectListNoTableSuggest($3, $2);
|
||||
}
|
||||
| 'SELECT' OptionalAllOrDistinct SelectList_ERROR TableExpression_EDIT
|
||||
;
|
||||
|
||||
SelectList_ERROR
|
||||
: ErrorList
|
||||
| SelectList ',' ErrorList
|
||||
| ErrorList ',' SelectList ',' ErrorList
|
||||
| ErrorList ',' SelectList
|
||||
| SelectList ',' ErrorList ',' SelectList
|
||||
;
|
||||
|
||||
SelectList_ERROR_EDIT
|
||||
: ErrorList ',' SelectList_EDIT -> $3
|
||||
| SelectList ',' ErrorList ',' SelectList_EDIT -> $5
|
||||
| ErrorList ',' SelectList ',' ErrorList ',' SelectList_EDIT -> $7
|
||||
| ErrorList ',' AnyCursor
|
||||
{
|
||||
$$ = { cursorAtStart : false, suggestFunctions: true, suggestColumns: true, suggestAggregateFunctions: true };
|
||||
}
|
||||
| SelectList ',' ErrorList ',' AnyCursor
|
||||
{
|
||||
$$ = { cursorAtStart : false, suggestFunctions: true, suggestColumns: true, suggestAggregateFunctions: true };
|
||||
}
|
||||
| ErrorList ',' SelectList ',' Errors ',' AnyCursor
|
||||
{
|
||||
$$ = { cursorAtStart : true, suggestFunctions: true, suggestColumns: true, suggestAggregateFunctions: true };
|
||||
}
|
||||
;
|
||||
|
||||
SetSpecification
|
||||
: 'SET' SetOption '=' error
|
||||
;
|
||||
|
||||
ErrorList
|
||||
: error
|
||||
| Errors ',' error
|
||||
;
|
||||
|
||||
JoinType_EDIT
|
||||
: 'FULL' 'CURSOR' error
|
||||
{
|
||||
parser.suggestKeywords(['JOIN', 'OUTER JOIN']);
|
||||
}
|
||||
| 'LEFT' 'CURSOR' error
|
||||
{
|
||||
parser.suggestKeywords(['JOIN', 'OUTER JOIN']);
|
||||
}
|
||||
| 'RIGHT' 'CURSOR' error
|
||||
{
|
||||
parser.suggestKeywords(['JOIN', 'OUTER JOIN']);
|
||||
}
|
||||
;
|
||||
|
||||
OptionalSelectConditions_EDIT
|
||||
: WhereClause error 'CURSOR' OptionalGroupByClause OptionalHavingClause OptionalOrderByClause OptionalLimitClause
|
||||
{
|
||||
$$ = {
|
||||
suggestKeywords: parser.getKeywordsForOptionalsLR([$4, $5, $6, $7], [{ value: 'GROUP BY', weight: 8 }, { value: 'HAVING', weight: 7 }, { value: 'ORDER BY', weight: 5 }, { value: 'LIMIT', weight: 3 }], [true, true, true, true]),
|
||||
cursorAtEnd: !$4 && !$5 && !$6 && !$7
|
||||
};
|
||||
}
|
||||
| OptionalWhereClause OptionalGroupByClause HavingClause error 'CURSOR' OptionalOrderByClause OptionalLimitClause
|
||||
{
|
||||
$$ = {
|
||||
suggestKeywords: parser.getKeywordsForOptionalsLR([$6, $7], [{ value: 'ORDER BY', weight: 5 }, { value: 'LIMIT', weight: 3 }], [true, true]),
|
||||
cursorAtEnd: !$6 && !$7
|
||||
}
|
||||
}
|
||||
| OptionalWhereClause OptionalGroupByClause OptionalHavingClause OrderByClause error 'CURSOR' OptionalLimitClause
|
||||
{
|
||||
$$ = {
|
||||
suggestKeywords: parser.getKeywordsForOptionalsLR([$7], [{ value: 'LIMIT', weight: 3 }], [true]),
|
||||
cursorAtEnd: !$7
|
||||
}
|
||||
}
|
||||
| OptionalWhereClause OptionalGroupByClause OptionalHavingClause OptionalOrderByClause LimitClause error 'CURSOR'
|
||||
;
|
||||
|
||||
OptionalSelectConditions_EDIT
|
||||
: WhereClause error GroupByClause_EDIT OptionalHavingClause OptionalOrderByClause OptionalLimitClause
|
||||
| WhereClause error OptionalGroupByClause HavingClause_EDIT OptionalOrderByClause OptionalLimitClause
|
||||
| WhereClause error OptionalGroupByClause OptionalHavingClause OrderByClause_EDIT OptionalLimitClause
|
||||
| WhereClause error OptionalGroupByClause OptionalHavingClause OptionalOrderByClause LimitClause_EDIT
|
||||
| OptionalWhereClause GroupByClause error HavingClause_EDIT OptionalOrderByClause OptionalLimitClause
|
||||
| OptionalWhereClause GroupByClause error OptionalHavingClause OrderByClause_EDIT OptionalLimitClause
|
||||
| OptionalWhereClause GroupByClause error OptionalHavingClause OptionalOrderByClause LimitClause_EDIT
|
||||
| OptionalWhereClause OptionalGroupByClause HavingClause error OrderByClause_EDIT OptionalLimitClause
|
||||
| OptionalWhereClause OptionalGroupByClause HavingClause error OptionalOrderByClause LimitClause_EDIT
|
||||
| OptionalWhereClause OptionalGroupByClause OptionalHavingClause OrderByClause error LimitClause_EDIT
|
||||
;
|
||||
|
||||
DatabaseDefinition_EDIT
|
||||
: 'CREATE' DatabaseOrSchema OptionalIfNotExists RegularIdentifier DatabaseDefinitionOptionals_EDIT error
|
||||
;
|
72
src/jison/sql/calcite/sql_insert.jison
Normal file
72
src/jison/sql/calcite/sql_insert.jison
Normal file
@ -0,0 +1,72 @@
|
||||
// Licensed to Cloudera, Inc. under one
|
||||
// or more contributor license agreements. See the NOTICE file
|
||||
// distributed with this work for additional information
|
||||
// regarding copyright ownership. Cloudera, Inc. licenses this file
|
||||
// to you under the Apache License, Version 2.0 (the
|
||||
// "License"); you may not use this file except in compliance
|
||||
// with the License. You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
DataManipulation
|
||||
: InsertStatement
|
||||
;
|
||||
|
||||
InsertStatement
|
||||
: InsertValuesStatement
|
||||
;
|
||||
|
||||
DataManipulation_EDIT
|
||||
: InsertValuesStatement_EDIT
|
||||
;
|
||||
|
||||
InsertValuesStatement
|
||||
: 'INSERT' 'INTO' OptionalTable SchemaQualifiedTableIdentifier 'VALUES' InsertValuesList
|
||||
{
|
||||
$4.owner = 'insert';
|
||||
parser.addTablePrimary($4);
|
||||
}
|
||||
;
|
||||
|
||||
InsertValuesStatement_EDIT
|
||||
: 'INSERT' 'CURSOR'
|
||||
{
|
||||
parser.suggestKeywords(['INTO']);
|
||||
}
|
||||
| 'INSERT' 'INTO' OptionalTable 'CURSOR'
|
||||
{
|
||||
if (!$3) {
|
||||
parser.suggestKeywords(['TABLE']);
|
||||
}
|
||||
parser.suggestTables();
|
||||
parser.suggestDatabases({ appendDot: true });
|
||||
}
|
||||
| 'INSERT' 'INTO' OptionalTable SchemaQualifiedTableIdentifier_EDIT
|
||||
| 'INSERT' 'INTO' OptionalTable SchemaQualifiedTableIdentifier 'CURSOR'
|
||||
{
|
||||
$4.owner = 'insert';
|
||||
parser.addTablePrimary($4);
|
||||
parser.suggestKeywords(['VALUES']);
|
||||
}
|
||||
| 'INSERT' 'INTO' OptionalTable SchemaQualifiedTableIdentifier_EDIT 'VALUES' InsertValuesList
|
||||
;
|
||||
|
||||
InsertValuesList
|
||||
: ParenthesizedRowValuesList
|
||||
| RowValuesList ',' ParenthesizedRowValuesList
|
||||
;
|
||||
|
||||
ParenthesizedRowValuesList
|
||||
: '(' InValueList ')'
|
||||
;
|
||||
|
||||
OptionalTable
|
||||
:
|
||||
| 'TABLE'
|
||||
;
|
2762
src/jison/sql/calcite/sql_main.jison
Normal file
2762
src/jison/sql/calcite/sql_main.jison
Normal file
File diff suppressed because it is too large
Load Diff
46
src/jison/sql/calcite/sql_set.jison
Normal file
46
src/jison/sql/calcite/sql_set.jison
Normal file
@ -0,0 +1,46 @@
|
||||
// Licensed to Cloudera, Inc. under one
|
||||
// or more contributor license agreements. See the NOTICE file
|
||||
// distributed with this work for additional information
|
||||
// regarding copyright ownership. Cloudera, Inc. licenses this file
|
||||
// to you under the Apache License, Version 2.0 (the
|
||||
// "License"); you may not use this file except in compliance
|
||||
// with the License. You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
DataDefinition
|
||||
: SetSpecification
|
||||
;
|
||||
|
||||
DataDefinition_EDIT
|
||||
: 'SET' 'CURSOR'
|
||||
{
|
||||
parser.suggestSetOptions();
|
||||
}
|
||||
;
|
||||
|
||||
SetSpecification
|
||||
: 'SET' SetOption '=' SetValue
|
||||
| 'SET' 'ALL'
|
||||
;
|
||||
|
||||
SetOption
|
||||
: RegularIdentifier
|
||||
| SetOption '.' RegularIdentifier
|
||||
;
|
||||
|
||||
SetValue
|
||||
: RegularIdentifier
|
||||
| SignedInteger
|
||||
| SignedInteger RegularIdentifier
|
||||
| QuotedValue
|
||||
| 'TRUE'
|
||||
| 'FALSE'
|
||||
| 'NULL'
|
||||
;
|
122
src/jison/sql/calcite/sql_update.jison
Normal file
122
src/jison/sql/calcite/sql_update.jison
Normal file
@ -0,0 +1,122 @@
|
||||
// Licensed to Cloudera, Inc. under one
|
||||
// or more contributor license agreements. See the NOTICE file
|
||||
// distributed with this work for additional information
|
||||
// regarding copyright ownership. Cloudera, Inc. licenses this file
|
||||
// to you under the Apache License, Version 2.0 (the
|
||||
// "License"); you may not use this file except in compliance
|
||||
// with the License. You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
DataManipulation
|
||||
: UpdateStatement
|
||||
;
|
||||
|
||||
DataManipulation_EDIT
|
||||
: UpdateStatement_EDIT
|
||||
;
|
||||
|
||||
UpdateStatement
|
||||
: 'UPDATE' TargetTable 'SET' SetClauseList OptionalFromJoinedTable OptionalWhereClause
|
||||
;
|
||||
|
||||
UpdateStatement_EDIT
|
||||
: 'UPDATE' TargetTable_EDIT 'SET' SetClauseList OptionalFromJoinedTable OptionalWhereClause
|
||||
| 'UPDATE' TargetTable 'SET' SetClauseList_EDIT OptionalFromJoinedTable OptionalWhereClause
|
||||
| 'UPDATE' TargetTable 'SET' SetClauseList FromJoinedTable_EDIT OptionalWhereClause
|
||||
| 'UPDATE' TargetTable 'SET' SetClauseList OptionalFromJoinedTable WhereClause_EDIT
|
||||
| 'UPDATE' TargetTable 'SET' SetClauseList OptionalFromJoinedTable OptionalWhereClause 'CURSOR'
|
||||
{
|
||||
parser.suggestKeywords([ 'WHERE' ]);
|
||||
}
|
||||
| 'UPDATE' TargetTable 'CURSOR'
|
||||
{
|
||||
parser.suggestKeywords([ 'SET' ]);
|
||||
}
|
||||
| 'UPDATE' TargetTable_EDIT
|
||||
| 'UPDATE' TargetTable
|
||||
| 'UPDATE' 'CURSOR'
|
||||
{
|
||||
parser.suggestTables();
|
||||
parser.suggestDatabases({ appendDot: true });
|
||||
}
|
||||
;
|
||||
|
||||
TargetTable
|
||||
: TableName
|
||||
;
|
||||
|
||||
TargetTable_EDIT
|
||||
: TableName_EDIT
|
||||
;
|
||||
|
||||
TableName
|
||||
: LocalOrSchemaQualifiedName
|
||||
{
|
||||
parser.addTablePrimary($1);
|
||||
}
|
||||
;
|
||||
|
||||
TableName_EDIT
|
||||
: LocalOrSchemaQualifiedName_EDIT
|
||||
;
|
||||
|
||||
SetClauseList
|
||||
: SetClause
|
||||
| SetClauseList ',' SetClause
|
||||
;
|
||||
|
||||
SetClauseList_EDIT
|
||||
: SetClause_EDIT
|
||||
| SetClauseList ',' SetClause_EDIT
|
||||
| SetClause_EDIT ',' SetClauseList
|
||||
| SetClauseList ',' SetClause_EDIT ',' SetClauseList
|
||||
;
|
||||
|
||||
SetClause
|
||||
: SetTarget '=' UpdateSource
|
||||
;
|
||||
|
||||
SetClause_EDIT
|
||||
: SetTarget '=' UpdateSource_EDIT
|
||||
| SetTarget 'CURSOR'
|
||||
{
|
||||
parser.suggestKeywords([ '=' ]);
|
||||
}
|
||||
| 'CURSOR'
|
||||
{
|
||||
parser.suggestColumns();
|
||||
}
|
||||
;
|
||||
|
||||
SetTarget
|
||||
: ColumnReference
|
||||
;
|
||||
|
||||
UpdateSource
|
||||
: ValueExpression
|
||||
;
|
||||
|
||||
UpdateSource_EDIT
|
||||
: ValueExpression_EDIT
|
||||
;
|
||||
|
||||
OptionalFromJoinedTable
|
||||
:
|
||||
| 'FROM' TableReference -> $2
|
||||
;
|
||||
|
||||
FromJoinedTable_EDIT
|
||||
: 'FROM' 'CURSOR'
|
||||
{
|
||||
parser.suggestTables();
|
||||
parser.suggestDatabases({ appendDot: true });
|
||||
}
|
||||
| 'FROM' TableReference_EDIT
|
||||
;
|
39
src/jison/sql/calcite/sql_use.jison
Normal file
39
src/jison/sql/calcite/sql_use.jison
Normal file
@ -0,0 +1,39 @@
|
||||
// Licensed to Cloudera, Inc. under one
|
||||
// or more contributor license agreements. See the NOTICE file
|
||||
// distributed with this work for additional information
|
||||
// regarding copyright ownership. Cloudera, Inc. licenses this file
|
||||
// to you under the Apache License, Version 2.0 (the
|
||||
// "License"); you may not use this file except in compliance
|
||||
// with the License. You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
DataDefinition
|
||||
: UseStatement
|
||||
;
|
||||
|
||||
DataDefinition_EDIT
|
||||
: UseStatement_EDIT
|
||||
;
|
||||
|
||||
UseStatement
|
||||
: 'USE' RegularIdentifier
|
||||
{
|
||||
if (! parser.yy.cursorFound) {
|
||||
parser.yy.result.useDatabase = $2;
|
||||
}
|
||||
}
|
||||
;
|
||||
|
||||
UseStatement_EDIT
|
||||
: 'USE' 'CURSOR'
|
||||
{
|
||||
parser.suggestDatabases();
|
||||
}
|
||||
;
|
839
src/jison/sql/calcite/sql_valueExpression.jison
Normal file
839
src/jison/sql/calcite/sql_valueExpression.jison
Normal file
@ -0,0 +1,839 @@
|
||||
// Licensed to Cloudera, Inc. under one
|
||||
// or more contributor license agreements. See the NOTICE file
|
||||
// distributed with this work for additional information
|
||||
// regarding copyright ownership. Cloudera, Inc. licenses this file
|
||||
// to you under the Apache License, Version 2.0 (the
|
||||
// "License"); you may not use this file except in compliance
|
||||
// with the License. You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
ValueExpression
|
||||
: 'NOT' ValueExpression
|
||||
{
|
||||
// verifyType($2, 'BOOLEAN');
|
||||
$$ = { types: [ 'BOOLEAN' ] };
|
||||
}
|
||||
| '!' ValueExpression
|
||||
{
|
||||
// verifyType($2, 'BOOLEAN');
|
||||
$$ = { types: [ 'BOOLEAN' ] };
|
||||
}
|
||||
| '~' ValueExpression -> $2
|
||||
| '-' ValueExpression %prec NEGATION
|
||||
{
|
||||
// verifyType($2, 'NUMBER');
|
||||
$$ = $2;
|
||||
$2.types = ['NUMBER'];
|
||||
}
|
||||
| ValueExpression 'IS' OptionalNot 'NULL' -> { types: [ 'BOOLEAN' ] }
|
||||
| ValueExpression 'IS' OptionalNot 'TRUE' -> { types: [ 'BOOLEAN' ] }
|
||||
| ValueExpression 'IS' OptionalNot 'FALSE' -> { types: [ 'BOOLEAN' ] }
|
||||
| ValueExpression 'IS' OptionalNot 'DISTINCT' 'FROM' ValueExpression -> { types: [ 'BOOLEAN' ] }
|
||||
;
|
||||
|
||||
ValueExpression_EDIT
|
||||
: 'NOT' ValueExpression_EDIT -> { types: [ 'BOOLEAN' ], suggestFilters: $2.suggestFilters }
|
||||
| 'NOT' 'CURSOR'
|
||||
{
|
||||
parser.suggestFunctions();
|
||||
parser.suggestColumns();
|
||||
parser.suggestKeywords(['EXISTS']);
|
||||
$$ = { types: [ 'BOOLEAN' ] };
|
||||
}
|
||||
| '!' ValueExpression_EDIT -> { types: [ 'BOOLEAN' ], suggestFilters: $2.suggestFilters }
|
||||
| '!' AnyCursor
|
||||
{
|
||||
parser.suggestFunctions({ types: [ 'BOOLEAN' ] });
|
||||
parser.suggestColumns({ types: [ 'BOOLEAN' ] });
|
||||
$$ = { types: [ 'BOOLEAN' ] };
|
||||
}
|
||||
| '~' ValueExpression_EDIT -> { types: [ 'T' ], suggestFilters: $2.suggestFilters }
|
||||
| '~' 'PARTIAL_CURSOR'
|
||||
{
|
||||
parser.suggestFunctions();
|
||||
parser.suggestColumns();
|
||||
$$ = { types: [ 'T' ] };
|
||||
}
|
||||
| '-' ValueExpression_EDIT %prec NEGATION
|
||||
{
|
||||
if (!$2.typeSet) {
|
||||
parser.applyTypeToSuggestions('NUMBER');
|
||||
}
|
||||
$$ = { types: [ 'NUMBER' ], suggestFilters: $2.suggestFilters };
|
||||
}
|
||||
| '-' 'PARTIAL_CURSOR' %prec NEGATION
|
||||
{
|
||||
parser.suggestFunctions({ types: [ 'NUMBER' ] });
|
||||
parser.suggestColumns({ types: [ 'NUMBER' ] });
|
||||
$$ = { types: [ 'NUMBER' ] };
|
||||
}
|
||||
| ValueExpression 'IS' 'CURSOR'
|
||||
{
|
||||
parser.suggestKeywords(['FALSE', 'NOT NULL', 'NOT TRUE', 'NOT FALSE', 'NULL', 'TRUE']);
|
||||
$$ = { types: [ 'BOOLEAN' ] };
|
||||
}
|
||||
| ValueExpression 'IS' 'NOT' 'CURSOR'
|
||||
{
|
||||
parser.suggestKeywords(['FALSE', 'NULL', 'TRUE']);
|
||||
$$ = { types: [ 'BOOLEAN' ] };
|
||||
}
|
||||
| ValueExpression 'IS' OptionalNot 'DISTINCT' 'CURSOR'
|
||||
{
|
||||
$$ = { types: [ 'BOOLEAN' ] };
|
||||
}
|
||||
| ValueExpression 'IS' 'CURSOR' 'NULL'
|
||||
{
|
||||
parser.suggestKeywords(['NOT']);
|
||||
$$ = { types: [ 'BOOLEAN' ] };
|
||||
}
|
||||
| ValueExpression 'IS' 'CURSOR' 'FALSE'
|
||||
{
|
||||
parser.suggestKeywords(['NOT']);
|
||||
$$ = { types: [ 'BOOLEAN' ] };
|
||||
}
|
||||
| ValueExpression 'IS' 'CURSOR' 'TRUE'
|
||||
{
|
||||
parser.suggestKeywords(['NOT']);
|
||||
$$ = { types: [ 'BOOLEAN' ] };
|
||||
}
|
||||
| ValueExpression 'IS' OptionalNot 'DISTINCT' 'FROM' PartialBacktickedOrAnyCursor
|
||||
{
|
||||
parser.valueExpressionSuggest($1, $3 ? 'IS NOT DISTINCT FROM' : 'IS DISTINCT FROM');
|
||||
$$ = { types: [ 'BOOLEAN' ] };
|
||||
}
|
||||
| ValueExpression 'IS' OptionalNot 'DISTINCT' 'FROM' ValueExpression_EDIT
|
||||
{
|
||||
$$ = { types: [ 'BOOLEAN' ], suggestFilters: $6.suggestFilters }
|
||||
}
|
||||
;
|
||||
|
||||
// ------------------ EXISTS and parenthesized ------------------
|
||||
ValueExpression
|
||||
: 'EXISTS' TableSubQuery
|
||||
{
|
||||
$$ = { types: [ 'BOOLEAN' ] };
|
||||
// clear correlated flag after completed sub-query (set by lexer)
|
||||
parser.yy.correlatedSubQuery = false;
|
||||
}
|
||||
| '(' ValueExpression ')' -> $2
|
||||
;
|
||||
|
||||
ValueExpression_EDIT
|
||||
: 'EXISTS' TableSubQuery_EDIT -> { types: [ 'BOOLEAN' ] }
|
||||
| '(' ValueExpression_EDIT RightParenthesisOrError
|
||||
{
|
||||
$$ = $2;
|
||||
}
|
||||
| '(' 'CURSOR' RightParenthesisOrError
|
||||
{
|
||||
parser.valueExpressionSuggest();
|
||||
$$ = { types: ['T'], typeSet: true };
|
||||
}
|
||||
;
|
||||
|
||||
// ------------------ COMPARISON ------------------
|
||||
|
||||
ValueExpression
|
||||
: ValueExpression '=' ValueExpression
|
||||
{
|
||||
parser.addColRefToVariableIfExists($1, $3);
|
||||
$$ = { types: [ 'BOOLEAN' ] };
|
||||
}
|
||||
| ValueExpression '<' ValueExpression
|
||||
{
|
||||
parser.addColRefToVariableIfExists($1, $3);
|
||||
$$ = { types: [ 'BOOLEAN' ] };
|
||||
}
|
||||
| ValueExpression '>' ValueExpression
|
||||
{
|
||||
parser.addColRefToVariableIfExists($1, $3);
|
||||
$$ = { types: [ 'BOOLEAN' ] };
|
||||
}
|
||||
| ValueExpression 'COMPARISON_OPERATOR' ValueExpression
|
||||
{
|
||||
parser.addColRefToVariableIfExists($1, $3);
|
||||
$$ = { types: [ 'BOOLEAN' ] };
|
||||
}
|
||||
;
|
||||
|
||||
ValueExpression_EDIT
|
||||
: 'CURSOR' '=' ValueExpression
|
||||
{
|
||||
parser.valueExpressionSuggest($3, $2);
|
||||
parser.applyTypeToSuggestions($3.types);
|
||||
$$ = { types: [ 'BOOLEAN' ], typeSet: true };
|
||||
}
|
||||
| 'CURSOR' '<' ValueExpression
|
||||
{
|
||||
parser.valueExpressionSuggest($3, $2);
|
||||
parser.applyTypeToSuggestions($3.types);
|
||||
$$ = { types: [ 'BOOLEAN' ], typeSet: true };
|
||||
}
|
||||
| 'CURSOR' '>' ValueExpression
|
||||
{
|
||||
parser.valueExpressionSuggest($3, $2);
|
||||
parser.applyTypeToSuggestions($3.types);
|
||||
$$ = { types: [ 'BOOLEAN' ], typeSet: true };
|
||||
}
|
||||
| 'CURSOR' 'COMPARISON_OPERATOR' ValueExpression
|
||||
{
|
||||
parser.valueExpressionSuggest($3, $2);
|
||||
parser.applyTypeToSuggestions($3.types);
|
||||
$$ = { types: [ 'BOOLEAN' ], typeSet: true };
|
||||
}
|
||||
| ValueExpression_EDIT '=' ValueExpression
|
||||
{
|
||||
if (!$1.typeSet) {
|
||||
parser.applyTypeToSuggestions($3.types);
|
||||
parser.addColRefIfExists($3);
|
||||
}
|
||||
$$ = { types: [ 'BOOLEAN' ], suggestFilters: $1.suggestFilters }
|
||||
}
|
||||
| ValueExpression_EDIT '<' ValueExpression
|
||||
{
|
||||
if (!$1.typeSet) {
|
||||
parser.applyTypeToSuggestions($3.types);
|
||||
parser.addColRefIfExists($3);
|
||||
}
|
||||
$$ = { types: [ 'BOOLEAN' ], suggestFilters: $1.suggestFilters }
|
||||
}
|
||||
| ValueExpression_EDIT '>' ValueExpression
|
||||
{
|
||||
if (!$1.typeSet) {
|
||||
parser.applyTypeToSuggestions($3.types);
|
||||
parser.addColRefIfExists($3);
|
||||
}
|
||||
$$ = { types: [ 'BOOLEAN' ], suggestFilters: $1.suggestFilters }
|
||||
}
|
||||
| ValueExpression_EDIT 'COMPARISON_OPERATOR' ValueExpression
|
||||
{
|
||||
if (!$1.typeSet) {
|
||||
parser.applyTypeToSuggestions($3.types);
|
||||
parser.addColRefIfExists($3);
|
||||
}
|
||||
$$ = { types: [ 'BOOLEAN' ], suggestFilters: $1.suggestFilters }
|
||||
}
|
||||
| ValueExpression '=' PartialBacktickedOrAnyCursor
|
||||
{
|
||||
parser.valueExpressionSuggest($1, $2);
|
||||
parser.applyTypeToSuggestions($1.types);
|
||||
$$ = { types: [ 'BOOLEAN' ], typeSet: true };
|
||||
}
|
||||
| ValueExpression '<' PartialBacktickedOrAnyCursor
|
||||
{
|
||||
parser.valueExpressionSuggest($1, $2);
|
||||
parser.applyTypeToSuggestions($1.types);
|
||||
$$ = { types: [ 'BOOLEAN' ] , typeSet: true, endsWithLessThanOrEqual: true };
|
||||
}
|
||||
| ValueExpression '>' PartialBacktickedOrAnyCursor
|
||||
{
|
||||
parser.valueExpressionSuggest($1, $2);
|
||||
parser.applyTypeToSuggestions($1.types);
|
||||
$$ = { types: [ 'BOOLEAN' ], typeSet: true };
|
||||
}
|
||||
| ValueExpression 'COMPARISON_OPERATOR' PartialBacktickedOrAnyCursor
|
||||
{
|
||||
parser.valueExpressionSuggest($1, $2);
|
||||
parser.applyTypeToSuggestions($1.types);
|
||||
$$ = { types: [ 'BOOLEAN' ], typeSet: true, endsWithLessThanOrEqual: $2 === '<=' };
|
||||
}
|
||||
| ValueExpression '=' ValueExpression_EDIT
|
||||
{
|
||||
if (!$3.typeSet) {
|
||||
parser.applyTypeToSuggestions($1.types);
|
||||
parser.addColRefIfExists($1);
|
||||
}
|
||||
$$ = { types: [ 'BOOLEAN' ], suggestFilters: $3.suggestFilters }
|
||||
}
|
||||
| ValueExpression '<' ValueExpression_EDIT
|
||||
{
|
||||
if (!$3.typeSet) {
|
||||
parser.applyTypeToSuggestions($1.types);
|
||||
parser.addColRefIfExists($1);
|
||||
}
|
||||
$$ = { types: [ 'BOOLEAN' ], suggestFilters: $3.suggestFilters }
|
||||
}
|
||||
| ValueExpression '>' ValueExpression_EDIT
|
||||
{
|
||||
if (!$3.typeSet) {
|
||||
parser.applyTypeToSuggestions($1.types);
|
||||
parser.addColRefIfExists($1);
|
||||
}
|
||||
$$ = { types: [ 'BOOLEAN' ], suggestFilters: $3.suggestFilters }
|
||||
}
|
||||
| ValueExpression 'COMPARISON_OPERATOR' ValueExpression_EDIT
|
||||
{
|
||||
if (!$3.typeSet) {
|
||||
parser.applyTypeToSuggestions($1.types);
|
||||
parser.addColRefIfExists($1);
|
||||
}
|
||||
$$ = { types: [ 'BOOLEAN' ], suggestFilters: $3.suggestFilters }
|
||||
}
|
||||
;
|
||||
|
||||
|
||||
// ------------------ IN ------------------
|
||||
|
||||
ValueExpression
|
||||
: ValueExpression 'NOT' 'IN' '(' TableSubQueryInner ')' -> { types: [ 'BOOLEAN' ] }
|
||||
| ValueExpression 'NOT' 'IN' '(' ValueExpressionList ')' -> { types: [ 'BOOLEAN' ] }
|
||||
| ValueExpression 'IN' '(' TableSubQueryInner ')' -> { types: [ 'BOOLEAN' ] }
|
||||
| ValueExpression 'IN' '(' ValueExpressionList ')' -> { types: [ 'BOOLEAN' ] }
|
||||
;
|
||||
|
||||
ValueExpression_EDIT
|
||||
: ValueExpression 'NOT' 'IN' ValueExpressionInSecondPart_EDIT
|
||||
{
|
||||
if ($4.inValueEdit) {
|
||||
parser.valueExpressionSuggest($1, $2 + ' ' + $3);
|
||||
parser.applyTypeToSuggestions($1.types);
|
||||
}
|
||||
if ($4.cursorAtStart) {
|
||||
parser.suggestKeywords(['SELECT']);
|
||||
}
|
||||
$$ = { types: [ 'BOOLEAN' ], typeSet: true };
|
||||
}
|
||||
| ValueExpression 'IN' ValueExpressionInSecondPart_EDIT
|
||||
{
|
||||
if ($3.inValueEdit) {
|
||||
parser.valueExpressionSuggest($1, $2);
|
||||
parser.applyTypeToSuggestions($1.types);
|
||||
}
|
||||
if ($3.cursorAtStart) {
|
||||
parser.suggestKeywords(['SELECT']);
|
||||
}
|
||||
$$ = { types: [ 'BOOLEAN' ], typeSet: true };
|
||||
}
|
||||
| ValueExpression_EDIT 'NOT' 'IN' '(' ValueExpressionList RightParenthesisOrError -> { types: [ 'BOOLEAN' ], suggestFilters: $1.suggestFilters }
|
||||
| ValueExpression_EDIT 'NOT' 'IN' '(' TableSubQueryInner RightParenthesisOrError -> { types: [ 'BOOLEAN' ], suggestFilters: $1.suggestFilters }
|
||||
| ValueExpression_EDIT 'IN' '(' ValueExpressionList RightParenthesisOrError -> { types: [ 'BOOLEAN' ], suggestFilters: $1.suggestFilters }
|
||||
| ValueExpression_EDIT 'IN' '(' TableSubQueryInner RightParenthesisOrError -> { types: [ 'BOOLEAN' ], suggestFilters: $1.suggestFilters }
|
||||
;
|
||||
|
||||
ValueExpressionInSecondPart_EDIT
|
||||
: '(' TableSubQueryInner_EDIT RightParenthesisOrError
|
||||
| '(' ValueExpressionList_EDIT RightParenthesisOrError -> { inValueEdit: true }
|
||||
| '(' AnyCursor RightParenthesisOrError -> { inValueEdit: true, cursorAtStart: true }
|
||||
;
|
||||
|
||||
// ------------------ BETWEEN ------------------
|
||||
|
||||
ValueExpression
|
||||
: ValueExpression 'NOT' 'BETWEEN' ValueExpression 'BETWEEN_AND' ValueExpression -> { types: [ 'BOOLEAN' ] }
|
||||
| ValueExpression 'BETWEEN' ValueExpression 'BETWEEN_AND' ValueExpression -> { types: [ 'BOOLEAN' ] }
|
||||
;
|
||||
|
||||
ValueExpression_EDIT
|
||||
: ValueExpression_EDIT 'NOT' 'BETWEEN' ValueExpression 'BETWEEN_AND' ValueExpression
|
||||
{
|
||||
if ($4.types[0] === $6.types[0] && !$1.typeSet) {
|
||||
parser.applyTypeToSuggestions($4.types);
|
||||
}
|
||||
$$ = { types: [ 'BOOLEAN' ], suggestFilters: $1.suggestFilters };
|
||||
}
|
||||
| ValueExpression 'NOT' 'BETWEEN' ValueExpression_EDIT 'BETWEEN_AND' ValueExpression
|
||||
{
|
||||
if ($1.types[0] === $6.types[0] && !$4.typeSet) {
|
||||
parser.applyTypeToSuggestions($1.types);
|
||||
}
|
||||
$$ = { types: [ 'BOOLEAN' ], suggestFilters: $4.suggestFilters };
|
||||
}
|
||||
| ValueExpression 'NOT' 'BETWEEN' ValueExpression 'BETWEEN_AND' ValueExpression_EDIT
|
||||
{
|
||||
if ($1.types[0] === $4.types[0] && !$6.typeSet) {
|
||||
parser.applyTypeToSuggestions($1.types);
|
||||
}
|
||||
$$ = { types: [ 'BOOLEAN' ], suggestFilters: $6.suggestFilters };
|
||||
}
|
||||
| ValueExpression 'NOT' 'BETWEEN' ValueExpression 'BETWEEN_AND' 'CURSOR'
|
||||
{
|
||||
parser.valueExpressionSuggest($1, $5);
|
||||
$$ = { types: [ 'BOOLEAN' ], typeSet: true };
|
||||
}
|
||||
| ValueExpression 'NOT' 'BETWEEN' ValueExpression 'CURSOR'
|
||||
{
|
||||
parser.suggestValueExpressionKeywords($4, ['AND']);
|
||||
$$ = { types: [ 'BOOLEAN' ] };
|
||||
}
|
||||
| ValueExpression 'NOT' 'BETWEEN' 'CURSOR'
|
||||
{
|
||||
parser.valueExpressionSuggest($1, $2 + ' ' + $3);
|
||||
$$ = { types: [ 'BOOLEAN' ], typeSet: true };
|
||||
}
|
||||
| ValueExpression_EDIT 'BETWEEN' ValueExpression 'BETWEEN_AND' ValueExpression
|
||||
{
|
||||
if ($1.types[0] === $3.types[0] && !$1.typeSet) {
|
||||
parser.applyTypeToSuggestions($1.types)
|
||||
}
|
||||
$$ = { types: [ 'BOOLEAN' ], suggestFilters: $1.suggestFilters };
|
||||
}
|
||||
| ValueExpression 'BETWEEN' ValueExpression_EDIT 'BETWEEN_AND' ValueExpression
|
||||
{
|
||||
if ($1.types[0] === $3.types[0] && !$3.typeSet) {
|
||||
parser.applyTypeToSuggestions($1.types)
|
||||
}
|
||||
$$ = { types: [ 'BOOLEAN' ], suggestFilters: $3.suggestFilters };
|
||||
}
|
||||
| ValueExpression 'BETWEEN' ValueExpression 'BETWEEN_AND' ValueExpression_EDIT
|
||||
{
|
||||
if ($1.types[0] === $3.types[0] && !$5.typeSet) {
|
||||
parser.applyTypeToSuggestions($1.types)
|
||||
}
|
||||
$$ = { types: [ 'BOOLEAN' ], suggestFilters: $5.suggestFilters };
|
||||
}
|
||||
| ValueExpression 'BETWEEN' ValueExpression 'BETWEEN_AND' 'CURSOR'
|
||||
{
|
||||
parser.valueExpressionSuggest($1, $4);
|
||||
parser.applyTypeToSuggestions($1.types);
|
||||
$$ = { types: [ 'BOOLEAN' ], typeSet: true };
|
||||
}
|
||||
| ValueExpression 'BETWEEN' ValueExpression 'CURSOR'
|
||||
{
|
||||
parser.suggestValueExpressionKeywords($3, ['AND']);
|
||||
$$ = { types: [ 'BOOLEAN' ] };
|
||||
}
|
||||
| ValueExpression 'BETWEEN' 'CURSOR'
|
||||
{
|
||||
parser.valueExpressionSuggest($1, $2);
|
||||
parser.applyTypeToSuggestions($1.types);
|
||||
$$ = { types: [ 'BOOLEAN' ], typeSet: true };
|
||||
}
|
||||
;
|
||||
|
||||
// ------------------ BOOLEAN ------------------
|
||||
|
||||
ValueExpression
|
||||
: ValueExpression 'OR' ValueExpression
|
||||
{
|
||||
// verifyType($1, 'BOOLEAN');
|
||||
// verifyType($3, 'BOOLEAN');
|
||||
$$ = { types: [ 'BOOLEAN' ] };
|
||||
}
|
||||
| ValueExpression 'AND' ValueExpression
|
||||
{
|
||||
// verifyType($1, 'BOOLEAN');
|
||||
// verifyType($3, 'BOOLEAN');
|
||||
$$ = { types: [ 'BOOLEAN' ] };
|
||||
}
|
||||
;
|
||||
|
||||
ValueExpression_EDIT
|
||||
: 'CURSOR' 'OR' ValueExpression
|
||||
{
|
||||
parser.valueExpressionSuggest(undefined, $2);
|
||||
$$ = { types: [ 'BOOLEAN' ], typeSet: true, suggestFilters: true };
|
||||
}
|
||||
| ValueExpression_EDIT 'OR' ValueExpression
|
||||
{
|
||||
parser.addColRefIfExists($3);
|
||||
$$ = { types: [ 'BOOLEAN' ], suggestFilters: $1.suggestFilters }
|
||||
}
|
||||
| ValueExpression 'OR' PartialBacktickedOrAnyCursor
|
||||
{
|
||||
parser.valueExpressionSuggest(undefined, $2);
|
||||
$$ = { types: [ 'BOOLEAN' ], typeSet: true, suggestFilters: true };
|
||||
}
|
||||
| ValueExpression 'OR' ValueExpression_EDIT
|
||||
{
|
||||
parser.addColRefIfExists($1);
|
||||
$$ = { types: [ 'BOOLEAN' ], suggestFilters: $3.suggestFilters }
|
||||
}
|
||||
| 'CURSOR' 'AND' ValueExpression
|
||||
{
|
||||
parser.valueExpressionSuggest(undefined, $2);
|
||||
$$ = { types: [ 'BOOLEAN' ], typeSet: true, suggestFilters: true };
|
||||
}
|
||||
| ValueExpression_EDIT 'AND' ValueExpression
|
||||
{
|
||||
parser.addColRefIfExists($3);
|
||||
$$ = { types: [ 'BOOLEAN' ], suggestFilters: $1.suggestFilters }
|
||||
}
|
||||
| ValueExpression 'AND' PartialBacktickedOrAnyCursor
|
||||
{
|
||||
parser.valueExpressionSuggest(undefined, $2);
|
||||
$$ = { types: [ 'BOOLEAN' ], typeSet: true, suggestFilters: true };
|
||||
}
|
||||
| ValueExpression 'AND' ValueExpression_EDIT
|
||||
{
|
||||
parser.addColRefIfExists($1);
|
||||
$$ = { types: [ 'BOOLEAN' ], suggestFilters: $3.suggestFilters }
|
||||
}
|
||||
;
|
||||
|
||||
// ------------------ ARITHMETIC ------------------
|
||||
|
||||
ValueExpression
|
||||
: ValueExpression '-' ValueExpression
|
||||
{
|
||||
// verifyType($1, 'NUMBER');
|
||||
// verifyType($3, 'NUMBER');
|
||||
$$ = { types: [ 'NUMBER' ] };
|
||||
}
|
||||
| ValueExpression '*' ValueExpression
|
||||
{
|
||||
// verifyType($1, 'NUMBER');
|
||||
// verifyType($3, 'NUMBER');
|
||||
$$ = { types: [ 'NUMBER' ] };
|
||||
}
|
||||
| ValueExpression 'ARITHMETIC_OPERATOR' ValueExpression
|
||||
{
|
||||
// verifyType($1, 'NUMBER');
|
||||
// verifyType($3, 'NUMBER');
|
||||
$$ = { types: [ 'NUMBER' ] };
|
||||
}
|
||||
;
|
||||
|
||||
ValueExpression_EDIT
|
||||
: 'CURSOR' '*' ValueExpression
|
||||
{
|
||||
parser.valueExpressionSuggest(undefined, $2);
|
||||
parser.applyTypeToSuggestions([ 'NUMBER' ]);
|
||||
$$ = { types: [ 'NUMBER' ], typeSet: true };
|
||||
}
|
||||
| 'CURSOR' 'ARITHMETIC_OPERATOR' ValueExpression
|
||||
{
|
||||
parser.valueExpressionSuggest(undefined, $2);
|
||||
parser.applyTypeToSuggestions([ 'NUMBER' ]);
|
||||
$$ = { types: [ 'NUMBER' ], typeSet: true };
|
||||
}
|
||||
| ValueExpression_EDIT '-' ValueExpression
|
||||
{
|
||||
if (!$1.typeSet) {
|
||||
parser.applyTypeToSuggestions(['NUMBER']);
|
||||
parser.addColRefIfExists($3);
|
||||
}
|
||||
$$ = { types: [ 'NUMBER' ], suggestFilters: $1.suggestFilters }
|
||||
}
|
||||
| ValueExpression_EDIT '*' ValueExpression
|
||||
{
|
||||
if (!$1.typeSet) {
|
||||
parser.applyTypeToSuggestions(['NUMBER']);
|
||||
parser.addColRefIfExists($3);
|
||||
}
|
||||
$$ = { types: [ 'NUMBER' ], suggestFilters: $1.suggestFilters }
|
||||
}
|
||||
| ValueExpression_EDIT 'ARITHMETIC_OPERATOR' ValueExpression
|
||||
{
|
||||
if (!$1.typeSet) {
|
||||
parser.applyTypeToSuggestions(['NUMBER']);
|
||||
parser.addColRefIfExists($3);
|
||||
}
|
||||
$$ = { types: [ 'NUMBER' ], suggestFilters: $1.suggestFilters }
|
||||
}
|
||||
| ValueExpression '-' PartialBacktickedOrAnyCursor
|
||||
{
|
||||
parser.valueExpressionSuggest(undefined, $2);
|
||||
parser.applyTypeToSuggestions(['NUMBER']);
|
||||
$$ = { types: [ 'NUMBER' ], typeSet: true };
|
||||
}
|
||||
| ValueExpression '*' PartialBacktickedOrAnyCursor
|
||||
{
|
||||
parser.valueExpressionSuggest(undefined, $2);
|
||||
parser.applyTypeToSuggestions(['NUMBER']);
|
||||
$$ = { types: [ 'NUMBER' ], typeSet: true };
|
||||
}
|
||||
| ValueExpression 'ARITHMETIC_OPERATOR' PartialBacktickedOrAnyCursor
|
||||
{
|
||||
parser.valueExpressionSuggest(undefined, $2);
|
||||
parser.applyTypeToSuggestions(['NUMBER']);
|
||||
$$ = { types: [ 'NUMBER' ], typeSet: true };
|
||||
}
|
||||
| ValueExpression '-' ValueExpression_EDIT
|
||||
{
|
||||
if (!$3.typeSet) {
|
||||
parser.applyTypeToSuggestions(['NUMBER']);
|
||||
parser.addColRefIfExists($1);
|
||||
}
|
||||
$$ = { types: [ 'NUMBER' ], suggestFilters: $3.suggestFilters };
|
||||
}
|
||||
| ValueExpression '*' ValueExpression_EDIT
|
||||
{
|
||||
if (!$3.typeSet) {
|
||||
parser.applyTypeToSuggestions(['NUMBER']);
|
||||
parser.addColRefIfExists($1);
|
||||
}
|
||||
$$ = { types: [ 'NUMBER' ], suggestFilters: $3.suggestFilters };
|
||||
}
|
||||
| ValueExpression 'ARITHMETIC_OPERATOR' ValueExpression_EDIT
|
||||
{
|
||||
if (!$3.typeSet) {
|
||||
parser.applyTypeToSuggestions(['NUMBER']);
|
||||
parser.addColRefIfExists($1);
|
||||
}
|
||||
$$ = { types: [ 'NUMBER' ], suggestFilters: $3.suggestFilters };
|
||||
}
|
||||
;
|
||||
|
||||
// ------------------ LIKE, RLIKE and REGEXP ------------------
|
||||
|
||||
ValueExpression
|
||||
: ValueExpression LikeRightPart -> { types: [ 'BOOLEAN' ] }
|
||||
| ValueExpression 'NOT' LikeRightPart -> { types: [ 'BOOLEAN' ] }
|
||||
;
|
||||
|
||||
LikeRightPart
|
||||
: 'LIKE' ValueExpression -> { suggestKeywords: ['NOT'] }
|
||||
| 'RLIKE' ValueExpression -> { suggestKeywords: ['NOT'] }
|
||||
| 'REGEXP' ValueExpression -> { suggestKeywords: ['NOT'] }
|
||||
;
|
||||
|
||||
LikeRightPart_EDIT
|
||||
: 'LIKE' ValueExpression_EDIT
|
||||
| 'RLIKE' ValueExpression_EDIT
|
||||
| 'REGEXP' ValueExpression_EDIT
|
||||
| 'LIKE' PartialBacktickedOrCursor
|
||||
{
|
||||
parser.suggestFunctions({ types: [ 'STRING' ] });
|
||||
parser.suggestColumns({ types: [ 'STRING' ] });
|
||||
$$ = { types: ['BOOLEAN'] }
|
||||
}
|
||||
| 'RLIKE' PartialBacktickedOrCursor
|
||||
{
|
||||
parser.suggestFunctions({ types: [ 'STRING' ] });
|
||||
parser.suggestColumns({ types: [ 'STRING' ] });
|
||||
$$ = { types: ['BOOLEAN'] }
|
||||
}
|
||||
| 'REGEXP' PartialBacktickedOrCursor
|
||||
{
|
||||
parser.suggestFunctions({ types: [ 'STRING' ] });
|
||||
parser.suggestColumns({ types: [ 'STRING' ] });
|
||||
$$ = { types: ['BOOLEAN'] }
|
||||
}
|
||||
;
|
||||
|
||||
ValueExpression_EDIT
|
||||
: ValueExpression_EDIT LikeRightPart -> { types: [ 'BOOLEAN' ], suggestFilters: $1.suggestFilters }
|
||||
| ValueExpression_EDIT 'NOT' LikeRightPart -> { types: [ 'BOOLEAN' ], suggestFilters: $1.suggestFilters }
|
||||
| ValueExpression LikeRightPart_EDIT -> { types: [ 'BOOLEAN' ] }
|
||||
| ValueExpression 'NOT' LikeRightPart_EDIT -> { types: [ 'BOOLEAN' ] }
|
||||
| 'CURSOR' LikeRightPart
|
||||
{
|
||||
parser.valueExpressionSuggest(undefined, $2);
|
||||
parser.applyTypeToSuggestions([ 'STRING' ]);
|
||||
$$ = { types: [ 'BOOLEAN' ], typeSet: true };
|
||||
}
|
||||
| 'CURSOR' 'NOT' LikeRightPart
|
||||
{
|
||||
parser.valueExpressionSuggest(undefined, $2 + ' ' + $3);
|
||||
parser.applyTypeToSuggestions([ 'STRING' ]);
|
||||
$$ = { types: [ 'BOOLEAN' ], typeSet: true };
|
||||
}
|
||||
;
|
||||
|
||||
// ------------------ CASE, WHEN, THEN ------------------
|
||||
|
||||
ValueExpression
|
||||
: 'CASE' CaseRightPart -> $2
|
||||
| 'CASE' ValueExpression CaseRightPart -> $3
|
||||
;
|
||||
|
||||
ValueExpression_EDIT
|
||||
: 'CASE' CaseRightPart_EDIT -> $2
|
||||
| 'CASE' 'CURSOR' EndOrError
|
||||
{
|
||||
parser.valueExpressionSuggest();
|
||||
parser.suggestKeywords(['WHEN']);
|
||||
$$ = { types: [ 'T' ], typeSet: true };
|
||||
}
|
||||
| 'CASE' ValueExpression CaseRightPart_EDIT -> $3
|
||||
| 'CASE' ValueExpression 'CURSOR' EndOrError
|
||||
{
|
||||
parser.suggestValueExpressionKeywords($2, ['WHEN']);
|
||||
$$ = { types: [ 'T' ], typeSet: true };
|
||||
}
|
||||
| 'CASE' ValueExpression_EDIT CaseRightPart
|
||||
{
|
||||
$$ = $3;
|
||||
$$.suggestFilters = $2.suggestFilters;
|
||||
}
|
||||
| 'CASE' ValueExpression_EDIT EndOrError -> { types: [ 'T' ], suggestFilters: $2.suggestFilters }
|
||||
| 'CASE' 'CURSOR' CaseRightPart -> { types: [ 'T' ] }
|
||||
;
|
||||
|
||||
CaseRightPart
|
||||
: CaseWhenThenList 'END' -> parser.findCaseType($1)
|
||||
| CaseWhenThenList 'ELSE' ValueExpression 'END'
|
||||
{
|
||||
$1.caseTypes.push($3);
|
||||
$$ = parser.findCaseType($1);
|
||||
}
|
||||
;
|
||||
|
||||
CaseRightPart_EDIT
|
||||
: CaseWhenThenList_EDIT EndOrError -> parser.findCaseType($1)
|
||||
| CaseWhenThenList 'ELSE' ValueExpression 'CURSOR'
|
||||
{
|
||||
parser.suggestValueExpressionKeywords($3, ['END']);
|
||||
$1.caseTypes.push($3);
|
||||
$$ = parser.findCaseType($1);
|
||||
}
|
||||
| CaseWhenThenList_EDIT 'ELSE' ValueExpression EndOrError
|
||||
{
|
||||
$1.caseTypes.push($3);
|
||||
$$ = parser.findCaseType($1);
|
||||
}
|
||||
| CaseWhenThenList_EDIT 'ELSE' EndOrError -> parser.findCaseType($1)
|
||||
| CaseWhenThenList 'CURSOR' ValueExpression EndOrError
|
||||
{
|
||||
if ($4.toLowerCase() !== 'end') {
|
||||
parser.suggestValueExpressionKeywords($1, [{ value: 'END', weight: 3 }, { value: 'ELSE', weight: 2 }, { value: 'WHEN', weight: 1 }]);
|
||||
} else {
|
||||
parser.suggestValueExpressionKeywords($1, [{ value: 'ELSE', weight: 2 }, { value: 'WHEN', weight: 1 }]);
|
||||
}
|
||||
$$ = parser.findCaseType($1);
|
||||
}
|
||||
| CaseWhenThenList 'CURSOR' EndOrError
|
||||
{
|
||||
if ($3.toLowerCase() !== 'end') {
|
||||
parser.suggestValueExpressionKeywords($1, [{ value: 'END', weight: 3 }, { value: 'ELSE', weight: 2 }, { value: 'WHEN', weight: 1 }]);
|
||||
} else {
|
||||
parser.suggestValueExpressionKeywords($1, [{ value: 'ELSE', weight: 2 }, { value: 'WHEN', weight: 1 }]);
|
||||
}
|
||||
$$ = parser.findCaseType($1);
|
||||
}
|
||||
| CaseWhenThenList 'ELSE' ValueExpression_EDIT EndOrError
|
||||
{
|
||||
$1.caseTypes.push($3);
|
||||
$$ = parser.findCaseType($1);
|
||||
$$.suggestFilters = $3.suggestFilters
|
||||
}
|
||||
| CaseWhenThenList 'ELSE' 'CURSOR' EndOrError
|
||||
{
|
||||
parser.valueExpressionSuggest();
|
||||
$$ = parser.findCaseType($1);
|
||||
}
|
||||
| 'ELSE' 'CURSOR' EndOrError
|
||||
{
|
||||
parser.valueExpressionSuggest();
|
||||
$$ = { types: [ 'T' ], typeSet: true };
|
||||
}
|
||||
| 'CURSOR' 'ELSE' ValueExpression EndOrError
|
||||
{
|
||||
parser.valueExpressionSuggest();
|
||||
parser.suggestKeywords(['WHEN']);
|
||||
$$ = $3;
|
||||
}
|
||||
| 'CURSOR' 'ELSE' EndOrError
|
||||
{
|
||||
parser.valueExpressionSuggest();
|
||||
parser.suggestKeywords(['WHEN']);
|
||||
$$ = { types: [ 'T' ] };
|
||||
}
|
||||
;
|
||||
|
||||
EndOrError
|
||||
: 'END'
|
||||
| error
|
||||
;
|
||||
|
||||
CaseWhenThenList
|
||||
: CaseWhenThenListPartTwo -> { caseTypes: [ $1 ], lastType: $1 }
|
||||
| CaseWhenThenList CaseWhenThenListPartTwo
|
||||
{
|
||||
$1.caseTypes.push($2);
|
||||
$$ = { caseTypes: $1.caseTypes, lastType: $2 };
|
||||
}
|
||||
;
|
||||
|
||||
CaseWhenThenList_EDIT
|
||||
: CaseWhenThenListPartTwo_EDIT
|
||||
| CaseWhenThenList CaseWhenThenListPartTwo_EDIT
|
||||
| CaseWhenThenList CaseWhenThenListPartTwo_EDIT CaseWhenThenList
|
||||
| CaseWhenThenList 'CURSOR' CaseWhenThenList
|
||||
{
|
||||
parser.suggestValueExpressionKeywords($1, ['WHEN']);
|
||||
}
|
||||
| CaseWhenThenListPartTwo_EDIT CaseWhenThenList -> $2
|
||||
;
|
||||
|
||||
CaseWhenThenListPartTwo
|
||||
: 'WHEN' ValueExpression 'THEN' ValueExpression -> $4
|
||||
;
|
||||
|
||||
CaseWhenThenListPartTwo_EDIT
|
||||
: 'WHEN' ValueExpression_EDIT -> { caseTypes: [{ types: ['T'] }], suggestFilters: $2.suggestFilters }
|
||||
| 'WHEN' ValueExpression_EDIT 'THEN' -> { caseTypes: [{ types: ['T'] }], suggestFilters: $2.suggestFilters }
|
||||
| 'WHEN' ValueExpression_EDIT 'THEN' ValueExpression -> { caseTypes: [$4], suggestFilters: $2.suggestFilters }
|
||||
| 'WHEN' ValueExpression 'THEN' ValueExpression_EDIT -> { caseTypes: [$4], suggestFilters: $4.suggestFilters }
|
||||
| 'WHEN' 'THEN' ValueExpression_EDIT -> { caseTypes: [$3], suggestFilters: $3.suggestFilters }
|
||||
| 'CURSOR' ValueExpression 'THEN'
|
||||
{
|
||||
parser.suggestKeywords(['WHEN']);
|
||||
$$ = { caseTypes: [{ types: ['T'] }] };
|
||||
}
|
||||
| 'CURSOR' ValueExpression 'THEN' ValueExpression
|
||||
{
|
||||
parser.suggestKeywords(['WHEN']);
|
||||
$$ = { caseTypes: [$4] };
|
||||
}
|
||||
| 'CURSOR' 'THEN'
|
||||
{
|
||||
parser.valueExpressionSuggest();
|
||||
parser.suggestKeywords(['WHEN']);
|
||||
$$ = { caseTypes: [{ types: ['T'] }] };
|
||||
}
|
||||
| 'CURSOR' 'THEN' ValueExpression
|
||||
{
|
||||
parser.valueExpressionSuggest();
|
||||
parser.suggestKeywords(['WHEN']);
|
||||
$$ = { caseTypes: [{ types: ['T'] }] };
|
||||
}
|
||||
| 'WHEN' 'CURSOR'
|
||||
{
|
||||
parser.valueExpressionSuggest();
|
||||
$$ = { caseTypes: [{ types: ['T'] }], suggestFilters: true };
|
||||
}
|
||||
| 'WHEN' 'CURSOR' ValueExpression
|
||||
{
|
||||
parser.valueExpressionSuggest();
|
||||
parser.suggestKeywords(['THEN']);
|
||||
$$ = { caseTypes: [{ types: ['T'] }], suggestFilters: true };
|
||||
}
|
||||
| 'WHEN' 'CURSOR' 'THEN'
|
||||
{
|
||||
parser.valueExpressionSuggest();
|
||||
$$ = { caseTypes: [{ types: ['T'] }], suggestFilters: true };
|
||||
}
|
||||
| 'WHEN' 'CURSOR' 'THEN' ValueExpression
|
||||
{
|
||||
parser.valueExpressionSuggest();
|
||||
$$ = { caseTypes: [$4], suggestFilters: true };
|
||||
}
|
||||
| 'WHEN' ValueExpression 'CURSOR'
|
||||
{
|
||||
parser.suggestValueExpressionKeywords($2, ['THEN']);
|
||||
$$ = { caseTypes: [{ types: ['T'] }] };
|
||||
}
|
||||
| 'WHEN' ValueExpression 'CURSOR' ValueExpression
|
||||
{
|
||||
parser.suggestValueExpressionKeywords($2, ['THEN']);
|
||||
$$ = { caseTypes: [{ types: ['T'] }] };
|
||||
}
|
||||
| 'WHEN' ValueExpression 'THEN' 'CURSOR'
|
||||
{
|
||||
parser.valueExpressionSuggest();
|
||||
$$ = { caseTypes: [{ types: ['T'] }] };
|
||||
}
|
||||
| 'WHEN' ValueExpression 'THEN' 'CURSOR' ValueExpression
|
||||
{
|
||||
parser.valueExpressionSuggest();
|
||||
$$ = { caseTypes: [{ types: ['T'] }] };
|
||||
}
|
||||
| 'WHEN' 'THEN' 'CURSOR' ValueExpression
|
||||
{
|
||||
parser.valueExpressionSuggest();
|
||||
$$ = { caseTypes: [{ types: ['T'] }] };
|
||||
}
|
||||
| 'WHEN' 'THEN' 'CURSOR'
|
||||
{
|
||||
parser.valueExpressionSuggest();
|
||||
$$ = { caseTypes: [{ types: ['T'] }] };
|
||||
}
|
||||
;
|
19
src/jison/sql/calcite/syntax_footer.jison
Normal file
19
src/jison/sql/calcite/syntax_footer.jison
Normal file
@ -0,0 +1,19 @@
|
||||
// Licensed to Cloudera, Inc. under one
|
||||
// or more contributor license agreements. See the NOTICE file
|
||||
// distributed with this work for additional information
|
||||
// regarding copyright ownership. Cloudera, Inc. licenses this file
|
||||
// to you under the Apache License, Version 2.0 (the
|
||||
// "License"); you may not use this file except in compliance
|
||||
// with the License. You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
%%
|
||||
|
||||
SqlParseSupport.initSyntaxParser(parser);
|
28
src/jison/sql/calcite/syntax_header.jison
Normal file
28
src/jison/sql/calcite/syntax_header.jison
Normal file
@ -0,0 +1,28 @@
|
||||
// Licensed to Cloudera, Inc. under one
|
||||
// or more contributor license agreements. See the NOTICE file
|
||||
// distributed with this work for additional information
|
||||
// regarding copyright ownership. Cloudera, Inc. licenses this file
|
||||
// to you under the Apache License, Version 2.0 (the
|
||||
// "License"); you may not use this file except in compliance
|
||||
// with the License. You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
%left 'AND' 'OR'
|
||||
%left 'BETWEEN'
|
||||
%left 'NOT' '!' '~'
|
||||
%left '=' '<' '>' 'COMPARISON_OPERATOR'
|
||||
%left '-' '*' 'ARITHMETIC_OPERATOR'
|
||||
|
||||
%left ';' ','
|
||||
%nonassoc 'IN' 'IS' 'LIKE' 'RLIKE' 'REGEXP' 'EXISTS' NEGATION
|
||||
|
||||
%start SqlSyntax
|
||||
|
||||
%%
|
19
src/jison/sql/druid/autocomplete_footer.jison
Normal file
19
src/jison/sql/druid/autocomplete_footer.jison
Normal file
@ -0,0 +1,19 @@
|
||||
// Licensed to Cloudera, Inc. under one
|
||||
// or more contributor license agreements. See the NOTICE file
|
||||
// distributed with this work for additional information
|
||||
// regarding copyright ownership. Cloudera, Inc. licenses this file
|
||||
// to you under the Apache License, Version 2.0 (the
|
||||
// "License"); you may not use this file except in compliance
|
||||
// with the License. You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
%%
|
||||
|
||||
SqlParseSupport.initSqlParser(parser);
|
29
src/jison/sql/druid/autocomplete_header.jison
Normal file
29
src/jison/sql/druid/autocomplete_header.jison
Normal file
@ -0,0 +1,29 @@
|
||||
// Licensed to Cloudera, Inc. under one
|
||||
// or more contributor license agreements. See the NOTICE file
|
||||
// distributed with this work for additional information
|
||||
// regarding copyright ownership. Cloudera, Inc. licenses this file
|
||||
// to you under the Apache License, Version 2.0 (the
|
||||
// "License"); you may not use this file except in compliance
|
||||
// with the License. You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
%left 'AND' 'OR'
|
||||
%left 'BETWEEN'
|
||||
%left 'NOT' '!' '~'
|
||||
%left '=' '<' '>' 'COMPARISON_OPERATOR'
|
||||
%left '-' '*' 'ARITHMETIC_OPERATOR'
|
||||
|
||||
%left ';' ','
|
||||
%nonassoc 'CURSOR' 'PARTIAL_CURSOR'
|
||||
%nonassoc 'IN' 'IS' 'LIKE' 'RLIKE' 'REGEXP' 'EXISTS' NEGATION
|
||||
|
||||
%start SqlAutocomplete
|
||||
|
||||
%%
|
226
src/jison/sql/druid/sql.jisonlex
Normal file
226
src/jison/sql/druid/sql.jisonlex
Normal file
@ -0,0 +1,226 @@
|
||||
// Licensed to Cloudera, Inc. under one
|
||||
// or more contributor license agreements. See the NOTICE file
|
||||
// distributed with this work for additional information
|
||||
// regarding copyright ownership. Cloudera, Inc. licenses this file
|
||||
// to you under the Apache License, Version 2.0 (the
|
||||
// "License"); you may not use this file except in compliance
|
||||
// with the License. You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
%options case-insensitive flex
|
||||
%s between
|
||||
%x hdfs doubleQuotedValue singleQuotedValue backtickedValue
|
||||
%%
|
||||
|
||||
\s { /* skip whitespace */ }
|
||||
'--'.* { /* skip comments */ }
|
||||
[/][*][^*]*[*]+([^/*][^*]*[*]+)*[/] { /* skip comments */ }
|
||||
|
||||
'\u2020' { parser.yy.partialCursor = false; parser.yy.cursorFound = yylloc; return 'CURSOR'; }
|
||||
'\u2021' { parser.yy.partialCursor = true; parser.yy.cursorFound = yylloc; return 'PARTIAL_CURSOR'; }
|
||||
|
||||
<between>'AND' { this.popState(); return 'BETWEEN_AND'; }
|
||||
|
||||
// Reserved Keywords
|
||||
'ALL' { return 'ALL'; }
|
||||
'ALTER' { parser.determineCase(yytext); parser.addStatementTypeLocation('ALTER', yylloc, yy.lexer.upcomingInput()); return 'ALTER'; }
|
||||
'AND' { return 'AND'; }
|
||||
'AS' { return 'AS'; }
|
||||
'ASC' { return 'ASC'; }
|
||||
'BETWEEN' { this.begin('between'); return 'BETWEEN'; }
|
||||
'BIGINT' { return 'BIGINT'; }
|
||||
'BOOLEAN' { return 'BOOLEAN'; }
|
||||
'BY' { return 'BY'; }
|
||||
'CASCADE' { return 'CASCADE'; }
|
||||
'CASE' { return 'CASE'; }
|
||||
'CHAR' { return 'CHAR'; }
|
||||
'COMMENT' { return 'COMMENT'; }
|
||||
'CREATE' { parser.determineCase(yytext); return 'CREATE'; }
|
||||
'CROSS' { return 'CROSS'; }
|
||||
'CURRENT' { return 'CURRENT'; }
|
||||
'DATABASE' { return 'DATABASE'; }
|
||||
'DECIMAL' { return 'DECIMAL'; }
|
||||
'DESC' { return 'DESC'; }
|
||||
'DISTINCT' { return 'DISTINCT'; }
|
||||
'DIV' { return 'ARITHMETIC_OPERATOR'; }
|
||||
'DOUBLE' { return 'DOUBLE'; }
|
||||
'DROP' { parser.determineCase(yytext); parser.addStatementTypeLocation('DROP', yylloc, yy.lexer.upcomingInput()); return 'DROP'; }
|
||||
'ELSE' { return 'ELSE'; }
|
||||
'END' { return 'END'; }
|
||||
'EXISTS' { parser.yy.correlatedSubQuery = true; return 'EXISTS'; }
|
||||
'FALSE' { return 'FALSE'; }
|
||||
'FLOAT' { return 'FLOAT'; }
|
||||
'FOLLOWING' { return 'FOLLOWING'; }
|
||||
'FROM' { parser.determineCase(yytext); return 'FROM'; }
|
||||
'FULL' { return 'FULL'; }
|
||||
'GROUP' { return 'GROUP'; }
|
||||
'HAVING' { return 'HAVING'; }
|
||||
'IF' { return 'IF'; }
|
||||
'IN' { return 'IN'; }
|
||||
'INNER' { return 'INNER'; }
|
||||
'INSERT' { return 'INSERT'; }
|
||||
'INT' { return 'INT'; }
|
||||
'INTO' { return 'INTO'; }
|
||||
'IS' { return 'IS'; }
|
||||
'JOIN' { return 'JOIN'; }
|
||||
'LEFT' { return 'LEFT'; }
|
||||
'LIKE' { return 'LIKE'; }
|
||||
'LIMIT' { return 'LIMIT'; }
|
||||
'NOT' { return 'NOT'; }
|
||||
'NULL' { return 'NULL'; }
|
||||
'ON' { return 'ON'; }
|
||||
'OPTION' { return 'OPTION'; }
|
||||
'OR' { return 'OR'; }
|
||||
'ORDER' { return 'ORDER'; }
|
||||
'OUTER' { return 'OUTER'; }
|
||||
'PARTITION' { return 'PARTITION'; }
|
||||
'PRECEDING' { return 'PRECEDING'; }
|
||||
'PURGE' { return 'PURGE'; }
|
||||
'RANGE' { return 'RANGE'; }
|
||||
'REGEXP' { return 'REGEXP'; }
|
||||
'RIGHT' { return 'RIGHT'; }
|
||||
'RLIKE' { return 'RLIKE'; }
|
||||
'ROW' { return 'ROW'; }
|
||||
'ROLE' { return 'ROLE'; }
|
||||
'ROWS' { return 'ROWS'; }
|
||||
'SCHEMA' { return 'SCHEMA'; }
|
||||
'SELECT' { parser.determineCase(yytext); parser.addStatementTypeLocation('SELECT', yylloc); return 'SELECT'; }
|
||||
'SEMI' { return 'SEMI'; }
|
||||
'SET' { parser.determineCase(yytext); parser.addStatementTypeLocation('SET', yylloc); return 'SET'; }
|
||||
'SHOW' { parser.determineCase(yytext); parser.addStatementTypeLocation('SHOW', yylloc); return 'SHOW'; }
|
||||
'SMALLINT' { return 'SMALLINT'; }
|
||||
'STRING' { return 'STRING'; }
|
||||
'TABLE' { return 'TABLE'; }
|
||||
'THEN' { return 'THEN'; }
|
||||
'TIMESTAMP' { return 'TIMESTAMP'; }
|
||||
'TINYINT' { return 'TINYINT'; }
|
||||
'TO' { return 'TO'; }
|
||||
'TRUE' { return 'TRUE'; }
|
||||
'TRUNCATE' { parser.determineCase(yytext); parser.addStatementTypeLocation('TRUNCATE', yylloc, yy.lexer.upcomingInput()); return 'TRUNCATE'; }
|
||||
'UNBOUNDED' { return 'UNBOUNDED'; }
|
||||
'UNION' { return 'UNION'; }
|
||||
'UPDATE' { parser.determineCase(yytext); return 'UPDATE'; }
|
||||
'USE' { parser.determineCase(yytext); parser.addStatementTypeLocation('USE', yylloc); return 'USE'; }
|
||||
'VALUES' { return 'VALUES'; }
|
||||
'VARCHAR' { return 'VARCHAR'; }
|
||||
'VIEW' { return 'VIEW'; }
|
||||
'WHEN' { return 'WHEN'; }
|
||||
'WHERE' { return 'WHERE'; }
|
||||
'WITH' { parser.determineCase(yytext); parser.addStatementTypeLocation('WITH', yylloc); return 'WITH'; }
|
||||
|
||||
// Non-reserved Keywords
|
||||
'OVER' { return 'OVER'; }
|
||||
'ROLE' { return 'ROLE'; }
|
||||
|
||||
// --- UDFs ---
|
||||
AVG\s*\( { yy.lexer.unput('('); yytext = 'avg'; parser.addFunctionLocation(yylloc, yytext); return 'AVG'; }
|
||||
CAST\s*\( { yy.lexer.unput('('); yytext = 'cast'; parser.addFunctionLocation(yylloc, yytext); return 'CAST'; }
|
||||
COUNT\s*\( { yy.lexer.unput('('); yytext = 'count'; parser.addFunctionLocation(yylloc, yytext); return 'COUNT'; }
|
||||
MAX\s*\( { yy.lexer.unput('('); yytext = 'max'; parser.addFunctionLocation(yylloc, yytext); return 'MAX'; }
|
||||
MIN\s*\( { yy.lexer.unput('('); yytext = 'min'; parser.addFunctionLocation(yylloc, yytext); return 'MIN'; }
|
||||
STDDEV_POP\s*\( { yy.lexer.unput('('); yytext = 'stddev_pop'; parser.addFunctionLocation(yylloc, yytext); return 'STDDEV_POP'; }
|
||||
STDDEV_SAMP\s*\( { yy.lexer.unput('('); yytext = 'stddev_samp'; parser.addFunctionLocation(yylloc, yytext); return 'STDDEV_SAMP'; }
|
||||
SUM\s*\( { yy.lexer.unput('('); yytext = 'sum'; parser.addFunctionLocation(yylloc, yytext); return 'SUM'; }
|
||||
VAR_POP\s*\( { yy.lexer.unput('('); yytext = 'var_pop'; parser.addFunctionLocation(yylloc, yytext); return 'VAR_POP'; }
|
||||
VAR_SAMP\s*\( { yy.lexer.unput('('); yytext = 'var_samp'; parser.addFunctionLocation(yylloc, yytext); return 'VAR_SAMP'; }
|
||||
VARIANCE\s*\( { yy.lexer.unput('('); yytext = 'variance'; parser.addFunctionLocation(yylloc, yytext); return 'VARIANCE'; }
|
||||
|
||||
// Analytical functions
|
||||
CUME_DIST\s*\( { yy.lexer.unput('('); yytext = 'cume_dist'; parser.addFunctionLocation(yylloc, yytext); return 'ANALYTIC'; }
|
||||
DENSE_RANK\s*\( { yy.lexer.unput('('); yytext = 'dense_rank'; parser.addFunctionLocation(yylloc, yytext); return 'ANALYTIC'; }
|
||||
FIRST_VALUE\s*\( { yy.lexer.unput('('); yytext = 'first_value'; parser.addFunctionLocation(yylloc, yytext); return 'ANALYTIC'; }
|
||||
LAG\s*\( { yy.lexer.unput('('); yytext = 'lag'; parser.addFunctionLocation(yylloc, yytext); return 'ANALYTIC'; }
|
||||
LAST_VALUE\s*\( { yy.lexer.unput('('); yytext = 'last_value'; parser.addFunctionLocation(yylloc, yytext); return 'ANALYTIC'; }
|
||||
LEAD\s*\( { yy.lexer.unput('('); yytext = 'lead'; parser.addFunctionLocation(yylloc, yytext); return 'ANALYTIC'; }
|
||||
RANK\s*\( { yy.lexer.unput('('); yytext = 'rank'; parser.addFunctionLocation(yylloc, yytext); return 'ANALYTIC'; }
|
||||
ROW_NUMBER\s*\( { yy.lexer.unput('('); yytext = 'row_number'; parser.addFunctionLocation(yylloc, yytext); return 'ANALYTIC'; }
|
||||
|
||||
[0-9]+ { return 'UNSIGNED_INTEGER'; }
|
||||
[0-9]+(?:[YSL]|BD)? { return 'UNSIGNED_INTEGER'; }
|
||||
[0-9]+E { return 'UNSIGNED_INTEGER_E'; }
|
||||
[A-Za-z0-9_]+ { return 'REGULAR_IDENTIFIER'; }
|
||||
|
||||
<hdfs>'\u2020' { parser.yy.cursorFound = true; return 'CURSOR'; }
|
||||
<hdfs>'\u2021' { parser.yy.cursorFound = true; return 'PARTIAL_CURSOR'; }
|
||||
<hdfs>\s+['"] { return 'HDFS_START_QUOTE'; }
|
||||
<hdfs>[^'"\u2020\u2021]+ { parser.addFileLocation(yylloc, yytext); return 'HDFS_PATH'; }
|
||||
<hdfs>['"] { this.popState(); return 'HDFS_END_QUOTE'; }
|
||||
<hdfs><<EOF>> { return 'EOF'; }
|
||||
|
||||
'&&' { return 'AND'; }
|
||||
'||' { return 'OR'; }
|
||||
|
||||
'=' { return '='; }
|
||||
'<' { return '<'; }
|
||||
'>' { return '>'; }
|
||||
'!=' { return 'COMPARISON_OPERATOR'; }
|
||||
'<=' { return 'COMPARISON_OPERATOR'; }
|
||||
'>=' { return 'COMPARISON_OPERATOR'; }
|
||||
'<>' { return 'COMPARISON_OPERATOR'; }
|
||||
'<=>' { return 'COMPARISON_OPERATOR'; }
|
||||
|
||||
'-' { return '-'; }
|
||||
'*' { return '*'; }
|
||||
'+' { return 'ARITHMETIC_OPERATOR'; }
|
||||
'/' { return 'ARITHMETIC_OPERATOR'; }
|
||||
'%' { return 'ARITHMETIC_OPERATOR'; }
|
||||
'|' { return 'ARITHMETIC_OPERATOR'; }
|
||||
'^' { return 'ARITHMETIC_OPERATOR'; }
|
||||
'&' { return 'ARITHMETIC_OPERATOR'; }
|
||||
|
||||
',' { return ','; }
|
||||
'.' { return '.'; }
|
||||
':' { return ':'; }
|
||||
';' { return ';'; }
|
||||
'~' { return '~'; }
|
||||
'!' { return '!'; }
|
||||
|
||||
'(' { return '('; }
|
||||
')' { return ')'; }
|
||||
'[' { return '['; }
|
||||
']' { return ']'; }
|
||||
|
||||
\$\{[^}]*\} { return 'VARIABLE_REFERENCE'; }
|
||||
|
||||
\` { this.begin('backtickedValue'); return 'BACKTICK'; }
|
||||
<backtickedValue>[^`]+ {
|
||||
if (parser.handleQuotedValueWithCursor(this, yytext, yylloc, '`')) {
|
||||
return 'PARTIAL_VALUE';
|
||||
}
|
||||
return 'VALUE';
|
||||
}
|
||||
<backtickedValue>\` { this.popState(); return 'BACKTICK'; }
|
||||
|
||||
\' { this.begin('singleQuotedValue'); return 'SINGLE_QUOTE'; }
|
||||
<singleQuotedValue>(?:\\\\|\\[']|[^'])+ {
|
||||
if (parser.handleQuotedValueWithCursor(this, yytext, yylloc, '\'')) {
|
||||
return 'PARTIAL_VALUE';
|
||||
}
|
||||
return 'VALUE';
|
||||
}
|
||||
<singleQuotedValue>\' { this.popState(); return 'SINGLE_QUOTE'; }
|
||||
|
||||
\" { this.begin('doubleQuotedValue'); return 'DOUBLE_QUOTE'; }
|
||||
<doubleQuotedValue>(?:\\\\|\\["]|[^"])+ {
|
||||
if (parser.handleQuotedValueWithCursor(this, yytext, yylloc, '"')) {
|
||||
return 'PARTIAL_VALUE';
|
||||
}
|
||||
return 'VALUE';
|
||||
}
|
||||
<doubleQuotedValue>\" { this.popState(); return 'DOUBLE_QUOTE'; }
|
||||
|
||||
<<EOF>> { return 'EOF'; }
|
||||
|
||||
. { /* To prevent console logging of unknown chars */ }
|
||||
<between>. { }
|
||||
<hdfs>. { }
|
||||
<backtickedValue>. { }
|
||||
<singleQuotedValue>. { }
|
||||
<doubleQuotedValue>. { }
|
109
src/jison/sql/druid/sql_alter.jison
Normal file
109
src/jison/sql/druid/sql_alter.jison
Normal file
@ -0,0 +1,109 @@
|
||||
// Licensed to Cloudera, Inc. under one
|
||||
// or more contributor license agreements. See the NOTICE file
|
||||
// distributed with this work for additional information
|
||||
// regarding copyright ownership. Cloudera, Inc. licenses this file
|
||||
// to you under the Apache License, Version 2.0 (the
|
||||
// "License"); you may not use this file except in compliance
|
||||
// with the License. You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
DataDefinition
|
||||
: AlterStatement
|
||||
;
|
||||
|
||||
DataDefinition_EDIT
|
||||
: AlterStatement_EDIT
|
||||
;
|
||||
|
||||
AlterStatement
|
||||
: AlterTable
|
||||
| AlterView
|
||||
;
|
||||
|
||||
AlterStatement_EDIT
|
||||
: AlterTable_EDIT
|
||||
| AlterView_EDIT
|
||||
| 'ALTER' 'CURSOR'
|
||||
{
|
||||
parser.suggestKeywords(['TABLE', 'VIEW']);
|
||||
}
|
||||
;
|
||||
|
||||
AlterTable
|
||||
: AlterTableLeftSide PartitionSpec
|
||||
;
|
||||
|
||||
AlterTable_EDIT
|
||||
: AlterTableLeftSide_EDIT
|
||||
| AlterTableLeftSide_EDIT PartitionSpec
|
||||
| AlterTableLeftSide 'CURSOR'
|
||||
| AlterTableLeftSide PartitionSpec 'CURSOR'
|
||||
;
|
||||
|
||||
AlterTableLeftSide
|
||||
: 'ALTER' 'TABLE' SchemaQualifiedTableIdentifier
|
||||
{
|
||||
parser.addTablePrimary($3);
|
||||
}
|
||||
;
|
||||
|
||||
AlterTableLeftSide_EDIT
|
||||
: 'ALTER' 'TABLE' SchemaQualifiedTableIdentifier_EDIT
|
||||
{
|
||||
if (parser.yy.result.suggestTables) {
|
||||
parser.yy.result.suggestTables.onlyTables = true;
|
||||
}
|
||||
}
|
||||
| 'ALTER' 'TABLE' 'CURSOR'
|
||||
{
|
||||
parser.suggestTables({ onlyTables: true });
|
||||
parser.suggestDatabases({ appendDot: true });
|
||||
}
|
||||
;
|
||||
|
||||
AlterView
|
||||
: AlterViewLeftSide 'AS' QuerySpecification
|
||||
;
|
||||
|
||||
AlterView_EDIT
|
||||
: AlterViewLeftSide_EDIT
|
||||
| AlterViewLeftSide 'CURSOR'
|
||||
{
|
||||
parser.suggestKeywords(['AS']);
|
||||
}
|
||||
| AlterViewLeftSide 'SET' 'CURSOR'
|
||||
| AlterViewLeftSide 'AS' 'CURSOR'
|
||||
{
|
||||
parser.suggestKeywords(['SELECT']);
|
||||
}
|
||||
| AlterViewLeftSide 'AS' QuerySpecification_EDIT
|
||||
;
|
||||
|
||||
|
||||
AlterViewLeftSide
|
||||
: 'ALTER' 'VIEW' SchemaQualifiedTableIdentifier
|
||||
{
|
||||
parser.addTablePrimary($3);
|
||||
}
|
||||
;
|
||||
|
||||
AlterViewLeftSide_EDIT
|
||||
: 'ALTER' 'VIEW' SchemaQualifiedTableIdentifier_EDIT
|
||||
{
|
||||
if (parser.yy.result.suggestTables) {
|
||||
parser.yy.result.suggestTables.onlyViews = true;
|
||||
}
|
||||
}
|
||||
| 'ALTER' 'VIEW' 'CURSOR'
|
||||
{
|
||||
parser.suggestTables({ onlyViews: true });
|
||||
parser.suggestDatabases({ appendDot: true });
|
||||
}
|
||||
;
|
615
src/jison/sql/druid/sql_create.jison
Normal file
615
src/jison/sql/druid/sql_create.jison
Normal file
@ -0,0 +1,615 @@
|
||||
// Licensed to Cloudera, Inc. under one
|
||||
// or more contributor license agreements. See the NOTICE file
|
||||
// distributed with this work for additional information
|
||||
// regarding copyright ownership. Cloudera, Inc. licenses this file
|
||||
// to you under the Apache License, Version 2.0 (the
|
||||
// "License"); you may not use this file except in compliance
|
||||
// with the License. You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
DataDefinition
|
||||
: CreateStatement
|
||||
;
|
||||
|
||||
DataDefinition_EDIT
|
||||
: CreateStatement_EDIT
|
||||
;
|
||||
|
||||
CreateStatement
|
||||
: DatabaseDefinition
|
||||
| TableDefinition
|
||||
| ViewDefinition
|
||||
| RoleDefinition
|
||||
;
|
||||
|
||||
CreateStatement_EDIT
|
||||
: DatabaseDefinition_EDIT
|
||||
| TableDefinition_EDIT
|
||||
| ViewDefinition_EDIT
|
||||
| 'CREATE' 'CURSOR'
|
||||
{
|
||||
parser.suggestKeywords(['DATABASE', 'ROLE', 'SCHEMA', 'TABLE', 'VIEW']);
|
||||
}
|
||||
;
|
||||
|
||||
DatabaseDefinition
|
||||
: 'CREATE' DatabaseOrSchema OptionalIfNotExists
|
||||
| 'CREATE' DatabaseOrSchema OptionalIfNotExists RegularIdentifier DatabaseDefinitionOptionals
|
||||
{
|
||||
parser.addNewDatabaseLocation(@4, [{ name: $4 }]);
|
||||
}
|
||||
;
|
||||
|
||||
DatabaseDefinition_EDIT
|
||||
: 'CREATE' DatabaseOrSchema OptionalIfNotExists 'CURSOR'
|
||||
{
|
||||
if (!$3) {
|
||||
parser.suggestKeywords(['IF NOT EXISTS']);
|
||||
}
|
||||
}
|
||||
| 'CREATE' DatabaseOrSchema OptionalIfNotExists_EDIT
|
||||
| 'CREATE' DatabaseOrSchema OptionalIfNotExists 'CURSOR' RegularIdentifier
|
||||
{
|
||||
if (!$3) {
|
||||
parser.suggestKeywords(['IF NOT EXISTS']);
|
||||
}
|
||||
parser.addNewDatabaseLocation(@5, [{ name: $5 }]);
|
||||
}
|
||||
| 'CREATE' DatabaseOrSchema OptionalIfNotExists_EDIT RegularIdentifier
|
||||
{
|
||||
parser.addNewDatabaseLocation(@4, [{ name: $4 }]);
|
||||
}
|
||||
| 'CREATE' DatabaseOrSchema OptionalIfNotExists RegularIdentifier DatabaseDefinitionOptionals 'CURSOR'
|
||||
{
|
||||
parser.addNewDatabaseLocation(@4, [{ name: $4 }]);
|
||||
}
|
||||
;
|
||||
|
||||
DatabaseDefinitionOptionals
|
||||
: OptionalComment
|
||||
{
|
||||
if (!$1) {
|
||||
parser.suggestKeywords(['COMMENT']);
|
||||
}
|
||||
}
|
||||
;
|
||||
|
||||
DatabaseDefinitionOptionals_EDIT
|
||||
: OptionalComment_INVALID
|
||||
;
|
||||
|
||||
OptionalComment
|
||||
:
|
||||
| Comment
|
||||
;
|
||||
|
||||
Comment
|
||||
: 'COMMENT' QuotedValue
|
||||
;
|
||||
|
||||
OptionalComment_INVALID
|
||||
: Comment_INVALID
|
||||
;
|
||||
|
||||
Comment_INVALID
|
||||
: 'COMMENT' SINGLE_QUOTE
|
||||
| 'COMMENT' DOUBLE_QUOTE
|
||||
| 'COMMENT' SINGLE_QUOTE VALUE
|
||||
| 'COMMENT' DOUBLE_QUOTE VALUE
|
||||
;
|
||||
|
||||
TableDefinition
|
||||
: 'CREATE' 'TABLE' OptionalIfNotExists TableDefinitionRightPart
|
||||
;
|
||||
|
||||
TableDefinition_EDIT
|
||||
: 'CREATE' 'TABLE' OptionalIfNotExists TableDefinitionRightPart_EDIT
|
||||
| 'CREATE' 'TABLE' OptionalIfNotExists 'CURSOR'
|
||||
{
|
||||
if (!$3) {
|
||||
parser.suggestKeywords(['IF NOT EXISTS']);
|
||||
}
|
||||
}
|
||||
| 'CREATE' 'TABLE' OptionalIfNotExists_EDIT
|
||||
;
|
||||
|
||||
TableDefinitionRightPart
|
||||
: TableIdentifierAndOptionalColumnSpecification OptionalPartitionedBy OptionalAsSelectStatement
|
||||
;
|
||||
|
||||
TableDefinitionRightPart_EDIT
|
||||
: TableIdentifierAndOptionalColumnSpecification_EDIT OptionalPartitionedBy OptionalAsSelectStatement
|
||||
| TableIdentifierAndOptionalColumnSpecification PartitionedBy_EDIT OptionalAsSelectStatement
|
||||
| TableIdentifierAndOptionalColumnSpecification OptionalPartitionedBy OptionalAsSelectStatement_EDIT
|
||||
| TableIdentifierAndOptionalColumnSpecification OptionalPartitionedBy 'CURSOR'
|
||||
{
|
||||
var keywords = [];
|
||||
if (!$1 && !$2) {
|
||||
keywords.push({ value: 'LIKE', weight: 1 });
|
||||
} else {
|
||||
if (!$2) {
|
||||
keywords.push({ value: 'PARTITIONED BY', weight: 12 });
|
||||
}
|
||||
keywords.push({ value: 'AS', weight: 1 });
|
||||
}
|
||||
|
||||
if (keywords.length > 0) {
|
||||
parser.suggestKeywords(keywords);
|
||||
}
|
||||
}
|
||||
;
|
||||
|
||||
TableIdentifierAndOptionalColumnSpecification
|
||||
: SchemaQualifiedIdentifier OptionalColumnSpecificationsOrLike
|
||||
{
|
||||
parser.addNewTableLocation(@1, $1, $2);
|
||||
$$ = $2;
|
||||
}
|
||||
;
|
||||
|
||||
TableIdentifierAndOptionalColumnSpecification_EDIT
|
||||
: SchemaQualifiedIdentifier OptionalColumnSpecificationsOrLike_EDIT
|
||||
| SchemaQualifiedIdentifier_EDIT OptionalColumnSpecificationsOrLike
|
||||
;
|
||||
|
||||
OptionalColumnSpecificationsOrLike
|
||||
:
|
||||
| ParenthesizedColumnSpecificationList
|
||||
| 'LIKE' SchemaQualifiedTableIdentifier -> []
|
||||
;
|
||||
|
||||
OptionalColumnSpecificationsOrLike_EDIT
|
||||
: ParenthesizedColumnSpecificationList_EDIT
|
||||
| 'LIKE' 'CURSOR'
|
||||
{
|
||||
parser.suggestTables();
|
||||
parser.suggestDatabases({ appendDot: true });
|
||||
}
|
||||
| 'LIKE' SchemaQualifiedTableIdentifier_EDIT
|
||||
;
|
||||
|
||||
ParenthesizedColumnSpecificationList
|
||||
: '(' ColumnSpecificationList ')' -> $2
|
||||
;
|
||||
|
||||
ParenthesizedColumnSpecificationList_EDIT
|
||||
: '(' ColumnSpecificationList_EDIT RightParenthesisOrError
|
||||
;
|
||||
|
||||
ColumnSpecificationList
|
||||
: ColumnSpecification -> [$1]
|
||||
| ColumnSpecificationList ',' ColumnSpecification -> $1.concat($3)
|
||||
;
|
||||
|
||||
ColumnSpecificationList_EDIT
|
||||
: ColumnSpecification_EDIT
|
||||
| ColumnSpecification_EDIT ',' ColumnSpecificationList
|
||||
| ColumnSpecificationList ',' ColumnSpecification_EDIT
|
||||
| ColumnSpecificationList ',' ColumnSpecification_EDIT ',' ColumnSpecificationList
|
||||
| ColumnSpecification 'CURSOR'
|
||||
{
|
||||
parser.checkForKeywords($1);
|
||||
}
|
||||
| ColumnSpecification 'CURSOR' ',' ColumnSpecificationList
|
||||
{
|
||||
parser.checkForKeywords($1);
|
||||
}
|
||||
| ColumnSpecificationList ',' ColumnSpecification 'CURSOR'
|
||||
{
|
||||
parser.checkForKeywords($3);
|
||||
}
|
||||
| ColumnSpecificationList ',' ColumnSpecification 'CURSOR' ',' ColumnSpecificationList
|
||||
{
|
||||
parser.checkForKeywords($3);
|
||||
}
|
||||
;
|
||||
|
||||
ColumnSpecification
|
||||
: ColumnIdentifier ColumnDataType OptionalColumnOptions
|
||||
{
|
||||
$$ = $1;
|
||||
$$.type = $2;
|
||||
var keywords = [];
|
||||
if (!$3['comment']) {
|
||||
keywords.push('COMMENT');
|
||||
}
|
||||
if (keywords.length > 0) {
|
||||
$$.suggestKeywords = keywords;
|
||||
}
|
||||
}
|
||||
;
|
||||
|
||||
ColumnSpecification_EDIT
|
||||
: ColumnIdentifier 'CURSOR' OptionalColumnOptions
|
||||
{
|
||||
parser.suggestKeywords(parser.getColumnDataTypeKeywords());
|
||||
}
|
||||
| ColumnIdentifier ColumnDataType_EDIT OptionalColumnOptions
|
||||
| ColumnIdentifier ColumnDataType ColumnOptions_EDIT
|
||||
;
|
||||
|
||||
OptionalColumnOptions
|
||||
: -> {}
|
||||
| ColumnOptions
|
||||
;
|
||||
|
||||
ColumnOptions
|
||||
: ColumnOption
|
||||
{
|
||||
$$ = {};
|
||||
$$[$1] = true;
|
||||
}
|
||||
| ColumnOptions ColumnOption
|
||||
{
|
||||
$1[$2] = true;
|
||||
}
|
||||
;
|
||||
|
||||
ColumnOptions_EDIT
|
||||
: ColumnOption_EDIT
|
||||
| ColumnOption_EDIT ColumnOptions
|
||||
| ColumnOptions ColumnOption_EDIT
|
||||
| ColumnOptions ColumnOption_EDIT ColumnOptions
|
||||
;
|
||||
|
||||
ColumnOption
|
||||
: 'NOT' 'NULL' -> 'null'
|
||||
| 'NULL' -> 'null'
|
||||
| Comment -> 'comment'
|
||||
;
|
||||
|
||||
ColumnOption_EDIT
|
||||
: 'NOT' 'CURSOR'
|
||||
{
|
||||
parser.suggestKeywords(['NULL']);
|
||||
}
|
||||
;
|
||||
|
||||
ColumnDataType
|
||||
: PrimitiveType
|
||||
| ArrayType
|
||||
| MapType
|
||||
| StructType
|
||||
| ArrayType_INVALID
|
||||
| MapType_INVALID
|
||||
| StructType_INVALID
|
||||
;
|
||||
|
||||
ColumnDataType_EDIT
|
||||
: ArrayType_EDIT
|
||||
| MapType_EDIT
|
||||
| StructType_EDIT
|
||||
;
|
||||
|
||||
ArrayType
|
||||
: 'ARRAY' '<' ColumnDataType '>'
|
||||
;
|
||||
|
||||
ArrayType_INVALID
|
||||
: 'ARRAY' '<' '>'
|
||||
;
|
||||
|
||||
ArrayType_EDIT
|
||||
: 'ARRAY' '<' AnyCursor GreaterThanOrError
|
||||
{
|
||||
parser.suggestKeywords(parser.getColumnDataTypeKeywords());
|
||||
}
|
||||
| 'ARRAY' '<' ColumnDataType_EDIT GreaterThanOrError
|
||||
;
|
||||
|
||||
MapType
|
||||
: 'MAP' '<' PrimitiveType ',' ColumnDataType '>'
|
||||
;
|
||||
|
||||
MapType_INVALID
|
||||
: 'MAP' '<' '>'
|
||||
;
|
||||
|
||||
MapType_EDIT
|
||||
: 'MAP' '<' PrimitiveType ',' ColumnDataType_EDIT GreaterThanOrError
|
||||
| 'MAP' '<' AnyCursor GreaterThanOrError
|
||||
{
|
||||
parser.suggestKeywords(parser.getTypeKeywords());
|
||||
}
|
||||
| 'MAP' '<' PrimitiveType ',' AnyCursor GreaterThanOrError
|
||||
{
|
||||
parser.suggestKeywords(parser.getColumnDataTypeKeywords());
|
||||
}
|
||||
| 'MAP' '<' ',' AnyCursor GreaterThanOrError
|
||||
{
|
||||
parser.suggestKeywords(parser.getColumnDataTypeKeywords());
|
||||
}
|
||||
;
|
||||
|
||||
StructType
|
||||
: 'STRUCT' '<' StructDefinitionList '>'
|
||||
;
|
||||
|
||||
StructType_INVALID
|
||||
: 'STRUCT' '<' '>'
|
||||
;
|
||||
|
||||
StructType_EDIT
|
||||
: 'STRUCT' '<' StructDefinitionList_EDIT GreaterThanOrError
|
||||
;
|
||||
|
||||
StructDefinitionList
|
||||
: StructDefinition
|
||||
| StructDefinitionList ',' StructDefinition
|
||||
;
|
||||
|
||||
StructDefinitionList_EDIT
|
||||
: StructDefinition_EDIT
|
||||
| StructDefinition_EDIT Commas
|
||||
| StructDefinition_EDIT Commas StructDefinitionList
|
||||
| StructDefinitionList ',' StructDefinition_EDIT
|
||||
| StructDefinitionList ',' StructDefinition_EDIT Commas StructDefinitionList
|
||||
;
|
||||
|
||||
StructDefinition
|
||||
: RegularOrBacktickedIdentifier ':' ColumnDataType OptionalComment
|
||||
;
|
||||
|
||||
StructDefinition_EDIT
|
||||
: Commas RegularOrBacktickedIdentifier ':' ColumnDataType 'CURSOR'
|
||||
{
|
||||
parser.suggestKeywords(['COMMENT']);
|
||||
}
|
||||
| Commas RegularOrBacktickedIdentifier ':' AnyCursor
|
||||
{
|
||||
parser.suggestKeywords(parser.getColumnDataTypeKeywords());
|
||||
}
|
||||
| Commas RegularOrBacktickedIdentifier ':' ColumnDataType_EDIT
|
||||
| RegularOrBacktickedIdentifier ':' ColumnDataType 'CURSOR'
|
||||
{
|
||||
parser.suggestKeywords(['COMMENT']);
|
||||
}
|
||||
| RegularOrBacktickedIdentifier ':' AnyCursor
|
||||
{
|
||||
parser.suggestKeywords(parser.getColumnDataTypeKeywords());
|
||||
}
|
||||
| RegularOrBacktickedIdentifier ':' ColumnDataType_EDIT
|
||||
;
|
||||
|
||||
ColumnDataTypeList
|
||||
: ColumnDataType
|
||||
| ColumnDataTypeList ',' ColumnDataType
|
||||
;
|
||||
|
||||
ColumnDataTypeList_EDIT
|
||||
: ColumnDataTypeListInner_EDIT
|
||||
| ColumnDataTypeListInner_EDIT Commas
|
||||
| ColumnDataTypeList ',' ColumnDataTypeListInner_EDIT
|
||||
| ColumnDataTypeListInner_EDIT Commas ColumnDataTypeList
|
||||
| ColumnDataTypeList ',' ColumnDataTypeListInner_EDIT Commas ColumnDataTypeList
|
||||
;
|
||||
|
||||
ColumnDataTypeListInner_EDIT
|
||||
: Commas AnyCursor
|
||||
{
|
||||
parser.suggestKeywords(parser.getColumnDataTypeKeywords());
|
||||
}
|
||||
| Commas ColumnDataType_EDIT
|
||||
| AnyCursor
|
||||
{
|
||||
parser.suggestKeywords(parser.getColumnDataTypeKeywords());
|
||||
}
|
||||
| ColumnDataType_EDIT
|
||||
;
|
||||
|
||||
GreaterThanOrError
|
||||
: '>'
|
||||
| error
|
||||
;
|
||||
|
||||
OptionalPartitionedBy
|
||||
:
|
||||
| PartitionedBy
|
||||
;
|
||||
|
||||
PartitionedBy
|
||||
: 'PARTITION' 'BY' RangeClause
|
||||
;
|
||||
|
||||
PartitionedBy_EDIT
|
||||
: 'PARTITION' 'CURSOR'
|
||||
{
|
||||
parser.suggestKeywords(['BY']);
|
||||
}
|
||||
| 'PARTITION' 'BY' 'CURSOR'
|
||||
{
|
||||
parser.suggestKeywords(['RANGE']);
|
||||
}
|
||||
| 'PARTITION' 'BY' RangeClause_EDIT
|
||||
;
|
||||
|
||||
RangeClause
|
||||
: 'RANGE' ParenthesizedColumnList ParenthesizedPartitionValuesList
|
||||
;
|
||||
|
||||
RangeClause_EDIT
|
||||
: 'RANGE' 'CURSOR'
|
||||
| 'RANGE' ParenthesizedColumnList_EDIT
|
||||
| 'RANGE' ParenthesizedColumnList 'CURSOR'
|
||||
| 'RANGE' ParenthesizedColumnList ParenthesizedPartitionValuesList_EDIT
|
||||
| 'RANGE' ParenthesizedColumnList_EDIT ParenthesizedPartitionValuesList
|
||||
;
|
||||
|
||||
ParenthesizedPartitionValuesList
|
||||
: '(' PartitionValueList ')'
|
||||
;
|
||||
|
||||
ParenthesizedPartitionValuesList_EDIT
|
||||
: '(' 'CURSOR' RightParenthesisOrError
|
||||
{
|
||||
parser.suggestKeywords(['PARTITION']);
|
||||
}
|
||||
|'(' PartitionValueList_EDIT RightParenthesisOrError
|
||||
;
|
||||
|
||||
PartitionValueList
|
||||
: PartitionValue
|
||||
| PartitionValueList ',' PartitionValue
|
||||
;
|
||||
|
||||
PartitionValueList_EDIT
|
||||
: PartitionValue_EDIT
|
||||
| PartitionValueList ',' 'CURSOR'
|
||||
{
|
||||
parser.suggestKeywords(['PARTITION']);
|
||||
}
|
||||
| PartitionValueList ',' 'CURSOR' ',' PartitionValueList
|
||||
{
|
||||
parser.suggestKeywords(['PARTITION']);
|
||||
}
|
||||
| PartitionValueList ',' PartitionValue_EDIT
|
||||
| PartitionValueList ',' PartitionValue_EDIT ',' PartitionValueList
|
||||
;
|
||||
|
||||
PartitionValue
|
||||
: 'PARTITION' ValueExpression LessThanOrEqualTo 'VALUES' LessThanOrEqualTo ValueExpression
|
||||
| 'PARTITION' 'VALUES' LessThanOrEqualTo ValueExpression
|
||||
| 'PARTITION' ValueExpression LessThanOrEqualTo 'VALUES'
|
||||
;
|
||||
|
||||
PartitionValue_EDIT
|
||||
: 'PARTITION' 'CURSOR'
|
||||
{
|
||||
parser.suggestKeywords(['VALUE', 'VALUES']);
|
||||
}
|
||||
| 'PARTITION' ValueExpression_EDIT
|
||||
{
|
||||
if ($2.endsWithLessThanOrEqual) {
|
||||
parser.suggestKeywords(['VALUES']);
|
||||
}
|
||||
}
|
||||
| 'PARTITION' ValueExpression 'CURSOR'
|
||||
{
|
||||
parser.suggestKeywords(['<', '<=']);
|
||||
}
|
||||
| 'PARTITION' ValueExpression LessThanOrEqualTo 'CURSOR'
|
||||
{
|
||||
parser.suggestKeywords(['VALUES']);
|
||||
}
|
||||
| 'PARTITION' ValueExpression_EDIT LessThanOrEqualTo 'VALUES'
|
||||
| 'PARTITION' ValueExpression LessThanOrEqualTo 'VALUES' 'CURSOR'
|
||||
{
|
||||
parser.suggestKeywords(['<', '<=']);
|
||||
}
|
||||
| 'PARTITION' ValueExpression LessThanOrEqualTo 'VALUES' LessThanOrEqualTo 'CURSOR'
|
||||
{
|
||||
parser.suggestFunctions();
|
||||
}
|
||||
| 'PARTITION' ValueExpression LessThanOrEqualTo 'VALUES' LessThanOrEqualTo ValueExpression_EDIT
|
||||
| 'PARTITION' 'VALUES' 'CURSOR'
|
||||
{
|
||||
parser.suggestKeywords(['<', '<=']);
|
||||
}
|
||||
| 'PARTITION' 'VALUES' LessThanOrEqualTo 'CURSOR'
|
||||
{
|
||||
parser.suggestFunctions();
|
||||
}
|
||||
| 'PARTITION' 'VALUES' LessThanOrEqualTo ValueExpression_EDIT
|
||||
;
|
||||
|
||||
LessThanOrEqualTo
|
||||
: '<'
|
||||
| 'COMPARISON_OPERATOR' // This is fine for autocompletion
|
||||
;
|
||||
|
||||
OptionalAsSelectStatement
|
||||
:
|
||||
| 'AS' CommitLocations QuerySpecification
|
||||
;
|
||||
|
||||
OptionalAsSelectStatement_EDIT
|
||||
: 'AS' CommitLocations 'CURSOR'
|
||||
{
|
||||
parser.suggestKeywords(['SELECT']);
|
||||
}
|
||||
| 'AS' CommitLocations QuerySpecification_EDIT
|
||||
;
|
||||
|
||||
CommitLocations
|
||||
: /* empty */
|
||||
{
|
||||
parser.commitLocations();
|
||||
}
|
||||
;
|
||||
|
||||
ViewDefinition
|
||||
: 'CREATE' 'VIEW' OptionalIfNotExists SchemaQualifiedIdentifier OptionalParenthesizedViewColumnList OptionalComment 'AS' QuerySpecification
|
||||
;
|
||||
|
||||
ViewDefinition_EDIT
|
||||
: 'CREATE' 'VIEW' OptionalIfNotExists 'CURSOR'
|
||||
{
|
||||
if (!$3) {
|
||||
parser.suggestKeywords(['IF NOT EXISTS']);
|
||||
}
|
||||
parser.suggestDatabases({ appendDot: true });
|
||||
}
|
||||
| 'CREATE' 'VIEW' OptionalIfNotExists 'CURSOR' SchemaQualifiedIdentifier OptionalParenthesizedViewColumnList OptionalComment 'AS' QuerySpecification
|
||||
{
|
||||
if (!$3) {
|
||||
parser.suggestKeywords(['IF NOT EXISTS']);
|
||||
}
|
||||
}
|
||||
| 'CREATE' 'VIEW' OptionalIfNotExists_EDIT
|
||||
| 'CREATE' 'VIEW' OptionalIfNotExists SchemaQualifiedIdentifier ParenthesizedViewColumnList_EDIT OptionalComment
|
||||
| 'CREATE' 'VIEW' OptionalIfNotExists SchemaQualifiedIdentifier OptionalParenthesizedViewColumnList OptionalComment 'CURSOR'
|
||||
{
|
||||
var keywords = [{value: 'AS', weight: 1 }];
|
||||
if (!$6) {
|
||||
keywords.push({ value: 'COMMENT', weight: 3 });
|
||||
}
|
||||
parser.suggestKeywords(keywords);
|
||||
}
|
||||
| 'CREATE' 'VIEW' OptionalIfNotExists SchemaQualifiedIdentifier OptionalParenthesizedViewColumnList OptionalComment 'AS' 'CURSOR'
|
||||
{
|
||||
parser.suggestKeywords(['SELECT']);
|
||||
}
|
||||
| 'CREATE' 'VIEW' OptionalIfNotExists SchemaQualifiedIdentifier OptionalParenthesizedViewColumnList OptionalComment 'AS' QuerySpecification_EDIT
|
||||
| 'CREATE' 'VIEW' OptionalIfNotExists SchemaQualifiedIdentifier_EDIT OptionalParenthesizedViewColumnList OptionalComment 'AS' QuerySpecification
|
||||
;
|
||||
|
||||
OptionalParenthesizedViewColumnList
|
||||
:
|
||||
| ParenthesizedViewColumnList
|
||||
;
|
||||
|
||||
ParenthesizedViewColumnList
|
||||
: '(' ViewColumnList ')'
|
||||
;
|
||||
|
||||
ParenthesizedViewColumnList_EDIT
|
||||
: '(' ViewColumnList_EDIT RightParenthesisOrError
|
||||
{
|
||||
if (!$2) {
|
||||
parser.suggestKeywords(['COMMENT']);
|
||||
}
|
||||
}
|
||||
;
|
||||
|
||||
ViewColumnList
|
||||
: ColumnReference OptionalComment
|
||||
| ViewColumnList ',' ColumnReference OptionalComment
|
||||
;
|
||||
|
||||
ViewColumnList_EDIT
|
||||
: ColumnReference OptionalComment 'CURSOR' -> $2
|
||||
| ColumnReference OptionalComment 'CURSOR' ',' ViewColumnList -> $2
|
||||
| ViewColumnList ',' ColumnReference OptionalComment 'CURSOR' -> $4
|
||||
| ViewColumnList ',' ColumnReference OptionalComment 'CURSOR' ',' ViewColumnList -> $4
|
||||
;
|
||||
|
||||
RoleDefinition
|
||||
: 'CREATE' 'ROLE' RegularIdentifier
|
||||
;
|
184
src/jison/sql/druid/sql_drop.jison
Normal file
184
src/jison/sql/druid/sql_drop.jison
Normal file
@ -0,0 +1,184 @@
|
||||
// Licensed to Cloudera, Inc. under one
|
||||
// or more contributor license agreements. See the NOTICE file
|
||||
// distributed with this work for additional information
|
||||
// regarding copyright ownership. Cloudera, Inc. licenses this file
|
||||
// to you under the Apache License, Version 2.0 (the
|
||||
// "License"); you may not use this file except in compliance
|
||||
// with the License. You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
DataDefinition
|
||||
: DropStatement
|
||||
;
|
||||
|
||||
DataDefinition_EDIT
|
||||
: DropStatement_EDIT
|
||||
;
|
||||
|
||||
DropStatement
|
||||
: DropDatabaseStatement
|
||||
| DropRoleStatement
|
||||
| DropTableStatement
|
||||
| DropViewStatement
|
||||
| TruncateTableStatement
|
||||
;
|
||||
|
||||
DropStatement_EDIT
|
||||
: DropDatabaseStatement_EDIT
|
||||
| DropTableStatement_EDIT
|
||||
| DropViewStatement_EDIT
|
||||
| TruncateTableStatement_EDIT
|
||||
| 'DROP' 'CURSOR'
|
||||
{
|
||||
parser.suggestKeywords(['DATABASE', 'ROLE', 'SCHEMA', 'TABLE', 'VIEW']);
|
||||
}
|
||||
;
|
||||
|
||||
DropDatabaseStatement
|
||||
: 'DROP' DatabaseOrSchema OptionalIfExists RegularOrBacktickedIdentifier OptionalCascade
|
||||
;
|
||||
|
||||
DropDatabaseStatement_EDIT
|
||||
: 'DROP' DatabaseOrSchema OptionalIfExists
|
||||
| 'DROP' DatabaseOrSchema OptionalIfExists_EDIT
|
||||
| 'DROP' DatabaseOrSchema OptionalIfExists 'CURSOR'
|
||||
{
|
||||
if (!$3) {
|
||||
parser.suggestKeywords(['IF EXISTS']);
|
||||
}
|
||||
parser.suggestDatabases();
|
||||
}
|
||||
| 'DROP' DatabaseOrSchema OptionalIfExists RegularOrBacktickedIdentifier 'CURSOR'
|
||||
{
|
||||
parser.suggestKeywords(['CASCADE']);
|
||||
}
|
||||
| 'DROP' DatabaseOrSchema OptionalIfExists_EDIT RegularOrBacktickedIdentifier OptionalCascade
|
||||
| 'DROP' DatabaseOrSchema OptionalIfExists 'CURSOR' RegularOrBacktickedIdentifier OptionalCascade
|
||||
{
|
||||
if (!$3) {
|
||||
parser.suggestKeywords(['IF EXISTS']);
|
||||
}
|
||||
}
|
||||
;
|
||||
DropRoleStatement
|
||||
: 'DROP' 'ROLE' RegularIdentifier
|
||||
;
|
||||
|
||||
DropTableStatement
|
||||
: 'DROP' 'TABLE' OptionalIfExists SchemaQualifiedTableIdentifier OptionalPurge
|
||||
{
|
||||
parser.addTablePrimary($4);
|
||||
}
|
||||
;
|
||||
|
||||
DropTableStatement_EDIT
|
||||
: 'DROP' 'TABLE' OptionalIfExists_EDIT
|
||||
| 'DROP' 'TABLE' OptionalIfExists 'CURSOR'
|
||||
{
|
||||
if (!$3) {
|
||||
parser.suggestKeywords(['IF EXISTS']);
|
||||
}
|
||||
parser.suggestTables({ onlyTables: true });
|
||||
parser.suggestDatabases({
|
||||
appendDot: true
|
||||
});
|
||||
}
|
||||
| 'DROP' 'TABLE' OptionalIfExists SchemaQualifiedTableIdentifier_EDIT OptionalPurge
|
||||
{
|
||||
if (parser.yy.result.suggestTables) {
|
||||
parser.yy.result.suggestTables.onlyTables = true;
|
||||
}
|
||||
}
|
||||
| 'DROP' 'TABLE' OptionalIfExists_EDIT SchemaQualifiedTableIdentifier OptionalPurge
|
||||
| 'DROP' 'TABLE' OptionalIfExists SchemaQualifiedTableIdentifier OptionalPurge 'CURSOR'
|
||||
{
|
||||
parser.addTablePrimary($4);
|
||||
if (!$5) {
|
||||
parser.suggestKeywords(['PURGE']);
|
||||
}
|
||||
}
|
||||
;
|
||||
|
||||
OptionalPurge
|
||||
:
|
||||
| 'PURGE'
|
||||
;
|
||||
|
||||
DropViewStatement
|
||||
: 'DROP' 'VIEW' OptionalIfExists SchemaQualifiedTableIdentifier
|
||||
{
|
||||
parser.addTablePrimary($4);
|
||||
}
|
||||
;
|
||||
|
||||
DropViewStatement_EDIT
|
||||
: 'DROP' 'VIEW' OptionalIfExists 'CURSOR'
|
||||
{
|
||||
if (!$3) {
|
||||
parser.suggestKeywords(['IF EXISTS']);
|
||||
}
|
||||
parser.suggestTables({ onlyViews: true });
|
||||
parser.suggestDatabases({ appendDot: true });
|
||||
}
|
||||
| 'DROP' 'VIEW' OptionalIfExists 'CURSOR' SchemaQualifiedTableIdentifier
|
||||
{
|
||||
parser.addTablePrimary($5);
|
||||
if (!$3) {
|
||||
parser.suggestKeywords(['IF EXISTS']);
|
||||
}
|
||||
}
|
||||
| 'DROP' 'VIEW' OptionalIfExists_EDIT
|
||||
| 'DROP' 'VIEW' OptionalIfExists_EDIT SchemaQualifiedTableIdentifier
|
||||
{
|
||||
parser.addTablePrimary($4);
|
||||
}
|
||||
| 'DROP' 'VIEW' OptionalIfExists SchemaQualifiedTableIdentifier_EDIT
|
||||
{
|
||||
if (parser.yy.result.suggestTables) {
|
||||
parser.yy.result.suggestTables.onlyViews = true;
|
||||
}
|
||||
}
|
||||
;
|
||||
|
||||
TruncateTableStatement
|
||||
: 'TRUNCATE' 'TABLE' OptionalIfExists SchemaQualifiedTableIdentifier
|
||||
{
|
||||
parser.addTablePrimary($4);
|
||||
}
|
||||
;
|
||||
|
||||
TruncateTableStatement_EDIT
|
||||
: 'TRUNCATE' 'CURSOR'
|
||||
{
|
||||
parser.suggestKeywords(['TABLE']);
|
||||
}
|
||||
| 'TRUNCATE' 'TABLE' OptionalIfExists 'CURSOR'
|
||||
{
|
||||
parser.suggestTables();
|
||||
parser.suggestDatabases({ appendDot: true });
|
||||
if (!$3) {
|
||||
parser.suggestKeywords(['IF EXISTS']);
|
||||
}
|
||||
}
|
||||
| 'TRUNCATE' 'TABLE' OptionalIfExists_EDIT
|
||||
| 'TRUNCATE' 'TABLE' OptionalIfExists SchemaQualifiedTableIdentifier_EDIT
|
||||
| 'TRUNCATE' 'TABLE' OptionalIfExists SchemaQualifiedTableIdentifier 'CURSOR'
|
||||
{
|
||||
parser.addTablePrimary($4);
|
||||
}
|
||||
| 'TRUNCATE' 'TABLE' OptionalIfExists 'CURSOR' SchemaQualifiedTableIdentifier
|
||||
{
|
||||
parser.addTablePrimary($4);
|
||||
if (!$3) {
|
||||
parser.suggestKeywords(['IF EXISTS']);
|
||||
}
|
||||
}
|
||||
| 'TRUNCATE' 'TABLE' OptionalIfExists_EDIT SchemaQualifiedTableIdentifier OptionalPartitionSpec
|
||||
;
|
132
src/jison/sql/druid/sql_error.jison
Normal file
132
src/jison/sql/druid/sql_error.jison
Normal file
@ -0,0 +1,132 @@
|
||||
// Licensed to Cloudera, Inc. under one
|
||||
// or more contributor license agreements. See the NOTICE file
|
||||
// distributed with this work for additional information
|
||||
// regarding copyright ownership. Cloudera, Inc. licenses this file
|
||||
// to you under the Apache License, Version 2.0 (the
|
||||
// "License"); you may not use this file except in compliance
|
||||
// with the License. You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
SqlStatements
|
||||
: error
|
||||
| NonStartingToken error // Having just ': error' does not work for some reason, jison bug?
|
||||
;
|
||||
|
||||
SqlStatement_EDIT
|
||||
: AnyCursor error
|
||||
{
|
||||
parser.suggestDdlAndDmlKeywords();
|
||||
}
|
||||
;
|
||||
|
||||
SelectStatement
|
||||
: 'SELECT' OptionalAllOrDistinct SelectList_ERROR TableExpression
|
||||
| 'SELECT' OptionalAllOrDistinct SelectList TableExpression_ERROR
|
||||
;
|
||||
|
||||
SelectStatement_EDIT
|
||||
: 'SELECT' OptionalAllOrDistinct SelectList_ERROR_EDIT TableExpression
|
||||
{
|
||||
parser.selectListNoTableSuggest($3, $2);
|
||||
}
|
||||
| 'SELECT' OptionalAllOrDistinct SelectList_ERROR TableExpression_EDIT
|
||||
;
|
||||
|
||||
SelectList_ERROR
|
||||
: ErrorList
|
||||
| SelectList ',' ErrorList
|
||||
| ErrorList ',' SelectList ',' ErrorList
|
||||
| ErrorList ',' SelectList
|
||||
| SelectList ',' ErrorList ',' SelectList
|
||||
;
|
||||
|
||||
SelectList_ERROR_EDIT
|
||||
: ErrorList ',' SelectList_EDIT -> $3
|
||||
| SelectList ',' ErrorList ',' SelectList_EDIT -> $5
|
||||
| ErrorList ',' SelectList ',' ErrorList ',' SelectList_EDIT -> $7
|
||||
| ErrorList ',' AnyCursor
|
||||
{
|
||||
$$ = { cursorAtStart : false, suggestFunctions: true, suggestColumns: true, suggestAggregateFunctions: true };
|
||||
}
|
||||
| SelectList ',' ErrorList ',' AnyCursor
|
||||
{
|
||||
$$ = { cursorAtStart : false, suggestFunctions: true, suggestColumns: true, suggestAggregateFunctions: true };
|
||||
}
|
||||
| ErrorList ',' SelectList ',' Errors ',' AnyCursor
|
||||
{
|
||||
$$ = { cursorAtStart : true, suggestFunctions: true, suggestColumns: true, suggestAggregateFunctions: true };
|
||||
}
|
||||
;
|
||||
|
||||
SetSpecification
|
||||
: 'SET' SetOption '=' error
|
||||
;
|
||||
|
||||
ErrorList
|
||||
: error
|
||||
| Errors ',' error
|
||||
;
|
||||
|
||||
JoinType_EDIT
|
||||
: 'FULL' 'CURSOR' error
|
||||
{
|
||||
parser.suggestKeywords(['JOIN', 'OUTER JOIN']);
|
||||
}
|
||||
| 'LEFT' 'CURSOR' error
|
||||
{
|
||||
parser.suggestKeywords(['JOIN', 'OUTER JOIN']);
|
||||
}
|
||||
| 'RIGHT' 'CURSOR' error
|
||||
{
|
||||
parser.suggestKeywords(['JOIN', 'OUTER JOIN']);
|
||||
}
|
||||
;
|
||||
|
||||
OptionalSelectConditions_EDIT
|
||||
: WhereClause error 'CURSOR' OptionalGroupByClause OptionalHavingClause OptionalOrderByClause OptionalLimitClause
|
||||
{
|
||||
$$ = {
|
||||
suggestKeywords: parser.getKeywordsForOptionalsLR([$4, $5, $6, $7], [{ value: 'GROUP BY', weight: 8 }, { value: 'HAVING', weight: 7 }, { value: 'ORDER BY', weight: 5 }, { value: 'LIMIT', weight: 3 }], [true, true, true, true]),
|
||||
cursorAtEnd: !$4 && !$5 && !$6 && !$7
|
||||
};
|
||||
}
|
||||
| OptionalWhereClause OptionalGroupByClause HavingClause error 'CURSOR' OptionalOrderByClause OptionalLimitClause
|
||||
{
|
||||
$$ = {
|
||||
suggestKeywords: parser.getKeywordsForOptionalsLR([$6, $7], [{ value: 'ORDER BY', weight: 5 }, { value: 'LIMIT', weight: 3 }], [true, true]),
|
||||
cursorAtEnd: !$6 && !$7
|
||||
}
|
||||
}
|
||||
| OptionalWhereClause OptionalGroupByClause OptionalHavingClause OrderByClause error 'CURSOR' OptionalLimitClause
|
||||
{
|
||||
$$ = {
|
||||
suggestKeywords: parser.getKeywordsForOptionalsLR([$7], [{ value: 'LIMIT', weight: 3 }], [true]),
|
||||
cursorAtEnd: !$7
|
||||
}
|
||||
}
|
||||
| OptionalWhereClause OptionalGroupByClause OptionalHavingClause OptionalOrderByClause LimitClause error 'CURSOR'
|
||||
;
|
||||
|
||||
OptionalSelectConditions_EDIT
|
||||
: WhereClause error GroupByClause_EDIT OptionalHavingClause OptionalOrderByClause OptionalLimitClause
|
||||
| WhereClause error OptionalGroupByClause HavingClause_EDIT OptionalOrderByClause OptionalLimitClause
|
||||
| WhereClause error OptionalGroupByClause OptionalHavingClause OrderByClause_EDIT OptionalLimitClause
|
||||
| WhereClause error OptionalGroupByClause OptionalHavingClause OptionalOrderByClause LimitClause_EDIT
|
||||
| OptionalWhereClause GroupByClause error HavingClause_EDIT OptionalOrderByClause OptionalLimitClause
|
||||
| OptionalWhereClause GroupByClause error OptionalHavingClause OrderByClause_EDIT OptionalLimitClause
|
||||
| OptionalWhereClause GroupByClause error OptionalHavingClause OptionalOrderByClause LimitClause_EDIT
|
||||
| OptionalWhereClause OptionalGroupByClause HavingClause error OrderByClause_EDIT OptionalLimitClause
|
||||
| OptionalWhereClause OptionalGroupByClause HavingClause error OptionalOrderByClause LimitClause_EDIT
|
||||
| OptionalWhereClause OptionalGroupByClause OptionalHavingClause OrderByClause error LimitClause_EDIT
|
||||
;
|
||||
|
||||
DatabaseDefinition_EDIT
|
||||
: 'CREATE' DatabaseOrSchema OptionalIfNotExists RegularIdentifier DatabaseDefinitionOptionals_EDIT error
|
||||
;
|
72
src/jison/sql/druid/sql_insert.jison
Normal file
72
src/jison/sql/druid/sql_insert.jison
Normal file
@ -0,0 +1,72 @@
|
||||
// Licensed to Cloudera, Inc. under one
|
||||
// or more contributor license agreements. See the NOTICE file
|
||||
// distributed with this work for additional information
|
||||
// regarding copyright ownership. Cloudera, Inc. licenses this file
|
||||
// to you under the Apache License, Version 2.0 (the
|
||||
// "License"); you may not use this file except in compliance
|
||||
// with the License. You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
DataManipulation
|
||||
: InsertStatement
|
||||
;
|
||||
|
||||
InsertStatement
|
||||
: InsertValuesStatement
|
||||
;
|
||||
|
||||
DataManipulation_EDIT
|
||||
: InsertValuesStatement_EDIT
|
||||
;
|
||||
|
||||
InsertValuesStatement
|
||||
: 'INSERT' 'INTO' OptionalTable SchemaQualifiedTableIdentifier 'VALUES' InsertValuesList
|
||||
{
|
||||
$4.owner = 'insert';
|
||||
parser.addTablePrimary($4);
|
||||
}
|
||||
;
|
||||
|
||||
InsertValuesStatement_EDIT
|
||||
: 'INSERT' 'CURSOR'
|
||||
{
|
||||
parser.suggestKeywords(['INTO']);
|
||||
}
|
||||
| 'INSERT' 'INTO' OptionalTable 'CURSOR'
|
||||
{
|
||||
if (!$3) {
|
||||
parser.suggestKeywords(['TABLE']);
|
||||
}
|
||||
parser.suggestTables();
|
||||
parser.suggestDatabases({ appendDot: true });
|
||||
}
|
||||
| 'INSERT' 'INTO' OptionalTable SchemaQualifiedTableIdentifier_EDIT
|
||||
| 'INSERT' 'INTO' OptionalTable SchemaQualifiedTableIdentifier 'CURSOR'
|
||||
{
|
||||
$4.owner = 'insert';
|
||||
parser.addTablePrimary($4);
|
||||
parser.suggestKeywords(['VALUES']);
|
||||
}
|
||||
| 'INSERT' 'INTO' OptionalTable SchemaQualifiedTableIdentifier_EDIT 'VALUES' InsertValuesList
|
||||
;
|
||||
|
||||
InsertValuesList
|
||||
: ParenthesizedRowValuesList
|
||||
| RowValuesList ',' ParenthesizedRowValuesList
|
||||
;
|
||||
|
||||
ParenthesizedRowValuesList
|
||||
: '(' InValueList ')'
|
||||
;
|
||||
|
||||
OptionalTable
|
||||
:
|
||||
| 'TABLE'
|
||||
;
|
2762
src/jison/sql/druid/sql_main.jison
Normal file
2762
src/jison/sql/druid/sql_main.jison
Normal file
File diff suppressed because it is too large
Load Diff
46
src/jison/sql/druid/sql_set.jison
Normal file
46
src/jison/sql/druid/sql_set.jison
Normal file
@ -0,0 +1,46 @@
|
||||
// Licensed to Cloudera, Inc. under one
|
||||
// or more contributor license agreements. See the NOTICE file
|
||||
// distributed with this work for additional information
|
||||
// regarding copyright ownership. Cloudera, Inc. licenses this file
|
||||
// to you under the Apache License, Version 2.0 (the
|
||||
// "License"); you may not use this file except in compliance
|
||||
// with the License. You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
DataDefinition
|
||||
: SetSpecification
|
||||
;
|
||||
|
||||
DataDefinition_EDIT
|
||||
: 'SET' 'CURSOR'
|
||||
{
|
||||
parser.suggestSetOptions();
|
||||
}
|
||||
;
|
||||
|
||||
SetSpecification
|
||||
: 'SET' SetOption '=' SetValue
|
||||
| 'SET' 'ALL'
|
||||
;
|
||||
|
||||
SetOption
|
||||
: RegularIdentifier
|
||||
| SetOption '.' RegularIdentifier
|
||||
;
|
||||
|
||||
SetValue
|
||||
: RegularIdentifier
|
||||
| SignedInteger
|
||||
| SignedInteger RegularIdentifier
|
||||
| QuotedValue
|
||||
| 'TRUE'
|
||||
| 'FALSE'
|
||||
| 'NULL'
|
||||
;
|
122
src/jison/sql/druid/sql_update.jison
Normal file
122
src/jison/sql/druid/sql_update.jison
Normal file
@ -0,0 +1,122 @@
|
||||
// Licensed to Cloudera, Inc. under one
|
||||
// or more contributor license agreements. See the NOTICE file
|
||||
// distributed with this work for additional information
|
||||
// regarding copyright ownership. Cloudera, Inc. licenses this file
|
||||
// to you under the Apache License, Version 2.0 (the
|
||||
// "License"); you may not use this file except in compliance
|
||||
// with the License. You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
DataManipulation
|
||||
: UpdateStatement
|
||||
;
|
||||
|
||||
DataManipulation_EDIT
|
||||
: UpdateStatement_EDIT
|
||||
;
|
||||
|
||||
UpdateStatement
|
||||
: 'UPDATE' TargetTable 'SET' SetClauseList OptionalFromJoinedTable OptionalWhereClause
|
||||
;
|
||||
|
||||
UpdateStatement_EDIT
|
||||
: 'UPDATE' TargetTable_EDIT 'SET' SetClauseList OptionalFromJoinedTable OptionalWhereClause
|
||||
| 'UPDATE' TargetTable 'SET' SetClauseList_EDIT OptionalFromJoinedTable OptionalWhereClause
|
||||
| 'UPDATE' TargetTable 'SET' SetClauseList FromJoinedTable_EDIT OptionalWhereClause
|
||||
| 'UPDATE' TargetTable 'SET' SetClauseList OptionalFromJoinedTable WhereClause_EDIT
|
||||
| 'UPDATE' TargetTable 'SET' SetClauseList OptionalFromJoinedTable OptionalWhereClause 'CURSOR'
|
||||
{
|
||||
parser.suggestKeywords([ 'WHERE' ]);
|
||||
}
|
||||
| 'UPDATE' TargetTable 'CURSOR'
|
||||
{
|
||||
parser.suggestKeywords([ 'SET' ]);
|
||||
}
|
||||
| 'UPDATE' TargetTable_EDIT
|
||||
| 'UPDATE' TargetTable
|
||||
| 'UPDATE' 'CURSOR'
|
||||
{
|
||||
parser.suggestTables();
|
||||
parser.suggestDatabases({ appendDot: true });
|
||||
}
|
||||
;
|
||||
|
||||
TargetTable
|
||||
: TableName
|
||||
;
|
||||
|
||||
TargetTable_EDIT
|
||||
: TableName_EDIT
|
||||
;
|
||||
|
||||
TableName
|
||||
: LocalOrSchemaQualifiedName
|
||||
{
|
||||
parser.addTablePrimary($1);
|
||||
}
|
||||
;
|
||||
|
||||
TableName_EDIT
|
||||
: LocalOrSchemaQualifiedName_EDIT
|
||||
;
|
||||
|
||||
SetClauseList
|
||||
: SetClause
|
||||
| SetClauseList ',' SetClause
|
||||
;
|
||||
|
||||
SetClauseList_EDIT
|
||||
: SetClause_EDIT
|
||||
| SetClauseList ',' SetClause_EDIT
|
||||
| SetClause_EDIT ',' SetClauseList
|
||||
| SetClauseList ',' SetClause_EDIT ',' SetClauseList
|
||||
;
|
||||
|
||||
SetClause
|
||||
: SetTarget '=' UpdateSource
|
||||
;
|
||||
|
||||
SetClause_EDIT
|
||||
: SetTarget '=' UpdateSource_EDIT
|
||||
| SetTarget 'CURSOR'
|
||||
{
|
||||
parser.suggestKeywords([ '=' ]);
|
||||
}
|
||||
| 'CURSOR'
|
||||
{
|
||||
parser.suggestColumns();
|
||||
}
|
||||
;
|
||||
|
||||
SetTarget
|
||||
: ColumnReference
|
||||
;
|
||||
|
||||
UpdateSource
|
||||
: ValueExpression
|
||||
;
|
||||
|
||||
UpdateSource_EDIT
|
||||
: ValueExpression_EDIT
|
||||
;
|
||||
|
||||
OptionalFromJoinedTable
|
||||
:
|
||||
| 'FROM' TableReference -> $2
|
||||
;
|
||||
|
||||
FromJoinedTable_EDIT
|
||||
: 'FROM' 'CURSOR'
|
||||
{
|
||||
parser.suggestTables();
|
||||
parser.suggestDatabases({ appendDot: true });
|
||||
}
|
||||
| 'FROM' TableReference_EDIT
|
||||
;
|
39
src/jison/sql/druid/sql_use.jison
Normal file
39
src/jison/sql/druid/sql_use.jison
Normal file
@ -0,0 +1,39 @@
|
||||
// Licensed to Cloudera, Inc. under one
|
||||
// or more contributor license agreements. See the NOTICE file
|
||||
// distributed with this work for additional information
|
||||
// regarding copyright ownership. Cloudera, Inc. licenses this file
|
||||
// to you under the Apache License, Version 2.0 (the
|
||||
// "License"); you may not use this file except in compliance
|
||||
// with the License. You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
DataDefinition
|
||||
: UseStatement
|
||||
;
|
||||
|
||||
DataDefinition_EDIT
|
||||
: UseStatement_EDIT
|
||||
;
|
||||
|
||||
UseStatement
|
||||
: 'USE' RegularIdentifier
|
||||
{
|
||||
if (! parser.yy.cursorFound) {
|
||||
parser.yy.result.useDatabase = $2;
|
||||
}
|
||||
}
|
||||
;
|
||||
|
||||
UseStatement_EDIT
|
||||
: 'USE' 'CURSOR'
|
||||
{
|
||||
parser.suggestDatabases();
|
||||
}
|
||||
;
|
839
src/jison/sql/druid/sql_valueExpression.jison
Normal file
839
src/jison/sql/druid/sql_valueExpression.jison
Normal file
@ -0,0 +1,839 @@
|
||||
// Licensed to Cloudera, Inc. under one
|
||||
// or more contributor license agreements. See the NOTICE file
|
||||
// distributed with this work for additional information
|
||||
// regarding copyright ownership. Cloudera, Inc. licenses this file
|
||||
// to you under the Apache License, Version 2.0 (the
|
||||
// "License"); you may not use this file except in compliance
|
||||
// with the License. You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
ValueExpression
|
||||
: 'NOT' ValueExpression
|
||||
{
|
||||
// verifyType($2, 'BOOLEAN');
|
||||
$$ = { types: [ 'BOOLEAN' ] };
|
||||
}
|
||||
| '!' ValueExpression
|
||||
{
|
||||
// verifyType($2, 'BOOLEAN');
|
||||
$$ = { types: [ 'BOOLEAN' ] };
|
||||
}
|
||||
| '~' ValueExpression -> $2
|
||||
| '-' ValueExpression %prec NEGATION
|
||||
{
|
||||
// verifyType($2, 'NUMBER');
|
||||
$$ = $2;
|
||||
$2.types = ['NUMBER'];
|
||||
}
|
||||
| ValueExpression 'IS' OptionalNot 'NULL' -> { types: [ 'BOOLEAN' ] }
|
||||
| ValueExpression 'IS' OptionalNot 'TRUE' -> { types: [ 'BOOLEAN' ] }
|
||||
| ValueExpression 'IS' OptionalNot 'FALSE' -> { types: [ 'BOOLEAN' ] }
|
||||
| ValueExpression 'IS' OptionalNot 'DISTINCT' 'FROM' ValueExpression -> { types: [ 'BOOLEAN' ] }
|
||||
;
|
||||
|
||||
ValueExpression_EDIT
|
||||
: 'NOT' ValueExpression_EDIT -> { types: [ 'BOOLEAN' ], suggestFilters: $2.suggestFilters }
|
||||
| 'NOT' 'CURSOR'
|
||||
{
|
||||
parser.suggestFunctions();
|
||||
parser.suggestColumns();
|
||||
parser.suggestKeywords(['EXISTS']);
|
||||
$$ = { types: [ 'BOOLEAN' ] };
|
||||
}
|
||||
| '!' ValueExpression_EDIT -> { types: [ 'BOOLEAN' ], suggestFilters: $2.suggestFilters }
|
||||
| '!' AnyCursor
|
||||
{
|
||||
parser.suggestFunctions({ types: [ 'BOOLEAN' ] });
|
||||
parser.suggestColumns({ types: [ 'BOOLEAN' ] });
|
||||
$$ = { types: [ 'BOOLEAN' ] };
|
||||
}
|
||||
| '~' ValueExpression_EDIT -> { types: [ 'T' ], suggestFilters: $2.suggestFilters }
|
||||
| '~' 'PARTIAL_CURSOR'
|
||||
{
|
||||
parser.suggestFunctions();
|
||||
parser.suggestColumns();
|
||||
$$ = { types: [ 'T' ] };
|
||||
}
|
||||
| '-' ValueExpression_EDIT %prec NEGATION
|
||||
{
|
||||
if (!$2.typeSet) {
|
||||
parser.applyTypeToSuggestions('NUMBER');
|
||||
}
|
||||
$$ = { types: [ 'NUMBER' ], suggestFilters: $2.suggestFilters };
|
||||
}
|
||||
| '-' 'PARTIAL_CURSOR' %prec NEGATION
|
||||
{
|
||||
parser.suggestFunctions({ types: [ 'NUMBER' ] });
|
||||
parser.suggestColumns({ types: [ 'NUMBER' ] });
|
||||
$$ = { types: [ 'NUMBER' ] };
|
||||
}
|
||||
| ValueExpression 'IS' 'CURSOR'
|
||||
{
|
||||
parser.suggestKeywords(['FALSE', 'NOT NULL', 'NOT TRUE', 'NOT FALSE', 'NULL', 'TRUE']);
|
||||
$$ = { types: [ 'BOOLEAN' ] };
|
||||
}
|
||||
| ValueExpression 'IS' 'NOT' 'CURSOR'
|
||||
{
|
||||
parser.suggestKeywords(['FALSE', 'NULL', 'TRUE']);
|
||||
$$ = { types: [ 'BOOLEAN' ] };
|
||||
}
|
||||
| ValueExpression 'IS' OptionalNot 'DISTINCT' 'CURSOR'
|
||||
{
|
||||
$$ = { types: [ 'BOOLEAN' ] };
|
||||
}
|
||||
| ValueExpression 'IS' 'CURSOR' 'NULL'
|
||||
{
|
||||
parser.suggestKeywords(['NOT']);
|
||||
$$ = { types: [ 'BOOLEAN' ] };
|
||||
}
|
||||
| ValueExpression 'IS' 'CURSOR' 'FALSE'
|
||||
{
|
||||
parser.suggestKeywords(['NOT']);
|
||||
$$ = { types: [ 'BOOLEAN' ] };
|
||||
}
|
||||
| ValueExpression 'IS' 'CURSOR' 'TRUE'
|
||||
{
|
||||
parser.suggestKeywords(['NOT']);
|
||||
$$ = { types: [ 'BOOLEAN' ] };
|
||||
}
|
||||
| ValueExpression 'IS' OptionalNot 'DISTINCT' 'FROM' PartialBacktickedOrAnyCursor
|
||||
{
|
||||
parser.valueExpressionSuggest($1, $3 ? 'IS NOT DISTINCT FROM' : 'IS DISTINCT FROM');
|
||||
$$ = { types: [ 'BOOLEAN' ] };
|
||||
}
|
||||
| ValueExpression 'IS' OptionalNot 'DISTINCT' 'FROM' ValueExpression_EDIT
|
||||
{
|
||||
$$ = { types: [ 'BOOLEAN' ], suggestFilters: $6.suggestFilters }
|
||||
}
|
||||
;
|
||||
|
||||
// ------------------ EXISTS and parenthesized ------------------
|
||||
ValueExpression
|
||||
: 'EXISTS' TableSubQuery
|
||||
{
|
||||
$$ = { types: [ 'BOOLEAN' ] };
|
||||
// clear correlated flag after completed sub-query (set by lexer)
|
||||
parser.yy.correlatedSubQuery = false;
|
||||
}
|
||||
| '(' ValueExpression ')' -> $2
|
||||
;
|
||||
|
||||
ValueExpression_EDIT
|
||||
: 'EXISTS' TableSubQuery_EDIT -> { types: [ 'BOOLEAN' ] }
|
||||
| '(' ValueExpression_EDIT RightParenthesisOrError
|
||||
{
|
||||
$$ = $2;
|
||||
}
|
||||
| '(' 'CURSOR' RightParenthesisOrError
|
||||
{
|
||||
parser.valueExpressionSuggest();
|
||||
$$ = { types: ['T'], typeSet: true };
|
||||
}
|
||||
;
|
||||
|
||||
// ------------------ COMPARISON ------------------
|
||||
|
||||
ValueExpression
|
||||
: ValueExpression '=' ValueExpression
|
||||
{
|
||||
parser.addColRefToVariableIfExists($1, $3);
|
||||
$$ = { types: [ 'BOOLEAN' ] };
|
||||
}
|
||||
| ValueExpression '<' ValueExpression
|
||||
{
|
||||
parser.addColRefToVariableIfExists($1, $3);
|
||||
$$ = { types: [ 'BOOLEAN' ] };
|
||||
}
|
||||
| ValueExpression '>' ValueExpression
|
||||
{
|
||||
parser.addColRefToVariableIfExists($1, $3);
|
||||
$$ = { types: [ 'BOOLEAN' ] };
|
||||
}
|
||||
| ValueExpression 'COMPARISON_OPERATOR' ValueExpression
|
||||
{
|
||||
parser.addColRefToVariableIfExists($1, $3);
|
||||
$$ = { types: [ 'BOOLEAN' ] };
|
||||
}
|
||||
;
|
||||
|
||||
ValueExpression_EDIT
|
||||
: 'CURSOR' '=' ValueExpression
|
||||
{
|
||||
parser.valueExpressionSuggest($3, $2);
|
||||
parser.applyTypeToSuggestions($3.types);
|
||||
$$ = { types: [ 'BOOLEAN' ], typeSet: true };
|
||||
}
|
||||
| 'CURSOR' '<' ValueExpression
|
||||
{
|
||||
parser.valueExpressionSuggest($3, $2);
|
||||
parser.applyTypeToSuggestions($3.types);
|
||||
$$ = { types: [ 'BOOLEAN' ], typeSet: true };
|
||||
}
|
||||
| 'CURSOR' '>' ValueExpression
|
||||
{
|
||||
parser.valueExpressionSuggest($3, $2);
|
||||
parser.applyTypeToSuggestions($3.types);
|
||||
$$ = { types: [ 'BOOLEAN' ], typeSet: true };
|
||||
}
|
||||
| 'CURSOR' 'COMPARISON_OPERATOR' ValueExpression
|
||||
{
|
||||
parser.valueExpressionSuggest($3, $2);
|
||||
parser.applyTypeToSuggestions($3.types);
|
||||
$$ = { types: [ 'BOOLEAN' ], typeSet: true };
|
||||
}
|
||||
| ValueExpression_EDIT '=' ValueExpression
|
||||
{
|
||||
if (!$1.typeSet) {
|
||||
parser.applyTypeToSuggestions($3.types);
|
||||
parser.addColRefIfExists($3);
|
||||
}
|
||||
$$ = { types: [ 'BOOLEAN' ], suggestFilters: $1.suggestFilters }
|
||||
}
|
||||
| ValueExpression_EDIT '<' ValueExpression
|
||||
{
|
||||
if (!$1.typeSet) {
|
||||
parser.applyTypeToSuggestions($3.types);
|
||||
parser.addColRefIfExists($3);
|
||||
}
|
||||
$$ = { types: [ 'BOOLEAN' ], suggestFilters: $1.suggestFilters }
|
||||
}
|
||||
| ValueExpression_EDIT '>' ValueExpression
|
||||
{
|
||||
if (!$1.typeSet) {
|
||||
parser.applyTypeToSuggestions($3.types);
|
||||
parser.addColRefIfExists($3);
|
||||
}
|
||||
$$ = { types: [ 'BOOLEAN' ], suggestFilters: $1.suggestFilters }
|
||||
}
|
||||
| ValueExpression_EDIT 'COMPARISON_OPERATOR' ValueExpression
|
||||
{
|
||||
if (!$1.typeSet) {
|
||||
parser.applyTypeToSuggestions($3.types);
|
||||
parser.addColRefIfExists($3);
|
||||
}
|
||||
$$ = { types: [ 'BOOLEAN' ], suggestFilters: $1.suggestFilters }
|
||||
}
|
||||
| ValueExpression '=' PartialBacktickedOrAnyCursor
|
||||
{
|
||||
parser.valueExpressionSuggest($1, $2);
|
||||
parser.applyTypeToSuggestions($1.types);
|
||||
$$ = { types: [ 'BOOLEAN' ], typeSet: true };
|
||||
}
|
||||
| ValueExpression '<' PartialBacktickedOrAnyCursor
|
||||
{
|
||||
parser.valueExpressionSuggest($1, $2);
|
||||
parser.applyTypeToSuggestions($1.types);
|
||||
$$ = { types: [ 'BOOLEAN' ] , typeSet: true, endsWithLessThanOrEqual: true };
|
||||
}
|
||||
| ValueExpression '>' PartialBacktickedOrAnyCursor
|
||||
{
|
||||
parser.valueExpressionSuggest($1, $2);
|
||||
parser.applyTypeToSuggestions($1.types);
|
||||
$$ = { types: [ 'BOOLEAN' ], typeSet: true };
|
||||
}
|
||||
| ValueExpression 'COMPARISON_OPERATOR' PartialBacktickedOrAnyCursor
|
||||
{
|
||||
parser.valueExpressionSuggest($1, $2);
|
||||
parser.applyTypeToSuggestions($1.types);
|
||||
$$ = { types: [ 'BOOLEAN' ], typeSet: true, endsWithLessThanOrEqual: $2 === '<=' };
|
||||
}
|
||||
| ValueExpression '=' ValueExpression_EDIT
|
||||
{
|
||||
if (!$3.typeSet) {
|
||||
parser.applyTypeToSuggestions($1.types);
|
||||
parser.addColRefIfExists($1);
|
||||
}
|
||||
$$ = { types: [ 'BOOLEAN' ], suggestFilters: $3.suggestFilters }
|
||||
}
|
||||
| ValueExpression '<' ValueExpression_EDIT
|
||||
{
|
||||
if (!$3.typeSet) {
|
||||
parser.applyTypeToSuggestions($1.types);
|
||||
parser.addColRefIfExists($1);
|
||||
}
|
||||
$$ = { types: [ 'BOOLEAN' ], suggestFilters: $3.suggestFilters }
|
||||
}
|
||||
| ValueExpression '>' ValueExpression_EDIT
|
||||
{
|
||||
if (!$3.typeSet) {
|
||||
parser.applyTypeToSuggestions($1.types);
|
||||
parser.addColRefIfExists($1);
|
||||
}
|
||||
$$ = { types: [ 'BOOLEAN' ], suggestFilters: $3.suggestFilters }
|
||||
}
|
||||
| ValueExpression 'COMPARISON_OPERATOR' ValueExpression_EDIT
|
||||
{
|
||||
if (!$3.typeSet) {
|
||||
parser.applyTypeToSuggestions($1.types);
|
||||
parser.addColRefIfExists($1);
|
||||
}
|
||||
$$ = { types: [ 'BOOLEAN' ], suggestFilters: $3.suggestFilters }
|
||||
}
|
||||
;
|
||||
|
||||
|
||||
// ------------------ IN ------------------
|
||||
|
||||
ValueExpression
|
||||
: ValueExpression 'NOT' 'IN' '(' TableSubQueryInner ')' -> { types: [ 'BOOLEAN' ] }
|
||||
| ValueExpression 'NOT' 'IN' '(' ValueExpressionList ')' -> { types: [ 'BOOLEAN' ] }
|
||||
| ValueExpression 'IN' '(' TableSubQueryInner ')' -> { types: [ 'BOOLEAN' ] }
|
||||
| ValueExpression 'IN' '(' ValueExpressionList ')' -> { types: [ 'BOOLEAN' ] }
|
||||
;
|
||||
|
||||
ValueExpression_EDIT
|
||||
: ValueExpression 'NOT' 'IN' ValueExpressionInSecondPart_EDIT
|
||||
{
|
||||
if ($4.inValueEdit) {
|
||||
parser.valueExpressionSuggest($1, $2 + ' ' + $3);
|
||||
parser.applyTypeToSuggestions($1.types);
|
||||
}
|
||||
if ($4.cursorAtStart) {
|
||||
parser.suggestKeywords(['SELECT']);
|
||||
}
|
||||
$$ = { types: [ 'BOOLEAN' ], typeSet: true };
|
||||
}
|
||||
| ValueExpression 'IN' ValueExpressionInSecondPart_EDIT
|
||||
{
|
||||
if ($3.inValueEdit) {
|
||||
parser.valueExpressionSuggest($1, $2);
|
||||
parser.applyTypeToSuggestions($1.types);
|
||||
}
|
||||
if ($3.cursorAtStart) {
|
||||
parser.suggestKeywords(['SELECT']);
|
||||
}
|
||||
$$ = { types: [ 'BOOLEAN' ], typeSet: true };
|
||||
}
|
||||
| ValueExpression_EDIT 'NOT' 'IN' '(' ValueExpressionList RightParenthesisOrError -> { types: [ 'BOOLEAN' ], suggestFilters: $1.suggestFilters }
|
||||
| ValueExpression_EDIT 'NOT' 'IN' '(' TableSubQueryInner RightParenthesisOrError -> { types: [ 'BOOLEAN' ], suggestFilters: $1.suggestFilters }
|
||||
| ValueExpression_EDIT 'IN' '(' ValueExpressionList RightParenthesisOrError -> { types: [ 'BOOLEAN' ], suggestFilters: $1.suggestFilters }
|
||||
| ValueExpression_EDIT 'IN' '(' TableSubQueryInner RightParenthesisOrError -> { types: [ 'BOOLEAN' ], suggestFilters: $1.suggestFilters }
|
||||
;
|
||||
|
||||
ValueExpressionInSecondPart_EDIT
|
||||
: '(' TableSubQueryInner_EDIT RightParenthesisOrError
|
||||
| '(' ValueExpressionList_EDIT RightParenthesisOrError -> { inValueEdit: true }
|
||||
| '(' AnyCursor RightParenthesisOrError -> { inValueEdit: true, cursorAtStart: true }
|
||||
;
|
||||
|
||||
// ------------------ BETWEEN ------------------
|
||||
|
||||
ValueExpression
|
||||
: ValueExpression 'NOT' 'BETWEEN' ValueExpression 'BETWEEN_AND' ValueExpression -> { types: [ 'BOOLEAN' ] }
|
||||
| ValueExpression 'BETWEEN' ValueExpression 'BETWEEN_AND' ValueExpression -> { types: [ 'BOOLEAN' ] }
|
||||
;
|
||||
|
||||
ValueExpression_EDIT
|
||||
: ValueExpression_EDIT 'NOT' 'BETWEEN' ValueExpression 'BETWEEN_AND' ValueExpression
|
||||
{
|
||||
if ($4.types[0] === $6.types[0] && !$1.typeSet) {
|
||||
parser.applyTypeToSuggestions($4.types);
|
||||
}
|
||||
$$ = { types: [ 'BOOLEAN' ], suggestFilters: $1.suggestFilters };
|
||||
}
|
||||
| ValueExpression 'NOT' 'BETWEEN' ValueExpression_EDIT 'BETWEEN_AND' ValueExpression
|
||||
{
|
||||
if ($1.types[0] === $6.types[0] && !$4.typeSet) {
|
||||
parser.applyTypeToSuggestions($1.types);
|
||||
}
|
||||
$$ = { types: [ 'BOOLEAN' ], suggestFilters: $4.suggestFilters };
|
||||
}
|
||||
| ValueExpression 'NOT' 'BETWEEN' ValueExpression 'BETWEEN_AND' ValueExpression_EDIT
|
||||
{
|
||||
if ($1.types[0] === $4.types[0] && !$6.typeSet) {
|
||||
parser.applyTypeToSuggestions($1.types);
|
||||
}
|
||||
$$ = { types: [ 'BOOLEAN' ], suggestFilters: $6.suggestFilters };
|
||||
}
|
||||
| ValueExpression 'NOT' 'BETWEEN' ValueExpression 'BETWEEN_AND' 'CURSOR'
|
||||
{
|
||||
parser.valueExpressionSuggest($1, $5);
|
||||
$$ = { types: [ 'BOOLEAN' ], typeSet: true };
|
||||
}
|
||||
| ValueExpression 'NOT' 'BETWEEN' ValueExpression 'CURSOR'
|
||||
{
|
||||
parser.suggestValueExpressionKeywords($4, ['AND']);
|
||||
$$ = { types: [ 'BOOLEAN' ] };
|
||||
}
|
||||
| ValueExpression 'NOT' 'BETWEEN' 'CURSOR'
|
||||
{
|
||||
parser.valueExpressionSuggest($1, $2 + ' ' + $3);
|
||||
$$ = { types: [ 'BOOLEAN' ], typeSet: true };
|
||||
}
|
||||
| ValueExpression_EDIT 'BETWEEN' ValueExpression 'BETWEEN_AND' ValueExpression
|
||||
{
|
||||
if ($1.types[0] === $3.types[0] && !$1.typeSet) {
|
||||
parser.applyTypeToSuggestions($1.types)
|
||||
}
|
||||
$$ = { types: [ 'BOOLEAN' ], suggestFilters: $1.suggestFilters };
|
||||
}
|
||||
| ValueExpression 'BETWEEN' ValueExpression_EDIT 'BETWEEN_AND' ValueExpression
|
||||
{
|
||||
if ($1.types[0] === $3.types[0] && !$3.typeSet) {
|
||||
parser.applyTypeToSuggestions($1.types)
|
||||
}
|
||||
$$ = { types: [ 'BOOLEAN' ], suggestFilters: $3.suggestFilters };
|
||||
}
|
||||
| ValueExpression 'BETWEEN' ValueExpression 'BETWEEN_AND' ValueExpression_EDIT
|
||||
{
|
||||
if ($1.types[0] === $3.types[0] && !$5.typeSet) {
|
||||
parser.applyTypeToSuggestions($1.types)
|
||||
}
|
||||
$$ = { types: [ 'BOOLEAN' ], suggestFilters: $5.suggestFilters };
|
||||
}
|
||||
| ValueExpression 'BETWEEN' ValueExpression 'BETWEEN_AND' 'CURSOR'
|
||||
{
|
||||
parser.valueExpressionSuggest($1, $4);
|
||||
parser.applyTypeToSuggestions($1.types);
|
||||
$$ = { types: [ 'BOOLEAN' ], typeSet: true };
|
||||
}
|
||||
| ValueExpression 'BETWEEN' ValueExpression 'CURSOR'
|
||||
{
|
||||
parser.suggestValueExpressionKeywords($3, ['AND']);
|
||||
$$ = { types: [ 'BOOLEAN' ] };
|
||||
}
|
||||
| ValueExpression 'BETWEEN' 'CURSOR'
|
||||
{
|
||||
parser.valueExpressionSuggest($1, $2);
|
||||
parser.applyTypeToSuggestions($1.types);
|
||||
$$ = { types: [ 'BOOLEAN' ], typeSet: true };
|
||||
}
|
||||
;
|
||||
|
||||
// ------------------ BOOLEAN ------------------
|
||||
|
||||
ValueExpression
|
||||
: ValueExpression 'OR' ValueExpression
|
||||
{
|
||||
// verifyType($1, 'BOOLEAN');
|
||||
// verifyType($3, 'BOOLEAN');
|
||||
$$ = { types: [ 'BOOLEAN' ] };
|
||||
}
|
||||
| ValueExpression 'AND' ValueExpression
|
||||
{
|
||||
// verifyType($1, 'BOOLEAN');
|
||||
// verifyType($3, 'BOOLEAN');
|
||||
$$ = { types: [ 'BOOLEAN' ] };
|
||||
}
|
||||
;
|
||||
|
||||
ValueExpression_EDIT
|
||||
: 'CURSOR' 'OR' ValueExpression
|
||||
{
|
||||
parser.valueExpressionSuggest(undefined, $2);
|
||||
$$ = { types: [ 'BOOLEAN' ], typeSet: true, suggestFilters: true };
|
||||
}
|
||||
| ValueExpression_EDIT 'OR' ValueExpression
|
||||
{
|
||||
parser.addColRefIfExists($3);
|
||||
$$ = { types: [ 'BOOLEAN' ], suggestFilters: $1.suggestFilters }
|
||||
}
|
||||
| ValueExpression 'OR' PartialBacktickedOrAnyCursor
|
||||
{
|
||||
parser.valueExpressionSuggest(undefined, $2);
|
||||
$$ = { types: [ 'BOOLEAN' ], typeSet: true, suggestFilters: true };
|
||||
}
|
||||
| ValueExpression 'OR' ValueExpression_EDIT
|
||||
{
|
||||
parser.addColRefIfExists($1);
|
||||
$$ = { types: [ 'BOOLEAN' ], suggestFilters: $3.suggestFilters }
|
||||
}
|
||||
| 'CURSOR' 'AND' ValueExpression
|
||||
{
|
||||
parser.valueExpressionSuggest(undefined, $2);
|
||||
$$ = { types: [ 'BOOLEAN' ], typeSet: true, suggestFilters: true };
|
||||
}
|
||||
| ValueExpression_EDIT 'AND' ValueExpression
|
||||
{
|
||||
parser.addColRefIfExists($3);
|
||||
$$ = { types: [ 'BOOLEAN' ], suggestFilters: $1.suggestFilters }
|
||||
}
|
||||
| ValueExpression 'AND' PartialBacktickedOrAnyCursor
|
||||
{
|
||||
parser.valueExpressionSuggest(undefined, $2);
|
||||
$$ = { types: [ 'BOOLEAN' ], typeSet: true, suggestFilters: true };
|
||||
}
|
||||
| ValueExpression 'AND' ValueExpression_EDIT
|
||||
{
|
||||
parser.addColRefIfExists($1);
|
||||
$$ = { types: [ 'BOOLEAN' ], suggestFilters: $3.suggestFilters }
|
||||
}
|
||||
;
|
||||
|
||||
// ------------------ ARITHMETIC ------------------
|
||||
|
||||
ValueExpression
|
||||
: ValueExpression '-' ValueExpression
|
||||
{
|
||||
// verifyType($1, 'NUMBER');
|
||||
// verifyType($3, 'NUMBER');
|
||||
$$ = { types: [ 'NUMBER' ] };
|
||||
}
|
||||
| ValueExpression '*' ValueExpression
|
||||
{
|
||||
// verifyType($1, 'NUMBER');
|
||||
// verifyType($3, 'NUMBER');
|
||||
$$ = { types: [ 'NUMBER' ] };
|
||||
}
|
||||
| ValueExpression 'ARITHMETIC_OPERATOR' ValueExpression
|
||||
{
|
||||
// verifyType($1, 'NUMBER');
|
||||
// verifyType($3, 'NUMBER');
|
||||
$$ = { types: [ 'NUMBER' ] };
|
||||
}
|
||||
;
|
||||
|
||||
ValueExpression_EDIT
|
||||
: 'CURSOR' '*' ValueExpression
|
||||
{
|
||||
parser.valueExpressionSuggest(undefined, $2);
|
||||
parser.applyTypeToSuggestions([ 'NUMBER' ]);
|
||||
$$ = { types: [ 'NUMBER' ], typeSet: true };
|
||||
}
|
||||
| 'CURSOR' 'ARITHMETIC_OPERATOR' ValueExpression
|
||||
{
|
||||
parser.valueExpressionSuggest(undefined, $2);
|
||||
parser.applyTypeToSuggestions([ 'NUMBER' ]);
|
||||
$$ = { types: [ 'NUMBER' ], typeSet: true };
|
||||
}
|
||||
| ValueExpression_EDIT '-' ValueExpression
|
||||
{
|
||||
if (!$1.typeSet) {
|
||||
parser.applyTypeToSuggestions(['NUMBER']);
|
||||
parser.addColRefIfExists($3);
|
||||
}
|
||||
$$ = { types: [ 'NUMBER' ], suggestFilters: $1.suggestFilters }
|
||||
}
|
||||
| ValueExpression_EDIT '*' ValueExpression
|
||||
{
|
||||
if (!$1.typeSet) {
|
||||
parser.applyTypeToSuggestions(['NUMBER']);
|
||||
parser.addColRefIfExists($3);
|
||||
}
|
||||
$$ = { types: [ 'NUMBER' ], suggestFilters: $1.suggestFilters }
|
||||
}
|
||||
| ValueExpression_EDIT 'ARITHMETIC_OPERATOR' ValueExpression
|
||||
{
|
||||
if (!$1.typeSet) {
|
||||
parser.applyTypeToSuggestions(['NUMBER']);
|
||||
parser.addColRefIfExists($3);
|
||||
}
|
||||
$$ = { types: [ 'NUMBER' ], suggestFilters: $1.suggestFilters }
|
||||
}
|
||||
| ValueExpression '-' PartialBacktickedOrAnyCursor
|
||||
{
|
||||
parser.valueExpressionSuggest(undefined, $2);
|
||||
parser.applyTypeToSuggestions(['NUMBER']);
|
||||
$$ = { types: [ 'NUMBER' ], typeSet: true };
|
||||
}
|
||||
| ValueExpression '*' PartialBacktickedOrAnyCursor
|
||||
{
|
||||
parser.valueExpressionSuggest(undefined, $2);
|
||||
parser.applyTypeToSuggestions(['NUMBER']);
|
||||
$$ = { types: [ 'NUMBER' ], typeSet: true };
|
||||
}
|
||||
| ValueExpression 'ARITHMETIC_OPERATOR' PartialBacktickedOrAnyCursor
|
||||
{
|
||||
parser.valueExpressionSuggest(undefined, $2);
|
||||
parser.applyTypeToSuggestions(['NUMBER']);
|
||||
$$ = { types: [ 'NUMBER' ], typeSet: true };
|
||||
}
|
||||
| ValueExpression '-' ValueExpression_EDIT
|
||||
{
|
||||
if (!$3.typeSet) {
|
||||
parser.applyTypeToSuggestions(['NUMBER']);
|
||||
parser.addColRefIfExists($1);
|
||||
}
|
||||
$$ = { types: [ 'NUMBER' ], suggestFilters: $3.suggestFilters };
|
||||
}
|
||||
| ValueExpression '*' ValueExpression_EDIT
|
||||
{
|
||||
if (!$3.typeSet) {
|
||||
parser.applyTypeToSuggestions(['NUMBER']);
|
||||
parser.addColRefIfExists($1);
|
||||
}
|
||||
$$ = { types: [ 'NUMBER' ], suggestFilters: $3.suggestFilters };
|
||||
}
|
||||
| ValueExpression 'ARITHMETIC_OPERATOR' ValueExpression_EDIT
|
||||
{
|
||||
if (!$3.typeSet) {
|
||||
parser.applyTypeToSuggestions(['NUMBER']);
|
||||
parser.addColRefIfExists($1);
|
||||
}
|
||||
$$ = { types: [ 'NUMBER' ], suggestFilters: $3.suggestFilters };
|
||||
}
|
||||
;
|
||||
|
||||
// ------------------ LIKE, RLIKE and REGEXP ------------------
|
||||
|
||||
ValueExpression
|
||||
: ValueExpression LikeRightPart -> { types: [ 'BOOLEAN' ] }
|
||||
| ValueExpression 'NOT' LikeRightPart -> { types: [ 'BOOLEAN' ] }
|
||||
;
|
||||
|
||||
LikeRightPart
|
||||
: 'LIKE' ValueExpression -> { suggestKeywords: ['NOT'] }
|
||||
| 'RLIKE' ValueExpression -> { suggestKeywords: ['NOT'] }
|
||||
| 'REGEXP' ValueExpression -> { suggestKeywords: ['NOT'] }
|
||||
;
|
||||
|
||||
LikeRightPart_EDIT
|
||||
: 'LIKE' ValueExpression_EDIT
|
||||
| 'RLIKE' ValueExpression_EDIT
|
||||
| 'REGEXP' ValueExpression_EDIT
|
||||
| 'LIKE' PartialBacktickedOrCursor
|
||||
{
|
||||
parser.suggestFunctions({ types: [ 'STRING' ] });
|
||||
parser.suggestColumns({ types: [ 'STRING' ] });
|
||||
$$ = { types: ['BOOLEAN'] }
|
||||
}
|
||||
| 'RLIKE' PartialBacktickedOrCursor
|
||||
{
|
||||
parser.suggestFunctions({ types: [ 'STRING' ] });
|
||||
parser.suggestColumns({ types: [ 'STRING' ] });
|
||||
$$ = { types: ['BOOLEAN'] }
|
||||
}
|
||||
| 'REGEXP' PartialBacktickedOrCursor
|
||||
{
|
||||
parser.suggestFunctions({ types: [ 'STRING' ] });
|
||||
parser.suggestColumns({ types: [ 'STRING' ] });
|
||||
$$ = { types: ['BOOLEAN'] }
|
||||
}
|
||||
;
|
||||
|
||||
ValueExpression_EDIT
|
||||
: ValueExpression_EDIT LikeRightPart -> { types: [ 'BOOLEAN' ], suggestFilters: $1.suggestFilters }
|
||||
| ValueExpression_EDIT 'NOT' LikeRightPart -> { types: [ 'BOOLEAN' ], suggestFilters: $1.suggestFilters }
|
||||
| ValueExpression LikeRightPart_EDIT -> { types: [ 'BOOLEAN' ] }
|
||||
| ValueExpression 'NOT' LikeRightPart_EDIT -> { types: [ 'BOOLEAN' ] }
|
||||
| 'CURSOR' LikeRightPart
|
||||
{
|
||||
parser.valueExpressionSuggest(undefined, $2);
|
||||
parser.applyTypeToSuggestions([ 'STRING' ]);
|
||||
$$ = { types: [ 'BOOLEAN' ], typeSet: true };
|
||||
}
|
||||
| 'CURSOR' 'NOT' LikeRightPart
|
||||
{
|
||||
parser.valueExpressionSuggest(undefined, $2 + ' ' + $3);
|
||||
parser.applyTypeToSuggestions([ 'STRING' ]);
|
||||
$$ = { types: [ 'BOOLEAN' ], typeSet: true };
|
||||
}
|
||||
;
|
||||
|
||||
// ------------------ CASE, WHEN, THEN ------------------
|
||||
|
||||
ValueExpression
|
||||
: 'CASE' CaseRightPart -> $2
|
||||
| 'CASE' ValueExpression CaseRightPart -> $3
|
||||
;
|
||||
|
||||
ValueExpression_EDIT
|
||||
: 'CASE' CaseRightPart_EDIT -> $2
|
||||
| 'CASE' 'CURSOR' EndOrError
|
||||
{
|
||||
parser.valueExpressionSuggest();
|
||||
parser.suggestKeywords(['WHEN']);
|
||||
$$ = { types: [ 'T' ], typeSet: true };
|
||||
}
|
||||
| 'CASE' ValueExpression CaseRightPart_EDIT -> $3
|
||||
| 'CASE' ValueExpression 'CURSOR' EndOrError
|
||||
{
|
||||
parser.suggestValueExpressionKeywords($2, ['WHEN']);
|
||||
$$ = { types: [ 'T' ], typeSet: true };
|
||||
}
|
||||
| 'CASE' ValueExpression_EDIT CaseRightPart
|
||||
{
|
||||
$$ = $3;
|
||||
$$.suggestFilters = $2.suggestFilters;
|
||||
}
|
||||
| 'CASE' ValueExpression_EDIT EndOrError -> { types: [ 'T' ], suggestFilters: $2.suggestFilters }
|
||||
| 'CASE' 'CURSOR' CaseRightPart -> { types: [ 'T' ] }
|
||||
;
|
||||
|
||||
CaseRightPart
|
||||
: CaseWhenThenList 'END' -> parser.findCaseType($1)
|
||||
| CaseWhenThenList 'ELSE' ValueExpression 'END'
|
||||
{
|
||||
$1.caseTypes.push($3);
|
||||
$$ = parser.findCaseType($1);
|
||||
}
|
||||
;
|
||||
|
||||
CaseRightPart_EDIT
|
||||
: CaseWhenThenList_EDIT EndOrError -> parser.findCaseType($1)
|
||||
| CaseWhenThenList 'ELSE' ValueExpression 'CURSOR'
|
||||
{
|
||||
parser.suggestValueExpressionKeywords($3, ['END']);
|
||||
$1.caseTypes.push($3);
|
||||
$$ = parser.findCaseType($1);
|
||||
}
|
||||
| CaseWhenThenList_EDIT 'ELSE' ValueExpression EndOrError
|
||||
{
|
||||
$1.caseTypes.push($3);
|
||||
$$ = parser.findCaseType($1);
|
||||
}
|
||||
| CaseWhenThenList_EDIT 'ELSE' EndOrError -> parser.findCaseType($1)
|
||||
| CaseWhenThenList 'CURSOR' ValueExpression EndOrError
|
||||
{
|
||||
if ($4.toLowerCase() !== 'end') {
|
||||
parser.suggestValueExpressionKeywords($1, [{ value: 'END', weight: 3 }, { value: 'ELSE', weight: 2 }, { value: 'WHEN', weight: 1 }]);
|
||||
} else {
|
||||
parser.suggestValueExpressionKeywords($1, [{ value: 'ELSE', weight: 2 }, { value: 'WHEN', weight: 1 }]);
|
||||
}
|
||||
$$ = parser.findCaseType($1);
|
||||
}
|
||||
| CaseWhenThenList 'CURSOR' EndOrError
|
||||
{
|
||||
if ($3.toLowerCase() !== 'end') {
|
||||
parser.suggestValueExpressionKeywords($1, [{ value: 'END', weight: 3 }, { value: 'ELSE', weight: 2 }, { value: 'WHEN', weight: 1 }]);
|
||||
} else {
|
||||
parser.suggestValueExpressionKeywords($1, [{ value: 'ELSE', weight: 2 }, { value: 'WHEN', weight: 1 }]);
|
||||
}
|
||||
$$ = parser.findCaseType($1);
|
||||
}
|
||||
| CaseWhenThenList 'ELSE' ValueExpression_EDIT EndOrError
|
||||
{
|
||||
$1.caseTypes.push($3);
|
||||
$$ = parser.findCaseType($1);
|
||||
$$.suggestFilters = $3.suggestFilters
|
||||
}
|
||||
| CaseWhenThenList 'ELSE' 'CURSOR' EndOrError
|
||||
{
|
||||
parser.valueExpressionSuggest();
|
||||
$$ = parser.findCaseType($1);
|
||||
}
|
||||
| 'ELSE' 'CURSOR' EndOrError
|
||||
{
|
||||
parser.valueExpressionSuggest();
|
||||
$$ = { types: [ 'T' ], typeSet: true };
|
||||
}
|
||||
| 'CURSOR' 'ELSE' ValueExpression EndOrError
|
||||
{
|
||||
parser.valueExpressionSuggest();
|
||||
parser.suggestKeywords(['WHEN']);
|
||||
$$ = $3;
|
||||
}
|
||||
| 'CURSOR' 'ELSE' EndOrError
|
||||
{
|
||||
parser.valueExpressionSuggest();
|
||||
parser.suggestKeywords(['WHEN']);
|
||||
$$ = { types: [ 'T' ] };
|
||||
}
|
||||
;
|
||||
|
||||
EndOrError
|
||||
: 'END'
|
||||
| error
|
||||
;
|
||||
|
||||
CaseWhenThenList
|
||||
: CaseWhenThenListPartTwo -> { caseTypes: [ $1 ], lastType: $1 }
|
||||
| CaseWhenThenList CaseWhenThenListPartTwo
|
||||
{
|
||||
$1.caseTypes.push($2);
|
||||
$$ = { caseTypes: $1.caseTypes, lastType: $2 };
|
||||
}
|
||||
;
|
||||
|
||||
CaseWhenThenList_EDIT
|
||||
: CaseWhenThenListPartTwo_EDIT
|
||||
| CaseWhenThenList CaseWhenThenListPartTwo_EDIT
|
||||
| CaseWhenThenList CaseWhenThenListPartTwo_EDIT CaseWhenThenList
|
||||
| CaseWhenThenList 'CURSOR' CaseWhenThenList
|
||||
{
|
||||
parser.suggestValueExpressionKeywords($1, ['WHEN']);
|
||||
}
|
||||
| CaseWhenThenListPartTwo_EDIT CaseWhenThenList -> $2
|
||||
;
|
||||
|
||||
CaseWhenThenListPartTwo
|
||||
: 'WHEN' ValueExpression 'THEN' ValueExpression -> $4
|
||||
;
|
||||
|
||||
CaseWhenThenListPartTwo_EDIT
|
||||
: 'WHEN' ValueExpression_EDIT -> { caseTypes: [{ types: ['T'] }], suggestFilters: $2.suggestFilters }
|
||||
| 'WHEN' ValueExpression_EDIT 'THEN' -> { caseTypes: [{ types: ['T'] }], suggestFilters: $2.suggestFilters }
|
||||
| 'WHEN' ValueExpression_EDIT 'THEN' ValueExpression -> { caseTypes: [$4], suggestFilters: $2.suggestFilters }
|
||||
| 'WHEN' ValueExpression 'THEN' ValueExpression_EDIT -> { caseTypes: [$4], suggestFilters: $4.suggestFilters }
|
||||
| 'WHEN' 'THEN' ValueExpression_EDIT -> { caseTypes: [$3], suggestFilters: $3.suggestFilters }
|
||||
| 'CURSOR' ValueExpression 'THEN'
|
||||
{
|
||||
parser.suggestKeywords(['WHEN']);
|
||||
$$ = { caseTypes: [{ types: ['T'] }] };
|
||||
}
|
||||
| 'CURSOR' ValueExpression 'THEN' ValueExpression
|
||||
{
|
||||
parser.suggestKeywords(['WHEN']);
|
||||
$$ = { caseTypes: [$4] };
|
||||
}
|
||||
| 'CURSOR' 'THEN'
|
||||
{
|
||||
parser.valueExpressionSuggest();
|
||||
parser.suggestKeywords(['WHEN']);
|
||||
$$ = { caseTypes: [{ types: ['T'] }] };
|
||||
}
|
||||
| 'CURSOR' 'THEN' ValueExpression
|
||||
{
|
||||
parser.valueExpressionSuggest();
|
||||
parser.suggestKeywords(['WHEN']);
|
||||
$$ = { caseTypes: [{ types: ['T'] }] };
|
||||
}
|
||||
| 'WHEN' 'CURSOR'
|
||||
{
|
||||
parser.valueExpressionSuggest();
|
||||
$$ = { caseTypes: [{ types: ['T'] }], suggestFilters: true };
|
||||
}
|
||||
| 'WHEN' 'CURSOR' ValueExpression
|
||||
{
|
||||
parser.valueExpressionSuggest();
|
||||
parser.suggestKeywords(['THEN']);
|
||||
$$ = { caseTypes: [{ types: ['T'] }], suggestFilters: true };
|
||||
}
|
||||
| 'WHEN' 'CURSOR' 'THEN'
|
||||
{
|
||||
parser.valueExpressionSuggest();
|
||||
$$ = { caseTypes: [{ types: ['T'] }], suggestFilters: true };
|
||||
}
|
||||
| 'WHEN' 'CURSOR' 'THEN' ValueExpression
|
||||
{
|
||||
parser.valueExpressionSuggest();
|
||||
$$ = { caseTypes: [$4], suggestFilters: true };
|
||||
}
|
||||
| 'WHEN' ValueExpression 'CURSOR'
|
||||
{
|
||||
parser.suggestValueExpressionKeywords($2, ['THEN']);
|
||||
$$ = { caseTypes: [{ types: ['T'] }] };
|
||||
}
|
||||
| 'WHEN' ValueExpression 'CURSOR' ValueExpression
|
||||
{
|
||||
parser.suggestValueExpressionKeywords($2, ['THEN']);
|
||||
$$ = { caseTypes: [{ types: ['T'] }] };
|
||||
}
|
||||
| 'WHEN' ValueExpression 'THEN' 'CURSOR'
|
||||
{
|
||||
parser.valueExpressionSuggest();
|
||||
$$ = { caseTypes: [{ types: ['T'] }] };
|
||||
}
|
||||
| 'WHEN' ValueExpression 'THEN' 'CURSOR' ValueExpression
|
||||
{
|
||||
parser.valueExpressionSuggest();
|
||||
$$ = { caseTypes: [{ types: ['T'] }] };
|
||||
}
|
||||
| 'WHEN' 'THEN' 'CURSOR' ValueExpression
|
||||
{
|
||||
parser.valueExpressionSuggest();
|
||||
$$ = { caseTypes: [{ types: ['T'] }] };
|
||||
}
|
||||
| 'WHEN' 'THEN' 'CURSOR'
|
||||
{
|
||||
parser.valueExpressionSuggest();
|
||||
$$ = { caseTypes: [{ types: ['T'] }] };
|
||||
}
|
||||
;
|
19
src/jison/sql/druid/syntax_footer.jison
Normal file
19
src/jison/sql/druid/syntax_footer.jison
Normal file
@ -0,0 +1,19 @@
|
||||
// Licensed to Cloudera, Inc. under one
|
||||
// or more contributor license agreements. See the NOTICE file
|
||||
// distributed with this work for additional information
|
||||
// regarding copyright ownership. Cloudera, Inc. licenses this file
|
||||
// to you under the Apache License, Version 2.0 (the
|
||||
// "License"); you may not use this file except in compliance
|
||||
// with the License. You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
%%
|
||||
|
||||
SqlParseSupport.initSyntaxParser(parser);
|
28
src/jison/sql/druid/syntax_header.jison
Normal file
28
src/jison/sql/druid/syntax_header.jison
Normal file
@ -0,0 +1,28 @@
|
||||
// Licensed to Cloudera, Inc. under one
|
||||
// or more contributor license agreements. See the NOTICE file
|
||||
// distributed with this work for additional information
|
||||
// regarding copyright ownership. Cloudera, Inc. licenses this file
|
||||
// to you under the Apache License, Version 2.0 (the
|
||||
// "License"); you may not use this file except in compliance
|
||||
// with the License. You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
%left 'AND' 'OR'
|
||||
%left 'BETWEEN'
|
||||
%left 'NOT' '!' '~'
|
||||
%left '=' '<' '>' 'COMPARISON_OPERATOR'
|
||||
%left '-' '*' 'ARITHMETIC_OPERATOR'
|
||||
|
||||
%left ';' ','
|
||||
%nonassoc 'IN' 'IS' 'LIKE' 'RLIKE' 'REGEXP' 'EXISTS' NEGATION
|
||||
|
||||
%start SqlSyntax
|
||||
|
||||
%%
|
19
src/jison/sql/elasticsearch/autocomplete_footer.jison
Normal file
19
src/jison/sql/elasticsearch/autocomplete_footer.jison
Normal file
@ -0,0 +1,19 @@
|
||||
// Licensed to Cloudera, Inc. under one
|
||||
// or more contributor license agreements. See the NOTICE file
|
||||
// distributed with this work for additional information
|
||||
// regarding copyright ownership. Cloudera, Inc. licenses this file
|
||||
// to you under the Apache License, Version 2.0 (the
|
||||
// "License"); you may not use this file except in compliance
|
||||
// with the License. You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
%%
|
||||
|
||||
SqlParseSupport.initSqlParser(parser);
|
29
src/jison/sql/elasticsearch/autocomplete_header.jison
Normal file
29
src/jison/sql/elasticsearch/autocomplete_header.jison
Normal file
@ -0,0 +1,29 @@
|
||||
// Licensed to Cloudera, Inc. under one
|
||||
// or more contributor license agreements. See the NOTICE file
|
||||
// distributed with this work for additional information
|
||||
// regarding copyright ownership. Cloudera, Inc. licenses this file
|
||||
// to you under the Apache License, Version 2.0 (the
|
||||
// "License"); you may not use this file except in compliance
|
||||
// with the License. You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
%left 'AND' 'OR'
|
||||
%left 'BETWEEN'
|
||||
%left 'NOT' '!' '~'
|
||||
%left '=' '<' '>' 'COMPARISON_OPERATOR'
|
||||
%left '-' '*' 'ARITHMETIC_OPERATOR'
|
||||
|
||||
%left ';' ','
|
||||
%nonassoc 'CURSOR' 'PARTIAL_CURSOR'
|
||||
%nonassoc 'IN' 'IS' 'LIKE' 'RLIKE' 'REGEXP' 'EXISTS' NEGATION
|
||||
|
||||
%start SqlAutocomplete
|
||||
|
||||
%%
|
226
src/jison/sql/elasticsearch/sql.jisonlex
Normal file
226
src/jison/sql/elasticsearch/sql.jisonlex
Normal file
@ -0,0 +1,226 @@
|
||||
// Licensed to Cloudera, Inc. under one
|
||||
// or more contributor license agreements. See the NOTICE file
|
||||
// distributed with this work for additional information
|
||||
// regarding copyright ownership. Cloudera, Inc. licenses this file
|
||||
// to you under the Apache License, Version 2.0 (the
|
||||
// "License"); you may not use this file except in compliance
|
||||
// with the License. You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
%options case-insensitive flex
|
||||
%s between
|
||||
%x hdfs doubleQuotedValue singleQuotedValue backtickedValue
|
||||
%%
|
||||
|
||||
\s { /* skip whitespace */ }
|
||||
'--'.* { /* skip comments */ }
|
||||
[/][*][^*]*[*]+([^/*][^*]*[*]+)*[/] { /* skip comments */ }
|
||||
|
||||
'\u2020' { parser.yy.partialCursor = false; parser.yy.cursorFound = yylloc; return 'CURSOR'; }
|
||||
'\u2021' { parser.yy.partialCursor = true; parser.yy.cursorFound = yylloc; return 'PARTIAL_CURSOR'; }
|
||||
|
||||
<between>'AND' { this.popState(); return 'BETWEEN_AND'; }
|
||||
|
||||
// Reserved Keywords
|
||||
'ALL' { return 'ALL'; }
|
||||
'ALTER' { parser.determineCase(yytext); parser.addStatementTypeLocation('ALTER', yylloc, yy.lexer.upcomingInput()); return 'ALTER'; }
|
||||
'AND' { return 'AND'; }
|
||||
'AS' { return 'AS'; }
|
||||
'ASC' { return 'ASC'; }
|
||||
'BETWEEN' { this.begin('between'); return 'BETWEEN'; }
|
||||
'BIGINT' { return 'BIGINT'; }
|
||||
'BOOLEAN' { return 'BOOLEAN'; }
|
||||
'BY' { return 'BY'; }
|
||||
'CASCADE' { return 'CASCADE'; }
|
||||
'CASE' { return 'CASE'; }
|
||||
'CHAR' { return 'CHAR'; }
|
||||
'COMMENT' { return 'COMMENT'; }
|
||||
'CREATE' { parser.determineCase(yytext); return 'CREATE'; }
|
||||
'CROSS' { return 'CROSS'; }
|
||||
'CURRENT' { return 'CURRENT'; }
|
||||
'DATABASE' { return 'DATABASE'; }
|
||||
'DECIMAL' { return 'DECIMAL'; }
|
||||
'DESC' { return 'DESC'; }
|
||||
'DISTINCT' { return 'DISTINCT'; }
|
||||
'DIV' { return 'ARITHMETIC_OPERATOR'; }
|
||||
'DOUBLE' { return 'DOUBLE'; }
|
||||
'DROP' { parser.determineCase(yytext); parser.addStatementTypeLocation('DROP', yylloc, yy.lexer.upcomingInput()); return 'DROP'; }
|
||||
'ELSE' { return 'ELSE'; }
|
||||
'END' { return 'END'; }
|
||||
'EXISTS' { parser.yy.correlatedSubQuery = true; return 'EXISTS'; }
|
||||
'FALSE' { return 'FALSE'; }
|
||||
'FLOAT' { return 'FLOAT'; }
|
||||
'FOLLOWING' { return 'FOLLOWING'; }
|
||||
'FROM' { parser.determineCase(yytext); return 'FROM'; }
|
||||
'FULL' { return 'FULL'; }
|
||||
'GROUP' { return 'GROUP'; }
|
||||
'HAVING' { return 'HAVING'; }
|
||||
'IF' { return 'IF'; }
|
||||
'IN' { return 'IN'; }
|
||||
'INNER' { return 'INNER'; }
|
||||
'INSERT' { return 'INSERT'; }
|
||||
'INT' { return 'INT'; }
|
||||
'INTO' { return 'INTO'; }
|
||||
'IS' { return 'IS'; }
|
||||
'JOIN' { return 'JOIN'; }
|
||||
'LEFT' { return 'LEFT'; }
|
||||
'LIKE' { return 'LIKE'; }
|
||||
'LIMIT' { return 'LIMIT'; }
|
||||
'NOT' { return 'NOT'; }
|
||||
'NULL' { return 'NULL'; }
|
||||
'ON' { return 'ON'; }
|
||||
'OPTION' { return 'OPTION'; }
|
||||
'OR' { return 'OR'; }
|
||||
'ORDER' { return 'ORDER'; }
|
||||
'OUTER' { return 'OUTER'; }
|
||||
'PARTITION' { return 'PARTITION'; }
|
||||
'PRECEDING' { return 'PRECEDING'; }
|
||||
'PURGE' { return 'PURGE'; }
|
||||
'RANGE' { return 'RANGE'; }
|
||||
'REGEXP' { return 'REGEXP'; }
|
||||
'RIGHT' { return 'RIGHT'; }
|
||||
'RLIKE' { return 'RLIKE'; }
|
||||
'ROW' { return 'ROW'; }
|
||||
'ROLE' { return 'ROLE'; }
|
||||
'ROWS' { return 'ROWS'; }
|
||||
'SCHEMA' { return 'SCHEMA'; }
|
||||
'SELECT' { parser.determineCase(yytext); parser.addStatementTypeLocation('SELECT', yylloc); return 'SELECT'; }
|
||||
'SEMI' { return 'SEMI'; }
|
||||
'SET' { parser.determineCase(yytext); parser.addStatementTypeLocation('SET', yylloc); return 'SET'; }
|
||||
'SHOW' { parser.determineCase(yytext); parser.addStatementTypeLocation('SHOW', yylloc); return 'SHOW'; }
|
||||
'SMALLINT' { return 'SMALLINT'; }
|
||||
'STRING' { return 'STRING'; }
|
||||
'TABLE' { return 'TABLE'; }
|
||||
'THEN' { return 'THEN'; }
|
||||
'TIMESTAMP' { return 'TIMESTAMP'; }
|
||||
'TINYINT' { return 'TINYINT'; }
|
||||
'TO' { return 'TO'; }
|
||||
'TRUE' { return 'TRUE'; }
|
||||
'TRUNCATE' { parser.determineCase(yytext); parser.addStatementTypeLocation('TRUNCATE', yylloc, yy.lexer.upcomingInput()); return 'TRUNCATE'; }
|
||||
'UNBOUNDED' { return 'UNBOUNDED'; }
|
||||
'UNION' { return 'UNION'; }
|
||||
'UPDATE' { parser.determineCase(yytext); return 'UPDATE'; }
|
||||
'USE' { parser.determineCase(yytext); parser.addStatementTypeLocation('USE', yylloc); return 'USE'; }
|
||||
'VALUES' { return 'VALUES'; }
|
||||
'VARCHAR' { return 'VARCHAR'; }
|
||||
'VIEW' { return 'VIEW'; }
|
||||
'WHEN' { return 'WHEN'; }
|
||||
'WHERE' { return 'WHERE'; }
|
||||
'WITH' { parser.determineCase(yytext); parser.addStatementTypeLocation('WITH', yylloc); return 'WITH'; }
|
||||
|
||||
// Non-reserved Keywords
|
||||
'OVER' { return 'OVER'; }
|
||||
'ROLE' { return 'ROLE'; }
|
||||
|
||||
// --- UDFs ---
|
||||
AVG\s*\( { yy.lexer.unput('('); yytext = 'avg'; parser.addFunctionLocation(yylloc, yytext); return 'AVG'; }
|
||||
CAST\s*\( { yy.lexer.unput('('); yytext = 'cast'; parser.addFunctionLocation(yylloc, yytext); return 'CAST'; }
|
||||
COUNT\s*\( { yy.lexer.unput('('); yytext = 'count'; parser.addFunctionLocation(yylloc, yytext); return 'COUNT'; }
|
||||
MAX\s*\( { yy.lexer.unput('('); yytext = 'max'; parser.addFunctionLocation(yylloc, yytext); return 'MAX'; }
|
||||
MIN\s*\( { yy.lexer.unput('('); yytext = 'min'; parser.addFunctionLocation(yylloc, yytext); return 'MIN'; }
|
||||
STDDEV_POP\s*\( { yy.lexer.unput('('); yytext = 'stddev_pop'; parser.addFunctionLocation(yylloc, yytext); return 'STDDEV_POP'; }
|
||||
STDDEV_SAMP\s*\( { yy.lexer.unput('('); yytext = 'stddev_samp'; parser.addFunctionLocation(yylloc, yytext); return 'STDDEV_SAMP'; }
|
||||
SUM\s*\( { yy.lexer.unput('('); yytext = 'sum'; parser.addFunctionLocation(yylloc, yytext); return 'SUM'; }
|
||||
VAR_POP\s*\( { yy.lexer.unput('('); yytext = 'var_pop'; parser.addFunctionLocation(yylloc, yytext); return 'VAR_POP'; }
|
||||
VAR_SAMP\s*\( { yy.lexer.unput('('); yytext = 'var_samp'; parser.addFunctionLocation(yylloc, yytext); return 'VAR_SAMP'; }
|
||||
VARIANCE\s*\( { yy.lexer.unput('('); yytext = 'variance'; parser.addFunctionLocation(yylloc, yytext); return 'VARIANCE'; }
|
||||
|
||||
// Analytical functions
|
||||
CUME_DIST\s*\( { yy.lexer.unput('('); yytext = 'cume_dist'; parser.addFunctionLocation(yylloc, yytext); return 'ANALYTIC'; }
|
||||
DENSE_RANK\s*\( { yy.lexer.unput('('); yytext = 'dense_rank'; parser.addFunctionLocation(yylloc, yytext); return 'ANALYTIC'; }
|
||||
FIRST_VALUE\s*\( { yy.lexer.unput('('); yytext = 'first_value'; parser.addFunctionLocation(yylloc, yytext); return 'ANALYTIC'; }
|
||||
LAG\s*\( { yy.lexer.unput('('); yytext = 'lag'; parser.addFunctionLocation(yylloc, yytext); return 'ANALYTIC'; }
|
||||
LAST_VALUE\s*\( { yy.lexer.unput('('); yytext = 'last_value'; parser.addFunctionLocation(yylloc, yytext); return 'ANALYTIC'; }
|
||||
LEAD\s*\( { yy.lexer.unput('('); yytext = 'lead'; parser.addFunctionLocation(yylloc, yytext); return 'ANALYTIC'; }
|
||||
RANK\s*\( { yy.lexer.unput('('); yytext = 'rank'; parser.addFunctionLocation(yylloc, yytext); return 'ANALYTIC'; }
|
||||
ROW_NUMBER\s*\( { yy.lexer.unput('('); yytext = 'row_number'; parser.addFunctionLocation(yylloc, yytext); return 'ANALYTIC'; }
|
||||
|
||||
[0-9]+ { return 'UNSIGNED_INTEGER'; }
|
||||
[0-9]+(?:[YSL]|BD)? { return 'UNSIGNED_INTEGER'; }
|
||||
[0-9]+E { return 'UNSIGNED_INTEGER_E'; }
|
||||
[A-Za-z0-9_]+ { return 'REGULAR_IDENTIFIER'; }
|
||||
|
||||
<hdfs>'\u2020' { parser.yy.cursorFound = true; return 'CURSOR'; }
|
||||
<hdfs>'\u2021' { parser.yy.cursorFound = true; return 'PARTIAL_CURSOR'; }
|
||||
<hdfs>\s+['"] { return 'HDFS_START_QUOTE'; }
|
||||
<hdfs>[^'"\u2020\u2021]+ { parser.addFileLocation(yylloc, yytext); return 'HDFS_PATH'; }
|
||||
<hdfs>['"] { this.popState(); return 'HDFS_END_QUOTE'; }
|
||||
<hdfs><<EOF>> { return 'EOF'; }
|
||||
|
||||
'&&' { return 'AND'; }
|
||||
'||' { return 'OR'; }
|
||||
|
||||
'=' { return '='; }
|
||||
'<' { return '<'; }
|
||||
'>' { return '>'; }
|
||||
'!=' { return 'COMPARISON_OPERATOR'; }
|
||||
'<=' { return 'COMPARISON_OPERATOR'; }
|
||||
'>=' { return 'COMPARISON_OPERATOR'; }
|
||||
'<>' { return 'COMPARISON_OPERATOR'; }
|
||||
'<=>' { return 'COMPARISON_OPERATOR'; }
|
||||
|
||||
'-' { return '-'; }
|
||||
'*' { return '*'; }
|
||||
'+' { return 'ARITHMETIC_OPERATOR'; }
|
||||
'/' { return 'ARITHMETIC_OPERATOR'; }
|
||||
'%' { return 'ARITHMETIC_OPERATOR'; }
|
||||
'|' { return 'ARITHMETIC_OPERATOR'; }
|
||||
'^' { return 'ARITHMETIC_OPERATOR'; }
|
||||
'&' { return 'ARITHMETIC_OPERATOR'; }
|
||||
|
||||
',' { return ','; }
|
||||
'.' { return '.'; }
|
||||
':' { return ':'; }
|
||||
';' { return ';'; }
|
||||
'~' { return '~'; }
|
||||
'!' { return '!'; }
|
||||
|
||||
'(' { return '('; }
|
||||
')' { return ')'; }
|
||||
'[' { return '['; }
|
||||
']' { return ']'; }
|
||||
|
||||
\$\{[^}]*\} { return 'VARIABLE_REFERENCE'; }
|
||||
|
||||
\` { this.begin('backtickedValue'); return 'BACKTICK'; }
|
||||
<backtickedValue>[^`]+ {
|
||||
if (parser.handleQuotedValueWithCursor(this, yytext, yylloc, '`')) {
|
||||
return 'PARTIAL_VALUE';
|
||||
}
|
||||
return 'VALUE';
|
||||
}
|
||||
<backtickedValue>\` { this.popState(); return 'BACKTICK'; }
|
||||
|
||||
\' { this.begin('singleQuotedValue'); return 'SINGLE_QUOTE'; }
|
||||
<singleQuotedValue>(?:\\\\|\\[']|[^'])+ {
|
||||
if (parser.handleQuotedValueWithCursor(this, yytext, yylloc, '\'')) {
|
||||
return 'PARTIAL_VALUE';
|
||||
}
|
||||
return 'VALUE';
|
||||
}
|
||||
<singleQuotedValue>\' { this.popState(); return 'SINGLE_QUOTE'; }
|
||||
|
||||
\" { this.begin('doubleQuotedValue'); return 'DOUBLE_QUOTE'; }
|
||||
<doubleQuotedValue>(?:\\\\|\\["]|[^"])+ {
|
||||
if (parser.handleQuotedValueWithCursor(this, yytext, yylloc, '"')) {
|
||||
return 'PARTIAL_VALUE';
|
||||
}
|
||||
return 'VALUE';
|
||||
}
|
||||
<doubleQuotedValue>\" { this.popState(); return 'DOUBLE_QUOTE'; }
|
||||
|
||||
<<EOF>> { return 'EOF'; }
|
||||
|
||||
. { /* To prevent console logging of unknown chars */ }
|
||||
<between>. { }
|
||||
<hdfs>. { }
|
||||
<backtickedValue>. { }
|
||||
<singleQuotedValue>. { }
|
||||
<doubleQuotedValue>. { }
|
109
src/jison/sql/elasticsearch/sql_alter.jison
Normal file
109
src/jison/sql/elasticsearch/sql_alter.jison
Normal file
@ -0,0 +1,109 @@
|
||||
// Licensed to Cloudera, Inc. under one
|
||||
// or more contributor license agreements. See the NOTICE file
|
||||
// distributed with this work for additional information
|
||||
// regarding copyright ownership. Cloudera, Inc. licenses this file
|
||||
// to you under the Apache License, Version 2.0 (the
|
||||
// "License"); you may not use this file except in compliance
|
||||
// with the License. You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
DataDefinition
|
||||
: AlterStatement
|
||||
;
|
||||
|
||||
DataDefinition_EDIT
|
||||
: AlterStatement_EDIT
|
||||
;
|
||||
|
||||
AlterStatement
|
||||
: AlterTable
|
||||
| AlterView
|
||||
;
|
||||
|
||||
AlterStatement_EDIT
|
||||
: AlterTable_EDIT
|
||||
| AlterView_EDIT
|
||||
| 'ALTER' 'CURSOR'
|
||||
{
|
||||
parser.suggestKeywords(['TABLE', 'VIEW']);
|
||||
}
|
||||
;
|
||||
|
||||
AlterTable
|
||||
: AlterTableLeftSide PartitionSpec
|
||||
;
|
||||
|
||||
AlterTable_EDIT
|
||||
: AlterTableLeftSide_EDIT
|
||||
| AlterTableLeftSide_EDIT PartitionSpec
|
||||
| AlterTableLeftSide 'CURSOR'
|
||||
| AlterTableLeftSide PartitionSpec 'CURSOR'
|
||||
;
|
||||
|
||||
AlterTableLeftSide
|
||||
: 'ALTER' 'TABLE' SchemaQualifiedTableIdentifier
|
||||
{
|
||||
parser.addTablePrimary($3);
|
||||
}
|
||||
;
|
||||
|
||||
AlterTableLeftSide_EDIT
|
||||
: 'ALTER' 'TABLE' SchemaQualifiedTableIdentifier_EDIT
|
||||
{
|
||||
if (parser.yy.result.suggestTables) {
|
||||
parser.yy.result.suggestTables.onlyTables = true;
|
||||
}
|
||||
}
|
||||
| 'ALTER' 'TABLE' 'CURSOR'
|
||||
{
|
||||
parser.suggestTables({ onlyTables: true });
|
||||
parser.suggestDatabases({ appendDot: true });
|
||||
}
|
||||
;
|
||||
|
||||
AlterView
|
||||
: AlterViewLeftSide 'AS' QuerySpecification
|
||||
;
|
||||
|
||||
AlterView_EDIT
|
||||
: AlterViewLeftSide_EDIT
|
||||
| AlterViewLeftSide 'CURSOR'
|
||||
{
|
||||
parser.suggestKeywords(['AS']);
|
||||
}
|
||||
| AlterViewLeftSide 'SET' 'CURSOR'
|
||||
| AlterViewLeftSide 'AS' 'CURSOR'
|
||||
{
|
||||
parser.suggestKeywords(['SELECT']);
|
||||
}
|
||||
| AlterViewLeftSide 'AS' QuerySpecification_EDIT
|
||||
;
|
||||
|
||||
|
||||
AlterViewLeftSide
|
||||
: 'ALTER' 'VIEW' SchemaQualifiedTableIdentifier
|
||||
{
|
||||
parser.addTablePrimary($3);
|
||||
}
|
||||
;
|
||||
|
||||
AlterViewLeftSide_EDIT
|
||||
: 'ALTER' 'VIEW' SchemaQualifiedTableIdentifier_EDIT
|
||||
{
|
||||
if (parser.yy.result.suggestTables) {
|
||||
parser.yy.result.suggestTables.onlyViews = true;
|
||||
}
|
||||
}
|
||||
| 'ALTER' 'VIEW' 'CURSOR'
|
||||
{
|
||||
parser.suggestTables({ onlyViews: true });
|
||||
parser.suggestDatabases({ appendDot: true });
|
||||
}
|
||||
;
|
615
src/jison/sql/elasticsearch/sql_create.jison
Normal file
615
src/jison/sql/elasticsearch/sql_create.jison
Normal file
@ -0,0 +1,615 @@
|
||||
// Licensed to Cloudera, Inc. under one
|
||||
// or more contributor license agreements. See the NOTICE file
|
||||
// distributed with this work for additional information
|
||||
// regarding copyright ownership. Cloudera, Inc. licenses this file
|
||||
// to you under the Apache License, Version 2.0 (the
|
||||
// "License"); you may not use this file except in compliance
|
||||
// with the License. You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
DataDefinition
|
||||
: CreateStatement
|
||||
;
|
||||
|
||||
DataDefinition_EDIT
|
||||
: CreateStatement_EDIT
|
||||
;
|
||||
|
||||
CreateStatement
|
||||
: DatabaseDefinition
|
||||
| TableDefinition
|
||||
| ViewDefinition
|
||||
| RoleDefinition
|
||||
;
|
||||
|
||||
CreateStatement_EDIT
|
||||
: DatabaseDefinition_EDIT
|
||||
| TableDefinition_EDIT
|
||||
| ViewDefinition_EDIT
|
||||
| 'CREATE' 'CURSOR'
|
||||
{
|
||||
parser.suggestKeywords(['DATABASE', 'ROLE', 'SCHEMA', 'TABLE', 'VIEW']);
|
||||
}
|
||||
;
|
||||
|
||||
DatabaseDefinition
|
||||
: 'CREATE' DatabaseOrSchema OptionalIfNotExists
|
||||
| 'CREATE' DatabaseOrSchema OptionalIfNotExists RegularIdentifier DatabaseDefinitionOptionals
|
||||
{
|
||||
parser.addNewDatabaseLocation(@4, [{ name: $4 }]);
|
||||
}
|
||||
;
|
||||
|
||||
DatabaseDefinition_EDIT
|
||||
: 'CREATE' DatabaseOrSchema OptionalIfNotExists 'CURSOR'
|
||||
{
|
||||
if (!$3) {
|
||||
parser.suggestKeywords(['IF NOT EXISTS']);
|
||||
}
|
||||
}
|
||||
| 'CREATE' DatabaseOrSchema OptionalIfNotExists_EDIT
|
||||
| 'CREATE' DatabaseOrSchema OptionalIfNotExists 'CURSOR' RegularIdentifier
|
||||
{
|
||||
if (!$3) {
|
||||
parser.suggestKeywords(['IF NOT EXISTS']);
|
||||
}
|
||||
parser.addNewDatabaseLocation(@5, [{ name: $5 }]);
|
||||
}
|
||||
| 'CREATE' DatabaseOrSchema OptionalIfNotExists_EDIT RegularIdentifier
|
||||
{
|
||||
parser.addNewDatabaseLocation(@4, [{ name: $4 }]);
|
||||
}
|
||||
| 'CREATE' DatabaseOrSchema OptionalIfNotExists RegularIdentifier DatabaseDefinitionOptionals 'CURSOR'
|
||||
{
|
||||
parser.addNewDatabaseLocation(@4, [{ name: $4 }]);
|
||||
}
|
||||
;
|
||||
|
||||
DatabaseDefinitionOptionals
|
||||
: OptionalComment
|
||||
{
|
||||
if (!$1) {
|
||||
parser.suggestKeywords(['COMMENT']);
|
||||
}
|
||||
}
|
||||
;
|
||||
|
||||
DatabaseDefinitionOptionals_EDIT
|
||||
: OptionalComment_INVALID
|
||||
;
|
||||
|
||||
OptionalComment
|
||||
:
|
||||
| Comment
|
||||
;
|
||||
|
||||
Comment
|
||||
: 'COMMENT' QuotedValue
|
||||
;
|
||||
|
||||
OptionalComment_INVALID
|
||||
: Comment_INVALID
|
||||
;
|
||||
|
||||
Comment_INVALID
|
||||
: 'COMMENT' SINGLE_QUOTE
|
||||
| 'COMMENT' DOUBLE_QUOTE
|
||||
| 'COMMENT' SINGLE_QUOTE VALUE
|
||||
| 'COMMENT' DOUBLE_QUOTE VALUE
|
||||
;
|
||||
|
||||
TableDefinition
|
||||
: 'CREATE' 'TABLE' OptionalIfNotExists TableDefinitionRightPart
|
||||
;
|
||||
|
||||
TableDefinition_EDIT
|
||||
: 'CREATE' 'TABLE' OptionalIfNotExists TableDefinitionRightPart_EDIT
|
||||
| 'CREATE' 'TABLE' OptionalIfNotExists 'CURSOR'
|
||||
{
|
||||
if (!$3) {
|
||||
parser.suggestKeywords(['IF NOT EXISTS']);
|
||||
}
|
||||
}
|
||||
| 'CREATE' 'TABLE' OptionalIfNotExists_EDIT
|
||||
;
|
||||
|
||||
TableDefinitionRightPart
|
||||
: TableIdentifierAndOptionalColumnSpecification OptionalPartitionedBy OptionalAsSelectStatement
|
||||
;
|
||||
|
||||
TableDefinitionRightPart_EDIT
|
||||
: TableIdentifierAndOptionalColumnSpecification_EDIT OptionalPartitionedBy OptionalAsSelectStatement
|
||||
| TableIdentifierAndOptionalColumnSpecification PartitionedBy_EDIT OptionalAsSelectStatement
|
||||
| TableIdentifierAndOptionalColumnSpecification OptionalPartitionedBy OptionalAsSelectStatement_EDIT
|
||||
| TableIdentifierAndOptionalColumnSpecification OptionalPartitionedBy 'CURSOR'
|
||||
{
|
||||
var keywords = [];
|
||||
if (!$1 && !$2) {
|
||||
keywords.push({ value: 'LIKE', weight: 1 });
|
||||
} else {
|
||||
if (!$2) {
|
||||
keywords.push({ value: 'PARTITIONED BY', weight: 12 });
|
||||
}
|
||||
keywords.push({ value: 'AS', weight: 1 });
|
||||
}
|
||||
|
||||
if (keywords.length > 0) {
|
||||
parser.suggestKeywords(keywords);
|
||||
}
|
||||
}
|
||||
;
|
||||
|
||||
TableIdentifierAndOptionalColumnSpecification
|
||||
: SchemaQualifiedIdentifier OptionalColumnSpecificationsOrLike
|
||||
{
|
||||
parser.addNewTableLocation(@1, $1, $2);
|
||||
$$ = $2;
|
||||
}
|
||||
;
|
||||
|
||||
TableIdentifierAndOptionalColumnSpecification_EDIT
|
||||
: SchemaQualifiedIdentifier OptionalColumnSpecificationsOrLike_EDIT
|
||||
| SchemaQualifiedIdentifier_EDIT OptionalColumnSpecificationsOrLike
|
||||
;
|
||||
|
||||
OptionalColumnSpecificationsOrLike
|
||||
:
|
||||
| ParenthesizedColumnSpecificationList
|
||||
| 'LIKE' SchemaQualifiedTableIdentifier -> []
|
||||
;
|
||||
|
||||
OptionalColumnSpecificationsOrLike_EDIT
|
||||
: ParenthesizedColumnSpecificationList_EDIT
|
||||
| 'LIKE' 'CURSOR'
|
||||
{
|
||||
parser.suggestTables();
|
||||
parser.suggestDatabases({ appendDot: true });
|
||||
}
|
||||
| 'LIKE' SchemaQualifiedTableIdentifier_EDIT
|
||||
;
|
||||
|
||||
ParenthesizedColumnSpecificationList
|
||||
: '(' ColumnSpecificationList ')' -> $2
|
||||
;
|
||||
|
||||
ParenthesizedColumnSpecificationList_EDIT
|
||||
: '(' ColumnSpecificationList_EDIT RightParenthesisOrError
|
||||
;
|
||||
|
||||
ColumnSpecificationList
|
||||
: ColumnSpecification -> [$1]
|
||||
| ColumnSpecificationList ',' ColumnSpecification -> $1.concat($3)
|
||||
;
|
||||
|
||||
ColumnSpecificationList_EDIT
|
||||
: ColumnSpecification_EDIT
|
||||
| ColumnSpecification_EDIT ',' ColumnSpecificationList
|
||||
| ColumnSpecificationList ',' ColumnSpecification_EDIT
|
||||
| ColumnSpecificationList ',' ColumnSpecification_EDIT ',' ColumnSpecificationList
|
||||
| ColumnSpecification 'CURSOR'
|
||||
{
|
||||
parser.checkForKeywords($1);
|
||||
}
|
||||
| ColumnSpecification 'CURSOR' ',' ColumnSpecificationList
|
||||
{
|
||||
parser.checkForKeywords($1);
|
||||
}
|
||||
| ColumnSpecificationList ',' ColumnSpecification 'CURSOR'
|
||||
{
|
||||
parser.checkForKeywords($3);
|
||||
}
|
||||
| ColumnSpecificationList ',' ColumnSpecification 'CURSOR' ',' ColumnSpecificationList
|
||||
{
|
||||
parser.checkForKeywords($3);
|
||||
}
|
||||
;
|
||||
|
||||
ColumnSpecification
|
||||
: ColumnIdentifier ColumnDataType OptionalColumnOptions
|
||||
{
|
||||
$$ = $1;
|
||||
$$.type = $2;
|
||||
var keywords = [];
|
||||
if (!$3['comment']) {
|
||||
keywords.push('COMMENT');
|
||||
}
|
||||
if (keywords.length > 0) {
|
||||
$$.suggestKeywords = keywords;
|
||||
}
|
||||
}
|
||||
;
|
||||
|
||||
ColumnSpecification_EDIT
|
||||
: ColumnIdentifier 'CURSOR' OptionalColumnOptions
|
||||
{
|
||||
parser.suggestKeywords(parser.getColumnDataTypeKeywords());
|
||||
}
|
||||
| ColumnIdentifier ColumnDataType_EDIT OptionalColumnOptions
|
||||
| ColumnIdentifier ColumnDataType ColumnOptions_EDIT
|
||||
;
|
||||
|
||||
OptionalColumnOptions
|
||||
: -> {}
|
||||
| ColumnOptions
|
||||
;
|
||||
|
||||
ColumnOptions
|
||||
: ColumnOption
|
||||
{
|
||||
$$ = {};
|
||||
$$[$1] = true;
|
||||
}
|
||||
| ColumnOptions ColumnOption
|
||||
{
|
||||
$1[$2] = true;
|
||||
}
|
||||
;
|
||||
|
||||
ColumnOptions_EDIT
|
||||
: ColumnOption_EDIT
|
||||
| ColumnOption_EDIT ColumnOptions
|
||||
| ColumnOptions ColumnOption_EDIT
|
||||
| ColumnOptions ColumnOption_EDIT ColumnOptions
|
||||
;
|
||||
|
||||
ColumnOption
|
||||
: 'NOT' 'NULL' -> 'null'
|
||||
| 'NULL' -> 'null'
|
||||
| Comment -> 'comment'
|
||||
;
|
||||
|
||||
ColumnOption_EDIT
|
||||
: 'NOT' 'CURSOR'
|
||||
{
|
||||
parser.suggestKeywords(['NULL']);
|
||||
}
|
||||
;
|
||||
|
||||
ColumnDataType
|
||||
: PrimitiveType
|
||||
| ArrayType
|
||||
| MapType
|
||||
| StructType
|
||||
| ArrayType_INVALID
|
||||
| MapType_INVALID
|
||||
| StructType_INVALID
|
||||
;
|
||||
|
||||
ColumnDataType_EDIT
|
||||
: ArrayType_EDIT
|
||||
| MapType_EDIT
|
||||
| StructType_EDIT
|
||||
;
|
||||
|
||||
ArrayType
|
||||
: 'ARRAY' '<' ColumnDataType '>'
|
||||
;
|
||||
|
||||
ArrayType_INVALID
|
||||
: 'ARRAY' '<' '>'
|
||||
;
|
||||
|
||||
ArrayType_EDIT
|
||||
: 'ARRAY' '<' AnyCursor GreaterThanOrError
|
||||
{
|
||||
parser.suggestKeywords(parser.getColumnDataTypeKeywords());
|
||||
}
|
||||
| 'ARRAY' '<' ColumnDataType_EDIT GreaterThanOrError
|
||||
;
|
||||
|
||||
MapType
|
||||
: 'MAP' '<' PrimitiveType ',' ColumnDataType '>'
|
||||
;
|
||||
|
||||
MapType_INVALID
|
||||
: 'MAP' '<' '>'
|
||||
;
|
||||
|
||||
MapType_EDIT
|
||||
: 'MAP' '<' PrimitiveType ',' ColumnDataType_EDIT GreaterThanOrError
|
||||
| 'MAP' '<' AnyCursor GreaterThanOrError
|
||||
{
|
||||
parser.suggestKeywords(parser.getTypeKeywords());
|
||||
}
|
||||
| 'MAP' '<' PrimitiveType ',' AnyCursor GreaterThanOrError
|
||||
{
|
||||
parser.suggestKeywords(parser.getColumnDataTypeKeywords());
|
||||
}
|
||||
| 'MAP' '<' ',' AnyCursor GreaterThanOrError
|
||||
{
|
||||
parser.suggestKeywords(parser.getColumnDataTypeKeywords());
|
||||
}
|
||||
;
|
||||
|
||||
StructType
|
||||
: 'STRUCT' '<' StructDefinitionList '>'
|
||||
;
|
||||
|
||||
StructType_INVALID
|
||||
: 'STRUCT' '<' '>'
|
||||
;
|
||||
|
||||
StructType_EDIT
|
||||
: 'STRUCT' '<' StructDefinitionList_EDIT GreaterThanOrError
|
||||
;
|
||||
|
||||
StructDefinitionList
|
||||
: StructDefinition
|
||||
| StructDefinitionList ',' StructDefinition
|
||||
;
|
||||
|
||||
StructDefinitionList_EDIT
|
||||
: StructDefinition_EDIT
|
||||
| StructDefinition_EDIT Commas
|
||||
| StructDefinition_EDIT Commas StructDefinitionList
|
||||
| StructDefinitionList ',' StructDefinition_EDIT
|
||||
| StructDefinitionList ',' StructDefinition_EDIT Commas StructDefinitionList
|
||||
;
|
||||
|
||||
StructDefinition
|
||||
: RegularOrBacktickedIdentifier ':' ColumnDataType OptionalComment
|
||||
;
|
||||
|
||||
StructDefinition_EDIT
|
||||
: Commas RegularOrBacktickedIdentifier ':' ColumnDataType 'CURSOR'
|
||||
{
|
||||
parser.suggestKeywords(['COMMENT']);
|
||||
}
|
||||
| Commas RegularOrBacktickedIdentifier ':' AnyCursor
|
||||
{
|
||||
parser.suggestKeywords(parser.getColumnDataTypeKeywords());
|
||||
}
|
||||
| Commas RegularOrBacktickedIdentifier ':' ColumnDataType_EDIT
|
||||
| RegularOrBacktickedIdentifier ':' ColumnDataType 'CURSOR'
|
||||
{
|
||||
parser.suggestKeywords(['COMMENT']);
|
||||
}
|
||||
| RegularOrBacktickedIdentifier ':' AnyCursor
|
||||
{
|
||||
parser.suggestKeywords(parser.getColumnDataTypeKeywords());
|
||||
}
|
||||
| RegularOrBacktickedIdentifier ':' ColumnDataType_EDIT
|
||||
;
|
||||
|
||||
ColumnDataTypeList
|
||||
: ColumnDataType
|
||||
| ColumnDataTypeList ',' ColumnDataType
|
||||
;
|
||||
|
||||
ColumnDataTypeList_EDIT
|
||||
: ColumnDataTypeListInner_EDIT
|
||||
| ColumnDataTypeListInner_EDIT Commas
|
||||
| ColumnDataTypeList ',' ColumnDataTypeListInner_EDIT
|
||||
| ColumnDataTypeListInner_EDIT Commas ColumnDataTypeList
|
||||
| ColumnDataTypeList ',' ColumnDataTypeListInner_EDIT Commas ColumnDataTypeList
|
||||
;
|
||||
|
||||
ColumnDataTypeListInner_EDIT
|
||||
: Commas AnyCursor
|
||||
{
|
||||
parser.suggestKeywords(parser.getColumnDataTypeKeywords());
|
||||
}
|
||||
| Commas ColumnDataType_EDIT
|
||||
| AnyCursor
|
||||
{
|
||||
parser.suggestKeywords(parser.getColumnDataTypeKeywords());
|
||||
}
|
||||
| ColumnDataType_EDIT
|
||||
;
|
||||
|
||||
GreaterThanOrError
|
||||
: '>'
|
||||
| error
|
||||
;
|
||||
|
||||
OptionalPartitionedBy
|
||||
:
|
||||
| PartitionedBy
|
||||
;
|
||||
|
||||
PartitionedBy
|
||||
: 'PARTITION' 'BY' RangeClause
|
||||
;
|
||||
|
||||
PartitionedBy_EDIT
|
||||
: 'PARTITION' 'CURSOR'
|
||||
{
|
||||
parser.suggestKeywords(['BY']);
|
||||
}
|
||||
| 'PARTITION' 'BY' 'CURSOR'
|
||||
{
|
||||
parser.suggestKeywords(['RANGE']);
|
||||
}
|
||||
| 'PARTITION' 'BY' RangeClause_EDIT
|
||||
;
|
||||
|
||||
RangeClause
|
||||
: 'RANGE' ParenthesizedColumnList ParenthesizedPartitionValuesList
|
||||
;
|
||||
|
||||
RangeClause_EDIT
|
||||
: 'RANGE' 'CURSOR'
|
||||
| 'RANGE' ParenthesizedColumnList_EDIT
|
||||
| 'RANGE' ParenthesizedColumnList 'CURSOR'
|
||||
| 'RANGE' ParenthesizedColumnList ParenthesizedPartitionValuesList_EDIT
|
||||
| 'RANGE' ParenthesizedColumnList_EDIT ParenthesizedPartitionValuesList
|
||||
;
|
||||
|
||||
ParenthesizedPartitionValuesList
|
||||
: '(' PartitionValueList ')'
|
||||
;
|
||||
|
||||
ParenthesizedPartitionValuesList_EDIT
|
||||
: '(' 'CURSOR' RightParenthesisOrError
|
||||
{
|
||||
parser.suggestKeywords(['PARTITION']);
|
||||
}
|
||||
|'(' PartitionValueList_EDIT RightParenthesisOrError
|
||||
;
|
||||
|
||||
PartitionValueList
|
||||
: PartitionValue
|
||||
| PartitionValueList ',' PartitionValue
|
||||
;
|
||||
|
||||
PartitionValueList_EDIT
|
||||
: PartitionValue_EDIT
|
||||
| PartitionValueList ',' 'CURSOR'
|
||||
{
|
||||
parser.suggestKeywords(['PARTITION']);
|
||||
}
|
||||
| PartitionValueList ',' 'CURSOR' ',' PartitionValueList
|
||||
{
|
||||
parser.suggestKeywords(['PARTITION']);
|
||||
}
|
||||
| PartitionValueList ',' PartitionValue_EDIT
|
||||
| PartitionValueList ',' PartitionValue_EDIT ',' PartitionValueList
|
||||
;
|
||||
|
||||
PartitionValue
|
||||
: 'PARTITION' ValueExpression LessThanOrEqualTo 'VALUES' LessThanOrEqualTo ValueExpression
|
||||
| 'PARTITION' 'VALUES' LessThanOrEqualTo ValueExpression
|
||||
| 'PARTITION' ValueExpression LessThanOrEqualTo 'VALUES'
|
||||
;
|
||||
|
||||
PartitionValue_EDIT
|
||||
: 'PARTITION' 'CURSOR'
|
||||
{
|
||||
parser.suggestKeywords(['VALUE', 'VALUES']);
|
||||
}
|
||||
| 'PARTITION' ValueExpression_EDIT
|
||||
{
|
||||
if ($2.endsWithLessThanOrEqual) {
|
||||
parser.suggestKeywords(['VALUES']);
|
||||
}
|
||||
}
|
||||
| 'PARTITION' ValueExpression 'CURSOR'
|
||||
{
|
||||
parser.suggestKeywords(['<', '<=']);
|
||||
}
|
||||
| 'PARTITION' ValueExpression LessThanOrEqualTo 'CURSOR'
|
||||
{
|
||||
parser.suggestKeywords(['VALUES']);
|
||||
}
|
||||
| 'PARTITION' ValueExpression_EDIT LessThanOrEqualTo 'VALUES'
|
||||
| 'PARTITION' ValueExpression LessThanOrEqualTo 'VALUES' 'CURSOR'
|
||||
{
|
||||
parser.suggestKeywords(['<', '<=']);
|
||||
}
|
||||
| 'PARTITION' ValueExpression LessThanOrEqualTo 'VALUES' LessThanOrEqualTo 'CURSOR'
|
||||
{
|
||||
parser.suggestFunctions();
|
||||
}
|
||||
| 'PARTITION' ValueExpression LessThanOrEqualTo 'VALUES' LessThanOrEqualTo ValueExpression_EDIT
|
||||
| 'PARTITION' 'VALUES' 'CURSOR'
|
||||
{
|
||||
parser.suggestKeywords(['<', '<=']);
|
||||
}
|
||||
| 'PARTITION' 'VALUES' LessThanOrEqualTo 'CURSOR'
|
||||
{
|
||||
parser.suggestFunctions();
|
||||
}
|
||||
| 'PARTITION' 'VALUES' LessThanOrEqualTo ValueExpression_EDIT
|
||||
;
|
||||
|
||||
LessThanOrEqualTo
|
||||
: '<'
|
||||
| 'COMPARISON_OPERATOR' // This is fine for autocompletion
|
||||
;
|
||||
|
||||
OptionalAsSelectStatement
|
||||
:
|
||||
| 'AS' CommitLocations QuerySpecification
|
||||
;
|
||||
|
||||
OptionalAsSelectStatement_EDIT
|
||||
: 'AS' CommitLocations 'CURSOR'
|
||||
{
|
||||
parser.suggestKeywords(['SELECT']);
|
||||
}
|
||||
| 'AS' CommitLocations QuerySpecification_EDIT
|
||||
;
|
||||
|
||||
CommitLocations
|
||||
: /* empty */
|
||||
{
|
||||
parser.commitLocations();
|
||||
}
|
||||
;
|
||||
|
||||
ViewDefinition
|
||||
: 'CREATE' 'VIEW' OptionalIfNotExists SchemaQualifiedIdentifier OptionalParenthesizedViewColumnList OptionalComment 'AS' QuerySpecification
|
||||
;
|
||||
|
||||
ViewDefinition_EDIT
|
||||
: 'CREATE' 'VIEW' OptionalIfNotExists 'CURSOR'
|
||||
{
|
||||
if (!$3) {
|
||||
parser.suggestKeywords(['IF NOT EXISTS']);
|
||||
}
|
||||
parser.suggestDatabases({ appendDot: true });
|
||||
}
|
||||
| 'CREATE' 'VIEW' OptionalIfNotExists 'CURSOR' SchemaQualifiedIdentifier OptionalParenthesizedViewColumnList OptionalComment 'AS' QuerySpecification
|
||||
{
|
||||
if (!$3) {
|
||||
parser.suggestKeywords(['IF NOT EXISTS']);
|
||||
}
|
||||
}
|
||||
| 'CREATE' 'VIEW' OptionalIfNotExists_EDIT
|
||||
| 'CREATE' 'VIEW' OptionalIfNotExists SchemaQualifiedIdentifier ParenthesizedViewColumnList_EDIT OptionalComment
|
||||
| 'CREATE' 'VIEW' OptionalIfNotExists SchemaQualifiedIdentifier OptionalParenthesizedViewColumnList OptionalComment 'CURSOR'
|
||||
{
|
||||
var keywords = [{value: 'AS', weight: 1 }];
|
||||
if (!$6) {
|
||||
keywords.push({ value: 'COMMENT', weight: 3 });
|
||||
}
|
||||
parser.suggestKeywords(keywords);
|
||||
}
|
||||
| 'CREATE' 'VIEW' OptionalIfNotExists SchemaQualifiedIdentifier OptionalParenthesizedViewColumnList OptionalComment 'AS' 'CURSOR'
|
||||
{
|
||||
parser.suggestKeywords(['SELECT']);
|
||||
}
|
||||
| 'CREATE' 'VIEW' OptionalIfNotExists SchemaQualifiedIdentifier OptionalParenthesizedViewColumnList OptionalComment 'AS' QuerySpecification_EDIT
|
||||
| 'CREATE' 'VIEW' OptionalIfNotExists SchemaQualifiedIdentifier_EDIT OptionalParenthesizedViewColumnList OptionalComment 'AS' QuerySpecification
|
||||
;
|
||||
|
||||
OptionalParenthesizedViewColumnList
|
||||
:
|
||||
| ParenthesizedViewColumnList
|
||||
;
|
||||
|
||||
ParenthesizedViewColumnList
|
||||
: '(' ViewColumnList ')'
|
||||
;
|
||||
|
||||
ParenthesizedViewColumnList_EDIT
|
||||
: '(' ViewColumnList_EDIT RightParenthesisOrError
|
||||
{
|
||||
if (!$2) {
|
||||
parser.suggestKeywords(['COMMENT']);
|
||||
}
|
||||
}
|
||||
;
|
||||
|
||||
ViewColumnList
|
||||
: ColumnReference OptionalComment
|
||||
| ViewColumnList ',' ColumnReference OptionalComment
|
||||
;
|
||||
|
||||
ViewColumnList_EDIT
|
||||
: ColumnReference OptionalComment 'CURSOR' -> $2
|
||||
| ColumnReference OptionalComment 'CURSOR' ',' ViewColumnList -> $2
|
||||
| ViewColumnList ',' ColumnReference OptionalComment 'CURSOR' -> $4
|
||||
| ViewColumnList ',' ColumnReference OptionalComment 'CURSOR' ',' ViewColumnList -> $4
|
||||
;
|
||||
|
||||
RoleDefinition
|
||||
: 'CREATE' 'ROLE' RegularIdentifier
|
||||
;
|
184
src/jison/sql/elasticsearch/sql_drop.jison
Normal file
184
src/jison/sql/elasticsearch/sql_drop.jison
Normal file
@ -0,0 +1,184 @@
|
||||
// Licensed to Cloudera, Inc. under one
|
||||
// or more contributor license agreements. See the NOTICE file
|
||||
// distributed with this work for additional information
|
||||
// regarding copyright ownership. Cloudera, Inc. licenses this file
|
||||
// to you under the Apache License, Version 2.0 (the
|
||||
// "License"); you may not use this file except in compliance
|
||||
// with the License. You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
DataDefinition
|
||||
: DropStatement
|
||||
;
|
||||
|
||||
DataDefinition_EDIT
|
||||
: DropStatement_EDIT
|
||||
;
|
||||
|
||||
DropStatement
|
||||
: DropDatabaseStatement
|
||||
| DropRoleStatement
|
||||
| DropTableStatement
|
||||
| DropViewStatement
|
||||
| TruncateTableStatement
|
||||
;
|
||||
|
||||
DropStatement_EDIT
|
||||
: DropDatabaseStatement_EDIT
|
||||
| DropTableStatement_EDIT
|
||||
| DropViewStatement_EDIT
|
||||
| TruncateTableStatement_EDIT
|
||||
| 'DROP' 'CURSOR'
|
||||
{
|
||||
parser.suggestKeywords(['DATABASE', 'ROLE', 'SCHEMA', 'TABLE', 'VIEW']);
|
||||
}
|
||||
;
|
||||
|
||||
DropDatabaseStatement
|
||||
: 'DROP' DatabaseOrSchema OptionalIfExists RegularOrBacktickedIdentifier OptionalCascade
|
||||
;
|
||||
|
||||
DropDatabaseStatement_EDIT
|
||||
: 'DROP' DatabaseOrSchema OptionalIfExists
|
||||
| 'DROP' DatabaseOrSchema OptionalIfExists_EDIT
|
||||
| 'DROP' DatabaseOrSchema OptionalIfExists 'CURSOR'
|
||||
{
|
||||
if (!$3) {
|
||||
parser.suggestKeywords(['IF EXISTS']);
|
||||
}
|
||||
parser.suggestDatabases();
|
||||
}
|
||||
| 'DROP' DatabaseOrSchema OptionalIfExists RegularOrBacktickedIdentifier 'CURSOR'
|
||||
{
|
||||
parser.suggestKeywords(['CASCADE']);
|
||||
}
|
||||
| 'DROP' DatabaseOrSchema OptionalIfExists_EDIT RegularOrBacktickedIdentifier OptionalCascade
|
||||
| 'DROP' DatabaseOrSchema OptionalIfExists 'CURSOR' RegularOrBacktickedIdentifier OptionalCascade
|
||||
{
|
||||
if (!$3) {
|
||||
parser.suggestKeywords(['IF EXISTS']);
|
||||
}
|
||||
}
|
||||
;
|
||||
DropRoleStatement
|
||||
: 'DROP' 'ROLE' RegularIdentifier
|
||||
;
|
||||
|
||||
DropTableStatement
|
||||
: 'DROP' 'TABLE' OptionalIfExists SchemaQualifiedTableIdentifier OptionalPurge
|
||||
{
|
||||
parser.addTablePrimary($4);
|
||||
}
|
||||
;
|
||||
|
||||
DropTableStatement_EDIT
|
||||
: 'DROP' 'TABLE' OptionalIfExists_EDIT
|
||||
| 'DROP' 'TABLE' OptionalIfExists 'CURSOR'
|
||||
{
|
||||
if (!$3) {
|
||||
parser.suggestKeywords(['IF EXISTS']);
|
||||
}
|
||||
parser.suggestTables({ onlyTables: true });
|
||||
parser.suggestDatabases({
|
||||
appendDot: true
|
||||
});
|
||||
}
|
||||
| 'DROP' 'TABLE' OptionalIfExists SchemaQualifiedTableIdentifier_EDIT OptionalPurge
|
||||
{
|
||||
if (parser.yy.result.suggestTables) {
|
||||
parser.yy.result.suggestTables.onlyTables = true;
|
||||
}
|
||||
}
|
||||
| 'DROP' 'TABLE' OptionalIfExists_EDIT SchemaQualifiedTableIdentifier OptionalPurge
|
||||
| 'DROP' 'TABLE' OptionalIfExists SchemaQualifiedTableIdentifier OptionalPurge 'CURSOR'
|
||||
{
|
||||
parser.addTablePrimary($4);
|
||||
if (!$5) {
|
||||
parser.suggestKeywords(['PURGE']);
|
||||
}
|
||||
}
|
||||
;
|
||||
|
||||
OptionalPurge
|
||||
:
|
||||
| 'PURGE'
|
||||
;
|
||||
|
||||
DropViewStatement
|
||||
: 'DROP' 'VIEW' OptionalIfExists SchemaQualifiedTableIdentifier
|
||||
{
|
||||
parser.addTablePrimary($4);
|
||||
}
|
||||
;
|
||||
|
||||
DropViewStatement_EDIT
|
||||
: 'DROP' 'VIEW' OptionalIfExists 'CURSOR'
|
||||
{
|
||||
if (!$3) {
|
||||
parser.suggestKeywords(['IF EXISTS']);
|
||||
}
|
||||
parser.suggestTables({ onlyViews: true });
|
||||
parser.suggestDatabases({ appendDot: true });
|
||||
}
|
||||
| 'DROP' 'VIEW' OptionalIfExists 'CURSOR' SchemaQualifiedTableIdentifier
|
||||
{
|
||||
parser.addTablePrimary($5);
|
||||
if (!$3) {
|
||||
parser.suggestKeywords(['IF EXISTS']);
|
||||
}
|
||||
}
|
||||
| 'DROP' 'VIEW' OptionalIfExists_EDIT
|
||||
| 'DROP' 'VIEW' OptionalIfExists_EDIT SchemaQualifiedTableIdentifier
|
||||
{
|
||||
parser.addTablePrimary($4);
|
||||
}
|
||||
| 'DROP' 'VIEW' OptionalIfExists SchemaQualifiedTableIdentifier_EDIT
|
||||
{
|
||||
if (parser.yy.result.suggestTables) {
|
||||
parser.yy.result.suggestTables.onlyViews = true;
|
||||
}
|
||||
}
|
||||
;
|
||||
|
||||
TruncateTableStatement
|
||||
: 'TRUNCATE' 'TABLE' OptionalIfExists SchemaQualifiedTableIdentifier
|
||||
{
|
||||
parser.addTablePrimary($4);
|
||||
}
|
||||
;
|
||||
|
||||
TruncateTableStatement_EDIT
|
||||
: 'TRUNCATE' 'CURSOR'
|
||||
{
|
||||
parser.suggestKeywords(['TABLE']);
|
||||
}
|
||||
| 'TRUNCATE' 'TABLE' OptionalIfExists 'CURSOR'
|
||||
{
|
||||
parser.suggestTables();
|
||||
parser.suggestDatabases({ appendDot: true });
|
||||
if (!$3) {
|
||||
parser.suggestKeywords(['IF EXISTS']);
|
||||
}
|
||||
}
|
||||
| 'TRUNCATE' 'TABLE' OptionalIfExists_EDIT
|
||||
| 'TRUNCATE' 'TABLE' OptionalIfExists SchemaQualifiedTableIdentifier_EDIT
|
||||
| 'TRUNCATE' 'TABLE' OptionalIfExists SchemaQualifiedTableIdentifier 'CURSOR'
|
||||
{
|
||||
parser.addTablePrimary($4);
|
||||
}
|
||||
| 'TRUNCATE' 'TABLE' OptionalIfExists 'CURSOR' SchemaQualifiedTableIdentifier
|
||||
{
|
||||
parser.addTablePrimary($4);
|
||||
if (!$3) {
|
||||
parser.suggestKeywords(['IF EXISTS']);
|
||||
}
|
||||
}
|
||||
| 'TRUNCATE' 'TABLE' OptionalIfExists_EDIT SchemaQualifiedTableIdentifier OptionalPartitionSpec
|
||||
;
|
132
src/jison/sql/elasticsearch/sql_error.jison
Normal file
132
src/jison/sql/elasticsearch/sql_error.jison
Normal file
@ -0,0 +1,132 @@
|
||||
// Licensed to Cloudera, Inc. under one
|
||||
// or more contributor license agreements. See the NOTICE file
|
||||
// distributed with this work for additional information
|
||||
// regarding copyright ownership. Cloudera, Inc. licenses this file
|
||||
// to you under the Apache License, Version 2.0 (the
|
||||
// "License"); you may not use this file except in compliance
|
||||
// with the License. You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
SqlStatements
|
||||
: error
|
||||
| NonStartingToken error // Having just ': error' does not work for some reason, jison bug?
|
||||
;
|
||||
|
||||
SqlStatement_EDIT
|
||||
: AnyCursor error
|
||||
{
|
||||
parser.suggestDdlAndDmlKeywords();
|
||||
}
|
||||
;
|
||||
|
||||
SelectStatement
|
||||
: 'SELECT' OptionalAllOrDistinct SelectList_ERROR TableExpression
|
||||
| 'SELECT' OptionalAllOrDistinct SelectList TableExpression_ERROR
|
||||
;
|
||||
|
||||
SelectStatement_EDIT
|
||||
: 'SELECT' OptionalAllOrDistinct SelectList_ERROR_EDIT TableExpression
|
||||
{
|
||||
parser.selectListNoTableSuggest($3, $2);
|
||||
}
|
||||
| 'SELECT' OptionalAllOrDistinct SelectList_ERROR TableExpression_EDIT
|
||||
;
|
||||
|
||||
SelectList_ERROR
|
||||
: ErrorList
|
||||
| SelectList ',' ErrorList
|
||||
| ErrorList ',' SelectList ',' ErrorList
|
||||
| ErrorList ',' SelectList
|
||||
| SelectList ',' ErrorList ',' SelectList
|
||||
;
|
||||
|
||||
SelectList_ERROR_EDIT
|
||||
: ErrorList ',' SelectList_EDIT -> $3
|
||||
| SelectList ',' ErrorList ',' SelectList_EDIT -> $5
|
||||
| ErrorList ',' SelectList ',' ErrorList ',' SelectList_EDIT -> $7
|
||||
| ErrorList ',' AnyCursor
|
||||
{
|
||||
$$ = { cursorAtStart : false, suggestFunctions: true, suggestColumns: true, suggestAggregateFunctions: true };
|
||||
}
|
||||
| SelectList ',' ErrorList ',' AnyCursor
|
||||
{
|
||||
$$ = { cursorAtStart : false, suggestFunctions: true, suggestColumns: true, suggestAggregateFunctions: true };
|
||||
}
|
||||
| ErrorList ',' SelectList ',' Errors ',' AnyCursor
|
||||
{
|
||||
$$ = { cursorAtStart : true, suggestFunctions: true, suggestColumns: true, suggestAggregateFunctions: true };
|
||||
}
|
||||
;
|
||||
|
||||
SetSpecification
|
||||
: 'SET' SetOption '=' error
|
||||
;
|
||||
|
||||
ErrorList
|
||||
: error
|
||||
| Errors ',' error
|
||||
;
|
||||
|
||||
JoinType_EDIT
|
||||
: 'FULL' 'CURSOR' error
|
||||
{
|
||||
parser.suggestKeywords(['JOIN', 'OUTER JOIN']);
|
||||
}
|
||||
| 'LEFT' 'CURSOR' error
|
||||
{
|
||||
parser.suggestKeywords(['JOIN', 'OUTER JOIN']);
|
||||
}
|
||||
| 'RIGHT' 'CURSOR' error
|
||||
{
|
||||
parser.suggestKeywords(['JOIN', 'OUTER JOIN']);
|
||||
}
|
||||
;
|
||||
|
||||
OptionalSelectConditions_EDIT
|
||||
: WhereClause error 'CURSOR' OptionalGroupByClause OptionalHavingClause OptionalOrderByClause OptionalLimitClause
|
||||
{
|
||||
$$ = {
|
||||
suggestKeywords: parser.getKeywordsForOptionalsLR([$4, $5, $6, $7], [{ value: 'GROUP BY', weight: 8 }, { value: 'HAVING', weight: 7 }, { value: 'ORDER BY', weight: 5 }, { value: 'LIMIT', weight: 3 }], [true, true, true, true]),
|
||||
cursorAtEnd: !$4 && !$5 && !$6 && !$7
|
||||
};
|
||||
}
|
||||
| OptionalWhereClause OptionalGroupByClause HavingClause error 'CURSOR' OptionalOrderByClause OptionalLimitClause
|
||||
{
|
||||
$$ = {
|
||||
suggestKeywords: parser.getKeywordsForOptionalsLR([$6, $7], [{ value: 'ORDER BY', weight: 5 }, { value: 'LIMIT', weight: 3 }], [true, true]),
|
||||
cursorAtEnd: !$6 && !$7
|
||||
}
|
||||
}
|
||||
| OptionalWhereClause OptionalGroupByClause OptionalHavingClause OrderByClause error 'CURSOR' OptionalLimitClause
|
||||
{
|
||||
$$ = {
|
||||
suggestKeywords: parser.getKeywordsForOptionalsLR([$7], [{ value: 'LIMIT', weight: 3 }], [true]),
|
||||
cursorAtEnd: !$7
|
||||
}
|
||||
}
|
||||
| OptionalWhereClause OptionalGroupByClause OptionalHavingClause OptionalOrderByClause LimitClause error 'CURSOR'
|
||||
;
|
||||
|
||||
OptionalSelectConditions_EDIT
|
||||
: WhereClause error GroupByClause_EDIT OptionalHavingClause OptionalOrderByClause OptionalLimitClause
|
||||
| WhereClause error OptionalGroupByClause HavingClause_EDIT OptionalOrderByClause OptionalLimitClause
|
||||
| WhereClause error OptionalGroupByClause OptionalHavingClause OrderByClause_EDIT OptionalLimitClause
|
||||
| WhereClause error OptionalGroupByClause OptionalHavingClause OptionalOrderByClause LimitClause_EDIT
|
||||
| OptionalWhereClause GroupByClause error HavingClause_EDIT OptionalOrderByClause OptionalLimitClause
|
||||
| OptionalWhereClause GroupByClause error OptionalHavingClause OrderByClause_EDIT OptionalLimitClause
|
||||
| OptionalWhereClause GroupByClause error OptionalHavingClause OptionalOrderByClause LimitClause_EDIT
|
||||
| OptionalWhereClause OptionalGroupByClause HavingClause error OrderByClause_EDIT OptionalLimitClause
|
||||
| OptionalWhereClause OptionalGroupByClause HavingClause error OptionalOrderByClause LimitClause_EDIT
|
||||
| OptionalWhereClause OptionalGroupByClause OptionalHavingClause OrderByClause error LimitClause_EDIT
|
||||
;
|
||||
|
||||
DatabaseDefinition_EDIT
|
||||
: 'CREATE' DatabaseOrSchema OptionalIfNotExists RegularIdentifier DatabaseDefinitionOptionals_EDIT error
|
||||
;
|
72
src/jison/sql/elasticsearch/sql_insert.jison
Normal file
72
src/jison/sql/elasticsearch/sql_insert.jison
Normal file
@ -0,0 +1,72 @@
|
||||
// Licensed to Cloudera, Inc. under one
|
||||
// or more contributor license agreements. See the NOTICE file
|
||||
// distributed with this work for additional information
|
||||
// regarding copyright ownership. Cloudera, Inc. licenses this file
|
||||
// to you under the Apache License, Version 2.0 (the
|
||||
// "License"); you may not use this file except in compliance
|
||||
// with the License. You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
DataManipulation
|
||||
: InsertStatement
|
||||
;
|
||||
|
||||
InsertStatement
|
||||
: InsertValuesStatement
|
||||
;
|
||||
|
||||
DataManipulation_EDIT
|
||||
: InsertValuesStatement_EDIT
|
||||
;
|
||||
|
||||
InsertValuesStatement
|
||||
: 'INSERT' 'INTO' OptionalTable SchemaQualifiedTableIdentifier 'VALUES' InsertValuesList
|
||||
{
|
||||
$4.owner = 'insert';
|
||||
parser.addTablePrimary($4);
|
||||
}
|
||||
;
|
||||
|
||||
InsertValuesStatement_EDIT
|
||||
: 'INSERT' 'CURSOR'
|
||||
{
|
||||
parser.suggestKeywords(['INTO']);
|
||||
}
|
||||
| 'INSERT' 'INTO' OptionalTable 'CURSOR'
|
||||
{
|
||||
if (!$3) {
|
||||
parser.suggestKeywords(['TABLE']);
|
||||
}
|
||||
parser.suggestTables();
|
||||
parser.suggestDatabases({ appendDot: true });
|
||||
}
|
||||
| 'INSERT' 'INTO' OptionalTable SchemaQualifiedTableIdentifier_EDIT
|
||||
| 'INSERT' 'INTO' OptionalTable SchemaQualifiedTableIdentifier 'CURSOR'
|
||||
{
|
||||
$4.owner = 'insert';
|
||||
parser.addTablePrimary($4);
|
||||
parser.suggestKeywords(['VALUES']);
|
||||
}
|
||||
| 'INSERT' 'INTO' OptionalTable SchemaQualifiedTableIdentifier_EDIT 'VALUES' InsertValuesList
|
||||
;
|
||||
|
||||
InsertValuesList
|
||||
: ParenthesizedRowValuesList
|
||||
| RowValuesList ',' ParenthesizedRowValuesList
|
||||
;
|
||||
|
||||
ParenthesizedRowValuesList
|
||||
: '(' InValueList ')'
|
||||
;
|
||||
|
||||
OptionalTable
|
||||
:
|
||||
| 'TABLE'
|
||||
;
|
2762
src/jison/sql/elasticsearch/sql_main.jison
Normal file
2762
src/jison/sql/elasticsearch/sql_main.jison
Normal file
File diff suppressed because it is too large
Load Diff
46
src/jison/sql/elasticsearch/sql_set.jison
Normal file
46
src/jison/sql/elasticsearch/sql_set.jison
Normal file
@ -0,0 +1,46 @@
|
||||
// Licensed to Cloudera, Inc. under one
|
||||
// or more contributor license agreements. See the NOTICE file
|
||||
// distributed with this work for additional information
|
||||
// regarding copyright ownership. Cloudera, Inc. licenses this file
|
||||
// to you under the Apache License, Version 2.0 (the
|
||||
// "License"); you may not use this file except in compliance
|
||||
// with the License. You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
DataDefinition
|
||||
: SetSpecification
|
||||
;
|
||||
|
||||
DataDefinition_EDIT
|
||||
: 'SET' 'CURSOR'
|
||||
{
|
||||
parser.suggestSetOptions();
|
||||
}
|
||||
;
|
||||
|
||||
SetSpecification
|
||||
: 'SET' SetOption '=' SetValue
|
||||
| 'SET' 'ALL'
|
||||
;
|
||||
|
||||
SetOption
|
||||
: RegularIdentifier
|
||||
| SetOption '.' RegularIdentifier
|
||||
;
|
||||
|
||||
SetValue
|
||||
: RegularIdentifier
|
||||
| SignedInteger
|
||||
| SignedInteger RegularIdentifier
|
||||
| QuotedValue
|
||||
| 'TRUE'
|
||||
| 'FALSE'
|
||||
| 'NULL'
|
||||
;
|
122
src/jison/sql/elasticsearch/sql_update.jison
Normal file
122
src/jison/sql/elasticsearch/sql_update.jison
Normal file
@ -0,0 +1,122 @@
|
||||
// Licensed to Cloudera, Inc. under one
|
||||
// or more contributor license agreements. See the NOTICE file
|
||||
// distributed with this work for additional information
|
||||
// regarding copyright ownership. Cloudera, Inc. licenses this file
|
||||
// to you under the Apache License, Version 2.0 (the
|
||||
// "License"); you may not use this file except in compliance
|
||||
// with the License. You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
DataManipulation
|
||||
: UpdateStatement
|
||||
;
|
||||
|
||||
DataManipulation_EDIT
|
||||
: UpdateStatement_EDIT
|
||||
;
|
||||
|
||||
UpdateStatement
|
||||
: 'UPDATE' TargetTable 'SET' SetClauseList OptionalFromJoinedTable OptionalWhereClause
|
||||
;
|
||||
|
||||
UpdateStatement_EDIT
|
||||
: 'UPDATE' TargetTable_EDIT 'SET' SetClauseList OptionalFromJoinedTable OptionalWhereClause
|
||||
| 'UPDATE' TargetTable 'SET' SetClauseList_EDIT OptionalFromJoinedTable OptionalWhereClause
|
||||
| 'UPDATE' TargetTable 'SET' SetClauseList FromJoinedTable_EDIT OptionalWhereClause
|
||||
| 'UPDATE' TargetTable 'SET' SetClauseList OptionalFromJoinedTable WhereClause_EDIT
|
||||
| 'UPDATE' TargetTable 'SET' SetClauseList OptionalFromJoinedTable OptionalWhereClause 'CURSOR'
|
||||
{
|
||||
parser.suggestKeywords([ 'WHERE' ]);
|
||||
}
|
||||
| 'UPDATE' TargetTable 'CURSOR'
|
||||
{
|
||||
parser.suggestKeywords([ 'SET' ]);
|
||||
}
|
||||
| 'UPDATE' TargetTable_EDIT
|
||||
| 'UPDATE' TargetTable
|
||||
| 'UPDATE' 'CURSOR'
|
||||
{
|
||||
parser.suggestTables();
|
||||
parser.suggestDatabases({ appendDot: true });
|
||||
}
|
||||
;
|
||||
|
||||
TargetTable
|
||||
: TableName
|
||||
;
|
||||
|
||||
TargetTable_EDIT
|
||||
: TableName_EDIT
|
||||
;
|
||||
|
||||
TableName
|
||||
: LocalOrSchemaQualifiedName
|
||||
{
|
||||
parser.addTablePrimary($1);
|
||||
}
|
||||
;
|
||||
|
||||
TableName_EDIT
|
||||
: LocalOrSchemaQualifiedName_EDIT
|
||||
;
|
||||
|
||||
SetClauseList
|
||||
: SetClause
|
||||
| SetClauseList ',' SetClause
|
||||
;
|
||||
|
||||
SetClauseList_EDIT
|
||||
: SetClause_EDIT
|
||||
| SetClauseList ',' SetClause_EDIT
|
||||
| SetClause_EDIT ',' SetClauseList
|
||||
| SetClauseList ',' SetClause_EDIT ',' SetClauseList
|
||||
;
|
||||
|
||||
SetClause
|
||||
: SetTarget '=' UpdateSource
|
||||
;
|
||||
|
||||
SetClause_EDIT
|
||||
: SetTarget '=' UpdateSource_EDIT
|
||||
| SetTarget 'CURSOR'
|
||||
{
|
||||
parser.suggestKeywords([ '=' ]);
|
||||
}
|
||||
| 'CURSOR'
|
||||
{
|
||||
parser.suggestColumns();
|
||||
}
|
||||
;
|
||||
|
||||
SetTarget
|
||||
: ColumnReference
|
||||
;
|
||||
|
||||
UpdateSource
|
||||
: ValueExpression
|
||||
;
|
||||
|
||||
UpdateSource_EDIT
|
||||
: ValueExpression_EDIT
|
||||
;
|
||||
|
||||
OptionalFromJoinedTable
|
||||
:
|
||||
| 'FROM' TableReference -> $2
|
||||
;
|
||||
|
||||
FromJoinedTable_EDIT
|
||||
: 'FROM' 'CURSOR'
|
||||
{
|
||||
parser.suggestTables();
|
||||
parser.suggestDatabases({ appendDot: true });
|
||||
}
|
||||
| 'FROM' TableReference_EDIT
|
||||
;
|
39
src/jison/sql/elasticsearch/sql_use.jison
Normal file
39
src/jison/sql/elasticsearch/sql_use.jison
Normal file
@ -0,0 +1,39 @@
|
||||
// Licensed to Cloudera, Inc. under one
|
||||
// or more contributor license agreements. See the NOTICE file
|
||||
// distributed with this work for additional information
|
||||
// regarding copyright ownership. Cloudera, Inc. licenses this file
|
||||
// to you under the Apache License, Version 2.0 (the
|
||||
// "License"); you may not use this file except in compliance
|
||||
// with the License. You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
DataDefinition
|
||||
: UseStatement
|
||||
;
|
||||
|
||||
DataDefinition_EDIT
|
||||
: UseStatement_EDIT
|
||||
;
|
||||
|
||||
UseStatement
|
||||
: 'USE' RegularIdentifier
|
||||
{
|
||||
if (! parser.yy.cursorFound) {
|
||||
parser.yy.result.useDatabase = $2;
|
||||
}
|
||||
}
|
||||
;
|
||||
|
||||
UseStatement_EDIT
|
||||
: 'USE' 'CURSOR'
|
||||
{
|
||||
parser.suggestDatabases();
|
||||
}
|
||||
;
|
839
src/jison/sql/elasticsearch/sql_valueExpression.jison
Normal file
839
src/jison/sql/elasticsearch/sql_valueExpression.jison
Normal file
@ -0,0 +1,839 @@
|
||||
// Licensed to Cloudera, Inc. under one
|
||||
// or more contributor license agreements. See the NOTICE file
|
||||
// distributed with this work for additional information
|
||||
// regarding copyright ownership. Cloudera, Inc. licenses this file
|
||||
// to you under the Apache License, Version 2.0 (the
|
||||
// "License"); you may not use this file except in compliance
|
||||
// with the License. You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
ValueExpression
|
||||
: 'NOT' ValueExpression
|
||||
{
|
||||
// verifyType($2, 'BOOLEAN');
|
||||
$$ = { types: [ 'BOOLEAN' ] };
|
||||
}
|
||||
| '!' ValueExpression
|
||||
{
|
||||
// verifyType($2, 'BOOLEAN');
|
||||
$$ = { types: [ 'BOOLEAN' ] };
|
||||
}
|
||||
| '~' ValueExpression -> $2
|
||||
| '-' ValueExpression %prec NEGATION
|
||||
{
|
||||
// verifyType($2, 'NUMBER');
|
||||
$$ = $2;
|
||||
$2.types = ['NUMBER'];
|
||||
}
|
||||
| ValueExpression 'IS' OptionalNot 'NULL' -> { types: [ 'BOOLEAN' ] }
|
||||
| ValueExpression 'IS' OptionalNot 'TRUE' -> { types: [ 'BOOLEAN' ] }
|
||||
| ValueExpression 'IS' OptionalNot 'FALSE' -> { types: [ 'BOOLEAN' ] }
|
||||
| ValueExpression 'IS' OptionalNot 'DISTINCT' 'FROM' ValueExpression -> { types: [ 'BOOLEAN' ] }
|
||||
;
|
||||
|
||||
ValueExpression_EDIT
|
||||
: 'NOT' ValueExpression_EDIT -> { types: [ 'BOOLEAN' ], suggestFilters: $2.suggestFilters }
|
||||
| 'NOT' 'CURSOR'
|
||||
{
|
||||
parser.suggestFunctions();
|
||||
parser.suggestColumns();
|
||||
parser.suggestKeywords(['EXISTS']);
|
||||
$$ = { types: [ 'BOOLEAN' ] };
|
||||
}
|
||||
| '!' ValueExpression_EDIT -> { types: [ 'BOOLEAN' ], suggestFilters: $2.suggestFilters }
|
||||
| '!' AnyCursor
|
||||
{
|
||||
parser.suggestFunctions({ types: [ 'BOOLEAN' ] });
|
||||
parser.suggestColumns({ types: [ 'BOOLEAN' ] });
|
||||
$$ = { types: [ 'BOOLEAN' ] };
|
||||
}
|
||||
| '~' ValueExpression_EDIT -> { types: [ 'T' ], suggestFilters: $2.suggestFilters }
|
||||
| '~' 'PARTIAL_CURSOR'
|
||||
{
|
||||
parser.suggestFunctions();
|
||||
parser.suggestColumns();
|
||||
$$ = { types: [ 'T' ] };
|
||||
}
|
||||
| '-' ValueExpression_EDIT %prec NEGATION
|
||||
{
|
||||
if (!$2.typeSet) {
|
||||
parser.applyTypeToSuggestions('NUMBER');
|
||||
}
|
||||
$$ = { types: [ 'NUMBER' ], suggestFilters: $2.suggestFilters };
|
||||
}
|
||||
| '-' 'PARTIAL_CURSOR' %prec NEGATION
|
||||
{
|
||||
parser.suggestFunctions({ types: [ 'NUMBER' ] });
|
||||
parser.suggestColumns({ types: [ 'NUMBER' ] });
|
||||
$$ = { types: [ 'NUMBER' ] };
|
||||
}
|
||||
| ValueExpression 'IS' 'CURSOR'
|
||||
{
|
||||
parser.suggestKeywords(['FALSE', 'NOT NULL', 'NOT TRUE', 'NOT FALSE', 'NULL', 'TRUE']);
|
||||
$$ = { types: [ 'BOOLEAN' ] };
|
||||
}
|
||||
| ValueExpression 'IS' 'NOT' 'CURSOR'
|
||||
{
|
||||
parser.suggestKeywords(['FALSE', 'NULL', 'TRUE']);
|
||||
$$ = { types: [ 'BOOLEAN' ] };
|
||||
}
|
||||
| ValueExpression 'IS' OptionalNot 'DISTINCT' 'CURSOR'
|
||||
{
|
||||
$$ = { types: [ 'BOOLEAN' ] };
|
||||
}
|
||||
| ValueExpression 'IS' 'CURSOR' 'NULL'
|
||||
{
|
||||
parser.suggestKeywords(['NOT']);
|
||||
$$ = { types: [ 'BOOLEAN' ] };
|
||||
}
|
||||
| ValueExpression 'IS' 'CURSOR' 'FALSE'
|
||||
{
|
||||
parser.suggestKeywords(['NOT']);
|
||||
$$ = { types: [ 'BOOLEAN' ] };
|
||||
}
|
||||
| ValueExpression 'IS' 'CURSOR' 'TRUE'
|
||||
{
|
||||
parser.suggestKeywords(['NOT']);
|
||||
$$ = { types: [ 'BOOLEAN' ] };
|
||||
}
|
||||
| ValueExpression 'IS' OptionalNot 'DISTINCT' 'FROM' PartialBacktickedOrAnyCursor
|
||||
{
|
||||
parser.valueExpressionSuggest($1, $3 ? 'IS NOT DISTINCT FROM' : 'IS DISTINCT FROM');
|
||||
$$ = { types: [ 'BOOLEAN' ] };
|
||||
}
|
||||
| ValueExpression 'IS' OptionalNot 'DISTINCT' 'FROM' ValueExpression_EDIT
|
||||
{
|
||||
$$ = { types: [ 'BOOLEAN' ], suggestFilters: $6.suggestFilters }
|
||||
}
|
||||
;
|
||||
|
||||
// ------------------ EXISTS and parenthesized ------------------
|
||||
ValueExpression
|
||||
: 'EXISTS' TableSubQuery
|
||||
{
|
||||
$$ = { types: [ 'BOOLEAN' ] };
|
||||
// clear correlated flag after completed sub-query (set by lexer)
|
||||
parser.yy.correlatedSubQuery = false;
|
||||
}
|
||||
| '(' ValueExpression ')' -> $2
|
||||
;
|
||||
|
||||
ValueExpression_EDIT
|
||||
: 'EXISTS' TableSubQuery_EDIT -> { types: [ 'BOOLEAN' ] }
|
||||
| '(' ValueExpression_EDIT RightParenthesisOrError
|
||||
{
|
||||
$$ = $2;
|
||||
}
|
||||
| '(' 'CURSOR' RightParenthesisOrError
|
||||
{
|
||||
parser.valueExpressionSuggest();
|
||||
$$ = { types: ['T'], typeSet: true };
|
||||
}
|
||||
;
|
||||
|
||||
// ------------------ COMPARISON ------------------
|
||||
|
||||
ValueExpression
|
||||
: ValueExpression '=' ValueExpression
|
||||
{
|
||||
parser.addColRefToVariableIfExists($1, $3);
|
||||
$$ = { types: [ 'BOOLEAN' ] };
|
||||
}
|
||||
| ValueExpression '<' ValueExpression
|
||||
{
|
||||
parser.addColRefToVariableIfExists($1, $3);
|
||||
$$ = { types: [ 'BOOLEAN' ] };
|
||||
}
|
||||
| ValueExpression '>' ValueExpression
|
||||
{
|
||||
parser.addColRefToVariableIfExists($1, $3);
|
||||
$$ = { types: [ 'BOOLEAN' ] };
|
||||
}
|
||||
| ValueExpression 'COMPARISON_OPERATOR' ValueExpression
|
||||
{
|
||||
parser.addColRefToVariableIfExists($1, $3);
|
||||
$$ = { types: [ 'BOOLEAN' ] };
|
||||
}
|
||||
;
|
||||
|
||||
ValueExpression_EDIT
|
||||
: 'CURSOR' '=' ValueExpression
|
||||
{
|
||||
parser.valueExpressionSuggest($3, $2);
|
||||
parser.applyTypeToSuggestions($3.types);
|
||||
$$ = { types: [ 'BOOLEAN' ], typeSet: true };
|
||||
}
|
||||
| 'CURSOR' '<' ValueExpression
|
||||
{
|
||||
parser.valueExpressionSuggest($3, $2);
|
||||
parser.applyTypeToSuggestions($3.types);
|
||||
$$ = { types: [ 'BOOLEAN' ], typeSet: true };
|
||||
}
|
||||
| 'CURSOR' '>' ValueExpression
|
||||
{
|
||||
parser.valueExpressionSuggest($3, $2);
|
||||
parser.applyTypeToSuggestions($3.types);
|
||||
$$ = { types: [ 'BOOLEAN' ], typeSet: true };
|
||||
}
|
||||
| 'CURSOR' 'COMPARISON_OPERATOR' ValueExpression
|
||||
{
|
||||
parser.valueExpressionSuggest($3, $2);
|
||||
parser.applyTypeToSuggestions($3.types);
|
||||
$$ = { types: [ 'BOOLEAN' ], typeSet: true };
|
||||
}
|
||||
| ValueExpression_EDIT '=' ValueExpression
|
||||
{
|
||||
if (!$1.typeSet) {
|
||||
parser.applyTypeToSuggestions($3.types);
|
||||
parser.addColRefIfExists($3);
|
||||
}
|
||||
$$ = { types: [ 'BOOLEAN' ], suggestFilters: $1.suggestFilters }
|
||||
}
|
||||
| ValueExpression_EDIT '<' ValueExpression
|
||||
{
|
||||
if (!$1.typeSet) {
|
||||
parser.applyTypeToSuggestions($3.types);
|
||||
parser.addColRefIfExists($3);
|
||||
}
|
||||
$$ = { types: [ 'BOOLEAN' ], suggestFilters: $1.suggestFilters }
|
||||
}
|
||||
| ValueExpression_EDIT '>' ValueExpression
|
||||
{
|
||||
if (!$1.typeSet) {
|
||||
parser.applyTypeToSuggestions($3.types);
|
||||
parser.addColRefIfExists($3);
|
||||
}
|
||||
$$ = { types: [ 'BOOLEAN' ], suggestFilters: $1.suggestFilters }
|
||||
}
|
||||
| ValueExpression_EDIT 'COMPARISON_OPERATOR' ValueExpression
|
||||
{
|
||||
if (!$1.typeSet) {
|
||||
parser.applyTypeToSuggestions($3.types);
|
||||
parser.addColRefIfExists($3);
|
||||
}
|
||||
$$ = { types: [ 'BOOLEAN' ], suggestFilters: $1.suggestFilters }
|
||||
}
|
||||
| ValueExpression '=' PartialBacktickedOrAnyCursor
|
||||
{
|
||||
parser.valueExpressionSuggest($1, $2);
|
||||
parser.applyTypeToSuggestions($1.types);
|
||||
$$ = { types: [ 'BOOLEAN' ], typeSet: true };
|
||||
}
|
||||
| ValueExpression '<' PartialBacktickedOrAnyCursor
|
||||
{
|
||||
parser.valueExpressionSuggest($1, $2);
|
||||
parser.applyTypeToSuggestions($1.types);
|
||||
$$ = { types: [ 'BOOLEAN' ] , typeSet: true, endsWithLessThanOrEqual: true };
|
||||
}
|
||||
| ValueExpression '>' PartialBacktickedOrAnyCursor
|
||||
{
|
||||
parser.valueExpressionSuggest($1, $2);
|
||||
parser.applyTypeToSuggestions($1.types);
|
||||
$$ = { types: [ 'BOOLEAN' ], typeSet: true };
|
||||
}
|
||||
| ValueExpression 'COMPARISON_OPERATOR' PartialBacktickedOrAnyCursor
|
||||
{
|
||||
parser.valueExpressionSuggest($1, $2);
|
||||
parser.applyTypeToSuggestions($1.types);
|
||||
$$ = { types: [ 'BOOLEAN' ], typeSet: true, endsWithLessThanOrEqual: $2 === '<=' };
|
||||
}
|
||||
| ValueExpression '=' ValueExpression_EDIT
|
||||
{
|
||||
if (!$3.typeSet) {
|
||||
parser.applyTypeToSuggestions($1.types);
|
||||
parser.addColRefIfExists($1);
|
||||
}
|
||||
$$ = { types: [ 'BOOLEAN' ], suggestFilters: $3.suggestFilters }
|
||||
}
|
||||
| ValueExpression '<' ValueExpression_EDIT
|
||||
{
|
||||
if (!$3.typeSet) {
|
||||
parser.applyTypeToSuggestions($1.types);
|
||||
parser.addColRefIfExists($1);
|
||||
}
|
||||
$$ = { types: [ 'BOOLEAN' ], suggestFilters: $3.suggestFilters }
|
||||
}
|
||||
| ValueExpression '>' ValueExpression_EDIT
|
||||
{
|
||||
if (!$3.typeSet) {
|
||||
parser.applyTypeToSuggestions($1.types);
|
||||
parser.addColRefIfExists($1);
|
||||
}
|
||||
$$ = { types: [ 'BOOLEAN' ], suggestFilters: $3.suggestFilters }
|
||||
}
|
||||
| ValueExpression 'COMPARISON_OPERATOR' ValueExpression_EDIT
|
||||
{
|
||||
if (!$3.typeSet) {
|
||||
parser.applyTypeToSuggestions($1.types);
|
||||
parser.addColRefIfExists($1);
|
||||
}
|
||||
$$ = { types: [ 'BOOLEAN' ], suggestFilters: $3.suggestFilters }
|
||||
}
|
||||
;
|
||||
|
||||
|
||||
// ------------------ IN ------------------
|
||||
|
||||
ValueExpression
|
||||
: ValueExpression 'NOT' 'IN' '(' TableSubQueryInner ')' -> { types: [ 'BOOLEAN' ] }
|
||||
| ValueExpression 'NOT' 'IN' '(' ValueExpressionList ')' -> { types: [ 'BOOLEAN' ] }
|
||||
| ValueExpression 'IN' '(' TableSubQueryInner ')' -> { types: [ 'BOOLEAN' ] }
|
||||
| ValueExpression 'IN' '(' ValueExpressionList ')' -> { types: [ 'BOOLEAN' ] }
|
||||
;
|
||||
|
||||
ValueExpression_EDIT
|
||||
: ValueExpression 'NOT' 'IN' ValueExpressionInSecondPart_EDIT
|
||||
{
|
||||
if ($4.inValueEdit) {
|
||||
parser.valueExpressionSuggest($1, $2 + ' ' + $3);
|
||||
parser.applyTypeToSuggestions($1.types);
|
||||
}
|
||||
if ($4.cursorAtStart) {
|
||||
parser.suggestKeywords(['SELECT']);
|
||||
}
|
||||
$$ = { types: [ 'BOOLEAN' ], typeSet: true };
|
||||
}
|
||||
| ValueExpression 'IN' ValueExpressionInSecondPart_EDIT
|
||||
{
|
||||
if ($3.inValueEdit) {
|
||||
parser.valueExpressionSuggest($1, $2);
|
||||
parser.applyTypeToSuggestions($1.types);
|
||||
}
|
||||
if ($3.cursorAtStart) {
|
||||
parser.suggestKeywords(['SELECT']);
|
||||
}
|
||||
$$ = { types: [ 'BOOLEAN' ], typeSet: true };
|
||||
}
|
||||
| ValueExpression_EDIT 'NOT' 'IN' '(' ValueExpressionList RightParenthesisOrError -> { types: [ 'BOOLEAN' ], suggestFilters: $1.suggestFilters }
|
||||
| ValueExpression_EDIT 'NOT' 'IN' '(' TableSubQueryInner RightParenthesisOrError -> { types: [ 'BOOLEAN' ], suggestFilters: $1.suggestFilters }
|
||||
| ValueExpression_EDIT 'IN' '(' ValueExpressionList RightParenthesisOrError -> { types: [ 'BOOLEAN' ], suggestFilters: $1.suggestFilters }
|
||||
| ValueExpression_EDIT 'IN' '(' TableSubQueryInner RightParenthesisOrError -> { types: [ 'BOOLEAN' ], suggestFilters: $1.suggestFilters }
|
||||
;
|
||||
|
||||
ValueExpressionInSecondPart_EDIT
|
||||
: '(' TableSubQueryInner_EDIT RightParenthesisOrError
|
||||
| '(' ValueExpressionList_EDIT RightParenthesisOrError -> { inValueEdit: true }
|
||||
| '(' AnyCursor RightParenthesisOrError -> { inValueEdit: true, cursorAtStart: true }
|
||||
;
|
||||
|
||||
// ------------------ BETWEEN ------------------
|
||||
|
||||
ValueExpression
|
||||
: ValueExpression 'NOT' 'BETWEEN' ValueExpression 'BETWEEN_AND' ValueExpression -> { types: [ 'BOOLEAN' ] }
|
||||
| ValueExpression 'BETWEEN' ValueExpression 'BETWEEN_AND' ValueExpression -> { types: [ 'BOOLEAN' ] }
|
||||
;
|
||||
|
||||
ValueExpression_EDIT
|
||||
: ValueExpression_EDIT 'NOT' 'BETWEEN' ValueExpression 'BETWEEN_AND' ValueExpression
|
||||
{
|
||||
if ($4.types[0] === $6.types[0] && !$1.typeSet) {
|
||||
parser.applyTypeToSuggestions($4.types);
|
||||
}
|
||||
$$ = { types: [ 'BOOLEAN' ], suggestFilters: $1.suggestFilters };
|
||||
}
|
||||
| ValueExpression 'NOT' 'BETWEEN' ValueExpression_EDIT 'BETWEEN_AND' ValueExpression
|
||||
{
|
||||
if ($1.types[0] === $6.types[0] && !$4.typeSet) {
|
||||
parser.applyTypeToSuggestions($1.types);
|
||||
}
|
||||
$$ = { types: [ 'BOOLEAN' ], suggestFilters: $4.suggestFilters };
|
||||
}
|
||||
| ValueExpression 'NOT' 'BETWEEN' ValueExpression 'BETWEEN_AND' ValueExpression_EDIT
|
||||
{
|
||||
if ($1.types[0] === $4.types[0] && !$6.typeSet) {
|
||||
parser.applyTypeToSuggestions($1.types);
|
||||
}
|
||||
$$ = { types: [ 'BOOLEAN' ], suggestFilters: $6.suggestFilters };
|
||||
}
|
||||
| ValueExpression 'NOT' 'BETWEEN' ValueExpression 'BETWEEN_AND' 'CURSOR'
|
||||
{
|
||||
parser.valueExpressionSuggest($1, $5);
|
||||
$$ = { types: [ 'BOOLEAN' ], typeSet: true };
|
||||
}
|
||||
| ValueExpression 'NOT' 'BETWEEN' ValueExpression 'CURSOR'
|
||||
{
|
||||
parser.suggestValueExpressionKeywords($4, ['AND']);
|
||||
$$ = { types: [ 'BOOLEAN' ] };
|
||||
}
|
||||
| ValueExpression 'NOT' 'BETWEEN' 'CURSOR'
|
||||
{
|
||||
parser.valueExpressionSuggest($1, $2 + ' ' + $3);
|
||||
$$ = { types: [ 'BOOLEAN' ], typeSet: true };
|
||||
}
|
||||
| ValueExpression_EDIT 'BETWEEN' ValueExpression 'BETWEEN_AND' ValueExpression
|
||||
{
|
||||
if ($1.types[0] === $3.types[0] && !$1.typeSet) {
|
||||
parser.applyTypeToSuggestions($1.types)
|
||||
}
|
||||
$$ = { types: [ 'BOOLEAN' ], suggestFilters: $1.suggestFilters };
|
||||
}
|
||||
| ValueExpression 'BETWEEN' ValueExpression_EDIT 'BETWEEN_AND' ValueExpression
|
||||
{
|
||||
if ($1.types[0] === $3.types[0] && !$3.typeSet) {
|
||||
parser.applyTypeToSuggestions($1.types)
|
||||
}
|
||||
$$ = { types: [ 'BOOLEAN' ], suggestFilters: $3.suggestFilters };
|
||||
}
|
||||
| ValueExpression 'BETWEEN' ValueExpression 'BETWEEN_AND' ValueExpression_EDIT
|
||||
{
|
||||
if ($1.types[0] === $3.types[0] && !$5.typeSet) {
|
||||
parser.applyTypeToSuggestions($1.types)
|
||||
}
|
||||
$$ = { types: [ 'BOOLEAN' ], suggestFilters: $5.suggestFilters };
|
||||
}
|
||||
| ValueExpression 'BETWEEN' ValueExpression 'BETWEEN_AND' 'CURSOR'
|
||||
{
|
||||
parser.valueExpressionSuggest($1, $4);
|
||||
parser.applyTypeToSuggestions($1.types);
|
||||
$$ = { types: [ 'BOOLEAN' ], typeSet: true };
|
||||
}
|
||||
| ValueExpression 'BETWEEN' ValueExpression 'CURSOR'
|
||||
{
|
||||
parser.suggestValueExpressionKeywords($3, ['AND']);
|
||||
$$ = { types: [ 'BOOLEAN' ] };
|
||||
}
|
||||
| ValueExpression 'BETWEEN' 'CURSOR'
|
||||
{
|
||||
parser.valueExpressionSuggest($1, $2);
|
||||
parser.applyTypeToSuggestions($1.types);
|
||||
$$ = { types: [ 'BOOLEAN' ], typeSet: true };
|
||||
}
|
||||
;
|
||||
|
||||
// ------------------ BOOLEAN ------------------
|
||||
|
||||
ValueExpression
|
||||
: ValueExpression 'OR' ValueExpression
|
||||
{
|
||||
// verifyType($1, 'BOOLEAN');
|
||||
// verifyType($3, 'BOOLEAN');
|
||||
$$ = { types: [ 'BOOLEAN' ] };
|
||||
}
|
||||
| ValueExpression 'AND' ValueExpression
|
||||
{
|
||||
// verifyType($1, 'BOOLEAN');
|
||||
// verifyType($3, 'BOOLEAN');
|
||||
$$ = { types: [ 'BOOLEAN' ] };
|
||||
}
|
||||
;
|
||||
|
||||
ValueExpression_EDIT
|
||||
: 'CURSOR' 'OR' ValueExpression
|
||||
{
|
||||
parser.valueExpressionSuggest(undefined, $2);
|
||||
$$ = { types: [ 'BOOLEAN' ], typeSet: true, suggestFilters: true };
|
||||
}
|
||||
| ValueExpression_EDIT 'OR' ValueExpression
|
||||
{
|
||||
parser.addColRefIfExists($3);
|
||||
$$ = { types: [ 'BOOLEAN' ], suggestFilters: $1.suggestFilters }
|
||||
}
|
||||
| ValueExpression 'OR' PartialBacktickedOrAnyCursor
|
||||
{
|
||||
parser.valueExpressionSuggest(undefined, $2);
|
||||
$$ = { types: [ 'BOOLEAN' ], typeSet: true, suggestFilters: true };
|
||||
}
|
||||
| ValueExpression 'OR' ValueExpression_EDIT
|
||||
{
|
||||
parser.addColRefIfExists($1);
|
||||
$$ = { types: [ 'BOOLEAN' ], suggestFilters: $3.suggestFilters }
|
||||
}
|
||||
| 'CURSOR' 'AND' ValueExpression
|
||||
{
|
||||
parser.valueExpressionSuggest(undefined, $2);
|
||||
$$ = { types: [ 'BOOLEAN' ], typeSet: true, suggestFilters: true };
|
||||
}
|
||||
| ValueExpression_EDIT 'AND' ValueExpression
|
||||
{
|
||||
parser.addColRefIfExists($3);
|
||||
$$ = { types: [ 'BOOLEAN' ], suggestFilters: $1.suggestFilters }
|
||||
}
|
||||
| ValueExpression 'AND' PartialBacktickedOrAnyCursor
|
||||
{
|
||||
parser.valueExpressionSuggest(undefined, $2);
|
||||
$$ = { types: [ 'BOOLEAN' ], typeSet: true, suggestFilters: true };
|
||||
}
|
||||
| ValueExpression 'AND' ValueExpression_EDIT
|
||||
{
|
||||
parser.addColRefIfExists($1);
|
||||
$$ = { types: [ 'BOOLEAN' ], suggestFilters: $3.suggestFilters }
|
||||
}
|
||||
;
|
||||
|
||||
// ------------------ ARITHMETIC ------------------
|
||||
|
||||
ValueExpression
|
||||
: ValueExpression '-' ValueExpression
|
||||
{
|
||||
// verifyType($1, 'NUMBER');
|
||||
// verifyType($3, 'NUMBER');
|
||||
$$ = { types: [ 'NUMBER' ] };
|
||||
}
|
||||
| ValueExpression '*' ValueExpression
|
||||
{
|
||||
// verifyType($1, 'NUMBER');
|
||||
// verifyType($3, 'NUMBER');
|
||||
$$ = { types: [ 'NUMBER' ] };
|
||||
}
|
||||
| ValueExpression 'ARITHMETIC_OPERATOR' ValueExpression
|
||||
{
|
||||
// verifyType($1, 'NUMBER');
|
||||
// verifyType($3, 'NUMBER');
|
||||
$$ = { types: [ 'NUMBER' ] };
|
||||
}
|
||||
;
|
||||
|
||||
ValueExpression_EDIT
|
||||
: 'CURSOR' '*' ValueExpression
|
||||
{
|
||||
parser.valueExpressionSuggest(undefined, $2);
|
||||
parser.applyTypeToSuggestions([ 'NUMBER' ]);
|
||||
$$ = { types: [ 'NUMBER' ], typeSet: true };
|
||||
}
|
||||
| 'CURSOR' 'ARITHMETIC_OPERATOR' ValueExpression
|
||||
{
|
||||
parser.valueExpressionSuggest(undefined, $2);
|
||||
parser.applyTypeToSuggestions([ 'NUMBER' ]);
|
||||
$$ = { types: [ 'NUMBER' ], typeSet: true };
|
||||
}
|
||||
| ValueExpression_EDIT '-' ValueExpression
|
||||
{
|
||||
if (!$1.typeSet) {
|
||||
parser.applyTypeToSuggestions(['NUMBER']);
|
||||
parser.addColRefIfExists($3);
|
||||
}
|
||||
$$ = { types: [ 'NUMBER' ], suggestFilters: $1.suggestFilters }
|
||||
}
|
||||
| ValueExpression_EDIT '*' ValueExpression
|
||||
{
|
||||
if (!$1.typeSet) {
|
||||
parser.applyTypeToSuggestions(['NUMBER']);
|
||||
parser.addColRefIfExists($3);
|
||||
}
|
||||
$$ = { types: [ 'NUMBER' ], suggestFilters: $1.suggestFilters }
|
||||
}
|
||||
| ValueExpression_EDIT 'ARITHMETIC_OPERATOR' ValueExpression
|
||||
{
|
||||
if (!$1.typeSet) {
|
||||
parser.applyTypeToSuggestions(['NUMBER']);
|
||||
parser.addColRefIfExists($3);
|
||||
}
|
||||
$$ = { types: [ 'NUMBER' ], suggestFilters: $1.suggestFilters }
|
||||
}
|
||||
| ValueExpression '-' PartialBacktickedOrAnyCursor
|
||||
{
|
||||
parser.valueExpressionSuggest(undefined, $2);
|
||||
parser.applyTypeToSuggestions(['NUMBER']);
|
||||
$$ = { types: [ 'NUMBER' ], typeSet: true };
|
||||
}
|
||||
| ValueExpression '*' PartialBacktickedOrAnyCursor
|
||||
{
|
||||
parser.valueExpressionSuggest(undefined, $2);
|
||||
parser.applyTypeToSuggestions(['NUMBER']);
|
||||
$$ = { types: [ 'NUMBER' ], typeSet: true };
|
||||
}
|
||||
| ValueExpression 'ARITHMETIC_OPERATOR' PartialBacktickedOrAnyCursor
|
||||
{
|
||||
parser.valueExpressionSuggest(undefined, $2);
|
||||
parser.applyTypeToSuggestions(['NUMBER']);
|
||||
$$ = { types: [ 'NUMBER' ], typeSet: true };
|
||||
}
|
||||
| ValueExpression '-' ValueExpression_EDIT
|
||||
{
|
||||
if (!$3.typeSet) {
|
||||
parser.applyTypeToSuggestions(['NUMBER']);
|
||||
parser.addColRefIfExists($1);
|
||||
}
|
||||
$$ = { types: [ 'NUMBER' ], suggestFilters: $3.suggestFilters };
|
||||
}
|
||||
| ValueExpression '*' ValueExpression_EDIT
|
||||
{
|
||||
if (!$3.typeSet) {
|
||||
parser.applyTypeToSuggestions(['NUMBER']);
|
||||
parser.addColRefIfExists($1);
|
||||
}
|
||||
$$ = { types: [ 'NUMBER' ], suggestFilters: $3.suggestFilters };
|
||||
}
|
||||
| ValueExpression 'ARITHMETIC_OPERATOR' ValueExpression_EDIT
|
||||
{
|
||||
if (!$3.typeSet) {
|
||||
parser.applyTypeToSuggestions(['NUMBER']);
|
||||
parser.addColRefIfExists($1);
|
||||
}
|
||||
$$ = { types: [ 'NUMBER' ], suggestFilters: $3.suggestFilters };
|
||||
}
|
||||
;
|
||||
|
||||
// ------------------ LIKE, RLIKE and REGEXP ------------------
|
||||
|
||||
ValueExpression
|
||||
: ValueExpression LikeRightPart -> { types: [ 'BOOLEAN' ] }
|
||||
| ValueExpression 'NOT' LikeRightPart -> { types: [ 'BOOLEAN' ] }
|
||||
;
|
||||
|
||||
LikeRightPart
|
||||
: 'LIKE' ValueExpression -> { suggestKeywords: ['NOT'] }
|
||||
| 'RLIKE' ValueExpression -> { suggestKeywords: ['NOT'] }
|
||||
| 'REGEXP' ValueExpression -> { suggestKeywords: ['NOT'] }
|
||||
;
|
||||
|
||||
LikeRightPart_EDIT
|
||||
: 'LIKE' ValueExpression_EDIT
|
||||
| 'RLIKE' ValueExpression_EDIT
|
||||
| 'REGEXP' ValueExpression_EDIT
|
||||
| 'LIKE' PartialBacktickedOrCursor
|
||||
{
|
||||
parser.suggestFunctions({ types: [ 'STRING' ] });
|
||||
parser.suggestColumns({ types: [ 'STRING' ] });
|
||||
$$ = { types: ['BOOLEAN'] }
|
||||
}
|
||||
| 'RLIKE' PartialBacktickedOrCursor
|
||||
{
|
||||
parser.suggestFunctions({ types: [ 'STRING' ] });
|
||||
parser.suggestColumns({ types: [ 'STRING' ] });
|
||||
$$ = { types: ['BOOLEAN'] }
|
||||
}
|
||||
| 'REGEXP' PartialBacktickedOrCursor
|
||||
{
|
||||
parser.suggestFunctions({ types: [ 'STRING' ] });
|
||||
parser.suggestColumns({ types: [ 'STRING' ] });
|
||||
$$ = { types: ['BOOLEAN'] }
|
||||
}
|
||||
;
|
||||
|
||||
ValueExpression_EDIT
|
||||
: ValueExpression_EDIT LikeRightPart -> { types: [ 'BOOLEAN' ], suggestFilters: $1.suggestFilters }
|
||||
| ValueExpression_EDIT 'NOT' LikeRightPart -> { types: [ 'BOOLEAN' ], suggestFilters: $1.suggestFilters }
|
||||
| ValueExpression LikeRightPart_EDIT -> { types: [ 'BOOLEAN' ] }
|
||||
| ValueExpression 'NOT' LikeRightPart_EDIT -> { types: [ 'BOOLEAN' ] }
|
||||
| 'CURSOR' LikeRightPart
|
||||
{
|
||||
parser.valueExpressionSuggest(undefined, $2);
|
||||
parser.applyTypeToSuggestions([ 'STRING' ]);
|
||||
$$ = { types: [ 'BOOLEAN' ], typeSet: true };
|
||||
}
|
||||
| 'CURSOR' 'NOT' LikeRightPart
|
||||
{
|
||||
parser.valueExpressionSuggest(undefined, $2 + ' ' + $3);
|
||||
parser.applyTypeToSuggestions([ 'STRING' ]);
|
||||
$$ = { types: [ 'BOOLEAN' ], typeSet: true };
|
||||
}
|
||||
;
|
||||
|
||||
// ------------------ CASE, WHEN, THEN ------------------
|
||||
|
||||
ValueExpression
|
||||
: 'CASE' CaseRightPart -> $2
|
||||
| 'CASE' ValueExpression CaseRightPart -> $3
|
||||
;
|
||||
|
||||
ValueExpression_EDIT
|
||||
: 'CASE' CaseRightPart_EDIT -> $2
|
||||
| 'CASE' 'CURSOR' EndOrError
|
||||
{
|
||||
parser.valueExpressionSuggest();
|
||||
parser.suggestKeywords(['WHEN']);
|
||||
$$ = { types: [ 'T' ], typeSet: true };
|
||||
}
|
||||
| 'CASE' ValueExpression CaseRightPart_EDIT -> $3
|
||||
| 'CASE' ValueExpression 'CURSOR' EndOrError
|
||||
{
|
||||
parser.suggestValueExpressionKeywords($2, ['WHEN']);
|
||||
$$ = { types: [ 'T' ], typeSet: true };
|
||||
}
|
||||
| 'CASE' ValueExpression_EDIT CaseRightPart
|
||||
{
|
||||
$$ = $3;
|
||||
$$.suggestFilters = $2.suggestFilters;
|
||||
}
|
||||
| 'CASE' ValueExpression_EDIT EndOrError -> { types: [ 'T' ], suggestFilters: $2.suggestFilters }
|
||||
| 'CASE' 'CURSOR' CaseRightPart -> { types: [ 'T' ] }
|
||||
;
|
||||
|
||||
CaseRightPart
|
||||
: CaseWhenThenList 'END' -> parser.findCaseType($1)
|
||||
| CaseWhenThenList 'ELSE' ValueExpression 'END'
|
||||
{
|
||||
$1.caseTypes.push($3);
|
||||
$$ = parser.findCaseType($1);
|
||||
}
|
||||
;
|
||||
|
||||
CaseRightPart_EDIT
|
||||
: CaseWhenThenList_EDIT EndOrError -> parser.findCaseType($1)
|
||||
| CaseWhenThenList 'ELSE' ValueExpression 'CURSOR'
|
||||
{
|
||||
parser.suggestValueExpressionKeywords($3, ['END']);
|
||||
$1.caseTypes.push($3);
|
||||
$$ = parser.findCaseType($1);
|
||||
}
|
||||
| CaseWhenThenList_EDIT 'ELSE' ValueExpression EndOrError
|
||||
{
|
||||
$1.caseTypes.push($3);
|
||||
$$ = parser.findCaseType($1);
|
||||
}
|
||||
| CaseWhenThenList_EDIT 'ELSE' EndOrError -> parser.findCaseType($1)
|
||||
| CaseWhenThenList 'CURSOR' ValueExpression EndOrError
|
||||
{
|
||||
if ($4.toLowerCase() !== 'end') {
|
||||
parser.suggestValueExpressionKeywords($1, [{ value: 'END', weight: 3 }, { value: 'ELSE', weight: 2 }, { value: 'WHEN', weight: 1 }]);
|
||||
} else {
|
||||
parser.suggestValueExpressionKeywords($1, [{ value: 'ELSE', weight: 2 }, { value: 'WHEN', weight: 1 }]);
|
||||
}
|
||||
$$ = parser.findCaseType($1);
|
||||
}
|
||||
| CaseWhenThenList 'CURSOR' EndOrError
|
||||
{
|
||||
if ($3.toLowerCase() !== 'end') {
|
||||
parser.suggestValueExpressionKeywords($1, [{ value: 'END', weight: 3 }, { value: 'ELSE', weight: 2 }, { value: 'WHEN', weight: 1 }]);
|
||||
} else {
|
||||
parser.suggestValueExpressionKeywords($1, [{ value: 'ELSE', weight: 2 }, { value: 'WHEN', weight: 1 }]);
|
||||
}
|
||||
$$ = parser.findCaseType($1);
|
||||
}
|
||||
| CaseWhenThenList 'ELSE' ValueExpression_EDIT EndOrError
|
||||
{
|
||||
$1.caseTypes.push($3);
|
||||
$$ = parser.findCaseType($1);
|
||||
$$.suggestFilters = $3.suggestFilters
|
||||
}
|
||||
| CaseWhenThenList 'ELSE' 'CURSOR' EndOrError
|
||||
{
|
||||
parser.valueExpressionSuggest();
|
||||
$$ = parser.findCaseType($1);
|
||||
}
|
||||
| 'ELSE' 'CURSOR' EndOrError
|
||||
{
|
||||
parser.valueExpressionSuggest();
|
||||
$$ = { types: [ 'T' ], typeSet: true };
|
||||
}
|
||||
| 'CURSOR' 'ELSE' ValueExpression EndOrError
|
||||
{
|
||||
parser.valueExpressionSuggest();
|
||||
parser.suggestKeywords(['WHEN']);
|
||||
$$ = $3;
|
||||
}
|
||||
| 'CURSOR' 'ELSE' EndOrError
|
||||
{
|
||||
parser.valueExpressionSuggest();
|
||||
parser.suggestKeywords(['WHEN']);
|
||||
$$ = { types: [ 'T' ] };
|
||||
}
|
||||
;
|
||||
|
||||
EndOrError
|
||||
: 'END'
|
||||
| error
|
||||
;
|
||||
|
||||
CaseWhenThenList
|
||||
: CaseWhenThenListPartTwo -> { caseTypes: [ $1 ], lastType: $1 }
|
||||
| CaseWhenThenList CaseWhenThenListPartTwo
|
||||
{
|
||||
$1.caseTypes.push($2);
|
||||
$$ = { caseTypes: $1.caseTypes, lastType: $2 };
|
||||
}
|
||||
;
|
||||
|
||||
CaseWhenThenList_EDIT
|
||||
: CaseWhenThenListPartTwo_EDIT
|
||||
| CaseWhenThenList CaseWhenThenListPartTwo_EDIT
|
||||
| CaseWhenThenList CaseWhenThenListPartTwo_EDIT CaseWhenThenList
|
||||
| CaseWhenThenList 'CURSOR' CaseWhenThenList
|
||||
{
|
||||
parser.suggestValueExpressionKeywords($1, ['WHEN']);
|
||||
}
|
||||
| CaseWhenThenListPartTwo_EDIT CaseWhenThenList -> $2
|
||||
;
|
||||
|
||||
CaseWhenThenListPartTwo
|
||||
: 'WHEN' ValueExpression 'THEN' ValueExpression -> $4
|
||||
;
|
||||
|
||||
CaseWhenThenListPartTwo_EDIT
|
||||
: 'WHEN' ValueExpression_EDIT -> { caseTypes: [{ types: ['T'] }], suggestFilters: $2.suggestFilters }
|
||||
| 'WHEN' ValueExpression_EDIT 'THEN' -> { caseTypes: [{ types: ['T'] }], suggestFilters: $2.suggestFilters }
|
||||
| 'WHEN' ValueExpression_EDIT 'THEN' ValueExpression -> { caseTypes: [$4], suggestFilters: $2.suggestFilters }
|
||||
| 'WHEN' ValueExpression 'THEN' ValueExpression_EDIT -> { caseTypes: [$4], suggestFilters: $4.suggestFilters }
|
||||
| 'WHEN' 'THEN' ValueExpression_EDIT -> { caseTypes: [$3], suggestFilters: $3.suggestFilters }
|
||||
| 'CURSOR' ValueExpression 'THEN'
|
||||
{
|
||||
parser.suggestKeywords(['WHEN']);
|
||||
$$ = { caseTypes: [{ types: ['T'] }] };
|
||||
}
|
||||
| 'CURSOR' ValueExpression 'THEN' ValueExpression
|
||||
{
|
||||
parser.suggestKeywords(['WHEN']);
|
||||
$$ = { caseTypes: [$4] };
|
||||
}
|
||||
| 'CURSOR' 'THEN'
|
||||
{
|
||||
parser.valueExpressionSuggest();
|
||||
parser.suggestKeywords(['WHEN']);
|
||||
$$ = { caseTypes: [{ types: ['T'] }] };
|
||||
}
|
||||
| 'CURSOR' 'THEN' ValueExpression
|
||||
{
|
||||
parser.valueExpressionSuggest();
|
||||
parser.suggestKeywords(['WHEN']);
|
||||
$$ = { caseTypes: [{ types: ['T'] }] };
|
||||
}
|
||||
| 'WHEN' 'CURSOR'
|
||||
{
|
||||
parser.valueExpressionSuggest();
|
||||
$$ = { caseTypes: [{ types: ['T'] }], suggestFilters: true };
|
||||
}
|
||||
| 'WHEN' 'CURSOR' ValueExpression
|
||||
{
|
||||
parser.valueExpressionSuggest();
|
||||
parser.suggestKeywords(['THEN']);
|
||||
$$ = { caseTypes: [{ types: ['T'] }], suggestFilters: true };
|
||||
}
|
||||
| 'WHEN' 'CURSOR' 'THEN'
|
||||
{
|
||||
parser.valueExpressionSuggest();
|
||||
$$ = { caseTypes: [{ types: ['T'] }], suggestFilters: true };
|
||||
}
|
||||
| 'WHEN' 'CURSOR' 'THEN' ValueExpression
|
||||
{
|
||||
parser.valueExpressionSuggest();
|
||||
$$ = { caseTypes: [$4], suggestFilters: true };
|
||||
}
|
||||
| 'WHEN' ValueExpression 'CURSOR'
|
||||
{
|
||||
parser.suggestValueExpressionKeywords($2, ['THEN']);
|
||||
$$ = { caseTypes: [{ types: ['T'] }] };
|
||||
}
|
||||
| 'WHEN' ValueExpression 'CURSOR' ValueExpression
|
||||
{
|
||||
parser.suggestValueExpressionKeywords($2, ['THEN']);
|
||||
$$ = { caseTypes: [{ types: ['T'] }] };
|
||||
}
|
||||
| 'WHEN' ValueExpression 'THEN' 'CURSOR'
|
||||
{
|
||||
parser.valueExpressionSuggest();
|
||||
$$ = { caseTypes: [{ types: ['T'] }] };
|
||||
}
|
||||
| 'WHEN' ValueExpression 'THEN' 'CURSOR' ValueExpression
|
||||
{
|
||||
parser.valueExpressionSuggest();
|
||||
$$ = { caseTypes: [{ types: ['T'] }] };
|
||||
}
|
||||
| 'WHEN' 'THEN' 'CURSOR' ValueExpression
|
||||
{
|
||||
parser.valueExpressionSuggest();
|
||||
$$ = { caseTypes: [{ types: ['T'] }] };
|
||||
}
|
||||
| 'WHEN' 'THEN' 'CURSOR'
|
||||
{
|
||||
parser.valueExpressionSuggest();
|
||||
$$ = { caseTypes: [{ types: ['T'] }] };
|
||||
}
|
||||
;
|
19
src/jison/sql/elasticsearch/syntax_footer.jison
Normal file
19
src/jison/sql/elasticsearch/syntax_footer.jison
Normal file
@ -0,0 +1,19 @@
|
||||
// Licensed to Cloudera, Inc. under one
|
||||
// or more contributor license agreements. See the NOTICE file
|
||||
// distributed with this work for additional information
|
||||
// regarding copyright ownership. Cloudera, Inc. licenses this file
|
||||
// to you under the Apache License, Version 2.0 (the
|
||||
// "License"); you may not use this file except in compliance
|
||||
// with the License. You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
%%
|
||||
|
||||
SqlParseSupport.initSyntaxParser(parser);
|
28
src/jison/sql/elasticsearch/syntax_header.jison
Normal file
28
src/jison/sql/elasticsearch/syntax_header.jison
Normal file
@ -0,0 +1,28 @@
|
||||
// Licensed to Cloudera, Inc. under one
|
||||
// or more contributor license agreements. See the NOTICE file
|
||||
// distributed with this work for additional information
|
||||
// regarding copyright ownership. Cloudera, Inc. licenses this file
|
||||
// to you under the Apache License, Version 2.0 (the
|
||||
// "License"); you may not use this file except in compliance
|
||||
// with the License. You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
%left 'AND' 'OR'
|
||||
%left 'BETWEEN'
|
||||
%left 'NOT' '!' '~'
|
||||
%left '=' '<' '>' 'COMPARISON_OPERATOR'
|
||||
%left '-' '*' 'ARITHMETIC_OPERATOR'
|
||||
|
||||
%left ';' ','
|
||||
%nonassoc 'IN' 'IS' 'LIKE' 'RLIKE' 'REGEXP' 'EXISTS' NEGATION
|
||||
|
||||
%start SqlSyntax
|
||||
|
||||
%%
|
19
src/jison/sql/flink/autocomplete_footer.jison
Normal file
19
src/jison/sql/flink/autocomplete_footer.jison
Normal file
@ -0,0 +1,19 @@
|
||||
// Licensed to Cloudera, Inc. under one
|
||||
// or more contributor license agreements. See the NOTICE file
|
||||
// distributed with this work for additional information
|
||||
// regarding copyright ownership. Cloudera, Inc. licenses this file
|
||||
// to you under the Apache License, Version 2.0 (the
|
||||
// "License"); you may not use this file except in compliance
|
||||
// with the License. You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
%%
|
||||
|
||||
SqlParseSupport.initSqlParser(parser);
|
29
src/jison/sql/flink/autocomplete_header.jison
Normal file
29
src/jison/sql/flink/autocomplete_header.jison
Normal file
@ -0,0 +1,29 @@
|
||||
// Licensed to Cloudera, Inc. under one
|
||||
// or more contributor license agreements. See the NOTICE file
|
||||
// distributed with this work for additional information
|
||||
// regarding copyright ownership. Cloudera, Inc. licenses this file
|
||||
// to you under the Apache License, Version 2.0 (the
|
||||
// "License"); you may not use this file except in compliance
|
||||
// with the License. You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
%left 'AND' 'OR'
|
||||
%left 'BETWEEN'
|
||||
%left 'NOT' '!' '~'
|
||||
%left '=' '<' '>' 'COMPARISON_OPERATOR'
|
||||
%left '-' '*' 'ARITHMETIC_OPERATOR'
|
||||
|
||||
%left ';' ','
|
||||
%nonassoc 'CURSOR' 'PARTIAL_CURSOR'
|
||||
%nonassoc 'IN' 'IS' 'LIKE' 'RLIKE' 'REGEXP' 'EXISTS' NEGATION
|
||||
|
||||
%start SqlAutocomplete
|
||||
|
||||
%%
|
279
src/jison/sql/flink/sql.jisonlex
Normal file
279
src/jison/sql/flink/sql.jisonlex
Normal file
@ -0,0 +1,279 @@
|
||||
// Licensed to Cloudera, Inc. under one
|
||||
// or more contributor license agreements. See the NOTICE file
|
||||
// distributed with this work for additional information
|
||||
// regarding copyright ownership. Cloudera, Inc. licenses this file
|
||||
// to you under the Apache License, Version 2.0 (the
|
||||
// "License"); you may not use this file except in compliance
|
||||
// with the License. You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
%options case-insensitive flex
|
||||
%s between
|
||||
%x hdfs doubleQuotedValue singleQuotedValue backtickedValue
|
||||
%%
|
||||
|
||||
\s { /* skip whitespace */ }
|
||||
'--'.* { /* skip comments */ }
|
||||
[/][*][^*]*[*]+([^/*][^*]*[*]+)*[/] { /* skip comments */ }
|
||||
|
||||
'\u2020' { parser.yy.partialCursor = false; parser.yy.cursorFound = yylloc; return 'CURSOR'; }
|
||||
'\u2021' { parser.yy.partialCursor = true; parser.yy.cursorFound = yylloc; return 'PARTIAL_CURSOR'; }
|
||||
|
||||
<between>'AND' { this.popState(); return 'BETWEEN_AND'; }
|
||||
|
||||
// Reserved Keywords
|
||||
'ADVANCE' { return 'ADVANCE'; }
|
||||
'ANALYZE' { return 'ANALYZE'; }
|
||||
'AND' { return 'AND'; }
|
||||
'ARRAY' { return 'ARRAY'; }
|
||||
'AS' { return 'AS'; }
|
||||
'AT' { return 'AT'; }
|
||||
'BEGINNING' { return 'BEGINNING' }
|
||||
'BETWEEN' { this.begin('between'); return 'BETWEEN'; }
|
||||
'BIGINT' { return 'BIGINT'; }
|
||||
'BOOLEAN' { return 'BOOLEAN'; }
|
||||
'BY' { return 'BY'; }
|
||||
'CASE' { return 'CASE'; }
|
||||
'CAST' { return 'CAST'; }
|
||||
'CATALOG' { return 'CATALOG'; }
|
||||
'CHANGES' { return 'CHANGES'; }
|
||||
'COLUMN' { return 'COLUMN'; }
|
||||
'COLUMNS' { return 'COLUMNS'; }
|
||||
'CONNECTOR' { return 'CONNECTOR'; }
|
||||
'CONNECTORS' { return 'CONNECTORS'; }
|
||||
'CREATE' { parser.determineCase(yytext); return 'CREATE'; }
|
||||
'DATE' { return 'DATE'; }
|
||||
'DAY' { return 'DAY'; }
|
||||
'DECIMAL' { return 'DECIMAL'; }
|
||||
'DELETE' { return 'DELETE'; }
|
||||
'DESCRIBE' { return 'DESCRIBE'; }
|
||||
'DISTINCT' { return 'DISTINCT'; }
|
||||
'DOUBLE' { return 'DOUBLE'; }
|
||||
'DROP' { parser.determineCase(yytext); parser.addStatementTypeLocation('DROP', yylloc, yy.lexer.upcomingInput()); return 'DROP'; }
|
||||
'ELSE' { return 'ELSE'; }
|
||||
'EMIT' { return 'EMIT'; }
|
||||
'END' { return 'END'; }
|
||||
'EXISTS' { parser.yy.correlatedSubQuery = true; return 'EXISTS'; }
|
||||
'EXPLAIN' { parser.determineCase(yytext); return 'EXPLAIN'; }
|
||||
'EXPORT' { return 'EXPORT'; }
|
||||
'EXTENDED' { return 'EXTENDED'; }
|
||||
'FROM' { parser.determineCase(yytext); return 'FROM'; }
|
||||
'FULL' { return 'FULL'; }
|
||||
'FUNCTION' { return 'FUNCTION'; }
|
||||
'FUNCTIONS' { return 'FUNCTIONS'; }
|
||||
'GROUP' { return 'GROUP'; }
|
||||
'HAVING' { return 'HAVING'; }
|
||||
'HOPPING' { return 'HOPPING'; }
|
||||
'HOUR' { return 'HOUR'; }
|
||||
'HOURS' { return 'HOURS'; }
|
||||
'IF' { return 'IF'; }
|
||||
'IN' { return 'IN'; }
|
||||
'INNER' { return 'INNER'; }
|
||||
'INSERT' { return 'INSERT'; }
|
||||
'INT' { return 'INT'; }
|
||||
'INTEGER' { return 'INTEGER'; }
|
||||
'INTO' { return 'INTO'; }
|
||||
'IS' { return 'IS'; }
|
||||
'JOIN' { return 'JOIN'; }
|
||||
'KEY' { return 'KEY'; }
|
||||
'LEFT' { return 'LEFT'; }
|
||||
'LIKE' { return 'LIKE'; }
|
||||
'LIMIT' { return 'LIMIT'; }
|
||||
'LIST' { return 'LIST'; }
|
||||
'LOAD' { return 'LOAD'; }
|
||||
'MAP' { return 'MAP'; }
|
||||
'MILLISECOND' { return 'MILLISECOND'; }
|
||||
'MILLISECONDS' { return 'MILLISECONDS'; }
|
||||
'MINUTE' { return 'MINUTE'; }
|
||||
'MINUTES' { return 'MINUTES'; }
|
||||
'MONTH' { return 'MONTH'; }
|
||||
'MONTHS' { return 'MONTHS'; }
|
||||
'NOT' { return 'NOT'; }
|
||||
'NULL' { return 'NULL'; }
|
||||
'ON' { return 'ON'; }
|
||||
'OR' { return 'OR'; }
|
||||
'OUTER' { return 'OUTER'; }
|
||||
'PARTITION' { return 'PARTITION'; }
|
||||
'PARTITIONS' { return 'PARTITIONS'; }
|
||||
'PRINT' { return 'PRINT'; }
|
||||
'PROPERTIES' { return 'PROPERTIES'; }
|
||||
'QUERIES' { return 'QUERIES'; }
|
||||
'QUERY' { return 'QUERY'; }
|
||||
'RENAME' { return 'RENAME'; }
|
||||
'RESET' { return 'RESET'; }
|
||||
'RIGHT' { return 'RIGHT'; }
|
||||
'RUN' { return 'RUN'; }
|
||||
'SAMPLE' { return 'SAMPLE'; }
|
||||
'SCRIPT' { return 'SCRIPT'; }
|
||||
'SECOND' { return 'SECOND'; }
|
||||
'SECOND' { return 'SECOND'; }
|
||||
'SELECT' { parser.determineCase(yytext); parser.addStatementTypeLocation('SELECT', yylloc); return 'SELECT'; }
|
||||
'SESSION' { return 'SESSION'; }
|
||||
'SET' { parser.determineCase(yytext); parser.addStatementTypeLocation('SET', yylloc); return 'SET'; }
|
||||
'SHOW' { parser.determineCase(yytext); parser.addStatementTypeLocation('SHOW', yylloc); return 'SHOW'; }
|
||||
'SINK' { return 'SINK'; }
|
||||
'SOURCE' { return 'SOURCE'; }
|
||||
'STREAM' { return 'STREAM'; }
|
||||
'STREAMS' { return 'STREAMS'; }
|
||||
'STRING' { return 'STRING'; }
|
||||
'STRUCT' { return 'STRUCT'; }
|
||||
'TABLE' { return 'TABLE'; }
|
||||
'TABLES' { return 'TABLES'; }
|
||||
'TERMINATE' { return 'TERMINATE'; }
|
||||
'THEN' { return 'THEN'; }
|
||||
'TIME' { return 'TIME'; }
|
||||
'TIMESTAMP' { return 'TIMESTAMP'; }
|
||||
'TO' { return 'TO'; }
|
||||
'TRUE' { return 'TRUE'; }
|
||||
'TOPIC' { return 'TOPIC'; }
|
||||
'TOPICS' { return 'TOPICS'; }
|
||||
'TUMBLING' { return 'TUMBLING'; }
|
||||
'TYPE' { return 'TYPE'; }
|
||||
'TYPES' { return 'TYPES'; }
|
||||
'UNSET' { return 'UNSET'; }
|
||||
'VALUES' { return 'VALUES'; }
|
||||
'VARCHAR' { return 'VARCHAR'; }
|
||||
'WHEN' { return 'WHEN'; }
|
||||
'WHERE' { return 'WHERE'; }
|
||||
'WITH' { parser.determineCase(yytext); parser.addStatementTypeLocation('WITH', yylloc); return 'WITH'; }
|
||||
'WITHIN' { return 'WITHIN'; }
|
||||
'YEAR' { return 'YEAR'; }
|
||||
'YEARS' { return 'YEARS'; }
|
||||
'ZONE' { return 'ZONE'; }
|
||||
|
||||
// --- UDFs ---
|
||||
ABS\s*\( { yy.lexer.unput('('); yytext = 'abs'; parser.addFunctionLocation(yylloc, yytext); return 'ABS'; }
|
||||
ARRAYCONTAINS\s*\( { yy.lexer.unput('('); yytext = 'arraycontains'; parser.addFunctionLocation(yylloc, yytext); return 'ARRAYCONTAINS'; }
|
||||
CEIL\s*\( { yy.lexer.unput('('); yytext = 'ceil'; parser.addFunctionLocation(yylloc, yytext); return 'CEIL'; }
|
||||
CONCAT\s*\( { yy.lexer.unput('('); yytext = 'concat'; parser.addFunctionLocation(yylloc, yytext); return 'CONCAT'; }
|
||||
DATETOSTRING\s*\( { yy.lexer.unput('('); yytext = 'datetostring'; parser.addFunctionLocation(yylloc, yytext); return 'DATETOSTRING'; }
|
||||
ELT\s*\( { yy.lexer.unput('('); yytext = 'elt'; parser.addFunctionLocation(yylloc, yytext); return 'ELT'; }
|
||||
EXTRACTJSONFIELD\s*\( { yy.lexer.unput('('); yytext = 'extractjsonfield'; parser.addFunctionLocation(yylloc, yytext); return 'EXTRACTJSONFIELD'; }
|
||||
FIELD\s*\( { yy.lexer.unput('('); yytext = 'field'; parser.addFunctionLocation(yylloc, yytext); return 'FIELD'; }
|
||||
FLOOR\s*\( { yy.lexer.unput('('); yytext = 'floor'; parser.addFunctionLocation(yylloc, yytext); return 'FLOOR'; }
|
||||
GEO_DISTANCE\s*\( { yy.lexer.unput('('); yytext = 'geo_distance'; parser.addFunctionLocation(yylloc, yytext); return 'GEO_DISTANCE'; }
|
||||
IFNULL\s*\( { yy.lexer.unput('('); yytext = 'ifnull'; parser.addFunctionLocation(yylloc, yytext); return 'IFNULL'; }
|
||||
LCASE\s*\( { yy.lexer.unput('('); yytext = 'lcase'; parser.addFunctionLocation(yylloc, yytext); return 'LCASE'; }
|
||||
LEN\s*\( { yy.lexer.unput('('); yytext = 'len'; parser.addFunctionLocation(yylloc, yytext); return 'LEN'; }
|
||||
MASK\s*\( { yy.lexer.unput('('); yytext = 'msk'; parser.addFunctionLocation(yylloc, yytext); return 'MASK'; }
|
||||
MASK_KEEP_LEFT\s*\( { yy.lexer.unput('('); yytext = 'mask_keep_left'; parser.addFunctionLocation(yylloc, yytext); return 'MASK_KEEP_LEFT'; }
|
||||
MASK_KEEP_RIGHT\s*\( { yy.lexer.unput('('); yytext = 'mask_keep_right'; parser.addFunctionLocation(yylloc, yytext); return 'MASK_KEEP_RIGHT'; }
|
||||
MASK_LEFT\s*\( { yy.lexer.unput('('); yytext = 'mask_left'; parser.addFunctionLocation(yylloc, yytext); return 'MASK_LEFT'; }
|
||||
MASK_RIGHT\s*\( { yy.lexer.unput('('); yytext = 'mask_right'; parser.addFunctionLocation(yylloc, yytext); return 'MASK_RIGHT'; }
|
||||
RANDOM\s*\( { yy.lexer.unput('('); yytext = 'random'; parser.addFunctionLocation(yylloc, yytext); return 'RANDOM'; }
|
||||
ROUND\s*\( { yy.lexer.unput('('); yytext = 'round'; parser.addFunctionLocation(yylloc, yytext); return 'ROUND'; }
|
||||
SPLIT\s*\( { yy.lexer.unput('('); yytext = 'split'; parser.addFunctionLocation(yylloc, yytext); return 'SPLIT'; }
|
||||
STRINGTODATE\s*\( { yy.lexer.unput('('); yytext = 'stringtodate'; parser.addFunctionLocation(yylloc, yytext); return 'STRINGTODATE'; }
|
||||
STRINGTOTIMESTAMP\s*\( { yy.lexer.unput('('); yytext = 'stringtotimestamp'; parser.addFunctionLocation(yylloc, yytext); return 'STRINGTOTIMESTAMP'; }
|
||||
SUBSTRING\s*\( { yy.lexer.unput('('); yytext = 'substring'; parser.addFunctionLocation(yylloc, yytext); return 'SUBSTRING'; }
|
||||
TIMESTAMPTOSTRING\s*\( { yy.lexer.unput('('); yytext = 'timestamptostring'; parser.addFunctionLocation(yylloc, yytext); return 'TIMESTAMPTOSTRING'; }
|
||||
TRIM\s*\( { yy.lexer.unput('('); yytext = 'trim'; parser.addFunctionLocation(yylloc, yytext); return 'TRIM'; }
|
||||
UCASE\s*\( { yy.lexer.unput('('); yytext = 'ucase'; parser.addFunctionLocation(yylloc, yytext); return 'UCASE'; }
|
||||
URL_DECODE_PARAM\s*\( { yy.lexer.unput('('); yytext = 'url_decode_param'; parser.addFunctionLocation(yylloc, yytext); return 'URL_DECODE_PARAM'; }
|
||||
URL_ENCODE_PARAM\s*\( { yy.lexer.unput('('); yytext = 'urel_encode_param'; parser.addFunctionLocation(yylloc, yytext); return 'URL_ENCODE_PARAM'; }
|
||||
URL_EXTRACT_FRAGMENT\s*\( { yy.lexer.unput('('); yytext = 'url_extract_fragment'; parser.addFunctionLocation(yylloc, yytext); return 'URL_EXTRACT_FRAGMENT'; }
|
||||
URL_EXTRACT_HOST\s*\( { yy.lexer.unput('('); yytext = 'url_extract_host'; parser.addFunctionLocation(yylloc, yytext); return 'URL_EXTRACT_HOST'; }
|
||||
URL_EXTRACT_PARAMETER\s*\( { yy.lexer.unput('('); yytext = 'url_extract_parameter'; parser.addFunctionLocation(yylloc, yytext); return 'URL_EXTRACT_PARAMETER'; }
|
||||
URL_EXTRACT_PATH\s*\( { yy.lexer.unput('('); yytext = 'url_extrct_path'; parser.addFunctionLocation(yylloc, yytext); return 'URL_EXTRACT_PATH'; }
|
||||
URL_EXTRACT_PORT\s*\( { yy.lexer.unput('('); yytext = 'url_extract_port'; parser.addFunctionLocation(yylloc, yytext); return 'URL_EXTRACT_PORT'; }
|
||||
URL_EXTRACT_PROTOCOL\s*\( { yy.lexer.unput('('); yytext = 'url_extract_protocol'; parser.addFunctionLocation(yylloc, yytext); return 'URL_EXTRACT_PROTOCOL'; }
|
||||
URL_EXTRACT_QUERY\s*\( { yy.lexer.unput('('); yytext = 'url_extract_query'; parser.addFunctionLocation(yylloc, yytext); return 'URL_EXTRACT_QUERY'; }
|
||||
|
||||
|
||||
// Analytical functions
|
||||
COLLECT_LIST\s*\( { yy.lexer.unput('('); yytext = 'collect_list'; parser.addFunctionLocation(yylloc, yytext); return 'COLLECT_LIST'; }
|
||||
COLLECT_SET\s*\( { yy.lexer.unput('('); yytext = 'collect_set'; parser.addFunctionLocation(yylloc, yytext); return 'COLLECT_SET'; }
|
||||
COUNT\s*\( { yy.lexer.unput('('); yytext = 'count'; parser.addFunctionLocation(yylloc, yytext); return 'COUNT'; }
|
||||
HISTOGRAM\s*\( { yy.lexer.unput('('); yytext = 'historgram'; parser.addFunctionLocation(yylloc, yytext); return 'HISTOGRAM'; }
|
||||
MAX\s*\( { yy.lexer.unput('('); yytext = 'max'; parser.addFunctionLocation(yylloc, yytext); return 'MAX'; }
|
||||
MIN\s*\( { yy.lexer.unput('('); yytext = 'min'; parser.addFunctionLocation(yylloc, yytext); return 'MIN'; }
|
||||
SUM\s*\( { yy.lexer.unput('('); yytext = 'sum'; parser.addFunctionLocation(yylloc, yytext); return 'SUM'; }
|
||||
TOPK\s*\( { yy.lexer.unput('('); yytext = 'topk'; parser.addFunctionLocation(yylloc, yytext); return 'TOPK'; }
|
||||
TOPKDISTINCT\s*\( { yy.lexer.unput('('); yytext = 'topkdistinct'; parser.addFunctionLocation(yylloc, yytext); return 'TOPKDISTINCT'; }
|
||||
WindowStart\s*\( { yy.lexer.unput('('); yytext = 'windowstart'; parser.addFunctionLocation(yylloc, yytext); return 'WindowStart'; }
|
||||
WindowEnd\s*\( { yy.lexer.unput('('); yytext = 'windowend'; parser.addFunctionLocation(yylloc, yytext); return 'WindowEnd'; }
|
||||
|
||||
|
||||
[0-9]+ { return 'UNSIGNED_INTEGER'; }
|
||||
[0-9]+(?:[YSL]|BD)? { return 'UNSIGNED_INTEGER'; }
|
||||
[0-9]+E { return 'UNSIGNED_INTEGER_E'; }
|
||||
[A-Za-z0-9_]+ { return 'REGULAR_IDENTIFIER'; }
|
||||
|
||||
|
||||
'&&' { return 'AND'; }
|
||||
'||' { return 'OR'; }
|
||||
|
||||
'=' { return '='; }
|
||||
'<' { return '<'; }
|
||||
'>' { return '>'; }
|
||||
'!=' { return 'COMPARISON_OPERATOR'; }
|
||||
'<=' { return 'COMPARISON_OPERATOR'; }
|
||||
'>=' { return 'COMPARISON_OPERATOR'; }
|
||||
'<>' { return 'COMPARISON_OPERATOR'; }
|
||||
'<=>' { return 'COMPARISON_OPERATOR'; }
|
||||
|
||||
'-' { return '-'; }
|
||||
'*' { return '*'; }
|
||||
'+' { return 'ARITHMETIC_OPERATOR'; }
|
||||
'/' { return 'ARITHMETIC_OPERATOR'; }
|
||||
'%' { return 'ARITHMETIC_OPERATOR'; }
|
||||
'|' { return 'ARITHMETIC_OPERATOR'; }
|
||||
'^' { return 'ARITHMETIC_OPERATOR'; }
|
||||
'&' { return 'ARITHMETIC_OPERATOR'; }
|
||||
|
||||
',' { return ','; }
|
||||
'.' { return '.'; }
|
||||
':' { return ':'; }
|
||||
';' { return ';'; }
|
||||
'~' { return '~'; }
|
||||
'!' { return '!'; }
|
||||
|
||||
'(' { return '('; }
|
||||
')' { return ')'; }
|
||||
'[' { return '['; }
|
||||
']' { return ']'; }
|
||||
|
||||
\$\{[^}]*\} { return 'VARIABLE_REFERENCE'; }
|
||||
|
||||
\` { this.begin('backtickedValue'); return 'BACKTICK'; }
|
||||
<backtickedValue>[^`]+ {
|
||||
if (parser.handleQuotedValueWithCursor(this, yytext, yylloc, '`')) {
|
||||
return 'PARTIAL_VALUE';
|
||||
}
|
||||
return 'VALUE';
|
||||
}
|
||||
<backtickedValue>\` { this.popState(); return 'BACKTICK'; }
|
||||
|
||||
\' { this.begin('singleQuotedValue'); return 'SINGLE_QUOTE'; }
|
||||
<singleQuotedValue>(?:\\\\|\\[']|[^'])+ {
|
||||
if (parser.handleQuotedValueWithCursor(this, yytext, yylloc, '\'')) {
|
||||
return 'PARTIAL_VALUE';
|
||||
}
|
||||
return 'VALUE';
|
||||
}
|
||||
<singleQuotedValue>\' { this.popState(); return 'SINGLE_QUOTE'; }
|
||||
|
||||
\" { this.begin('doubleQuotedValue'); return 'DOUBLE_QUOTE'; }
|
||||
<doubleQuotedValue>(?:\\\\|\\["]|[^"])+ {
|
||||
if (parser.handleQuotedValueWithCursor(this, yytext, yylloc, '"')) {
|
||||
return 'PARTIAL_VALUE';
|
||||
}
|
||||
return 'VALUE';
|
||||
}
|
||||
<doubleQuotedValue>\" { this.popState(); return 'DOUBLE_QUOTE'; }
|
||||
|
||||
<<EOF>> { return 'EOF'; }
|
||||
|
||||
. { /* To prevent console logging of unknown chars */ }
|
||||
<between>. { }
|
||||
<hdfs>. { }
|
||||
<backtickedValue>. { }
|
||||
<singleQuotedValue>. { }
|
||||
<doubleQuotedValue>. { }
|
615
src/jison/sql/flink/sql_create.jison
Normal file
615
src/jison/sql/flink/sql_create.jison
Normal file
@ -0,0 +1,615 @@
|
||||
// Licensed to Cloudera, Inc. under one
|
||||
// or more contributor license agreements. See the NOTICE file
|
||||
// distributed with this work for additional information
|
||||
// regarding copyright ownership. Cloudera, Inc. licenses this file
|
||||
// to you under the Apache License, Version 2.0 (the
|
||||
// "License"); you may not use this file except in compliance
|
||||
// with the License. You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
DataDefinition
|
||||
: CreateStatement
|
||||
;
|
||||
|
||||
DataDefinition_EDIT
|
||||
: CreateStatement_EDIT
|
||||
;
|
||||
|
||||
CreateStatement
|
||||
: DatabaseDefinition
|
||||
| TableDefinition
|
||||
| ViewDefinition
|
||||
| RoleDefinition
|
||||
;
|
||||
|
||||
CreateStatement_EDIT
|
||||
: DatabaseDefinition_EDIT
|
||||
| TableDefinition_EDIT
|
||||
| ViewDefinition_EDIT
|
||||
| 'CREATE' 'CURSOR'
|
||||
{
|
||||
parser.suggestKeywords(['DATABASE', 'ROLE', 'SCHEMA', 'TABLE', 'VIEW']);
|
||||
}
|
||||
;
|
||||
|
||||
DatabaseDefinition
|
||||
: 'CREATE' DatabaseOrSchema OptionalIfNotExists
|
||||
| 'CREATE' DatabaseOrSchema OptionalIfNotExists RegularIdentifier DatabaseDefinitionOptionals
|
||||
{
|
||||
parser.addNewDatabaseLocation(@4, [{ name: $4 }]);
|
||||
}
|
||||
;
|
||||
|
||||
DatabaseDefinition_EDIT
|
||||
: 'CREATE' DatabaseOrSchema OptionalIfNotExists 'CURSOR'
|
||||
{
|
||||
if (!$3) {
|
||||
parser.suggestKeywords(['IF NOT EXISTS']);
|
||||
}
|
||||
}
|
||||
| 'CREATE' DatabaseOrSchema OptionalIfNotExists_EDIT
|
||||
| 'CREATE' DatabaseOrSchema OptionalIfNotExists 'CURSOR' RegularIdentifier
|
||||
{
|
||||
if (!$3) {
|
||||
parser.suggestKeywords(['IF NOT EXISTS']);
|
||||
}
|
||||
parser.addNewDatabaseLocation(@5, [{ name: $5 }]);
|
||||
}
|
||||
| 'CREATE' DatabaseOrSchema OptionalIfNotExists_EDIT RegularIdentifier
|
||||
{
|
||||
parser.addNewDatabaseLocation(@4, [{ name: $4 }]);
|
||||
}
|
||||
| 'CREATE' DatabaseOrSchema OptionalIfNotExists RegularIdentifier DatabaseDefinitionOptionals 'CURSOR'
|
||||
{
|
||||
parser.addNewDatabaseLocation(@4, [{ name: $4 }]);
|
||||
}
|
||||
;
|
||||
|
||||
DatabaseDefinitionOptionals
|
||||
: OptionalComment
|
||||
{
|
||||
if (!$1) {
|
||||
parser.suggestKeywords(['COMMENT']);
|
||||
}
|
||||
}
|
||||
;
|
||||
|
||||
DatabaseDefinitionOptionals_EDIT
|
||||
: OptionalComment_INVALID
|
||||
;
|
||||
|
||||
OptionalComment
|
||||
:
|
||||
| Comment
|
||||
;
|
||||
|
||||
Comment
|
||||
: 'COMMENT' QuotedValue
|
||||
;
|
||||
|
||||
OptionalComment_INVALID
|
||||
: Comment_INVALID
|
||||
;
|
||||
|
||||
Comment_INVALID
|
||||
: 'COMMENT' SINGLE_QUOTE
|
||||
| 'COMMENT' DOUBLE_QUOTE
|
||||
| 'COMMENT' SINGLE_QUOTE VALUE
|
||||
| 'COMMENT' DOUBLE_QUOTE VALUE
|
||||
;
|
||||
|
||||
TableDefinition
|
||||
: 'CREATE' 'TABLE' OptionalIfNotExists TableDefinitionRightPart
|
||||
;
|
||||
|
||||
TableDefinition_EDIT
|
||||
: 'CREATE' 'TABLE' OptionalIfNotExists TableDefinitionRightPart_EDIT
|
||||
| 'CREATE' 'TABLE' OptionalIfNotExists 'CURSOR'
|
||||
{
|
||||
if (!$3) {
|
||||
parser.suggestKeywords(['IF NOT EXISTS']);
|
||||
}
|
||||
}
|
||||
| 'CREATE' 'TABLE' OptionalIfNotExists_EDIT
|
||||
;
|
||||
|
||||
TableDefinitionRightPart
|
||||
: TableIdentifierAndOptionalColumnSpecification OptionalPartitionedBy OptionalAsSelectStatement
|
||||
;
|
||||
|
||||
TableDefinitionRightPart_EDIT
|
||||
: TableIdentifierAndOptionalColumnSpecification_EDIT OptionalPartitionedBy OptionalAsSelectStatement
|
||||
| TableIdentifierAndOptionalColumnSpecification PartitionedBy_EDIT OptionalAsSelectStatement
|
||||
| TableIdentifierAndOptionalColumnSpecification OptionalPartitionedBy OptionalAsSelectStatement_EDIT
|
||||
| TableIdentifierAndOptionalColumnSpecification OptionalPartitionedBy 'CURSOR'
|
||||
{
|
||||
var keywords = [];
|
||||
if (!$1 && !$2) {
|
||||
keywords.push({ value: 'LIKE', weight: 1 });
|
||||
} else {
|
||||
if (!$2) {
|
||||
keywords.push({ value: 'PARTITIONED BY', weight: 12 });
|
||||
}
|
||||
keywords.push({ value: 'AS', weight: 1 });
|
||||
}
|
||||
|
||||
if (keywords.length > 0) {
|
||||
parser.suggestKeywords(keywords);
|
||||
}
|
||||
}
|
||||
;
|
||||
|
||||
TableIdentifierAndOptionalColumnSpecification
|
||||
: SchemaQualifiedIdentifier OptionalColumnSpecificationsOrLike
|
||||
{
|
||||
parser.addNewTableLocation(@1, $1, $2);
|
||||
$$ = $2;
|
||||
}
|
||||
;
|
||||
|
||||
TableIdentifierAndOptionalColumnSpecification_EDIT
|
||||
: SchemaQualifiedIdentifier OptionalColumnSpecificationsOrLike_EDIT
|
||||
| SchemaQualifiedIdentifier_EDIT OptionalColumnSpecificationsOrLike
|
||||
;
|
||||
|
||||
OptionalColumnSpecificationsOrLike
|
||||
:
|
||||
| ParenthesizedColumnSpecificationList
|
||||
| 'LIKE' SchemaQualifiedTableIdentifier -> []
|
||||
;
|
||||
|
||||
OptionalColumnSpecificationsOrLike_EDIT
|
||||
: ParenthesizedColumnSpecificationList_EDIT
|
||||
| 'LIKE' 'CURSOR'
|
||||
{
|
||||
parser.suggestTables();
|
||||
parser.suggestDatabases({ appendDot: true });
|
||||
}
|
||||
| 'LIKE' SchemaQualifiedTableIdentifier_EDIT
|
||||
;
|
||||
|
||||
ParenthesizedColumnSpecificationList
|
||||
: '(' ColumnSpecificationList ')' -> $2
|
||||
;
|
||||
|
||||
ParenthesizedColumnSpecificationList_EDIT
|
||||
: '(' ColumnSpecificationList_EDIT RightParenthesisOrError
|
||||
;
|
||||
|
||||
ColumnSpecificationList
|
||||
: ColumnSpecification -> [$1]
|
||||
| ColumnSpecificationList ',' ColumnSpecification -> $1.concat($3)
|
||||
;
|
||||
|
||||
ColumnSpecificationList_EDIT
|
||||
: ColumnSpecification_EDIT
|
||||
| ColumnSpecification_EDIT ',' ColumnSpecificationList
|
||||
| ColumnSpecificationList ',' ColumnSpecification_EDIT
|
||||
| ColumnSpecificationList ',' ColumnSpecification_EDIT ',' ColumnSpecificationList
|
||||
| ColumnSpecification 'CURSOR'
|
||||
{
|
||||
parser.checkForKeywords($1);
|
||||
}
|
||||
| ColumnSpecification 'CURSOR' ',' ColumnSpecificationList
|
||||
{
|
||||
parser.checkForKeywords($1);
|
||||
}
|
||||
| ColumnSpecificationList ',' ColumnSpecification 'CURSOR'
|
||||
{
|
||||
parser.checkForKeywords($3);
|
||||
}
|
||||
| ColumnSpecificationList ',' ColumnSpecification 'CURSOR' ',' ColumnSpecificationList
|
||||
{
|
||||
parser.checkForKeywords($3);
|
||||
}
|
||||
;
|
||||
|
||||
ColumnSpecification
|
||||
: ColumnIdentifier ColumnDataType OptionalColumnOptions
|
||||
{
|
||||
$$ = $1;
|
||||
$$.type = $2;
|
||||
var keywords = [];
|
||||
if (!$3['comment']) {
|
||||
keywords.push('COMMENT');
|
||||
}
|
||||
if (keywords.length > 0) {
|
||||
$$.suggestKeywords = keywords;
|
||||
}
|
||||
}
|
||||
;
|
||||
|
||||
ColumnSpecification_EDIT
|
||||
: ColumnIdentifier 'CURSOR' OptionalColumnOptions
|
||||
{
|
||||
parser.suggestKeywords(parser.getColumnDataTypeKeywords());
|
||||
}
|
||||
| ColumnIdentifier ColumnDataType_EDIT OptionalColumnOptions
|
||||
| ColumnIdentifier ColumnDataType ColumnOptions_EDIT
|
||||
;
|
||||
|
||||
OptionalColumnOptions
|
||||
: -> {}
|
||||
| ColumnOptions
|
||||
;
|
||||
|
||||
ColumnOptions
|
||||
: ColumnOption
|
||||
{
|
||||
$$ = {};
|
||||
$$[$1] = true;
|
||||
}
|
||||
| ColumnOptions ColumnOption
|
||||
{
|
||||
$1[$2] = true;
|
||||
}
|
||||
;
|
||||
|
||||
ColumnOptions_EDIT
|
||||
: ColumnOption_EDIT
|
||||
| ColumnOption_EDIT ColumnOptions
|
||||
| ColumnOptions ColumnOption_EDIT
|
||||
| ColumnOptions ColumnOption_EDIT ColumnOptions
|
||||
;
|
||||
|
||||
ColumnOption
|
||||
: 'NOT' 'NULL' -> 'null'
|
||||
| 'NULL' -> 'null'
|
||||
| Comment -> 'comment'
|
||||
;
|
||||
|
||||
ColumnOption_EDIT
|
||||
: 'NOT' 'CURSOR'
|
||||
{
|
||||
parser.suggestKeywords(['NULL']);
|
||||
}
|
||||
;
|
||||
|
||||
ColumnDataType
|
||||
: PrimitiveType
|
||||
| ArrayType
|
||||
| MapType
|
||||
| StructType
|
||||
| ArrayType_INVALID
|
||||
| MapType_INVALID
|
||||
| StructType_INVALID
|
||||
;
|
||||
|
||||
ColumnDataType_EDIT
|
||||
: ArrayType_EDIT
|
||||
| MapType_EDIT
|
||||
| StructType_EDIT
|
||||
;
|
||||
|
||||
ArrayType
|
||||
: 'ARRAY' '<' ColumnDataType '>'
|
||||
;
|
||||
|
||||
ArrayType_INVALID
|
||||
: 'ARRAY' '<' '>'
|
||||
;
|
||||
|
||||
ArrayType_EDIT
|
||||
: 'ARRAY' '<' AnyCursor GreaterThanOrError
|
||||
{
|
||||
parser.suggestKeywords(parser.getColumnDataTypeKeywords());
|
||||
}
|
||||
| 'ARRAY' '<' ColumnDataType_EDIT GreaterThanOrError
|
||||
;
|
||||
|
||||
MapType
|
||||
: 'MAP' '<' PrimitiveType ',' ColumnDataType '>'
|
||||
;
|
||||
|
||||
MapType_INVALID
|
||||
: 'MAP' '<' '>'
|
||||
;
|
||||
|
||||
MapType_EDIT
|
||||
: 'MAP' '<' PrimitiveType ',' ColumnDataType_EDIT GreaterThanOrError
|
||||
| 'MAP' '<' AnyCursor GreaterThanOrError
|
||||
{
|
||||
parser.suggestKeywords(parser.getTypeKeywords());
|
||||
}
|
||||
| 'MAP' '<' PrimitiveType ',' AnyCursor GreaterThanOrError
|
||||
{
|
||||
parser.suggestKeywords(parser.getColumnDataTypeKeywords());
|
||||
}
|
||||
| 'MAP' '<' ',' AnyCursor GreaterThanOrError
|
||||
{
|
||||
parser.suggestKeywords(parser.getColumnDataTypeKeywords());
|
||||
}
|
||||
;
|
||||
|
||||
StructType
|
||||
: 'STRUCT' '<' StructDefinitionList '>'
|
||||
;
|
||||
|
||||
StructType_INVALID
|
||||
: 'STRUCT' '<' '>'
|
||||
;
|
||||
|
||||
StructType_EDIT
|
||||
: 'STRUCT' '<' StructDefinitionList_EDIT GreaterThanOrError
|
||||
;
|
||||
|
||||
StructDefinitionList
|
||||
: StructDefinition
|
||||
| StructDefinitionList ',' StructDefinition
|
||||
;
|
||||
|
||||
StructDefinitionList_EDIT
|
||||
: StructDefinition_EDIT
|
||||
| StructDefinition_EDIT Commas
|
||||
| StructDefinition_EDIT Commas StructDefinitionList
|
||||
| StructDefinitionList ',' StructDefinition_EDIT
|
||||
| StructDefinitionList ',' StructDefinition_EDIT Commas StructDefinitionList
|
||||
;
|
||||
|
||||
StructDefinition
|
||||
: RegularOrBacktickedIdentifier ':' ColumnDataType OptionalComment
|
||||
;
|
||||
|
||||
StructDefinition_EDIT
|
||||
: Commas RegularOrBacktickedIdentifier ':' ColumnDataType 'CURSOR'
|
||||
{
|
||||
parser.suggestKeywords(['COMMENT']);
|
||||
}
|
||||
| Commas RegularOrBacktickedIdentifier ':' AnyCursor
|
||||
{
|
||||
parser.suggestKeywords(parser.getColumnDataTypeKeywords());
|
||||
}
|
||||
| Commas RegularOrBacktickedIdentifier ':' ColumnDataType_EDIT
|
||||
| RegularOrBacktickedIdentifier ':' ColumnDataType 'CURSOR'
|
||||
{
|
||||
parser.suggestKeywords(['COMMENT']);
|
||||
}
|
||||
| RegularOrBacktickedIdentifier ':' AnyCursor
|
||||
{
|
||||
parser.suggestKeywords(parser.getColumnDataTypeKeywords());
|
||||
}
|
||||
| RegularOrBacktickedIdentifier ':' ColumnDataType_EDIT
|
||||
;
|
||||
|
||||
ColumnDataTypeList
|
||||
: ColumnDataType
|
||||
| ColumnDataTypeList ',' ColumnDataType
|
||||
;
|
||||
|
||||
ColumnDataTypeList_EDIT
|
||||
: ColumnDataTypeListInner_EDIT
|
||||
| ColumnDataTypeListInner_EDIT Commas
|
||||
| ColumnDataTypeList ',' ColumnDataTypeListInner_EDIT
|
||||
| ColumnDataTypeListInner_EDIT Commas ColumnDataTypeList
|
||||
| ColumnDataTypeList ',' ColumnDataTypeListInner_EDIT Commas ColumnDataTypeList
|
||||
;
|
||||
|
||||
ColumnDataTypeListInner_EDIT
|
||||
: Commas AnyCursor
|
||||
{
|
||||
parser.suggestKeywords(parser.getColumnDataTypeKeywords());
|
||||
}
|
||||
| Commas ColumnDataType_EDIT
|
||||
| AnyCursor
|
||||
{
|
||||
parser.suggestKeywords(parser.getColumnDataTypeKeywords());
|
||||
}
|
||||
| ColumnDataType_EDIT
|
||||
;
|
||||
|
||||
GreaterThanOrError
|
||||
: '>'
|
||||
| error
|
||||
;
|
||||
|
||||
OptionalPartitionedBy
|
||||
:
|
||||
| PartitionedBy
|
||||
;
|
||||
|
||||
PartitionedBy
|
||||
: 'PARTITION' 'BY' RangeClause
|
||||
;
|
||||
|
||||
PartitionedBy_EDIT
|
||||
: 'PARTITION' 'CURSOR'
|
||||
{
|
||||
parser.suggestKeywords(['BY']);
|
||||
}
|
||||
| 'PARTITION' 'BY' 'CURSOR'
|
||||
{
|
||||
parser.suggestKeywords(['RANGE']);
|
||||
}
|
||||
| 'PARTITION' 'BY' RangeClause_EDIT
|
||||
;
|
||||
|
||||
RangeClause
|
||||
: 'RANGE' ParenthesizedColumnList ParenthesizedPartitionValuesList
|
||||
;
|
||||
|
||||
RangeClause_EDIT
|
||||
: 'RANGE' 'CURSOR'
|
||||
| 'RANGE' ParenthesizedColumnList_EDIT
|
||||
| 'RANGE' ParenthesizedColumnList 'CURSOR'
|
||||
| 'RANGE' ParenthesizedColumnList ParenthesizedPartitionValuesList_EDIT
|
||||
| 'RANGE' ParenthesizedColumnList_EDIT ParenthesizedPartitionValuesList
|
||||
;
|
||||
|
||||
ParenthesizedPartitionValuesList
|
||||
: '(' PartitionValueList ')'
|
||||
;
|
||||
|
||||
ParenthesizedPartitionValuesList_EDIT
|
||||
: '(' 'CURSOR' RightParenthesisOrError
|
||||
{
|
||||
parser.suggestKeywords(['PARTITION']);
|
||||
}
|
||||
|'(' PartitionValueList_EDIT RightParenthesisOrError
|
||||
;
|
||||
|
||||
PartitionValueList
|
||||
: PartitionValue
|
||||
| PartitionValueList ',' PartitionValue
|
||||
;
|
||||
|
||||
PartitionValueList_EDIT
|
||||
: PartitionValue_EDIT
|
||||
| PartitionValueList ',' 'CURSOR'
|
||||
{
|
||||
parser.suggestKeywords(['PARTITION']);
|
||||
}
|
||||
| PartitionValueList ',' 'CURSOR' ',' PartitionValueList
|
||||
{
|
||||
parser.suggestKeywords(['PARTITION']);
|
||||
}
|
||||
| PartitionValueList ',' PartitionValue_EDIT
|
||||
| PartitionValueList ',' PartitionValue_EDIT ',' PartitionValueList
|
||||
;
|
||||
|
||||
PartitionValue
|
||||
: 'PARTITION' ValueExpression LessThanOrEqualTo 'VALUES' LessThanOrEqualTo ValueExpression
|
||||
| 'PARTITION' 'VALUES' LessThanOrEqualTo ValueExpression
|
||||
| 'PARTITION' ValueExpression LessThanOrEqualTo 'VALUES'
|
||||
;
|
||||
|
||||
PartitionValue_EDIT
|
||||
: 'PARTITION' 'CURSOR'
|
||||
{
|
||||
parser.suggestKeywords(['VALUE', 'VALUES']);
|
||||
}
|
||||
| 'PARTITION' ValueExpression_EDIT
|
||||
{
|
||||
if ($2.endsWithLessThanOrEqual) {
|
||||
parser.suggestKeywords(['VALUES']);
|
||||
}
|
||||
}
|
||||
| 'PARTITION' ValueExpression 'CURSOR'
|
||||
{
|
||||
parser.suggestKeywords(['<', '<=']);
|
||||
}
|
||||
| 'PARTITION' ValueExpression LessThanOrEqualTo 'CURSOR'
|
||||
{
|
||||
parser.suggestKeywords(['VALUES']);
|
||||
}
|
||||
| 'PARTITION' ValueExpression_EDIT LessThanOrEqualTo 'VALUES'
|
||||
| 'PARTITION' ValueExpression LessThanOrEqualTo 'VALUES' 'CURSOR'
|
||||
{
|
||||
parser.suggestKeywords(['<', '<=']);
|
||||
}
|
||||
| 'PARTITION' ValueExpression LessThanOrEqualTo 'VALUES' LessThanOrEqualTo 'CURSOR'
|
||||
{
|
||||
parser.suggestFunctions();
|
||||
}
|
||||
| 'PARTITION' ValueExpression LessThanOrEqualTo 'VALUES' LessThanOrEqualTo ValueExpression_EDIT
|
||||
| 'PARTITION' 'VALUES' 'CURSOR'
|
||||
{
|
||||
parser.suggestKeywords(['<', '<=']);
|
||||
}
|
||||
| 'PARTITION' 'VALUES' LessThanOrEqualTo 'CURSOR'
|
||||
{
|
||||
parser.suggestFunctions();
|
||||
}
|
||||
| 'PARTITION' 'VALUES' LessThanOrEqualTo ValueExpression_EDIT
|
||||
;
|
||||
|
||||
LessThanOrEqualTo
|
||||
: '<'
|
||||
| 'COMPARISON_OPERATOR' // This is fine for autocompletion
|
||||
;
|
||||
|
||||
OptionalAsSelectStatement
|
||||
:
|
||||
| 'AS' CommitLocations QuerySpecification
|
||||
;
|
||||
|
||||
OptionalAsSelectStatement_EDIT
|
||||
: 'AS' CommitLocations 'CURSOR'
|
||||
{
|
||||
parser.suggestKeywords(['SELECT']);
|
||||
}
|
||||
| 'AS' CommitLocations QuerySpecification_EDIT
|
||||
;
|
||||
|
||||
CommitLocations
|
||||
: /* empty */
|
||||
{
|
||||
parser.commitLocations();
|
||||
}
|
||||
;
|
||||
|
||||
ViewDefinition
|
||||
: 'CREATE' 'VIEW' OptionalIfNotExists SchemaQualifiedIdentifier OptionalParenthesizedViewColumnList OptionalComment 'AS' QuerySpecification
|
||||
;
|
||||
|
||||
ViewDefinition_EDIT
|
||||
: 'CREATE' 'VIEW' OptionalIfNotExists 'CURSOR'
|
||||
{
|
||||
if (!$3) {
|
||||
parser.suggestKeywords(['IF NOT EXISTS']);
|
||||
}
|
||||
parser.suggestDatabases({ appendDot: true });
|
||||
}
|
||||
| 'CREATE' 'VIEW' OptionalIfNotExists 'CURSOR' SchemaQualifiedIdentifier OptionalParenthesizedViewColumnList OptionalComment 'AS' QuerySpecification
|
||||
{
|
||||
if (!$3) {
|
||||
parser.suggestKeywords(['IF NOT EXISTS']);
|
||||
}
|
||||
}
|
||||
| 'CREATE' 'VIEW' OptionalIfNotExists_EDIT
|
||||
| 'CREATE' 'VIEW' OptionalIfNotExists SchemaQualifiedIdentifier ParenthesizedViewColumnList_EDIT OptionalComment
|
||||
| 'CREATE' 'VIEW' OptionalIfNotExists SchemaQualifiedIdentifier OptionalParenthesizedViewColumnList OptionalComment 'CURSOR'
|
||||
{
|
||||
var keywords = [{value: 'AS', weight: 1 }];
|
||||
if (!$6) {
|
||||
keywords.push({ value: 'COMMENT', weight: 3 });
|
||||
}
|
||||
parser.suggestKeywords(keywords);
|
||||
}
|
||||
| 'CREATE' 'VIEW' OptionalIfNotExists SchemaQualifiedIdentifier OptionalParenthesizedViewColumnList OptionalComment 'AS' 'CURSOR'
|
||||
{
|
||||
parser.suggestKeywords(['SELECT']);
|
||||
}
|
||||
| 'CREATE' 'VIEW' OptionalIfNotExists SchemaQualifiedIdentifier OptionalParenthesizedViewColumnList OptionalComment 'AS' QuerySpecification_EDIT
|
||||
| 'CREATE' 'VIEW' OptionalIfNotExists SchemaQualifiedIdentifier_EDIT OptionalParenthesizedViewColumnList OptionalComment 'AS' QuerySpecification
|
||||
;
|
||||
|
||||
OptionalParenthesizedViewColumnList
|
||||
:
|
||||
| ParenthesizedViewColumnList
|
||||
;
|
||||
|
||||
ParenthesizedViewColumnList
|
||||
: '(' ViewColumnList ')'
|
||||
;
|
||||
|
||||
ParenthesizedViewColumnList_EDIT
|
||||
: '(' ViewColumnList_EDIT RightParenthesisOrError
|
||||
{
|
||||
if (!$2) {
|
||||
parser.suggestKeywords(['COMMENT']);
|
||||
}
|
||||
}
|
||||
;
|
||||
|
||||
ViewColumnList
|
||||
: ColumnReference OptionalComment
|
||||
| ViewColumnList ',' ColumnReference OptionalComment
|
||||
;
|
||||
|
||||
ViewColumnList_EDIT
|
||||
: ColumnReference OptionalComment 'CURSOR' -> $2
|
||||
| ColumnReference OptionalComment 'CURSOR' ',' ViewColumnList -> $2
|
||||
| ViewColumnList ',' ColumnReference OptionalComment 'CURSOR' -> $4
|
||||
| ViewColumnList ',' ColumnReference OptionalComment 'CURSOR' ',' ViewColumnList -> $4
|
||||
;
|
||||
|
||||
RoleDefinition
|
||||
: 'CREATE' 'ROLE' RegularIdentifier
|
||||
;
|
184
src/jison/sql/flink/sql_drop.jison
Normal file
184
src/jison/sql/flink/sql_drop.jison
Normal file
@ -0,0 +1,184 @@
|
||||
// Licensed to Cloudera, Inc. under one
|
||||
// or more contributor license agreements. See the NOTICE file
|
||||
// distributed with this work for additional information
|
||||
// regarding copyright ownership. Cloudera, Inc. licenses this file
|
||||
// to you under the Apache License, Version 2.0 (the
|
||||
// "License"); you may not use this file except in compliance
|
||||
// with the License. You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
DataDefinition
|
||||
: DropStatement
|
||||
;
|
||||
|
||||
DataDefinition_EDIT
|
||||
: DropStatement_EDIT
|
||||
;
|
||||
|
||||
DropStatement
|
||||
: DropDatabaseStatement
|
||||
| DropRoleStatement
|
||||
| DropTableStatement
|
||||
| DropViewStatement
|
||||
| TruncateTableStatement
|
||||
;
|
||||
|
||||
DropStatement_EDIT
|
||||
: DropDatabaseStatement_EDIT
|
||||
| DropTableStatement_EDIT
|
||||
| DropViewStatement_EDIT
|
||||
| TruncateTableStatement_EDIT
|
||||
| 'DROP' 'CURSOR'
|
||||
{
|
||||
parser.suggestKeywords(['DATABASE', 'ROLE', 'SCHEMA', 'TABLE', 'VIEW']);
|
||||
}
|
||||
;
|
||||
|
||||
DropDatabaseStatement
|
||||
: 'DROP' DatabaseOrSchema OptionalIfExists RegularOrBacktickedIdentifier OptionalCascade
|
||||
;
|
||||
|
||||
DropDatabaseStatement_EDIT
|
||||
: 'DROP' DatabaseOrSchema OptionalIfExists
|
||||
| 'DROP' DatabaseOrSchema OptionalIfExists_EDIT
|
||||
| 'DROP' DatabaseOrSchema OptionalIfExists 'CURSOR'
|
||||
{
|
||||
if (!$3) {
|
||||
parser.suggestKeywords(['IF EXISTS']);
|
||||
}
|
||||
parser.suggestDatabases();
|
||||
}
|
||||
| 'DROP' DatabaseOrSchema OptionalIfExists RegularOrBacktickedIdentifier 'CURSOR'
|
||||
{
|
||||
parser.suggestKeywords(['CASCADE']);
|
||||
}
|
||||
| 'DROP' DatabaseOrSchema OptionalIfExists_EDIT RegularOrBacktickedIdentifier OptionalCascade
|
||||
| 'DROP' DatabaseOrSchema OptionalIfExists 'CURSOR' RegularOrBacktickedIdentifier OptionalCascade
|
||||
{
|
||||
if (!$3) {
|
||||
parser.suggestKeywords(['IF EXISTS']);
|
||||
}
|
||||
}
|
||||
;
|
||||
DropRoleStatement
|
||||
: 'DROP' 'ROLE' RegularIdentifier
|
||||
;
|
||||
|
||||
DropTableStatement
|
||||
: 'DROP' 'TABLE' OptionalIfExists SchemaQualifiedTableIdentifier OptionalPurge
|
||||
{
|
||||
parser.addTablePrimary($4);
|
||||
}
|
||||
;
|
||||
|
||||
DropTableStatement_EDIT
|
||||
: 'DROP' 'TABLE' OptionalIfExists_EDIT
|
||||
| 'DROP' 'TABLE' OptionalIfExists 'CURSOR'
|
||||
{
|
||||
if (!$3) {
|
||||
parser.suggestKeywords(['IF EXISTS']);
|
||||
}
|
||||
parser.suggestTables({ onlyTables: true });
|
||||
parser.suggestDatabases({
|
||||
appendDot: true
|
||||
});
|
||||
}
|
||||
| 'DROP' 'TABLE' OptionalIfExists SchemaQualifiedTableIdentifier_EDIT OptionalPurge
|
||||
{
|
||||
if (parser.yy.result.suggestTables) {
|
||||
parser.yy.result.suggestTables.onlyTables = true;
|
||||
}
|
||||
}
|
||||
| 'DROP' 'TABLE' OptionalIfExists_EDIT SchemaQualifiedTableIdentifier OptionalPurge
|
||||
| 'DROP' 'TABLE' OptionalIfExists SchemaQualifiedTableIdentifier OptionalPurge 'CURSOR'
|
||||
{
|
||||
parser.addTablePrimary($4);
|
||||
if (!$5) {
|
||||
parser.suggestKeywords(['PURGE']);
|
||||
}
|
||||
}
|
||||
;
|
||||
|
||||
OptionalPurge
|
||||
:
|
||||
| 'PURGE'
|
||||
;
|
||||
|
||||
DropViewStatement
|
||||
: 'DROP' 'VIEW' OptionalIfExists SchemaQualifiedTableIdentifier
|
||||
{
|
||||
parser.addTablePrimary($4);
|
||||
}
|
||||
;
|
||||
|
||||
DropViewStatement_EDIT
|
||||
: 'DROP' 'VIEW' OptionalIfExists 'CURSOR'
|
||||
{
|
||||
if (!$3) {
|
||||
parser.suggestKeywords(['IF EXISTS']);
|
||||
}
|
||||
parser.suggestTables({ onlyViews: true });
|
||||
parser.suggestDatabases({ appendDot: true });
|
||||
}
|
||||
| 'DROP' 'VIEW' OptionalIfExists 'CURSOR' SchemaQualifiedTableIdentifier
|
||||
{
|
||||
parser.addTablePrimary($5);
|
||||
if (!$3) {
|
||||
parser.suggestKeywords(['IF EXISTS']);
|
||||
}
|
||||
}
|
||||
| 'DROP' 'VIEW' OptionalIfExists_EDIT
|
||||
| 'DROP' 'VIEW' OptionalIfExists_EDIT SchemaQualifiedTableIdentifier
|
||||
{
|
||||
parser.addTablePrimary($4);
|
||||
}
|
||||
| 'DROP' 'VIEW' OptionalIfExists SchemaQualifiedTableIdentifier_EDIT
|
||||
{
|
||||
if (parser.yy.result.suggestTables) {
|
||||
parser.yy.result.suggestTables.onlyViews = true;
|
||||
}
|
||||
}
|
||||
;
|
||||
|
||||
TruncateTableStatement
|
||||
: 'TRUNCATE' 'TABLE' OptionalIfExists SchemaQualifiedTableIdentifier
|
||||
{
|
||||
parser.addTablePrimary($4);
|
||||
}
|
||||
;
|
||||
|
||||
TruncateTableStatement_EDIT
|
||||
: 'TRUNCATE' 'CURSOR'
|
||||
{
|
||||
parser.suggestKeywords(['TABLE']);
|
||||
}
|
||||
| 'TRUNCATE' 'TABLE' OptionalIfExists 'CURSOR'
|
||||
{
|
||||
parser.suggestTables();
|
||||
parser.suggestDatabases({ appendDot: true });
|
||||
if (!$3) {
|
||||
parser.suggestKeywords(['IF EXISTS']);
|
||||
}
|
||||
}
|
||||
| 'TRUNCATE' 'TABLE' OptionalIfExists_EDIT
|
||||
| 'TRUNCATE' 'TABLE' OptionalIfExists SchemaQualifiedTableIdentifier_EDIT
|
||||
| 'TRUNCATE' 'TABLE' OptionalIfExists SchemaQualifiedTableIdentifier 'CURSOR'
|
||||
{
|
||||
parser.addTablePrimary($4);
|
||||
}
|
||||
| 'TRUNCATE' 'TABLE' OptionalIfExists 'CURSOR' SchemaQualifiedTableIdentifier
|
||||
{
|
||||
parser.addTablePrimary($4);
|
||||
if (!$3) {
|
||||
parser.suggestKeywords(['IF EXISTS']);
|
||||
}
|
||||
}
|
||||
| 'TRUNCATE' 'TABLE' OptionalIfExists_EDIT SchemaQualifiedTableIdentifier OptionalPartitionSpec
|
||||
;
|
132
src/jison/sql/flink/sql_error.jison
Normal file
132
src/jison/sql/flink/sql_error.jison
Normal file
@ -0,0 +1,132 @@
|
||||
// Licensed to Cloudera, Inc. under one
|
||||
// or more contributor license agreements. See the NOTICE file
|
||||
// distributed with this work for additional information
|
||||
// regarding copyright ownership. Cloudera, Inc. licenses this file
|
||||
// to you under the Apache License, Version 2.0 (the
|
||||
// "License"); you may not use this file except in compliance
|
||||
// with the License. You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
SqlStatements
|
||||
: error
|
||||
| NonStartingToken error // Having just ': error' does not work for some reason, jison bug?
|
||||
;
|
||||
|
||||
SqlStatement_EDIT
|
||||
: AnyCursor error
|
||||
{
|
||||
parser.suggestDdlAndDmlKeywords();
|
||||
}
|
||||
;
|
||||
|
||||
SelectStatement
|
||||
: 'SELECT' OptionalAllOrDistinct SelectList_ERROR TableExpression
|
||||
| 'SELECT' OptionalAllOrDistinct SelectList TableExpression_ERROR
|
||||
;
|
||||
|
||||
SelectStatement_EDIT
|
||||
: 'SELECT' OptionalAllOrDistinct SelectList_ERROR_EDIT TableExpression
|
||||
{
|
||||
parser.selectListNoTableSuggest($3, $2);
|
||||
}
|
||||
| 'SELECT' OptionalAllOrDistinct SelectList_ERROR TableExpression_EDIT
|
||||
;
|
||||
|
||||
SelectList_ERROR
|
||||
: ErrorList
|
||||
| SelectList ',' ErrorList
|
||||
| ErrorList ',' SelectList ',' ErrorList
|
||||
| ErrorList ',' SelectList
|
||||
| SelectList ',' ErrorList ',' SelectList
|
||||
;
|
||||
|
||||
SelectList_ERROR_EDIT
|
||||
: ErrorList ',' SelectList_EDIT -> $3
|
||||
| SelectList ',' ErrorList ',' SelectList_EDIT -> $5
|
||||
| ErrorList ',' SelectList ',' ErrorList ',' SelectList_EDIT -> $7
|
||||
| ErrorList ',' AnyCursor
|
||||
{
|
||||
$$ = { cursorAtStart : false, suggestFunctions: true, suggestColumns: true, suggestAggregateFunctions: true };
|
||||
}
|
||||
| SelectList ',' ErrorList ',' AnyCursor
|
||||
{
|
||||
$$ = { cursorAtStart : false, suggestFunctions: true, suggestColumns: true, suggestAggregateFunctions: true };
|
||||
}
|
||||
| ErrorList ',' SelectList ',' Errors ',' AnyCursor
|
||||
{
|
||||
$$ = { cursorAtStart : true, suggestFunctions: true, suggestColumns: true, suggestAggregateFunctions: true };
|
||||
}
|
||||
;
|
||||
|
||||
SetSpecification
|
||||
: 'SET' SetOption '=' error
|
||||
;
|
||||
|
||||
ErrorList
|
||||
: error
|
||||
| Errors ',' error
|
||||
;
|
||||
|
||||
JoinType_EDIT
|
||||
: 'FULL' 'CURSOR' error
|
||||
{
|
||||
parser.suggestKeywords(['JOIN', 'OUTER JOIN']);
|
||||
}
|
||||
| 'LEFT' 'CURSOR' error
|
||||
{
|
||||
parser.suggestKeywords(['JOIN', 'OUTER JOIN']);
|
||||
}
|
||||
| 'RIGHT' 'CURSOR' error
|
||||
{
|
||||
parser.suggestKeywords(['JOIN', 'OUTER JOIN']);
|
||||
}
|
||||
;
|
||||
|
||||
OptionalSelectConditions_EDIT
|
||||
: WhereClause error 'CURSOR' OptionalGroupByClause OptionalHavingClause OptionalOrderByClause OptionalLimitClause
|
||||
{
|
||||
$$ = {
|
||||
suggestKeywords: parser.getKeywordsForOptionalsLR([$4, $5, $6, $7], [{ value: 'GROUP BY', weight: 8 }, { value: 'HAVING', weight: 7 }, { value: 'ORDER BY', weight: 5 }, { value: 'LIMIT', weight: 3 }], [true, true, true, true]),
|
||||
cursorAtEnd: !$4 && !$5 && !$6 && !$7
|
||||
};
|
||||
}
|
||||
| OptionalWhereClause OptionalGroupByClause HavingClause error 'CURSOR' OptionalOrderByClause OptionalLimitClause
|
||||
{
|
||||
$$ = {
|
||||
suggestKeywords: parser.getKeywordsForOptionalsLR([$6, $7], [{ value: 'ORDER BY', weight: 5 }, { value: 'LIMIT', weight: 3 }], [true, true]),
|
||||
cursorAtEnd: !$6 && !$7
|
||||
}
|
||||
}
|
||||
| OptionalWhereClause OptionalGroupByClause OptionalHavingClause OrderByClause error 'CURSOR' OptionalLimitClause
|
||||
{
|
||||
$$ = {
|
||||
suggestKeywords: parser.getKeywordsForOptionalsLR([$7], [{ value: 'LIMIT', weight: 3 }], [true]),
|
||||
cursorAtEnd: !$7
|
||||
}
|
||||
}
|
||||
| OptionalWhereClause OptionalGroupByClause OptionalHavingClause OptionalOrderByClause LimitClause error 'CURSOR'
|
||||
;
|
||||
|
||||
OptionalSelectConditions_EDIT
|
||||
: WhereClause error GroupByClause_EDIT OptionalHavingClause OptionalOrderByClause OptionalLimitClause
|
||||
| WhereClause error OptionalGroupByClause HavingClause_EDIT OptionalOrderByClause OptionalLimitClause
|
||||
| WhereClause error OptionalGroupByClause OptionalHavingClause OrderByClause_EDIT OptionalLimitClause
|
||||
| WhereClause error OptionalGroupByClause OptionalHavingClause OptionalOrderByClause LimitClause_EDIT
|
||||
| OptionalWhereClause GroupByClause error HavingClause_EDIT OptionalOrderByClause OptionalLimitClause
|
||||
| OptionalWhereClause GroupByClause error OptionalHavingClause OrderByClause_EDIT OptionalLimitClause
|
||||
| OptionalWhereClause GroupByClause error OptionalHavingClause OptionalOrderByClause LimitClause_EDIT
|
||||
| OptionalWhereClause OptionalGroupByClause HavingClause error OrderByClause_EDIT OptionalLimitClause
|
||||
| OptionalWhereClause OptionalGroupByClause HavingClause error OptionalOrderByClause LimitClause_EDIT
|
||||
| OptionalWhereClause OptionalGroupByClause OptionalHavingClause OrderByClause error LimitClause_EDIT
|
||||
;
|
||||
|
||||
DatabaseDefinition_EDIT
|
||||
: 'CREATE' DatabaseOrSchema OptionalIfNotExists RegularIdentifier DatabaseDefinitionOptionals_EDIT error
|
||||
;
|
72
src/jison/sql/flink/sql_insert.jison
Normal file
72
src/jison/sql/flink/sql_insert.jison
Normal file
@ -0,0 +1,72 @@
|
||||
// Licensed to Cloudera, Inc. under one
|
||||
// or more contributor license agreements. See the NOTICE file
|
||||
// distributed with this work for additional information
|
||||
// regarding copyright ownership. Cloudera, Inc. licenses this file
|
||||
// to you under the Apache License, Version 2.0 (the
|
||||
// "License"); you may not use this file except in compliance
|
||||
// with the License. You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
DataManipulation
|
||||
: InsertStatement
|
||||
;
|
||||
|
||||
InsertStatement
|
||||
: InsertValuesStatement
|
||||
;
|
||||
|
||||
DataManipulation_EDIT
|
||||
: InsertValuesStatement_EDIT
|
||||
;
|
||||
|
||||
InsertValuesStatement
|
||||
: 'INSERT' 'INTO' OptionalTable SchemaQualifiedTableIdentifier 'VALUES' InsertValuesList
|
||||
{
|
||||
$4.owner = 'insert';
|
||||
parser.addTablePrimary($4);
|
||||
}
|
||||
;
|
||||
|
||||
InsertValuesStatement_EDIT
|
||||
: 'INSERT' 'CURSOR'
|
||||
{
|
||||
parser.suggestKeywords(['INTO']);
|
||||
}
|
||||
| 'INSERT' 'INTO' OptionalTable 'CURSOR'
|
||||
{
|
||||
if (!$3) {
|
||||
parser.suggestKeywords(['TABLE']);
|
||||
}
|
||||
parser.suggestTables();
|
||||
parser.suggestDatabases({ appendDot: true });
|
||||
}
|
||||
| 'INSERT' 'INTO' OptionalTable SchemaQualifiedTableIdentifier_EDIT
|
||||
| 'INSERT' 'INTO' OptionalTable SchemaQualifiedTableIdentifier 'CURSOR'
|
||||
{
|
||||
$4.owner = 'insert';
|
||||
parser.addTablePrimary($4);
|
||||
parser.suggestKeywords(['VALUES']);
|
||||
}
|
||||
| 'INSERT' 'INTO' OptionalTable SchemaQualifiedTableIdentifier_EDIT 'VALUES' InsertValuesList
|
||||
;
|
||||
|
||||
InsertValuesList
|
||||
: ParenthesizedRowValuesList
|
||||
| RowValuesList ',' ParenthesizedRowValuesList
|
||||
;
|
||||
|
||||
ParenthesizedRowValuesList
|
||||
: '(' InValueList ')'
|
||||
;
|
||||
|
||||
OptionalTable
|
||||
:
|
||||
| 'TABLE'
|
||||
;
|
37
src/jison/sql/flink/sql_list.jison
Normal file
37
src/jison/sql/flink/sql_list.jison
Normal file
@ -0,0 +1,37 @@
|
||||
// Licensed to Cloudera, Inc. under one
|
||||
// or more contributor license agreements. See the NOTICE file
|
||||
// distributed with this work for additional information
|
||||
// regarding copyright ownership. Cloudera, Inc. licenses this file
|
||||
// to you under the Apache License, Version 2.0 (the
|
||||
// "License"); you may not use this file except in compliance
|
||||
// with the License. You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
DataDefinition
|
||||
: 'LIST' ListStatement
|
||||
;
|
||||
|
||||
DataDefinition_EDIT
|
||||
: ListStatement_EDIT
|
||||
;
|
||||
|
||||
ListStatement
|
||||
: 'TABLES'
|
||||
| 'STREAMS'
|
||||
| 'TOPICS'
|
||||
;
|
||||
|
||||
|
||||
ListStatement_EDIT
|
||||
: 'LIST' 'CURSOR'
|
||||
{
|
||||
parser.suggestKeywords(['TABLES', 'STREAMS', 'TOPICS']);
|
||||
}
|
||||
;
|
2762
src/jison/sql/flink/sql_main.jison
Normal file
2762
src/jison/sql/flink/sql_main.jison
Normal file
File diff suppressed because it is too large
Load Diff
46
src/jison/sql/flink/sql_set.jison
Normal file
46
src/jison/sql/flink/sql_set.jison
Normal file
@ -0,0 +1,46 @@
|
||||
// Licensed to Cloudera, Inc. under one
|
||||
// or more contributor license agreements. See the NOTICE file
|
||||
// distributed with this work for additional information
|
||||
// regarding copyright ownership. Cloudera, Inc. licenses this file
|
||||
// to you under the Apache License, Version 2.0 (the
|
||||
// "License"); you may not use this file except in compliance
|
||||
// with the License. You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
DataDefinition
|
||||
: SetSpecification
|
||||
;
|
||||
|
||||
DataDefinition_EDIT
|
||||
: 'SET' 'CURSOR'
|
||||
{
|
||||
parser.suggestSetOptions();
|
||||
}
|
||||
;
|
||||
|
||||
SetSpecification
|
||||
: 'SET' SetOption '=' SetValue
|
||||
| 'SET' 'ALL'
|
||||
;
|
||||
|
||||
SetOption
|
||||
: RegularIdentifier
|
||||
| SetOption '.' RegularIdentifier
|
||||
;
|
||||
|
||||
SetValue
|
||||
: RegularIdentifier
|
||||
| SignedInteger
|
||||
| SignedInteger RegularIdentifier
|
||||
| QuotedValue
|
||||
| 'TRUE'
|
||||
| 'FALSE'
|
||||
| 'NULL'
|
||||
;
|
39
src/jison/sql/flink/sql_show.jison
Normal file
39
src/jison/sql/flink/sql_show.jison
Normal file
@ -0,0 +1,39 @@
|
||||
// Licensed to Cloudera, Inc. under one
|
||||
// or more contributor license agreements. See the NOTICE file
|
||||
// distributed with this work for additional information
|
||||
// regarding copyright ownership. Cloudera, Inc. licenses this file
|
||||
// to you under the Apache License, Version 2.0 (the
|
||||
// "License"); you may not use this file except in compliance
|
||||
// with the License. You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
DataDefinition
|
||||
: 'SHOW' ShowStatement
|
||||
;
|
||||
|
||||
DataDefinition_EDIT
|
||||
: ShowStatement_EDIT
|
||||
;
|
||||
|
||||
ShowStatement
|
||||
: 'TABLES'
|
||||
| 'STREAMS'
|
||||
| 'TOPICS'
|
||||
| 'QUERIES'
|
||||
| 'PROPERTIES'
|
||||
;
|
||||
|
||||
|
||||
ShowStatement_EDIT
|
||||
: 'SHOW' 'CURSOR'
|
||||
{
|
||||
parser.suggestKeywords(['TABLES', 'STREAMS', 'TOPICS', 'QUERIES', 'PROPERTIES']);
|
||||
}
|
||||
;
|
839
src/jison/sql/flink/sql_valueExpression.jison
Normal file
839
src/jison/sql/flink/sql_valueExpression.jison
Normal file
@ -0,0 +1,839 @@
|
||||
// Licensed to Cloudera, Inc. under one
|
||||
// or more contributor license agreements. See the NOTICE file
|
||||
// distributed with this work for additional information
|
||||
// regarding copyright ownership. Cloudera, Inc. licenses this file
|
||||
// to you under the Apache License, Version 2.0 (the
|
||||
// "License"); you may not use this file except in compliance
|
||||
// with the License. You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
ValueExpression
|
||||
: 'NOT' ValueExpression
|
||||
{
|
||||
// verifyType($2, 'BOOLEAN');
|
||||
$$ = { types: [ 'BOOLEAN' ] };
|
||||
}
|
||||
| '!' ValueExpression
|
||||
{
|
||||
// verifyType($2, 'BOOLEAN');
|
||||
$$ = { types: [ 'BOOLEAN' ] };
|
||||
}
|
||||
| '~' ValueExpression -> $2
|
||||
| '-' ValueExpression %prec NEGATION
|
||||
{
|
||||
// verifyType($2, 'NUMBER');
|
||||
$$ = $2;
|
||||
$2.types = ['NUMBER'];
|
||||
}
|
||||
| ValueExpression 'IS' OptionalNot 'NULL' -> { types: [ 'BOOLEAN' ] }
|
||||
| ValueExpression 'IS' OptionalNot 'TRUE' -> { types: [ 'BOOLEAN' ] }
|
||||
| ValueExpression 'IS' OptionalNot 'FALSE' -> { types: [ 'BOOLEAN' ] }
|
||||
| ValueExpression 'IS' OptionalNot 'DISTINCT' 'FROM' ValueExpression -> { types: [ 'BOOLEAN' ] }
|
||||
;
|
||||
|
||||
ValueExpression_EDIT
|
||||
: 'NOT' ValueExpression_EDIT -> { types: [ 'BOOLEAN' ], suggestFilters: $2.suggestFilters }
|
||||
| 'NOT' 'CURSOR'
|
||||
{
|
||||
parser.suggestFunctions();
|
||||
parser.suggestColumns();
|
||||
parser.suggestKeywords(['EXISTS']);
|
||||
$$ = { types: [ 'BOOLEAN' ] };
|
||||
}
|
||||
| '!' ValueExpression_EDIT -> { types: [ 'BOOLEAN' ], suggestFilters: $2.suggestFilters }
|
||||
| '!' AnyCursor
|
||||
{
|
||||
parser.suggestFunctions({ types: [ 'BOOLEAN' ] });
|
||||
parser.suggestColumns({ types: [ 'BOOLEAN' ] });
|
||||
$$ = { types: [ 'BOOLEAN' ] };
|
||||
}
|
||||
| '~' ValueExpression_EDIT -> { types: [ 'T' ], suggestFilters: $2.suggestFilters }
|
||||
| '~' 'PARTIAL_CURSOR'
|
||||
{
|
||||
parser.suggestFunctions();
|
||||
parser.suggestColumns();
|
||||
$$ = { types: [ 'T' ] };
|
||||
}
|
||||
| '-' ValueExpression_EDIT %prec NEGATION
|
||||
{
|
||||
if (!$2.typeSet) {
|
||||
parser.applyTypeToSuggestions('NUMBER');
|
||||
}
|
||||
$$ = { types: [ 'NUMBER' ], suggestFilters: $2.suggestFilters };
|
||||
}
|
||||
| '-' 'PARTIAL_CURSOR' %prec NEGATION
|
||||
{
|
||||
parser.suggestFunctions({ types: [ 'NUMBER' ] });
|
||||
parser.suggestColumns({ types: [ 'NUMBER' ] });
|
||||
$$ = { types: [ 'NUMBER' ] };
|
||||
}
|
||||
| ValueExpression 'IS' 'CURSOR'
|
||||
{
|
||||
parser.suggestKeywords(['FALSE', 'NOT NULL', 'NOT TRUE', 'NOT FALSE', 'NULL', 'TRUE']);
|
||||
$$ = { types: [ 'BOOLEAN' ] };
|
||||
}
|
||||
| ValueExpression 'IS' 'NOT' 'CURSOR'
|
||||
{
|
||||
parser.suggestKeywords(['FALSE', 'NULL', 'TRUE']);
|
||||
$$ = { types: [ 'BOOLEAN' ] };
|
||||
}
|
||||
| ValueExpression 'IS' OptionalNot 'DISTINCT' 'CURSOR'
|
||||
{
|
||||
$$ = { types: [ 'BOOLEAN' ] };
|
||||
}
|
||||
| ValueExpression 'IS' 'CURSOR' 'NULL'
|
||||
{
|
||||
parser.suggestKeywords(['NOT']);
|
||||
$$ = { types: [ 'BOOLEAN' ] };
|
||||
}
|
||||
| ValueExpression 'IS' 'CURSOR' 'FALSE'
|
||||
{
|
||||
parser.suggestKeywords(['NOT']);
|
||||
$$ = { types: [ 'BOOLEAN' ] };
|
||||
}
|
||||
| ValueExpression 'IS' 'CURSOR' 'TRUE'
|
||||
{
|
||||
parser.suggestKeywords(['NOT']);
|
||||
$$ = { types: [ 'BOOLEAN' ] };
|
||||
}
|
||||
| ValueExpression 'IS' OptionalNot 'DISTINCT' 'FROM' PartialBacktickedOrAnyCursor
|
||||
{
|
||||
parser.valueExpressionSuggest($1, $3 ? 'IS NOT DISTINCT FROM' : 'IS DISTINCT FROM');
|
||||
$$ = { types: [ 'BOOLEAN' ] };
|
||||
}
|
||||
| ValueExpression 'IS' OptionalNot 'DISTINCT' 'FROM' ValueExpression_EDIT
|
||||
{
|
||||
$$ = { types: [ 'BOOLEAN' ], suggestFilters: $6.suggestFilters }
|
||||
}
|
||||
;
|
||||
|
||||
// ------------------ EXISTS and parenthesized ------------------
|
||||
ValueExpression
|
||||
: 'EXISTS' TableSubQuery
|
||||
{
|
||||
$$ = { types: [ 'BOOLEAN' ] };
|
||||
// clear correlated flag after completed sub-query (set by lexer)
|
||||
parser.yy.correlatedSubQuery = false;
|
||||
}
|
||||
| '(' ValueExpression ')' -> $2
|
||||
;
|
||||
|
||||
ValueExpression_EDIT
|
||||
: 'EXISTS' TableSubQuery_EDIT -> { types: [ 'BOOLEAN' ] }
|
||||
| '(' ValueExpression_EDIT RightParenthesisOrError
|
||||
{
|
||||
$$ = $2;
|
||||
}
|
||||
| '(' 'CURSOR' RightParenthesisOrError
|
||||
{
|
||||
parser.valueExpressionSuggest();
|
||||
$$ = { types: ['T'], typeSet: true };
|
||||
}
|
||||
;
|
||||
|
||||
// ------------------ COMPARISON ------------------
|
||||
|
||||
ValueExpression
|
||||
: ValueExpression '=' ValueExpression
|
||||
{
|
||||
parser.addColRefToVariableIfExists($1, $3);
|
||||
$$ = { types: [ 'BOOLEAN' ] };
|
||||
}
|
||||
| ValueExpression '<' ValueExpression
|
||||
{
|
||||
parser.addColRefToVariableIfExists($1, $3);
|
||||
$$ = { types: [ 'BOOLEAN' ] };
|
||||
}
|
||||
| ValueExpression '>' ValueExpression
|
||||
{
|
||||
parser.addColRefToVariableIfExists($1, $3);
|
||||
$$ = { types: [ 'BOOLEAN' ] };
|
||||
}
|
||||
| ValueExpression 'COMPARISON_OPERATOR' ValueExpression
|
||||
{
|
||||
parser.addColRefToVariableIfExists($1, $3);
|
||||
$$ = { types: [ 'BOOLEAN' ] };
|
||||
}
|
||||
;
|
||||
|
||||
ValueExpression_EDIT
|
||||
: 'CURSOR' '=' ValueExpression
|
||||
{
|
||||
parser.valueExpressionSuggest($3, $2);
|
||||
parser.applyTypeToSuggestions($3.types);
|
||||
$$ = { types: [ 'BOOLEAN' ], typeSet: true };
|
||||
}
|
||||
| 'CURSOR' '<' ValueExpression
|
||||
{
|
||||
parser.valueExpressionSuggest($3, $2);
|
||||
parser.applyTypeToSuggestions($3.types);
|
||||
$$ = { types: [ 'BOOLEAN' ], typeSet: true };
|
||||
}
|
||||
| 'CURSOR' '>' ValueExpression
|
||||
{
|
||||
parser.valueExpressionSuggest($3, $2);
|
||||
parser.applyTypeToSuggestions($3.types);
|
||||
$$ = { types: [ 'BOOLEAN' ], typeSet: true };
|
||||
}
|
||||
| 'CURSOR' 'COMPARISON_OPERATOR' ValueExpression
|
||||
{
|
||||
parser.valueExpressionSuggest($3, $2);
|
||||
parser.applyTypeToSuggestions($3.types);
|
||||
$$ = { types: [ 'BOOLEAN' ], typeSet: true };
|
||||
}
|
||||
| ValueExpression_EDIT '=' ValueExpression
|
||||
{
|
||||
if (!$1.typeSet) {
|
||||
parser.applyTypeToSuggestions($3.types);
|
||||
parser.addColRefIfExists($3);
|
||||
}
|
||||
$$ = { types: [ 'BOOLEAN' ], suggestFilters: $1.suggestFilters }
|
||||
}
|
||||
| ValueExpression_EDIT '<' ValueExpression
|
||||
{
|
||||
if (!$1.typeSet) {
|
||||
parser.applyTypeToSuggestions($3.types);
|
||||
parser.addColRefIfExists($3);
|
||||
}
|
||||
$$ = { types: [ 'BOOLEAN' ], suggestFilters: $1.suggestFilters }
|
||||
}
|
||||
| ValueExpression_EDIT '>' ValueExpression
|
||||
{
|
||||
if (!$1.typeSet) {
|
||||
parser.applyTypeToSuggestions($3.types);
|
||||
parser.addColRefIfExists($3);
|
||||
}
|
||||
$$ = { types: [ 'BOOLEAN' ], suggestFilters: $1.suggestFilters }
|
||||
}
|
||||
| ValueExpression_EDIT 'COMPARISON_OPERATOR' ValueExpression
|
||||
{
|
||||
if (!$1.typeSet) {
|
||||
parser.applyTypeToSuggestions($3.types);
|
||||
parser.addColRefIfExists($3);
|
||||
}
|
||||
$$ = { types: [ 'BOOLEAN' ], suggestFilters: $1.suggestFilters }
|
||||
}
|
||||
| ValueExpression '=' PartialBacktickedOrAnyCursor
|
||||
{
|
||||
parser.valueExpressionSuggest($1, $2);
|
||||
parser.applyTypeToSuggestions($1.types);
|
||||
$$ = { types: [ 'BOOLEAN' ], typeSet: true };
|
||||
}
|
||||
| ValueExpression '<' PartialBacktickedOrAnyCursor
|
||||
{
|
||||
parser.valueExpressionSuggest($1, $2);
|
||||
parser.applyTypeToSuggestions($1.types);
|
||||
$$ = { types: [ 'BOOLEAN' ] , typeSet: true, endsWithLessThanOrEqual: true };
|
||||
}
|
||||
| ValueExpression '>' PartialBacktickedOrAnyCursor
|
||||
{
|
||||
parser.valueExpressionSuggest($1, $2);
|
||||
parser.applyTypeToSuggestions($1.types);
|
||||
$$ = { types: [ 'BOOLEAN' ], typeSet: true };
|
||||
}
|
||||
| ValueExpression 'COMPARISON_OPERATOR' PartialBacktickedOrAnyCursor
|
||||
{
|
||||
parser.valueExpressionSuggest($1, $2);
|
||||
parser.applyTypeToSuggestions($1.types);
|
||||
$$ = { types: [ 'BOOLEAN' ], typeSet: true, endsWithLessThanOrEqual: $2 === '<=' };
|
||||
}
|
||||
| ValueExpression '=' ValueExpression_EDIT
|
||||
{
|
||||
if (!$3.typeSet) {
|
||||
parser.applyTypeToSuggestions($1.types);
|
||||
parser.addColRefIfExists($1);
|
||||
}
|
||||
$$ = { types: [ 'BOOLEAN' ], suggestFilters: $3.suggestFilters }
|
||||
}
|
||||
| ValueExpression '<' ValueExpression_EDIT
|
||||
{
|
||||
if (!$3.typeSet) {
|
||||
parser.applyTypeToSuggestions($1.types);
|
||||
parser.addColRefIfExists($1);
|
||||
}
|
||||
$$ = { types: [ 'BOOLEAN' ], suggestFilters: $3.suggestFilters }
|
||||
}
|
||||
| ValueExpression '>' ValueExpression_EDIT
|
||||
{
|
||||
if (!$3.typeSet) {
|
||||
parser.applyTypeToSuggestions($1.types);
|
||||
parser.addColRefIfExists($1);
|
||||
}
|
||||
$$ = { types: [ 'BOOLEAN' ], suggestFilters: $3.suggestFilters }
|
||||
}
|
||||
| ValueExpression 'COMPARISON_OPERATOR' ValueExpression_EDIT
|
||||
{
|
||||
if (!$3.typeSet) {
|
||||
parser.applyTypeToSuggestions($1.types);
|
||||
parser.addColRefIfExists($1);
|
||||
}
|
||||
$$ = { types: [ 'BOOLEAN' ], suggestFilters: $3.suggestFilters }
|
||||
}
|
||||
;
|
||||
|
||||
|
||||
// ------------------ IN ------------------
|
||||
|
||||
ValueExpression
|
||||
: ValueExpression 'NOT' 'IN' '(' TableSubQueryInner ')' -> { types: [ 'BOOLEAN' ] }
|
||||
| ValueExpression 'NOT' 'IN' '(' ValueExpressionList ')' -> { types: [ 'BOOLEAN' ] }
|
||||
| ValueExpression 'IN' '(' TableSubQueryInner ')' -> { types: [ 'BOOLEAN' ] }
|
||||
| ValueExpression 'IN' '(' ValueExpressionList ')' -> { types: [ 'BOOLEAN' ] }
|
||||
;
|
||||
|
||||
ValueExpression_EDIT
|
||||
: ValueExpression 'NOT' 'IN' ValueExpressionInSecondPart_EDIT
|
||||
{
|
||||
if ($4.inValueEdit) {
|
||||
parser.valueExpressionSuggest($1, $2 + ' ' + $3);
|
||||
parser.applyTypeToSuggestions($1.types);
|
||||
}
|
||||
if ($4.cursorAtStart) {
|
||||
parser.suggestKeywords(['SELECT']);
|
||||
}
|
||||
$$ = { types: [ 'BOOLEAN' ], typeSet: true };
|
||||
}
|
||||
| ValueExpression 'IN' ValueExpressionInSecondPart_EDIT
|
||||
{
|
||||
if ($3.inValueEdit) {
|
||||
parser.valueExpressionSuggest($1, $2);
|
||||
parser.applyTypeToSuggestions($1.types);
|
||||
}
|
||||
if ($3.cursorAtStart) {
|
||||
parser.suggestKeywords(['SELECT']);
|
||||
}
|
||||
$$ = { types: [ 'BOOLEAN' ], typeSet: true };
|
||||
}
|
||||
| ValueExpression_EDIT 'NOT' 'IN' '(' ValueExpressionList RightParenthesisOrError -> { types: [ 'BOOLEAN' ], suggestFilters: $1.suggestFilters }
|
||||
| ValueExpression_EDIT 'NOT' 'IN' '(' TableSubQueryInner RightParenthesisOrError -> { types: [ 'BOOLEAN' ], suggestFilters: $1.suggestFilters }
|
||||
| ValueExpression_EDIT 'IN' '(' ValueExpressionList RightParenthesisOrError -> { types: [ 'BOOLEAN' ], suggestFilters: $1.suggestFilters }
|
||||
| ValueExpression_EDIT 'IN' '(' TableSubQueryInner RightParenthesisOrError -> { types: [ 'BOOLEAN' ], suggestFilters: $1.suggestFilters }
|
||||
;
|
||||
|
||||
ValueExpressionInSecondPart_EDIT
|
||||
: '(' TableSubQueryInner_EDIT RightParenthesisOrError
|
||||
| '(' ValueExpressionList_EDIT RightParenthesisOrError -> { inValueEdit: true }
|
||||
| '(' AnyCursor RightParenthesisOrError -> { inValueEdit: true, cursorAtStart: true }
|
||||
;
|
||||
|
||||
// ------------------ BETWEEN ------------------
|
||||
|
||||
ValueExpression
|
||||
: ValueExpression 'NOT' 'BETWEEN' ValueExpression 'BETWEEN_AND' ValueExpression -> { types: [ 'BOOLEAN' ] }
|
||||
| ValueExpression 'BETWEEN' ValueExpression 'BETWEEN_AND' ValueExpression -> { types: [ 'BOOLEAN' ] }
|
||||
;
|
||||
|
||||
ValueExpression_EDIT
|
||||
: ValueExpression_EDIT 'NOT' 'BETWEEN' ValueExpression 'BETWEEN_AND' ValueExpression
|
||||
{
|
||||
if ($4.types[0] === $6.types[0] && !$1.typeSet) {
|
||||
parser.applyTypeToSuggestions($4.types);
|
||||
}
|
||||
$$ = { types: [ 'BOOLEAN' ], suggestFilters: $1.suggestFilters };
|
||||
}
|
||||
| ValueExpression 'NOT' 'BETWEEN' ValueExpression_EDIT 'BETWEEN_AND' ValueExpression
|
||||
{
|
||||
if ($1.types[0] === $6.types[0] && !$4.typeSet) {
|
||||
parser.applyTypeToSuggestions($1.types);
|
||||
}
|
||||
$$ = { types: [ 'BOOLEAN' ], suggestFilters: $4.suggestFilters };
|
||||
}
|
||||
| ValueExpression 'NOT' 'BETWEEN' ValueExpression 'BETWEEN_AND' ValueExpression_EDIT
|
||||
{
|
||||
if ($1.types[0] === $4.types[0] && !$6.typeSet) {
|
||||
parser.applyTypeToSuggestions($1.types);
|
||||
}
|
||||
$$ = { types: [ 'BOOLEAN' ], suggestFilters: $6.suggestFilters };
|
||||
}
|
||||
| ValueExpression 'NOT' 'BETWEEN' ValueExpression 'BETWEEN_AND' 'CURSOR'
|
||||
{
|
||||
parser.valueExpressionSuggest($1, $5);
|
||||
$$ = { types: [ 'BOOLEAN' ], typeSet: true };
|
||||
}
|
||||
| ValueExpression 'NOT' 'BETWEEN' ValueExpression 'CURSOR'
|
||||
{
|
||||
parser.suggestValueExpressionKeywords($4, ['AND']);
|
||||
$$ = { types: [ 'BOOLEAN' ] };
|
||||
}
|
||||
| ValueExpression 'NOT' 'BETWEEN' 'CURSOR'
|
||||
{
|
||||
parser.valueExpressionSuggest($1, $2 + ' ' + $3);
|
||||
$$ = { types: [ 'BOOLEAN' ], typeSet: true };
|
||||
}
|
||||
| ValueExpression_EDIT 'BETWEEN' ValueExpression 'BETWEEN_AND' ValueExpression
|
||||
{
|
||||
if ($1.types[0] === $3.types[0] && !$1.typeSet) {
|
||||
parser.applyTypeToSuggestions($1.types)
|
||||
}
|
||||
$$ = { types: [ 'BOOLEAN' ], suggestFilters: $1.suggestFilters };
|
||||
}
|
||||
| ValueExpression 'BETWEEN' ValueExpression_EDIT 'BETWEEN_AND' ValueExpression
|
||||
{
|
||||
if ($1.types[0] === $3.types[0] && !$3.typeSet) {
|
||||
parser.applyTypeToSuggestions($1.types)
|
||||
}
|
||||
$$ = { types: [ 'BOOLEAN' ], suggestFilters: $3.suggestFilters };
|
||||
}
|
||||
| ValueExpression 'BETWEEN' ValueExpression 'BETWEEN_AND' ValueExpression_EDIT
|
||||
{
|
||||
if ($1.types[0] === $3.types[0] && !$5.typeSet) {
|
||||
parser.applyTypeToSuggestions($1.types)
|
||||
}
|
||||
$$ = { types: [ 'BOOLEAN' ], suggestFilters: $5.suggestFilters };
|
||||
}
|
||||
| ValueExpression 'BETWEEN' ValueExpression 'BETWEEN_AND' 'CURSOR'
|
||||
{
|
||||
parser.valueExpressionSuggest($1, $4);
|
||||
parser.applyTypeToSuggestions($1.types);
|
||||
$$ = { types: [ 'BOOLEAN' ], typeSet: true };
|
||||
}
|
||||
| ValueExpression 'BETWEEN' ValueExpression 'CURSOR'
|
||||
{
|
||||
parser.suggestValueExpressionKeywords($3, ['AND']);
|
||||
$$ = { types: [ 'BOOLEAN' ] };
|
||||
}
|
||||
| ValueExpression 'BETWEEN' 'CURSOR'
|
||||
{
|
||||
parser.valueExpressionSuggest($1, $2);
|
||||
parser.applyTypeToSuggestions($1.types);
|
||||
$$ = { types: [ 'BOOLEAN' ], typeSet: true };
|
||||
}
|
||||
;
|
||||
|
||||
// ------------------ BOOLEAN ------------------
|
||||
|
||||
ValueExpression
|
||||
: ValueExpression 'OR' ValueExpression
|
||||
{
|
||||
// verifyType($1, 'BOOLEAN');
|
||||
// verifyType($3, 'BOOLEAN');
|
||||
$$ = { types: [ 'BOOLEAN' ] };
|
||||
}
|
||||
| ValueExpression 'AND' ValueExpression
|
||||
{
|
||||
// verifyType($1, 'BOOLEAN');
|
||||
// verifyType($3, 'BOOLEAN');
|
||||
$$ = { types: [ 'BOOLEAN' ] };
|
||||
}
|
||||
;
|
||||
|
||||
ValueExpression_EDIT
|
||||
: 'CURSOR' 'OR' ValueExpression
|
||||
{
|
||||
parser.valueExpressionSuggest(undefined, $2);
|
||||
$$ = { types: [ 'BOOLEAN' ], typeSet: true, suggestFilters: true };
|
||||
}
|
||||
| ValueExpression_EDIT 'OR' ValueExpression
|
||||
{
|
||||
parser.addColRefIfExists($3);
|
||||
$$ = { types: [ 'BOOLEAN' ], suggestFilters: $1.suggestFilters }
|
||||
}
|
||||
| ValueExpression 'OR' PartialBacktickedOrAnyCursor
|
||||
{
|
||||
parser.valueExpressionSuggest(undefined, $2);
|
||||
$$ = { types: [ 'BOOLEAN' ], typeSet: true, suggestFilters: true };
|
||||
}
|
||||
| ValueExpression 'OR' ValueExpression_EDIT
|
||||
{
|
||||
parser.addColRefIfExists($1);
|
||||
$$ = { types: [ 'BOOLEAN' ], suggestFilters: $3.suggestFilters }
|
||||
}
|
||||
| 'CURSOR' 'AND' ValueExpression
|
||||
{
|
||||
parser.valueExpressionSuggest(undefined, $2);
|
||||
$$ = { types: [ 'BOOLEAN' ], typeSet: true, suggestFilters: true };
|
||||
}
|
||||
| ValueExpression_EDIT 'AND' ValueExpression
|
||||
{
|
||||
parser.addColRefIfExists($3);
|
||||
$$ = { types: [ 'BOOLEAN' ], suggestFilters: $1.suggestFilters }
|
||||
}
|
||||
| ValueExpression 'AND' PartialBacktickedOrAnyCursor
|
||||
{
|
||||
parser.valueExpressionSuggest(undefined, $2);
|
||||
$$ = { types: [ 'BOOLEAN' ], typeSet: true, suggestFilters: true };
|
||||
}
|
||||
| ValueExpression 'AND' ValueExpression_EDIT
|
||||
{
|
||||
parser.addColRefIfExists($1);
|
||||
$$ = { types: [ 'BOOLEAN' ], suggestFilters: $3.suggestFilters }
|
||||
}
|
||||
;
|
||||
|
||||
// ------------------ ARITHMETIC ------------------
|
||||
|
||||
ValueExpression
|
||||
: ValueExpression '-' ValueExpression
|
||||
{
|
||||
// verifyType($1, 'NUMBER');
|
||||
// verifyType($3, 'NUMBER');
|
||||
$$ = { types: [ 'NUMBER' ] };
|
||||
}
|
||||
| ValueExpression '*' ValueExpression
|
||||
{
|
||||
// verifyType($1, 'NUMBER');
|
||||
// verifyType($3, 'NUMBER');
|
||||
$$ = { types: [ 'NUMBER' ] };
|
||||
}
|
||||
| ValueExpression 'ARITHMETIC_OPERATOR' ValueExpression
|
||||
{
|
||||
// verifyType($1, 'NUMBER');
|
||||
// verifyType($3, 'NUMBER');
|
||||
$$ = { types: [ 'NUMBER' ] };
|
||||
}
|
||||
;
|
||||
|
||||
ValueExpression_EDIT
|
||||
: 'CURSOR' '*' ValueExpression
|
||||
{
|
||||
parser.valueExpressionSuggest(undefined, $2);
|
||||
parser.applyTypeToSuggestions([ 'NUMBER' ]);
|
||||
$$ = { types: [ 'NUMBER' ], typeSet: true };
|
||||
}
|
||||
| 'CURSOR' 'ARITHMETIC_OPERATOR' ValueExpression
|
||||
{
|
||||
parser.valueExpressionSuggest(undefined, $2);
|
||||
parser.applyTypeToSuggestions([ 'NUMBER' ]);
|
||||
$$ = { types: [ 'NUMBER' ], typeSet: true };
|
||||
}
|
||||
| ValueExpression_EDIT '-' ValueExpression
|
||||
{
|
||||
if (!$1.typeSet) {
|
||||
parser.applyTypeToSuggestions(['NUMBER']);
|
||||
parser.addColRefIfExists($3);
|
||||
}
|
||||
$$ = { types: [ 'NUMBER' ], suggestFilters: $1.suggestFilters }
|
||||
}
|
||||
| ValueExpression_EDIT '*' ValueExpression
|
||||
{
|
||||
if (!$1.typeSet) {
|
||||
parser.applyTypeToSuggestions(['NUMBER']);
|
||||
parser.addColRefIfExists($3);
|
||||
}
|
||||
$$ = { types: [ 'NUMBER' ], suggestFilters: $1.suggestFilters }
|
||||
}
|
||||
| ValueExpression_EDIT 'ARITHMETIC_OPERATOR' ValueExpression
|
||||
{
|
||||
if (!$1.typeSet) {
|
||||
parser.applyTypeToSuggestions(['NUMBER']);
|
||||
parser.addColRefIfExists($3);
|
||||
}
|
||||
$$ = { types: [ 'NUMBER' ], suggestFilters: $1.suggestFilters }
|
||||
}
|
||||
| ValueExpression '-' PartialBacktickedOrAnyCursor
|
||||
{
|
||||
parser.valueExpressionSuggest(undefined, $2);
|
||||
parser.applyTypeToSuggestions(['NUMBER']);
|
||||
$$ = { types: [ 'NUMBER' ], typeSet: true };
|
||||
}
|
||||
| ValueExpression '*' PartialBacktickedOrAnyCursor
|
||||
{
|
||||
parser.valueExpressionSuggest(undefined, $2);
|
||||
parser.applyTypeToSuggestions(['NUMBER']);
|
||||
$$ = { types: [ 'NUMBER' ], typeSet: true };
|
||||
}
|
||||
| ValueExpression 'ARITHMETIC_OPERATOR' PartialBacktickedOrAnyCursor
|
||||
{
|
||||
parser.valueExpressionSuggest(undefined, $2);
|
||||
parser.applyTypeToSuggestions(['NUMBER']);
|
||||
$$ = { types: [ 'NUMBER' ], typeSet: true };
|
||||
}
|
||||
| ValueExpression '-' ValueExpression_EDIT
|
||||
{
|
||||
if (!$3.typeSet) {
|
||||
parser.applyTypeToSuggestions(['NUMBER']);
|
||||
parser.addColRefIfExists($1);
|
||||
}
|
||||
$$ = { types: [ 'NUMBER' ], suggestFilters: $3.suggestFilters };
|
||||
}
|
||||
| ValueExpression '*' ValueExpression_EDIT
|
||||
{
|
||||
if (!$3.typeSet) {
|
||||
parser.applyTypeToSuggestions(['NUMBER']);
|
||||
parser.addColRefIfExists($1);
|
||||
}
|
||||
$$ = { types: [ 'NUMBER' ], suggestFilters: $3.suggestFilters };
|
||||
}
|
||||
| ValueExpression 'ARITHMETIC_OPERATOR' ValueExpression_EDIT
|
||||
{
|
||||
if (!$3.typeSet) {
|
||||
parser.applyTypeToSuggestions(['NUMBER']);
|
||||
parser.addColRefIfExists($1);
|
||||
}
|
||||
$$ = { types: [ 'NUMBER' ], suggestFilters: $3.suggestFilters };
|
||||
}
|
||||
;
|
||||
|
||||
// ------------------ LIKE, RLIKE and REGEXP ------------------
|
||||
|
||||
ValueExpression
|
||||
: ValueExpression LikeRightPart -> { types: [ 'BOOLEAN' ] }
|
||||
| ValueExpression 'NOT' LikeRightPart -> { types: [ 'BOOLEAN' ] }
|
||||
;
|
||||
|
||||
LikeRightPart
|
||||
: 'LIKE' ValueExpression -> { suggestKeywords: ['NOT'] }
|
||||
| 'RLIKE' ValueExpression -> { suggestKeywords: ['NOT'] }
|
||||
| 'REGEXP' ValueExpression -> { suggestKeywords: ['NOT'] }
|
||||
;
|
||||
|
||||
LikeRightPart_EDIT
|
||||
: 'LIKE' ValueExpression_EDIT
|
||||
| 'RLIKE' ValueExpression_EDIT
|
||||
| 'REGEXP' ValueExpression_EDIT
|
||||
| 'LIKE' PartialBacktickedOrCursor
|
||||
{
|
||||
parser.suggestFunctions({ types: [ 'STRING' ] });
|
||||
parser.suggestColumns({ types: [ 'STRING' ] });
|
||||
$$ = { types: ['BOOLEAN'] }
|
||||
}
|
||||
| 'RLIKE' PartialBacktickedOrCursor
|
||||
{
|
||||
parser.suggestFunctions({ types: [ 'STRING' ] });
|
||||
parser.suggestColumns({ types: [ 'STRING' ] });
|
||||
$$ = { types: ['BOOLEAN'] }
|
||||
}
|
||||
| 'REGEXP' PartialBacktickedOrCursor
|
||||
{
|
||||
parser.suggestFunctions({ types: [ 'STRING' ] });
|
||||
parser.suggestColumns({ types: [ 'STRING' ] });
|
||||
$$ = { types: ['BOOLEAN'] }
|
||||
}
|
||||
;
|
||||
|
||||
ValueExpression_EDIT
|
||||
: ValueExpression_EDIT LikeRightPart -> { types: [ 'BOOLEAN' ], suggestFilters: $1.suggestFilters }
|
||||
| ValueExpression_EDIT 'NOT' LikeRightPart -> { types: [ 'BOOLEAN' ], suggestFilters: $1.suggestFilters }
|
||||
| ValueExpression LikeRightPart_EDIT -> { types: [ 'BOOLEAN' ] }
|
||||
| ValueExpression 'NOT' LikeRightPart_EDIT -> { types: [ 'BOOLEAN' ] }
|
||||
| 'CURSOR' LikeRightPart
|
||||
{
|
||||
parser.valueExpressionSuggest(undefined, $2);
|
||||
parser.applyTypeToSuggestions([ 'STRING' ]);
|
||||
$$ = { types: [ 'BOOLEAN' ], typeSet: true };
|
||||
}
|
||||
| 'CURSOR' 'NOT' LikeRightPart
|
||||
{
|
||||
parser.valueExpressionSuggest(undefined, $2 + ' ' + $3);
|
||||
parser.applyTypeToSuggestions([ 'STRING' ]);
|
||||
$$ = { types: [ 'BOOLEAN' ], typeSet: true };
|
||||
}
|
||||
;
|
||||
|
||||
// ------------------ CASE, WHEN, THEN ------------------
|
||||
|
||||
ValueExpression
|
||||
: 'CASE' CaseRightPart -> $2
|
||||
| 'CASE' ValueExpression CaseRightPart -> $3
|
||||
;
|
||||
|
||||
ValueExpression_EDIT
|
||||
: 'CASE' CaseRightPart_EDIT -> $2
|
||||
| 'CASE' 'CURSOR' EndOrError
|
||||
{
|
||||
parser.valueExpressionSuggest();
|
||||
parser.suggestKeywords(['WHEN']);
|
||||
$$ = { types: [ 'T' ], typeSet: true };
|
||||
}
|
||||
| 'CASE' ValueExpression CaseRightPart_EDIT -> $3
|
||||
| 'CASE' ValueExpression 'CURSOR' EndOrError
|
||||
{
|
||||
parser.suggestValueExpressionKeywords($2, ['WHEN']);
|
||||
$$ = { types: [ 'T' ], typeSet: true };
|
||||
}
|
||||
| 'CASE' ValueExpression_EDIT CaseRightPart
|
||||
{
|
||||
$$ = $3;
|
||||
$$.suggestFilters = $2.suggestFilters;
|
||||
}
|
||||
| 'CASE' ValueExpression_EDIT EndOrError -> { types: [ 'T' ], suggestFilters: $2.suggestFilters }
|
||||
| 'CASE' 'CURSOR' CaseRightPart -> { types: [ 'T' ] }
|
||||
;
|
||||
|
||||
CaseRightPart
|
||||
: CaseWhenThenList 'END' -> parser.findCaseType($1)
|
||||
| CaseWhenThenList 'ELSE' ValueExpression 'END'
|
||||
{
|
||||
$1.caseTypes.push($3);
|
||||
$$ = parser.findCaseType($1);
|
||||
}
|
||||
;
|
||||
|
||||
CaseRightPart_EDIT
|
||||
: CaseWhenThenList_EDIT EndOrError -> parser.findCaseType($1)
|
||||
| CaseWhenThenList 'ELSE' ValueExpression 'CURSOR'
|
||||
{
|
||||
parser.suggestValueExpressionKeywords($3, ['END']);
|
||||
$1.caseTypes.push($3);
|
||||
$$ = parser.findCaseType($1);
|
||||
}
|
||||
| CaseWhenThenList_EDIT 'ELSE' ValueExpression EndOrError
|
||||
{
|
||||
$1.caseTypes.push($3);
|
||||
$$ = parser.findCaseType($1);
|
||||
}
|
||||
| CaseWhenThenList_EDIT 'ELSE' EndOrError -> parser.findCaseType($1)
|
||||
| CaseWhenThenList 'CURSOR' ValueExpression EndOrError
|
||||
{
|
||||
if ($4.toLowerCase() !== 'end') {
|
||||
parser.suggestValueExpressionKeywords($1, [{ value: 'END', weight: 3 }, { value: 'ELSE', weight: 2 }, { value: 'WHEN', weight: 1 }]);
|
||||
} else {
|
||||
parser.suggestValueExpressionKeywords($1, [{ value: 'ELSE', weight: 2 }, { value: 'WHEN', weight: 1 }]);
|
||||
}
|
||||
$$ = parser.findCaseType($1);
|
||||
}
|
||||
| CaseWhenThenList 'CURSOR' EndOrError
|
||||
{
|
||||
if ($3.toLowerCase() !== 'end') {
|
||||
parser.suggestValueExpressionKeywords($1, [{ value: 'END', weight: 3 }, { value: 'ELSE', weight: 2 }, { value: 'WHEN', weight: 1 }]);
|
||||
} else {
|
||||
parser.suggestValueExpressionKeywords($1, [{ value: 'ELSE', weight: 2 }, { value: 'WHEN', weight: 1 }]);
|
||||
}
|
||||
$$ = parser.findCaseType($1);
|
||||
}
|
||||
| CaseWhenThenList 'ELSE' ValueExpression_EDIT EndOrError
|
||||
{
|
||||
$1.caseTypes.push($3);
|
||||
$$ = parser.findCaseType($1);
|
||||
$$.suggestFilters = $3.suggestFilters
|
||||
}
|
||||
| CaseWhenThenList 'ELSE' 'CURSOR' EndOrError
|
||||
{
|
||||
parser.valueExpressionSuggest();
|
||||
$$ = parser.findCaseType($1);
|
||||
}
|
||||
| 'ELSE' 'CURSOR' EndOrError
|
||||
{
|
||||
parser.valueExpressionSuggest();
|
||||
$$ = { types: [ 'T' ], typeSet: true };
|
||||
}
|
||||
| 'CURSOR' 'ELSE' ValueExpression EndOrError
|
||||
{
|
||||
parser.valueExpressionSuggest();
|
||||
parser.suggestKeywords(['WHEN']);
|
||||
$$ = $3;
|
||||
}
|
||||
| 'CURSOR' 'ELSE' EndOrError
|
||||
{
|
||||
parser.valueExpressionSuggest();
|
||||
parser.suggestKeywords(['WHEN']);
|
||||
$$ = { types: [ 'T' ] };
|
||||
}
|
||||
;
|
||||
|
||||
EndOrError
|
||||
: 'END'
|
||||
| error
|
||||
;
|
||||
|
||||
CaseWhenThenList
|
||||
: CaseWhenThenListPartTwo -> { caseTypes: [ $1 ], lastType: $1 }
|
||||
| CaseWhenThenList CaseWhenThenListPartTwo
|
||||
{
|
||||
$1.caseTypes.push($2);
|
||||
$$ = { caseTypes: $1.caseTypes, lastType: $2 };
|
||||
}
|
||||
;
|
||||
|
||||
CaseWhenThenList_EDIT
|
||||
: CaseWhenThenListPartTwo_EDIT
|
||||
| CaseWhenThenList CaseWhenThenListPartTwo_EDIT
|
||||
| CaseWhenThenList CaseWhenThenListPartTwo_EDIT CaseWhenThenList
|
||||
| CaseWhenThenList 'CURSOR' CaseWhenThenList
|
||||
{
|
||||
parser.suggestValueExpressionKeywords($1, ['WHEN']);
|
||||
}
|
||||
| CaseWhenThenListPartTwo_EDIT CaseWhenThenList -> $2
|
||||
;
|
||||
|
||||
CaseWhenThenListPartTwo
|
||||
: 'WHEN' ValueExpression 'THEN' ValueExpression -> $4
|
||||
;
|
||||
|
||||
CaseWhenThenListPartTwo_EDIT
|
||||
: 'WHEN' ValueExpression_EDIT -> { caseTypes: [{ types: ['T'] }], suggestFilters: $2.suggestFilters }
|
||||
| 'WHEN' ValueExpression_EDIT 'THEN' -> { caseTypes: [{ types: ['T'] }], suggestFilters: $2.suggestFilters }
|
||||
| 'WHEN' ValueExpression_EDIT 'THEN' ValueExpression -> { caseTypes: [$4], suggestFilters: $2.suggestFilters }
|
||||
| 'WHEN' ValueExpression 'THEN' ValueExpression_EDIT -> { caseTypes: [$4], suggestFilters: $4.suggestFilters }
|
||||
| 'WHEN' 'THEN' ValueExpression_EDIT -> { caseTypes: [$3], suggestFilters: $3.suggestFilters }
|
||||
| 'CURSOR' ValueExpression 'THEN'
|
||||
{
|
||||
parser.suggestKeywords(['WHEN']);
|
||||
$$ = { caseTypes: [{ types: ['T'] }] };
|
||||
}
|
||||
| 'CURSOR' ValueExpression 'THEN' ValueExpression
|
||||
{
|
||||
parser.suggestKeywords(['WHEN']);
|
||||
$$ = { caseTypes: [$4] };
|
||||
}
|
||||
| 'CURSOR' 'THEN'
|
||||
{
|
||||
parser.valueExpressionSuggest();
|
||||
parser.suggestKeywords(['WHEN']);
|
||||
$$ = { caseTypes: [{ types: ['T'] }] };
|
||||
}
|
||||
| 'CURSOR' 'THEN' ValueExpression
|
||||
{
|
||||
parser.valueExpressionSuggest();
|
||||
parser.suggestKeywords(['WHEN']);
|
||||
$$ = { caseTypes: [{ types: ['T'] }] };
|
||||
}
|
||||
| 'WHEN' 'CURSOR'
|
||||
{
|
||||
parser.valueExpressionSuggest();
|
||||
$$ = { caseTypes: [{ types: ['T'] }], suggestFilters: true };
|
||||
}
|
||||
| 'WHEN' 'CURSOR' ValueExpression
|
||||
{
|
||||
parser.valueExpressionSuggest();
|
||||
parser.suggestKeywords(['THEN']);
|
||||
$$ = { caseTypes: [{ types: ['T'] }], suggestFilters: true };
|
||||
}
|
||||
| 'WHEN' 'CURSOR' 'THEN'
|
||||
{
|
||||
parser.valueExpressionSuggest();
|
||||
$$ = { caseTypes: [{ types: ['T'] }], suggestFilters: true };
|
||||
}
|
||||
| 'WHEN' 'CURSOR' 'THEN' ValueExpression
|
||||
{
|
||||
parser.valueExpressionSuggest();
|
||||
$$ = { caseTypes: [$4], suggestFilters: true };
|
||||
}
|
||||
| 'WHEN' ValueExpression 'CURSOR'
|
||||
{
|
||||
parser.suggestValueExpressionKeywords($2, ['THEN']);
|
||||
$$ = { caseTypes: [{ types: ['T'] }] };
|
||||
}
|
||||
| 'WHEN' ValueExpression 'CURSOR' ValueExpression
|
||||
{
|
||||
parser.suggestValueExpressionKeywords($2, ['THEN']);
|
||||
$$ = { caseTypes: [{ types: ['T'] }] };
|
||||
}
|
||||
| 'WHEN' ValueExpression 'THEN' 'CURSOR'
|
||||
{
|
||||
parser.valueExpressionSuggest();
|
||||
$$ = { caseTypes: [{ types: ['T'] }] };
|
||||
}
|
||||
| 'WHEN' ValueExpression 'THEN' 'CURSOR' ValueExpression
|
||||
{
|
||||
parser.valueExpressionSuggest();
|
||||
$$ = { caseTypes: [{ types: ['T'] }] };
|
||||
}
|
||||
| 'WHEN' 'THEN' 'CURSOR' ValueExpression
|
||||
{
|
||||
parser.valueExpressionSuggest();
|
||||
$$ = { caseTypes: [{ types: ['T'] }] };
|
||||
}
|
||||
| 'WHEN' 'THEN' 'CURSOR'
|
||||
{
|
||||
parser.valueExpressionSuggest();
|
||||
$$ = { caseTypes: [{ types: ['T'] }] };
|
||||
}
|
||||
;
|
19
src/jison/sql/flink/syntax_footer.jison
Normal file
19
src/jison/sql/flink/syntax_footer.jison
Normal file
@ -0,0 +1,19 @@
|
||||
// Licensed to Cloudera, Inc. under one
|
||||
// or more contributor license agreements. See the NOTICE file
|
||||
// distributed with this work for additional information
|
||||
// regarding copyright ownership. Cloudera, Inc. licenses this file
|
||||
// to you under the Apache License, Version 2.0 (the
|
||||
// "License"); you may not use this file except in compliance
|
||||
// with the License. You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
%%
|
||||
|
||||
SqlParseSupport.initSyntaxParser(parser);
|
28
src/jison/sql/flink/syntax_header.jison
Normal file
28
src/jison/sql/flink/syntax_header.jison
Normal file
@ -0,0 +1,28 @@
|
||||
// Licensed to Cloudera, Inc. under one
|
||||
// or more contributor license agreements. See the NOTICE file
|
||||
// distributed with this work for additional information
|
||||
// regarding copyright ownership. Cloudera, Inc. licenses this file
|
||||
// to you under the Apache License, Version 2.0 (the
|
||||
// "License"); you may not use this file except in compliance
|
||||
// with the License. You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
%left 'AND' 'OR'
|
||||
%left 'BETWEEN'
|
||||
%left 'NOT' '!' '~'
|
||||
%left '=' '<' '>' 'COMPARISON_OPERATOR'
|
||||
%left '-' '*' 'ARITHMETIC_OPERATOR'
|
||||
|
||||
%left ';' ','
|
||||
%nonassoc 'IN' 'IS' 'LIKE' 'RLIKE' 'REGEXP' 'EXISTS' NEGATION
|
||||
|
||||
%start SqlSyntax
|
||||
|
||||
%%
|
19
src/jison/sql/generic/autocomplete_footer.jison
Normal file
19
src/jison/sql/generic/autocomplete_footer.jison
Normal file
@ -0,0 +1,19 @@
|
||||
// Licensed to Cloudera, Inc. under one
|
||||
// or more contributor license agreements. See the NOTICE file
|
||||
// distributed with this work for additional information
|
||||
// regarding copyright ownership. Cloudera, Inc. licenses this file
|
||||
// to you under the Apache License, Version 2.0 (the
|
||||
// "License"); you may not use this file except in compliance
|
||||
// with the License. You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
%%
|
||||
|
||||
SqlParseSupport.initSqlParser(parser);
|
29
src/jison/sql/generic/autocomplete_header.jison
Normal file
29
src/jison/sql/generic/autocomplete_header.jison
Normal file
@ -0,0 +1,29 @@
|
||||
// Licensed to Cloudera, Inc. under one
|
||||
// or more contributor license agreements. See the NOTICE file
|
||||
// distributed with this work for additional information
|
||||
// regarding copyright ownership. Cloudera, Inc. licenses this file
|
||||
// to you under the Apache License, Version 2.0 (the
|
||||
// "License"); you may not use this file except in compliance
|
||||
// with the License. You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
%left 'AND' 'OR'
|
||||
%left 'BETWEEN'
|
||||
%left 'NOT' '!' '~'
|
||||
%left '=' '<' '>' 'COMPARISON_OPERATOR'
|
||||
%left '-' '*' 'ARITHMETIC_OPERATOR'
|
||||
|
||||
%left ';' ','
|
||||
%nonassoc 'CURSOR' 'PARTIAL_CURSOR'
|
||||
%nonassoc 'IN' 'IS' 'LIKE' 'RLIKE' 'REGEXP' 'EXISTS' NEGATION
|
||||
|
||||
%start SqlAutocomplete
|
||||
|
||||
%%
|
226
src/jison/sql/generic/sql.jisonlex
Normal file
226
src/jison/sql/generic/sql.jisonlex
Normal file
@ -0,0 +1,226 @@
|
||||
// Licensed to Cloudera, Inc. under one
|
||||
// or more contributor license agreements. See the NOTICE file
|
||||
// distributed with this work for additional information
|
||||
// regarding copyright ownership. Cloudera, Inc. licenses this file
|
||||
// to you under the Apache License, Version 2.0 (the
|
||||
// "License"); you may not use this file except in compliance
|
||||
// with the License. You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
%options case-insensitive flex
|
||||
%s between
|
||||
%x hdfs doubleQuotedValue singleQuotedValue backtickedValue
|
||||
%%
|
||||
|
||||
\s { /* skip whitespace */ }
|
||||
'--'.* { /* skip comments */ }
|
||||
[/][*][^*]*[*]+([^/*][^*]*[*]+)*[/] { /* skip comments */ }
|
||||
|
||||
'\u2020' { parser.yy.partialCursor = false; parser.yy.cursorFound = yylloc; return 'CURSOR'; }
|
||||
'\u2021' { parser.yy.partialCursor = true; parser.yy.cursorFound = yylloc; return 'PARTIAL_CURSOR'; }
|
||||
|
||||
<between>'AND' { this.popState(); return 'BETWEEN_AND'; }
|
||||
|
||||
// Reserved Keywords
|
||||
'ALL' { return 'ALL'; }
|
||||
'ALTER' { parser.determineCase(yytext); parser.addStatementTypeLocation('ALTER', yylloc, yy.lexer.upcomingInput()); return 'ALTER'; }
|
||||
'AND' { return 'AND'; }
|
||||
'AS' { return 'AS'; }
|
||||
'ASC' { return 'ASC'; }
|
||||
'BETWEEN' { this.begin('between'); return 'BETWEEN'; }
|
||||
'BIGINT' { return 'BIGINT'; }
|
||||
'BOOLEAN' { return 'BOOLEAN'; }
|
||||
'BY' { return 'BY'; }
|
||||
'CASCADE' { return 'CASCADE'; }
|
||||
'CASE' { return 'CASE'; }
|
||||
'CHAR' { return 'CHAR'; }
|
||||
'COMMENT' { return 'COMMENT'; }
|
||||
'CREATE' { parser.determineCase(yytext); return 'CREATE'; }
|
||||
'CROSS' { return 'CROSS'; }
|
||||
'CURRENT' { return 'CURRENT'; }
|
||||
'DATABASE' { return 'DATABASE'; }
|
||||
'DECIMAL' { return 'DECIMAL'; }
|
||||
'DESC' { return 'DESC'; }
|
||||
'DISTINCT' { return 'DISTINCT'; }
|
||||
'DIV' { return 'ARITHMETIC_OPERATOR'; }
|
||||
'DOUBLE' { return 'DOUBLE'; }
|
||||
'DROP' { parser.determineCase(yytext); parser.addStatementTypeLocation('DROP', yylloc, yy.lexer.upcomingInput()); return 'DROP'; }
|
||||
'ELSE' { return 'ELSE'; }
|
||||
'END' { return 'END'; }
|
||||
'EXISTS' { parser.yy.correlatedSubQuery = true; return 'EXISTS'; }
|
||||
'FALSE' { return 'FALSE'; }
|
||||
'FLOAT' { return 'FLOAT'; }
|
||||
'FOLLOWING' { return 'FOLLOWING'; }
|
||||
'FROM' { parser.determineCase(yytext); return 'FROM'; }
|
||||
'FULL' { return 'FULL'; }
|
||||
'GROUP' { return 'GROUP'; }
|
||||
'HAVING' { return 'HAVING'; }
|
||||
'IF' { return 'IF'; }
|
||||
'IN' { return 'IN'; }
|
||||
'INNER' { return 'INNER'; }
|
||||
'INSERT' { return 'INSERT'; }
|
||||
'INT' { return 'INT'; }
|
||||
'INTO' { return 'INTO'; }
|
||||
'IS' { return 'IS'; }
|
||||
'JOIN' { return 'JOIN'; }
|
||||
'LEFT' { return 'LEFT'; }
|
||||
'LIKE' { return 'LIKE'; }
|
||||
'LIMIT' { return 'LIMIT'; }
|
||||
'NOT' { return 'NOT'; }
|
||||
'NULL' { return 'NULL'; }
|
||||
'ON' { return 'ON'; }
|
||||
'OPTION' { return 'OPTION'; }
|
||||
'OR' { return 'OR'; }
|
||||
'ORDER' { return 'ORDER'; }
|
||||
'OUTER' { return 'OUTER'; }
|
||||
'PARTITION' { return 'PARTITION'; }
|
||||
'PRECEDING' { return 'PRECEDING'; }
|
||||
'PURGE' { return 'PURGE'; }
|
||||
'RANGE' { return 'RANGE'; }
|
||||
'REGEXP' { return 'REGEXP'; }
|
||||
'RIGHT' { return 'RIGHT'; }
|
||||
'RLIKE' { return 'RLIKE'; }
|
||||
'ROW' { return 'ROW'; }
|
||||
'ROLE' { return 'ROLE'; }
|
||||
'ROWS' { return 'ROWS'; }
|
||||
'SCHEMA' { return 'SCHEMA'; }
|
||||
'SELECT' { parser.determineCase(yytext); parser.addStatementTypeLocation('SELECT', yylloc); return 'SELECT'; }
|
||||
'SEMI' { return 'SEMI'; }
|
||||
'SET' { parser.determineCase(yytext); parser.addStatementTypeLocation('SET', yylloc); return 'SET'; }
|
||||
'SHOW' { parser.determineCase(yytext); parser.addStatementTypeLocation('SHOW', yylloc); return 'SHOW'; }
|
||||
'SMALLINT' { return 'SMALLINT'; }
|
||||
'STRING' { return 'STRING'; }
|
||||
'TABLE' { return 'TABLE'; }
|
||||
'THEN' { return 'THEN'; }
|
||||
'TIMESTAMP' { return 'TIMESTAMP'; }
|
||||
'TINYINT' { return 'TINYINT'; }
|
||||
'TO' { return 'TO'; }
|
||||
'TRUE' { return 'TRUE'; }
|
||||
'TRUNCATE' { parser.determineCase(yytext); parser.addStatementTypeLocation('TRUNCATE', yylloc, yy.lexer.upcomingInput()); return 'TRUNCATE'; }
|
||||
'UNBOUNDED' { return 'UNBOUNDED'; }
|
||||
'UNION' { return 'UNION'; }
|
||||
'UPDATE' { parser.determineCase(yytext); return 'UPDATE'; }
|
||||
'USE' { parser.determineCase(yytext); parser.addStatementTypeLocation('USE', yylloc); return 'USE'; }
|
||||
'VALUES' { return 'VALUES'; }
|
||||
'VARCHAR' { return 'VARCHAR'; }
|
||||
'VIEW' { return 'VIEW'; }
|
||||
'WHEN' { return 'WHEN'; }
|
||||
'WHERE' { return 'WHERE'; }
|
||||
'WITH' { parser.determineCase(yytext); parser.addStatementTypeLocation('WITH', yylloc); return 'WITH'; }
|
||||
|
||||
// Non-reserved Keywords
|
||||
'OVER' { return 'OVER'; }
|
||||
'ROLE' { return 'ROLE'; }
|
||||
|
||||
// --- UDFs ---
|
||||
AVG\s*\( { yy.lexer.unput('('); yytext = 'avg'; parser.addFunctionLocation(yylloc, yytext); return 'AVG'; }
|
||||
CAST\s*\( { yy.lexer.unput('('); yytext = 'cast'; parser.addFunctionLocation(yylloc, yytext); return 'CAST'; }
|
||||
COUNT\s*\( { yy.lexer.unput('('); yytext = 'count'; parser.addFunctionLocation(yylloc, yytext); return 'COUNT'; }
|
||||
MAX\s*\( { yy.lexer.unput('('); yytext = 'max'; parser.addFunctionLocation(yylloc, yytext); return 'MAX'; }
|
||||
MIN\s*\( { yy.lexer.unput('('); yytext = 'min'; parser.addFunctionLocation(yylloc, yytext); return 'MIN'; }
|
||||
STDDEV_POP\s*\( { yy.lexer.unput('('); yytext = 'stddev_pop'; parser.addFunctionLocation(yylloc, yytext); return 'STDDEV_POP'; }
|
||||
STDDEV_SAMP\s*\( { yy.lexer.unput('('); yytext = 'stddev_samp'; parser.addFunctionLocation(yylloc, yytext); return 'STDDEV_SAMP'; }
|
||||
SUM\s*\( { yy.lexer.unput('('); yytext = 'sum'; parser.addFunctionLocation(yylloc, yytext); return 'SUM'; }
|
||||
VAR_POP\s*\( { yy.lexer.unput('('); yytext = 'var_pop'; parser.addFunctionLocation(yylloc, yytext); return 'VAR_POP'; }
|
||||
VAR_SAMP\s*\( { yy.lexer.unput('('); yytext = 'var_samp'; parser.addFunctionLocation(yylloc, yytext); return 'VAR_SAMP'; }
|
||||
VARIANCE\s*\( { yy.lexer.unput('('); yytext = 'variance'; parser.addFunctionLocation(yylloc, yytext); return 'VARIANCE'; }
|
||||
|
||||
// Analytical functions
|
||||
CUME_DIST\s*\( { yy.lexer.unput('('); yytext = 'cume_dist'; parser.addFunctionLocation(yylloc, yytext); return 'ANALYTIC'; }
|
||||
DENSE_RANK\s*\( { yy.lexer.unput('('); yytext = 'dense_rank'; parser.addFunctionLocation(yylloc, yytext); return 'ANALYTIC'; }
|
||||
FIRST_VALUE\s*\( { yy.lexer.unput('('); yytext = 'first_value'; parser.addFunctionLocation(yylloc, yytext); return 'ANALYTIC'; }
|
||||
LAG\s*\( { yy.lexer.unput('('); yytext = 'lag'; parser.addFunctionLocation(yylloc, yytext); return 'ANALYTIC'; }
|
||||
LAST_VALUE\s*\( { yy.lexer.unput('('); yytext = 'last_value'; parser.addFunctionLocation(yylloc, yytext); return 'ANALYTIC'; }
|
||||
LEAD\s*\( { yy.lexer.unput('('); yytext = 'lead'; parser.addFunctionLocation(yylloc, yytext); return 'ANALYTIC'; }
|
||||
RANK\s*\( { yy.lexer.unput('('); yytext = 'rank'; parser.addFunctionLocation(yylloc, yytext); return 'ANALYTIC'; }
|
||||
ROW_NUMBER\s*\( { yy.lexer.unput('('); yytext = 'row_number'; parser.addFunctionLocation(yylloc, yytext); return 'ANALYTIC'; }
|
||||
|
||||
[0-9]+ { return 'UNSIGNED_INTEGER'; }
|
||||
[0-9]+(?:[YSL]|BD)? { return 'UNSIGNED_INTEGER'; }
|
||||
[0-9]+E { return 'UNSIGNED_INTEGER_E'; }
|
||||
[A-Za-z0-9_]+ { return 'REGULAR_IDENTIFIER'; }
|
||||
|
||||
<hdfs>'\u2020' { parser.yy.cursorFound = true; return 'CURSOR'; }
|
||||
<hdfs>'\u2021' { parser.yy.cursorFound = true; return 'PARTIAL_CURSOR'; }
|
||||
<hdfs>\s+['"] { return 'HDFS_START_QUOTE'; }
|
||||
<hdfs>[^'"\u2020\u2021]+ { parser.addFileLocation(yylloc, yytext); return 'HDFS_PATH'; }
|
||||
<hdfs>['"] { this.popState(); return 'HDFS_END_QUOTE'; }
|
||||
<hdfs><<EOF>> { return 'EOF'; }
|
||||
|
||||
'&&' { return 'AND'; }
|
||||
'||' { return 'OR'; }
|
||||
|
||||
'=' { return '='; }
|
||||
'<' { return '<'; }
|
||||
'>' { return '>'; }
|
||||
'!=' { return 'COMPARISON_OPERATOR'; }
|
||||
'<=' { return 'COMPARISON_OPERATOR'; }
|
||||
'>=' { return 'COMPARISON_OPERATOR'; }
|
||||
'<>' { return 'COMPARISON_OPERATOR'; }
|
||||
'<=>' { return 'COMPARISON_OPERATOR'; }
|
||||
|
||||
'-' { return '-'; }
|
||||
'*' { return '*'; }
|
||||
'+' { return 'ARITHMETIC_OPERATOR'; }
|
||||
'/' { return 'ARITHMETIC_OPERATOR'; }
|
||||
'%' { return 'ARITHMETIC_OPERATOR'; }
|
||||
'|' { return 'ARITHMETIC_OPERATOR'; }
|
||||
'^' { return 'ARITHMETIC_OPERATOR'; }
|
||||
'&' { return 'ARITHMETIC_OPERATOR'; }
|
||||
|
||||
',' { return ','; }
|
||||
'.' { return '.'; }
|
||||
':' { return ':'; }
|
||||
';' { return ';'; }
|
||||
'~' { return '~'; }
|
||||
'!' { return '!'; }
|
||||
|
||||
'(' { return '('; }
|
||||
')' { return ')'; }
|
||||
'[' { return '['; }
|
||||
']' { return ']'; }
|
||||
|
||||
\$\{[^}]*\} { return 'VARIABLE_REFERENCE'; }
|
||||
|
||||
\` { this.begin('backtickedValue'); return 'BACKTICK'; }
|
||||
<backtickedValue>[^`]+ {
|
||||
if (parser.handleQuotedValueWithCursor(this, yytext, yylloc, '`')) {
|
||||
return 'PARTIAL_VALUE';
|
||||
}
|
||||
return 'VALUE';
|
||||
}
|
||||
<backtickedValue>\` { this.popState(); return 'BACKTICK'; }
|
||||
|
||||
\' { this.begin('singleQuotedValue'); return 'SINGLE_QUOTE'; }
|
||||
<singleQuotedValue>(?:\\\\|\\[']|[^'])+ {
|
||||
if (parser.handleQuotedValueWithCursor(this, yytext, yylloc, '\'')) {
|
||||
return 'PARTIAL_VALUE';
|
||||
}
|
||||
return 'VALUE';
|
||||
}
|
||||
<singleQuotedValue>\' { this.popState(); return 'SINGLE_QUOTE'; }
|
||||
|
||||
\" { this.begin('doubleQuotedValue'); return 'DOUBLE_QUOTE'; }
|
||||
<doubleQuotedValue>(?:\\\\|\\["]|[^"])+ {
|
||||
if (parser.handleQuotedValueWithCursor(this, yytext, yylloc, '"')) {
|
||||
return 'PARTIAL_VALUE';
|
||||
}
|
||||
return 'VALUE';
|
||||
}
|
||||
<doubleQuotedValue>\" { this.popState(); return 'DOUBLE_QUOTE'; }
|
||||
|
||||
<<EOF>> { return 'EOF'; }
|
||||
|
||||
. { /* To prevent console logging of unknown chars */ }
|
||||
<between>. { }
|
||||
<hdfs>. { }
|
||||
<backtickedValue>. { }
|
||||
<singleQuotedValue>. { }
|
||||
<doubleQuotedValue>. { }
|
109
src/jison/sql/generic/sql_alter.jison
Normal file
109
src/jison/sql/generic/sql_alter.jison
Normal file
@ -0,0 +1,109 @@
|
||||
// Licensed to Cloudera, Inc. under one
|
||||
// or more contributor license agreements. See the NOTICE file
|
||||
// distributed with this work for additional information
|
||||
// regarding copyright ownership. Cloudera, Inc. licenses this file
|
||||
// to you under the Apache License, Version 2.0 (the
|
||||
// "License"); you may not use this file except in compliance
|
||||
// with the License. You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
DataDefinition
|
||||
: AlterStatement
|
||||
;
|
||||
|
||||
DataDefinition_EDIT
|
||||
: AlterStatement_EDIT
|
||||
;
|
||||
|
||||
AlterStatement
|
||||
: AlterTable
|
||||
| AlterView
|
||||
;
|
||||
|
||||
AlterStatement_EDIT
|
||||
: AlterTable_EDIT
|
||||
| AlterView_EDIT
|
||||
| 'ALTER' 'CURSOR'
|
||||
{
|
||||
parser.suggestKeywords(['TABLE', 'VIEW']);
|
||||
}
|
||||
;
|
||||
|
||||
AlterTable
|
||||
: AlterTableLeftSide PartitionSpec
|
||||
;
|
||||
|
||||
AlterTable_EDIT
|
||||
: AlterTableLeftSide_EDIT
|
||||
| AlterTableLeftSide_EDIT PartitionSpec
|
||||
| AlterTableLeftSide 'CURSOR'
|
||||
| AlterTableLeftSide PartitionSpec 'CURSOR'
|
||||
;
|
||||
|
||||
AlterTableLeftSide
|
||||
: 'ALTER' 'TABLE' SchemaQualifiedTableIdentifier
|
||||
{
|
||||
parser.addTablePrimary($3);
|
||||
}
|
||||
;
|
||||
|
||||
AlterTableLeftSide_EDIT
|
||||
: 'ALTER' 'TABLE' SchemaQualifiedTableIdentifier_EDIT
|
||||
{
|
||||
if (parser.yy.result.suggestTables) {
|
||||
parser.yy.result.suggestTables.onlyTables = true;
|
||||
}
|
||||
}
|
||||
| 'ALTER' 'TABLE' 'CURSOR'
|
||||
{
|
||||
parser.suggestTables({ onlyTables: true });
|
||||
parser.suggestDatabases({ appendDot: true });
|
||||
}
|
||||
;
|
||||
|
||||
AlterView
|
||||
: AlterViewLeftSide 'AS' QuerySpecification
|
||||
;
|
||||
|
||||
AlterView_EDIT
|
||||
: AlterViewLeftSide_EDIT
|
||||
| AlterViewLeftSide 'CURSOR'
|
||||
{
|
||||
parser.suggestKeywords(['AS']);
|
||||
}
|
||||
| AlterViewLeftSide 'SET' 'CURSOR'
|
||||
| AlterViewLeftSide 'AS' 'CURSOR'
|
||||
{
|
||||
parser.suggestKeywords(['SELECT']);
|
||||
}
|
||||
| AlterViewLeftSide 'AS' QuerySpecification_EDIT
|
||||
;
|
||||
|
||||
|
||||
AlterViewLeftSide
|
||||
: 'ALTER' 'VIEW' SchemaQualifiedTableIdentifier
|
||||
{
|
||||
parser.addTablePrimary($3);
|
||||
}
|
||||
;
|
||||
|
||||
AlterViewLeftSide_EDIT
|
||||
: 'ALTER' 'VIEW' SchemaQualifiedTableIdentifier_EDIT
|
||||
{
|
||||
if (parser.yy.result.suggestTables) {
|
||||
parser.yy.result.suggestTables.onlyViews = true;
|
||||
}
|
||||
}
|
||||
| 'ALTER' 'VIEW' 'CURSOR'
|
||||
{
|
||||
parser.suggestTables({ onlyViews: true });
|
||||
parser.suggestDatabases({ appendDot: true });
|
||||
}
|
||||
;
|
615
src/jison/sql/generic/sql_create.jison
Normal file
615
src/jison/sql/generic/sql_create.jison
Normal file
@ -0,0 +1,615 @@
|
||||
// Licensed to Cloudera, Inc. under one
|
||||
// or more contributor license agreements. See the NOTICE file
|
||||
// distributed with this work for additional information
|
||||
// regarding copyright ownership. Cloudera, Inc. licenses this file
|
||||
// to you under the Apache License, Version 2.0 (the
|
||||
// "License"); you may not use this file except in compliance
|
||||
// with the License. You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
DataDefinition
|
||||
: CreateStatement
|
||||
;
|
||||
|
||||
DataDefinition_EDIT
|
||||
: CreateStatement_EDIT
|
||||
;
|
||||
|
||||
CreateStatement
|
||||
: DatabaseDefinition
|
||||
| TableDefinition
|
||||
| ViewDefinition
|
||||
| RoleDefinition
|
||||
;
|
||||
|
||||
CreateStatement_EDIT
|
||||
: DatabaseDefinition_EDIT
|
||||
| TableDefinition_EDIT
|
||||
| ViewDefinition_EDIT
|
||||
| 'CREATE' 'CURSOR'
|
||||
{
|
||||
parser.suggestKeywords(['DATABASE', 'ROLE', 'SCHEMA', 'TABLE', 'VIEW']);
|
||||
}
|
||||
;
|
||||
|
||||
DatabaseDefinition
|
||||
: 'CREATE' DatabaseOrSchema OptionalIfNotExists
|
||||
| 'CREATE' DatabaseOrSchema OptionalIfNotExists RegularIdentifier DatabaseDefinitionOptionals
|
||||
{
|
||||
parser.addNewDatabaseLocation(@4, [{ name: $4 }]);
|
||||
}
|
||||
;
|
||||
|
||||
DatabaseDefinition_EDIT
|
||||
: 'CREATE' DatabaseOrSchema OptionalIfNotExists 'CURSOR'
|
||||
{
|
||||
if (!$3) {
|
||||
parser.suggestKeywords(['IF NOT EXISTS']);
|
||||
}
|
||||
}
|
||||
| 'CREATE' DatabaseOrSchema OptionalIfNotExists_EDIT
|
||||
| 'CREATE' DatabaseOrSchema OptionalIfNotExists 'CURSOR' RegularIdentifier
|
||||
{
|
||||
if (!$3) {
|
||||
parser.suggestKeywords(['IF NOT EXISTS']);
|
||||
}
|
||||
parser.addNewDatabaseLocation(@5, [{ name: $5 }]);
|
||||
}
|
||||
| 'CREATE' DatabaseOrSchema OptionalIfNotExists_EDIT RegularIdentifier
|
||||
{
|
||||
parser.addNewDatabaseLocation(@4, [{ name: $4 }]);
|
||||
}
|
||||
| 'CREATE' DatabaseOrSchema OptionalIfNotExists RegularIdentifier DatabaseDefinitionOptionals 'CURSOR'
|
||||
{
|
||||
parser.addNewDatabaseLocation(@4, [{ name: $4 }]);
|
||||
}
|
||||
;
|
||||
|
||||
DatabaseDefinitionOptionals
|
||||
: OptionalComment
|
||||
{
|
||||
if (!$1) {
|
||||
parser.suggestKeywords(['COMMENT']);
|
||||
}
|
||||
}
|
||||
;
|
||||
|
||||
DatabaseDefinitionOptionals_EDIT
|
||||
: OptionalComment_INVALID
|
||||
;
|
||||
|
||||
OptionalComment
|
||||
:
|
||||
| Comment
|
||||
;
|
||||
|
||||
Comment
|
||||
: 'COMMENT' QuotedValue
|
||||
;
|
||||
|
||||
OptionalComment_INVALID
|
||||
: Comment_INVALID
|
||||
;
|
||||
|
||||
Comment_INVALID
|
||||
: 'COMMENT' SINGLE_QUOTE
|
||||
| 'COMMENT' DOUBLE_QUOTE
|
||||
| 'COMMENT' SINGLE_QUOTE VALUE
|
||||
| 'COMMENT' DOUBLE_QUOTE VALUE
|
||||
;
|
||||
|
||||
TableDefinition
|
||||
: 'CREATE' 'TABLE' OptionalIfNotExists TableDefinitionRightPart
|
||||
;
|
||||
|
||||
TableDefinition_EDIT
|
||||
: 'CREATE' 'TABLE' OptionalIfNotExists TableDefinitionRightPart_EDIT
|
||||
| 'CREATE' 'TABLE' OptionalIfNotExists 'CURSOR'
|
||||
{
|
||||
if (!$3) {
|
||||
parser.suggestKeywords(['IF NOT EXISTS']);
|
||||
}
|
||||
}
|
||||
| 'CREATE' 'TABLE' OptionalIfNotExists_EDIT
|
||||
;
|
||||
|
||||
TableDefinitionRightPart
|
||||
: TableIdentifierAndOptionalColumnSpecification OptionalPartitionedBy OptionalAsSelectStatement
|
||||
;
|
||||
|
||||
TableDefinitionRightPart_EDIT
|
||||
: TableIdentifierAndOptionalColumnSpecification_EDIT OptionalPartitionedBy OptionalAsSelectStatement
|
||||
| TableIdentifierAndOptionalColumnSpecification PartitionedBy_EDIT OptionalAsSelectStatement
|
||||
| TableIdentifierAndOptionalColumnSpecification OptionalPartitionedBy OptionalAsSelectStatement_EDIT
|
||||
| TableIdentifierAndOptionalColumnSpecification OptionalPartitionedBy 'CURSOR'
|
||||
{
|
||||
var keywords = [];
|
||||
if (!$1 && !$2) {
|
||||
keywords.push({ value: 'LIKE', weight: 1 });
|
||||
} else {
|
||||
if (!$2) {
|
||||
keywords.push({ value: 'PARTITIONED BY', weight: 12 });
|
||||
}
|
||||
keywords.push({ value: 'AS', weight: 1 });
|
||||
}
|
||||
|
||||
if (keywords.length > 0) {
|
||||
parser.suggestKeywords(keywords);
|
||||
}
|
||||
}
|
||||
;
|
||||
|
||||
TableIdentifierAndOptionalColumnSpecification
|
||||
: SchemaQualifiedIdentifier OptionalColumnSpecificationsOrLike
|
||||
{
|
||||
parser.addNewTableLocation(@1, $1, $2);
|
||||
$$ = $2;
|
||||
}
|
||||
;
|
||||
|
||||
TableIdentifierAndOptionalColumnSpecification_EDIT
|
||||
: SchemaQualifiedIdentifier OptionalColumnSpecificationsOrLike_EDIT
|
||||
| SchemaQualifiedIdentifier_EDIT OptionalColumnSpecificationsOrLike
|
||||
;
|
||||
|
||||
OptionalColumnSpecificationsOrLike
|
||||
:
|
||||
| ParenthesizedColumnSpecificationList
|
||||
| 'LIKE' SchemaQualifiedTableIdentifier -> []
|
||||
;
|
||||
|
||||
OptionalColumnSpecificationsOrLike_EDIT
|
||||
: ParenthesizedColumnSpecificationList_EDIT
|
||||
| 'LIKE' 'CURSOR'
|
||||
{
|
||||
parser.suggestTables();
|
||||
parser.suggestDatabases({ appendDot: true });
|
||||
}
|
||||
| 'LIKE' SchemaQualifiedTableIdentifier_EDIT
|
||||
;
|
||||
|
||||
ParenthesizedColumnSpecificationList
|
||||
: '(' ColumnSpecificationList ')' -> $2
|
||||
;
|
||||
|
||||
ParenthesizedColumnSpecificationList_EDIT
|
||||
: '(' ColumnSpecificationList_EDIT RightParenthesisOrError
|
||||
;
|
||||
|
||||
ColumnSpecificationList
|
||||
: ColumnSpecification -> [$1]
|
||||
| ColumnSpecificationList ',' ColumnSpecification -> $1.concat($3)
|
||||
;
|
||||
|
||||
ColumnSpecificationList_EDIT
|
||||
: ColumnSpecification_EDIT
|
||||
| ColumnSpecification_EDIT ',' ColumnSpecificationList
|
||||
| ColumnSpecificationList ',' ColumnSpecification_EDIT
|
||||
| ColumnSpecificationList ',' ColumnSpecification_EDIT ',' ColumnSpecificationList
|
||||
| ColumnSpecification 'CURSOR'
|
||||
{
|
||||
parser.checkForKeywords($1);
|
||||
}
|
||||
| ColumnSpecification 'CURSOR' ',' ColumnSpecificationList
|
||||
{
|
||||
parser.checkForKeywords($1);
|
||||
}
|
||||
| ColumnSpecificationList ',' ColumnSpecification 'CURSOR'
|
||||
{
|
||||
parser.checkForKeywords($3);
|
||||
}
|
||||
| ColumnSpecificationList ',' ColumnSpecification 'CURSOR' ',' ColumnSpecificationList
|
||||
{
|
||||
parser.checkForKeywords($3);
|
||||
}
|
||||
;
|
||||
|
||||
ColumnSpecification
|
||||
: ColumnIdentifier ColumnDataType OptionalColumnOptions
|
||||
{
|
||||
$$ = $1;
|
||||
$$.type = $2;
|
||||
var keywords = [];
|
||||
if (!$3['comment']) {
|
||||
keywords.push('COMMENT');
|
||||
}
|
||||
if (keywords.length > 0) {
|
||||
$$.suggestKeywords = keywords;
|
||||
}
|
||||
}
|
||||
;
|
||||
|
||||
ColumnSpecification_EDIT
|
||||
: ColumnIdentifier 'CURSOR' OptionalColumnOptions
|
||||
{
|
||||
parser.suggestKeywords(parser.getColumnDataTypeKeywords());
|
||||
}
|
||||
| ColumnIdentifier ColumnDataType_EDIT OptionalColumnOptions
|
||||
| ColumnIdentifier ColumnDataType ColumnOptions_EDIT
|
||||
;
|
||||
|
||||
OptionalColumnOptions
|
||||
: -> {}
|
||||
| ColumnOptions
|
||||
;
|
||||
|
||||
ColumnOptions
|
||||
: ColumnOption
|
||||
{
|
||||
$$ = {};
|
||||
$$[$1] = true;
|
||||
}
|
||||
| ColumnOptions ColumnOption
|
||||
{
|
||||
$1[$2] = true;
|
||||
}
|
||||
;
|
||||
|
||||
ColumnOptions_EDIT
|
||||
: ColumnOption_EDIT
|
||||
| ColumnOption_EDIT ColumnOptions
|
||||
| ColumnOptions ColumnOption_EDIT
|
||||
| ColumnOptions ColumnOption_EDIT ColumnOptions
|
||||
;
|
||||
|
||||
ColumnOption
|
||||
: 'NOT' 'NULL' -> 'null'
|
||||
| 'NULL' -> 'null'
|
||||
| Comment -> 'comment'
|
||||
;
|
||||
|
||||
ColumnOption_EDIT
|
||||
: 'NOT' 'CURSOR'
|
||||
{
|
||||
parser.suggestKeywords(['NULL']);
|
||||
}
|
||||
;
|
||||
|
||||
ColumnDataType
|
||||
: PrimitiveType
|
||||
| ArrayType
|
||||
| MapType
|
||||
| StructType
|
||||
| ArrayType_INVALID
|
||||
| MapType_INVALID
|
||||
| StructType_INVALID
|
||||
;
|
||||
|
||||
ColumnDataType_EDIT
|
||||
: ArrayType_EDIT
|
||||
| MapType_EDIT
|
||||
| StructType_EDIT
|
||||
;
|
||||
|
||||
ArrayType
|
||||
: 'ARRAY' '<' ColumnDataType '>'
|
||||
;
|
||||
|
||||
ArrayType_INVALID
|
||||
: 'ARRAY' '<' '>'
|
||||
;
|
||||
|
||||
ArrayType_EDIT
|
||||
: 'ARRAY' '<' AnyCursor GreaterThanOrError
|
||||
{
|
||||
parser.suggestKeywords(parser.getColumnDataTypeKeywords());
|
||||
}
|
||||
| 'ARRAY' '<' ColumnDataType_EDIT GreaterThanOrError
|
||||
;
|
||||
|
||||
MapType
|
||||
: 'MAP' '<' PrimitiveType ',' ColumnDataType '>'
|
||||
;
|
||||
|
||||
MapType_INVALID
|
||||
: 'MAP' '<' '>'
|
||||
;
|
||||
|
||||
MapType_EDIT
|
||||
: 'MAP' '<' PrimitiveType ',' ColumnDataType_EDIT GreaterThanOrError
|
||||
| 'MAP' '<' AnyCursor GreaterThanOrError
|
||||
{
|
||||
parser.suggestKeywords(parser.getTypeKeywords());
|
||||
}
|
||||
| 'MAP' '<' PrimitiveType ',' AnyCursor GreaterThanOrError
|
||||
{
|
||||
parser.suggestKeywords(parser.getColumnDataTypeKeywords());
|
||||
}
|
||||
| 'MAP' '<' ',' AnyCursor GreaterThanOrError
|
||||
{
|
||||
parser.suggestKeywords(parser.getColumnDataTypeKeywords());
|
||||
}
|
||||
;
|
||||
|
||||
StructType
|
||||
: 'STRUCT' '<' StructDefinitionList '>'
|
||||
;
|
||||
|
||||
StructType_INVALID
|
||||
: 'STRUCT' '<' '>'
|
||||
;
|
||||
|
||||
StructType_EDIT
|
||||
: 'STRUCT' '<' StructDefinitionList_EDIT GreaterThanOrError
|
||||
;
|
||||
|
||||
StructDefinitionList
|
||||
: StructDefinition
|
||||
| StructDefinitionList ',' StructDefinition
|
||||
;
|
||||
|
||||
StructDefinitionList_EDIT
|
||||
: StructDefinition_EDIT
|
||||
| StructDefinition_EDIT Commas
|
||||
| StructDefinition_EDIT Commas StructDefinitionList
|
||||
| StructDefinitionList ',' StructDefinition_EDIT
|
||||
| StructDefinitionList ',' StructDefinition_EDIT Commas StructDefinitionList
|
||||
;
|
||||
|
||||
StructDefinition
|
||||
: RegularOrBacktickedIdentifier ':' ColumnDataType OptionalComment
|
||||
;
|
||||
|
||||
StructDefinition_EDIT
|
||||
: Commas RegularOrBacktickedIdentifier ':' ColumnDataType 'CURSOR'
|
||||
{
|
||||
parser.suggestKeywords(['COMMENT']);
|
||||
}
|
||||
| Commas RegularOrBacktickedIdentifier ':' AnyCursor
|
||||
{
|
||||
parser.suggestKeywords(parser.getColumnDataTypeKeywords());
|
||||
}
|
||||
| Commas RegularOrBacktickedIdentifier ':' ColumnDataType_EDIT
|
||||
| RegularOrBacktickedIdentifier ':' ColumnDataType 'CURSOR'
|
||||
{
|
||||
parser.suggestKeywords(['COMMENT']);
|
||||
}
|
||||
| RegularOrBacktickedIdentifier ':' AnyCursor
|
||||
{
|
||||
parser.suggestKeywords(parser.getColumnDataTypeKeywords());
|
||||
}
|
||||
| RegularOrBacktickedIdentifier ':' ColumnDataType_EDIT
|
||||
;
|
||||
|
||||
ColumnDataTypeList
|
||||
: ColumnDataType
|
||||
| ColumnDataTypeList ',' ColumnDataType
|
||||
;
|
||||
|
||||
ColumnDataTypeList_EDIT
|
||||
: ColumnDataTypeListInner_EDIT
|
||||
| ColumnDataTypeListInner_EDIT Commas
|
||||
| ColumnDataTypeList ',' ColumnDataTypeListInner_EDIT
|
||||
| ColumnDataTypeListInner_EDIT Commas ColumnDataTypeList
|
||||
| ColumnDataTypeList ',' ColumnDataTypeListInner_EDIT Commas ColumnDataTypeList
|
||||
;
|
||||
|
||||
ColumnDataTypeListInner_EDIT
|
||||
: Commas AnyCursor
|
||||
{
|
||||
parser.suggestKeywords(parser.getColumnDataTypeKeywords());
|
||||
}
|
||||
| Commas ColumnDataType_EDIT
|
||||
| AnyCursor
|
||||
{
|
||||
parser.suggestKeywords(parser.getColumnDataTypeKeywords());
|
||||
}
|
||||
| ColumnDataType_EDIT
|
||||
;
|
||||
|
||||
GreaterThanOrError
|
||||
: '>'
|
||||
| error
|
||||
;
|
||||
|
||||
OptionalPartitionedBy
|
||||
:
|
||||
| PartitionedBy
|
||||
;
|
||||
|
||||
PartitionedBy
|
||||
: 'PARTITION' 'BY' RangeClause
|
||||
;
|
||||
|
||||
PartitionedBy_EDIT
|
||||
: 'PARTITION' 'CURSOR'
|
||||
{
|
||||
parser.suggestKeywords(['BY']);
|
||||
}
|
||||
| 'PARTITION' 'BY' 'CURSOR'
|
||||
{
|
||||
parser.suggestKeywords(['RANGE']);
|
||||
}
|
||||
| 'PARTITION' 'BY' RangeClause_EDIT
|
||||
;
|
||||
|
||||
RangeClause
|
||||
: 'RANGE' ParenthesizedColumnList ParenthesizedPartitionValuesList
|
||||
;
|
||||
|
||||
RangeClause_EDIT
|
||||
: 'RANGE' 'CURSOR'
|
||||
| 'RANGE' ParenthesizedColumnList_EDIT
|
||||
| 'RANGE' ParenthesizedColumnList 'CURSOR'
|
||||
| 'RANGE' ParenthesizedColumnList ParenthesizedPartitionValuesList_EDIT
|
||||
| 'RANGE' ParenthesizedColumnList_EDIT ParenthesizedPartitionValuesList
|
||||
;
|
||||
|
||||
ParenthesizedPartitionValuesList
|
||||
: '(' PartitionValueList ')'
|
||||
;
|
||||
|
||||
ParenthesizedPartitionValuesList_EDIT
|
||||
: '(' 'CURSOR' RightParenthesisOrError
|
||||
{
|
||||
parser.suggestKeywords(['PARTITION']);
|
||||
}
|
||||
|'(' PartitionValueList_EDIT RightParenthesisOrError
|
||||
;
|
||||
|
||||
PartitionValueList
|
||||
: PartitionValue
|
||||
| PartitionValueList ',' PartitionValue
|
||||
;
|
||||
|
||||
PartitionValueList_EDIT
|
||||
: PartitionValue_EDIT
|
||||
| PartitionValueList ',' 'CURSOR'
|
||||
{
|
||||
parser.suggestKeywords(['PARTITION']);
|
||||
}
|
||||
| PartitionValueList ',' 'CURSOR' ',' PartitionValueList
|
||||
{
|
||||
parser.suggestKeywords(['PARTITION']);
|
||||
}
|
||||
| PartitionValueList ',' PartitionValue_EDIT
|
||||
| PartitionValueList ',' PartitionValue_EDIT ',' PartitionValueList
|
||||
;
|
||||
|
||||
PartitionValue
|
||||
: 'PARTITION' ValueExpression LessThanOrEqualTo 'VALUES' LessThanOrEqualTo ValueExpression
|
||||
| 'PARTITION' 'VALUES' LessThanOrEqualTo ValueExpression
|
||||
| 'PARTITION' ValueExpression LessThanOrEqualTo 'VALUES'
|
||||
;
|
||||
|
||||
PartitionValue_EDIT
|
||||
: 'PARTITION' 'CURSOR'
|
||||
{
|
||||
parser.suggestKeywords(['VALUE', 'VALUES']);
|
||||
}
|
||||
| 'PARTITION' ValueExpression_EDIT
|
||||
{
|
||||
if ($2.endsWithLessThanOrEqual) {
|
||||
parser.suggestKeywords(['VALUES']);
|
||||
}
|
||||
}
|
||||
| 'PARTITION' ValueExpression 'CURSOR'
|
||||
{
|
||||
parser.suggestKeywords(['<', '<=']);
|
||||
}
|
||||
| 'PARTITION' ValueExpression LessThanOrEqualTo 'CURSOR'
|
||||
{
|
||||
parser.suggestKeywords(['VALUES']);
|
||||
}
|
||||
| 'PARTITION' ValueExpression_EDIT LessThanOrEqualTo 'VALUES'
|
||||
| 'PARTITION' ValueExpression LessThanOrEqualTo 'VALUES' 'CURSOR'
|
||||
{
|
||||
parser.suggestKeywords(['<', '<=']);
|
||||
}
|
||||
| 'PARTITION' ValueExpression LessThanOrEqualTo 'VALUES' LessThanOrEqualTo 'CURSOR'
|
||||
{
|
||||
parser.suggestFunctions();
|
||||
}
|
||||
| 'PARTITION' ValueExpression LessThanOrEqualTo 'VALUES' LessThanOrEqualTo ValueExpression_EDIT
|
||||
| 'PARTITION' 'VALUES' 'CURSOR'
|
||||
{
|
||||
parser.suggestKeywords(['<', '<=']);
|
||||
}
|
||||
| 'PARTITION' 'VALUES' LessThanOrEqualTo 'CURSOR'
|
||||
{
|
||||
parser.suggestFunctions();
|
||||
}
|
||||
| 'PARTITION' 'VALUES' LessThanOrEqualTo ValueExpression_EDIT
|
||||
;
|
||||
|
||||
LessThanOrEqualTo
|
||||
: '<'
|
||||
| 'COMPARISON_OPERATOR' // This is fine for autocompletion
|
||||
;
|
||||
|
||||
OptionalAsSelectStatement
|
||||
:
|
||||
| 'AS' CommitLocations QuerySpecification
|
||||
;
|
||||
|
||||
OptionalAsSelectStatement_EDIT
|
||||
: 'AS' CommitLocations 'CURSOR'
|
||||
{
|
||||
parser.suggestKeywords(['SELECT']);
|
||||
}
|
||||
| 'AS' CommitLocations QuerySpecification_EDIT
|
||||
;
|
||||
|
||||
CommitLocations
|
||||
: /* empty */
|
||||
{
|
||||
parser.commitLocations();
|
||||
}
|
||||
;
|
||||
|
||||
ViewDefinition
|
||||
: 'CREATE' 'VIEW' OptionalIfNotExists SchemaQualifiedIdentifier OptionalParenthesizedViewColumnList OptionalComment 'AS' QuerySpecification
|
||||
;
|
||||
|
||||
ViewDefinition_EDIT
|
||||
: 'CREATE' 'VIEW' OptionalIfNotExists 'CURSOR'
|
||||
{
|
||||
if (!$3) {
|
||||
parser.suggestKeywords(['IF NOT EXISTS']);
|
||||
}
|
||||
parser.suggestDatabases({ appendDot: true });
|
||||
}
|
||||
| 'CREATE' 'VIEW' OptionalIfNotExists 'CURSOR' SchemaQualifiedIdentifier OptionalParenthesizedViewColumnList OptionalComment 'AS' QuerySpecification
|
||||
{
|
||||
if (!$3) {
|
||||
parser.suggestKeywords(['IF NOT EXISTS']);
|
||||
}
|
||||
}
|
||||
| 'CREATE' 'VIEW' OptionalIfNotExists_EDIT
|
||||
| 'CREATE' 'VIEW' OptionalIfNotExists SchemaQualifiedIdentifier ParenthesizedViewColumnList_EDIT OptionalComment
|
||||
| 'CREATE' 'VIEW' OptionalIfNotExists SchemaQualifiedIdentifier OptionalParenthesizedViewColumnList OptionalComment 'CURSOR'
|
||||
{
|
||||
var keywords = [{value: 'AS', weight: 1 }];
|
||||
if (!$6) {
|
||||
keywords.push({ value: 'COMMENT', weight: 3 });
|
||||
}
|
||||
parser.suggestKeywords(keywords);
|
||||
}
|
||||
| 'CREATE' 'VIEW' OptionalIfNotExists SchemaQualifiedIdentifier OptionalParenthesizedViewColumnList OptionalComment 'AS' 'CURSOR'
|
||||
{
|
||||
parser.suggestKeywords(['SELECT']);
|
||||
}
|
||||
| 'CREATE' 'VIEW' OptionalIfNotExists SchemaQualifiedIdentifier OptionalParenthesizedViewColumnList OptionalComment 'AS' QuerySpecification_EDIT
|
||||
| 'CREATE' 'VIEW' OptionalIfNotExists SchemaQualifiedIdentifier_EDIT OptionalParenthesizedViewColumnList OptionalComment 'AS' QuerySpecification
|
||||
;
|
||||
|
||||
OptionalParenthesizedViewColumnList
|
||||
:
|
||||
| ParenthesizedViewColumnList
|
||||
;
|
||||
|
||||
ParenthesizedViewColumnList
|
||||
: '(' ViewColumnList ')'
|
||||
;
|
||||
|
||||
ParenthesizedViewColumnList_EDIT
|
||||
: '(' ViewColumnList_EDIT RightParenthesisOrError
|
||||
{
|
||||
if (!$2) {
|
||||
parser.suggestKeywords(['COMMENT']);
|
||||
}
|
||||
}
|
||||
;
|
||||
|
||||
ViewColumnList
|
||||
: ColumnReference OptionalComment
|
||||
| ViewColumnList ',' ColumnReference OptionalComment
|
||||
;
|
||||
|
||||
ViewColumnList_EDIT
|
||||
: ColumnReference OptionalComment 'CURSOR' -> $2
|
||||
| ColumnReference OptionalComment 'CURSOR' ',' ViewColumnList -> $2
|
||||
| ViewColumnList ',' ColumnReference OptionalComment 'CURSOR' -> $4
|
||||
| ViewColumnList ',' ColumnReference OptionalComment 'CURSOR' ',' ViewColumnList -> $4
|
||||
;
|
||||
|
||||
RoleDefinition
|
||||
: 'CREATE' 'ROLE' RegularIdentifier
|
||||
;
|
184
src/jison/sql/generic/sql_drop.jison
Normal file
184
src/jison/sql/generic/sql_drop.jison
Normal file
@ -0,0 +1,184 @@
|
||||
// Licensed to Cloudera, Inc. under one
|
||||
// or more contributor license agreements. See the NOTICE file
|
||||
// distributed with this work for additional information
|
||||
// regarding copyright ownership. Cloudera, Inc. licenses this file
|
||||
// to you under the Apache License, Version 2.0 (the
|
||||
// "License"); you may not use this file except in compliance
|
||||
// with the License. You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
DataDefinition
|
||||
: DropStatement
|
||||
;
|
||||
|
||||
DataDefinition_EDIT
|
||||
: DropStatement_EDIT
|
||||
;
|
||||
|
||||
DropStatement
|
||||
: DropDatabaseStatement
|
||||
| DropRoleStatement
|
||||
| DropTableStatement
|
||||
| DropViewStatement
|
||||
| TruncateTableStatement
|
||||
;
|
||||
|
||||
DropStatement_EDIT
|
||||
: DropDatabaseStatement_EDIT
|
||||
| DropTableStatement_EDIT
|
||||
| DropViewStatement_EDIT
|
||||
| TruncateTableStatement_EDIT
|
||||
| 'DROP' 'CURSOR'
|
||||
{
|
||||
parser.suggestKeywords(['DATABASE', 'ROLE', 'SCHEMA', 'TABLE', 'VIEW']);
|
||||
}
|
||||
;
|
||||
|
||||
DropDatabaseStatement
|
||||
: 'DROP' DatabaseOrSchema OptionalIfExists RegularOrBacktickedIdentifier OptionalCascade
|
||||
;
|
||||
|
||||
DropDatabaseStatement_EDIT
|
||||
: 'DROP' DatabaseOrSchema OptionalIfExists
|
||||
| 'DROP' DatabaseOrSchema OptionalIfExists_EDIT
|
||||
| 'DROP' DatabaseOrSchema OptionalIfExists 'CURSOR'
|
||||
{
|
||||
if (!$3) {
|
||||
parser.suggestKeywords(['IF EXISTS']);
|
||||
}
|
||||
parser.suggestDatabases();
|
||||
}
|
||||
| 'DROP' DatabaseOrSchema OptionalIfExists RegularOrBacktickedIdentifier 'CURSOR'
|
||||
{
|
||||
parser.suggestKeywords(['CASCADE']);
|
||||
}
|
||||
| 'DROP' DatabaseOrSchema OptionalIfExists_EDIT RegularOrBacktickedIdentifier OptionalCascade
|
||||
| 'DROP' DatabaseOrSchema OptionalIfExists 'CURSOR' RegularOrBacktickedIdentifier OptionalCascade
|
||||
{
|
||||
if (!$3) {
|
||||
parser.suggestKeywords(['IF EXISTS']);
|
||||
}
|
||||
}
|
||||
;
|
||||
DropRoleStatement
|
||||
: 'DROP' 'ROLE' RegularIdentifier
|
||||
;
|
||||
|
||||
DropTableStatement
|
||||
: 'DROP' 'TABLE' OptionalIfExists SchemaQualifiedTableIdentifier OptionalPurge
|
||||
{
|
||||
parser.addTablePrimary($4);
|
||||
}
|
||||
;
|
||||
|
||||
DropTableStatement_EDIT
|
||||
: 'DROP' 'TABLE' OptionalIfExists_EDIT
|
||||
| 'DROP' 'TABLE' OptionalIfExists 'CURSOR'
|
||||
{
|
||||
if (!$3) {
|
||||
parser.suggestKeywords(['IF EXISTS']);
|
||||
}
|
||||
parser.suggestTables({ onlyTables: true });
|
||||
parser.suggestDatabases({
|
||||
appendDot: true
|
||||
});
|
||||
}
|
||||
| 'DROP' 'TABLE' OptionalIfExists SchemaQualifiedTableIdentifier_EDIT OptionalPurge
|
||||
{
|
||||
if (parser.yy.result.suggestTables) {
|
||||
parser.yy.result.suggestTables.onlyTables = true;
|
||||
}
|
||||
}
|
||||
| 'DROP' 'TABLE' OptionalIfExists_EDIT SchemaQualifiedTableIdentifier OptionalPurge
|
||||
| 'DROP' 'TABLE' OptionalIfExists SchemaQualifiedTableIdentifier OptionalPurge 'CURSOR'
|
||||
{
|
||||
parser.addTablePrimary($4);
|
||||
if (!$5) {
|
||||
parser.suggestKeywords(['PURGE']);
|
||||
}
|
||||
}
|
||||
;
|
||||
|
||||
OptionalPurge
|
||||
:
|
||||
| 'PURGE'
|
||||
;
|
||||
|
||||
DropViewStatement
|
||||
: 'DROP' 'VIEW' OptionalIfExists SchemaQualifiedTableIdentifier
|
||||
{
|
||||
parser.addTablePrimary($4);
|
||||
}
|
||||
;
|
||||
|
||||
DropViewStatement_EDIT
|
||||
: 'DROP' 'VIEW' OptionalIfExists 'CURSOR'
|
||||
{
|
||||
if (!$3) {
|
||||
parser.suggestKeywords(['IF EXISTS']);
|
||||
}
|
||||
parser.suggestTables({ onlyViews: true });
|
||||
parser.suggestDatabases({ appendDot: true });
|
||||
}
|
||||
| 'DROP' 'VIEW' OptionalIfExists 'CURSOR' SchemaQualifiedTableIdentifier
|
||||
{
|
||||
parser.addTablePrimary($5);
|
||||
if (!$3) {
|
||||
parser.suggestKeywords(['IF EXISTS']);
|
||||
}
|
||||
}
|
||||
| 'DROP' 'VIEW' OptionalIfExists_EDIT
|
||||
| 'DROP' 'VIEW' OptionalIfExists_EDIT SchemaQualifiedTableIdentifier
|
||||
{
|
||||
parser.addTablePrimary($4);
|
||||
}
|
||||
| 'DROP' 'VIEW' OptionalIfExists SchemaQualifiedTableIdentifier_EDIT
|
||||
{
|
||||
if (parser.yy.result.suggestTables) {
|
||||
parser.yy.result.suggestTables.onlyViews = true;
|
||||
}
|
||||
}
|
||||
;
|
||||
|
||||
TruncateTableStatement
|
||||
: 'TRUNCATE' 'TABLE' OptionalIfExists SchemaQualifiedTableIdentifier
|
||||
{
|
||||
parser.addTablePrimary($4);
|
||||
}
|
||||
;
|
||||
|
||||
TruncateTableStatement_EDIT
|
||||
: 'TRUNCATE' 'CURSOR'
|
||||
{
|
||||
parser.suggestKeywords(['TABLE']);
|
||||
}
|
||||
| 'TRUNCATE' 'TABLE' OptionalIfExists 'CURSOR'
|
||||
{
|
||||
parser.suggestTables();
|
||||
parser.suggestDatabases({ appendDot: true });
|
||||
if (!$3) {
|
||||
parser.suggestKeywords(['IF EXISTS']);
|
||||
}
|
||||
}
|
||||
| 'TRUNCATE' 'TABLE' OptionalIfExists_EDIT
|
||||
| 'TRUNCATE' 'TABLE' OptionalIfExists SchemaQualifiedTableIdentifier_EDIT
|
||||
| 'TRUNCATE' 'TABLE' OptionalIfExists SchemaQualifiedTableIdentifier 'CURSOR'
|
||||
{
|
||||
parser.addTablePrimary($4);
|
||||
}
|
||||
| 'TRUNCATE' 'TABLE' OptionalIfExists 'CURSOR' SchemaQualifiedTableIdentifier
|
||||
{
|
||||
parser.addTablePrimary($4);
|
||||
if (!$3) {
|
||||
parser.suggestKeywords(['IF EXISTS']);
|
||||
}
|
||||
}
|
||||
| 'TRUNCATE' 'TABLE' OptionalIfExists_EDIT SchemaQualifiedTableIdentifier OptionalPartitionSpec
|
||||
;
|
132
src/jison/sql/generic/sql_error.jison
Normal file
132
src/jison/sql/generic/sql_error.jison
Normal file
@ -0,0 +1,132 @@
|
||||
// Licensed to Cloudera, Inc. under one
|
||||
// or more contributor license agreements. See the NOTICE file
|
||||
// distributed with this work for additional information
|
||||
// regarding copyright ownership. Cloudera, Inc. licenses this file
|
||||
// to you under the Apache License, Version 2.0 (the
|
||||
// "License"); you may not use this file except in compliance
|
||||
// with the License. You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
SqlStatements
|
||||
: error
|
||||
| NonStartingToken error // Having just ': error' does not work for some reason, jison bug?
|
||||
;
|
||||
|
||||
SqlStatement_EDIT
|
||||
: AnyCursor error
|
||||
{
|
||||
parser.suggestDdlAndDmlKeywords();
|
||||
}
|
||||
;
|
||||
|
||||
SelectStatement
|
||||
: 'SELECT' OptionalAllOrDistinct SelectList_ERROR TableExpression
|
||||
| 'SELECT' OptionalAllOrDistinct SelectList TableExpression_ERROR
|
||||
;
|
||||
|
||||
SelectStatement_EDIT
|
||||
: 'SELECT' OptionalAllOrDistinct SelectList_ERROR_EDIT TableExpression
|
||||
{
|
||||
parser.selectListNoTableSuggest($3, $2);
|
||||
}
|
||||
| 'SELECT' OptionalAllOrDistinct SelectList_ERROR TableExpression_EDIT
|
||||
;
|
||||
|
||||
SelectList_ERROR
|
||||
: ErrorList
|
||||
| SelectList ',' ErrorList
|
||||
| ErrorList ',' SelectList ',' ErrorList
|
||||
| ErrorList ',' SelectList
|
||||
| SelectList ',' ErrorList ',' SelectList
|
||||
;
|
||||
|
||||
SelectList_ERROR_EDIT
|
||||
: ErrorList ',' SelectList_EDIT -> $3
|
||||
| SelectList ',' ErrorList ',' SelectList_EDIT -> $5
|
||||
| ErrorList ',' SelectList ',' ErrorList ',' SelectList_EDIT -> $7
|
||||
| ErrorList ',' AnyCursor
|
||||
{
|
||||
$$ = { cursorAtStart : false, suggestFunctions: true, suggestColumns: true, suggestAggregateFunctions: true };
|
||||
}
|
||||
| SelectList ',' ErrorList ',' AnyCursor
|
||||
{
|
||||
$$ = { cursorAtStart : false, suggestFunctions: true, suggestColumns: true, suggestAggregateFunctions: true };
|
||||
}
|
||||
| ErrorList ',' SelectList ',' Errors ',' AnyCursor
|
||||
{
|
||||
$$ = { cursorAtStart : true, suggestFunctions: true, suggestColumns: true, suggestAggregateFunctions: true };
|
||||
}
|
||||
;
|
||||
|
||||
SetSpecification
|
||||
: 'SET' SetOption '=' error
|
||||
;
|
||||
|
||||
ErrorList
|
||||
: error
|
||||
| Errors ',' error
|
||||
;
|
||||
|
||||
JoinType_EDIT
|
||||
: 'FULL' 'CURSOR' error
|
||||
{
|
||||
parser.suggestKeywords(['JOIN', 'OUTER JOIN']);
|
||||
}
|
||||
| 'LEFT' 'CURSOR' error
|
||||
{
|
||||
parser.suggestKeywords(['JOIN', 'OUTER JOIN']);
|
||||
}
|
||||
| 'RIGHT' 'CURSOR' error
|
||||
{
|
||||
parser.suggestKeywords(['JOIN', 'OUTER JOIN']);
|
||||
}
|
||||
;
|
||||
|
||||
OptionalSelectConditions_EDIT
|
||||
: WhereClause error 'CURSOR' OptionalGroupByClause OptionalHavingClause OptionalOrderByClause OptionalLimitClause
|
||||
{
|
||||
$$ = {
|
||||
suggestKeywords: parser.getKeywordsForOptionalsLR([$4, $5, $6, $7], [{ value: 'GROUP BY', weight: 8 }, { value: 'HAVING', weight: 7 }, { value: 'ORDER BY', weight: 5 }, { value: 'LIMIT', weight: 3 }], [true, true, true, true]),
|
||||
cursorAtEnd: !$4 && !$5 && !$6 && !$7
|
||||
};
|
||||
}
|
||||
| OptionalWhereClause OptionalGroupByClause HavingClause error 'CURSOR' OptionalOrderByClause OptionalLimitClause
|
||||
{
|
||||
$$ = {
|
||||
suggestKeywords: parser.getKeywordsForOptionalsLR([$6, $7], [{ value: 'ORDER BY', weight: 5 }, { value: 'LIMIT', weight: 3 }], [true, true]),
|
||||
cursorAtEnd: !$6 && !$7
|
||||
}
|
||||
}
|
||||
| OptionalWhereClause OptionalGroupByClause OptionalHavingClause OrderByClause error 'CURSOR' OptionalLimitClause
|
||||
{
|
||||
$$ = {
|
||||
suggestKeywords: parser.getKeywordsForOptionalsLR([$7], [{ value: 'LIMIT', weight: 3 }], [true]),
|
||||
cursorAtEnd: !$7
|
||||
}
|
||||
}
|
||||
| OptionalWhereClause OptionalGroupByClause OptionalHavingClause OptionalOrderByClause LimitClause error 'CURSOR'
|
||||
;
|
||||
|
||||
OptionalSelectConditions_EDIT
|
||||
: WhereClause error GroupByClause_EDIT OptionalHavingClause OptionalOrderByClause OptionalLimitClause
|
||||
| WhereClause error OptionalGroupByClause HavingClause_EDIT OptionalOrderByClause OptionalLimitClause
|
||||
| WhereClause error OptionalGroupByClause OptionalHavingClause OrderByClause_EDIT OptionalLimitClause
|
||||
| WhereClause error OptionalGroupByClause OptionalHavingClause OptionalOrderByClause LimitClause_EDIT
|
||||
| OptionalWhereClause GroupByClause error HavingClause_EDIT OptionalOrderByClause OptionalLimitClause
|
||||
| OptionalWhereClause GroupByClause error OptionalHavingClause OrderByClause_EDIT OptionalLimitClause
|
||||
| OptionalWhereClause GroupByClause error OptionalHavingClause OptionalOrderByClause LimitClause_EDIT
|
||||
| OptionalWhereClause OptionalGroupByClause HavingClause error OrderByClause_EDIT OptionalLimitClause
|
||||
| OptionalWhereClause OptionalGroupByClause HavingClause error OptionalOrderByClause LimitClause_EDIT
|
||||
| OptionalWhereClause OptionalGroupByClause OptionalHavingClause OrderByClause error LimitClause_EDIT
|
||||
;
|
||||
|
||||
DatabaseDefinition_EDIT
|
||||
: 'CREATE' DatabaseOrSchema OptionalIfNotExists RegularIdentifier DatabaseDefinitionOptionals_EDIT error
|
||||
;
|
72
src/jison/sql/generic/sql_insert.jison
Normal file
72
src/jison/sql/generic/sql_insert.jison
Normal file
@ -0,0 +1,72 @@
|
||||
// Licensed to Cloudera, Inc. under one
|
||||
// or more contributor license agreements. See the NOTICE file
|
||||
// distributed with this work for additional information
|
||||
// regarding copyright ownership. Cloudera, Inc. licenses this file
|
||||
// to you under the Apache License, Version 2.0 (the
|
||||
// "License"); you may not use this file except in compliance
|
||||
// with the License. You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
DataManipulation
|
||||
: InsertStatement
|
||||
;
|
||||
|
||||
InsertStatement
|
||||
: InsertValuesStatement
|
||||
;
|
||||
|
||||
DataManipulation_EDIT
|
||||
: InsertValuesStatement_EDIT
|
||||
;
|
||||
|
||||
InsertValuesStatement
|
||||
: 'INSERT' 'INTO' OptionalTable SchemaQualifiedTableIdentifier 'VALUES' InsertValuesList
|
||||
{
|
||||
$4.owner = 'insert';
|
||||
parser.addTablePrimary($4);
|
||||
}
|
||||
;
|
||||
|
||||
InsertValuesStatement_EDIT
|
||||
: 'INSERT' 'CURSOR'
|
||||
{
|
||||
parser.suggestKeywords(['INTO']);
|
||||
}
|
||||
| 'INSERT' 'INTO' OptionalTable 'CURSOR'
|
||||
{
|
||||
if (!$3) {
|
||||
parser.suggestKeywords(['TABLE']);
|
||||
}
|
||||
parser.suggestTables();
|
||||
parser.suggestDatabases({ appendDot: true });
|
||||
}
|
||||
| 'INSERT' 'INTO' OptionalTable SchemaQualifiedTableIdentifier_EDIT
|
||||
| 'INSERT' 'INTO' OptionalTable SchemaQualifiedTableIdentifier 'CURSOR'
|
||||
{
|
||||
$4.owner = 'insert';
|
||||
parser.addTablePrimary($4);
|
||||
parser.suggestKeywords(['VALUES']);
|
||||
}
|
||||
| 'INSERT' 'INTO' OptionalTable SchemaQualifiedTableIdentifier_EDIT 'VALUES' InsertValuesList
|
||||
;
|
||||
|
||||
InsertValuesList
|
||||
: ParenthesizedRowValuesList
|
||||
| RowValuesList ',' ParenthesizedRowValuesList
|
||||
;
|
||||
|
||||
ParenthesizedRowValuesList
|
||||
: '(' InValueList ')'
|
||||
;
|
||||
|
||||
OptionalTable
|
||||
:
|
||||
| 'TABLE'
|
||||
;
|
2762
src/jison/sql/generic/sql_main.jison
Normal file
2762
src/jison/sql/generic/sql_main.jison
Normal file
File diff suppressed because it is too large
Load Diff
46
src/jison/sql/generic/sql_set.jison
Normal file
46
src/jison/sql/generic/sql_set.jison
Normal file
@ -0,0 +1,46 @@
|
||||
// Licensed to Cloudera, Inc. under one
|
||||
// or more contributor license agreements. See the NOTICE file
|
||||
// distributed with this work for additional information
|
||||
// regarding copyright ownership. Cloudera, Inc. licenses this file
|
||||
// to you under the Apache License, Version 2.0 (the
|
||||
// "License"); you may not use this file except in compliance
|
||||
// with the License. You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
DataDefinition
|
||||
: SetSpecification
|
||||
;
|
||||
|
||||
DataDefinition_EDIT
|
||||
: 'SET' 'CURSOR'
|
||||
{
|
||||
parser.suggestSetOptions();
|
||||
}
|
||||
;
|
||||
|
||||
SetSpecification
|
||||
: 'SET' SetOption '=' SetValue
|
||||
| 'SET' 'ALL'
|
||||
;
|
||||
|
||||
SetOption
|
||||
: RegularIdentifier
|
||||
| SetOption '.' RegularIdentifier
|
||||
;
|
||||
|
||||
SetValue
|
||||
: RegularIdentifier
|
||||
| SignedInteger
|
||||
| SignedInteger RegularIdentifier
|
||||
| QuotedValue
|
||||
| 'TRUE'
|
||||
| 'FALSE'
|
||||
| 'NULL'
|
||||
;
|
122
src/jison/sql/generic/sql_update.jison
Normal file
122
src/jison/sql/generic/sql_update.jison
Normal file
@ -0,0 +1,122 @@
|
||||
// Licensed to Cloudera, Inc. under one
|
||||
// or more contributor license agreements. See the NOTICE file
|
||||
// distributed with this work for additional information
|
||||
// regarding copyright ownership. Cloudera, Inc. licenses this file
|
||||
// to you under the Apache License, Version 2.0 (the
|
||||
// "License"); you may not use this file except in compliance
|
||||
// with the License. You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
DataManipulation
|
||||
: UpdateStatement
|
||||
;
|
||||
|
||||
DataManipulation_EDIT
|
||||
: UpdateStatement_EDIT
|
||||
;
|
||||
|
||||
UpdateStatement
|
||||
: 'UPDATE' TargetTable 'SET' SetClauseList OptionalFromJoinedTable OptionalWhereClause
|
||||
;
|
||||
|
||||
UpdateStatement_EDIT
|
||||
: 'UPDATE' TargetTable_EDIT 'SET' SetClauseList OptionalFromJoinedTable OptionalWhereClause
|
||||
| 'UPDATE' TargetTable 'SET' SetClauseList_EDIT OptionalFromJoinedTable OptionalWhereClause
|
||||
| 'UPDATE' TargetTable 'SET' SetClauseList FromJoinedTable_EDIT OptionalWhereClause
|
||||
| 'UPDATE' TargetTable 'SET' SetClauseList OptionalFromJoinedTable WhereClause_EDIT
|
||||
| 'UPDATE' TargetTable 'SET' SetClauseList OptionalFromJoinedTable OptionalWhereClause 'CURSOR'
|
||||
{
|
||||
parser.suggestKeywords([ 'WHERE' ]);
|
||||
}
|
||||
| 'UPDATE' TargetTable 'CURSOR'
|
||||
{
|
||||
parser.suggestKeywords([ 'SET' ]);
|
||||
}
|
||||
| 'UPDATE' TargetTable_EDIT
|
||||
| 'UPDATE' TargetTable
|
||||
| 'UPDATE' 'CURSOR'
|
||||
{
|
||||
parser.suggestTables();
|
||||
parser.suggestDatabases({ appendDot: true });
|
||||
}
|
||||
;
|
||||
|
||||
TargetTable
|
||||
: TableName
|
||||
;
|
||||
|
||||
TargetTable_EDIT
|
||||
: TableName_EDIT
|
||||
;
|
||||
|
||||
TableName
|
||||
: LocalOrSchemaQualifiedName
|
||||
{
|
||||
parser.addTablePrimary($1);
|
||||
}
|
||||
;
|
||||
|
||||
TableName_EDIT
|
||||
: LocalOrSchemaQualifiedName_EDIT
|
||||
;
|
||||
|
||||
SetClauseList
|
||||
: SetClause
|
||||
| SetClauseList ',' SetClause
|
||||
;
|
||||
|
||||
SetClauseList_EDIT
|
||||
: SetClause_EDIT
|
||||
| SetClauseList ',' SetClause_EDIT
|
||||
| SetClause_EDIT ',' SetClauseList
|
||||
| SetClauseList ',' SetClause_EDIT ',' SetClauseList
|
||||
;
|
||||
|
||||
SetClause
|
||||
: SetTarget '=' UpdateSource
|
||||
;
|
||||
|
||||
SetClause_EDIT
|
||||
: SetTarget '=' UpdateSource_EDIT
|
||||
| SetTarget 'CURSOR'
|
||||
{
|
||||
parser.suggestKeywords([ '=' ]);
|
||||
}
|
||||
| 'CURSOR'
|
||||
{
|
||||
parser.suggestColumns();
|
||||
}
|
||||
;
|
||||
|
||||
SetTarget
|
||||
: ColumnReference
|
||||
;
|
||||
|
||||
UpdateSource
|
||||
: ValueExpression
|
||||
;
|
||||
|
||||
UpdateSource_EDIT
|
||||
: ValueExpression_EDIT
|
||||
;
|
||||
|
||||
OptionalFromJoinedTable
|
||||
:
|
||||
| 'FROM' TableReference -> $2
|
||||
;
|
||||
|
||||
FromJoinedTable_EDIT
|
||||
: 'FROM' 'CURSOR'
|
||||
{
|
||||
parser.suggestTables();
|
||||
parser.suggestDatabases({ appendDot: true });
|
||||
}
|
||||
| 'FROM' TableReference_EDIT
|
||||
;
|
39
src/jison/sql/generic/sql_use.jison
Normal file
39
src/jison/sql/generic/sql_use.jison
Normal file
@ -0,0 +1,39 @@
|
||||
// Licensed to Cloudera, Inc. under one
|
||||
// or more contributor license agreements. See the NOTICE file
|
||||
// distributed with this work for additional information
|
||||
// regarding copyright ownership. Cloudera, Inc. licenses this file
|
||||
// to you under the Apache License, Version 2.0 (the
|
||||
// "License"); you may not use this file except in compliance
|
||||
// with the License. You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
DataDefinition
|
||||
: UseStatement
|
||||
;
|
||||
|
||||
DataDefinition_EDIT
|
||||
: UseStatement_EDIT
|
||||
;
|
||||
|
||||
UseStatement
|
||||
: 'USE' RegularIdentifier
|
||||
{
|
||||
if (! parser.yy.cursorFound) {
|
||||
parser.yy.result.useDatabase = $2;
|
||||
}
|
||||
}
|
||||
;
|
||||
|
||||
UseStatement_EDIT
|
||||
: 'USE' 'CURSOR'
|
||||
{
|
||||
parser.suggestDatabases();
|
||||
}
|
||||
;
|
839
src/jison/sql/generic/sql_valueExpression.jison
Normal file
839
src/jison/sql/generic/sql_valueExpression.jison
Normal file
@ -0,0 +1,839 @@
|
||||
// Licensed to Cloudera, Inc. under one
|
||||
// or more contributor license agreements. See the NOTICE file
|
||||
// distributed with this work for additional information
|
||||
// regarding copyright ownership. Cloudera, Inc. licenses this file
|
||||
// to you under the Apache License, Version 2.0 (the
|
||||
// "License"); you may not use this file except in compliance
|
||||
// with the License. You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
ValueExpression
|
||||
: 'NOT' ValueExpression
|
||||
{
|
||||
// verifyType($2, 'BOOLEAN');
|
||||
$$ = { types: [ 'BOOLEAN' ] };
|
||||
}
|
||||
| '!' ValueExpression
|
||||
{
|
||||
// verifyType($2, 'BOOLEAN');
|
||||
$$ = { types: [ 'BOOLEAN' ] };
|
||||
}
|
||||
| '~' ValueExpression -> $2
|
||||
| '-' ValueExpression %prec NEGATION
|
||||
{
|
||||
// verifyType($2, 'NUMBER');
|
||||
$$ = $2;
|
||||
$2.types = ['NUMBER'];
|
||||
}
|
||||
| ValueExpression 'IS' OptionalNot 'NULL' -> { types: [ 'BOOLEAN' ] }
|
||||
| ValueExpression 'IS' OptionalNot 'TRUE' -> { types: [ 'BOOLEAN' ] }
|
||||
| ValueExpression 'IS' OptionalNot 'FALSE' -> { types: [ 'BOOLEAN' ] }
|
||||
| ValueExpression 'IS' OptionalNot 'DISTINCT' 'FROM' ValueExpression -> { types: [ 'BOOLEAN' ] }
|
||||
;
|
||||
|
||||
ValueExpression_EDIT
|
||||
: 'NOT' ValueExpression_EDIT -> { types: [ 'BOOLEAN' ], suggestFilters: $2.suggestFilters }
|
||||
| 'NOT' 'CURSOR'
|
||||
{
|
||||
parser.suggestFunctions();
|
||||
parser.suggestColumns();
|
||||
parser.suggestKeywords(['EXISTS']);
|
||||
$$ = { types: [ 'BOOLEAN' ] };
|
||||
}
|
||||
| '!' ValueExpression_EDIT -> { types: [ 'BOOLEAN' ], suggestFilters: $2.suggestFilters }
|
||||
| '!' AnyCursor
|
||||
{
|
||||
parser.suggestFunctions({ types: [ 'BOOLEAN' ] });
|
||||
parser.suggestColumns({ types: [ 'BOOLEAN' ] });
|
||||
$$ = { types: [ 'BOOLEAN' ] };
|
||||
}
|
||||
| '~' ValueExpression_EDIT -> { types: [ 'T' ], suggestFilters: $2.suggestFilters }
|
||||
| '~' 'PARTIAL_CURSOR'
|
||||
{
|
||||
parser.suggestFunctions();
|
||||
parser.suggestColumns();
|
||||
$$ = { types: [ 'T' ] };
|
||||
}
|
||||
| '-' ValueExpression_EDIT %prec NEGATION
|
||||
{
|
||||
if (!$2.typeSet) {
|
||||
parser.applyTypeToSuggestions('NUMBER');
|
||||
}
|
||||
$$ = { types: [ 'NUMBER' ], suggestFilters: $2.suggestFilters };
|
||||
}
|
||||
| '-' 'PARTIAL_CURSOR' %prec NEGATION
|
||||
{
|
||||
parser.suggestFunctions({ types: [ 'NUMBER' ] });
|
||||
parser.suggestColumns({ types: [ 'NUMBER' ] });
|
||||
$$ = { types: [ 'NUMBER' ] };
|
||||
}
|
||||
| ValueExpression 'IS' 'CURSOR'
|
||||
{
|
||||
parser.suggestKeywords(['FALSE', 'NOT NULL', 'NOT TRUE', 'NOT FALSE', 'NULL', 'TRUE']);
|
||||
$$ = { types: [ 'BOOLEAN' ] };
|
||||
}
|
||||
| ValueExpression 'IS' 'NOT' 'CURSOR'
|
||||
{
|
||||
parser.suggestKeywords(['FALSE', 'NULL', 'TRUE']);
|
||||
$$ = { types: [ 'BOOLEAN' ] };
|
||||
}
|
||||
| ValueExpression 'IS' OptionalNot 'DISTINCT' 'CURSOR'
|
||||
{
|
||||
$$ = { types: [ 'BOOLEAN' ] };
|
||||
}
|
||||
| ValueExpression 'IS' 'CURSOR' 'NULL'
|
||||
{
|
||||
parser.suggestKeywords(['NOT']);
|
||||
$$ = { types: [ 'BOOLEAN' ] };
|
||||
}
|
||||
| ValueExpression 'IS' 'CURSOR' 'FALSE'
|
||||
{
|
||||
parser.suggestKeywords(['NOT']);
|
||||
$$ = { types: [ 'BOOLEAN' ] };
|
||||
}
|
||||
| ValueExpression 'IS' 'CURSOR' 'TRUE'
|
||||
{
|
||||
parser.suggestKeywords(['NOT']);
|
||||
$$ = { types: [ 'BOOLEAN' ] };
|
||||
}
|
||||
| ValueExpression 'IS' OptionalNot 'DISTINCT' 'FROM' PartialBacktickedOrAnyCursor
|
||||
{
|
||||
parser.valueExpressionSuggest($1, $3 ? 'IS NOT DISTINCT FROM' : 'IS DISTINCT FROM');
|
||||
$$ = { types: [ 'BOOLEAN' ] };
|
||||
}
|
||||
| ValueExpression 'IS' OptionalNot 'DISTINCT' 'FROM' ValueExpression_EDIT
|
||||
{
|
||||
$$ = { types: [ 'BOOLEAN' ], suggestFilters: $6.suggestFilters }
|
||||
}
|
||||
;
|
||||
|
||||
// ------------------ EXISTS and parenthesized ------------------
|
||||
ValueExpression
|
||||
: 'EXISTS' TableSubQuery
|
||||
{
|
||||
$$ = { types: [ 'BOOLEAN' ] };
|
||||
// clear correlated flag after completed sub-query (set by lexer)
|
||||
parser.yy.correlatedSubQuery = false;
|
||||
}
|
||||
| '(' ValueExpression ')' -> $2
|
||||
;
|
||||
|
||||
ValueExpression_EDIT
|
||||
: 'EXISTS' TableSubQuery_EDIT -> { types: [ 'BOOLEAN' ] }
|
||||
| '(' ValueExpression_EDIT RightParenthesisOrError
|
||||
{
|
||||
$$ = $2;
|
||||
}
|
||||
| '(' 'CURSOR' RightParenthesisOrError
|
||||
{
|
||||
parser.valueExpressionSuggest();
|
||||
$$ = { types: ['T'], typeSet: true };
|
||||
}
|
||||
;
|
||||
|
||||
// ------------------ COMPARISON ------------------
|
||||
|
||||
ValueExpression
|
||||
: ValueExpression '=' ValueExpression
|
||||
{
|
||||
parser.addColRefToVariableIfExists($1, $3);
|
||||
$$ = { types: [ 'BOOLEAN' ] };
|
||||
}
|
||||
| ValueExpression '<' ValueExpression
|
||||
{
|
||||
parser.addColRefToVariableIfExists($1, $3);
|
||||
$$ = { types: [ 'BOOLEAN' ] };
|
||||
}
|
||||
| ValueExpression '>' ValueExpression
|
||||
{
|
||||
parser.addColRefToVariableIfExists($1, $3);
|
||||
$$ = { types: [ 'BOOLEAN' ] };
|
||||
}
|
||||
| ValueExpression 'COMPARISON_OPERATOR' ValueExpression
|
||||
{
|
||||
parser.addColRefToVariableIfExists($1, $3);
|
||||
$$ = { types: [ 'BOOLEAN' ] };
|
||||
}
|
||||
;
|
||||
|
||||
ValueExpression_EDIT
|
||||
: 'CURSOR' '=' ValueExpression
|
||||
{
|
||||
parser.valueExpressionSuggest($3, $2);
|
||||
parser.applyTypeToSuggestions($3.types);
|
||||
$$ = { types: [ 'BOOLEAN' ], typeSet: true };
|
||||
}
|
||||
| 'CURSOR' '<' ValueExpression
|
||||
{
|
||||
parser.valueExpressionSuggest($3, $2);
|
||||
parser.applyTypeToSuggestions($3.types);
|
||||
$$ = { types: [ 'BOOLEAN' ], typeSet: true };
|
||||
}
|
||||
| 'CURSOR' '>' ValueExpression
|
||||
{
|
||||
parser.valueExpressionSuggest($3, $2);
|
||||
parser.applyTypeToSuggestions($3.types);
|
||||
$$ = { types: [ 'BOOLEAN' ], typeSet: true };
|
||||
}
|
||||
| 'CURSOR' 'COMPARISON_OPERATOR' ValueExpression
|
||||
{
|
||||
parser.valueExpressionSuggest($3, $2);
|
||||
parser.applyTypeToSuggestions($3.types);
|
||||
$$ = { types: [ 'BOOLEAN' ], typeSet: true };
|
||||
}
|
||||
| ValueExpression_EDIT '=' ValueExpression
|
||||
{
|
||||
if (!$1.typeSet) {
|
||||
parser.applyTypeToSuggestions($3.types);
|
||||
parser.addColRefIfExists($3);
|
||||
}
|
||||
$$ = { types: [ 'BOOLEAN' ], suggestFilters: $1.suggestFilters }
|
||||
}
|
||||
| ValueExpression_EDIT '<' ValueExpression
|
||||
{
|
||||
if (!$1.typeSet) {
|
||||
parser.applyTypeToSuggestions($3.types);
|
||||
parser.addColRefIfExists($3);
|
||||
}
|
||||
$$ = { types: [ 'BOOLEAN' ], suggestFilters: $1.suggestFilters }
|
||||
}
|
||||
| ValueExpression_EDIT '>' ValueExpression
|
||||
{
|
||||
if (!$1.typeSet) {
|
||||
parser.applyTypeToSuggestions($3.types);
|
||||
parser.addColRefIfExists($3);
|
||||
}
|
||||
$$ = { types: [ 'BOOLEAN' ], suggestFilters: $1.suggestFilters }
|
||||
}
|
||||
| ValueExpression_EDIT 'COMPARISON_OPERATOR' ValueExpression
|
||||
{
|
||||
if (!$1.typeSet) {
|
||||
parser.applyTypeToSuggestions($3.types);
|
||||
parser.addColRefIfExists($3);
|
||||
}
|
||||
$$ = { types: [ 'BOOLEAN' ], suggestFilters: $1.suggestFilters }
|
||||
}
|
||||
| ValueExpression '=' PartialBacktickedOrAnyCursor
|
||||
{
|
||||
parser.valueExpressionSuggest($1, $2);
|
||||
parser.applyTypeToSuggestions($1.types);
|
||||
$$ = { types: [ 'BOOLEAN' ], typeSet: true };
|
||||
}
|
||||
| ValueExpression '<' PartialBacktickedOrAnyCursor
|
||||
{
|
||||
parser.valueExpressionSuggest($1, $2);
|
||||
parser.applyTypeToSuggestions($1.types);
|
||||
$$ = { types: [ 'BOOLEAN' ] , typeSet: true, endsWithLessThanOrEqual: true };
|
||||
}
|
||||
| ValueExpression '>' PartialBacktickedOrAnyCursor
|
||||
{
|
||||
parser.valueExpressionSuggest($1, $2);
|
||||
parser.applyTypeToSuggestions($1.types);
|
||||
$$ = { types: [ 'BOOLEAN' ], typeSet: true };
|
||||
}
|
||||
| ValueExpression 'COMPARISON_OPERATOR' PartialBacktickedOrAnyCursor
|
||||
{
|
||||
parser.valueExpressionSuggest($1, $2);
|
||||
parser.applyTypeToSuggestions($1.types);
|
||||
$$ = { types: [ 'BOOLEAN' ], typeSet: true, endsWithLessThanOrEqual: $2 === '<=' };
|
||||
}
|
||||
| ValueExpression '=' ValueExpression_EDIT
|
||||
{
|
||||
if (!$3.typeSet) {
|
||||
parser.applyTypeToSuggestions($1.types);
|
||||
parser.addColRefIfExists($1);
|
||||
}
|
||||
$$ = { types: [ 'BOOLEAN' ], suggestFilters: $3.suggestFilters }
|
||||
}
|
||||
| ValueExpression '<' ValueExpression_EDIT
|
||||
{
|
||||
if (!$3.typeSet) {
|
||||
parser.applyTypeToSuggestions($1.types);
|
||||
parser.addColRefIfExists($1);
|
||||
}
|
||||
$$ = { types: [ 'BOOLEAN' ], suggestFilters: $3.suggestFilters }
|
||||
}
|
||||
| ValueExpression '>' ValueExpression_EDIT
|
||||
{
|
||||
if (!$3.typeSet) {
|
||||
parser.applyTypeToSuggestions($1.types);
|
||||
parser.addColRefIfExists($1);
|
||||
}
|
||||
$$ = { types: [ 'BOOLEAN' ], suggestFilters: $3.suggestFilters }
|
||||
}
|
||||
| ValueExpression 'COMPARISON_OPERATOR' ValueExpression_EDIT
|
||||
{
|
||||
if (!$3.typeSet) {
|
||||
parser.applyTypeToSuggestions($1.types);
|
||||
parser.addColRefIfExists($1);
|
||||
}
|
||||
$$ = { types: [ 'BOOLEAN' ], suggestFilters: $3.suggestFilters }
|
||||
}
|
||||
;
|
||||
|
||||
|
||||
// ------------------ IN ------------------
|
||||
|
||||
ValueExpression
|
||||
: ValueExpression 'NOT' 'IN' '(' TableSubQueryInner ')' -> { types: [ 'BOOLEAN' ] }
|
||||
| ValueExpression 'NOT' 'IN' '(' ValueExpressionList ')' -> { types: [ 'BOOLEAN' ] }
|
||||
| ValueExpression 'IN' '(' TableSubQueryInner ')' -> { types: [ 'BOOLEAN' ] }
|
||||
| ValueExpression 'IN' '(' ValueExpressionList ')' -> { types: [ 'BOOLEAN' ] }
|
||||
;
|
||||
|
||||
ValueExpression_EDIT
|
||||
: ValueExpression 'NOT' 'IN' ValueExpressionInSecondPart_EDIT
|
||||
{
|
||||
if ($4.inValueEdit) {
|
||||
parser.valueExpressionSuggest($1, $2 + ' ' + $3);
|
||||
parser.applyTypeToSuggestions($1.types);
|
||||
}
|
||||
if ($4.cursorAtStart) {
|
||||
parser.suggestKeywords(['SELECT']);
|
||||
}
|
||||
$$ = { types: [ 'BOOLEAN' ], typeSet: true };
|
||||
}
|
||||
| ValueExpression 'IN' ValueExpressionInSecondPart_EDIT
|
||||
{
|
||||
if ($3.inValueEdit) {
|
||||
parser.valueExpressionSuggest($1, $2);
|
||||
parser.applyTypeToSuggestions($1.types);
|
||||
}
|
||||
if ($3.cursorAtStart) {
|
||||
parser.suggestKeywords(['SELECT']);
|
||||
}
|
||||
$$ = { types: [ 'BOOLEAN' ], typeSet: true };
|
||||
}
|
||||
| ValueExpression_EDIT 'NOT' 'IN' '(' ValueExpressionList RightParenthesisOrError -> { types: [ 'BOOLEAN' ], suggestFilters: $1.suggestFilters }
|
||||
| ValueExpression_EDIT 'NOT' 'IN' '(' TableSubQueryInner RightParenthesisOrError -> { types: [ 'BOOLEAN' ], suggestFilters: $1.suggestFilters }
|
||||
| ValueExpression_EDIT 'IN' '(' ValueExpressionList RightParenthesisOrError -> { types: [ 'BOOLEAN' ], suggestFilters: $1.suggestFilters }
|
||||
| ValueExpression_EDIT 'IN' '(' TableSubQueryInner RightParenthesisOrError -> { types: [ 'BOOLEAN' ], suggestFilters: $1.suggestFilters }
|
||||
;
|
||||
|
||||
ValueExpressionInSecondPart_EDIT
|
||||
: '(' TableSubQueryInner_EDIT RightParenthesisOrError
|
||||
| '(' ValueExpressionList_EDIT RightParenthesisOrError -> { inValueEdit: true }
|
||||
| '(' AnyCursor RightParenthesisOrError -> { inValueEdit: true, cursorAtStart: true }
|
||||
;
|
||||
|
||||
// ------------------ BETWEEN ------------------
|
||||
|
||||
ValueExpression
|
||||
: ValueExpression 'NOT' 'BETWEEN' ValueExpression 'BETWEEN_AND' ValueExpression -> { types: [ 'BOOLEAN' ] }
|
||||
| ValueExpression 'BETWEEN' ValueExpression 'BETWEEN_AND' ValueExpression -> { types: [ 'BOOLEAN' ] }
|
||||
;
|
||||
|
||||
ValueExpression_EDIT
|
||||
: ValueExpression_EDIT 'NOT' 'BETWEEN' ValueExpression 'BETWEEN_AND' ValueExpression
|
||||
{
|
||||
if ($4.types[0] === $6.types[0] && !$1.typeSet) {
|
||||
parser.applyTypeToSuggestions($4.types);
|
||||
}
|
||||
$$ = { types: [ 'BOOLEAN' ], suggestFilters: $1.suggestFilters };
|
||||
}
|
||||
| ValueExpression 'NOT' 'BETWEEN' ValueExpression_EDIT 'BETWEEN_AND' ValueExpression
|
||||
{
|
||||
if ($1.types[0] === $6.types[0] && !$4.typeSet) {
|
||||
parser.applyTypeToSuggestions($1.types);
|
||||
}
|
||||
$$ = { types: [ 'BOOLEAN' ], suggestFilters: $4.suggestFilters };
|
||||
}
|
||||
| ValueExpression 'NOT' 'BETWEEN' ValueExpression 'BETWEEN_AND' ValueExpression_EDIT
|
||||
{
|
||||
if ($1.types[0] === $4.types[0] && !$6.typeSet) {
|
||||
parser.applyTypeToSuggestions($1.types);
|
||||
}
|
||||
$$ = { types: [ 'BOOLEAN' ], suggestFilters: $6.suggestFilters };
|
||||
}
|
||||
| ValueExpression 'NOT' 'BETWEEN' ValueExpression 'BETWEEN_AND' 'CURSOR'
|
||||
{
|
||||
parser.valueExpressionSuggest($1, $5);
|
||||
$$ = { types: [ 'BOOLEAN' ], typeSet: true };
|
||||
}
|
||||
| ValueExpression 'NOT' 'BETWEEN' ValueExpression 'CURSOR'
|
||||
{
|
||||
parser.suggestValueExpressionKeywords($4, ['AND']);
|
||||
$$ = { types: [ 'BOOLEAN' ] };
|
||||
}
|
||||
| ValueExpression 'NOT' 'BETWEEN' 'CURSOR'
|
||||
{
|
||||
parser.valueExpressionSuggest($1, $2 + ' ' + $3);
|
||||
$$ = { types: [ 'BOOLEAN' ], typeSet: true };
|
||||
}
|
||||
| ValueExpression_EDIT 'BETWEEN' ValueExpression 'BETWEEN_AND' ValueExpression
|
||||
{
|
||||
if ($1.types[0] === $3.types[0] && !$1.typeSet) {
|
||||
parser.applyTypeToSuggestions($1.types)
|
||||
}
|
||||
$$ = { types: [ 'BOOLEAN' ], suggestFilters: $1.suggestFilters };
|
||||
}
|
||||
| ValueExpression 'BETWEEN' ValueExpression_EDIT 'BETWEEN_AND' ValueExpression
|
||||
{
|
||||
if ($1.types[0] === $3.types[0] && !$3.typeSet) {
|
||||
parser.applyTypeToSuggestions($1.types)
|
||||
}
|
||||
$$ = { types: [ 'BOOLEAN' ], suggestFilters: $3.suggestFilters };
|
||||
}
|
||||
| ValueExpression 'BETWEEN' ValueExpression 'BETWEEN_AND' ValueExpression_EDIT
|
||||
{
|
||||
if ($1.types[0] === $3.types[0] && !$5.typeSet) {
|
||||
parser.applyTypeToSuggestions($1.types)
|
||||
}
|
||||
$$ = { types: [ 'BOOLEAN' ], suggestFilters: $5.suggestFilters };
|
||||
}
|
||||
| ValueExpression 'BETWEEN' ValueExpression 'BETWEEN_AND' 'CURSOR'
|
||||
{
|
||||
parser.valueExpressionSuggest($1, $4);
|
||||
parser.applyTypeToSuggestions($1.types);
|
||||
$$ = { types: [ 'BOOLEAN' ], typeSet: true };
|
||||
}
|
||||
| ValueExpression 'BETWEEN' ValueExpression 'CURSOR'
|
||||
{
|
||||
parser.suggestValueExpressionKeywords($3, ['AND']);
|
||||
$$ = { types: [ 'BOOLEAN' ] };
|
||||
}
|
||||
| ValueExpression 'BETWEEN' 'CURSOR'
|
||||
{
|
||||
parser.valueExpressionSuggest($1, $2);
|
||||
parser.applyTypeToSuggestions($1.types);
|
||||
$$ = { types: [ 'BOOLEAN' ], typeSet: true };
|
||||
}
|
||||
;
|
||||
|
||||
// ------------------ BOOLEAN ------------------
|
||||
|
||||
ValueExpression
|
||||
: ValueExpression 'OR' ValueExpression
|
||||
{
|
||||
// verifyType($1, 'BOOLEAN');
|
||||
// verifyType($3, 'BOOLEAN');
|
||||
$$ = { types: [ 'BOOLEAN' ] };
|
||||
}
|
||||
| ValueExpression 'AND' ValueExpression
|
||||
{
|
||||
// verifyType($1, 'BOOLEAN');
|
||||
// verifyType($3, 'BOOLEAN');
|
||||
$$ = { types: [ 'BOOLEAN' ] };
|
||||
}
|
||||
;
|
||||
|
||||
ValueExpression_EDIT
|
||||
: 'CURSOR' 'OR' ValueExpression
|
||||
{
|
||||
parser.valueExpressionSuggest(undefined, $2);
|
||||
$$ = { types: [ 'BOOLEAN' ], typeSet: true, suggestFilters: true };
|
||||
}
|
||||
| ValueExpression_EDIT 'OR' ValueExpression
|
||||
{
|
||||
parser.addColRefIfExists($3);
|
||||
$$ = { types: [ 'BOOLEAN' ], suggestFilters: $1.suggestFilters }
|
||||
}
|
||||
| ValueExpression 'OR' PartialBacktickedOrAnyCursor
|
||||
{
|
||||
parser.valueExpressionSuggest(undefined, $2);
|
||||
$$ = { types: [ 'BOOLEAN' ], typeSet: true, suggestFilters: true };
|
||||
}
|
||||
| ValueExpression 'OR' ValueExpression_EDIT
|
||||
{
|
||||
parser.addColRefIfExists($1);
|
||||
$$ = { types: [ 'BOOLEAN' ], suggestFilters: $3.suggestFilters }
|
||||
}
|
||||
| 'CURSOR' 'AND' ValueExpression
|
||||
{
|
||||
parser.valueExpressionSuggest(undefined, $2);
|
||||
$$ = { types: [ 'BOOLEAN' ], typeSet: true, suggestFilters: true };
|
||||
}
|
||||
| ValueExpression_EDIT 'AND' ValueExpression
|
||||
{
|
||||
parser.addColRefIfExists($3);
|
||||
$$ = { types: [ 'BOOLEAN' ], suggestFilters: $1.suggestFilters }
|
||||
}
|
||||
| ValueExpression 'AND' PartialBacktickedOrAnyCursor
|
||||
{
|
||||
parser.valueExpressionSuggest(undefined, $2);
|
||||
$$ = { types: [ 'BOOLEAN' ], typeSet: true, suggestFilters: true };
|
||||
}
|
||||
| ValueExpression 'AND' ValueExpression_EDIT
|
||||
{
|
||||
parser.addColRefIfExists($1);
|
||||
$$ = { types: [ 'BOOLEAN' ], suggestFilters: $3.suggestFilters }
|
||||
}
|
||||
;
|
||||
|
||||
// ------------------ ARITHMETIC ------------------
|
||||
|
||||
ValueExpression
|
||||
: ValueExpression '-' ValueExpression
|
||||
{
|
||||
// verifyType($1, 'NUMBER');
|
||||
// verifyType($3, 'NUMBER');
|
||||
$$ = { types: [ 'NUMBER' ] };
|
||||
}
|
||||
| ValueExpression '*' ValueExpression
|
||||
{
|
||||
// verifyType($1, 'NUMBER');
|
||||
// verifyType($3, 'NUMBER');
|
||||
$$ = { types: [ 'NUMBER' ] };
|
||||
}
|
||||
| ValueExpression 'ARITHMETIC_OPERATOR' ValueExpression
|
||||
{
|
||||
// verifyType($1, 'NUMBER');
|
||||
// verifyType($3, 'NUMBER');
|
||||
$$ = { types: [ 'NUMBER' ] };
|
||||
}
|
||||
;
|
||||
|
||||
ValueExpression_EDIT
|
||||
: 'CURSOR' '*' ValueExpression
|
||||
{
|
||||
parser.valueExpressionSuggest(undefined, $2);
|
||||
parser.applyTypeToSuggestions([ 'NUMBER' ]);
|
||||
$$ = { types: [ 'NUMBER' ], typeSet: true };
|
||||
}
|
||||
| 'CURSOR' 'ARITHMETIC_OPERATOR' ValueExpression
|
||||
{
|
||||
parser.valueExpressionSuggest(undefined, $2);
|
||||
parser.applyTypeToSuggestions([ 'NUMBER' ]);
|
||||
$$ = { types: [ 'NUMBER' ], typeSet: true };
|
||||
}
|
||||
| ValueExpression_EDIT '-' ValueExpression
|
||||
{
|
||||
if (!$1.typeSet) {
|
||||
parser.applyTypeToSuggestions(['NUMBER']);
|
||||
parser.addColRefIfExists($3);
|
||||
}
|
||||
$$ = { types: [ 'NUMBER' ], suggestFilters: $1.suggestFilters }
|
||||
}
|
||||
| ValueExpression_EDIT '*' ValueExpression
|
||||
{
|
||||
if (!$1.typeSet) {
|
||||
parser.applyTypeToSuggestions(['NUMBER']);
|
||||
parser.addColRefIfExists($3);
|
||||
}
|
||||
$$ = { types: [ 'NUMBER' ], suggestFilters: $1.suggestFilters }
|
||||
}
|
||||
| ValueExpression_EDIT 'ARITHMETIC_OPERATOR' ValueExpression
|
||||
{
|
||||
if (!$1.typeSet) {
|
||||
parser.applyTypeToSuggestions(['NUMBER']);
|
||||
parser.addColRefIfExists($3);
|
||||
}
|
||||
$$ = { types: [ 'NUMBER' ], suggestFilters: $1.suggestFilters }
|
||||
}
|
||||
| ValueExpression '-' PartialBacktickedOrAnyCursor
|
||||
{
|
||||
parser.valueExpressionSuggest(undefined, $2);
|
||||
parser.applyTypeToSuggestions(['NUMBER']);
|
||||
$$ = { types: [ 'NUMBER' ], typeSet: true };
|
||||
}
|
||||
| ValueExpression '*' PartialBacktickedOrAnyCursor
|
||||
{
|
||||
parser.valueExpressionSuggest(undefined, $2);
|
||||
parser.applyTypeToSuggestions(['NUMBER']);
|
||||
$$ = { types: [ 'NUMBER' ], typeSet: true };
|
||||
}
|
||||
| ValueExpression 'ARITHMETIC_OPERATOR' PartialBacktickedOrAnyCursor
|
||||
{
|
||||
parser.valueExpressionSuggest(undefined, $2);
|
||||
parser.applyTypeToSuggestions(['NUMBER']);
|
||||
$$ = { types: [ 'NUMBER' ], typeSet: true };
|
||||
}
|
||||
| ValueExpression '-' ValueExpression_EDIT
|
||||
{
|
||||
if (!$3.typeSet) {
|
||||
parser.applyTypeToSuggestions(['NUMBER']);
|
||||
parser.addColRefIfExists($1);
|
||||
}
|
||||
$$ = { types: [ 'NUMBER' ], suggestFilters: $3.suggestFilters };
|
||||
}
|
||||
| ValueExpression '*' ValueExpression_EDIT
|
||||
{
|
||||
if (!$3.typeSet) {
|
||||
parser.applyTypeToSuggestions(['NUMBER']);
|
||||
parser.addColRefIfExists($1);
|
||||
}
|
||||
$$ = { types: [ 'NUMBER' ], suggestFilters: $3.suggestFilters };
|
||||
}
|
||||
| ValueExpression 'ARITHMETIC_OPERATOR' ValueExpression_EDIT
|
||||
{
|
||||
if (!$3.typeSet) {
|
||||
parser.applyTypeToSuggestions(['NUMBER']);
|
||||
parser.addColRefIfExists($1);
|
||||
}
|
||||
$$ = { types: [ 'NUMBER' ], suggestFilters: $3.suggestFilters };
|
||||
}
|
||||
;
|
||||
|
||||
// ------------------ LIKE, RLIKE and REGEXP ------------------
|
||||
|
||||
ValueExpression
|
||||
: ValueExpression LikeRightPart -> { types: [ 'BOOLEAN' ] }
|
||||
| ValueExpression 'NOT' LikeRightPart -> { types: [ 'BOOLEAN' ] }
|
||||
;
|
||||
|
||||
LikeRightPart
|
||||
: 'LIKE' ValueExpression -> { suggestKeywords: ['NOT'] }
|
||||
| 'RLIKE' ValueExpression -> { suggestKeywords: ['NOT'] }
|
||||
| 'REGEXP' ValueExpression -> { suggestKeywords: ['NOT'] }
|
||||
;
|
||||
|
||||
LikeRightPart_EDIT
|
||||
: 'LIKE' ValueExpression_EDIT
|
||||
| 'RLIKE' ValueExpression_EDIT
|
||||
| 'REGEXP' ValueExpression_EDIT
|
||||
| 'LIKE' PartialBacktickedOrCursor
|
||||
{
|
||||
parser.suggestFunctions({ types: [ 'STRING' ] });
|
||||
parser.suggestColumns({ types: [ 'STRING' ] });
|
||||
$$ = { types: ['BOOLEAN'] }
|
||||
}
|
||||
| 'RLIKE' PartialBacktickedOrCursor
|
||||
{
|
||||
parser.suggestFunctions({ types: [ 'STRING' ] });
|
||||
parser.suggestColumns({ types: [ 'STRING' ] });
|
||||
$$ = { types: ['BOOLEAN'] }
|
||||
}
|
||||
| 'REGEXP' PartialBacktickedOrCursor
|
||||
{
|
||||
parser.suggestFunctions({ types: [ 'STRING' ] });
|
||||
parser.suggestColumns({ types: [ 'STRING' ] });
|
||||
$$ = { types: ['BOOLEAN'] }
|
||||
}
|
||||
;
|
||||
|
||||
ValueExpression_EDIT
|
||||
: ValueExpression_EDIT LikeRightPart -> { types: [ 'BOOLEAN' ], suggestFilters: $1.suggestFilters }
|
||||
| ValueExpression_EDIT 'NOT' LikeRightPart -> { types: [ 'BOOLEAN' ], suggestFilters: $1.suggestFilters }
|
||||
| ValueExpression LikeRightPart_EDIT -> { types: [ 'BOOLEAN' ] }
|
||||
| ValueExpression 'NOT' LikeRightPart_EDIT -> { types: [ 'BOOLEAN' ] }
|
||||
| 'CURSOR' LikeRightPart
|
||||
{
|
||||
parser.valueExpressionSuggest(undefined, $2);
|
||||
parser.applyTypeToSuggestions([ 'STRING' ]);
|
||||
$$ = { types: [ 'BOOLEAN' ], typeSet: true };
|
||||
}
|
||||
| 'CURSOR' 'NOT' LikeRightPart
|
||||
{
|
||||
parser.valueExpressionSuggest(undefined, $2 + ' ' + $3);
|
||||
parser.applyTypeToSuggestions([ 'STRING' ]);
|
||||
$$ = { types: [ 'BOOLEAN' ], typeSet: true };
|
||||
}
|
||||
;
|
||||
|
||||
// ------------------ CASE, WHEN, THEN ------------------
|
||||
|
||||
ValueExpression
|
||||
: 'CASE' CaseRightPart -> $2
|
||||
| 'CASE' ValueExpression CaseRightPart -> $3
|
||||
;
|
||||
|
||||
ValueExpression_EDIT
|
||||
: 'CASE' CaseRightPart_EDIT -> $2
|
||||
| 'CASE' 'CURSOR' EndOrError
|
||||
{
|
||||
parser.valueExpressionSuggest();
|
||||
parser.suggestKeywords(['WHEN']);
|
||||
$$ = { types: [ 'T' ], typeSet: true };
|
||||
}
|
||||
| 'CASE' ValueExpression CaseRightPart_EDIT -> $3
|
||||
| 'CASE' ValueExpression 'CURSOR' EndOrError
|
||||
{
|
||||
parser.suggestValueExpressionKeywords($2, ['WHEN']);
|
||||
$$ = { types: [ 'T' ], typeSet: true };
|
||||
}
|
||||
| 'CASE' ValueExpression_EDIT CaseRightPart
|
||||
{
|
||||
$$ = $3;
|
||||
$$.suggestFilters = $2.suggestFilters;
|
||||
}
|
||||
| 'CASE' ValueExpression_EDIT EndOrError -> { types: [ 'T' ], suggestFilters: $2.suggestFilters }
|
||||
| 'CASE' 'CURSOR' CaseRightPart -> { types: [ 'T' ] }
|
||||
;
|
||||
|
||||
CaseRightPart
|
||||
: CaseWhenThenList 'END' -> parser.findCaseType($1)
|
||||
| CaseWhenThenList 'ELSE' ValueExpression 'END'
|
||||
{
|
||||
$1.caseTypes.push($3);
|
||||
$$ = parser.findCaseType($1);
|
||||
}
|
||||
;
|
||||
|
||||
CaseRightPart_EDIT
|
||||
: CaseWhenThenList_EDIT EndOrError -> parser.findCaseType($1)
|
||||
| CaseWhenThenList 'ELSE' ValueExpression 'CURSOR'
|
||||
{
|
||||
parser.suggestValueExpressionKeywords($3, ['END']);
|
||||
$1.caseTypes.push($3);
|
||||
$$ = parser.findCaseType($1);
|
||||
}
|
||||
| CaseWhenThenList_EDIT 'ELSE' ValueExpression EndOrError
|
||||
{
|
||||
$1.caseTypes.push($3);
|
||||
$$ = parser.findCaseType($1);
|
||||
}
|
||||
| CaseWhenThenList_EDIT 'ELSE' EndOrError -> parser.findCaseType($1)
|
||||
| CaseWhenThenList 'CURSOR' ValueExpression EndOrError
|
||||
{
|
||||
if ($4.toLowerCase() !== 'end') {
|
||||
parser.suggestValueExpressionKeywords($1, [{ value: 'END', weight: 3 }, { value: 'ELSE', weight: 2 }, { value: 'WHEN', weight: 1 }]);
|
||||
} else {
|
||||
parser.suggestValueExpressionKeywords($1, [{ value: 'ELSE', weight: 2 }, { value: 'WHEN', weight: 1 }]);
|
||||
}
|
||||
$$ = parser.findCaseType($1);
|
||||
}
|
||||
| CaseWhenThenList 'CURSOR' EndOrError
|
||||
{
|
||||
if ($3.toLowerCase() !== 'end') {
|
||||
parser.suggestValueExpressionKeywords($1, [{ value: 'END', weight: 3 }, { value: 'ELSE', weight: 2 }, { value: 'WHEN', weight: 1 }]);
|
||||
} else {
|
||||
parser.suggestValueExpressionKeywords($1, [{ value: 'ELSE', weight: 2 }, { value: 'WHEN', weight: 1 }]);
|
||||
}
|
||||
$$ = parser.findCaseType($1);
|
||||
}
|
||||
| CaseWhenThenList 'ELSE' ValueExpression_EDIT EndOrError
|
||||
{
|
||||
$1.caseTypes.push($3);
|
||||
$$ = parser.findCaseType($1);
|
||||
$$.suggestFilters = $3.suggestFilters
|
||||
}
|
||||
| CaseWhenThenList 'ELSE' 'CURSOR' EndOrError
|
||||
{
|
||||
parser.valueExpressionSuggest();
|
||||
$$ = parser.findCaseType($1);
|
||||
}
|
||||
| 'ELSE' 'CURSOR' EndOrError
|
||||
{
|
||||
parser.valueExpressionSuggest();
|
||||
$$ = { types: [ 'T' ], typeSet: true };
|
||||
}
|
||||
| 'CURSOR' 'ELSE' ValueExpression EndOrError
|
||||
{
|
||||
parser.valueExpressionSuggest();
|
||||
parser.suggestKeywords(['WHEN']);
|
||||
$$ = $3;
|
||||
}
|
||||
| 'CURSOR' 'ELSE' EndOrError
|
||||
{
|
||||
parser.valueExpressionSuggest();
|
||||
parser.suggestKeywords(['WHEN']);
|
||||
$$ = { types: [ 'T' ] };
|
||||
}
|
||||
;
|
||||
|
||||
EndOrError
|
||||
: 'END'
|
||||
| error
|
||||
;
|
||||
|
||||
CaseWhenThenList
|
||||
: CaseWhenThenListPartTwo -> { caseTypes: [ $1 ], lastType: $1 }
|
||||
| CaseWhenThenList CaseWhenThenListPartTwo
|
||||
{
|
||||
$1.caseTypes.push($2);
|
||||
$$ = { caseTypes: $1.caseTypes, lastType: $2 };
|
||||
}
|
||||
;
|
||||
|
||||
CaseWhenThenList_EDIT
|
||||
: CaseWhenThenListPartTwo_EDIT
|
||||
| CaseWhenThenList CaseWhenThenListPartTwo_EDIT
|
||||
| CaseWhenThenList CaseWhenThenListPartTwo_EDIT CaseWhenThenList
|
||||
| CaseWhenThenList 'CURSOR' CaseWhenThenList
|
||||
{
|
||||
parser.suggestValueExpressionKeywords($1, ['WHEN']);
|
||||
}
|
||||
| CaseWhenThenListPartTwo_EDIT CaseWhenThenList -> $2
|
||||
;
|
||||
|
||||
CaseWhenThenListPartTwo
|
||||
: 'WHEN' ValueExpression 'THEN' ValueExpression -> $4
|
||||
;
|
||||
|
||||
CaseWhenThenListPartTwo_EDIT
|
||||
: 'WHEN' ValueExpression_EDIT -> { caseTypes: [{ types: ['T'] }], suggestFilters: $2.suggestFilters }
|
||||
| 'WHEN' ValueExpression_EDIT 'THEN' -> { caseTypes: [{ types: ['T'] }], suggestFilters: $2.suggestFilters }
|
||||
| 'WHEN' ValueExpression_EDIT 'THEN' ValueExpression -> { caseTypes: [$4], suggestFilters: $2.suggestFilters }
|
||||
| 'WHEN' ValueExpression 'THEN' ValueExpression_EDIT -> { caseTypes: [$4], suggestFilters: $4.suggestFilters }
|
||||
| 'WHEN' 'THEN' ValueExpression_EDIT -> { caseTypes: [$3], suggestFilters: $3.suggestFilters }
|
||||
| 'CURSOR' ValueExpression 'THEN'
|
||||
{
|
||||
parser.suggestKeywords(['WHEN']);
|
||||
$$ = { caseTypes: [{ types: ['T'] }] };
|
||||
}
|
||||
| 'CURSOR' ValueExpression 'THEN' ValueExpression
|
||||
{
|
||||
parser.suggestKeywords(['WHEN']);
|
||||
$$ = { caseTypes: [$4] };
|
||||
}
|
||||
| 'CURSOR' 'THEN'
|
||||
{
|
||||
parser.valueExpressionSuggest();
|
||||
parser.suggestKeywords(['WHEN']);
|
||||
$$ = { caseTypes: [{ types: ['T'] }] };
|
||||
}
|
||||
| 'CURSOR' 'THEN' ValueExpression
|
||||
{
|
||||
parser.valueExpressionSuggest();
|
||||
parser.suggestKeywords(['WHEN']);
|
||||
$$ = { caseTypes: [{ types: ['T'] }] };
|
||||
}
|
||||
| 'WHEN' 'CURSOR'
|
||||
{
|
||||
parser.valueExpressionSuggest();
|
||||
$$ = { caseTypes: [{ types: ['T'] }], suggestFilters: true };
|
||||
}
|
||||
| 'WHEN' 'CURSOR' ValueExpression
|
||||
{
|
||||
parser.valueExpressionSuggest();
|
||||
parser.suggestKeywords(['THEN']);
|
||||
$$ = { caseTypes: [{ types: ['T'] }], suggestFilters: true };
|
||||
}
|
||||
| 'WHEN' 'CURSOR' 'THEN'
|
||||
{
|
||||
parser.valueExpressionSuggest();
|
||||
$$ = { caseTypes: [{ types: ['T'] }], suggestFilters: true };
|
||||
}
|
||||
| 'WHEN' 'CURSOR' 'THEN' ValueExpression
|
||||
{
|
||||
parser.valueExpressionSuggest();
|
||||
$$ = { caseTypes: [$4], suggestFilters: true };
|
||||
}
|
||||
| 'WHEN' ValueExpression 'CURSOR'
|
||||
{
|
||||
parser.suggestValueExpressionKeywords($2, ['THEN']);
|
||||
$$ = { caseTypes: [{ types: ['T'] }] };
|
||||
}
|
||||
| 'WHEN' ValueExpression 'CURSOR' ValueExpression
|
||||
{
|
||||
parser.suggestValueExpressionKeywords($2, ['THEN']);
|
||||
$$ = { caseTypes: [{ types: ['T'] }] };
|
||||
}
|
||||
| 'WHEN' ValueExpression 'THEN' 'CURSOR'
|
||||
{
|
||||
parser.valueExpressionSuggest();
|
||||
$$ = { caseTypes: [{ types: ['T'] }] };
|
||||
}
|
||||
| 'WHEN' ValueExpression 'THEN' 'CURSOR' ValueExpression
|
||||
{
|
||||
parser.valueExpressionSuggest();
|
||||
$$ = { caseTypes: [{ types: ['T'] }] };
|
||||
}
|
||||
| 'WHEN' 'THEN' 'CURSOR' ValueExpression
|
||||
{
|
||||
parser.valueExpressionSuggest();
|
||||
$$ = { caseTypes: [{ types: ['T'] }] };
|
||||
}
|
||||
| 'WHEN' 'THEN' 'CURSOR'
|
||||
{
|
||||
parser.valueExpressionSuggest();
|
||||
$$ = { caseTypes: [{ types: ['T'] }] };
|
||||
}
|
||||
;
|
19
src/jison/sql/generic/syntax_footer.jison
Normal file
19
src/jison/sql/generic/syntax_footer.jison
Normal file
@ -0,0 +1,19 @@
|
||||
// Licensed to Cloudera, Inc. under one
|
||||
// or more contributor license agreements. See the NOTICE file
|
||||
// distributed with this work for additional information
|
||||
// regarding copyright ownership. Cloudera, Inc. licenses this file
|
||||
// to you under the Apache License, Version 2.0 (the
|
||||
// "License"); you may not use this file except in compliance
|
||||
// with the License. You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
%%
|
||||
|
||||
SqlParseSupport.initSyntaxParser(parser);
|
28
src/jison/sql/generic/syntax_header.jison
Normal file
28
src/jison/sql/generic/syntax_header.jison
Normal file
@ -0,0 +1,28 @@
|
||||
// Licensed to Cloudera, Inc. under one
|
||||
// or more contributor license agreements. See the NOTICE file
|
||||
// distributed with this work for additional information
|
||||
// regarding copyright ownership. Cloudera, Inc. licenses this file
|
||||
// to you under the Apache License, Version 2.0 (the
|
||||
// "License"); you may not use this file except in compliance
|
||||
// with the License. You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
%left 'AND' 'OR'
|
||||
%left 'BETWEEN'
|
||||
%left 'NOT' '!' '~'
|
||||
%left '=' '<' '>' 'COMPARISON_OPERATOR'
|
||||
%left '-' '*' 'ARITHMETIC_OPERATOR'
|
||||
|
||||
%left ';' ','
|
||||
%nonassoc 'IN' 'IS' 'LIKE' 'RLIKE' 'REGEXP' 'EXISTS' NEGATION
|
||||
|
||||
%start SqlSyntax
|
||||
|
||||
%%
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user