Skip to content

Commit

Permalink
[editor] Add SparkSQL autocomplete for DROP, INSERT, LOAD, MSCK and T…
Browse files Browse the repository at this point in the history
…RUNCATE statements
  • Loading branch information
JohanAhlen committed Nov 4, 2022
1 parent f44ad92 commit 11fc7d8
Show file tree
Hide file tree
Showing 30 changed files with 4,035 additions and 1,283 deletions.
Expand Up @@ -80,5 +80,32 @@
"onlyViews": true
}
}
},
{
"namePrefix": "should suggest views",
"beforeCursor": "DROP VIEW IF EXISTS foo.",
"afterCursor": "",
"expectedResult": {
"lowerCase": false,
"suggestTables": {
"identifierChain": [
{
"name": "foo"
}
],
"onlyViews": true
}
}
},
{
"namePrefix": "should suggest keywords",
"beforeCursor": "DROP VIEW ",
"afterCursor": " foo.bar",
"expectedResult": {
"lowerCase": false,
"suggestKeywords": [
"IF EXISTS"
]
}
}
]
Expand Up @@ -3,11 +3,11 @@
"namePrefix": "should suggest keywords",
"beforeCursor": "SELECT * FROM database_two.testTable ORDER BY foo LIMIT 10 ",
"afterCursor": "",
"containsKeywords": [
"UNION"
],
"expectedResult": {
"lowerCase": false,
"suggestKeywords": [
"UNION"
]
"lowerCase": false
}
},
{
Expand Down
Expand Up @@ -32,6 +32,13 @@ PropertyAssignmentList

PropertyAssignment
: QuotedValue '=' UnsignedValueSpecification
| QuotedValue '=' RegularIdentifier
| QuotedValue RegularIdentifier
| QuotedValue QuotedValue
| RegularIdentifier '=' UnsignedValueSpecification
| RegularIdentifier UnsignedValueSpecification
| RegularIdentifier '=' RegularIdentifier
| RegularIdentifier RegularIdentifier
;

ParenthesizedPropertyList
Expand Down
@@ -0,0 +1,22 @@
// 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_EDIT
: 'DROP' 'CURSOR'
{
parser.suggestKeywords(['DATABASE', 'FUNCTION', 'SCHEMA', 'TABLE', 'TEMPORARY FUNCTION', 'VIEW']);
}
;
@@ -0,0 +1,13 @@
[
{
"namePrefix": "should suggest keywords",
"beforeCursor": "",
"afterCursor": "",
"containsKeywords": [
"DROP"
],
"expectedResult": {
"lowerCase": false
}
}
]
@@ -0,0 +1,49 @@
// 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
: DropFunctionStatement
;

DataDefinition_EDIT
: DropFunctionStatement_EDIT
;

DropFunctionStatement
: 'DROP' OptionalTemporary 'FUNCTION' OptionalIfExists SchemaQualifiedIdentifier
;

DropFunctionStatement_EDIT
: 'DROP' 'TEMPORARY' 'CURSOR'
{
parser.suggestKeywords(['FUNCTION']);
}
| 'DROP' OptionalTemporary 'FUNCTION' OptionalIfExists 'CURSOR'
{
if (!$4) {
parser.suggestKeywords(['IF EXISTS']);
}
}
| 'DROP' OptionalTemporary 'FUNCTION' OptionalIfExists 'CURSOR' SchemaQualifiedIdentifier
{
if (!$4) {
parser.suggestKeywords(['IF EXISTS']);
}
}
| 'DROP' OptionalTemporary 'FUNCTION' OptionalIfExists_EDIT
| 'DROP' OptionalTemporary 'FUNCTION' OptionalIfExists_EDIT SchemaQualifiedIdentifier
| 'DROP' OptionalTemporary 'FUNCTION' OptionalIfExists SchemaQualifiedIdentifier_EDIT
;
@@ -0,0 +1,59 @@
[
{
"namePrefix": "should handle",
"beforeCursor": "DROP TEMPORARY FUNCTION IF EXISTS baa;",
"afterCursor": "",
"containsKeywords": [
"SELECT"
],
"noErrors": true,
"expectedResult": {
"lowerCase": false
}
},
{
"namePrefix": "should suggest keywords",
"beforeCursor": "DROP ",
"afterCursor": "",
"containsKeywords": [
"FUNCTION",
"TEMPORARY FUNCTION"
],
"expectedResult": {
"lowerCase": false
}
},
{
"namePrefix": "should suggest keywords",
"beforeCursor": "DROP TEMPORARY ",
"afterCursor": "",
"containsKeywords": [
"FUNCTION"
],
"expectedResult": {
"lowerCase": false
}
},
{
"namePrefix": "should suggest keywords",
"beforeCursor": "DROP FUNCTION ",
"afterCursor": "",
"expectedResult": {
"lowerCase": false,
"suggestKeywords": [
"IF EXISTS"
]
}
},
{
"namePrefix": "should suggest keywords",
"beforeCursor": "DROP FUNCTION IF ",
"afterCursor": "",
"expectedResult": {
"lowerCase": false,
"suggestKeywords": [
"EXISTS"
]
}
}
]
@@ -0,0 +1,57 @@
// 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
: DropTableStatement
;

DataDefinition_EDIT
: DropTableStatement_EDIT
;

DropTableStatement
: 'DROP' 'TABLE' OptionalIfExists SchemaQualifiedTableIdentifier
{
parser.addTablePrimary($4);
}
;

DropTableStatement_EDIT
: 'DROP' 'TABLE' OptionalIfExists_EDIT
| 'DROP' 'TABLE' OptionalIfExists 'CURSOR'
{
if (!$3) {
parser.suggestKeywords(['IF EXISTS']);
}
parser.suggestTables({ onlyTables: true });
parser.suggestDatabases({
appendDot: true
});
}
| 'DROP' 'TABLE' OptionalIfExists SchemaQualifiedTableIdentifier_EDIT
{
if (parser.yy.result.suggestTables) {
parser.yy.result.suggestTables.onlyTables = true;
}
}
| 'DROP' 'TABLE' OptionalIfExists 'CURSOR' SchemaQualifiedTableIdentifier
{
if (!$3) {
parser.suggestKeywords(['IF EXISTS']);
}
}
| 'DROP' 'TABLE' OptionalIfExists_EDIT SchemaQualifiedTableIdentifier
;
@@ -0,0 +1,94 @@
[
{
"namePrefix": "should handle",
"beforeCursor": "DROP TABLE IF EXISTS db.tbl;",
"afterCursor": "",
"containsKeywords": [
"SELECT"
],
"noErrors": true,
"expectedResult": {
"lowerCase": false
}
},
{
"namePrefix": "should suggest keywords",
"beforeCursor": "DROP ",
"afterCursor": "",
"containsKeywords": [
"TABLE"
],
"expectedResult": {
"lowerCase": false
}
},
{
"namePrefix": "should suggest tables",
"beforeCursor": "DROP TABLE ",
"afterCursor": "",
"expectedResult": {
"lowerCase": false,
"suggestTables": {
"onlyTables": true
},
"suggestDatabases": {
"appendDot": true
},
"suggestKeywords": [
"IF EXISTS"
]
}
},
{
"namePrefix": "should suggest keywords",
"beforeCursor": "DROP TABLE IF ",
"afterCursor": "",
"expectedResult": {
"lowerCase": false,
"suggestKeywords": [
"EXISTS"
]
}
},
{
"namePrefix": "should suggest tables",
"beforeCursor": "DROP TABLE IF EXISTS ",
"afterCursor": "",
"expectedResult": {
"lowerCase": false,
"suggestTables": {
"onlyTables": true
},
"suggestDatabases": {
"appendDot": true
}
}
},
{
"namePrefix": "should suggest tables",
"beforeCursor": "DROP TABLE IF EXISTS foo.",
"afterCursor": "",
"expectedResult": {
"lowerCase": false,
"suggestTables": {
"identifierChain": [
{
"name": "foo"
}
],
"onlyTables": true
}
}
},
{
"namePrefix": "should suggest keywords",
"beforeCursor": "DROP TABLE ",
"afterCursor": " foo.bar",
"expectedResult": {
"lowerCase": false,
"suggestKeywords": [
"IF EXISTS"
]
}
}
]

0 comments on commit 11fc7d8

Please sign in to comment.