This commit is contained in:
HSunboy 2018-08-16 18:02:51 +08:00
parent 12f1595850
commit d7aa6a3e60
29 changed files with 24501 additions and 0 deletions

9
core/index.html Normal file
View File

@ -0,0 +1,9 @@
<html>
<head>
</head>
<body>
1
</body>
<script src="./sqlSyntaxParser.js"></script>
</html>

9191
core/sqlSyntaxParser.js Normal file

File diff suppressed because one or more lines are too long

19
jison/autocomplete_footer.jison Executable file
View 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
jison/autocomplete_header.jison Executable file
View 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' '<impala>ILIKE' '<impala>IREGEXP' 'LIKE' 'RLIKE' 'REGEXP' 'EXISTS' NEGATION
%start SqlAutocomplete
%%

179
jison/globalSearchParser.jison Executable file
View File

@ -0,0 +1,179 @@
// 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.
%lex
%x singleQuote doubleQuote
%%
\s+ { return 'WS' }
'\u2020' { parser.yy.cursorFound = yylloc; return 'CURSOR'; }
[a-zA-Z]+[:] { return 'FACET' }
\' { this.begin('singleQuote'); return 'QUOTE'; }
<singleQuote>(?:\\[']|[^'])+ {
if (parser.handleQuotedValueWithCursor(this, yytext, yylloc, '\'')) {
return 'PARTIAL_VALUE';
}
return 'VALUE';
}
<singleQuote>\' { this.popState(); return 'QUOTE'; }
\" { this.begin('doubleQuote'); return 'QUOTE'; }
<doubleQuote>(?:\\["]|[^"])+ {
if (parser.handleQuotedValueWithCursor(this, yytext, yylloc, '"')) {
return 'PARTIAL_VALUE';
}
return 'VALUE';
}
<doubleQuote>\" { this.popState(); return 'QUOTE'; }
[^"'\s\u2020]+ { return 'TEXT'; }
<<EOF>> { return 'EOF'; }
/lex
%start GlobalSearchAutocomplete
%%
GlobalSearchAutocomplete
: OptionalWhitespace SearchParts OptionalWhitespace 'EOF'
{
return $2;
}
| OptionalWhitespace SearchParts_EDIT 'EOF'
{
if (!$2.facets) {
$2.facets = {};
}
if (!$2.text) {
$2.text = [];
}
return $2;
}
| OptionalWhitespace 'EOF'
{
return { facets: {}, text: [] };
}
;
SearchParts
: SearchPart
| SearchParts WS SearchPart
{
parser.mergeFacets($1, $3);
parser.mergeText($1, $3);
}
;
SearchParts_EDIT
: SearchPart_EDIT
| SearchParts WS SearchPart_EDIT
{
parser.mergeFacets($1, $3);
parser.mergeText($1, $3);
$$ = $3;
$$.text = $1.text;
$$.facets = $1.facets;
}
| SearchPart_EDIT WS SearchParts
{
$$ = $1;
parser.mergeFacets($$, $3);
parser.mergeText($$, $3);
}
| SearchParts WS SearchPart_EDIT WS SearchParts
{
parser.mergeFacets($1, $3);
parser.mergeFacets($1, $5);
parser.mergeText($1, $3);
parser.mergeText($1, $5);
$$ = $3;
$$.text = $1.text;
$$.facets = $1.facets;
}
;
SearchPart
: Facet --> { text: [], facets: $1.facets }
| FreeText --> { text: [$1], facets: {} }
;
SearchPart_EDIT
: Facet_EDIT
| FreeText_EDIT
;
Facet
: 'FACET' OptionalWhitespace FreeText
{
var facet = {};
var facetName = $1.substring(0, $1.length - 1).toLowerCase();
facet[facetName] = {};
facet[facetName][$3.toLowerCase()] = true;
$$ = { facets: facet };
}
;
Facet_EDIT
: 'FACET' OptionalWhitespace 'CURSOR' --> { suggestFacetValues: $1.substring(0, $1.length - 1).toLowerCase() }
| 'FACET' OptionalWhitespace FreeText 'CURSOR'
{
var facet = {};
var facetName = $1.substring(0, $1.length - 1).toLowerCase();
facet[facetName] = {};
facet[facetName][$3.toLowerCase()] = true;
$$ = { suggestFacetValues: facetName, facets: facet }
}
;
FreeText
: 'TEXT'
| QuotedValue
;
FreeText_EDIT
: 'CURSOR' --> { suggestFacets: true, suggestResults: true }
| 'CURSOR' 'TEXT' --> { suggestFacets: true, suggestResults: true, text: [$2] }
| 'TEXT' 'CURSOR' 'TEXT' --> { suggestFacets: true, suggestResults: true, text: [$1+$3] }
| 'TEXT' 'CURSOR' --> { suggestFacets: true, suggestResults: true, text: [$1] }
| QuotedValue_EDIT
;
QuotedValue
: 'QUOTE' 'VALUE' 'QUOTE' --> $2
| 'QUOTE' 'QUOTE' --> ''
;
QuotedValue_EDIT
: 'QUOTE' 'PARTIAL_VALUE' --> $2
;
OptionalWhitespace
:
| WS
;
%%
SqlParseSupport.initGlobalSearchParser(parser);

37
jison/hue-sql-syntax.sh Executable file
View File

@ -0,0 +1,37 @@
#!/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!"

15
jison/license.txt Executable file
View File

@ -0,0 +1,15 @@
// 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.

265
jison/solrFormulaParser.jison Executable file
View File

@ -0,0 +1,265 @@
// 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.
%lex
%options case-insensitive
%%
\s { /* skip whitespace */ }
'--'.* { /* skip comments */ }
[/][*][^*]*[*]+([^/*][^*]*[*]+)*[/] { /* skip comments */ }
'\u2020' { parser.yy.cursorFound = yylloc; return 'CURSOR'; }
[0-9]+(?:[,.][0-9]+)? { return 'NUMBER'; }
'-' { return '-'; }
'+' { return '+'; }
'*' { return '*'; }
'/' { return '/'; }
[a-z]+\s*\( {
yy.lexer.unput('(');
parser.addFunctionLocation({
first_line: yylloc.first_line,
first_column: yylloc.first_column,
last_line: yylloc.first_line,
last_column: yylloc.first_column + yytext.trim().length
}, yytext.trim());
return 'FUNCTION';
}
',' { return ','; }
'(' { return '('; }
')' { return ')'; }
<<EOF>> { return 'EOF'; }
[^\s\u2020()]+ { parser.addFieldLocation(yylloc, yytext); return 'IDENTIFIER'; }
/lex
%left '+' '-'
%left '*' '/'
%start SolrFormulaAutocomplete
%%
SolrFormulaAutocomplete
: SolrFormula 'EOF'
{
return {
parsedValue: $1
};
}
| SolrFormula_EDIT 'EOF'
{
return $1
}
| 'CURSOR' 'EOF'
{
return { suggestAggregateFunctions: true }
}
;
SolrFormula
: NonParenthesizedSolrFormula
| '(' NonParenthesizedSolrFormula ')' -> $1 + $2 + $3
;
SolrFormula_EDIT
: NonParenthesizedSolrFormula_EDIT
| '(' NonParenthesizedSolrFormula_EDIT RightParenthesisOrError --> $2
;
NonParenthesizedSolrFormula
: 'NUMBER'
| 'IDENTIFIER'
| 'FUNCTION' '(' ArgumentList ')' -> $1 + $2 + $3 + $4
| SolrFormula '+' SolrFormula -> 'sum(' + $1 + ',' + $3 + ')'
| SolrFormula '-' SolrFormula -> 'sub(' + $1 + ',' + $3 + ')'
| SolrFormula '*' SolrFormula -> 'mul(' + $1 + ',' + $3 + ')'
| SolrFormula '/' SolrFormula -> 'div(' + $1 + ',' + $3 + ')'
| '-' SolrFormula -> 'sub(0,' + $2 + ')'
;
NonParenthesizedSolrFormula_EDIT
: 'NUMBER' 'CURSOR' --> { suggestOperators: true }
| 'IDENTIFIER' 'CURSOR' --> { suggestOperators: true }
| 'CURSOR' 'NUMBER' --> { suggestAggregateFunctions: true, suggestFunctions: true, suggestFields: true }
| 'CURSOR' 'IDENTIFIER' --> { suggestAggregateFunctions: true, suggestFunctions: true, suggestFields: true }
;
NonParenthesizedSolrFormula_EDIT
: 'FUNCTION' '(' 'CURSOR' RightParenthesisOrError --> { suggestAggregateFunctions: true, suggestFunctions: true, suggestFields: true }
| 'FUNCTION' '(' ArgumentList_EDIT RightParenthesisOrError --> $3
| 'FUNCTION' '(' ArgumentList ')' 'CURSOR' --> { suggestOperators: true }
;
NonParenthesizedSolrFormula_EDIT
: SolrFormula '+' 'CURSOR' --> { suggestAggregateFunctions: true, suggestFunctions: true, suggestFields: true }
| 'CURSOR' '+' SolrFormula --> { suggestAggregateFunctions: true, suggestFunctions: true, suggestFields: true }
| SolrFormula_EDIT '+' SolrFormula --> $1
| SolrFormula '+' SolrFormula_EDIT --> $3
;
NonParenthesizedSolrFormula_EDIT
: SolrFormula '-' 'CURSOR' --> { suggestAggregateFunctions: true, suggestFunctions: true, suggestFields: true }
| 'CURSOR' '-' SolrFormula --> { suggestAggregateFunctions: true, suggestFunctions: true, suggestFields: true }
| SolrFormula_EDIT '-' SolrFormula --> $1
| SolrFormula '-' SolrFormula_EDIT --> $3
;
NonParenthesizedSolrFormula_EDIT
: SolrFormula '*' 'CURSOR' --> { suggestAggregateFunctions: true, suggestFunctions: true, suggestFields: true }
| 'CURSOR' '*' SolrFormula --> { suggestAggregateFunctions: true, suggestFunctions: true, suggestFields: true }
| SolrFormula_EDIT '*' SolrFormula --> $1
| SolrFormula '*' SolrFormula_EDIT --> $3
;
NonParenthesizedSolrFormula_EDIT
: SolrFormula '/' 'CURSOR' --> { suggestAggregateFunctions: true, suggestFunctions: true, suggestFields: true }
| 'CURSOR' '/' SolrFormula --> { suggestAggregateFunctions: true, suggestFunctions: true, suggestFields: true }
| SolrFormula_EDIT '/' SolrFormula --> $1
| SolrFormula '/' SolrFormula_EDIT --> $3
;
NonParenthesizedSolrFormula_EDIT
: '-' 'CURSOR' --> { suggestAggregateFunctions: true, suggestFunctions: true, suggestFields: true }
| '-' SolrFormula_EDIT --> $2
;
ArgumentList
: SolrFormula
| ArgumentList ',' SolrFormula
;
ArgumentList_EDIT
: SolrFormula_EDIT
| ArgumentList ',' SolrFormula_EDIT --> $3
| SolrFormula_EDIT ',' ArgumentList
| ArgumentList ',' SolrFormula_EDIT ',' ArgumentList --> $3
;
RightParenthesisOrError
: ')'
| error
;
%%
parser.yy.parseError = function () { return false; }
parser.identifyPartials = function (beforeCursor, afterCursor) {
var beforeMatch = beforeCursor.match(/[^()-*+/,\s]*$/);
var afterMatch = afterCursor.match(/^[^()-*+/,\s]*/);
return {left: beforeMatch ? beforeMatch[0].length : 0, right: afterMatch ? afterMatch[0].length : 0};
};
var adjustLocationForCursor = function (location) {
// columns are 0-based and lines not, so add 1 to cols
var newLocation = {
first_line: location.first_line,
last_line: location.last_line,
first_column: location.first_column + 1,
last_column: location.last_column + 1
};
if (parser.yy.cursorFound) {
if (parser.yy.cursorFound.first_line === newLocation.first_line && parser.yy.cursorFound.last_column <= newLocation.first_column) {
var additionalSpace = parser.yy.partialLengths.left + parser.yy.partialLengths.right;
additionalSpace -= parser.yy.partialCursor ? 1 : 3; // For some reason the normal cursor eats 3 positions.
newLocation.first_column = newLocation.first_column + additionalSpace;
newLocation.last_column = newLocation.last_column + additionalSpace;
}
}
return newLocation;
};
parser.addFunctionLocation = function (location, name) {
parser.yy.locations.push({ type: 'function', name: name, location: adjustLocationForCursor(location) });
}
parser.addFieldLocation = function (location, name) {
parser.yy.locations.push({ type: 'field', name: name, location: adjustLocationForCursor(location) });
}
parser.parseSolrFormula = function (formula, debug) {
parser.yy.cursorFound = false;
parser.yy.locations = [];
formula = formula.replace(/\r\n|\n\r/gm, '\n');
var result;
try {
result = parser.parse(formula);
} catch (err) {
if (debug) {
console.log(beforeCursor + '\u2020' + afterCursor);
console.log(err);
console.error(err.stack);
}
}
return result || false;
}
parser.autocompleteSolrFormula = function (beforeCursor, afterCursor, debug) {
parser.yy.cursorFound = false;
parser.yy.locations = [];
beforeCursor = beforeCursor.replace(/\r\n|\n\r/gm, '\n');
afterCursor = afterCursor.replace(/\r\n|\n\r/gm, '\n');
parser.yy.partialLengths = parser.identifyPartials(beforeCursor, afterCursor);
if (parser.yy.partialLengths.left > 0) {
beforeCursor = beforeCursor.substring(0, beforeCursor.length - parser.yy.partialLengths.left);
}
if (parser.yy.partialLengths.right > 0) {
afterCursor = afterCursor.substring(parser.yy.partialLengths.right);
}
var result;
try {
result = parser.parse(beforeCursor + '\u2020' + afterCursor);
} catch (err) {
// Workaround for too many missing parentheses (it's the only error we handle in the parser)
if (err && err.toString().indexOf('Parsing halted while starting to recover from another error') !== -1) {
var leftCount = (beforeCursor.match(/\(/g) || []).length;
var rightCount = (beforeCursor.match(/\)/g) || []).length;
var parenthesisPad = '';
while (rightCount < leftCount) {
parenthesisPad += ')';
rightCount++;
}
try {
result = parser.parse(beforeCursor + '\u2020' + parenthesisPad);
} catch (err) {
return {}
}
} else {
if (debug) {
console.log(beforeCursor + '\u2020' + afterCursor);
console.log(err);
console.error(err.stack);
}
return {}
}
}
result.locations = parser.yy.locations;
return result;
};

292
jison/solrQueryParser.jison Executable file
View File

@ -0,0 +1,292 @@
// 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.
%lex
%options case-insensitive flex
%x squareBracketRange curlyBracketRange doubleQuotedValue singleQuotedValue
%%
\s { /* skip whitespace */ }
'--'.* { /* skip comments */ }
[/][*][^*]*[*]+([^/*][^*]*[*]+)*[/] { /* skip comments */ }
'\u2020' { parser.yy.cursorFound = yylloc; return 'CURSOR'; }
'AND' { return 'AND'; }
'&&' { return 'AND'; }
'OR' { return 'OR'; }
'||' { return 'OR'; }
'NOT' { return 'NOT'; }
'!' { return 'NOT'; }
'+' { return '+'; }
'-' { return '-'; }
':' { return ':'; }
'*' { return '*'; }
'(' { return '('; }
')' { return ')'; }
[0-9]+(?:[,.][0-9]+)? { return 'NUMBER'; }
'[' { this.begin('squareBracketRange'); return '['; }
<squareBracketRange>(?:\\[\]]|[^\]])+ {
if (parser.handleQuotedValueWithCursor(this, yytext, yylloc, ']')) {
return 'PARTIAL_VALUE';
}
return 'VALUE';
}
<singleQuotedValue>\] { this.popState(); return ']'; }
'{' { this.begin('curlyBracketRange'); return '{'; }
<curlyBracketRange>(?:\\[\}]|[^\}])+ {
if (parser.handleQuotedValueWithCursor(this, yytext, yylloc, '}')) {
return 'PARTIAL_VALUE';
}
return 'VALUE';
}
<curlyBracketRange>\} { this.popState(); return '}'; }
\' { this.begin('singleQuotedValue'); return 'SINGLE_QUOTE'; }
<singleQuotedValue>(?:\\[']|[^'])+ {
if (parser.handleQuotedValueWithCursor(this, yytext, yylloc, '\'')) {
yytext = yytext.replace(/[\u2020].*/, '');
return 'PARTIAL_VALUE';
}
return 'VALUE';
}
<singleQuotedValue>\' { this.popState(); return 'SINGLE_QUOTE'; }
\" { this.begin('doubleQuotedValue'); return 'DOUBLE_QUOTE'; }
<doubleQuotedValue>(?:\\["]|[^"])+ {
if (parser.handleQuotedValueWithCursor(this, yytext, yylloc, '"')) {
yytext = yytext.replace(/[\u2020].*/, '');
return 'PARTIAL_VALUE';
}
return 'VALUE';
}
<doubleQuotedValue>\" { this.popState(); return 'DOUBLE_QUOTE'; }
[^\s\u3000!():"'^+\-\[\]{}~*?/\u2020]+ { return 'TERM'; }
<<EOF>> { return 'EOF'; }
/lex
%left 'AND' 'OR' '&&' '||' BooleanOperator
%left 'CURSOR' // Cursor precedence needed to not conflict with operators i.e. x 'CURSOR' y vs. x 'AND' y
%start SolrQueryAutocomplete
%%
SolrQueryAutocomplete
: SolrQuery 'EOF'
{
return {}
}
| SolrQuery_EDIT 'EOF'
{
return $1;
}
| 'CURSOR' 'EOF'
{
return { suggestFields: { appendColon: true } }
}
;
SolrQuery
: NonParenthesizedSolrQuery
| '(' NonParenthesizedSolrQuery ')' --> $2
;
SolrQuery_EDIT
: NonParenthesizedSolrQuery_EDIT
| '(' NonParenthesizedSolrQuery_EDIT RightParenthesisOrError --> $2
;
NonParenthesizedSolrQuery
: 'NUMBER'
| 'TERM'
| KeywordMatch --> { hasKeywordMatch: true }
;
NonParenthesizedSolrQuery_EDIT
: KeywordMatch_EDIT
;
NonParenthesizedSolrQuery
: SolrQuery BooleanOperator SolrQuery
;
NonParenthesizedSolrQuery_EDIT
: SolrQuery 'CURSOR'
{
if ($1.hasKeywordMatch) {
$$ = { suggestKeywords: ['AND', 'OR'] };
} else {
$$ = { suggestKeywords: ['AND', 'OR', ':'], suggestValues: { field: $1, prependColon: true } };
}
}
| SolrQuery 'CURSOR' SolrQuery
{
if ($1.hasKeywordMatch) {
$$ = { suggestKeywords: ['AND', 'OR'] };
} else {
$$ = { suggestKeywords: ['AND', 'OR', ':'], suggestValues: { field: $1, prependColon: true } };
}
}
| 'CURSOR' SolrQuery --> { suggestFields: { appendColon: true } }
;
NonParenthesizedSolrQuery_EDIT
: SolrQuery BooleanOperator 'CURSOR' --> { suggestFields: { appendColon: true } }
| 'CURSOR' BooleanOperator SolrQuery --> { suggestFields: { appendColon: true } }
| SolrQuery BooleanOperator SolrQuery_EDIT --> $3
| SolrQuery_EDIT BooleanOperator SolrQuery --> $1
;
KeywordMatch
: 'TERM' ':' 'TERM'
| 'TERM' ':' QuotedValue
;
KeywordMatch_EDIT
: 'TERM' ':' 'CURSOR' --> { suggestValues: { field: $1 } }
| 'TERM' ':' QuotedValue_EDIT --> { suggestValues: { field: $1, quotePresent: true, partial: $3 } }
;
// ======= Common constructs =======
BooleanOperator
: 'AND' | 'OR' | '&&' | '||';
QuotedValue
: 'SINGLE_QUOTE' 'VALUE' 'SINGLE_QUOTE' --> $2
| 'DOUBLE_QUOTE' 'VALUE' 'DOUBLE_QUOTE' --> $2
;
QuotedValue_EDIT
: 'SINGLE_QUOTE' 'PARTIAL_VALUE' --> $2
| 'DOUBLE_QUOTE' 'PARTIAL_VALUE' --> $2
;
RightParenthesisOrError: ')' | error;
%%
parser.yy.parseError = function () { return false; }
parser.addFieldLocation = function (location, name) {
parser.yy.locations.push({ type: 'field', name: name, location: adjustLocationForCursor(location) });
}
parser.identifyPartials = function (beforeCursor, afterCursor) {
var beforeMatch = beforeCursor.match(/[^()-*+/,:"'\s]*$/);
var afterMatch = afterCursor.match(/^[^()-*+/,:"'\s]*/);
return { left: beforeMatch ? beforeMatch[0].length : 0, right: afterMatch ? afterMatch[0].length : 0 };
};
parser.handleQuotedValueWithCursor = function (lexer, yytext, yylloc, quoteChar) {
if (yytext.indexOf('\u2020') !== -1) {
var cursorIndex = yytext.indexOf('\u2020');
parser.yy.cursorFound = {
first_line: yylloc.first_line,
last_line: yylloc.last_line,
first_column: yylloc.first_column + cursorIndex,
last_column: yylloc.first_column + cursorIndex + 1
};
var remainder = yytext.substring(cursorIndex + 1);
var remainingQuotes = (lexer.upcomingInput().match(new RegExp(quoteChar, 'g')) || []).length;
if (remainingQuotes > 0 && remainingQuotes & 1 != 0) {
parser.yy.missingEndQuote = false;
lexer.input();
} else {
parser.yy.missingEndQuote = true;
lexer.unput(remainder);
}
lexer.popState();
return true;
}
return false;
};
var adjustLocationForCursor = function (location) {
// columns are 0-based and lines not, so add 1 to cols
var newLocation = {
first_line: location.first_line,
last_line: location.last_line,
first_column: location.first_column + 1,
last_column: location.last_column + 1
};
if (parser.yy.cursorFound) {
if (parser.yy.cursorFound.first_line === newLocation.first_line && parser.yy.cursorFound.last_column <= newLocation.first_column) {
var additionalSpace = parser.yy.partialLengths.left + parser.yy.partialLengths.right;
additionalSpace -= parser.yy.partialCursor ? 1 : 3; // For some reason the normal cursor eats 3 positions.
newLocation.first_column = newLocation.first_column + additionalSpace;
newLocation.last_column = newLocation.last_column + additionalSpace;
}
}
return newLocation;
};
parser.autocompleteSolrQuery = function (beforeCursor, afterCursor, debug) {
parser.yy.cursorFound = false;
parser.yy.locations = [];
beforeCursor = beforeCursor.replace(/\r\n|\n\r/gm, '\n');
afterCursor = afterCursor.replace(/\r\n|\n\r/gm, '\n');
parser.yy.partialLengths = parser.identifyPartials(beforeCursor, afterCursor);
parser.yy.partialCursor = parser.yy.partialLengths.left > 0;
if (parser.yy.partialLengths.left > 0) {
beforeCursor = beforeCursor.substring(0, beforeCursor.length - parser.yy.partialLengths.left);
}
if (parser.yy.partialLengths.right > 0) {
afterCursor = afterCursor.substring(parser.yy.partialLengths.right);
}
var result;
try {
result = parser.parse(beforeCursor + '\u2020' + afterCursor);
} catch (err) {
// Workaround for too many missing parentheses (it's the only error we handle in the parser)
if (err && err.toString().indexOf('Parsing halted while starting to recover from another error') !== -1) {
var leftCount = (beforeCursor.match(/\(/g) || []).length;
var rightCount = (beforeCursor.match(/\)/g) || []).length;
var parenthesisPad = '';
while (rightCount < leftCount) {
parenthesisPad += ')';
rightCount++;
}
try {
result = parser.parse(beforeCursor + '\u2020' + parenthesisPad);
} catch (err) {
return { locations: parser.yy.locations }
}
} else {
if (debug) {
console.log(beforeCursor + '\u2020' + afterCursor);
console.log(err);
console.error(err.stack);
}
return { locations: parser.yy.locations }
}
}
result.locations = parser.yy.locations;
return result;
};

550
jison/sql.jisonlex Executable file
View File

@ -0,0 +1,550 @@
// 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 hive impala
%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'; }
// Reserved Keywords
<hive>'ALL' { return '<hive>ALL'; }
<hive>'ARRAY' { return 'ARRAY'; }
<hive>'AS' { return '<hive>AS'; }
<hive>'AUTHORIZATION' { return '<hive>AUTHORIZATION'; }
<hive>'BINARY' { return '<hive>BINARY'; }
<hive>'CACHE' { return '<hive>CACHE'; }
<hive>'COLUMN' { return '<hive>COLUMN'; }
<hive>'CONF' { return '<hive>CONF'; }
<hive>'CONSTRAINT' { return '<hive>CONSTRAINT'; }
<hive>'CREATE' { parser.determineCase(yytext); return '<hive>CREATE'; }
<hive>'CUBE' { return '<hive>CUBE'; }
<hive>'CURRENT' { return '<hive>CURRENT'; }
<hive>'DATE' { return '<hive>DATE'; }
<hive>'DELETE' { parser.determineCase(yytext); return '<hive>DELETE'; }
<hive>'DESCRIBE' { parser.determineCase(yytext); return '<hive>DESCRIBE'; }
<hive>'EXTENDED' { return '<hive>EXTENDED'; }
<hive>'EXTERNAL' { return '<hive>EXTERNAL'; }
<hive>'FOR' { return '<hive>FOR'; }
<hive>'FOREIGN' { return '<hive>FOREIGN'; }
<hive>'FUNCTION' { return '<hive>FUNCTION'; }
<hive>'GRANT' { return '<hive>GRANT'; }
<hive>'GROUPING' { return '<hive>GROUPING'; }
<hive>'IMPORT' { parser.determineCase(yytext); return '<hive>IMPORT'; }
<hive>'INSERT' { parser.determineCase(yytext); return '<hive>INSERT'; }
<hive>'LATERAL' { return '<hive>LATERAL'; }
<hive>'LOCAL' { return '<hive>LOCAL'; }
<hive>'MACRO' { return '<hive>MACRO'; }
<hive>'MAP' { return 'MAP'; }
<hive>'NONE' { return '<hive>NONE'; }
<hive>'OF' { return '<hive>OF'; }
<hive>'OUT' { return '<hive>OUT'; }
<hive>'PRIMARY' { return '<hive>PRIMARY'; }
<hive>'REFERENCES' { return '<hive>REFERENCES'; }
<hive>'REVOKE' { return '<hive>REVOKE'; }
<hive>'ROLLUP' { return '<hive>ROLLUP'; }
<hive>'TABLE' { return '<hive>TABLE'; }
<hive>'TIMESTAMP' { return '<hive>TIMESTAMP'; }
<hive>'USER' { return '<hive>USER'; }
<hive>'USING' { return '<hive>USING'; }
<hive>'VIEWS' { return '<hive>VIEWS'; }
<hive>'LIFECYCLE' { return '<hive>LIFECYCLE'; }
// Non-reserved Keywords
<hive>'ABORT' { parser.determineCase(yytext); return '<hive>ABORT'; }
<hive>'ADD' { return '<hive>ADD'; }
<hive>'ADMIN' { return '<hive>ADMIN'; }
<hive>'AFTER' { return '<hive>AFTER'; }
<hive>'ANALYZE' { parser.determineCase(yytext); return '<hive>ANALYZE'; }
<hive>'ARCHIVE' { return '<hive>ARCHIVE'; }
<hive>'ASC' { return '<hive>ASC'; }
<hive>'AVRO' { return '<hive>AVRO'; }
<hive>'BUCKET' { return '<hive>BUCKET'; }
<hive>'BUCKETS' { return '<hive>BUCKETS'; }
<hive>'CASCADE' { return '<hive>CASCADE'; }
<hive>'CHANGE' { return '<hive>CHANGE'; }
<hive>'CLUSTER' { return '<hive>CLUSTER'; }
<hive>'CLUSTERED' { return '<hive>CLUSTERED'; }
<hive>'COLLECTION' { return '<hive>COLLECTION'; }
<hive>'COLUMNS' { return '<hive>COLUMNS'; }
<hive>'COMMENT' { return '<hive>COMMENT'; }
<hive>'COMPACT' { return '<hive>COMPACT'; }
<hive>'COMPACTIONS' { return '<hive>COMPACTIONS'; }
<hive>'COMPUTE' { return '<hive>COMPUTE'; }
<hive>'CONCATENATE' { return '<hive>CONCATENATE'; }
<hive>'DATA' { return '<hive>DATA'; }
<hive>'DATABASES' { return '<hive>DATABASES'; }
<hive>'DAY' { return '<hive>DAY'; }
<hive>'DAYOFWEEK' { return '<hive>DAYOFWEEK'; }
<hive>'DBPROPERTIES' { return '<hive>DBPROPERTIES'; }
<hive>'DEFERRED' { return '<hive>DEFERRED'; }
<hive>'DEFINED' { return '<hive>DEFINED'; }
<hive>'DELIMITED' { return '<hive>DELIMITED'; }
<hive>'DEPENDENCY' { return '<hive>DEPENDENCY'; }
<hive>'DESC' { return '<hive>DESC'; }
<hive>'DIRECTORY' { this.begin('hdfs'); return '<hive>DIRECTORY'; }
<hive>'DISABLE' { return '<hive>DISABLE'; }
<hive>'DISTRIBUTE' { return '<hive>DISTRIBUTE'; }
<hive>DOUBLE\s+PRECISION { return '<hive>DOUBLE_PRECISION'; }
<hive>'ESCAPED' { return '<hive>ESCAPED'; }
<hive>'ENABLE' { return '<hive>ENABLE'; }
<hive>'EXCHANGE' { return '<hive>EXCHANGE'; }
<hive>'EXPLAIN' { parser.determineCase(yytext); return '<hive>EXPLAIN'; }
<hive>'EXPORT' { parser.determineCase(yytext); return '<hive>EXPORT'; }
<hive>'FIELDS' { return '<hive>FIELDS'; }
<hive>'FILE' { return '<hive>FILE'; }
<hive>'FILEFORMAT' { return '<hive>FILEFORMAT'; }
<hive>'FIRST' { return '<hive>FIRST'; }
<hive>'FORMAT' { return '<hive>FORMAT'; }
<hive>'FORMATTED' { return '<hive>FORMATTED'; }
<hive>'FUNCTION' { return '<hive>FUNCTION'; }
<hive>'FUNCTIONS' { return '<hive>FUNCTIONS'; }
<hive>'HOUR' { return '<hive>HOUR'; }
<hive>'IDXPROPERTIES' { return '<hive>IDXPROPERTIES'; }
<hive>'INDEX' { return '<hive>INDEX'; }
<hive>'INDEXES' { return '<hive>INDEXES'; }
<hive>'INPATH' { this.begin('hdfs'); return '<hive>INPATH'; }
<hive>'INPUTFORMAT' { return '<hive>INPUTFORMAT'; }
<hive>'ITEMS' { return '<hive>ITEMS'; }
<hive>'JAR' { return '<hive>JAR'; }
<hive>'KEY' { return '<hive>KEY'; }
<hive>'KEYS' { return '<hive>KEYS'; }
<hive>'LINES' { return '<hive>LINES'; }
<hive>'LOAD' { parser.determineCase(yytext); return '<hive>LOAD'; }
<hive>'LOCATION' { this.begin('hdfs'); return '<hive>LOCATION'; }
<hive>'LOCK' { return '<hive>LOCK'; }
<hive>'LOCKS' { return '<hive>LOCKS'; }
<hive>'MATCHED' { return '<hive>MATCHED'; }
<hive>'MERGE' { return '<hive>MERGE'; }
<hive>'METADATA' { return '<hive>METADATA'; }
<hive>'MINUTE' { return '<hive>MINUTE'; }
<hive>'MONTH' { return '<hive>MONTH'; }
<hive>'MSCK' { return '<hive>MSCK'; }
<hive>'NORELY' { return '<hive>NORELY'; }
<hive>'NOSCAN' { return '<hive>NOSCAN'; }
<hive>'NOVALIDATE' { return '<hive>NOVALIDATE'; }
<hive>'NO_DROP' { return '<hive>NO_DROP'; }
<hive>'OFFLINE' { return '<hive>OFFLINE'; }
<hive>'ORC' { return '<hive>ORC'; }
<hive>'OUTPUTFORMAT' { return '<hive>OUTPUTFORMAT'; }
<hive>'OVERWRITE' { return '<hive>OVERWRITE'; }
<hive>OVERWRITE\s+DIRECTORY { this.begin('hdfs'); return '<hive>OVERWRITE_DIRECTORY'; }
<hive>'OWNER' { return '<hive>OWNER'; }
<hive>'PARQUET' { return '<hive>PARQUET'; }
<hive>'PARTITIONED' { return '<hive>PARTITIONED'; }
<hive>'PARTITIONS' { return '<hive>PARTITIONS'; }
<hive>'PERCENT' { return '<hive>PERCENT'; }
<hive>'PRIVILEGES' { return '<hive>PRIVILEGES'; }
<hive>'PURGE' { return '<hive>PURGE'; }
<hive>'QUARTER' { return '<hive>QUARTER'; }
<hive>'RCFILE' { return '<hive>RCFILE'; }
<hive>'REBUILD' { return '<hive>REBUILD'; }
<hive>'RELOAD' { parser.determineCase(yytext); return '<hive>RELOAD'; }
<hive>'RELY' { return '<hive>RELY'; }
<hive>'REPAIR' { return '<hive>REPAIR'; }
<hive>'REPLICATION' { return '<hive>REPLICATION'; }
<hive>'RECOVER' { return '<hive>RECOVER'; }
<hive>'RENAME' { return '<hive>RENAME'; }
<hive>'REPLACE' { return '<hive>REPLACE'; }
<hive>'RESTRICT' { return '<hive>RESTRICT'; }
<hive>'ROLE' { return '<hive>ROLE'; }
<hive>'ROLES' { return '<hive>ROLES'; }
<hive>'SECOND' { return '<hive>SECOND'; }
<hive>'SCHEMA' { return '<hive>SCHEMA'; }
<hive>'SCHEMAS' { return '<hive>SCHEMAS'; }
<hive>'SEQUENCEFILE' { return '<hive>SEQUENCEFILE'; }
<hive>'SERDE' { return '<hive>SERDE'; }
<hive>'SERDEPROPERTIES' { return '<hive>SERDEPROPERTIES'; }
<hive>'SETS' { return '<hive>SETS'; }
<hive>'SHOW' { parser.determineCase(yytext); return '<hive>SHOW'; }
<hive>'SHOW_DATABASE' { return '<hive>SHOW_DATABASE'; }
<hive>'SKEWED' { return '<hive>SKEWED'; }
<hive>'SKEWED LOCATION' { return '<hive>SKEWED_LOCATION'; } // Hack to prevent hdfs lexer state
<hive>'SORT' { return '<hive>SORT'; }
<hive>'SORTED' { return '<hive>SORTED'; }
<hive>'STATISTICS' { return '<hive>STATISTICS'; }
<hive>'STORED' { return '<hive>STORED'; }
<hive>STORED\s+AS\s+DIRECTORIES { return '<hive>STORED_AS_DIRECTORIES'; }
<hive>'STRING' { return '<hive>STRING'; }
<hive>'STRUCT' { return 'STRUCT'; }
<hive>'TABLES' { return '<hive>TABLES'; }
<hive>'TABLESAMPLE' { return '<hive>TABLESAMPLE'; }
<hive>'TBLPROPERTIES' { return '<hive>TBLPROPERTIES'; }
<hive>'TEMPORARY' { return '<hive>TEMPORARY'; }
<hive>'TERMINATED' { return '<hive>TERMINATED'; }
<hive>'TEXTFILE' { return '<hive>TEXTFILE'; }
<hive>'TINYINT' { return '<hive>TINYINT'; }
<hive>'TOUCH' { return '<hive>TOUCH'; }
<hive>'TRANSACTIONS' { return '<hive>TRANSACTIONS'; }
<hive>'UNARCHIVE' { return '<hive>UNARCHIVE'; }
<hive>'UNIONTYPE' { return '<hive>UNIONTYPE'; }
<hive>'USE' { parser.determineCase(yytext); return '<hive>USE'; }
<hive>'VIEW' { return '<hive>VIEW'; }
<hive>'WAIT' { return '<hive>WAIT'; }
<hive>'WEEK' { return '<hive>WEEK'; }
<hive>'WINDOW' { return '<hive>WINDOW'; }
<hive>'YEAR' { return '<hive>YEAR'; }
<hive>'.' { return '<hive>.'; }
<hive>'[' { return '<hive>['; }
<hive>']' { return '<hive>]'; }
// Reserved Keywords
<impala>'ADD' { return '<impala>ADD'; }
<impala>'AGGREGATE' { return '<impala>AGGREGATE'; }
<impala>'AVRO' { return '<impala>AVRO'; }
<impala>'CACHED' { return '<impala>CACHED'; }
<impala>'CASCADE' { return '<impala>CASCADE'; }
<impala>'CHANGE' { return '<impala>CHANGE'; }
<impala>'CLOSE_FN' { return '<impala>CLOSE_FN'; }
<impala>'COLUMN' { return '<impala>COLUMN'; }
<impala>'COLUMNS' { return '<impala>COLUMNS'; }
<impala>'COMMENT' { parser.determineCase(yytext); return '<impala>COMMENT'; }
<impala>'COMPUTE' { parser.determineCase(yytext); return '<impala>COMPUTE'; }
<impala>'CREATE' { parser.determineCase(yytext); parser.addStatementTypeLocation('CREATE', yylloc, yy.lexer.upcomingInput()); return '<impala>CREATE'; }
<impala>'DATA' { return '<impala>DATA'; }
<impala>'DATABASES' { return '<impala>DATABASES'; }
<impala>'DELETE' { return '<impala>DELETE'; }
<impala>'DELIMITED' { return '<impala>DELIMITED'; }
<impala>'DESCRIBE' { parser.determineCase(yytext); parser.addStatementTypeLocation('DESCRIBE', yylloc); return '<impala>DESCRIBE'; }
<impala>'ESCAPED' { return '<impala>ESCAPED'; }
<impala>'EXPLAIN' { parser.determineCase(yytext); parser.addStatementTypeLocation('EXPLAIN', yylloc); return '<impala>EXPLAIN'; }
<impala>'EXTERNAL' { return '<impala>EXTERNAL'; }
<impala>'EXTENDED' { return '<impala>EXTENDED'; }
<impala>'FIELDS' { return '<impala>FIELDS'; }
<impala>'FILEFORMAT' { return '<impala>FILEFORMAT'; }
<impala>'FILES' { return '<impala>FILES'; }
<impala>'FINALIZE_FN' { return '<impala>FINALIZE_FN'; }
<impala>'FIRST' { return '<impala>FIRST'; }
<impala>'FORMAT' { return '<impala>FORMAT'; }
<impala>'FORMATTED' { return '<impala>FORMATTED'; }
<impala>'FUNCTION' { return '<impala>FUNCTION'; }
<impala>'FUNCTIONS' { return '<impala>FUNCTIONS'; }
<impala>'GROUP' { return '<impala>GROUP'; }
<impala>'HASH' { return '<impala>HASH'; }
<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>'INIT_FN' { return '<impala>INIT_FN'; }
<impala>'INVALIDATE' { parser.determineCase(yytext); parser.addStatementTypeLocation('INVALIDATE', yylloc, yy.lexer.upcomingInput()); return '<impala>INVALIDATE'; }
<impala>'INPATH' { this.begin('hdfs'); return '<impala>INPATH'; }
<impala>'IREGEXP' { return '<impala>IREGEXP'; }
<impala>'KEY' { return '<impala>KEY'; }
<impala>'KUDU' { return '<impala>KUDU'; }
<impala>'LAST' { return '<impala>LAST'; }
<impala>LIKE\s+PARQUET { this.begin('hdfs'); return '<impala>LIKE_PARQUET'; }
<impala>'LIMIT' { return '<impala>LIMIT'; }
<impala>'LINES' { return '<impala>LINES'; }
<impala>'LOAD' { parser.determineCase(yytext); parser.addStatementTypeLocation('LOAD', yylloc, yy.lexer.upcomingInput()); return '<impala>LOAD'; }
<impala>'LOCATION' { this.begin('hdfs'); return '<impala>LOCATION'; }
<impala>'MERGE_FN' { return '<impala>MERGE_FN'; }
<impala>'METADATA' { return '<impala>METADATA'; }
<impala>'NULLS' { return '<impala>NULLS'; }
<impala>'OFFSET' { return '<impala>OFFSET'; }
<impala>'ORC' { return '<impala>ORC'; }
<impala>'OVERWRITE' { return '<impala>OVERWRITE'; }
<impala>'PARQUET' { return '<impala>PARQUET'; }
<impala>'PARTITIONED' { return '<impala>PARTITIONED'; }
<impala>'PARTITIONS' { return '<impala>PARTITIONS'; }
<impala>'PREPARE_FN' { return '<impala>PREPARE_FN'; }
<impala>'PRIMARY' { return '<impala>PRIMARY'; }
<impala>'RCFILE' { return '<impala>RCFILE'; }
<impala>'RANGE' { return '<impala>RANGE'; }
<impala>'REAL' { return '<impala>REAL'; }
<impala>'REFRESH' { parser.determineCase(yytext); parser.addStatementTypeLocation('REFRESH', yylloc); return '<impala>REFRESH'; }
<impala>'RENAME' { return '<impala>RENAME'; }
<impala>'REPEATABLE' { return '<impala>REPEATABLE'; }
<impala>'REPLACE' { return '<impala>REPLACE'; }
<impala>'REPLICATION' { return '<impala>REPLICATION'; }
<impala>'RESTRICT' { return '<impala>RESTRICT'; }
<impala>'RETURNS' { return '<impala>RETURNS'; }
<impala>'REVOKE' { parser.determineCase(yytext); parser.addStatementTypeLocation('REVOKE', yylloc); return '<impala>REVOKE'; }
<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>'SORT' { return '<impala>SORT'; }
<impala>'STATS' { return '<impala>STATS'; }
<impala>'STORED' { return '<impala>STORED'; }
<impala>'STRAIGHT_JOIN' { return '<impala>STRAIGHT_JOIN'; }
<impala>'SYMBOL' { return '<impala>SYMBOL'; }
<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>'UNCACHED' { return '<impala>UNCACHED'; }
<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>'USING' { return '<impala>USING'; }
<impala>PARTITION\s+VALUE\s { return '<impala>PARTITION_VALUE'; }
// 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>'STRUCT' { return 'STRUCT'; }
<impala>'UNKNOWN' { return '<impala>UNKNOWN'; }
<impala>\[BROADCAST\] { return '<impala>BROADCAST'; }
<impala>\[NOSHUFFLE\] { return '<impala>NOSHUFFLE'; }
<impala>\[SHUFFLE\] { return '<impala>SHUFFLE'; }
<impala>'...' { return '<impala>...'; }
<impala>'.' { return '<impala>.'; }
<impala>'[' { return '<impala>['; }
<impala>']' { return '<impala>]'; }
<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'; }
'CASE' { return 'CASE'; }
'CHAR' { return 'CHAR'; }
'CREATE' { parser.determineCase(yytext); return 'CREATE'; }
'CROSS' { return 'CROSS'; }
'CURRENT' { return 'CURRENT'; }
'DATABASE' { return 'DATABASE'; }
'DECIMAL' { return 'DECIMAL'; }
'DISTINCT' { return 'DISTINCT'; }
'DIV' { return 'ARITHMETIC_OPERATOR'; }
'DOUBLE' { return 'DOUBLE'; }
'DESC' { return 'DESC'; }
'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'; }
'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'; }
'UPDATE' { parser.determineCase(yytext); return 'UPDATE'; }
'USE' { parser.determineCase(yytext); parser.addStatementTypeLocation('USE', yylloc); return 'USE'; }
'UNION' { return 'UNION'; }
'VIEW' { return 'VIEW'; }
'VARCHAR' { return 'VARCHAR'; } // Not in Impala
'VALUES' { return 'VALUES'; }
'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'; }
VARIANCE\s*\( { yy.lexer.unput('('); yytext = 'variance'; parser.addFunctionLocation(yylloc, yytext); return 'VARIANCE'; }
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'; }
<hive>COLLECT_SET\s*\( { yy.lexer.unput('('); yytext = 'collect_set'; parser.addFunctionLocation(yylloc, yytext); return '<hive>COLLECT_SET'; }
<hive>COLLECT_LIST\s*\( { yy.lexer.unput('('); yytext = 'collect_list'; parser.addFunctionLocation(yylloc, yytext); return '<hive>COLLECT_LIST'; }
<hive>CORR\s*\( { yy.lexer.unput('('); yytext = 'corr'; parser.addFunctionLocation(yylloc, yytext); return '<hive>CORR'; }
<hive>COVAR_POP\s*\( { yy.lexer.unput('('); yytext = 'covar_pop'; parser.addFunctionLocation(yylloc, yytext); return '<hive>COVAR_POP'; }
<hive>COVAR_SAMP\s*\( { yy.lexer.unput('('); yytext = 'covar_samp'; parser.addFunctionLocation(yylloc, yytext); return '<hive>COVAR_SAMP'; }
<hive>EXTRACT\s*\( { yy.lexer.unput('('); yytext = 'extract'; parser.addFunctionLocation(yylloc, yytext); return '<hive>EXTRACT'; }
<hive>HISTOGRAM_NUMERIC\s*\( { yy.lexer.unput('('); yytext = 'histogram_numeric'; parser.addFunctionLocation(yylloc, yytext); return '<hive>HISTOGRAM_NUMERIC'; }
<hive>NTILE\s*\( { yy.lexer.unput('('); yytext = 'ntile'; parser.addFunctionLocation(yylloc, yytext); return '<hive>NTILE'; }
<hive>PERCENTILE\s*\( { yy.lexer.unput('('); yytext = 'percentile'; parser.addFunctionLocation(yylloc, yytext); return '<hive>PERCENTILE'; }
<hive>PERCENTILE_APPROX\s*\( { yy.lexer.unput('('); yytext = 'percentile_approx'; parser.addFunctionLocation(yylloc, yytext); return '<hive>PERCENTILE_APPROX'; }
<impala>APPX_MEDIAN\s*\( { yy.lexer.unput('('); yytext = 'appx_median'; parser.addFunctionLocation(yylloc, yytext); return '<impala>APPX_MEDIAN'; }
<impala>EXTRACT\s*\( { yy.lexer.unput('('); yytext = 'extract'; parser.addFunctionLocation(yylloc, yytext); return '<impala>EXTRACT'; }
<impala>GROUP_CONCAT\s*\( { yy.lexer.unput('('); yytext = 'group_concat'; parser.addFunctionLocation(yylloc, yytext); return '<impala>GROUP_CONCAT'; }
<impala>NDV\s*\( { yy.lexer.unput('('); yytext = 'ndv'; parser.addFunctionLocation(yylloc, yytext); return '<impala>NDV'; }
<impala>STDDEV\s*\( { yy.lexer.unput('('); yytext = 'stddev'; parser.addFunctionLocation(yylloc, yytext); return '<impala>STDDEV'; }
<impala>VARIANCE_POP\s*\( { yy.lexer.unput('('); yytext = 'variance_pop'; parser.addFunctionLocation(yylloc, yytext); return '<impala>VARIANCE_POP'; }
<impala>VARIANCE_SAMP\s*\( { yy.lexer.unput('('); yytext = 'variance_samp'; parser.addFunctionLocation(yylloc, yytext); return '<impala>VARIANCE_SAMP'; }
// 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'; }
<hive>CUME_DIST\s*\( { yy.lexer.unput('('); yytext = 'cume_dist'; parser.addFunctionLocation(yylloc, yytext); return 'ANALYTIC'; }
<hive>PERCENT_RANK\s*\( { yy.lexer.unput('('); yytext = 'percent_rank'; parser.addFunctionLocation(yylloc, yytext); return 'ANALYTIC'; }
<impala>NTILE\s*\( { yy.lexer.unput('('); yytext = 'ntile'; parser.addFunctionLocation(yylloc, yytext); return 'ANALYTIC'; }
<impala>PERCENT_RANK\s*\( { yy.lexer.unput('('); yytext = 'percent_rank'; parser.addFunctionLocation(yylloc, yytext); return 'ANALYTIC'; }
<impala>SYSTEM\s*\( { yy.lexer.unput('('); yytext = 'system'; return '<impala>SYSTEM'; }
[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>. { }
<hive>. { }
<impala>. { }
<hdfs>. { }
<backtickedValue>. { }
<singleQuotedValue>. { }
<doubleQuotedValue>. { }

2278
jison/sqlParseSupport.js Executable file

File diff suppressed because it is too large Load Diff

172
jison/sqlStatementsParser.jison Executable file
View File

@ -0,0 +1,172 @@
// 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.
%lex
%options flex
%x multiLineComment inLineComment singleQuote doubleQuote backTick
%%
'/*' { this.begin("multiLineComment"); return 'PART_OF_STATEMENT'; }
<multiLineComment>[^*]+ { return 'PART_OF_STATEMENT'; }
<multiLineComment>[*][^/] { return 'PART_OF_STATEMENT'; }
<multiLineComment><<EOF>> { this.popState(); return 'PART_OF_STATEMENT'; }
<multiLineComment>'*/' { this.popState(); return 'PART_OF_STATEMENT'; }
'--' { this.begin("inLineComment"); return 'PART_OF_STATEMENT'; }
<inLineComment>[^\n]+ { return 'PART_OF_STATEMENT'; }
<inLineComment><<EOF>> { this.popState(); return 'EOF'; }
<inLineComment>[\n] { this.popState(); return 'PART_OF_STATEMENT'; }
'"' { this.begin("doubleQuote"); return 'PART_OF_STATEMENT'; }
<doubleQuote>(?:\\["]|[^"])+ { return 'PART_OF_STATEMENT'; }
<doubleQuote><<EOF>> { this.popState(); return 'EOF'; }
<doubleQuote>'"' { this.popState(); return 'PART_OF_STATEMENT'; }
'\'' { this.begin("singleQuote"); return 'PART_OF_STATEMENT'; }
<singleQuote>(?:\\[']|[^'])+ { return 'PART_OF_STATEMENT'; }
<singleQuote><<EOF>> { this.popState(); return 'EOF'; }
<singleQuote>'\'' { this.popState(); return 'PART_OF_STATEMENT'; }
'`' { this.begin("backTick"); return 'PART_OF_STATEMENT'; }
<backTick>[^`]+ { return 'PART_OF_STATEMENT'; }
<backTick><<EOF>> { this.popState(); return 'EOF'; }
<backTick>'`' { this.popState(); return 'PART_OF_STATEMENT'; }
[^"\/;'`-]+ {
if (!parser.yy.firstToken) {
var firstWordMatch = yytext.match(/[a-zA-Z_]+/);
if (firstWordMatch) {
parser.yy.firstToken = firstWordMatch[0];
}
};
return 'PART_OF_STATEMENT';
}
[-][^;-]? { return 'PART_OF_STATEMENT'; }
[/][^;*]? { return 'PART_OF_STATEMENT'; }
';' { return ';'; }
<<EOF>> { return 'EOF'; }
. { /* To prevent console logging of unknown chars */ }
/lex
%start SqlStatementsParser
%%
SqlStatementsParser
: Statements 'EOF'
{
parser.removeTrailingWhiteSpace($1);
return $1;
}
| OneOrMoreSeparators Statements 'EOF'
{
parser.handleLeadingStatements($1, $2);
parser.removeTrailingWhiteSpace($2);
return $2;
}
| OneOrMoreSeparators Statements OneOrMoreSeparators 'EOF'
{
parser.handleLeadingStatements($1, $2);
parser.handleTrailingStatements($2, $3);
parser.removeTrailingWhiteSpace($2);
return $2;
}
| Statements OneOrMoreSeparators 'EOF'
{
parser.handleTrailingStatements($1, $2);
parser.removeTrailingWhiteSpace($1);
return $1;
}
| OneOrMoreSeparators 'EOF'
{
var result = [];
parser.handleLeadingStatements($1, result);
return result;
}
| 'EOF'
{
return [];
}
;
Statements
: StatementParts
{
if (parser.yy.firstToken) {
$$ = [{ type: 'statement', statement: $1, location: @1, firstToken: parser.yy.firstToken }];
parser.yy.firstToken = null;
} else {
$$ = [{ type: 'statement', statement: $1, location: @1 }];
}
}
| Statements OneOrMoreSeparators StatementParts
{
parser.handleTrailingStatements($1, $2);
if (parser.yy.firstToken) {
$1.push({ type: 'statement', statement: $3, location: @3, firstToken: parser.yy.firstToken });
parser.yy.firstToken = null;
} else {
$1.push({ type: 'statement', statement: $3, location: @3 });
}
}
;
StatementParts
: 'PART_OF_STATEMENT'
| StatementParts 'PART_OF_STATEMENT' -> $1 + $2;
;
OneOrMoreSeparators
: ';' -> [@1]
| OneOrMoreSeparators ';'
{
$1.push(@2);
}
;
%%
parser.handleLeadingStatements = function (emptyStatements, result) {
for (var i = emptyStatements.length - 1; i >= 0; i--) {
result.unshift({ type: 'statement', statement: ';', location: emptyStatements[i] });
}
}
parser.handleTrailingStatements = function (result, emptyStatements) {
var lastStatement = result[result.length - 1];
lastStatement.statement += ';'
lastStatement.location = {
first_line: lastStatement.location.first_line,
first_column: lastStatement.location.first_column,
last_line: emptyStatements[0].last_line,
last_column: emptyStatements[0].last_column
}
if (emptyStatements.length > 1) {
for (var i = 1; i < emptyStatements.length; i++) {
result.push({ type: 'statement', statement: ';', location: emptyStatements[i] });
}
}
}
parser.removeTrailingWhiteSpace = function (result) {
var lastStatement = result[result.length - 1];
if (/^\s+$/.test(lastStatement.statement)) {
result.pop()
}
}

1100
jison/sql_alter.jison Executable file

File diff suppressed because it is too large Load Diff

274
jison/sql_analyze.jison Executable file
View File

@ -0,0 +1,274 @@
// 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
: AnalyzeStatement
| RefreshStatement
| InvalidateStatement
| ComputeStatsStatement
;
DataDefinition_EDIT
: AnalyzeStatement_EDIT
| RefreshStatement_EDIT
| InvalidateStatement_EDIT
| ComputeStatsStatement_EDIT
;
AnalyzeStatement
: '<hive>ANALYZE' '<hive>TABLE' SchemaQualifiedTableIdentifier OptionalPartitionSpec '<hive>COMPUTE' '<hive>STATISTICS' OptionalForColumns OptionalCacheMetadata OptionalNoscan
{
parser.addTablePrimary($3);
}
;
AnalyzeStatement_EDIT
: '<hive>ANALYZE' 'CURSOR'
{
parser.suggestKeywords(['TABLE']);
}
| '<hive>ANALYZE' '<hive>TABLE' 'CURSOR'
{
parser.suggestTables({ onlyTables: true });
parser.suggestDatabases({ appendDot: true });
}
| '<hive>ANALYZE' '<hive>TABLE' SchemaQualifiedTableIdentifier_EDIT OptionalPartitionSpec
{
if (parser.yy.result.suggestTables) {
parser.yy.result.suggestTables.onlyTables = true;
}
}
| '<hive>ANALYZE' '<hive>TABLE' SchemaQualifiedTableIdentifier OptionalPartitionSpec_EDIT
{
parser.addTablePrimary($3);
}
| '<hive>ANALYZE' '<hive>TABLE' SchemaQualifiedTableIdentifier OptionalPartitionSpec 'CURSOR'
{
parser.addTablePrimary($3);
if (!$4) {
parser.suggestKeywords([{ value: 'PARTITION', weight: 2 }, { value: 'COMPUTE STATISTICS', weight: 1 }]);
} else {
parser.suggestKeywords(['COMPUTE STATISTICS']);
}
}
| '<hive>ANALYZE' '<hive>TABLE' SchemaQualifiedTableIdentifier OptionalPartitionSpec '<hive>COMPUTE' 'CURSOR'
{
parser.addTablePrimary($3);
parser.suggestKeywords(['STATISTICS']);
}
| '<hive>ANALYZE' '<hive>TABLE' SchemaQualifiedTableIdentifier OptionalPartitionSpec '<hive>COMPUTE' '<hive>STATISTICS' 'CURSOR' OptionalForColumns OptionalCacheMetadata OptionalNoscan
{
parser.addTablePrimary($3);
parser.suggestKeywords(parser.getKeywordsForOptionalsLR([$8, $9, $10], [{ value: 'FOR COLUMNS', weight: 3 }, { value: 'CACHE METADATA', weight: 2 }, { value: 'NOSCAN', weight: 1 }]));
}
| '<hive>ANALYZE' '<hive>TABLE' SchemaQualifiedTableIdentifier OptionalPartitionSpec '<hive>COMPUTE' '<hive>STATISTICS' ForColumns 'CURSOR' OptionalCacheMetadata OptionalNoscan
{
parser.addTablePrimary($3);
parser.suggestKeywords(parser.getKeywordsForOptionalsLR([$9, $10], [{ value: 'CACHE METADATA', weight: 2 }, { value: 'NOSCAN', weight: 1 }]));
}
| '<hive>ANALYZE' '<hive>TABLE' SchemaQualifiedTableIdentifier OptionalPartitionSpec '<hive>COMPUTE' '<hive>STATISTICS' OptionalForColumns CacheMetadata 'CURSOR' OptionalNoscan
{
parser.addTablePrimary($3);
parser.suggestKeywords(parser.getKeywordsForOptionalsLR([$10], [{ value: 'NOSCAN', weight: 1 }]));
}
| '<hive>ANALYZE' 'CURSOR' SchemaQualifiedTableIdentifier OptionalPartitionSpec
{
parser.suggestKeywords(['TABLE']);
parser.addTablePrimary($3);
}
| '<hive>ANALYZE' 'CURSOR' SchemaQualifiedTableIdentifier OptionalPartitionSpec '<hive>COMPUTE' '<hive>STATISTICS' OptionalForColumns OptionalCacheMetadata OptionalNoscan
{
parser.suggestKeywords(['TABLE']);
parser.addTablePrimary($3);
}
| '<hive>ANALYZE' '<hive>TABLE' SchemaQualifiedTableIdentifier_EDIT OptionalPartitionSpec '<hive>COMPUTE' '<hive>STATISTICS' OptionalForColumns OptionalCacheMetadata OptionalNoscan
| '<hive>ANALYZE' '<hive>TABLE' SchemaQualifiedTableIdentifier OptionalPartitionSpec_EDIT '<hive>COMPUTE' '<hive>STATISTICS' OptionalForColumns OptionalCacheMetadata OptionalNoscan
| '<hive>ANALYZE' '<hive>TABLE' SchemaQualifiedTableIdentifier OptionalPartitionSpec '<hive>COMPUTE' '<hive>STATISTICS' ForColumns_EDIT OptionalCacheMetadata OptionalNoscan
| '<hive>ANALYZE' '<hive>TABLE' SchemaQualifiedTableIdentifier OptionalPartitionSpec '<hive>COMPUTE' '<hive>STATISTICS' OptionalForColumns CacheMetadata_EDIT OptionalNoscan
;
OptionalForColumns
:
| ForColumns
;
ForColumns
: '<hive>FOR' '<hive>COLUMNS'
;
ForColumns_EDIT
: '<hive>FOR' 'CURSOR'
{
parser.suggestKeywords(['COLUMNS']);
}
;
OptionalCacheMetadata
:
| CacheMetadata
;
CacheMetadata
: '<hive>CACHE' '<hive>METADATA'
;
CacheMetadata_EDIT
: '<hive>CACHE' 'CURSOR'
{
parser.suggestKeywords(['METADATA']);
}
;
OptionalNoscan
:
| '<hive>NOSCAN'
;
RefreshStatement
: '<impala>REFRESH' SchemaQualifiedTableIdentifier OptionalPartitionSpec
{
parser.addTablePrimary($2);
}
| '<impala>REFRESH' '<impala>FUNCTIONS' DatabaseIdentifier
{
parser.addDatabaseLocation(@3, [{ name: $3 }]);
}
;
RefreshStatement_EDIT
: '<impala>REFRESH' 'CURSOR'
{
parser.suggestTables();
parser.suggestDatabases({ appendDot: true });
parser.suggestKeywords(['FUNCTIONS']);
}
| '<impala>REFRESH' SchemaQualifiedTableIdentifier_EDIT OptionalPartitionSpec
| '<impala>REFRESH' SchemaQualifiedTableIdentifier OptionalPartitionSpec 'CURSOR'
{
parser.addTablePrimary($2);
if (!$3) {
parser.suggestKeywords(['PARTITION']);
}
}
| '<impala>REFRESH' SchemaQualifiedTableIdentifier OptionalPartitionSpec_EDIT
| '<impala>REFRESH' '<impala>FUNCTIONS' 'CURSOR'
{
parser.suggestDatabases();
}
;
InvalidateStatement
: '<impala>INVALIDATE' '<impala>METADATA'
| '<impala>INVALIDATE' '<impala>METADATA' SchemaQualifiedTableIdentifier
{
parser.addTablePrimary($3);
}
;
InvalidateStatement_EDIT
: '<impala>INVALIDATE' 'CURSOR'
{
parser.suggestKeywords(['METADATA']);
}
| '<impala>INVALIDATE' '<impala>METADATA' 'CURSOR'
{
parser.suggestTables();
parser.suggestDatabases({ appendDot: true });
}
| '<impala>INVALIDATE' '<impala>METADATA' SchemaQualifiedTableIdentifier_EDIT
| '<impala>INVALIDATE' 'CURSOR' SchemaQualifiedTableIdentifier
{
parser.addTablePrimary($3);
parser.suggestKeywords(['METADATA']);
}
;
ComputeStatsStatement
: '<impala>COMPUTE' '<impala>STATS' SchemaQualifiedTableIdentifier OptionalParenthesizedColumnList OptionalImpalaTableSample
{
parser.addTablePrimary($3);
}
| '<impala>COMPUTE' '<impala>INCREMENTAL' '<impala>STATS' SchemaQualifiedTableIdentifier OptionalPartitionSpec
{
parser.addTablePrimary($4);
}
;
ComputeStatsStatement_EDIT
: '<impala>COMPUTE' 'CURSOR'
{
parser.suggestKeywords(['STATS', 'INCREMENTAL STATS']);
}
| '<impala>COMPUTE' '<impala>STATS' 'CURSOR'
{
parser.suggestTables();
parser.suggestDatabases({ appendDot: true });
}
| '<impala>COMPUTE' '<impala>STATS' SchemaQualifiedTableIdentifier_EDIT
| '<impala>COMPUTE' 'CURSOR' SchemaQualifiedTableIdentifier OptionalPartitionSpec
{
parser.addTablePrimary($3);
parser.suggestKeywords(['STATS', 'INCREMENTAL STATS']);
}
| '<impala>COMPUTE' '<impala>STATS' SchemaQualifiedTableIdentifier OptionalParenthesizedColumnList OptionalImpalaTableSample 'CURSOR'
{
parser.addTablePrimary($3);
if (!$5) {
parser.suggestKeywords(['TABLESAMPLE']);
} else if ($5.suggestKeywords) {
parser.suggestKeywords($5.suggestKeywords);
}
}
| '<impala>COMPUTE' '<impala>STATS' SchemaQualifiedTableIdentifier ParenthesizedColumnList_EDIT OptionalImpalaTableSample
{
parser.addTablePrimary($3);
}
| '<impala>COMPUTE' '<impala>STATS' SchemaQualifiedTableIdentifier OptionalParenthesizedColumnList OptionalImpalaTableSample_EDIT
{
parser.addTablePrimary($3);
}
| '<impala>COMPUTE' 'CURSOR' '<impala>STATS' SchemaQualifiedTableIdentifier OptionalPartitionSpec
{
parser.addTablePrimary($4);
parser.suggestKeywords(['INCREMENTAL']);
}
| '<impala>COMPUTE' '<impala>INCREMENTAL' 'CURSOR'
{
parser.suggestKeywords(['STATS']);
}
| '<impala>COMPUTE' '<impala>INCREMENTAL' 'CURSOR' SchemaQualifiedTableIdentifier OptionalPartitionSpec
{
parser.addTablePrimary($4);
parser.suggestKeywords(['STATS']);
}
| '<impala>COMPUTE' '<impala>INCREMENTAL' '<impala>STATS' 'CURSOR'
{
parser.suggestTables();
parser.suggestDatabases({ appendDot: true });
}
| '<impala>COMPUTE' '<impala>INCREMENTAL' '<impala>STATS' SchemaQualifiedTableIdentifier_EDIT OptionalPartitionSpec
| '<impala>COMPUTE' '<impala>INCREMENTAL' '<impala>STATS' SchemaQualifiedTableIdentifier 'CURSOR' OptionalPartitionSpec
{
parser.addTablePrimary($4);
if (!$6) {
parser.suggestKeywords(['PARTITION']);
}
}
| '<impala>COMPUTE' '<impala>INCREMENTAL' '<impala>STATS' SchemaQualifiedTableIdentifier PartitionSpec_EDIT
{
parser.addTablePrimary($4);
}
;

1933
jison/sql_create.jison Executable file

File diff suppressed because it is too large Load Diff

504
jison/sql_drop.jison Executable file
View File

@ -0,0 +1,504 @@
// 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
| HiveAbortStatement
;
DataDefinition_EDIT
: DropStatement_EDIT
| HiveAbortStatement_EDIT
;
DataManipulation
: HiveDeleteStatement
| ImpalaDeleteStatement
;
DataManipulation_EDIT
: HiveDeleteStatement_EDIT
| ImpalaDeleteStatement_EDIT
;
DropStatement
: DropDatabaseStatement
| DropFunctionStatement
| DropRoleStatement
| DropStatsStatement
| DropTableStatement
| DropIndexStatement
| DropMacroStatement
| DropViewStatement
| TruncateTableStatement
;
DropStatement_EDIT
: DropDatabaseStatement_EDIT
| DropFunctionStatement_EDIT
| DropStatsStatement_EDIT
| DropTableStatement_EDIT
| DropIndexStatement_EDIT
| DropMacroStatement_EDIT
| DropViewStatement_EDIT
| TruncateTableStatement_EDIT
| 'DROP' 'CURSOR'
{
if (parser.isHive()) {
parser.suggestKeywords(['DATABASE', 'FUNCTION', 'INDEX', 'ROLE', 'SCHEMA', 'TABLE', 'TEMPORARY FUNCTION', 'TEMPORARY MACRO', 'VIEW']);
} else if (parser.isImpala()) {
parser.suggestKeywords(['AGGREGATE FUNCTION', 'DATABASE', 'FUNCTION', 'INCREMENTAL STATS', 'ROLE', 'SCHEMA', 'STATS', 'TABLE', 'VIEW']);
} else {
parser.suggestKeywords(['ROLE', 'SCHEMA', 'TABLE', 'VIEW']);
}
}
;
DropDatabaseStatement
: 'DROP' DatabaseOrSchema OptionalIfExists RegularOrBacktickedIdentifier OptionalCascadeOrRestrict
;
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'
{
if (parser.isHive() || parser.isImpala()) {
parser.suggestKeywords(['CASCADE', 'RESTRICT']);
}
}
| 'DROP' DatabaseOrSchema OptionalIfExists_EDIT RegularOrBacktickedIdentifier OptionalCascadeOrRestrict
| 'DROP' DatabaseOrSchema OptionalIfExists 'CURSOR' RegularOrBacktickedIdentifier OptionalCascadeOrRestrict
{
if (!$3) {
parser.suggestKeywords(['IF EXISTS']);
}
}
;
DropFunctionStatement
: DropImpalaFunction
| DropHiveFunction
;
DropFunctionStatement_EDIT
: DropImpalaFunction_EDIT
| DropHiveFunction_EDIT
;
// OptionalAggregate is no go for look ahead reasons
DropImpalaFunction
: 'DROP' '<impala>FUNCTION' OptionalIfExists SchemaQualifiedIdentifier ParenthesizedImpalaArgumentList
| 'DROP' '<impala>AGGREGATE' '<impala>FUNCTION' OptionalIfExists SchemaQualifiedIdentifier ParenthesizedImpalaArgumentList
;
DropImpalaFunction_EDIT
: 'DROP' '<impala>FUNCTION' OptionalIfExists 'CURSOR'
{
if (!$3) {
parser.suggestKeywords(['IF EXISTS']);
}
parser.suggestDatabases({ appendDot: true });
}
| 'DROP' '<impala>AGGREGATE' '<impala>FUNCTION' OptionalIfExists 'CURSOR'
{
if (!$4) {
parser.suggestKeywords(['IF EXISTS']);
}
parser.suggestDatabases({ appendDot: true });
}
| 'DROP' '<impala>FUNCTION' OptionalIfExists 'CURSOR' SchemaQualifiedIdentifier ParenthesizedImpalaArgumentList
{
if (!$3) {
parser.suggestKeywords(['IF EXISTS']);
}
}
| 'DROP' '<impala>FUNCTION' OptionalIfExists_EDIT
| 'DROP' 'CURSOR' '<impala>FUNCTION' OptionalIfExists SchemaQualifiedIdentifier ParenthesizedImpalaArgumentList
{
parser.suggestKeywords(['AGGREGATE']);
}
| 'DROP' '<impala>FUNCTION' OptionalIfExists SchemaQualifiedIdentifier ParenthesizedImpalaArgumentList_EDIT
| 'DROP' '<impala>AGGREGATE' 'CURSOR'
{
parser.suggestKeywords(['FUNCTION']);
}
| 'DROP' '<impala>AGGREGATE' '<impala>FUNCTION' OptionalIfExists 'CURSOR' SchemaQualifiedIdentifier ParenthesizedImpalaArgumentList
{
if (!$4) {
parser.suggestKeywords(['IF EXISTS']);
}
}
| 'DROP' '<impala>AGGREGATE' '<impala>FUNCTION' OptionalIfExists_EDIT
| 'DROP' '<impala>AGGREGATE' '<impala>FUNCTION' OptionalIfExists SchemaQualifiedIdentifier ParenthesizedImpalaArgumentList_EDIT
| 'DROP' '<impala>FUNCTION' OptionalIfExists SchemaQualifiedIdentifier_EDIT ParenthesizedImpalaArgumentList
| 'DROP' '<impala>AGGREGATE' '<impala>FUNCTION' OptionalIfExists SchemaQualifiedIdentifier_EDIT ParenthesizedImpalaArgumentList
;
DropHiveFunction
: 'DROP' '<hive>FUNCTION' OptionalIfExists SchemaQualifiedIdentifier
| 'DROP' '<hive>TEMPORARY' '<hive>FUNCTION' OptionalIfExists RegularIdentifier
;
DropHiveFunction_EDIT
: 'DROP' '<hive>FUNCTION' OptionalIfExists 'CURSOR'
{
if (!$3) {
parser.suggestKeywords(['IF EXISTS']);
}
}
| 'DROP' '<hive>FUNCTION' OptionalIfExists 'CURSOR' SchemaQualifiedIdentifier
{
if (!$3) {
parser.suggestKeywords(['IF EXISTS']);
}
}
| 'DROP' '<hive>FUNCTION' OptionalIfExists_EDIT
| 'DROP' '<hive>FUNCTION' OptionalIfExists_EDIT SchemaQualifiedIdentifier
| 'DROP' '<hive>FUNCTION' OptionalIfExists SchemaQualifiedIdentifier_EDIT
| 'DROP' '<hive>TEMPORARY' '<hive>FUNCTION' OptionalIfExists 'CURSOR'
{
if (!$4) {
parser.suggestKeywords(['IF EXISTS']);
}
}
| 'DROP' '<hive>TEMPORARY' '<hive>FUNCTION' OptionalIfExists_EDIT
;
DropRoleStatement
: 'DROP' AnyRole RegularIdentifier
;
DropStatsStatement
: 'DROP' '<impala>STATS' SchemaQualifiedTableIdentifier
{
parser.addTablePrimary($3);
}
| 'DROP' '<impala>INCREMENTAL' '<impala>STATS' SchemaQualifiedTableIdentifier PartitionSpec
{
parser.addTablePrimary($4);
}
;
DropStatsStatement_EDIT
: 'DROP' '<impala>STATS' 'CURSOR'
{
parser.suggestTables();
parser.suggestDatabases({ appendDot: true });
}
| 'DROP' '<impala>STATS' SchemaQualifiedTableIdentifier_EDIT
| 'DROP' 'CURSOR' '<impala>STATS' SchemaQualifiedTableIdentifier
{
parser.addTablePrimary($4);
parser.suggestKeywords(['INCREMENTAL']);
}
| 'DROP' 'CURSOR' '<impala>STATS' SchemaQualifiedTableIdentifier PartitionSpec
{
parser.addTablePrimary($4);
parser.suggestKeywords(['INCREMENTAL']);
}
| 'DROP' '<impala>INCREMENTAL' 'CURSOR'
{
parser.suggestKeywords(['STATS']);
}
| 'DROP' '<impala>INCREMENTAL' '<impala>STATS' 'CURSOR'
{
parser.suggestTables();
parser.suggestDatabases({ appendDot: true });
}
| 'DROP' '<impala>INCREMENTAL' '<impala>STATS' SchemaQualifiedTableIdentifier_EDIT
| 'DROP' '<impala>INCREMENTAL' '<impala>STATS' SchemaQualifiedTableIdentifier_EDIT PartitionSpec
| 'DROP' '<impala>INCREMENTAL' '<impala>STATS' SchemaQualifiedTableIdentifier 'CURSOR'
{
parser.addTablePrimary($4);
parser.suggestKeywords(['PARTITION']);
}
| 'DROP' '<impala>INCREMENTAL' '<impala>STATS' SchemaQualifiedTableIdentifier PartitionSpec_EDIT
{
parser.addTablePrimary($4);
}
;
DropTableStatement
: 'DROP' AnyTable OptionalIfExists SchemaQualifiedTableIdentifier OptionalPurge
{
parser.addTablePrimary($4);
}
;
DropTableStatement_EDIT
: 'DROP' AnyTable OptionalIfExists_EDIT
| 'DROP' AnyTable OptionalIfExists 'CURSOR'
{
if (!$3) {
parser.suggestKeywords(['IF EXISTS']);
}
parser.suggestTables({ onlyTables: true });
parser.suggestDatabases({
appendDot: true
});
}
| 'DROP' AnyTable OptionalIfExists SchemaQualifiedTableIdentifier_EDIT OptionalPurge
{
if (parser.yy.result.suggestTables) {
parser.yy.result.suggestTables.onlyTables = true;
}
}
| 'DROP' AnyTable OptionalIfExists_EDIT SchemaQualifiedTableIdentifier OptionalPurge
| 'DROP' AnyTable OptionalIfExists SchemaQualifiedTableIdentifier OptionalPurge 'CURSOR'
{
parser.addTablePrimary($4);
if (!$5) {
parser.suggestKeywords(['PURGE']);
}
}
;
OptionalPurge
:
| 'PURGE'
| '<hive>PURGE'
;
DropIndexStatement
: 'DROP' '<hive>INDEX' OptionalIfExists RegularOrBacktickedIdentifier 'ON' SchemaQualifiedTableIdentifier
{
parser.addTablePrimary($6);
}
;
DropIndexStatement_EDIT
: 'DROP' '<hive>INDEX' OptionalIfExists 'CURSOR'
{
parser.suggestKeywords(['IF EXISTS']);
}
| 'DROP' '<hive>INDEX' OptionalIfExists_EDIT
| 'DROP' '<hive>INDEX' OptionalIfExists RegularOrBacktickedIdentifier 'CURSOR'
{
parser.suggestKeywords(['ON']);
}
| 'DROP' '<hive>INDEX' OptionalIfExists RegularOrBacktickedIdentifier 'ON' 'CURSOR'
{
parser.suggestTables();
parser.suggestDatabases({ appendDot: true });
}
| 'DROP' '<hive>INDEX' OptionalIfExists RegularOrBacktickedIdentifier 'ON' SchemaQualifiedTableIdentifier_EDIT
;
DropMacroStatement
: 'DROP' '<hive>TEMPORARY' '<hive>MACRO' OptionalIfExists RegularIdentifier
;
DropMacroStatement_EDIT
: 'DROP' '<hive>TEMPORARY' 'CURSOR'
{
parser.suggestKeywords(['FUNCTION', 'MACRO']);
}
| 'DROP' '<hive>TEMPORARY' '<hive>MACRO' OptionalIfExists 'CURSOR'
{
if (!$4) {
parser.suggestKeywords(['IF EXISTS']);
}
}
| 'DROP' '<hive>TEMPORARY' '<hive>MACRO' OptionalIfExists_EDIT
;
DropViewStatement
: 'DROP' AnyView OptionalIfExists SchemaQualifiedTableIdentifier
{
parser.addTablePrimary($4);
}
;
DropViewStatement_EDIT
: 'DROP' AnyView OptionalIfExists 'CURSOR'
{
if (!$3) {
parser.suggestKeywords(['IF EXISTS']);
}
parser.suggestTables({ onlyViews: true });
parser.suggestDatabases({ appendDot: true });
}
| 'DROP' AnyView OptionalIfExists 'CURSOR' SchemaQualifiedTableIdentifier
{
parser.addTablePrimary($5);
if (!$3) {
parser.suggestKeywords(['IF EXISTS']);
}
}
| 'DROP' AnyView OptionalIfExists_EDIT
| 'DROP' AnyView OptionalIfExists_EDIT SchemaQualifiedTableIdentifier
{
parser.addTablePrimary($4);
}
| 'DROP' AnyView OptionalIfExists SchemaQualifiedTableIdentifier_EDIT
{
if (parser.yy.result.suggestTables) {
parser.yy.result.suggestTables.onlyViews = true;
}
}
;
TruncateTableStatement
: 'TRUNCATE' AnyTable OptionalIfExists SchemaQualifiedTableIdentifier OptionalPartitionSpec
{
parser.addTablePrimary($4);
}
;
TruncateTableStatement_EDIT
: 'TRUNCATE' 'CURSOR'
{
parser.suggestKeywords(['TABLE']);
}
| 'TRUNCATE' AnyTable OptionalIfExists 'CURSOR' OptionalPartitionSpec
{
parser.suggestTables();
parser.suggestDatabases({ appendDot: true });
if (parser.isImpala() && !$3) {
parser.suggestKeywords(['IF EXISTS']);
}
}
| 'TRUNCATE' AnyTable OptionalIfExists_EDIT OptionalPartitionSpec
| 'TRUNCATE' AnyTable OptionalIfExists SchemaQualifiedTableIdentifier_EDIT OptionalPartitionSpec
| 'TRUNCATE' AnyTable OptionalIfExists SchemaQualifiedTableIdentifier OptionalPartitionSpec 'CURSOR'
{
parser.addTablePrimary($4);
if (parser.isHive() && !$5) {
parser.suggestKeywords(['PARTITION']);
}
}
| 'TRUNCATE' AnyTable OptionalIfExists SchemaQualifiedTableIdentifier OptionalPartitionSpec_EDIT
{
parser.addTablePrimary($4);
}
| 'TRUNCATE' AnyTable OptionalIfExists 'CURSOR' SchemaQualifiedTableIdentifier OptionalPartitionSpec
{
parser.addTablePrimary($4);
if (parser.isImpala() && !$3) {
parser.suggestKeywords(['IF EXISTS']);
}
}
| 'TRUNCATE' AnyTable OptionalIfExists_EDIT SchemaQualifiedTableIdentifier OptionalPartitionSpec
;
HiveDeleteStatement
: '<hive>DELETE' 'FROM' SchemaQualifiedTableIdentifier OptionalWhereClause
{
parser.addTablePrimary($3);
}
;
HiveDeleteStatement_EDIT
: '<hive>DELETE' 'CURSOR'
{
parser.suggestKeywords(['FROM']);
}
| '<hive>DELETE' 'FROM' 'CURSOR'
{
parser.suggestTables();
parser.suggestDatabases({ appendDot: true });
}
| '<hive>DELETE' 'FROM' SchemaQualifiedTableIdentifier 'CURSOR' OptionalWhereClause
{
parser.addTablePrimary($3);
if (!$5) {
parser.suggestKeywords(['WHERE']);
}
}
| '<hive>DELETE' 'FROM' SchemaQualifiedTableIdentifier_EDIT OptionalWhereClause
| '<hive>DELETE' 'FROM' SchemaQualifiedTableIdentifier WhereClause_EDIT
{
parser.addTablePrimary($3);
}
;
ImpalaDeleteStatement
: '<impala>DELETE' OptionalImpalaDeleteTableRef 'FROM' TableReference OptionalWhereClause
;
ImpalaDeleteStatement_EDIT
: '<impala>DELETE' OptionalImpalaDeleteTableRef 'CURSOR'
{
parser.suggestKeywords(['FROM']);
if (parser.isImpala() && !$2) {
parser.suggestTables();
parser.suggestDatabases({ appendDot: true });
}
}
| '<impala>DELETE' ImpalaDeleteTableRef_EDIT
| '<impala>DELETE' OptionalImpalaDeleteTableRef 'FROM' 'CURSOR'
{
parser.suggestTables();
parser.suggestDatabases({ appendDot: true });
}
| '<impala>DELETE' OptionalImpalaDeleteTableRef 'FROM' TableReference 'CURSOR' OptionalWhereClause
{
var keywords = [{ value: 'FULL JOIN', weight: 1 }, { value: 'FULL OUTER JOIN', weight: 1 }, { value: 'JOIN', weight: 1 }, { value: 'LEFT JOIN', weight: 1 }, { value: 'LEFT OUTER JOIN', weight: 1 }, { value: 'RIGHT JOIN', weight: 1 }, { value: 'RIGHT OUTER JOIN', weight: 1 }, { value: 'INNER JOIN', weight: 1 }, { value: 'LEFT ANTI JOIN', weight: 1 }, { value: 'LEFT SEMI JOIN', weight: 1 }, { value: 'RIGHT ANTI JOIN', weight: 1 }, { value: 'RIGHT SEMI JOIN', weight: 1 }];
if (!$6) {
keywords.push({ value: 'WHERE', weight: 3 });
}
if ($4.suggestJoinConditions) {
parser.suggestJoinConditions($4.suggestJoinConditions);
}
if ($4.suggestJoins) {
parser.suggestJoins($4.suggestJoins);
}
if ($4.suggestKeywords) {
keywords = keywords.concat(parser.createWeightedKeywords($4.suggestKeywords, 2));
}
if (keywords.length > 0) {
parser.suggestKeywords(keywords);
}
}
| '<impala>DELETE' ImpalaDeleteTableRef_EDIT 'FROM'
| '<impala>DELETE' ImpalaDeleteTableRef_EDIT 'FROM' TableReference OptionalWhereClause
| '<impala>DELETE' OptionalImpalaDeleteTableRef 'FROM' TableReference_EDIT OptionalWhereClause
| '<impala>DELETE' OptionalImpalaDeleteTableRef 'FROM' TableReference WhereClause_EDIT
;
OptionalImpalaDeleteTableRef
:
| TableReference
;
ImpalaDeleteTableRef_EDIT
: TableReference_EDIT
;
HiveAbortStatement
: '<hive>ABORT' '<hive>TRANSACTIONS' TransactionIdList
;
HiveAbortStatement_EDIT
: '<hive>ABORT' 'CURSOR'
{
parser.suggestKeywords(['TRANSACTIONS']);
}
;
TransactionIdList
: UnsignedNumericLiteral
| TransactionIdList ',' UnsignedNumericLiteral
;

190
jison/sql_error.jison Executable file
View File

@ -0,0 +1,190 @@
// 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
{
if (parser.isHive()) {
parser.suggestDdlAndDmlKeywords(['EXPLAIN', 'FROM']);
} else if (parser.isImpala()) {
parser.suggestDdlAndDmlKeywords(['EXPLAIN']);
} else {
parser.suggestDdlAndDmlKeywords();
}
}
;
SelectStatement
: 'SELECT' OptionalAllOrDistinct OptionalStraightJoin SelectList_ERROR TableExpression
| 'SELECT' OptionalAllOrDistinct OptionalStraightJoin SelectList TableExpression_ERROR
;
SelectStatement_EDIT
: 'SELECT' OptionalAllOrDistinct OptionalStraightJoin SelectList_ERROR_EDIT TableExpression
{
parser.selectListNoTableSuggest($4, $2);
}
| 'SELECT' OptionalAllOrDistinct OptionalStraightJoin 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
;
LateralView
: '<hive>LATERAL' '<hive>VIEW' OptionalOuter ArbitraryFunction RegularOrBacktickedIdentifier '<hive>AS' error -> { }
| '<hive>LATERAL' '<hive>VIEW' OptionalOuter ArbitraryFunction error -> { }
| '<hive>LATERAL' '<hive>VIEW' OptionalOuter error -> { }
| '<hive>LATERAL' error -> { }
;
JoinType_EDIT
: 'FULL' 'CURSOR' error
{
parser.suggestKeywords(['JOIN', 'OUTER JOIN']);
}
| 'LEFT' 'CURSOR' error
{
if (parser.isHive()) {
parser.suggestKeywords(['JOIN', 'OUTER JOIN', 'SEMI JOIN']);
} else if (parser.isImpala()) {
parser.suggestKeywords(['ANTI JOIN', 'INNER JOIN', 'JOIN', 'OUTER JOIN', 'SEMI JOIN']);
} else {
parser.suggestKeywords(['JOIN', 'OUTER JOIN']);
}
}
| 'RIGHT' 'CURSOR' error
{
if (parser.isImpala()) {
parser.suggestKeywords(['ANTI JOIN', 'INNER JOIN', 'JOIN', 'OUTER JOIN', 'SEMI JOIN']);
} else {
parser.suggestKeywords(['JOIN', 'OUTER JOIN']);
}
}
;
OptionalSelectConditions_EDIT
: WhereClause error 'CURSOR' OptionalGroupByClause OptionalHavingClause OptionalWindowClause OptionalOrderByClause OptionalClusterOrDistributeBy OptionalLimitClause OptionalOffsetClause
{
$$ = {
suggestKeywords: parser.getKeywordsForOptionalsLR([$4, $5, $6, $7, $8, $9, $10], [{ value: 'GROUP BY', weight: 8 }, { value: 'HAVING', weight: 7 }, { value: 'WINDOW', weight: 6 }, { value: 'ORDER BY', weight: 5 }, [{ value: 'CLUSTER BY', weight: 4 }, { value: 'DISTRIBUTE BY', weight: 4 }, { value: 'SORT BY', weight: 4 }], { value: 'LIMIT', weight: 3 }, { value: 'OFFSET', weight: 2 }], [true, true, parser.isHive(), true, parser.isHive(), true, parser.isImpala()]),
cursorAtEnd: !$4 && !$5 && !$6 && !$7 && !$8 && !$9 && !$10
};
}
| OptionalWhereClause OptionalGroupByClause HavingClause error 'CURSOR' OptionalWindowClause OptionalOrderByClause OptionalClusterOrDistributeBy OptionalLimitClause OptionalOffsetClause
{
$$ = {
suggestKeywords: parser.getKeywordsForOptionalsLR([$6, $7, $8, $9, $10], [{ value: 'WINDOW', weight: 6 }, { value: 'ORDER BY', weight: 5 }, [{ value: 'CLUSTER BY', weight: 4 }, { value: 'DISTRIBUTE BY', weight: 4 }, { value: 'SORT BY', weight: 4 }], { value: 'LIMIT', weight: 3 }, { value: 'OFFSET', weight: 2 }], [parser.isHive(), true, parser.isHive(), true, parser.isImpala()]),
cursorAtEnd: !$6 && !$7 && !$8 && !$9 && !$10
}
}
| OptionalWhereClause OptionalGroupByClause OptionalHavingClause WindowClause error 'CURSOR' OptionalOrderByClause OptionalClusterOrDistributeBy OptionalLimitClause OptionalOffsetClause
{
$$ = {
suggestKeywords: parser.getKeywordsForOptionalsLR([$7, $8, $9, $10], [{ value: 'ORDER BY', weight: 5 }, [{ value: 'CLUSTER BY', weight: 4 }, { value: 'DISTRIBUTE BY', weight: 4 }, { value: 'SORT BY', weight: 4 }], { value: 'LIMIT', weight: 3 }, { value: 'OFFSET', weight: 2 }], [true, parser.isHive(), true, parser.isImpala()]),
cursorAtEnd: !$7 && !$8 && !$9 && !$10
}
}
| OptionalWhereClause OptionalGroupByClause OptionalHavingClause OptionalWindowClause OrderByClause error 'CURSOR' OptionalClusterOrDistributeBy OptionalLimitClause OptionalOffsetClause
{
$$ = {
suggestKeywords: parser.getKeywordsForOptionalsLR([$8, $9, $10], [[{ value: 'CLUSTER BY', weight: 4 }, { value: 'DISTRIBUTE BY', weight: 4 }, { value: 'SORT BY', weight: 4 }], { value: 'LIMIT', weight: 3 }, { value: 'OFFSET', weight: 2 }], [parser.isHive(), true, parser.isImpala()]),
cursorAtEnd: !$8 && !$9 && !$10
}
}
| OptionalWhereClause OptionalGroupByClause OptionalHavingClause OptionalWindowClause OptionalOrderByClause ClusterOrDistributeBy error 'CURSOR' OptionalLimitClause OptionalOffsetClause
{
$$ = {
suggestKeywords: parser.getKeywordsForOptionalsLR([$9, $10], [{ value: 'LIMIT', weight: 3 }, { value: 'OFFSET', weight: 2 }], [true, parser.isImpala()]),
cursorAtEnd: !$9 && !$10
}
}
| OptionalWhereClause OptionalGroupByClause OptionalHavingClause OptionalWindowClause OptionalOrderByClause OptionalClusterOrDistributeBy LimitClause error 'CURSOR' OptionalOffsetClause
{
$$ = {
suggestKeywords: parser.getKeywordsForOptionalsLR([$10], [{ value: 'OFFSET', weight: 2 }], [parser.isImpala()]),
cursorAtEnd: !$10
}
}
;
OptionalSelectConditions_EDIT
: WhereClause error GroupByClause_EDIT OptionalHavingClause OptionalWindowClause OptionalOrderByClause OptionalClusterOrDistributeBy OptionalLimitClause OptionalOffsetClause
| WhereClause error OptionalGroupByClause HavingClause_EDIT OptionalWindowClause OptionalOrderByClause OptionalClusterOrDistributeBy OptionalLimitClause OptionalOffsetClause
| WhereClause error OptionalGroupByClause OptionalHavingClause WindowClause_EDIT OptionalOrderByClause OptionalClusterOrDistributeBy OptionalLimitClause OptionalOffsetClause
| WhereClause error OptionalGroupByClause OptionalHavingClause OptionalWindowClause OrderByClause_EDIT OptionalClusterOrDistributeBy OptionalLimitClause OptionalOffsetClause
| WhereClause error OptionalGroupByClause OptionalHavingClause OptionalWindowClause OptionalOrderByClause ClusterOrDistributeBy_EDIT OptionalLimitClause OptionalOffsetClause
| WhereClause error OptionalGroupByClause OptionalHavingClause OptionalWindowClause OptionalOrderByClause OptionalClusterOrDistributeBy LimitClause_EDIT OptionalOffsetClause
| WhereClause error OptionalGroupByClause OptionalHavingClause OptionalWindowClause OptionalOrderByClause OptionalClusterOrDistributeBy OptionalLimitClause OffsetClause_EDIT
| OptionalWhereClause GroupByClause error HavingClause_EDIT OptionalWindowClause OptionalOrderByClause OptionalClusterOrDistributeBy OptionalLimitClause OptionalOffsetClause
| OptionalWhereClause GroupByClause error OptionalHavingClause WindowClause_EDIT OptionalOrderByClause OptionalClusterOrDistributeBy OptionalLimitClause OptionalOffsetClause
| OptionalWhereClause GroupByClause error OptionalHavingClause OptionalWindowClause OrderByClause_EDIT OptionalClusterOrDistributeBy OptionalLimitClause OptionalOffsetClause
| OptionalWhereClause GroupByClause error OptionalHavingClause OptionalWindowClause OptionalOrderByClause ClusterOrDistributeBy_EDIT OptionalLimitClause OptionalOffsetClause
| OptionalWhereClause GroupByClause error OptionalHavingClause OptionalWindowClause OptionalOrderByClause OptionalClusterOrDistributeBy LimitClause_EDIT OptionalOffsetClause
| OptionalWhereClause GroupByClause error OptionalHavingClause OptionalWindowClause OptionalOrderByClause OptionalClusterOrDistributeBy OptionalLimitClause OffsetClause_EDIT
| OptionalWhereClause OptionalGroupByClause HavingClause error WindowClause_EDIT OptionalOrderByClause OptionalClusterOrDistributeBy OptionalLimitClause OptionalOffsetClause
| OptionalWhereClause OptionalGroupByClause HavingClause error OptionalWindowClause OrderByClause_EDIT OptionalClusterOrDistributeBy OptionalLimitClause OptionalOffsetClause
| OptionalWhereClause OptionalGroupByClause HavingClause error OptionalWindowClause OptionalOrderByClause ClusterOrDistributeBy_EDIT OptionalLimitClause OptionalOffsetClause
| OptionalWhereClause OptionalGroupByClause HavingClause error OptionalWindowClause OptionalOrderByClause OptionalClusterOrDistributeBy LimitClause_EDIT OptionalOffsetClause
| OptionalWhereClause OptionalGroupByClause HavingClause error OptionalWindowClause OptionalOrderByClause OptionalClusterOrDistributeBy OptionalLimitClause OffsetClause_EDIT
| OptionalWhereClause OptionalGroupByClause OptionalHavingClause WindowClause error OrderByClause_EDIT OptionalClusterOrDistributeBy OptionalLimitClause OptionalOffsetClause
| OptionalWhereClause OptionalGroupByClause OptionalHavingClause WindowClause error OptionalOrderByClause ClusterOrDistributeBy_EDIT OptionalLimitClause OptionalOffsetClause
| OptionalWhereClause OptionalGroupByClause OptionalHavingClause WindowClause error OptionalOrderByClause OptionalClusterOrDistributeBy LimitClause_EDIT OptionalOffsetClause
| OptionalWhereClause OptionalGroupByClause OptionalHavingClause WindowClause error OptionalOrderByClause OptionalClusterOrDistributeBy OptionalLimitClause OffsetClause_EDIT
| OptionalWhereClause OptionalGroupByClause OptionalHavingClause OptionalWindowClause OrderByClause error ClusterOrDistributeBy_EDIT OptionalLimitClause OptionalOffsetClause
| OptionalWhereClause OptionalGroupByClause OptionalHavingClause OptionalWindowClause OrderByClause error OptionalClusterOrDistributeBy LimitClause_EDIT OptionalOffsetClause
| OptionalWhereClause OptionalGroupByClause OptionalHavingClause OptionalWindowClause OrderByClause error OptionalClusterOrDistributeBy OptionalLimitClause OffsetClause_EDIT
;
DatabaseDefinition_EDIT
: AnyCreate DatabaseOrSchema OptionalIfNotExists RegularIdentifier DatabaseDefinitionOptionals_EDIT error
;

516
jison/sql_grant.jison Executable file
View File

@ -0,0 +1,516 @@
// 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
: GrantStatement
| RevokeStatement
;
DataDefinition_EDIT
: GrantStatement_EDIT
| RevokeStatement_EDIT
;
GrantStatement
: '<hive>GRANT' HivePrivilegeTypeList OptionalOnSpecification 'TO' PrincipalSpecificationList OptionalWithGrantOption
| '<hive>GRANT' UserOrRoleList 'TO' PrincipalSpecificationList OptionalWithAdminOption
| '<hive>GRANT' '<hive>ROLE' UserOrRoleList 'TO' PrincipalSpecificationList OptionalWithAdminOption
| '<impala>GRANT' '<impala>ROLE' RegularOrBacktickedIdentifier 'TO' '<impala>GROUP' RegularOrBacktickedIdentifier
| '<impala>GRANT' ImpalaPrivilegeType 'ON' ImpalaObjectSpecification 'TO' RegularOrBacktickedIdentifier OptionalWithGrantOption
| '<impala>GRANT' ImpalaPrivilegeType 'ON' ImpalaObjectSpecification 'TO' '<impala>ROLE' RegularOrBacktickedIdentifier OptionalWithGrantOption
;
GrantStatement_EDIT
: '<hive>GRANT' 'CURSOR'
{
parser.suggestKeywords(['ALL', 'ALTER', 'CREATE', 'DELETE', 'DROP', 'INDEX', 'INSERT', 'LOCK', 'ROLE', 'SELECT', 'UPDATE']);
}
| '<hive>GRANT' HivePrivilegeTypeList_EDIT OptionalOnSpecification
| '<hive>GRANT' HivePrivilegeTypeList OnSpecification_EDIT
| '<hive>GRANT' HivePrivilegeTypeList OptionalOnSpecification 'CURSOR'
{
if (!$3) {
parser.suggestKeywords(['ON', 'TO']);
} else {
parser.suggestKeywords(['TO']);
}
}
| '<hive>GRANT' HivePrivilegeTypeList OptionalOnSpecification 'TO' 'CURSOR'
{
parser.suggestKeywords(['GROUP', 'ROLE', 'USER']);
}
| '<hive>GRANT' HivePrivilegeTypeList OptionalOnSpecification 'TO' PrincipalSpecificationList_EDIT
| '<hive>GRANT' HivePrivilegeTypeList OptionalOnSpecification 'TO' PrincipalSpecificationList OptionalWithGrantOption 'CURSOR'
{
if (!$6) {
parser.suggestKeywords(['WITH GRANT OPTION']);
}
}
| '<hive>GRANT' HivePrivilegeTypeList OptionalOnSpecification 'TO' PrincipalSpecificationList WithGrantOption_EDIT
| '<hive>GRANT' UserOrRoleList 'CURSOR'
{
parser.suggestKeywords(['TO']);
}
| '<hive>GRANT' UserOrRoleList 'TO' 'CURSOR'
{
parser.suggestKeywords(['GROUP', 'ROLE', 'USER']);
}
| '<hive>GRANT' UserOrRoleList 'TO' PrincipalSpecificationList_EDIT
| '<hive>GRANT' UserOrRoleList 'TO' PrincipalSpecificationList OptionalWithAdminOption 'CURSOR'
{
if (!$5) {
parser.suggestKeywords(['WITH ADMIN OPTION']);
}
}
| '<hive>GRANT' UserOrRoleList 'TO' PrincipalSpecificationList WithAdminOption_EDIT
| '<hive>GRANT' '<hive>ROLE' UserOrRoleList 'TO' 'CURSOR'
{
parser.suggestKeywords(['GROUP', 'ROLE', 'USER']);
}
| '<hive>GRANT' '<hive>ROLE' UserOrRoleList 'TO' PrincipalSpecificationList_EDIT
| '<hive>GRANT' '<hive>ROLE' UserOrRoleList 'TO' PrincipalSpecificationList OptionalWithAdminOption 'CURSOR'
{
if (!$6) {
parser.suggestKeywords(['WITH ADMIN OPTION']);
}
}
| '<hive>GRANT' '<hive>ROLE' UserOrRoleList 'TO' PrincipalSpecificationList WithAdminOption_EDIT
| '<impala>GRANT' 'CURSOR'
{
parser.suggestKeywords(['ALL', 'ALTER', 'CREATE', 'DROP', 'INSERT', 'REFRESH', 'ROLE', 'SELECT']);
}
| '<impala>GRANT' '<impala>ROLE' RegularOrBacktickedIdentifier 'CURSOR'
{
parser.suggestKeywords(['TO GROUP']);
}
| '<impala>GRANT' '<impala>ROLE' RegularOrBacktickedIdentifier 'TO' 'CURSOR'
{
parser.suggestKeywords(['GROUP']);
}
| '<impala>GRANT' ImpalaPrivilegeType_EDIT
| '<impala>GRANT' ImpalaPrivilegeType 'CURSOR'
{
if ($2.isCreate) {
parser.suggestKeywords(['ON DATABASE', 'ON SERVER']);
} else {
parser.suggestKeywords(['ON DATABASE', 'ON SERVER', 'ON TABLE', 'ON URI']);
}
}
| '<impala>GRANT' ImpalaPrivilegeType 'ON' 'CURSOR'
{
if ($2.isCreate) {
parser.suggestKeywords(['DATABASE', 'SERVER']);
} else {
parser.suggestKeywords(['DATABASE', 'SERVER', 'TABLE', 'URI']);
}
}
| '<impala>GRANT' ImpalaPrivilegeType 'ON' ImpalaObjectSpecification_EDIT
| '<impala>GRANT' ImpalaPrivilegeType 'ON' ImpalaObjectSpecification 'CURSOR'
{
parser.suggestKeywords(['TO']);
}
| '<impala>GRANT' ImpalaPrivilegeType 'ON' ImpalaObjectSpecification 'TO' 'CURSOR'
{
parser.suggestKeywords(['ROLE']);
}
| '<impala>GRANT' ImpalaPrivilegeType 'ON' ImpalaObjectSpecification 'TO' RegularOrBacktickedIdentifier OptionalWithGrantOption 'CURSOR'
{
if (!$7) {
parser.suggestKeywords(['WITH GRANT OPTION']);
}
}
| '<impala>GRANT' ImpalaPrivilegeType 'ON' ImpalaObjectSpecification 'TO' RegularOrBacktickedIdentifier WithGrantOption_EDIT
| '<impala>GRANT' ImpalaPrivilegeType 'ON' ImpalaObjectSpecification 'TO' '<impala>ROLE' RegularOrBacktickedIdentifier OptionalWithGrantOption 'CURSOR'
{
if (!$8) {
parser.suggestKeywords(['WITH GRANT OPTION']);
}
}
| '<impala>GRANT' ImpalaPrivilegeType 'ON' ImpalaObjectSpecification 'TO' '<impala>ROLE' RegularOrBacktickedIdentifier WithGrantOption_EDIT
;
OptionalOnSpecification
:
| 'ON' HiveObjectSpecification
;
OnSpecification_EDIT
: 'ON' 'CURSOR'
{
parser.suggestKeywords(['DATABASE', 'TABLE']);
parser.suggestTables();
parser.suggestDatabases({ appendDot: true });
}
| 'ON' HiveObjectSpecification_EDIT
;
HiveObjectSpecification
: 'DATABASE' RegularOrBacktickedIdentifier
| '<hive>TABLE' SchemaQualifiedTableIdentifier
{
parser.addTablePrimary($2);
}
| SchemaQualifiedTableIdentifier
{
parser.addTablePrimary($1);
}
;
HiveObjectSpecification_EDIT
: 'DATABASE' 'CURSOR'
{
parser.suggestDatabases();
}
| '<hive>TABLE' 'CURSOR'
{
parser.suggestTables();
parser.suggestDatabases({ appendDot: true });
}
| '<hive>TABLE' SchemaQualifiedTableIdentifier_EDIT
| SchemaQualifiedTableIdentifier_EDIT
;
ImpalaObjectSpecification
: 'DATABASE' RegularOrBacktickedIdentifier
| '<impala>TABLE' SchemaQualifiedTableIdentifier
{
parser.addTablePrimary($2);
}
| '<impala>SERVER' RegularOrBacktickedIdentifier
| '<impala>URI' RegularOrBacktickedIdentifier
;
ImpalaObjectSpecification_EDIT
: 'DATABASE' 'CURSOR'
{
parser.suggestDatabases();
}
| '<impala>TABLE' 'CURSOR'
{
parser.suggestTables();
parser.suggestDatabases({ appendDot: true });
}
| '<impala>TABLE' SchemaQualifiedTableIdentifier_EDIT
;
HivePrivilegeTypeList
: HivePrivilegeTypeWithOptionalColumn
{
if ($1.toUpperCase() === 'ALL') {
$$ = { singleAll: true };
}
}
| HivePrivilegeTypeList ',' HivePrivilegeTypeWithOptionalColumn
;
HivePrivilegeTypeList_EDIT
: HivePrivilegeTypeWithOptionalColumn_EDIT
| HivePrivilegeTypeList ',' HivePrivilegeTypeWithOptionalColumn_EDIT
| HivePrivilegeTypeWithOptionalColumn_EDIT ',' HivePrivilegeTypeList
| HivePrivilegeTypeList ',' HivePrivilegeTypeWithOptionalColumn_EDIT ',' HivePrivilegeTypeList
| 'CURSOR' ',' HivePrivilegeTypeList
{
parser.suggestKeywords(['ALL', 'ALTER', 'CREATE', 'DELETE', 'DROP', 'INDEX', 'INSERT', 'LOCK', 'SELECT', 'SHOW_DATABASE', 'UPDATE']);
}
| HivePrivilegeTypeList ',' 'CURSOR'
{
parser.suggestKeywords(['ALL', 'ALTER', 'CREATE', 'DELETE', 'DROP', 'INDEX', 'INSERT', 'LOCK', 'SELECT', 'SHOW_DATABASE', 'UPDATE']);
}
| HivePrivilegeTypeList ',' 'CURSOR' ',' HivePrivilegeTypeList
{
parser.suggestKeywords(['ALL', 'ALTER', 'CREATE', 'DELETE', 'DROP', 'INDEX', 'INSERT', 'LOCK', 'SELECT', 'SHOW_DATABASE', 'UPDATE']);
}
;
HivePrivilegeTypeWithOptionalColumn
: HivePrivilegeType OptionalParenthesizedColumnList
;
HivePrivilegeTypeWithOptionalColumn_EDIT
: HivePrivilegeType ParenthesizedColumnList_EDIT
;
HivePrivilegeType
: '<hive>INSERT'
| 'SELECT'
| 'UPDATE'
| '<hive>DELETE'
| 'ALTER'
| '<hive>CREATE'
| 'DROP'
| '<hive>INDEX'
| '<hive>LOCK'
| '<hive>SHOW_DATABASE'
| '<hive>ALL'
;
ImpalaPrivilegeType
: 'ALL'
| 'ALTER'
| '<impala>CREATE' --> { isCreate: true }
| 'DROP'
| '<impala>INSERT'
| '<impala>REFRESH'
| 'SELECT' OptionalParenthesizedColumnList
;
ImpalaPrivilegeType_EDIT
: 'SELECT' ParenthesizedColumnList_EDIT
;
PrincipalSpecificationList
: PrincipalSpecification
| PrincipalSpecificationList ',' PrincipalSpecification
;
PrincipalSpecificationList_EDIT
: PrincipalSpecificationList ',' 'CURSOR'
{
parser.suggestKeywords(['GROUP', 'ROLE', 'USER']);
}
| 'CURSOR' ',' PrincipalSpecificationList
{
parser.suggestKeywords(['GROUP', 'ROLE', 'USER']);
}
| PrincipalSpecificationList ',' 'CURSOR' ',' PrincipalSpecificationList
{
parser.suggestKeywords(['GROUP', 'ROLE', 'USER']);
}
;
PrincipalSpecification
: '<hive>USER' RegularOrBacktickedIdentifier
| 'GROUP' RegularOrBacktickedIdentifier
| '<hive>ROLE' RegularOrBacktickedIdentifier
;
PrincipalSpecification_EDIT
: '<hive>USER' 'CURSOR'
| 'GROUP' 'CURSOR'
| '<hive>ROLE' 'CURSOR'
;
UserOrRoleList
: RegularOrBacktickedIdentifier
| UserOrRoleList ',' RegularOrBacktickedIdentifier
;
OptionalWithGrantOption
:
| 'WITH' '<hive>GRANT' 'OPTION'
| 'WITH' '<impala>GRANT' 'OPTION'
;
WithGrantOption_EDIT
: 'WITH' 'CURSOR'
{
parser.suggestKeywords(['GRANT OPTION']);
}
| 'WITH' '<hive>GRANT' 'CURSOR'
{
parser.suggestKeywords(['OPTION']);
}
| 'WITH' '<impala>GRANT' 'CURSOR'
{
parser.suggestKeywords(['OPTION']);
}
;
OptionalWithAdminOption
:
| 'WITH' '<hive>ADMIN' 'OPTION'
;
WithAdminOption_EDIT
: 'WITH' 'CURSOR'
{
parser.suggestKeywords(['ADMIN OPTION']);
}
| 'WITH' '<hive>ADMIN' 'CURSOR'
{
parser.suggestKeywords(['OPTION']);
}
;
RevokeStatement
: '<hive>REVOKE' HivePrivilegeTypeList OptionalOnSpecification 'FROM' PrincipalSpecificationList
| '<hive>REVOKE' '<hive>GRANT' 'OPTION' '<hive>FOR' HivePrivilegeTypeList OptionalOnSpecification 'FROM' PrincipalSpecificationList
| '<hive>REVOKE' UserOrRoleList 'FROM' PrincipalSpecificationList
| '<hive>REVOKE' '<hive>ROLE' UserOrRoleList 'FROM' PrincipalSpecificationList
| '<hive>REVOKE' '<hive>ADMIN' 'OPTION' '<hive>FOR' UserOrRoleList 'FROM' PrincipalSpecificationList
| '<hive>REVOKE' '<hive>ADMIN' 'OPTION' '<hive>FOR' '<hive>ROLE' UserOrRoleList 'FROM' PrincipalSpecificationList
| '<hive>REVOKE' '<hive>ALL' PrivilegesOrGrantOption 'FROM' UserOrRoleList
| '<impala>REVOKE' '<impala>ROLE' RegularOrBacktickedIdentifier 'FROM' '<impala>GROUP' RegularOrBacktickedIdentifier
| '<impala>REVOKE' ImpalaPrivilegeType 'ON' ImpalaObjectSpecification 'FROM' RegularOrBacktickedIdentifier
| '<impala>REVOKE' ImpalaPrivilegeType 'ON' ImpalaObjectSpecification 'FROM' '<impala>ROLE' RegularOrBacktickedIdentifier
;
RevokeStatement_EDIT
: '<hive>REVOKE' 'CURSOR'
{
parser.suggestKeywords(['ADMIN OPTION FOR', 'ALL', 'ALL GRANT OPTION FROM', 'ALL PRIVILEGES FROM', 'ALTER', 'CREATE', 'DELETE', 'DROP', 'GRANT OPTION FOR', 'INDEX', 'INSERT', 'LOCK', 'ROLE', 'SELECT', 'UPDATE']);
}
| '<hive>REVOKE' HivePrivilegeTypeList_EDIT
| '<hive>REVOKE' HivePrivilegeTypeList OnSpecification_EDIT
| '<hive>REVOKE' HivePrivilegeTypeList OptionalOnSpecification 'CURSOR'
{
if (!$3) {
if ($2.singleAll) {
parser.suggestKeywords(['FROM', 'GRANT OPTION', 'ON', 'PRIVILEGES FROM']);
} else {
parser.suggestKeywords(['FROM', 'ON']);
}
} else {
parser.suggestKeywords(['FROM']);
}
}
| '<hive>REVOKE' HivePrivilegeTypeList OptionalOnSpecification 'FROM' 'CURSOR'
{
parser.suggestKeywords(['GROUP', 'ROLE', 'USER']);
}
| '<hive>REVOKE' HivePrivilegeTypeList OptionalOnSpecification 'FROM' PrincipalSpecificationList_EDIT
| '<hive>REVOKE' '<hive>GRANT' 'CURSOR'
{
parser.suggestKeywords(['OPTION FOR']);
}
| '<hive>REVOKE' '<hive>GRANT' 'OPTION' 'CURSOR'
{
parser.suggestKeywords(['FOR']);
}
| '<hive>REVOKE' '<hive>GRANT' 'OPTION' '<hive>FOR' 'CURSOR'
{
parser.suggestKeywords(['ALL', 'ALTER', 'CREATE', 'DELETE', 'DROP', 'INDEX', 'INSERT', 'LOCK', 'SELECT', 'SHOW_DATABASE', 'UPDATE']);
}
| '<hive>REVOKE' '<hive>GRANT' 'OPTION' '<hive>FOR' HivePrivilegeTypeList_EDIT
| '<hive>REVOKE' '<hive>GRANT' 'OPTION' '<hive>FOR' HivePrivilegeTypeList OnSpecification_EDIT
| '<hive>REVOKE' '<hive>GRANT' 'OPTION' '<hive>FOR' HivePrivilegeTypeList OptionalOnSpecification 'CURSOR'
{
if (!$6) {
parser.suggestKeywords(['FROM', 'ON']);
} else {
parser.suggestKeywords(['FROM']);
}
}
| '<hive>REVOKE' '<hive>GRANT' 'OPTION' '<hive>FOR' HivePrivilegeTypeList OptionalOnSpecification 'FROM' 'CURSOR'
{
parser.suggestKeywords(['GROUP', 'ROLE', 'USER']);
}
| '<hive>REVOKE' '<hive>GRANT' 'OPTION' '<hive>FOR' HivePrivilegeTypeList OptionalOnSpecification 'FROM' PrincipalSpecificationList_EDIT
| '<hive>REVOKE' UserOrRoleList 'CURSOR'
{
if ($2.toUpperCase() === 'ADMIN') {
parser.suggestKeywords(['FROM', 'OPTION FOR']);
} else {
parser.suggestKeywords(['FROM']);
}
}
| '<hive>REVOKE' UserOrRoleList 'FROM' 'CURSOR'
{
parser.suggestKeywords(['GROUP', 'ROLE', 'USER']);
}
| '<hive>REVOKE' UserOrRoleList 'FROM' PrincipalSpecificationList_EDIT
| '<hive>REVOKE' '<hive>ROLE' UserOrRoleList 'CURSOR'
{
parser.suggestKeywords(['FROM']);
}
| '<hive>REVOKE' '<hive>ROLE' UserOrRoleList 'FROM' 'CURSOR'
{
parser.suggestKeywords(['GROUP', 'ROLE', 'USER']);
}
| '<hive>REVOKE' '<hive>ROLE' UserOrRoleList 'FROM' PrincipalSpecificationList_EDIT
| '<hive>REVOKE' '<hive>ADMIN' 'OPTION' 'CURSOR'
{
parser.suggestKeywords(['FOR']);
}
| '<hive>REVOKE' '<hive>ADMIN' 'OPTION' '<hive>FOR' 'CURSOR'
{
parser.suggestKeywords(['ROLE']);
}
| '<hive>REVOKE' '<hive>ADMIN' 'OPTION' '<hive>FOR' UserOrRoleList 'CURSOR'
{
parser.suggestKeywords(['FROM']);
}
| '<hive>REVOKE' '<hive>ADMIN' 'OPTION' '<hive>FOR' UserOrRoleList 'FROM' 'CURSOR'
{
parser.suggestKeywords(['GROUP', 'ROLE', 'USER']);
}
| '<hive>REVOKE' '<hive>ADMIN' 'OPTION' '<hive>FOR' UserOrRoleList 'FROM' PrincipalSpecificationList_EDIT
| '<hive>REVOKE' '<hive>ADMIN' 'OPTION' '<hive>FOR' '<hive>ROLE' UserOrRoleList 'CURSOR'
{
parser.suggestKeywords(['FROM']);
}
| '<hive>REVOKE' '<hive>ADMIN' 'OPTION' '<hive>FOR' '<hive>ROLE' UserOrRoleList 'FROM' 'CURSOR'
{
parser.suggestKeywords(['GROUP', 'ROLE', 'USER']);
}
| '<hive>REVOKE' '<hive>ADMIN' 'OPTION' '<hive>FOR' '<hive>ROLE' UserOrRoleList 'FROM' PrincipalSpecificationList_EDIT
| '<hive>REVOKE' '<hive>ALL' PrivilegesOrGrantOption_EDIT
| '<hive>REVOKE' '<hive>ALL' PrivilegesOrGrantOption 'CURSOR'
{
parser.suggestKeywords(['FROM']);
}
| '<impala>REVOKE' 'CURSOR'
{
parser.suggestKeywords(['ALL', 'ALTER', 'CREATE', 'DROP', 'INSERT', 'REFRESH', 'ROLE', 'SELECT']);
}
| '<impala>REVOKE' '<impala>ROLE' RegularOrBacktickedIdentifier 'CURSOR'
{
parser.suggestKeywords(['FROM GROUP']);
}
| '<impala>REVOKE' '<impala>ROLE' RegularOrBacktickedIdentifier 'FROM' 'CURSOR'
{
parser.suggestKeywords(['GROUP']);
}
| '<impala>REVOKE' ImpalaPrivilegeType_EDIT
| '<impala>REVOKE' ImpalaPrivilegeType 'CURSOR'
{
if ($2.isCreate) {
parser.suggestKeywords(['ON DATABASE', 'ON SERVER']);
} else {
parser.suggestKeywords(['ON DATABASE', 'ON SERVER', 'ON TABLE', 'ON URI']);
}
}
| '<impala>REVOKE' ImpalaPrivilegeType 'ON' 'CURSOR'
{
if ($2.isCreate) {
parser.suggestKeywords(['DATABASE', 'SERVER']);
} else {
parser.suggestKeywords(['DATABASE', 'SERVER', 'TABLE', 'URI']);
}
}
| '<impala>REVOKE' ImpalaPrivilegeType 'ON' ImpalaObjectSpecification_EDIT
| '<impala>REVOKE' ImpalaPrivilegeType 'ON' ImpalaObjectSpecification 'CURSOR'
{
parser.suggestKeywords(['FROM']);
}
| '<impala>REVOKE' ImpalaPrivilegeType 'ON' ImpalaObjectSpecification 'FROM' 'CURSOR'
{
parser.suggestKeywords(['ROLE']);
}
;
PrivilegesOrGrantOption
: '<hive>PRIVILEGES'
| '<hive>GRANT' 'OPTION'
;
PrivilegesOrGrantOption_EDIT
: '<hive>GRANT' 'CURSOR'
{
parser.suggestKeywords(['OPTION']);
}
;

762
jison/sql_insert.jison Executable file
View File

@ -0,0 +1,762 @@
// 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
: HiveInsertStatement
| InsertValuesStatement
| ImpalaInsertOrUpsertStatement
| CommonTableExpression HiveInsertStatement
| CommonTableExpression ImpalaInsertOrUpsertStatement
| HiveMergeStatement
;
DataManipulation_EDIT
: HiveInsertStatement_EDIT
| InsertValuesStatement_EDIT
| ImpalaInsertOrUpsertStatement_EDIT
| CommonTableExpression HiveInsertStatement_EDIT
{
parser.addCommonTableExpressions($1);
}
| CommonTableExpression_EDIT HiveInsertStatement
| CommonTableExpression ImpalaInsertOrUpsertStatement_EDIT
{
parser.addCommonTableExpressions($1);
}
| CommonTableExpression_EDIT ImpalaInsertOrUpsertStatement
| HiveMergeStatement_EDIT
;
HiveInsertStatement
: HiveInsertWithoutQuery QuerySpecification
| FromClause HiveInserts
| FromClause SelectWithoutTableExpression OptionalSelectConditions
;
HiveInsertStatement_EDIT
: HiveInsertWithoutQuery_EDIT
| HiveInsertWithoutQuery 'CURSOR'
{
var keywords = [];
if ($1.suggestKeywords) {
keywords = parser.createWeightedKeywords($1.suggestKeywords, 2).concat([{ value: 'SELECT', weight: 1}]);
} else {
keywords = ['SELECT'];
}
if ($1.addValues) {
keywords.push({ weight: 1.1, value: 'VALUES' });
}
if (keywords.length > 0) {
parser.suggestKeywords(keywords);
}
}
| HiveInsertWithoutQuery_EDIT QuerySpecification
| HiveInsertWithoutQuery QuerySpecification_EDIT
| FromClause HiveInserts_EDIT
{
if (!$2.keepTables) {
delete parser.yy.result.suggestTables;
delete parser.yy.result.suggestDatabases;
}
}
| FromClause_EDIT
| FromClause_EDIT HiveInserts
| FromClause_EDIT SelectWithoutTableExpression OptionalSelectConditions
| FromClause 'CURSOR'
{
parser.suggestKeywords(['INSERT INTO', 'INSERT OVERWRITE', 'SELECT']);
}
| FromClause SelectWithoutTableExpression_EDIT OptionalSelectConditions
{
if ($2.cursorAtEnd) {
parser.checkForSelectListKeywords($2);
var keywords = parser.yy.result.suggestKeywords || [];
if ($3.suggestKeywords) {
keywords = keywords.concat($3.suggestKeywords);
}
if (keywords.length > 0) {
parser.suggestKeywords(keywords);
}
}
delete parser.yy.result.suggestTables;
delete parser.yy.result.suggestDatabases;
}
| FromClause SelectWithoutTableExpression OptionalSelectConditions_EDIT
{
if ($3.cursorAtStart) {
parser.checkForSelectListKeywords($2.tableExpression);
}
}
;
HiveInsertWithoutQuery
: '<hive>INSERT' '<hive>OVERWRITE' OptionalHiveTable SchemaQualifiedTableIdentifier OptionalPartitionSpec OptionalIfNotExists
{
$4.owner = 'insert';
parser.addTablePrimary($4);
if (!$5 && !$6) {
$$ = { suggestKeywords: ['PARTITION'] }
} else if (!$6) {
$$ = { suggestKeywords: ['IF NOT EXISTS'] }
}
}
| '<hive>INSERT' '<hive>OVERWRITE' '<hive>LOCAL' '<hive>DIRECTORY' HdfsPath OptionalInsertRowFormat OptionalStoredAs
{
if (!$6 && !$7) {
$$ = { suggestKeywords: [{ value: 'ROW FORMAT', weight: 2 }, { value: 'STORED AS', weight: 1}] };
} else if (!$7) {
$$ = { suggestKeywords: ['STORED AS'] };
}
}
| '<hive>INSERT' '<hive>OVERWRITE_DIRECTORY' HdfsPath OptionalInsertRowFormat OptionalStoredAs
{
if (!$4 && !$5) {
$$ = { suggestKeywords: [{ value: 'ROW FORMAT', weight: 2 }, { value: 'STORED AS', weight: 1}] };
} else if (!$5) {
$$ = { suggestKeywords: ['STORED AS'] };
}
}
| '<hive>INSERT' 'INTO' OptionalHiveTable SchemaQualifiedTableIdentifier OptionalPartitionSpec OptionalParenthesizedColumnList
{
$4.owner = 'insert';
parser.addTablePrimary($4);
if (!$5 && !$6) {
$$ = { suggestKeywords: ['PARTITION'], addValues: true };
} else if (!$6) {
$$ = { addValues: true };
}
}
;
HiveInsertWithoutQuery_EDIT
: '<hive>INSERT' 'CURSOR'
{
parser.suggestKeywords(['OVERWRITE', 'INTO']);
}
| '<hive>INSERT' '<hive>OVERWRITE' OptionalHiveTable 'CURSOR'
{
if (!$3) {
parser.suggestKeywords(['DIRECTORY', 'LOCAL DIRECTORY', 'TABLE']);
}
parser.suggestTables();
parser.suggestDatabases({ appendDot: true });
$$ = { keepTables: true }
}
| '<hive>INSERT' '<hive>OVERWRITE' OptionalHiveTable SchemaQualifiedTableIdentifier_EDIT OptionalPartitionSpec OptionalParenthesizedColumnList
{
$$ = { keepTables: true }
}
| '<hive>INSERT' '<hive>OVERWRITE' OptionalHiveTable SchemaQualifiedTableIdentifier OptionalPartitionSpec_EDIT OptionalIfNotExists
{
$4.owner = 'insert';
parser.addTablePrimary($4);
if (parser.yy.result.suggestColumns) {
parser.yy.result.suggestColumns.owner = 'insert';
}
}
| '<hive>INSERT' '<hive>OVERWRITE' OptionalHiveTable SchemaQualifiedTableIdentifier OptionalPartitionSpec OptionalIfNotExists_EDIT
{
$4.owner = 'insert';
parser.addTablePrimary($4);
}
| '<hive>INSERT' '<hive>OVERWRITE' '<hive>LOCAL' 'CURSOR'
{
parser.suggestKeywords(['DIRECTORY']);
}
| '<hive>INSERT' '<hive>OVERWRITE' '<hive>LOCAL' '<hive>DIRECTORY' HdfsPath_EDIT OptionalInsertRowFormat OptionalStoredAs
| '<hive>INSERT' '<hive>OVERWRITE' '<hive>LOCAL' '<hive>DIRECTORY' HdfsPath OptionalInsertRowFormat_EDIT OptionalStoredAs
| '<hive>INSERT' '<hive>OVERWRITE' '<hive>LOCAL' '<hive>DIRECTORY' HdfsPath OptionalInsertRowFormat OptionalStoredAs_EDIT
| '<hive>INSERT' '<hive>OVERWRITE_DIRECTORY' HdfsPath_EDIT OptionalInsertRowFormat OptionalStoredAs // DIRECTORY is a non-reserved keyword
| '<hive>INSERT' '<hive>OVERWRITE_DIRECTORY' HdfsPath OptionalInsertRowFormat_EDIT OptionalStoredAs
| '<hive>INSERT' '<hive>OVERWRITE_DIRECTORY' HdfsPath OptionalInsertRowFormat OptionalStoredAs_EDIT
| '<hive>INSERT' 'INTO' OptionalHiveTable 'CURSOR'
{
if (!$3) {
parser.suggestKeywords(['TABLE']);
}
parser.suggestTables();
parser.suggestDatabases({ appendDot: true });
$$ = { keepTables: true }
}
| '<hive>INSERT' 'INTO' OptionalHiveTable SchemaQualifiedTableIdentifier_EDIT OptionalPartitionSpec OptionalParenthesizedColumnList
{
$$ = { keepTables: true }
}
| '<hive>INSERT' 'INTO' OptionalHiveTable SchemaQualifiedTableIdentifier OptionalPartitionSpec_EDIT OptionalParenthesizedColumnList
{
$4.owner = 'insert';
parser.addTablePrimary($4);
if (parser.yy.result.suggestColumns) {
parser.yy.result.suggestColumns.owner = 'insert';
}
}
| '<hive>INSERT' 'INTO' OptionalHiveTable SchemaQualifiedTableIdentifier OptionalPartitionSpec OptionalParenthesizedColumnList_EDIT
{
$4.owner = 'insert';
parser.addTablePrimary($4);
if (parser.yy.result.suggestColumns) {
parser.yy.result.suggestColumns.owner = 'insert';
}
}
;
HiveInserts
: HiveInsert
| HiveInserts HiveInsert
;
HiveInserts_EDIT
: HiveInsert_EDIT
| HiveInserts HiveInsert_EDIT
| HiveInsert_EDIT HiveInserts
| HiveInserts HiveInsert_EDIT HiveInserts
;
// TODO: Verify Hive unions in insert
HiveInsert
: HiveInsertWithoutQuery SelectWithoutTableExpression OptionalSelectConditions
;
HiveInsert_EDIT
: HiveInsertWithoutQuery_EDIT
| HiveInsertWithoutQuery_EDIT SelectWithoutTableExpression OptionalSelectConditions
| HiveInsertWithoutQuery 'CURSOR'
{
if ($1.suggestKeywords) {
parser.suggestKeywords(parser.createWeightedKeywords($1.suggestKeywords, 2).concat([{ value: 'SELECT', weight: 1}]));
} else {
parser.suggestKeywords(['SELECT']);
}
}
| HiveInsertWithoutQuery SelectWithoutTableExpression_EDIT OptionalSelectConditions
{
if ($2.cursorAtEnd) {
parser.checkForSelectListKeywords($2);
var keywords = parser.yy.result.suggestKeywords || [];
if ($3.suggestKeywords) {
keywords = keywords.concat($3.suggestKeywords);
}
if (keywords.length > 0) {
parser.suggestKeywords(keywords);
}
}
}
| HiveInsertWithoutQuery SelectWithoutTableExpression OptionalSelectConditions_EDIT
;
InsertValuesStatement
: '<hive>INSERT' 'INTO' OptionalHiveTable SchemaQualifiedTableIdentifier OptionalPartitionSpec 'VALUES' InsertValuesList
{
$4.owner = 'insert';
parser.addTablePrimary($4);
}
| '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'
;
OptionalInsertRowFormat
:
| 'ROW' '<hive>FORMAT' HiveDelimitedRowFormat
;
OptionalInsertRowFormat_EDIT
: 'ROW' 'CURSOR'
{
parser.suggestKeywords(['FORMAT DELIMITED']);
}
| 'ROW' '<hive>FORMAT' 'CURSOR'
{
parser.suggestKeywords(['DELIMITED']);
}
| 'ROW' '<hive>FORMAT' HiveDelimitedRowFormat_EDIT
;
SelectWithoutTableExpression
: 'SELECT' OptionalAllOrDistinct OptionalStraightJoin SelectList -> { selectList: $4 }
;
SelectWithoutTableExpression_EDIT
: 'SELECT' OptionalAllOrDistinct OptionalStraightJoin SelectList 'CURSOR'
{
$$ = $4;
$$.cursorAtEnd = true;
}
| 'SELECT' OptionalAllOrDistinct OptionalStraightJoin SelectList_EDIT
{
parser.selectListNoTableSuggest($4, $2);
}
| 'SELECT' OptionalAllOrDistinct OptionalStraightJoin 'CURSOR'
{
var keywords = parser.getSelectListKeywords();
if (!$2 || $2 === 'ALL') {
parser.suggestAggregateFunctions();
parser.suggestAnalyticFunctions();
}
if (!$3 && !$2) {
keywords.push({ value: 'ALL', weight: 2 });
keywords.push({ value: 'DISTINCT', weight: 2 });
}
if (parser.isImpala() && !$3) {
keywords.push({ value: 'STRAIGHT_JOIN', weight: 1 });
}
parser.suggestKeywords(keywords);
parser.suggestFunctions();
parser.suggestColumns();
}
;
OptionalHiveTable
:
| '<hive>TABLE'
;
ImpalaInsertOrUpsertStatement
: ImpalaInsertOrUpsertStatementWithoutCTE
;
ImpalaInsertOrUpsertStatement_EDIT
: ImpalaInsertOrUpsertStatementWithoutCTE_EDIT
;
ImpalaInsertOrUpsertStatementWithoutCTE
: ImpalaInsertOrUpsertLeftPart OptionalImpalaShuffleOrNoShuffle SelectStatement OptionalUnions
| ImpalaInsertOrUpsertLeftPart 'VALUES' ImpalaRowValuesLists
;
ImpalaInsertOrUpsertStatementWithoutCTE_EDIT
: ImpalaInsertOrUpsertLeftPart_EDIT
| ImpalaInsertOrUpsertLeftPart OptionalImpalaShuffleOrNoShuffle 'CURSOR'
{
var keywords = $1.suggestKeywords && !$2 ? parser.createWeightedKeywords($1.suggestKeywords, 2) : [];
if (!$2) {
keywords = keywords.concat(['[NOSHUFFLE]', '[SHUFFLE]', 'SELECT', 'VALUES'])
} else {
keywords = keywords.concat(['SELECT'])
}
parser.suggestKeywords(keywords);
}
| ImpalaInsertOrUpsertLeftPart_EDIT OptionalImpalaShuffleOrNoShuffle SelectStatement OptionalUnions
| ImpalaInsertOrUpsertLeftPart OptionalImpalaShuffleOrNoShuffle SelectStatement_EDIT OptionalUnions
| ImpalaInsertOrUpsertLeftPart OptionalImpalaShuffleOrNoShuffle SelectStatement OptionalUnions_EDIT
| ImpalaInsertOrUpsertLeftPart_EDIT 'VALUES' ImpalaRowValuesLists
| ImpalaInsertOrUpsertLeftPart 'VALUES' ImpalaRowValuesLists_EDIT
;
ImpalaInsertOrUpsertLeftPart
: ImpalaUpsertStatementLeftPart
| ImpalaInsertLeftPart
;
ImpalaInsertOrUpsertLeftPart_EDIT
: ImpalaUpsertStatementLeftPart_EDIT
| ImpalaInsertLeftPart_EDIT
;
ImpalaUpsertStatementLeftPart
: '<impala>UPSERT' 'INTO' OptionalImpalaTable SchemaQualifiedTableIdentifier OptionalParenthesizedColumnList
{
$4.owner = 'upsert';
parser.addTablePrimary($4);
}
;
ImpalaUpsertStatementLeftPart_EDIT
: '<impala>UPSERT' 'CURSOR'
{
parser.suggestKeywords(['INTO']);
}
| '<impala>UPSERT' 'INTO' OptionalImpalaTable 'CURSOR'
{
if (!$3) {
parser.suggestKeywords(['TABLE']);
}
parser.suggestTables();
parser.suggestDatabases({ appendDot: true });
}
| '<impala>UPSERT' 'INTO' OptionalImpalaTable 'CURSOR' SchemaQualifiedTableIdentifier OptionalParenthesizedColumnList
{
if (!$3) {
parser.suggestKeywords(['TABLE']);
}
$5.owner = 'upsert';
parser.addTablePrimary($5);
}
| '<impala>UPSERT' 'INTO' OptionalImpalaTable SchemaQualifiedTableIdentifier_EDIT OptionalParenthesizedColumnList
| '<impala>UPSERT' 'INTO' OptionalImpalaTable SchemaQualifiedTableIdentifier OptionalParenthesizedColumnList_EDIT
{
$4.owner = 'upsert';
parser.addTablePrimary($4);
if (parser.yy.result.suggestColumns) {
parser.yy.result.suggestColumns.owner = 'upsert';
}
}
;
ImpalaInsertLeftPart
: '<impala>INSERT' IntoOrOverwrite OptionalImpalaTable SchemaQualifiedTableIdentifier OptionalParenthesizedColumnList OptionalPartitionSpec
{
$4.owner = 'insert';
parser.addTablePrimary($4);
if (!$6) {
$$ = { suggestKeywords: ['PARTITION'] };
}
}
;
ImpalaInsertLeftPart_EDIT
: '<impala>INSERT' 'CURSOR'
{
parser.suggestKeywords(['INTO', 'OVERWRITE']);
}
| '<impala>INSERT' IntoOrOverwrite OptionalImpalaTable 'CURSOR'
{
if (!$3) {
parser.suggestKeywords(['TABLE']);
}
parser.suggestTables();
parser.suggestDatabases({ appendDot: true });
}
| '<impala>INSERT' IntoOrOverwrite OptionalImpalaTable 'CURSOR' SchemaQualifiedTableIdentifier OptionalParenthesizedColumnList OptionalPartitionSpec
{
if (!$3) {
parser.suggestKeywords(['TABLE']);
}
$5.owner = 'insert';
parser.addTablePrimary($5);
}
| '<impala>INSERT' IntoOrOverwrite OptionalImpalaTable SchemaQualifiedTableIdentifier_EDIT OptionalParenthesizedColumnList OptionalPartitionSpec
| '<impala>INSERT' IntoOrOverwrite OptionalImpalaTable SchemaQualifiedTableIdentifier OptionalParenthesizedColumnList_EDIT OptionalPartitionSpec
{
$4.owner = 'insert';
parser.addTablePrimary($4);
if (parser.yy.result.suggestColumns) {
parser.yy.result.suggestColumns.owner = 'insert';
}
}
| '<impala>INSERT' IntoOrOverwrite OptionalImpalaTable SchemaQualifiedTableIdentifier OptionalParenthesizedColumnList OptionalPartitionSpec_EDIT
{
$4.owner = 'insert';
parser.addTablePrimary($4);
if (parser.yy.result.suggestColumns) {
parser.yy.result.suggestColumns.owner = 'insert';
}
}
;
IntoOrOverwrite
: 'INTO'
| '<impala>OVERWRITE'
;
OptionalImpalaTable
:
| '<impala>TABLE'
;
OptionalImpalaShuffleOrNoShuffle
:
| '<impala>SHUFFLE'
| '<impala>NOSHUFFLE'
;
ImpalaRowValuesLists
: ParenthesizedImpalaRowValuesList
| ImpalaRowValuesLists ',' ParenthesizedImpalaRowValuesList
;
ImpalaRowValuesLists_EDIT
: ParenthesizedImpalaRowValuesList_EDIT
| ImpalaRowValuesLists ',' ParenthesizedImpalaRowValuesList_EDIT
| ImpalaRowValuesLists ',' ParenthesizedImpalaRowValuesList_EDIT ',' ImpalaRowValuesLists
| ParenthesizedImpalaRowValuesList_EDIT ',' ImpalaRowValuesLists
;
ParenthesizedImpalaRowValuesList
: '(' ValueExpressionList ')'
;
ParenthesizedImpalaRowValuesList_EDIT
: '(' AnyCursor RightParenthesisOrError
{
parser.suggestFunctions();
}
| '(' ValueExpressionList_EDIT RightParenthesisOrError
;
HiveMergeStatement
: HiveMergeStatementLeftPart 'ON' ValueExpression WhenList
;
HiveMergeStatement_EDIT
: HiveMergeStatementLeftPart_EDIT
| HiveMergeStatementLeftPart 'CURSOR'
{
parser.suggestKeywords(['ON']);
}
| HiveMergeStatementLeftPart 'ON' 'CURSOR'
{
parser.valueExpressionSuggest();
}
| HiveMergeStatementLeftPart 'ON' ValueExpression_EDIT
| HiveMergeStatementLeftPart 'ON' ValueExpression 'CURSOR'
{
parser.suggestValueExpressionKeywords($3, [{ value: 'WHEN', weight: 2 }]);
}
| HiveMergeStatementLeftPart 'ON' ValueExpression WhenList_EDIT
;
HiveMergeStatementLeftPart
: '<hive>MERGE' 'INTO' SchemaQualifiedTableIdentifier '<hive>AS' RegularIdentifier '<hive>USING' MergeSource '<hive>AS' RegularIdentifier
{
$3.alias = $5;
parser.addTablePrimary($3);
if ($7.subQuery) {
parser.addTablePrimary({ subQueryAlias: $9 });
} else {
$7.alias = $9;
}
}
;
HiveMergeStatementLeftPart_EDIT
: '<hive>MERGE' 'CURSOR'
{
parser.suggestKeywords(['INTO']);
}
| '<hive>MERGE' 'INTO' 'CURSOR'
{
parser.suggestDatabases({ appendDot: true });
parser.suggestTables();
}
| '<hive>MERGE' 'INTO' SchemaQualifiedTableIdentifier_EDIT
| '<hive>MERGE' 'INTO' SchemaQualifiedTableIdentifier 'CURSOR'
{
parser.addTablePrimary($3);
parser.suggestKeywords(['AS T USING']);
}
| '<hive>MERGE' 'INTO' SchemaQualifiedTableIdentifier '<hive>AS' 'CURSOR'
{
parser.addTablePrimary($3);
parser.suggestKeywords(['T USING']);
}
| '<hive>MERGE' 'INTO' SchemaQualifiedTableIdentifier '<hive>AS' RegularIdentifier 'CURSOR'
{
$3.alias = $5;
parser.addTablePrimary($3);
parser.suggestKeywords(['USING']);
}
| '<hive>MERGE' 'INTO' SchemaQualifiedTableIdentifier '<hive>AS' RegularIdentifier '<hive>USING' 'CURSOR'
{
$3.alias = $5;
parser.addTablePrimary($3);
parser.suggestDatabases({ appendDot: true });
parser.suggestTables();
}
| '<hive>MERGE' 'INTO' SchemaQualifiedTableIdentifier '<hive>AS' RegularIdentifier '<hive>USING' MergeSource_EDIT
{
$3.alias = $5;
parser.addTablePrimary($3);
}
| '<hive>MERGE' 'INTO' SchemaQualifiedTableIdentifier '<hive>AS' RegularIdentifier '<hive>USING' MergeSource 'CURSOR'
{
$3.alias = $5;
parser.addTablePrimary($3);
parser.suggestKeywords(['AS S ON']);
}
| '<hive>MERGE' 'INTO' SchemaQualifiedTableIdentifier '<hive>AS' RegularIdentifier '<hive>USING' MergeSource '<hive>AS' 'CURSOR'
{
$3.alias = $5;
parser.addTablePrimary($3);
parser.suggestKeywords(['S ON']);
}
;
MergeSource
: '(' TableSubQueryInner ')' --> $2
| SchemaQualifiedTableIdentifier
{
parser.addTablePrimary($1);
}
;
MergeSource_EDIT
: '(' 'CURSOR' RightParenthesisOrError
{
parser.suggestKeywords(['SELECT']);
}
| '(' TableSubQueryInner_EDIT RightParenthesisOrError
| SchemaQualifiedTableIdentifier_EDIT
;
WhenList
: WhenClause
| WhenClause WhenClause
| WhenClause WhenClause WhenClause
;
WhenList_EDIT
: WhenClause_EDIT
{
if ($1.suggestThenKeywords) {
parser.suggestKeywords(['DELETE', 'INSERT VALUES', 'UPDATE SET']);
}
}
| WhenClause 'CURSOR'
{
if (!$1.notPresent) {
parser.suggestKeywords(['WHEN']);
}
}
| WhenClause WhenClause_EDIT
{
if (!$1.notPresent && $2.suggestThenKeywords) {
var keywords = [];
if (!$1.isDelete) {
keywords.push('DELETE');
}
if (!$1.isInsert) {
keywords.push('INSERT VALUES');
}
if (!$1.isUpdate) {
keywords.push('UPDATE SET');
}
parser.suggestKeywords(keywords);
}
}
| WhenClause WhenClause 'CURSOR'
{
if (!$2.notPresent) {
parser.suggestKeywords(['WHEN']);
}
}
| WhenClause WhenClause WhenClause_EDIT
{
if (!$2.notPresent && $3.suggestThenKeywords) {
var keywords = [];
if (!$1.isDelete && !$2.isDelete) {
keywords.push('DELETE');
}
if (!$1.isInsert && !$2.isInsert) {
keywords.push('INSERT VALUES');
}
if (!$1.isUpdate && !$2.isUpdate) {
keywords.push('UPDATE SET');
}
parser.suggestKeywords(keywords);
}
}
;
WhenClause
: 'WHEN' OptionalNot '<hive>MATCHED' OptionalMatchCondition 'THEN' UpdateDeleteOrInsert --> { notPresent: !!$2, isDelete: $6.isDelete, isInsert: $6.isInsert, isUpdate: $6.isUpdate }
;
WhenClause_EDIT
: 'WHEN' OptionalNot 'CURSOR'
{
if (!$2) {
parser.suggestKeywords(['NOT MATCHED', 'MATCHED']);
} else {
parser.suggestKeywords(['MATCHED']);
}
}
| 'WHEN' OptionalNot '<hive>MATCHED' OptionalMatchCondition 'CURSOR'
{
if (!$4) {
parser.suggestKeywords(['AND', 'THEN']);
} else {
parser.suggestValueExpressionKeywords($4, [{ value: 'THEN', weight: 2 }]);
}
}
| 'WHEN' OptionalNot '<hive>MATCHED' MatchCondition_EDIT
| 'WHEN' OptionalNot '<hive>MATCHED' OptionalMatchCondition 'THEN' 'CURSOR' --> { suggestThenKeywords: true }
| 'WHEN' OptionalNot '<hive>MATCHED' OptionalMatchCondition 'THEN' UpdateDeleteOrInsert_EDIT
;
OptionalMatchCondition
:
| 'AND' ValueExpression --> $2
;
MatchCondition_EDIT
: 'AND' 'CURSOR'
{
parser.valueExpressionSuggest();
}
;
UpdateDeleteOrInsert
: 'UPDATE' 'SET' SetClauseList --> { isUpdate: true }
| '<hive>DELETE' --> { isDelete: true }
| '<hive>INSERT' 'VALUES' InsertValuesList --> { isInsert: true }
;
UpdateDeleteOrInsert_EDIT
: 'UPDATE' 'CURSOR'
{
parser.suggestKeywords(['SET']);
}
| 'UPDATE' 'SET' SetClauseList_EDIT
| '<hive>INSERT' 'CURSOR'
{
parser.suggestKeywords(['VALUES']);
}
;

291
jison/sql_load.jison Executable file
View File

@ -0,0 +1,291 @@
// 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
: LoadStatement
| ImportStatement
| ExportStatement
;
DataManipulation_EDIT
: LoadStatement_EDIT
| ImportStatement_EDIT
| ExportStatement_EDIT
;
LoadStatement
: AnyLoad AnyData OptionalHiveLocal AnyInpath HdfsPath OptionalOverwrite 'INTO' AnyTable SchemaQualifiedTableIdentifier OptionalPartitionSpec
{
parser.addTablePrimary($9);
}
;
LoadStatement_EDIT
: AnyLoad 'CURSOR'
{
if (parser.isHive()) {
parser.suggestKeywords(['DATA LOCAL INPATH', 'DATA INPATH']);
} else if (parser.isImpala()) {
parser.suggestKeywords(['DATA INPATH']);
}
}
| AnyLoad AnyData OptionalHiveLocal 'CURSOR'
{
if (parser.isHive() && !$3) {
parser.suggestKeywords(['INPATH', 'LOCAL INPATH']);
} else {
parser.suggestKeywords(['INPATH']);
}
}
| AnyLoad AnyData OptionalHiveLocal AnyInpath HdfsPath_EDIT OptionalOverwrite
| AnyLoad AnyData OptionalHiveLocal AnyInpath HdfsPath OptionalOverwrite 'CURSOR'
{
if (!$6) {
parser.suggestKeywords(['OVERWRITE INTO TABLE', 'INTO TABLE']);
} else {
parser.suggestKeywords(['INTO TABLE']);
}
}
| AnyLoad AnyData OptionalHiveLocal AnyInpath HdfsPath OptionalOverwrite 'INTO' 'CURSOR'
{
parser.suggestKeywords([ 'TABLE' ]);
}
| AnyLoad AnyData OptionalHiveLocal AnyInpath HdfsPath OptionalOverwrite 'INTO' AnyTable 'CURSOR'
{
parser.suggestTables();
parser.suggestDatabases({ appendDot: true });
}
| AnyLoad AnyData OptionalHiveLocal AnyInpath HdfsPath OptionalOverwrite 'INTO' AnyTable SchemaQualifiedTableIdentifier_EDIT OptionalPartitionSpec
| AnyLoad AnyData OptionalHiveLocal AnyInpath HdfsPath OptionalOverwrite 'INTO' AnyTable SchemaQualifiedTableIdentifier OptionalPartitionSpec 'CURSOR'
{
parser.addTablePrimary($9);
if (!$10) {
parser.suggestKeywords(['PARTITION']);
}
}
| AnyLoad AnyData OptionalHiveLocal AnyInpath HdfsPath OptionalOverwrite 'INTO' AnyTable SchemaQualifiedTableIdentifier OptionalPartitionSpec_EDIT
{
parser.addTablePrimary($9);
}
| AnyLoad AnyData OptionalHiveLocal AnyInpath HdfsPath_EDIT OptionalOverwrite 'INTO' AnyTable SchemaQualifiedTableIdentifier OptionalPartitionSpec
{
parser.addTablePrimary($9);
}
;
OptionalOverwrite
:
| '<hive>OVERWRITE'
| '<impala>OVERWRITE'
;
OptionalHiveLocal
:
| '<hive>LOCAL'
;
AnyLoad
: '<hive>LOAD'
| '<impala>LOAD'
;
AnyData
: '<hive>DATA'
| '<impala>DATA'
;
AnyInpath
: '<hive>INPATH'
| '<impala>INPATH'
;
ImportStatement
: '<hive>IMPORT' OptionalTableWithPartition PushHdfsLexerState 'FROM' HdfsPath OptionalHdfsLocation
;
ImportStatement_EDIT
: '<hive>IMPORT' 'CURSOR' OptionalTableWithPartition
{
if (!$3) {
parser.suggestKeywords(['EXTERNAL TABLE', 'FROM', 'TABLE']);
} else if (!$3.hasExternal) {
parser.suggestKeywords(['EXTERNAL']);
}
}
| '<hive>IMPORT' TableWithPartition 'CURSOR'
{
if ($2.suggestKeywords) {
parser.suggestKeywords(parser.createWeightedKeywords($2.suggestKeywords, 2).concat(['FROM']));
} else {
parser.suggestKeywords(['FROM']);
}
}
| '<hive>IMPORT' TableWithPartition_EDIT
| '<hive>IMPORT' OptionalTableWithPartition PushHdfsLexerState 'FROM' HdfsPath_EDIT OptionalHdfsLocation
| '<hive>IMPORT' OptionalTableWithPartition PushHdfsLexerState 'FROM' HdfsPath HdfsLocation_EDIT
| '<hive>IMPORT' OptionalTableWithPartition PushHdfsLexerState 'FROM' HdfsPath OptionalHdfsLocation 'CURSOR'
{
if (!$6) {
parser.suggestKeywords(['LOCATION']);
}
}
| '<hive>IMPORT' 'CURSOR' OptionalTableWithPartition PushHdfsLexerState 'FROM' HdfsPath OptionalHdfsLocation
{
if (!$3) {
parser.suggestKeywords(['EXTERNAL TABLE', 'TABLE']);
} else if (!$3.hasExternal) {
parser.suggestKeywords(['EXTERNAL']);
}
}
| '<hive>IMPORT' TableWithPartition_EDIT PushHdfsLexerState 'FROM' HdfsPath OptionalHdfsLocation
| '<hive>IMPORT' TableWithPartition 'CURSOR' PushHdfsLexerState 'FROM' HdfsPath OptionalHdfsLocation
{
if ($2.suggestKeywords) {
parser.suggestKeywords(parser.createWeightedKeywords($2.suggestKeywords, 2).concat(['FROM']));
}
}
;
OptionalTableWithPartition
:
| TableWithPartition
;
TableWithPartition
: '<hive>EXTERNAL' '<hive>TABLE' SchemaQualifiedTableIdentifier OptionalPartitionSpec
{
parser.addTablePrimary($3);
if (!$4) {
$$ = { hasExternal: true, suggestKeywords: ['PARTITION'] };
} else {
$$ = { hasExternal: true }
}
}
| '<hive>TABLE' SchemaQualifiedTableIdentifier OptionalPartitionSpec
{
parser.addTablePrimary($2);
if (!$3) {
$$ = { suggestKeywords: ['PARTITION'] };
}
}
;
TableWithPartition_EDIT
: '<hive>EXTERNAL' 'CURSOR'
{
parser.suggestKeywords(['TABLE']);
}
| '<hive>EXTERNAL' '<hive>TABLE' 'CURSOR'
{
parser.suggestTables();
parser.suggestDatabases({ appendDot: true });
}
| '<hive>EXTERNAL' '<hive>TABLE' SchemaQualifiedTableIdentifier_EDIT OptionalPartitionSpec
| '<hive>EXTERNAL' '<hive>TABLE' SchemaQualifiedTableIdentifier PartitionSpec_EDIT
{
parser.addTablePrimary($3);
}
| '<hive>TABLE' 'CURSOR'
{
parser.suggestTables();
parser.suggestDatabases({ appendDot: true });
}
| '<hive>TABLE' SchemaQualifiedTableIdentifier_EDIT OptionalPartitionSpec
| '<hive>TABLE' SchemaQualifiedTableIdentifier PartitionSpec_EDIT
{
parser.addTablePrimary($3);
}
;
ExportStatement
: '<hive>EXPORT' '<hive>TABLE' SchemaQualifiedTableIdentifier OptionalPartitionSpec PushHdfsLexerState 'TO' HdfsPath
{
parser.addTablePrimary($3);
}
| '<hive>EXPORT' '<hive>TABLE' SchemaQualifiedTableIdentifier OptionalPartitionSpec PushHdfsLexerState 'TO' HdfsPath '<hive>FOR' '<hive>REPLICATION' '(' QuotedValue ')'
{
parser.addTablePrimary($3);
}
;
ExportStatement_EDIT
: '<hive>EXPORT' 'CURSOR'
{
parser.suggestKeywords(['TABLE']);
}
| '<hive>EXPORT' '<hive>TABLE' 'CURSOR'
{
parser.suggestTables();
parser.suggestDatabases({ appendDot: true });
}
| '<hive>EXPORT' '<hive>TABLE' SchemaQualifiedTableIdentifier_EDIT
| '<hive>EXPORT' '<hive>TABLE' SchemaQualifiedTableIdentifier OptionalPartitionSpec 'CURSOR'
{
parser.addTablePrimary($3);
if (!$4) {
parser.suggestKeywords([{ weight: 2, value: 'PARTITION' }, { weight: 1, value: 'TO' }]);
} else {
parser.suggestKeywords([ 'TO' ]);
}
}
| '<hive>EXPORT' '<hive>TABLE' SchemaQualifiedTableIdentifier PartitionSpec_EDIT
{
parser.addTablePrimary($3);
}
| '<hive>EXPORT' '<hive>TABLE' SchemaQualifiedTableIdentifier OptionalPartitionSpec PushHdfsLexerState 'TO' HdfsPath_EDIT
{
parser.addTablePrimary($3);
}
| '<hive>EXPORT' '<hive>TABLE' SchemaQualifiedTableIdentifier OptionalPartitionSpec PushHdfsLexerState 'TO' HdfsPath 'CURSOR'
{
parser.addTablePrimary($3);
parser.suggestKeywords(['FOR replication()']);
}
| '<hive>EXPORT' '<hive>TABLE' SchemaQualifiedTableIdentifier OptionalPartitionSpec PushHdfsLexerState 'TO' HdfsPath '<hive>FOR' 'CURSOR'
{
parser.addTablePrimary($3);
parser.suggestKeywords(['replication()']);
}
| '<hive>EXPORT' '<hive>TABLE' SchemaQualifiedTableIdentifier_EDIT OptionalPartitionSpec PushHdfsLexerState 'TO' HdfsPath
| '<hive>EXPORT' '<hive>TABLE' SchemaQualifiedTableIdentifier_EDIT OptionalPartitionSpec PushHdfsLexerState 'TO' HdfsPath '<hive>FOR' '<hive>REPLICATION' '(' QuotedValue ')'
| '<hive>EXPORT' '<hive>TABLE' SchemaQualifiedTableIdentifier OptionalPartitionSpec 'CURSOR' PushHdfsLexerState 'TO' HdfsPath
{
parser.addTablePrimary($3);
if (!$4) {
parser.suggestKeywords(['PARTITION']);
}
}
| '<hive>EXPORT' '<hive>TABLE' SchemaQualifiedTableIdentifier OptionalPartitionSpec 'CURSOR' PushHdfsLexerState 'TO' HdfsPath '<hive>FOR' '<hive>REPLICATION' '(' QuotedValue ')'
{
parser.addTablePrimary($3);
if (!$4) {
parser.suggestKeywords(['PARTITION']);
}
}
| '<hive>EXPORT' '<hive>TABLE' SchemaQualifiedTableIdentifier PartitionSpec_EDIT PushHdfsLexerState 'TO' HdfsPath
{
parser.addTablePrimary($3);
}
| '<hive>EXPORT' '<hive>TABLE' SchemaQualifiedTableIdentifier PartitionSpec_EDIT PushHdfsLexerState 'TO' HdfsPath '<hive>FOR' '<hive>REPLICATION' '(' QuotedValue ')'
{
parser.addTablePrimary($3);
}
| '<hive>EXPORT' '<hive>TABLE' SchemaQualifiedTableIdentifier OptionalPartitionSpec PushHdfsLexerState 'TO' HdfsPath_EDIT '<hive>FOR' '<hive>REPLICATION' '(' QuotedValue ')'
{
parser.addTablePrimary($3);
}
;

4024
jison/sql_main.jison Executable file

File diff suppressed because it is too large Load Diff

67
jison/sql_set.jison Executable file
View File

@ -0,0 +1,67 @@
// 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
: SetRoleStatement
| SetSpecification
;
DataDefinition_EDIT
: SetRoleStatement_EDIT
| 'SET' 'CURSOR'
{
parser.suggestSetOptions();
if (parser.isHive()) {
parser.suggestKeywords(['ROLE']);
}
if (parser.isImpala()) {
parser.suggestKeywords(['ALL']);
}
}
;
SetSpecification
: 'SET' SetOption '=' SetValue
| 'SET' 'ALL'
;
SetOption
: RegularIdentifier
| SetOption AnyDot RegularIdentifier
;
SetValue
: RegularIdentifier
| SignedInteger
| SignedInteger RegularIdentifier
| QuotedValue
| 'TRUE'
| 'FALSE'
| 'NULL'
;
SetRoleStatement
: 'SET' '<hive>ROLE' RegularIdentifier
| 'SET' '<hive>ROLE' '<hive>ALL'
| 'SET' '<hive>ROLE' '<hive>NONE'
;
SetRoleStatement_EDIT
: 'SET' '<hive>ROLE' 'CURSOR'
{
parser.suggestKeywords(['ALL', 'NONE']);
}
;

706
jison/sql_show.jison Executable file
View File

@ -0,0 +1,706 @@
// 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
: ShowStatement
;
DataDefinition_EDIT
: ShowStatement_EDIT
;
ShowStatement
: ShowColumnStatsStatement
| ShowColumnsStatement
| ShowCompactionsStatement
| ShowConfStatement
| ShowCreateTableStatement
| ShowCurrentRolesStatement
| ShowDatabasesStatement
| ShowFilesStatement
| ShowFunctionsStatement
| ShowGrantStatement
| ShowIndexStatement
| ShowLocksStatement
| ShowPartitionsStatement
| ShowRoleStatement
| ShowRolesStatement
| ShowTableStatement
| ShowTablesStatement
| ShowTblPropertiesStatement
| ShowTransactionsStatement
| ShowViewsStatement
;
AnyShow
: 'SHOW'
| '<hive>SHOW'
;
ShowStatement_EDIT
: AnyShow 'CURSOR'
{
if (parser.isHive()) {
parser.suggestKeywords(['COLUMNS', 'COMPACTIONS', 'CONF', 'CREATE TABLE', 'CURRENT ROLES', 'DATABASES', 'FORMATTED', 'FUNCTIONS', 'GRANT', 'INDEX', 'INDEXES', 'LOCKS', 'PARTITIONS', 'PRINCIPALS', 'ROLE GRANT', 'ROLES', 'SCHEMAS', 'TABLE EXTENDED', 'TABLES', 'TBLPROPERTIES', 'TRANSACTIONS', 'VIEWS']);
} else if (parser.isImpala()) {
parser.suggestKeywords(['AGGREGATE FUNCTIONS', 'ANALYTIC FUNCTIONS', 'COLUMN STATS', 'CREATE TABLE', 'CURRENT ROLES', 'DATABASES', 'FILES IN', 'FUNCTIONS', 'GRANT ROLE', 'PARTITIONS', 'RANGE PARTITIONS', 'ROLE GRANT GROUP', 'ROLES', 'SCHEMAS', 'TABLE STATS', 'TABLES']);
} else {
parser.suggestKeywords(['COLUMNS', 'DATABASES', 'TABLES']);
}
}
| AnyShow 'CURSOR' RegularOrBackTickedSchemaQualifiedName
{
// ROLES is considered a non-reserved keywords so we can't match it in ShowCurrentRolesStatement_EDIT
if ($3.identifierChain && $3.identifierChain.length === 1 && $3.identifierChain[0].name.toLowerCase() === 'roles') {
parser.suggestKeywords(['CURRENT']);
parser.yy.locations.pop();
} else {
parser.addTablePrimary($3);
if (parser.isImpala()) {
parser.suggestKeywords(['COLUMN STATS', 'CREATE TABLE', 'FILES IN', 'PARTITIONS', 'RANGE PARTITIONS', 'TABLE STATS']);
}
}
}
| AnyShow 'CURSOR' LIKE SingleQuotedValue
{
if (parser.isImpala()) {
parser.suggestKeywords(['AGGREGATE FUNCTIONS', 'ANALYTIC FUNCTIONS', 'DATABASES', 'FUNCTIONS', 'SCHEMAS', 'TABLES']);
} else if (parser.isHive()) {
parser.suggestKeywords(['DATABASES', 'SCHEMAS', 'TABLE EXTENDED']);
}
}
| ShowColumnStatsStatement_EDIT
| ShowColumnsStatement_EDIT
| ShowCreateTableStatement_EDIT
| ShowCurrentRolesStatement_EDIT
| ShowDatabasesStatement_EDIT
| ShowFilesStatement_EDIT
| ShowFunctionsStatement_EDIT
| ShowGrantStatement_EDIT
| ShowIndexStatement_EDIT
| ShowLocksStatement_EDIT
| ShowPartitionsStatement_EDIT
| ShowRoleStatement_EDIT
| ShowTableStatement_EDIT
| ShowTablesStatement_EDIT
| ShowTblPropertiesStatement_EDIT
| ShowViewsStatement_EDIT
;
ShowColumnStatsStatement
: AnyShow '<impala>COLUMN' '<impala>STATS' RegularOrBackTickedSchemaQualifiedName
{
parser.addTablePrimary($4);
}
;
ShowColumnStatsStatement_EDIT
: AnyShow '<impala>COLUMN' 'CURSOR'
{
parser.suggestKeywords(['STATS']);
}
| AnyShow '<impala>COLUMN' '<impala>STATS' 'CURSOR'
{
parser.suggestTables();
parser.suggestDatabases({
appendDot: true
});
}
| AnyShow '<impala>COLUMN' '<impala>STATS' RegularOrBackTickedSchemaQualifiedName_EDIT
;
ShowColumnsStatement
: AnyShow '<hive>COLUMNS' AnyFromOrIn RegularOrBacktickedIdentifier
| AnyShow '<hive>COLUMNS' AnyFromOrIn RegularOrBacktickedIdentifier AnyFromOrIn RegularOrBacktickedIdentifier
;
ShowColumnsStatement_EDIT
: AnyShow '<hive>COLUMNS' 'CURSOR'
{
parser.suggestKeywords(['FROM', 'IN']);
}
| AnyShow '<hive>COLUMNS' 'CURSOR' RegularOrBacktickedIdentifier
{
parser.suggestKeywords(['FROM', 'IN']);
}
| AnyShow '<hive>COLUMNS' AnyFromOrIn 'CURSOR'
{
parser.suggestTables();
}
| AnyShow '<hive>COLUMNS' AnyFromOrIn 'CURSOR' AnyFromOrIn
{
parser.suggestTables();
}
| AnyShow '<hive>COLUMNS' AnyFromOrIn 'CURSOR' AnyFromOrIn RegularOrBacktickedIdentifier
{
parser.suggestTables();
}
| AnyShow '<hive>COLUMNS' AnyFromOrIn RegularOrBacktickedIdentifier 'CURSOR'
{
parser.suggestKeywords(['FROM', 'IN']);
}
| AnyShow '<hive>COLUMNS' AnyFromOrIn RegularOrBacktickedIdentifier 'CURSOR' RegularOrBacktickedIdentifier
{
parser.suggestKeywords(['FROM', 'IN']);
}
| AnyShow '<hive>COLUMNS' AnyFromOrIn RegularOrBacktickedIdentifier AnyFromOrIn 'CURSOR'
{
parser.suggestDatabases();
}
;
ShowCompactionsStatement
: AnyShow '<hive>COMPACTIONS'
;
ShowConfStatement
: AnyShow '<hive>CONF' ConfigurationName
;
ShowCreateTableStatement
: AnyShow HiveOrImpalaCreate AnyTableOrView RegularOrBackTickedSchemaQualifiedName
{
parser.addTablePrimary($4);
}
;
ShowCreateTableStatement_EDIT
: AnyShow HiveOrImpalaCreate 'CURSOR'
{
if (parser.isImpala()) {
parser.suggestKeywords(['TABLE', 'VIEW']);
} else {
parser.suggestKeywords(['TABLE']);
}
}
| AnyShow HiveOrImpalaCreate AnyTableOrView 'CURSOR'
{
if ($3.isView && parser.isImpala()) {
parser.suggestTables({ onlyViews: true });
} else {
parser.suggestTables();
}
parser.suggestDatabases({
appendDot: true
});
}
| AnyShow HiveOrImpalaCreate AnyTableOrView RegularOrBackTickedSchemaQualifiedName_EDIT
{
if (parser.yy.result.suggestTables && $3.isView) {
parser.yy.result.suggestTables.onlyViews = true;
}
}
| AnyShow HiveOrImpalaCreate 'CURSOR' RegularOrBackTickedSchemaQualifiedName
{
parser.addTablePrimary($4);
if (parser.isImpala()) {
parser.suggestKeywords(['TABLE', 'VIEW']);
} else {
parser.suggestKeywords(['TABLE']);
}
}
;
AnyTableOrView
: AnyTable
| 'VIEW' --> { isView: true }
;
ShowCurrentRolesStatement
: AnyShow '<hive>CURRENT' '<hive>ROLES'
| AnyShow '<impala>CURRENT' '<impala>ROLES'
;
ShowCurrentRolesStatement_EDIT
: AnyShow '<hive>CURRENT' 'CURSOR'
{
parser.suggestKeywords([ 'ROLES' ]);
}
| AnyShow '<impala>CURRENT' 'CURSOR'
{
parser.suggestKeywords([ 'ROLES' ]);
}
;
ShowDatabasesStatement
: AnyShow HiveOrImpalaDatabasesOrSchemas 'LIKE' SingleQuotedValue
| AnyShow '<impala>DATABASES' SingleQuotedValue
;
ShowDatabasesStatement_EDIT
: AnyShow HiveOrImpalaDatabasesOrSchemas 'CURSOR'
{
parser.suggestKeywords(['LIKE']);
}
;
ShowFilesStatement
: AnyShow '<impala>FILES' 'IN' RegularOrBackTickedSchemaQualifiedName OptionalPartitionSpec
{
parser.addTablePrimary($4);
}
;
ShowFilesStatement_EDIT
: AnyShow '<impala>FILES' 'CURSOR'
{
parser.suggestKeywords(['IN']);
}
| AnyShow '<impala>FILES' 'IN' 'CURSOR'
{
parser.suggestTables();
parser.suggestDatabases({
appendDot: true
});
}
| AnyShow '<impala>FILES' 'IN' RegularOrBackTickedSchemaQualifiedName_EDIT OptionalPartitionSpec
| AnyShow '<impala>FILES' 'IN' RegularOrBackTickedSchemaQualifiedName OptionalPartitionSpec 'CURSOR'
{
parser.addTablePrimary($4);
if (!$5) {
parser.suggestKeywords(['PARTITION']);
}
}
| AnyShow '<impala>FILES' 'IN' RegularOrBackTickedSchemaQualifiedName OptionalPartitionSpec_EDIT
| AnyShow '<impala>FILES' 'CURSOR' RegularOrBackTickedSchemaQualifiedName OptionalPartitionSpec
{
parser.addTablePrimary($4);
parser.suggestKeywords(['IN']);
}
;
ShowFunctionsStatement
: AnyShow '<hive>FUNCTIONS'
| AnyShow '<hive>FUNCTIONS' DoubleQuotedValue
| AnyShow OptionalAggregateOrAnalytic '<impala>FUNCTIONS' OptionalInDatabase
| AnyShow OptionalAggregateOrAnalytic '<impala>FUNCTIONS' OptionalInDatabase 'LIKE' QuotedValue
;
ShowFunctionsStatement_EDIT
: AnyShow AggregateOrAnalytic 'CURSOR'
{
parser.suggestKeywords(['FUNCTIONS']);
}
| AnyShow 'CURSOR' '<impala>FUNCTIONS' OptionalInDatabase
{
parser.suggestKeywords(['AGGREGATE', 'ANALYTICAL']);
}
| AnyShow OptionalAggregateOrAnalytic '<impala>FUNCTIONS' OptionalInDatabase 'CURSOR'
{
if (!$4) {
parser.suggestKeywords(['IN', 'LIKE']);
} else {
parser.suggestKeywords(['LIKE']);
}
}
| AnyShow AggregateOrAnalytic 'CURSOR' OptionalInDatabase 'LIKE' QuotedValue
{
parser.suggestKeywords(['FUNCTIONS']);
}
| AnyShow 'CURSOR' '<impala>FUNCTIONS' OptionalInDatabase 'LIKE' QuotedValue
{
parser.suggestKeywords(['AGGREGATE', 'ANALYTICAL']);
}
| AnyShow OptionalAggregateOrAnalytic '<impala>FUNCTIONS' OptionalInDatabase 'CURSOR' QuotedValue
{
if (!$4) {
parser.suggestKeywords([{ value: 'IN', weight: 2 }, { value: 'LIKE', weight: 1 }]);
} else {
parser.suggestKeywords(['LIKE']);
}
}
;
ShowGrantStatement
: AnyShow '<hive>GRANT' OptionalPrincipalName
| AnyShow '<hive>GRANT' OptionalPrincipalName 'ON' '<hive>ALL'
| AnyShow '<hive>GRANT' OptionalPrincipalName 'ON' RegularOrBacktickedIdentifier
| AnyShow '<hive>GRANT' OptionalPrincipalName 'ON' AnyTable RegularOrBacktickedIdentifier
| AnyShow '<impala>GRANT' '<impala>ROLE' RegularOrBacktickedIdentifier
;
ShowGrantStatement_EDIT
: AnyShow '<hive>GRANT' OptionalPrincipalName_EDIT
{
parser.suggestKeywords(['ON']);
}
| AnyShow '<hive>GRANT' OptionalPrincipalName_EDIT 'ON' '<hive>ALL'
| AnyShow '<hive>GRANT' OptionalPrincipalName 'ON' 'CURSOR'
{
parser.suggestKeywords(['ALL', 'TABLE']);
parser.suggestTables();
}
| AnyShow '<hive>GRANT' OptionalPrincipalName 'ON' AnyTable 'CURSOR'
{
parser.suggestTables();
}
| AnyShow '<hive>GRANT' OptionalPrincipalName 'ON' 'CURSOR' RegularOrBacktickedIdentifier
{
parser.suggestKeywords(['TABLE']);
}
| AnyShow '<impala>GRANT' 'CURSOR'
{
parser.suggestKeywords(['ROLE']);
}
;
OptionalPrincipalName
:
| RegularIdentifier
;
OptionalPrincipalName_EDIT
: 'CURSOR'
| RegularIdentifier 'CURSOR'
;
ShowIndexStatement
: AnyShow OptionallyFormattedIndex 'ON' RegularOrBacktickedIdentifier
| AnyShow OptionallyFormattedIndex 'ON' RegularOrBacktickedIdentifier AnyFromOrIn RegularOrBacktickedIdentifier
;
ShowIndexStatement_EDIT
: AnyShow OptionallyFormattedIndex
| AnyShow OptionallyFormattedIndex_EDIT
| AnyShow OptionallyFormattedIndex_EDIT 'ON' RegularOrBacktickedIdentifier
| AnyShow OptionallyFormattedIndex_EDIT 'ON' RegularOrBacktickedIdentifier AnyFromOrIn RegularOrBacktickedIdentifier
| AnyShow OptionallyFormattedIndex 'CURSOR'
{
parser.suggestKeywords(['ON']);
}
| AnyShow OptionallyFormattedIndex 'ON' 'CURSOR'
{
parser.suggestTables();
}
| AnyShow OptionallyFormattedIndex 'CURSOR' RegularOrBacktickedIdentifier
{
parser.suggestKeywords(['ON']);
}
| AnyShow OptionallyFormattedIndex 'ON' RegularOrBacktickedIdentifier 'CURSOR'
{
parser.suggestKeywords(['FROM', 'IN']);
}
| AnyShow OptionallyFormattedIndex 'ON' RegularOrBacktickedIdentifier 'CURSOR' RegularOrBacktickedIdentifier
{
parser.suggestKeywords(['FROM', 'IN']);
}
| AnyShow OptionallyFormattedIndex 'ON' RegularOrBacktickedIdentifier AnyFromOrIn 'CURSOR'
{
parser.suggestDatabases();
}
| AnyShow OptionallyFormattedIndex 'ON' 'CURSOR' AnyFromOrIn RegularOrBacktickedIdentifier
{
parser.suggestTables({identifierChain: [{name: $6}]});
}
;
ShowLocksStatement
: AnyShow '<hive>LOCKS' RegularOrBackTickedSchemaQualifiedName
{
parser.addTablePrimary($3);
}
| AnyShow '<hive>LOCKS' RegularOrBackTickedSchemaQualifiedName '<hive>EXTENDED'
{
parser.addTablePrimary($3);
}
| AnyShow '<hive>LOCKS' RegularOrBackTickedSchemaQualifiedName PartitionSpec
{
parser.addTablePrimary($3);
}
| AnyShow '<hive>LOCKS' RegularOrBackTickedSchemaQualifiedName PartitionSpec '<hive>EXTENDED'
{
parser.addTablePrimary($3);
}
| AnyShow '<hive>LOCKS' DatabaseOrSchema RegularOrBacktickedIdentifier
;
ShowLocksStatement_EDIT
: AnyShow '<hive>LOCKS' 'CURSOR'
{
parser.suggestTables();
parser.suggestDatabases({
appendDot: true
});
parser.suggestKeywords(['DATABASE', 'SCHEMA']);
}
| AnyShow '<hive>LOCKS' RegularOrBackTickedSchemaQualifiedName_EDIT
| AnyShow '<hive>LOCKS' RegularOrBackTickedSchemaQualifiedName 'CURSOR'
{
parser.addTablePrimary($3);
parser.suggestKeywords(['EXTENDED', 'PARTITION']);
}
| AnyShow '<hive>LOCKS' RegularOrBackTickedSchemaQualifiedName_EDIT '<hive>EXTENDED'
| AnyShow '<hive>LOCKS' RegularOrBackTickedSchemaQualifiedName_EDIT PartitionSpec
| AnyShow '<hive>LOCKS' RegularOrBackTickedSchemaQualifiedName PartitionSpec 'CURSOR'
{
parser.addTablePrimary($3);
parser.suggestKeywords(['EXTENDED']);
}
| AnyShow '<hive>LOCKS' RegularOrBackTickedSchemaQualifiedName_EDIT PartitionSpec '<hive>EXTENDED'
| AnyShow '<hive>LOCKS' DatabaseOrSchema 'CURSOR'
{
parser.suggestDatabases();
}
;
ShowPartitionsStatement
: AnyShow '<hive>PARTITIONS' RegularOrBackTickedSchemaQualifiedName
{
parser.addTablePrimary($3);
}
| AnyShow '<hive>PARTITIONS' RegularOrBackTickedSchemaQualifiedName PartitionSpec
{
parser.addTablePrimary($3);
}
| AnyShow '<impala>PARTITIONS' RegularOrBackTickedSchemaQualifiedName
{
parser.addTablePrimary($3);
}
| AnyShow '<impala>RANGE' '<impala>PARTITIONS' RegularOrBackTickedSchemaQualifiedName
{
parser.addTablePrimary($3);
}
;
ShowPartitionsStatement_EDIT
: AnyShow '<hive>PARTITIONS' 'CURSOR'
{
parser.suggestTables();
parser.suggestDatabases({
appendDot: true
});
}
| AnyShow '<hive>PARTITIONS' RegularOrBackTickedSchemaQualifiedName_EDIT
| AnyShow '<hive>PARTITIONS' RegularOrBackTickedSchemaQualifiedName 'CURSOR'
{
parser.addTablePrimary($3);
parser.suggestKeywords(['PARTITION']);
}
| AnyShow '<hive>PARTITIONS' RegularOrBackTickedSchemaQualifiedName_EDIT PartitionSpec
| AnyShow '<impala>PARTITIONS' 'CURSOR'
{
parser.suggestTables();
parser.suggestDatabases({
appendDot: true
});
}
| AnyShow '<impala>PARTITIONS' RegularOrBackTickedSchemaQualifiedName_EDIT
| AnyShow '<impala>RANGE' '<impala>PARTITIONS' 'CURSOR'
{
parser.suggestTables();
parser.suggestDatabases({
appendDot: true
});
}
| AnyShow '<impala>RANGE' '<impala>PARTITIONS' RegularOrBackTickedSchemaQualifiedName_EDIT
;
ShowRoleStatement
: AnyShow '<hive>ROLE' '<hive>GRANT' HiveRoleOrUser RegularIdentifier
| AnyShow '<impala>ROLE' '<impala>GRANT' '<impala>GROUP' RegularIdentifier
;
ShowRoleStatement_EDIT
: AnyShow '<hive>ROLE' 'CURSOR'
{
parser.suggestKeywords(['GRANT']);
}
| AnyShow '<impala>ROLE' 'CURSOR'
{
parser.suggestKeywords(['GRANT']);
}
| AnyShow '<hive>ROLE' 'CURSOR' HiveRoleOrUser RegularIdentifier
{
parser.suggestKeywords(['GRANT']);
}
| AnyShow '<hive>ROLE' '<hive>GRANT' 'CURSOR'
{
parser.suggestKeywords(['ROLE', 'USER']);
}
| AnyShow '<hive>ROLE' '<hive>GRANT' 'CURSOR' RegularIdentifier
{
parser.suggestKeywords(['ROLE', 'USER']);
}
| AnyShow '<impala>ROLE' '<impala>GRANT' 'CURSOR'
{
parser.suggestKeywords(['GROUP']);
}
| AnyShow '<impala>ROLE' '<impala>GRANT' 'CURSOR' RegularIdentifier
{
parser.suggestKeywords(['GROUP']);
}
;
ShowRolesStatement
: AnyShow '<impala>ROLES'
| AnyShow '<hive>ROLES'
;
ShowTableStatement
: AnyShow '<hive>TABLE' '<hive>EXTENDED' OptionalFromDatabase 'LIKE' SingleQuotedValue
| AnyShow '<hive>TABLE' '<hive>EXTENDED' OptionalFromDatabase 'LIKE' SingleQuotedValue PartitionSpec
;
ShowTableStatement_EDIT
: AnyShow '<hive>TABLE' 'CURSOR'
{
parser.suggestKeywords(['EXTENDED']);
}
| AnyShow '<hive>TABLE' '<hive>EXTENDED' OptionalFromDatabase
| AnyShow '<hive>TABLE' '<hive>EXTENDED' OptionalFromDatabase_EDIT
| AnyShow '<hive>TABLE' '<hive>EXTENDED' OptionalFromDatabase 'CURSOR'
{
if ($4) {
parser.suggestKeywords(['LIKE']);
} else {
parser.suggestKeywords(['FROM', 'IN', 'LIKE']);
}
}
| AnyShow '<hive>TABLE' '<hive>EXTENDED' OptionalFromDatabase_EDIT 'LIKE' SingleQuotedValue
| AnyShow '<hive>TABLE' 'CURSOR' OptionalFromDatabase 'LIKE' SingleQuotedValue
{
if (parser.isHive()) {
parser.suggestKeywords(['EXTENDED']);
}
}
| AnyShow '<hive>TABLE' '<hive>EXTENDED' OptionalFromDatabase 'CURSOR' SingleQuotedValue
{
parser.suggestKeywords(['LIKE']);
}
| AnyShow '<hive>TABLE' '<hive>EXTENDED' OptionalFromDatabase 'LIKE' SingleQuotedValue 'CURSOR'
{
parser.suggestKeywords(['PARTITION']);
}
| AnyShow '<hive>TABLE' '<hive>EXTENDED' OptionalFromDatabase_EDIT 'LIKE' SingleQuotedValue PartitionSpec
| AnyShow '<hive>TABLE' 'CURSOR' OptionalFromDatabase 'LIKE' SingleQuotedValue PartitionSpec
{
parser.suggestKeywords(['EXTENDED']);
}
| AnyShow '<hive>TABLE' '<hive>EXTENDED' OptionalFromDatabase 'CURSOR' SingleQuotedValue PartitionSpec
{
parser.suggestKeywords(['LIKE']);
}
| AnyShow '<hive>TABLE' '<hive>EXTENDED' OptionalFromDatabase 'LIKE' SingleQuotedValue 'CURSOR' PartitionSpecList
{
parser.suggestKeywords(['PARTITION']);
}
| AnyShow '<impala>TABLE' 'CURSOR'
{
parser.suggestKeywords(['STATS']);
}
| AnyShow '<impala>TABLE' '<impala>STATS' 'CURSOR'
{
parser.suggestTables();
parser.suggestDatabases({
appendDot: true
});
}
| AnyShow '<impala>TABLE' '<impala>STATS' RegularOrBackTickedSchemaQualifiedName
{
parser.addTablePrimary($4);
}
| AnyShow '<impala>TABLE' '<impala>STATS' RegularOrBackTickedSchemaQualifiedName_EDIT
;
ShowTablesStatement
: AnyShow HiveOrImpalaTables OptionalInDatabase
| AnyShow HiveOrImpalaTables OptionalInDatabase SingleQuotedValue
| AnyShow HiveOrImpalaTables OptionalInDatabase 'LIKE' SingleQuotedValue
;
ShowTablesStatement_EDIT
: AnyShow HiveOrImpalaTables OptionalInDatabase 'CURSOR'
{
if (!$3) {
parser.suggestKeywords(['IN', 'LIKE']);
} else {
parser.suggestKeywords(['LIKE']);
}
}
;
ShowTblPropertiesStatement
: AnyShow '<hive>TBLPROPERTIES' RegularOrBackTickedSchemaQualifiedName
{
parser.addTablePrimary($3);
}
| AnyShow '<hive>TBLPROPERTIES' RegularOrBackTickedSchemaQualifiedName '(' QuotedValue ')'
{
parser.addTablePrimary($3);
}
;
ShowTblPropertiesStatement_EDIT
: AnyShow '<hive>TBLPROPERTIES' RegularOrBackTickedSchemaQualifiedName_EDIT
| AnyShow '<hive>TBLPROPERTIES' 'CURSOR'
{
parser.suggestTables();
parser.suggestDatabases({ prependDot: true });
}
;
ShowTransactionsStatement
: AnyShow '<hive>TRANSACTIONS'
;
ShowViewsStatement
: AnyShow '<hive>VIEWS' OptionalInOrFromDatabase OptionalLike
;
ShowViewsStatement_EDIT
: AnyShow '<hive>VIEWS' OptionalInOrFromDatabase OptionalLike 'CURSOR'
{
if (!$4 && !$3) {
parser.suggestKeywords([{ value: 'IN', weight: 2 }, { value: 'FROM', weight: 2 }, { value: 'LIKE', weight: 1 }]);
} else if (!$4) {
parser.suggestKeywords(['LIKE']);
}
}
| AnyShow '<hive>VIEWS' InOrFromDatabase_EDIT OptionalLike
| AnyShow '<hive>VIEWS' OptionalInOrFromDatabase Like_EDIT
;
OptionalInOrFromDatabase
:
| 'IN' RegularOrBacktickedIdentifier
{
parser.addDatabaseLocation(@2, [ { name: $2 } ]);
}
| 'FROM' RegularOrBacktickedIdentifier
{
parser.addDatabaseLocation(@2, [ { name: $2 } ]);
}
;
InOrFromDatabase_EDIT
: 'IN' 'CURSOR'
{
parser.suggestDatabases();
}
| 'FROM' 'CURSOR'
{
parser.suggestDatabases();
}
;
OptionalLike
:
| 'LIKE' SingleQuotedValue
;
Like_EDIT
: 'LIKE' 'CURSOR'
;

138
jison/sql_update.jison Executable file
View File

@ -0,0 +1,138 @@
// 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'
{
if (parser.isImpala() && !$6 && !$5) {
parser.suggestKeywords([{ value: 'FROM', weight: 2 }, { value: 'WHERE', weight: 1 }]);
} else if (parser.isImpala() && !$6 && $5) {
var keywords = [{ value: 'FULL JOIN', weight: 2 }, { value: 'FULL OUTER JOIN', weight: 2 }, { value: 'JOIN', weight: 2 }, { value: 'LEFT JOIN', weight: 2 }, { value: 'LEFT OUTER JOIN', weight: 2 }, { value: 'RIGHT JOIN', weight: 2 }, { value: 'RIGHT OUTER JOIN', weight: 2 }, { value: 'INNER JOIN', weight: 2 }, { value: 'LEFT ANTI JOIN', weight: 2 }, { value: 'LEFT SEMI JOIN', weight: 2 }, { value: 'RIGHT ANTI JOIN', weight: 2 }, { value: 'RIGHT SEMI JOIN', weight: 2 }, { value: 'WHERE', weight: 1 }];
if ($5.suggestJoinConditions) {
parser.suggestJoinConditions($5.suggestJoinConditions);
}
if ($5.suggestJoins) {
parser.suggestJoins($5.suggestJoins);
}
if ($5.suggestKeywords) {
keywords = keywords.concat(parser.createWeightedKeywords($5.suggestKeywords, 3));
}
parser.suggestKeywords(keywords);
} else if (!$6) {
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
;

47
jison/sql_use.jison Executable file
View File

@ -0,0 +1,47 @@
// 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
;
AnyUse
: 'USE'
| '<hive>USE'
;
UseStatement
: AnyUse RegularIdentifier
{
if (! parser.yy.cursorFound) {
parser.yy.result.useDatabase = $2;
}
}
;
UseStatement_EDIT
: AnyUse 'CURSOR'
{
parser.suggestDatabases();
}
;
// ===================================== Fin =====================================

867
jison/sql_valueExpression.jison Executable file
View File

@ -0,0 +1,867 @@
// 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 '<impala>UNKNOWN' -> { 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'
{
var keywords = ['FALSE', 'NOT NULL', 'NOT TRUE', 'NOT FALSE', 'NULL', 'TRUE'];
if (parser.isImpala()) {
keywords = keywords.concat(['DISTINCT FROM', 'NOT DISTINCT FROM', 'NOT UNKNOWN', 'UNKNOWN']);
}
parser.suggestKeywords(keywords);
$$ = { types: [ 'BOOLEAN' ] };
}
| ValueExpression 'IS' 'NOT' 'CURSOR'
{
var keywords = ['FALSE', 'NULL', 'TRUE'];
if (parser.isImpala()) {
keywords = keywords.concat(['DISTINCT FROM', 'UNKNOWN']);
}
parser.suggestKeywords(keywords);
$$ = { types: [ 'BOOLEAN' ] };
}
| ValueExpression 'IS' OptionalNot 'DISTINCT' 'CURSOR'
{
if (parser.isImpala()) {
parser.suggestKeywords(['FROM']);
}
$$ = { 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'] }
| '<impala>ILIKE' ValueExpression -> { suggestKeywords: ['NOT'] }
| '<impala>IREGEXP' ValueExpression -> { suggestKeywords: ['NOT'] }
| 'RLIKE' ValueExpression -> { suggestKeywords: ['NOT'] }
| 'REGEXP' ValueExpression -> { suggestKeywords: ['NOT'] }
;
LikeRightPart_EDIT
: 'LIKE' ValueExpression_EDIT
| '<impala>ILIKE' ValueExpression_EDIT
| '<impala>IREGEXP' ValueExpression_EDIT
| 'RLIKE' ValueExpression_EDIT
| 'REGEXP' ValueExpression_EDIT
| 'LIKE' PartialBacktickedOrCursor
{
parser.suggestFunctions({ types: [ 'STRING' ] });
parser.suggestColumns({ types: [ 'STRING' ] });
$$ = { types: ['BOOLEAN'] }
}
| '<impala>ILIKE' PartialBacktickedOrCursor
{
parser.suggestFunctions({ types: [ 'STRING' ] });
parser.suggestColumns({ types: [ 'STRING' ] });
$$ = { types: ['BOOLEAN'] }
}
| '<impala>IREGEXP' 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'] }] };
}
;

18
jison/syntax_footer.jison Executable file
View File

@ -0,0 +1,18 @@
// 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
jison/syntax_header.jison Executable file
View 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' '<impala>ILIKE' '<impala>IREGEXP' 'LIKE' 'RLIKE' 'REGEXP' 'EXISTS' NEGATION
%start SqlSyntax
%%

BIN
lib/.DS_Store vendored Normal file

Binary file not shown.