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

Fix throw exception when compare with null #14074

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
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 @@ -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 s2 - 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 @@ -22,10 +22,13 @@
import java.util.Map;
import java.util.Optional;

import static org.apache.tsfile.read.common.type.DateType.DATE;
import static org.apache.tsfile.read.common.type.DoubleType.DOUBLE;
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.TimestampType.TIMESTAMP;
import static org.apache.tsfile.read.common.type.UnknownType.UNKNOWN;

public class DivisionResolver {

Expand All @@ -36,21 +39,36 @@ 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(DATE, UNKNOWN, DATE);

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 @@ -22,10 +22,13 @@
import java.util.Map;
import java.util.Optional;

import static org.apache.tsfile.read.common.type.DateType.DATE;
import static org.apache.tsfile.read.common.type.DoubleType.DOUBLE;
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.TimestampType.TIMESTAMP;
import static org.apache.tsfile.read.common.type.UnknownType.UNKNOWN;

public class ModulusResolver {

Expand All @@ -36,21 +39,36 @@ 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(DATE, UNKNOWN, DATE);

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 @@ -22,10 +22,13 @@
import java.util.Map;
import java.util.Optional;

import static org.apache.tsfile.read.common.type.DateType.DATE;
import static org.apache.tsfile.read.common.type.DoubleType.DOUBLE;
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.TimestampType.TIMESTAMP;
import static org.apache.tsfile.read.common.type.UnknownType.UNKNOWN;

public class MultiplicationResolver {

Expand All @@ -36,21 +39,36 @@ 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(DATE, UNKNOWN, DATE);

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 @@ -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,40 @@ 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(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 @@ -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 @@ -106,7 +110,6 @@ public Optional<TableSchema> getTableSchema(SessionInfo session, QualifiedObject
@Override
public Type getOperatorReturnType(OperatorType operatorType, List<? extends Type> argumentTypes)
throws OperatorNotFoundException {

switch (operatorType) {
case ADD:
if (!isTwoTypeCalculable(argumentTypes)
Expand Down Expand Up @@ -780,6 +783,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 @@ -793,9 +800,11 @@ public static boolean isTwoTypeComparable(List<? extends Type> argumentTypes) {
if (left.equals(right)) {
return true;
}

// 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 @@ -813,6 +822,19 @@ 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);
}

public static boolean isCalculateWithNull(List<? extends Type> argumentTypes) {
if (argumentTypes.size() != 2) {
return false;
}
Type left = argumentTypes.get(0);
Type right = argumentTypes.get(1);
return isArithmeticType(left) && isUnknownType(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
Loading