-
Notifications
You must be signed in to change notification settings - Fork 181
Support ppl CAST function with Calcite #3439
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support ppl CAST function with Calcite #3439
Conversation
Signed-off-by: Lantao Jin <ltjin@amazon.com>
Signed-off-by: Lantao Jin <ltjin@amazon.com>
| INTERVAL(ExprCoreType.INTERVAL); | ||
| INTERVAL(ExprCoreType.INTERVAL), | ||
|
|
||
| IP(ExprCoreType.IP); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cast_to_IP unsupported yet since IP type is not supported with Calcite. But this is a missing code in DataType class.
| RelDataType type = context.rexBuilder.getTypeFactory().createSqlType(sqlTypeName); | ||
| RelDataType nullableType = | ||
| context.rexBuilder.getTypeFactory().createTypeWithNullability(type, true); | ||
| return context.rexBuilder.makeCast(SqlParserPos.ZERO, nullableType, expr, false, true); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use this 4 lines instead of context.relbuilder.cast() because we need the last parameter to true
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does Calcite has same Data Type Conversion rule? anything we want to call-out and update doc?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will add more test for this table
|
|
||
| @Test | ||
| public void testCastToUnknownType() { | ||
| assertThrows( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what is error message?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in V2, the cast function has a convertedType list.
sql/ppl/src/main/antlr/OpenSearchPPLParser.g4
Lines 407 to 420 in f805df0
| convertedDataType | |
| : typeName = DATE | |
| | typeName = TIME | |
| | typeName = TIMESTAMP | |
| | typeName = INT | |
| | typeName = INTEGER | |
| | typeName = DOUBLE | |
| | typeName = LONG | |
| | typeName = FLOAT | |
| | typeName = STRING | |
| | typeName = BOOLEAN | |
| | typeName = IP | |
| | typeName = JSON | |
| ; |
Any unsupported type will throw SyntaxCheckException, no matter what the message is.
| "source=%s | eval a = cast(state as string) | fields a", | ||
| TEST_INDEX_STATE_COUNTRY_WITH_NULL)); | ||
|
|
||
| assertEquals( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not verifyDataRows?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know how to check null row with verifyDataRows
The method rows() cannot work with null.
| String actual = | ||
| execute( | ||
| String.format( | ||
| "source=%s | eval a = cast(name as boolean) | fields a", TEST_INDEX_STATE_COUNTRY)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cast("1" as boolean) should return True?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no, only 'true', 'True', 'TRUE' etc could return True in cast_to_boolean.
cast(1 as boolean), cast(2.5 as boolean) are all return false and cast("1" as boolean) return null.
This seems a breaking change comparing to V2:
cast("1" as boolean) returns false
cast(1 as boolean), cast(2.5 as boolean) return true
cast(0 as boolean) returns false
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apache Spark:
select cast(1 as boolean); -- true
select cast(2 as boolean); -- true
select cast(0 as boolean); -- false
select cast('1' as boolean); -- true
select cast('2' as boolean); -- null
select cast('0' as boolean); -- false
select cast('aa' as boolean); -- null
Em, I think this is a bug of Calcite, we can fix it in our side.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Open #3443 for discussion
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The latest commit follows the behaviour of SparkSQL. Check above
| RelDataType type = context.rexBuilder.getTypeFactory().createSqlType(sqlTypeName); | ||
| RelDataType nullableType = | ||
| context.rexBuilder.getTypeFactory().createTypeWithNullability(type, true); | ||
| return context.rexBuilder.makeCast(SqlParserPos.ZERO, nullableType, expr, false, true); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does Calcite has same Data Type Conversion rule? anything we want to call-out and update doc?
Signed-off-by: Lantao Jin <ltjin@amazon.com>
Call-out:
|
penghuo
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please fix IT before merge.
Signed-off-by: Lantao Jin <ltjin@amazon.com>
0022a31
into
opensearch-project:feature/calcite-engine
|
Failure caused by a flaky test |
* init commit Signed-off-by: Lantao Jin <ltjin@amazon.com> * Support ppl CAST function with Calcite Signed-off-by: Lantao Jin <ltjin@amazon.com> * Add more tests Signed-off-by: Lantao Jin <ltjin@amazon.com> * fix ci issue Signed-off-by: Lantao Jin <ltjin@amazon.com> --------- Signed-off-by: Lantao Jin <ltjin@amazon.com> Signed-off-by: xinyual <xinyual@amazon.com>
Description
Support ppl CAST function with Calcite
Related Issues
Resolves #3417
Check List
--signoff.By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.