Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1. Implement VARCHAR(length) 2. Add mini-language to calculate return type parameter co-authored with Dain Sundstrom 3. Insert cast function even for type-only coercions This patch changes the way optimization for not inserting cast calls for type-type only coercions work. Original code caused errors during bytecode preparation for plan execution. Problematic case: ARRAY('dog', 'kitten'). During semantic analysis this was treated as: ARRAY((CAST 'dog' as VARCHAR(6)), 'kitten') and therefore implementation of ArrayConstructor for parameter type VARCHAR(6) was generated. But cast expression was not added to result query expression, as case VARCHAR(3) -> VARCHAR(6) is type-only cast. Then byte generating code was failing as it was looking for instantiation of ARRAY_CONSTRUCTOR(VARCHAR(3), VARCHAR(6)) despite the fact only ARRAY_CONSTRUCTOR(VARCHAR(6), VARCHAR(6)) was generated. Now we add Cast operator to AST. But it has typeOnly marker set to true. And then when execution plan is generated no cast operation call is generated. co-authored with Lukas Osipiuk 4. Add explicit literalParameters
- Loading branch information
Showing
65 changed files
with
1,913 additions
and
460 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
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
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
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
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
56 changes: 56 additions & 0 deletions
56
presto-main/src/main/antlr4/com/facebook/presto/type/TypeCalculation.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,56 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
//TODO: consider using the SQL grammar for this | ||
grammar TypeCalculation; | ||
|
||
typeCalculation | ||
: expression | ||
; | ||
|
||
expression | ||
: NULL #nullLiteral | ||
| INTEGER_VALUE #numericLiteral | ||
| IDENTIFIER #identifier | ||
| '(' expression ')' #parenthesizedExpression | ||
| operator=(MINUS | PLUS) expression #arithmeticUnary | ||
| left=expression operator=(ASTERISK | SLASH) right=expression #arithmeticBinary | ||
| left=expression operator=(PLUS | MINUS) right=expression #arithmeticBinary | ||
; | ||
|
||
PLUS: '+'; | ||
MINUS: '-'; | ||
ASTERISK: '*'; | ||
SLASH: '/'; | ||
NULL: 'NULL'; | ||
|
||
IDENTIFIER | ||
: (LETTER | '_') (LETTER | DIGIT | '_' )* | ||
; | ||
|
||
INTEGER_VALUE | ||
: DIGIT+ | ||
; | ||
|
||
fragment DIGIT | ||
: ('0'..'9') | ||
; | ||
|
||
fragment LETTER | ||
: [A-Za-z] | ||
; | ||
|
||
WS | ||
: [ \r\n\t]+ -> channel(HIDDEN) | ||
; |
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.