Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1984,6 +1984,13 @@
case ALL:
return RexUtil.composeConjunction(rexBuilder, comparisons, true);
case NOT_IN:
if (comparisons.stream().allMatch(c -> c.getKind() == SqlKind.EQUALS)) {
final List<RexNode> notEqualsComparisons =
Util.transform(comparisons,
c -> rexBuilder.makeCall(SqlStdOperatorTable.NOT_EQUALS,
((RexCall) c).getOperands()));
return RexUtil.composeConjunction(rexBuilder, notEqualsComparisons, false);
}
return rexBuilder.makeCall(SqlStdOperatorTable.NOT,
RexUtil.composeDisjunction(rexBuilder, comparisons));
case IN:
Expand Down Expand Up @@ -2891,7 +2898,7 @@
bb.setRoot(uncollect, true);
}

protected void convertMatchRecognize(Blackboard bb,

Check failure on line 2901 in core/src/main/java/org/apache/calcite/sql2rel/SqlToRelConverter.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Refactor this method to reduce its Cognitive Complexity from 19 to the 15 allowed.

See more on https://sonarcloud.io/project/issues?id=apache_calcite&issues=AZ-clsoctfFoT9tN6FR7&open=AZ-clsoctfFoT9tN6FR7&pullRequest=5121
SqlMatchRecognize matchRecognize) {
final SqlValidatorNamespace ns = getNamespace(matchRecognize);
final SqlValidatorScope scope = validator().getMatchRecognizeScope(matchRecognize);
Expand Down Expand Up @@ -5921,7 +5928,7 @@
}
}

@Override public RexNode convertExpression(SqlNode expr) {

Check warning on line 5931 in core/src/main/java/org/apache/calcite/sql2rel/SqlToRelConverter.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

A "Brain Method" was detected. Refactor it to reduce at least one of the following metrics: LOC from 166 to 64, Complexity from 51 to 14, Nesting Level from 4 to 2, Number of Variables from 22 to 6.

See more on https://sonarcloud.io/project/issues?id=apache_calcite&issues=AZ-clsoctfFoT9tN6FR8&open=AZ-clsoctfFoT9tN6FR8&pullRequest=5121
// If we're in aggregation mode and this is an expression in the
// GROUP BY clause, return a reference to the field.
AggConverter agg = this.agg;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -945,6 +945,16 @@ public static void checkActualAndReferenceFiles() {
sql(sql).ok();
}

@Test void testNotInSingleValue() {
final String sql = "select * from emp where deptno not in (10)";
sql(sql).ok();
}

@Test void testNotInMultiValue() {
final String sql = "select * from emp where deptno not in (10, 20)";
sql(sql).ok();
}

@Test void testAggFilterWithInSubQuery() {
final String sql = "select\n"
+ " count(*) filter (where empno in (select deptno from empnullables))\n"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6582,7 +6582,7 @@ join sales.emp e on e.deptno = d.deptno and d.deptno not in (4, 6)]]>
<Resource name="planBefore">
<![CDATA[
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8], EMPNO0=[$9], ENAME0=[$10], JOB0=[$11], MGR0=[$12], HIREDATE0=[$13], SAL0=[$14], COMM0=[$15], DEPTNO0=[$16], SLACKER0=[$17])
LogicalJoin(condition=[AND(=($16, $7), NOT(OR(=($7, 4), =($7, 6))))], joinType=[inner])
LogicalJoin(condition=[AND(=($16, $7), <>($7, 4), <>($7, 6))], joinType=[inner])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
Expand All @@ -6591,7 +6591,7 @@ LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$
<![CDATA[
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8], EMPNO0=[$9], ENAME0=[$10], JOB0=[$11], MGR0=[$12], HIREDATE0=[$13], SAL0=[$14], COMM0=[$15], DEPTNO0=[$16], SLACKER0=[$17])
LogicalJoin(condition=[=($16, $7)], joinType=[inner])
LogicalFilter(condition=[NOT(OR(=($7, 4), =($7, 6)))])
LogicalFilter(condition=[AND(<>($7, 4), <>($7, 6))])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalFilter(condition=[SEARCH($7, Sarg[(-∞..4), (4..6), (6..+∞)])])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6015,7 +6015,7 @@ LogicalProject(EXPR$0=[COMPARE_STRINGS_OR_NUMERIC_VALUES(1, 1)])
<Resource name="plan">
<![CDATA[
LogicalProject(EMPNO=[$0])
LogicalFilter(condition=[CASE(true, NOT(OR(=($7, 10), =($7, 20))), false, NOT(false), NOT(OR(=($7, 30), =($7, 40))))])
LogicalFilter(condition=[CASE(true, AND(<>($7, 10), <>($7, 20)), false, NOT(false), AND(<>($7, 30), <>($7, 40)))])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
Expand All @@ -6027,7 +6027,7 @@ LogicalProject(EMPNO=[$0])
<Resource name="plan">
<![CDATA[
LogicalProject(EMPNO=[$0])
LogicalFilter(condition=[CASE(true, NOT(OR(=($7, 10), =($7, 20))), NOT(true))])
LogicalFilter(condition=[CASE(true, AND(<>($7, 10), <>($7, 20)), NOT(true))])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
Expand All @@ -6039,7 +6039,7 @@ LogicalProject(EMPNO=[$0])
<Resource name="plan">
<![CDATA[
LogicalProject(EMPNO=[$0])
LogicalFilter(condition=[CASE(true, CAST(NOT(OR(=($7, 10), =($7, 20)))):BOOLEAN, null:BOOLEAN)])
LogicalFilter(condition=[CASE(true, CAST(AND(<>($7, 10), <>($7, 20))):BOOLEAN, null:BOOLEAN)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
Expand All @@ -6059,6 +6059,30 @@ LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$
LogicalProject($f0=[true])
LogicalFilter(condition=[=($cor0.DEPTNO, $0)])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
</TestCase>
<TestCase name="testNotInMultiValue">
<Resource name="sql">
<![CDATA[select * from emp where deptno not in (10, 20)]]>
</Resource>
<Resource name="plan">
<![CDATA[
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalFilter(condition=[AND(<>($7, 10), <>($7, 20))])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testNotInSingleValue">
<Resource name="sql">
<![CDATA[select * from emp where deptno not in (10)]]>
</Resource>
<Resource name="plan">
<![CDATA[
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalFilter(condition=[<>($7, 10)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
Expand Down
Loading