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 @@ -284,7 +284,7 @@ public class SqlStdOperatorTable extends ReflectiveSqlOperatorTable {
}
return type;
}),
null,
InferTypes.RETURN_TYPE,
OperandTypes.STRING_SAME_SAME_OR_ARRAY_SAME_SAME);


Expand Down
11 changes: 11 additions & 0 deletions core/src/test/java/org/apache/calcite/test/JdbcTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -5967,6 +5967,17 @@ private CalciteAssert.AssertQuery withEmpDept(String sql) {
});
}

/** Test case for
* <a href="https://issues.apache.org/jira/browse/CALCITE-7407">[CALCITE-7407]
* Illegal use of dynamic parameter with ||</a>. */
@Test void testPreparedStatementConcatDynamicParameter() {
CalciteAssert.hr()
.query("select \"name\" from \"hr\".\"emps\"\n"
+ "where \"name\" = (? || 'odore')")
.consumesPreparedStatement(p -> p.setString(1, "The"))
.returns("name=Theodore\n");
}

/** Test case for
* <a href="https://issues.apache.org/jira/browse/CALCITE-2061">[CALCITE-2061]
* Dynamic parameters in offset/fetch</a>. */
Expand Down
22 changes: 22 additions & 0 deletions core/src/test/java/org/apache/calcite/test/SqlValidatorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -822,6 +822,10 @@ static SqlOperatorTable operatorTableFor(SqlLibrary library) {
.columnType("CHAR(6) NOT NULL");
expr("'a'||'b'||cast('cde' as VARCHAR(3))|| 'f'")
.columnType("VARCHAR(6) NOT NULL");
expr("null||'b'")
.columnType("VARCHAR");
expr("cast(null as ANY)||cast(null as ANY)")
.columnType("ANY");
expr("_UTF16'a'||_UTF16'b'||_UTF16'c'").ok();
}

Expand Down Expand Up @@ -8287,6 +8291,24 @@ void testGroupExpressionEquivalenceParams() {
sql("select 1 from emp having sum(sal) < ?").ok();
}

/** Test case for
* <a href="https://issues.apache.org/jira/browse/CALCITE-7407">[CALCITE-7407]
* Illegal use of dynamic parameter with ||</a>. */
@Test void testBindConcat() {
sql("select * from emp where ename = (? || 'KI')").ok();
sql("select * from emp where ename = ('SM' || ?)").ok();
}

/** Test case for
* <a href="https://issues.apache.org/jira/browse/CALCITE-7407">[CALCITE-7407]
* Illegal use of dynamic parameter with ||</a>. */
@Test void testConcatNullAndAnyWithContext() {
sql("select * from emp where ename = (null || 'KI')").ok();
sql("select * from emp where ename = ('SM' || null)").ok();
sql("select * from emp where ename = (cast(null as any) || 'KI')").ok();
sql("select * from emp where ename = ('SM' || cast(null as any))").ok();
}

/** Test case for
* <a href="https://issues.apache.org/jira/browse/CALCITE-1310">[CALCITE-1310]
* Infer type of arguments to BETWEEN operator</a>. */
Expand Down
Loading