Skip to content
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

[CALCITE-6349] CoreRules.PROJECT_REDUCE_EXPRESSIONS crashes... #3747

Merged
merged 1 commit into from
Apr 9, 2024
Merged
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 @@ -1399,7 +1399,7 @@ private static RelDataType arrayInsertReturnType(SqlOperatorBinding opBinding) {
@LibraryOperator(libraries = {SPARK})
public static final SqlFunction ARRAY_REPEAT =
SqlBasicFunction.create(SqlKind.ARRAY_REPEAT,
ReturnTypes.TO_ARRAY,
ReturnTypes.TO_ARRAY.andThen(SqlTypeTransforms.TO_NULLABLE),
OperandTypes.sequence(
"ARRAY_REPEAT(ANY, INTEGER)",
OperandTypes.ANY, OperandTypes.typeName(SqlTypeName.INTEGER)));
Expand Down
14 changes: 14 additions & 0 deletions core/src/test/java/org/apache/calcite/test/RelOptRulesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2002,6 +2002,20 @@ private void checkSemiOrAntiJoinProjectTranspose(JoinRelType type) {
.checkUnchanged();
}

/** Test case for <a href="https://issues.apache.org/jira/projects/CALCITE/issues/CALCITE-6349">
* [CALCITE-6349] CoreRules.PROJECT_REDUCE_EXPRESSIONS crashes on expression
* with ARRAY_REPEAT</a>. */
@Test void testArrayRepeat() {
final String sql = "select array_repeat(1, null)";
sql(sql)
.withFactory(
t -> t.withOperatorTable(
opTab -> SqlLibraryOperatorTableFactory.INSTANCE.getOperatorTable(
SqlLibrary.STANDARD, SqlLibrary.SPARK)))
.withRule(CoreRules.PROJECT_REDUCE_EXPRESSIONS)
.check();
}

@Test void testDistinctCountMixed() {
final String sql = "select deptno, count(distinct deptno, job) as cddj,\n"
+ " sum(sal) as s\n"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1300,6 +1300,23 @@ LogicalProject(EXPR$0=[ARRAY_CONCAT(ARRAY(1, 2), ARRAY(3, 4))])
<![CDATA[
LogicalProject(EXPR$0=[CAST(ARRAY(1, 2, 3, 4)):INTEGER NOT NULL ARRAY NOT NULL])
LogicalValues(tuples=[[{ 0 }]])
]]>
</Resource>
</TestCase>
<TestCase name="testArrayRepeat">
<Resource name="sql">
<![CDATA[select array_repeat(1, null)]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(EXPR$0=[ARRAY_REPEAT(1, null:DECIMAL(19, 9))])
LogicalValues(tuples=[[{ 0 }]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(EXPR$0=[null:INTEGER NOT NULL ARRAY])
LogicalValues(tuples=[[{ 0 }]])
]]>
</Resource>
</TestCase>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6820,7 +6820,7 @@ void checkRegexpExtract(SqlOperatorFixture f0, FunctionAlias functionAlias) {
f.checkScalar("array_repeat(map[1, 'a', 2, 'b'], 2)", "[{1=a, 2=b}, {1=a, 2=b}]",
"(INTEGER NOT NULL, CHAR(1) NOT NULL) MAP NOT NULL ARRAY NOT NULL");
f.checkScalar("array_repeat(cast(null as integer), 2)", "[null, null]",
"INTEGER ARRAY NOT NULL");
"INTEGER ARRAY");
// elements cast
f.checkScalar("array_repeat(cast(1 as tinyint), 2)", "[1, 1]",
"TINYINT NOT NULL ARRAY NOT NULL");
Expand Down
Loading