Skip to content

[CALCITE-3210] Fix the bug that RelToSqlConverter converts "cast(null as $type)" just as null#1338

Closed
weidong3630 wants to merge 5 commits intoapache:masterfrom
weidong3630:CALCITE-3210
Closed

[CALCITE-3210] Fix the bug that RelToSqlConverter converts "cast(null as $type)" just as null#1338
weidong3630 wants to merge 5 commits intoapache:masterfrom
weidong3630:CALCITE-3210

Conversation

@weidong3630
Copy link
Contributor

@danny0405
Copy link
Contributor

@weidong3630 You can have multiple commits to one PR and do not close the old one, the committers would rebase the code when merging into master.

@weidong3630
Copy link
Contributor Author

@weidong3630 You can have multiple commits to one PR and do not close the old one, the committers would rebase the code when merging into master.

Thanks for your advise, I just do it according to the calcite document. I will be attention to it later.

@julianhyde
Copy link
Contributor

The first word of a commit message should generally not be "Fix". I changed the JIRA subject to "JDBC adapter should generate "CAST(NULL AS type)" rather than "NULL", so maybe use that as the commit message.

Copy link
Contributor

@julianhyde julianhyde left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spaces after '//' please.

Javadoc method comments should start with a verb, first letter upper-case, and end with a period. Rather than "Check whether null item in select need to be casted", write "Returns whether a NULL literal in the SELECT clause needs to be wrapped in a CAST." In the javadoc of that method, can you explain what the algorithm is? I guess you want to wrap if and only if the expression will end up in a SELECT clause? In which case the javadoc should be "Returns whether a NULL literal needs to be wrapped in a CAST."

@weidong3630
Copy link
Contributor Author

I've adopted your suggestions and modify my code and commit message. @julianhyde

* because that the type of NULL can be inferred by the target table of TableModify,
* so NULL does not need to be wrapped in a CAST.
* Here is an example,
* "INSERT INTO t SELECT CAST(NULL AS INT) AS c1, c2 FROM t1"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you mean by "SingleRel", i didn't see any in your example.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implemented done.

@weidong3630
Copy link
Contributor Author

I've solved some conflicts and rebase the commit. Who can help me to review or merge this code?

sql(expected).exec();
}

@Test public void testSelectNullWithInsert() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, can we also give a test case for Join relational expression ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, see testSelectNullWithInsertFromJoin.

[CALCITE-3267] Remove method SqlDataTypeSpec#deriveType(RelDataTypefa…
@weidong3630 weidong3630 force-pushed the CALCITE-3210 branch 2 times, most recently from 1ae3e6c to 199a46c Compare August 20, 2019 13:05
…er than "NULL" conditionally (Wang Weidong)

Add test case of "testSelectNullWithInsertFromJoin".
+ "\"account\"(\"account_id\",\"account_parent\",\"account_type\",\"account_rollup\")"
+ "\tselect \"product\".\"product_id\", \n"
+ "\tcast(NULL AS INT), \n"
+ "\tcast(\"product\".\"product_id\" as varchar), \n"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we replace all these "\t" with "\n" ? Also put a "\n" at the end of every sql statement line.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

…her than "NULL" conditionally (Wang Weidong)

    Modify format of test case.
…her than "NULL" conditionally (Wang Weidong)

    Modify format of test case.
@danny0405 danny0405 added the LGTM-will-merge-soon Overall PR looks OK. Only minor things left. label Aug 26, 2019
Copy link
Contributor

@danny0405 danny0405 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 , except some nit problems about code style, will fix when merging.

@danny0405 danny0405 closed this in e863294 Aug 26, 2019
wangxlong pushed a commit to wangxlong/calcite that referenced this pull request Feb 13, 2020
…er than "NULL" conditionally (Wang Weidong)

Always wrap NULL literal in Project project list with CAST operator
during rel-to-sql conversion.

close apache#1338
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

LGTM-will-merge-soon Overall PR looks OK. Only minor things left.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants