Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DRILL-6964: Implement CREATE / DROP SCHEMA commands
Note: this PR only adds support for CREATE / DROP SCHEMA commands which allow to store and delete schema. Schema usage during querying the data will be covered in other PRs. 1. Added parser methods / handles to parse CREATE / DROP schema commands. 2. Added SchemaProviders classes to separate ways of schema provision (file, table function). 3. Added schema parsing using ANTLR4 (lexer, parser, visitors). 4. Added appropriate unit tests. close #1615
- Loading branch information
1 parent
b1594cb
commit 0a61b8f
Showing
36 changed files
with
3,207 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
...a-exec/src/main/antlr4/org/apache/drill/exec/record/metadata/schema/parser/SchemaLexer.g4
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
lexer grammar SchemaLexer; | ||
|
||
@header { | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF 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. | ||
*/ | ||
} | ||
|
||
// data types | ||
// https://drill.apache.org/docs/supported-data-types/ | ||
INT: 'INT'; | ||
INTEGER: 'INTEGER'; | ||
BIGINT: 'BIGINT'; | ||
|
||
FLOAT: 'FLOAT'; | ||
DOUBLE: 'DOUBLE'; | ||
|
||
DEC: 'DEC'; | ||
DECIMAL: 'DECIMAL'; | ||
NUMERIC: 'NUMERIC'; | ||
|
||
BOOLEAN: 'BOOLEAN'; | ||
|
||
CHAR: 'CHAR'; | ||
CHARACTER: 'CHARACTER'; | ||
VARYING: 'VARYING'; | ||
VARCHAR: 'VARCHAR'; | ||
BINARY: 'BINARY'; | ||
VARBINARY: 'VARBINARY'; | ||
|
||
TIME: 'TIME'; | ||
DATE: 'DATE'; | ||
TIMESTAMP: 'TIMESTAMP'; | ||
INTERVAL: 'INTERVAL'; | ||
|
||
YEAR: 'YEAR'; | ||
MONTH: 'MONTH'; | ||
DAY: 'DAY'; | ||
HOUR: 'HOUR'; | ||
MINUTE: 'MINUTE'; | ||
SECOND: 'SECOND'; | ||
|
||
MAP: 'MAP'; | ||
ARRAY: 'ARRAY'; | ||
|
||
// symbols | ||
COMMA: ','; | ||
REVERSE_QUOTE: '`'; | ||
LEFT_PAREN: '('; | ||
RIGHT_PAREN: ')'; | ||
LEFT_ANGLE_BRACKET: '<'; | ||
RIGHT_ANGLE_BRACKET: '>'; | ||
|
||
NOT: 'NOT'; | ||
NULL: 'NULL'; | ||
AS: 'AS'; | ||
|
||
NUMBER: [1-9] DIGIT* | '0'; | ||
fragment DIGIT: [0-9]; | ||
|
||
// identifiers | ||
|
||
// column name can start with any letter, dollar sign ($) or underscore (_), | ||
// consequently can contain any letter, dollar sign ($), underscore (_) or digit | ||
// if any other symbols are present, use QUOTED_ID | ||
ID: ([A-Z$_]) ([A-Z$_] | DIGIT)*; | ||
|
||
// column name should be enclosed into backticks, can contain any symbols including space | ||
// if contains backtick, it should be escaped with backslash (`a\\`b` -> a`b) | ||
// if contains backslash, it should be escaped as well (`a\\\\b` -> a\b) | ||
QUOTED_ID: REVERSE_QUOTE (~[`\\] | '\\' [`\\])* REVERSE_QUOTE; | ||
|
||
// skip | ||
LINE_COMMENT: '//' ~[\r\n]* -> skip; | ||
BLOCK_COMMENT: '/*' .*? '*/' -> skip; | ||
SPACE: [ \n\t\r\u000C]+ -> skip; |
72 changes: 72 additions & 0 deletions
72
...-exec/src/main/antlr4/org/apache/drill/exec/record/metadata/schema/parser/SchemaParser.g4
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
parser grammar SchemaParser; | ||
|
||
options { | ||
language=Java; | ||
tokenVocab=SchemaLexer; | ||
} | ||
|
||
@header { | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF 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. | ||
*/ | ||
} | ||
|
||
schema: (columns | LEFT_PAREN columns RIGHT_PAREN) EOF; | ||
|
||
columns: column (COMMA column)*; | ||
|
||
column: (primitive_column | map_column | simple_array_column | complex_array_column); | ||
|
||
primitive_column: column_id simple_type nullability?; | ||
|
||
simple_array_column: column_id simple_array_type nullability?; | ||
|
||
map_column: column_id map_type nullability?; | ||
|
||
complex_array_column: column_id complex_array_type nullability?; | ||
|
||
column_id | ||
: ID # id | ||
| QUOTED_ID # quoted_id | ||
; | ||
|
||
simple_type | ||
: (INT | INTEGER) # int | ||
| BIGINT # bigint | ||
| FLOAT # float | ||
| DOUBLE # double | ||
| (DEC | DECIMAL | NUMERIC) (LEFT_PAREN NUMBER (COMMA NUMBER)? RIGHT_PAREN)? # decimal | ||
| BOOLEAN # boolean | ||
| (CHAR | VARCHAR | CHARACTER VARYING?) (LEFT_PAREN NUMBER RIGHT_PAREN)? # varchar | ||
| (BINARY | VARBINARY) (LEFT_PAREN NUMBER RIGHT_PAREN)? # binary | ||
| TIME (LEFT_PAREN NUMBER RIGHT_PAREN)? # time | ||
| DATE # date | ||
| TIMESTAMP (LEFT_PAREN NUMBER RIGHT_PAREN)? # timestamp | ||
| INTERVAL (YEAR | MONTH) # interval_year | ||
| INTERVAL (DAY | HOUR | MINUTE | SECOND) # interval_day | ||
| INTERVAL # interval | ||
; | ||
|
||
complex_type: (simple_array_type | complex_array_type); | ||
|
||
simple_array_type: ARRAY LEFT_ANGLE_BRACKET (simple_type | map_type) RIGHT_ANGLE_BRACKET; | ||
|
||
complex_array_type: ARRAY LEFT_ANGLE_BRACKET complex_type RIGHT_ANGLE_BRACKET; | ||
|
||
map_type: MAP LEFT_ANGLE_BRACKET columns RIGHT_ANGLE_BRACKET; | ||
|
||
nullability: NOT NULL; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.