-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support inserting into table having CHECK constraint in Delta Lake
Extract relevant tests from TestDeltaLakeCheckConstraintsCompatibility.
- Loading branch information
Showing
19 changed files
with
1,427 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
118 changes: 118 additions & 0 deletions
118
.../trino-delta-lake/src/main/antlr4/io/trino/plugin/deltalake/expression/SparkExpression.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,118 @@ | ||
/* | ||
* Licensed 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. | ||
*/ | ||
|
||
grammar SparkExpression; | ||
|
||
tokens { | ||
DELIMITER | ||
} | ||
|
||
standaloneExpression | ||
: expression EOF | ||
; | ||
|
||
expression | ||
: booleanExpression | ||
; | ||
|
||
booleanExpression | ||
: valueExpression predicate[$valueExpression.ctx]? #predicated | ||
| booleanExpression AND booleanExpression #and | ||
; | ||
|
||
// workaround for https://github.com/antlr/antlr4/issues/780 | ||
predicate[ParserRuleContext value] | ||
: comparisonOperator right=valueExpression #comparison | ||
; | ||
|
||
valueExpression | ||
: primaryExpression #valueExpressionDefault | ||
; | ||
|
||
primaryExpression | ||
: number #numericLiteral | ||
| booleanValue #booleanLiteral | ||
| string #stringLiteral | ||
| identifier #columnReference | ||
; | ||
|
||
string | ||
: STRING #basicStringLiteral | ||
; | ||
|
||
comparisonOperator | ||
: EQ | NEQ | LT | LTE | GT | GTE | ||
; | ||
|
||
booleanValue | ||
: TRUE | FALSE | ||
; | ||
|
||
identifier | ||
: IDENTIFIER #unquotedIdentifier | ||
| BACKQUOTED_IDENTIFIER #backQuotedIdentifier | ||
; | ||
|
||
number | ||
: MINUS? INTEGER_VALUE #integerLiteral | ||
; | ||
|
||
AND: 'AND'; | ||
FALSE: 'FALSE'; | ||
TRUE: 'TRUE'; | ||
|
||
EQ: '='; | ||
NEQ: '<>' | '!='; | ||
LT: '<'; | ||
LTE: '<='; | ||
GT: '>'; | ||
GTE: '>='; | ||
|
||
MINUS: '-'; | ||
|
||
STRING | ||
: '\'' ( ~'\'' | '\'\'' )* '\'' | ||
| '"' ( ~'"' | '""' )* '"' | ||
; | ||
|
||
INTEGER_VALUE | ||
: DIGIT+ | ||
; | ||
|
||
IDENTIFIER | ||
: (LETTER | '_') (LETTER | DIGIT | '_')* | ||
; | ||
|
||
BACKQUOTED_IDENTIFIER | ||
: '`' ( ~'`' | '``' )* '`' | ||
; | ||
|
||
fragment DIGIT | ||
: [0-9] | ||
; | ||
|
||
fragment LETTER | ||
: [A-Z] | ||
; | ||
|
||
WS | ||
: [ \r\n\t]+ -> channel(HIDDEN) | ||
; | ||
|
||
// Catch-all for anything we can't recognize. | ||
// We use this to be able to ignore and recover all the text | ||
// when splitting statements with DelimiterLexer | ||
UNRECOGNIZED | ||
: . | ||
; |
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
59 changes: 59 additions & 0 deletions
59
plugin/trino-delta-lake/src/main/java/io/trino/plugin/deltalake/expression/AstVisitor.java
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,59 @@ | ||
/* | ||
* Licensed 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. | ||
*/ | ||
package io.trino.plugin.deltalake.expression; | ||
|
||
import javax.annotation.Nullable; | ||
|
||
public abstract class AstVisitor<R, C> | ||
{ | ||
public R process(Node node, @Nullable C context) | ||
{ | ||
return node.accept(this, context); | ||
} | ||
|
||
protected R visitNode(Node node, C context) | ||
{ | ||
return null; | ||
} | ||
|
||
protected R visitExpression(Expression node, C context) | ||
{ | ||
return visitNode(node, context); | ||
} | ||
|
||
protected R visitComparisonExpression(ComparisonExpression node, C context) | ||
{ | ||
return visitExpression(node, context); | ||
} | ||
|
||
protected R visitLogicalExpression(LogicalExpression node, C context) | ||
{ | ||
return visitExpression(node, context); | ||
} | ||
|
||
protected R visitIdentifier(Identifier node, C context) | ||
{ | ||
return visitExpression(node, context); | ||
} | ||
|
||
protected R visitStringLiteral(StringLiteral node, C context) | ||
{ | ||
return visitLiteral(node, context); | ||
} | ||
|
||
protected R visitLiteral(Literal node, C context) | ||
{ | ||
return visitExpression(node, context); | ||
} | ||
} |
91 changes: 91 additions & 0 deletions
91
...-delta-lake/src/main/java/io/trino/plugin/deltalake/expression/CaseInsensitiveStream.java
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,91 @@ | ||
/* | ||
* Licensed 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. | ||
*/ | ||
package io.trino.plugin.deltalake.expression; | ||
|
||
import org.antlr.v4.runtime.CharStream; | ||
import org.antlr.v4.runtime.IntStream; | ||
import org.antlr.v4.runtime.misc.Interval; | ||
|
||
public class CaseInsensitiveStream | ||
implements CharStream | ||
{ | ||
private final CharStream stream; | ||
|
||
public CaseInsensitiveStream(CharStream stream) | ||
{ | ||
this.stream = stream; | ||
} | ||
|
||
@Override | ||
public String getText(Interval interval) | ||
{ | ||
return stream.getText(interval); | ||
} | ||
|
||
@Override | ||
public void consume() | ||
{ | ||
stream.consume(); | ||
} | ||
|
||
@Override | ||
public int LA(int i) | ||
{ | ||
int result = stream.LA(i); | ||
|
||
switch (result) { | ||
case 0: | ||
case IntStream.EOF: | ||
return result; | ||
default: | ||
return Character.toUpperCase(result); | ||
} | ||
} | ||
|
||
@Override | ||
public int mark() | ||
{ | ||
return stream.mark(); | ||
} | ||
|
||
@Override | ||
public void release(int marker) | ||
{ | ||
stream.release(marker); | ||
} | ||
|
||
@Override | ||
public int index() | ||
{ | ||
return stream.index(); | ||
} | ||
|
||
@Override | ||
public void seek(int index) | ||
{ | ||
stream.seek(index); | ||
} | ||
|
||
@Override | ||
public int size() | ||
{ | ||
return stream.size(); | ||
} | ||
|
||
@Override | ||
public String getSourceName() | ||
{ | ||
return stream.getSourceName(); | ||
} | ||
} |
Oops, something went wrong.