Skip to content

Commit

Permalink
Fix throw exception when compare with null
Browse files Browse the repository at this point in the history
  • Loading branch information
FearfulTomcat27 authored Nov 27, 2024
1 parent 77a21a7 commit b072f9e
Show file tree
Hide file tree
Showing 9 changed files with 99 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -237,4 +237,28 @@ public void testFilterWithUDTF() {
fail(throwable.getMessage());
}
}

@Test
public void testCompareWithNull() {
tableResultSetEqualTest(
"select s1 from sg1 where s1 != null", new String[] {"s1"}, new String[] {}, DATABASE_NAME);
tableResultSetEqualTest(
"select s1 from sg1 where s1 <> null", new String[] {"s1"}, new String[] {}, DATABASE_NAME);
tableResultSetEqualTest(
"select s1 from sg1 where s1 = null", new String[] {"s1"}, new String[] {}, DATABASE_NAME);
}

@Test
public void testCalculateWithNull() {
tableResultSetEqualTest(
"select s1 + null from sg1",
new String[] {"_col0"},
new String[] {"null,", "null,"},
DATABASE_NAME);
tableResultSetEqualTest(
"select s1 - null from sg1",
new String[] {"_col0"},
new String[] {"null,", "null,"},
DATABASE_NAME);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import static org.apache.tsfile.read.common.type.IntType.INT32;
import static org.apache.tsfile.read.common.type.LongType.INT64;
import static org.apache.tsfile.read.common.type.TimestampType.TIMESTAMP;
import static org.apache.tsfile.read.common.type.UnknownType.UNKNOWN;

public class AdditionResolver {

Expand All @@ -40,29 +41,42 @@ public class AdditionResolver {
addCondition(INT32, DOUBLE, DOUBLE);
addCondition(INT32, DATE, DATE);
addCondition(INT32, TIMESTAMP, TIMESTAMP);
addCondition(INT32, UNKNOWN, INT32);

addCondition(INT64, INT32, INT64);
addCondition(INT64, INT64, INT64);
addCondition(INT64, FLOAT, FLOAT);
addCondition(INT64, DOUBLE, DOUBLE);
addCondition(INT64, DATE, DATE);
addCondition(INT64, TIMESTAMP, TIMESTAMP);
addCondition(INT64, UNKNOWN, INT64);

addCondition(FLOAT, INT32, FLOAT);
addCondition(FLOAT, INT64, FLOAT);
addCondition(FLOAT, FLOAT, FLOAT);
addCondition(FLOAT, DOUBLE, DOUBLE);
addCondition(FLOAT, UNKNOWN, FLOAT);

addCondition(DOUBLE, INT32, DOUBLE);
addCondition(DOUBLE, INT64, DOUBLE);
addCondition(DOUBLE, FLOAT, DOUBLE);
addCondition(DOUBLE, DOUBLE, DOUBLE);
addCondition(DOUBLE, UNKNOWN, DOUBLE);

addCondition(DATE, INT32, DATE);
addCondition(DATE, INT64, DATE);
addCondition(DATE, UNKNOWN, DATE);

addCondition(TIMESTAMP, INT32, TIMESTAMP);
addCondition(TIMESTAMP, INT64, TIMESTAMP);
addCondition(TIMESTAMP, UNKNOWN, TIMESTAMP);

addCondition(UNKNOWN, INT32, INT32);
addCondition(UNKNOWN, INT64, INT64);
addCondition(UNKNOWN, FLOAT, FLOAT);
addCondition(UNKNOWN, DOUBLE, DOUBLE);
addCondition(UNKNOWN, DATE, DATE);
addCondition(UNKNOWN, TIMESTAMP, TIMESTAMP);
}

private static void addCondition(Type condition1, Type condition2, Type result) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import static org.apache.tsfile.read.common.type.FloatType.FLOAT;
import static org.apache.tsfile.read.common.type.IntType.INT32;
import static org.apache.tsfile.read.common.type.LongType.INT64;
import static org.apache.tsfile.read.common.type.UnknownType.UNKNOWN;

public class DivisionResolver {

Expand All @@ -36,21 +37,30 @@ public class DivisionResolver {
addCondition(INT32, INT64, INT64);
addCondition(INT32, FLOAT, FLOAT);
addCondition(INT32, DOUBLE, DOUBLE);
addCondition(INT32, UNKNOWN, INT32);

addCondition(INT64, INT32, INT64);
addCondition(INT64, INT64, INT64);
addCondition(INT64, FLOAT, FLOAT);
addCondition(INT64, DOUBLE, DOUBLE);
addCondition(INT64, UNKNOWN, INT64);

addCondition(FLOAT, INT32, FLOAT);
addCondition(FLOAT, INT64, FLOAT);
addCondition(FLOAT, FLOAT, FLOAT);
addCondition(FLOAT, DOUBLE, DOUBLE);
addCondition(FLOAT, UNKNOWN, FLOAT);

addCondition(DOUBLE, INT32, DOUBLE);
addCondition(DOUBLE, INT64, DOUBLE);
addCondition(DOUBLE, FLOAT, DOUBLE);
addCondition(DOUBLE, DOUBLE, DOUBLE);
addCondition(DOUBLE, UNKNOWN, DOUBLE);

addCondition(UNKNOWN, INT32, INT32);
addCondition(UNKNOWN, INT64, INT64);
addCondition(UNKNOWN, FLOAT, FLOAT);
addCondition(UNKNOWN, DOUBLE, DOUBLE);
}

private static void addCondition(Type condition1, Type condition2, Type result) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import static org.apache.tsfile.read.common.type.FloatType.FLOAT;
import static org.apache.tsfile.read.common.type.IntType.INT32;
import static org.apache.tsfile.read.common.type.LongType.INT64;
import static org.apache.tsfile.read.common.type.UnknownType.UNKNOWN;

public class ModulusResolver {

Expand All @@ -36,21 +37,30 @@ public class ModulusResolver {
addCondition(INT32, INT64, INT64);
addCondition(INT32, FLOAT, FLOAT);
addCondition(INT32, DOUBLE, DOUBLE);
addCondition(INT32, UNKNOWN, INT32);

addCondition(INT64, INT32, INT64);
addCondition(INT64, INT64, INT64);
addCondition(INT64, FLOAT, FLOAT);
addCondition(INT64, DOUBLE, DOUBLE);
addCondition(INT64, UNKNOWN, INT64);

addCondition(FLOAT, INT32, FLOAT);
addCondition(FLOAT, INT64, FLOAT);
addCondition(FLOAT, FLOAT, FLOAT);
addCondition(FLOAT, DOUBLE, DOUBLE);
addCondition(FLOAT, UNKNOWN, FLOAT);

addCondition(DOUBLE, INT32, DOUBLE);
addCondition(DOUBLE, INT64, DOUBLE);
addCondition(DOUBLE, FLOAT, DOUBLE);
addCondition(DOUBLE, DOUBLE, DOUBLE);
addCondition(DOUBLE, UNKNOWN, DOUBLE);

addCondition(UNKNOWN, INT32, INT32);
addCondition(UNKNOWN, INT64, INT64);
addCondition(UNKNOWN, FLOAT, FLOAT);
addCondition(UNKNOWN, DOUBLE, DOUBLE);
}

private static void addCondition(Type condition1, Type condition2, Type result) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import static org.apache.tsfile.read.common.type.FloatType.FLOAT;
import static org.apache.tsfile.read.common.type.IntType.INT32;
import static org.apache.tsfile.read.common.type.LongType.INT64;
import static org.apache.tsfile.read.common.type.UnknownType.UNKNOWN;

public class MultiplicationResolver {

Expand All @@ -36,21 +37,30 @@ public class MultiplicationResolver {
addCondition(INT32, INT64, INT64);
addCondition(INT32, FLOAT, FLOAT);
addCondition(INT32, DOUBLE, DOUBLE);
addCondition(INT32, UNKNOWN, INT32);

addCondition(INT64, INT32, INT64);
addCondition(INT64, INT64, INT64);
addCondition(INT64, FLOAT, FLOAT);
addCondition(INT64, DOUBLE, DOUBLE);
addCondition(INT64, UNKNOWN, INT64);

addCondition(FLOAT, INT32, FLOAT);
addCondition(FLOAT, INT64, FLOAT);
addCondition(FLOAT, FLOAT, FLOAT);
addCondition(FLOAT, DOUBLE, DOUBLE);
addCondition(FLOAT, UNKNOWN, FLOAT);

addCondition(DOUBLE, INT32, DOUBLE);
addCondition(DOUBLE, INT64, DOUBLE);
addCondition(DOUBLE, FLOAT, DOUBLE);
addCondition(DOUBLE, DOUBLE, DOUBLE);
addCondition(DOUBLE, UNKNOWN, DOUBLE);

addCondition(UNKNOWN, INT32, INT32);
addCondition(UNKNOWN, INT64, INT64);
addCondition(UNKNOWN, FLOAT, FLOAT);
addCondition(UNKNOWN, DOUBLE, DOUBLE);
}

private static void addCondition(Type condition1, Type condition2, Type result) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import static org.apache.tsfile.read.common.type.IntType.INT32;
import static org.apache.tsfile.read.common.type.LongType.INT64;
import static org.apache.tsfile.read.common.type.TimestampType.TIMESTAMP;
import static org.apache.tsfile.read.common.type.UnknownType.UNKNOWN;

public class SubtractionResolver {

Expand All @@ -38,27 +39,36 @@ public class SubtractionResolver {
addCondition(INT32, INT64, INT64);
addCondition(INT32, FLOAT, FLOAT);
addCondition(INT32, DOUBLE, DOUBLE);
addCondition(INT32, UNKNOWN, INT32);

addCondition(INT64, INT32, INT64);
addCondition(INT64, INT64, INT64);
addCondition(INT64, FLOAT, FLOAT);
addCondition(INT64, DOUBLE, DOUBLE);
addCondition(INT64, UNKNOWN, INT64);

addCondition(FLOAT, INT32, FLOAT);
addCondition(FLOAT, INT64, FLOAT);
addCondition(FLOAT, FLOAT, FLOAT);
addCondition(FLOAT, DOUBLE, DOUBLE);
addCondition(FLOAT, UNKNOWN, FLOAT);

addCondition(DOUBLE, INT32, DOUBLE);
addCondition(DOUBLE, INT64, DOUBLE);
addCondition(DOUBLE, FLOAT, DOUBLE);
addCondition(DOUBLE, DOUBLE, DOUBLE);
addCondition(DOUBLE, UNKNOWN, DOUBLE);

addCondition(DATE, INT32, DATE);
addCondition(DATE, INT64, DATE);

addCondition(TIMESTAMP, INT32, TIMESTAMP);
addCondition(TIMESTAMP, INT64, TIMESTAMP);

addCondition(UNKNOWN, INT32, INT32);
addCondition(UNKNOWN, INT64, INT64);
addCondition(UNKNOWN, FLOAT, FLOAT);
addCondition(UNKNOWN, DOUBLE, DOUBLE);
}

private static void addCondition(Type condition1, Type condition2, Type result) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@

import static org.apache.iotdb.commons.conf.IoTDBConstant.PATH_ROOT;
import static org.apache.iotdb.commons.conf.IoTDBConstant.PATH_SEPARATOR;
import static org.apache.iotdb.db.queryengine.plan.relational.function.OperatorType.EQUAL;
import static org.apache.iotdb.db.queryengine.plan.relational.function.OperatorType.LESS_THAN;
import static org.apache.iotdb.db.queryengine.plan.relational.function.OperatorType.LESS_THAN_OR_EQUAL;
import static org.apache.tsfile.read.common.type.BinaryType.TEXT;
import static org.apache.tsfile.read.common.type.BooleanType.BOOLEAN;
import static org.apache.tsfile.read.common.type.DateType.DATE;
Expand All @@ -70,6 +73,7 @@
import static org.apache.tsfile.read.common.type.LongType.INT64;
import static org.apache.tsfile.read.common.type.StringType.STRING;
import static org.apache.tsfile.read.common.type.TimestampType.TIMESTAMP;
import static org.apache.tsfile.read.common.type.UnknownType.UNKNOWN;

public class TableMetadataImpl implements Metadata {

Expand Down Expand Up @@ -786,6 +790,10 @@ public static boolean isTimestampType(Type type) {
return TIMESTAMP.equals(type);
}

public static boolean isUnknownType(Type type) {
return UNKNOWN.equals(type);
}

public static boolean isIntegerNumber(Type type) {
return INT32.equals(type) || INT64.equals(type);
}
Expand All @@ -801,7 +809,10 @@ public static boolean isTwoTypeComparable(List<? extends Type> argumentTypes) {
}

// Boolean type and Binary Type can not be compared with other types
return (isNumericType(left) && isNumericType(right)) || (isCharType(left) && isCharType(right));
return (isNumericType(left) && isNumericType(right))
|| (isCharType(left) && isCharType(right))
|| (isUnknownType(left) && (isNumericType(right) || isCharType(right)))
|| ((isNumericType(left) || isCharType(left)) && isUnknownType(right));
}

public static boolean isArithmeticType(Type type) {
Expand All @@ -819,6 +830,10 @@ public static boolean isTwoTypeCalculable(List<? extends Type> argumentTypes) {
}
Type left = argumentTypes.get(0);
Type right = argumentTypes.get(1);
if ((isUnknownType(left) && isArithmeticType(right))
|| (isUnknownType(right) && isArithmeticType(left))) {
return true;
}
return isArithmeticType(left) && isArithmeticType(right);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@

import org.apache.tsfile.read.common.block.column.NullColumn;

import static org.apache.tsfile.read.common.type.UnknownType.UNKNOWN;

public class NullColumnTransformer extends LeafColumnTransformer {

public NullColumnTransformer() {
super(null);
super(UNKNOWN);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ protected AbstractCastFunctionColumnTransformer(

@Override
protected void doTransform(Column column, ColumnBuilder columnBuilder) {
TypeEnum sourceType = childColumnTransformer.getType().getTypeEnum();
Type childType = childColumnTransformer.getType();
TypeEnum sourceType = childType.getTypeEnum();
for (int i = 0, n = column.getPositionCount(); i < n; i++) {
if (!column.isNull(i)) {
transform(column, columnBuilder, sourceType, childType, i);
Expand All @@ -61,8 +61,8 @@ protected void doTransform(Column column, ColumnBuilder columnBuilder) {

@Override
protected void doTransform(Column column, ColumnBuilder columnBuilder, boolean[] selection) {
TypeEnum sourceType = childColumnTransformer.getType().getTypeEnum();
Type childType = childColumnTransformer.getType();
TypeEnum sourceType = childType.getTypeEnum();
for (int i = 0, n = column.getPositionCount(); i < n; i++) {
if (selection[i] && !column.isNull(i)) {
transform(column, columnBuilder, sourceType, childType, i);
Expand Down

0 comments on commit b072f9e

Please sign in to comment.