-
Notifications
You must be signed in to change notification settings - Fork 2.5k
[CALCITE-3210] Fix the bug that RelToSqlConverter converts "cast(null as $type)" just as null #1338
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
Closed
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
35e07e7
Merge pull request #4 from apache/master
weidong3630 0bcce38
[CALCITE-3210] JDBC adapter should generate "CAST(NULL AS type)" rath…
weidong3630 f96b187
[CALCITE-3210] JDBC adapter should generate "CAST(NULL AS type)" rath…
weidong3630 dfdb5e0
[CALCITE-3210] JDBC adapter should generate "CAST(NULL AS type)" …
weidong3630 82c118a
[CALCITE-3210] JDBC adapter should generate "CAST(NULL AS type)" …
weidong3630 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -3694,6 +3694,96 @@ private void checkLiteral2(String expression, String expected) { | |
| assertTrue(postgresqlDialect.supportsDataType(integerDataType)); | ||
| } | ||
|
|
||
| @Test public void testSelectNull() { | ||
| String query = "SELECT CAST(NULL AS INT)"; | ||
| final String expected = "SELECT CAST(NULL AS INTEGER)\n" | ||
| + "FROM (VALUES (0)) AS \"t\" (\"ZERO\")"; | ||
| sql(query).ok(expected); | ||
| // validate | ||
| sql(expected).exec(); | ||
| } | ||
|
|
||
| @Test public void testSelectNullWithCount() { | ||
| String query = "SELECT COUNT(CAST(NULL AS INT))"; | ||
| final String expected = "SELECT COUNT(CAST(NULL AS INTEGER))\n" | ||
| + "FROM (VALUES (0)) AS \"t\" (\"ZERO\")"; | ||
| sql(query).ok(expected); | ||
| // validate | ||
| sql(expected).exec(); | ||
| } | ||
|
|
||
| @Test public void testSelectNullWithGroupByNull() { | ||
| String query = "SELECT COUNT(CAST(NULL AS INT)) FROM (VALUES (0)) " | ||
| + "AS \"t\" GROUP BY CAST(NULL AS VARCHAR CHARACTER SET \"ISO-8859-1\")"; | ||
weidong3630 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| final String expected = "SELECT COUNT(CAST(NULL AS INTEGER))\n" | ||
| + "FROM (VALUES (0)) AS \"t\" (\"EXPR$0\")\nGROUP BY CAST(NULL " | ||
| + "AS VARCHAR CHARACTER SET \"ISO-8859-1\")"; | ||
| sql(query).ok(expected); | ||
| // validate | ||
| sql(expected).exec(); | ||
| } | ||
|
|
||
| @Test public void testSelectNullWithGroupByVar() { | ||
| String query = "SELECT COUNT(CAST(NULL AS INT)) FROM \"account\" " | ||
| + "AS \"t\" GROUP BY \"account_type\""; | ||
| final String expected = "SELECT COUNT(CAST(NULL AS INTEGER))\n" | ||
| + "FROM \"foodmart\".\"account\"\n" | ||
| + "GROUP BY \"account_type\""; | ||
| sql(query).ok(expected); | ||
| // validate | ||
| sql(expected).exec(); | ||
| } | ||
|
|
||
| @Test public void testSelectNullWithInsert() { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks, can we also give a test case for
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done, see |
||
| String query = "insert into " | ||
| + "\"account\"(\"account_id\",\"account_parent\",\"account_type\",\"account_rollup\")" | ||
| + " select 1, cast(NULL AS INT), cast(123 as varchar), cast(123 as varchar)"; | ||
| final String expected = "INSERT INTO \"foodmart\".\"account\" (" | ||
| + "\"account_id\", \"account_parent\", \"account_description\", " | ||
| + "\"account_type\", \"account_rollup\", \"Custom_Members\")\n" | ||
| + "(SELECT 1 AS \"account_id\", CAST(NULL AS INTEGER) AS \"account_parent\"," | ||
| + " CAST(NULL AS VARCHAR(30) CHARACTER SET " | ||
| + "\"ISO-8859-1\") AS \"account_description\", '123' AS \"account_type\", " | ||
| + "" | ||
| + "'123' AS \"account_rollup\", CAST(NULL AS VARCHAR" | ||
| + "(255) CHARACTER SET \"ISO-8859-1\") AS \"Custom_Members\"\n" | ||
| + "FROM (VALUES (0)) AS \"t\" (\"ZERO\"))"; | ||
| sql(query).ok(expected); | ||
| // validate | ||
| sql(expected).exec(); | ||
rubenada marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| @Test public void testSelectNullWithInsertFromJoin() { | ||
| String query = "insert into \n" | ||
| + "\"account\"(\"account_id\",\"account_parent\",\n" | ||
| + "\"account_type\",\"account_rollup\")\n" | ||
| + "select \"product\".\"product_id\", \n" | ||
| + "cast(NULL AS INT), \n" | ||
| + "cast(\"product\".\"product_id\" as varchar), \n" | ||
| + "cast(\"sales_fact_1997\".\"store_id\" as varchar)\n" | ||
| + "from \"product\"\n" | ||
| + "inner join \"sales_fact_1997\"\n" | ||
| + "on \"product\".\"product_id\" = \"sales_fact_1997\".\"product_id\""; | ||
| final String expected = "INSERT INTO \"foodmart\".\"account\" " | ||
| + "(\"account_id\", \"account_parent\", \"account_description\", " | ||
| + "\"account_type\", \"account_rollup\", \"Custom_Members\")\n" | ||
| + "(SELECT \"product\".\"product_id\" AS \"account_id\", " | ||
| + "CAST(NULL AS INTEGER) AS \"account_parent\", CAST(NULL AS VARCHAR" | ||
| + "(30) CHARACTER SET \"ISO-8859-1\") AS \"account_description\", " | ||
| + "CAST(\"product\".\"product_id\" AS VARCHAR CHARACTER SET " | ||
| + "\"ISO-8859-1\") AS \"account_type\", " | ||
| + "CAST(\"sales_fact_1997\".\"store_id\" AS VARCHAR CHARACTER SET \"ISO-8859-1\") AS " | ||
| + "\"account_rollup\", " | ||
| + "CAST(NULL AS VARCHAR(255) CHARACTER SET \"ISO-8859-1\") AS \"Custom_Members\"\n" | ||
| + "FROM \"foodmart\".\"product\"\n" | ||
| + "INNER JOIN \"foodmart\".\"sales_fact_1997\" " | ||
| + "ON \"product\".\"product_id\" = \"sales_fact_1997\".\"product_id\")"; | ||
| sql(query).ok(expected); | ||
| // validate | ||
| sql(expected).exec(); | ||
| } | ||
|
|
||
|
|
||
| @Test public void testDialectQuoteStringLiteral() { | ||
| dialects().forEach((dialect, databaseProduct) -> { | ||
| assertThat(dialect.quoteStringLiteral(""), is("''")); | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.