Skip to content

Commit

Permalink
[CALCITE-4060] Supports implicit type coercion for "NOT IN".
Browse files Browse the repository at this point in the history
  • Loading branch information
Aaaaaaron committed Jun 16, 2020
1 parent f577b7e commit 0268aea
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ public boolean caseWhenCoercion(SqlCallBinding callBinding) {
*/
public boolean inOperationCoercion(SqlCallBinding binding) {
SqlOperator operator = binding.getOperator();
if (operator.getKind() == SqlKind.IN) {
if (operator.getKind() == SqlKind.IN || operator.getKind() == SqlKind.NOT_IN) {
assert binding.getOperandCount() == 2;
final RelDataType type1 = binding.getOperandType(0);
final RelDataType type2 = binding.getOperandType(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,14 @@ class TypeCoercionConverterTest extends SqlToRelTestBase {
+ "from (values (true, true, true))");
}

@Test void testNotInOperation() {
checkPlanEquals("select\n"
+ "4 not in ('1', '2', '3') as f0,\n"
+ "(3, 4) not in (('1', '2')) as f1,\n"
+ "(2, 3) not in (('1', '2'), ('3', '4')) as f2\n"
+ "from (values (true, true, true))");
}

/** Test cases for {@link TypeCoercion#inOperationCoercion}. */
@Test void testInDateTimestamp() {
checkPlanEquals("select (t1_timestamp, t1_date)\n"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,22 @@ LogicalProject(F0=[true], F1=[true], F2=[true])
]]>
</Resource>
</TestCase>
<TestCase name="testInDateTimestamp">
<TestCase name="testNotInOperation">
<Resource name="sql">
<![CDATA[select
4 not in ('1', '2', '3') as f0,
(3, 4) not in (('1', '2')) as f1,
(2, 3) not in (('1', '2'), ('3', '4')) as f2
from (values (true, true, true))]]>
</Resource>
<Resource name="plan">
<![CDATA[
LogicalProject(F0=[true], F1=[true], F2=[true])
LogicalValues(tuples=[[{ true, true, true }]])
]]>
</Resource>
</TestCase>
<TestCase name="testInDateTimestamp">
<Resource name="sql">
<![CDATA[select (t1_timestamp, t1_date)
in ((DATE '2020-04-16', TIMESTAMP '2020-04-16 11:40:53'))
Expand Down

0 comments on commit 0268aea

Please sign in to comment.