Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Vladsz83 committed Oct 2, 2024
1 parent 12fb9cb commit 8cba45d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@
import org.apache.calcite.sql.SqlNodeList;
import org.apache.calcite.sql.parser.SqlParseException;
import org.apache.calcite.sql.parser.SqlParser;
import org.apache.calcite.sql.type.SqlTypeFamily;
import org.apache.calcite.sql.type.SqlTypeName;
import org.apache.calcite.sql.type.SqlTypeUtil;
import org.apache.calcite.util.ImmutableBitSet;
import org.apache.calcite.util.ImmutableIntList;
Expand Down Expand Up @@ -150,7 +148,7 @@ public static <T> List<T> intersect(Set<T> set, List<T> list) {
}

/**
* Finds the least restrictive type of the inputs and adds a cast projection if required. Doesn't cast {@link SqlTypeName#NULL}.
* Finds the least restrictive type of the inputs and adds a cast projection if required.
*
* @param inputs Inputs to try to cast.
* @param cluster Cluster.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -471,17 +471,17 @@ public void testSetOpRewindability() {
/** */
@Test
public void testNumbersCastInUnion() throws Exception {
doTestNumbersCastInSetOp("UNION", 10, 20, 30, 33, 40, 44, 50);
doTestNumbersCastInSetOp("UNION", 10, 20, 30, 33, 40, 44, 50, null);

doTestNumbersCastInSetOp("UNION ALL", 10, 20, 20, 30, 30, 33, 40, 44, 50, 50, 50, 50);
doTestNumbersCastInSetOp("UNION ALL", 10, 20, 20, 30, 30, 33, 40, 44, 50, 50, 50, 50, null, null);
}

/** */
@Test
public void testNumbersCastInIntersect() throws Exception {
doTestNumbersCastInSetOp("INTERSECT", 20, 50);
doTestNumbersCastInSetOp("INTERSECT", 20, 50, null);

doTestNumbersCastInSetOp("INTERSECT ALL", 20, 50, 50);
doTestNumbersCastInSetOp("INTERSECT ALL", 20, 50, 50, null);
}

/** */
Expand All @@ -494,27 +494,28 @@ public void testNumbersCastInExcept() throws Exception {

/**
* Tests 'SELECT TBL1.val SetOp TBL2.val' where TBL1 has `INT val` and TBL2 has 'val' of different numeric type.
* TBL1: 30, 20, 30, 40, 50, 50
* TBL2: 10, 20, 33, 44, 50, 50
* TBL1: 30, 20, 30, 40, 50, 50, null
* TBL2: 10, 20, 33, 44, 50, 50, null
*
* @param op Operation like 'UNION' or 'INTERSECT'
* @param expected Expected result as integers.
*/
private void doTestNumbersCastInSetOp(String op, int... expected) throws InterruptedException {
private void doTestNumbersCastInSetOp(String op, Integer... expected) throws InterruptedException {
List<String> types = F.asList("TINYINT", "SMALLINT", "INTEGER", "REAL", "FLOAT", "BIGINT", "DOUBLE", "DECIMAL");

sql(client, "CREATE TABLE t0(id INT PRIMARY KEY, val INTEGER) WITH \"affinity_key=id\"");

try {
sql(client, "INSERT INTO t0 VALUES (1, 30), (2, 20), (3, 30), (4, 40), (5, 50), (6, 50)");
sql(client, "INSERT INTO t0 VALUES (1, 30), (2, 20), (3, 30), (4, 40), (5, 50), (6, 50), (7, null)");

for (String tblOpts : Arrays.asList("", " WITH \"template=replicated\"", " WITH \"affinity_key=aff\"")) {
for (String t2 : types) {
sql(client, "CREATE TABLE t1(id INT, aff INT, val " + t2 + ", PRIMARY KEY(id, aff))" + tblOpts);

sql(client, "INSERT INTO t1 VALUES (1, 1, 10), (2, 1, 20), (3, 1, 33), (4, 2, 44), (5, 2, 50), (6, 3, 50)");
sql(client, "INSERT INTO t1 VALUES (1, 1, 10), (2, 1, 20), (3, 1, 33), (4, 2, 44), (5, 2, 50), " +
"(6, 3, 50), (7, 3, null)");

List<List<?>> res = sql(client, "SELECT val from t0 " + op + " select val from t1 ORDER BY 1");
List<List<?>> res = sql(client, "SELECT val from t0 " + op + " select val from t1 ORDER BY 1 NULLS LAST");

sql(client, "DROP TABLE t1");

Expand All @@ -523,7 +524,7 @@ private void doTestNumbersCastInSetOp(String op, int... expected) throws Interru
for (int i = 0; i < expected.length; ++i) {
assertEquals(1, res.get(i).size());

assertEquals(expected[i], ((Number)res.get(i).get(0)).intValue());
assertEquals(expected[i], res.get(i).get(0) == null ? null : ((Number)res.get(i).get(0)).intValue());
}
}
}
Expand Down

0 comments on commit 8cba45d

Please sign in to comment.