Skip to content
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 @@ -66,7 +66,7 @@ public static void tearDown() throws Exception {

@Test
public void nullFilterTest() throws Exception {
final String result = defaultFormatDataTime(1) + ",0,false,11.1";
String result = defaultFormatDataTime(1) + ",0,false,11.1";
try (final Connection connectionIsNull =
EnvFactory.getEnv().getConnection(BaseEnv.TABLE_SQL_DIALECT);
final Statement statement = connectionIsNull.createStatement()) {
Expand Down Expand Up @@ -134,6 +134,28 @@ public void nullFilterTest() throws Exception {
+ resultSet.getString("s3");
assertEquals(result, ans);
assertFalse(resultSet.next());

// Test constant select item
resultSet = statement.executeQuery("select *, 1 from testNullId");
result = defaultFormatDataTime(1) + ",null,null,0,false,11.1,1";
assertTrue(resultSet.next());
ans =
resultSet.getString("time")
+ ","
+ resultSet.getString("id1")
+ ","
+ resultSet.getString("id2")
+ ","
+ resultSet.getString("s1")
+ ","
+ resultSet.getString("s2")
+ ","
+ resultSet.getString("s3")
+ ","
+ resultSet.getString("_col6");

assertEquals(result, ans);
assertFalse(resultSet.next());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@
import org.apache.tsfile.read.common.block.column.BinaryColumn;
import org.apache.tsfile.read.common.block.column.BooleanColumn;
import org.apache.tsfile.read.common.block.column.DoubleColumn;
import org.apache.tsfile.read.common.block.column.IntColumn;
import org.apache.tsfile.read.common.block.column.LongColumn;
import org.apache.tsfile.read.common.type.Type;
import org.apache.tsfile.utils.Binary;
Expand All @@ -119,6 +120,7 @@
import static org.apache.tsfile.read.common.type.BlobType.BLOB;
import static org.apache.tsfile.read.common.type.BooleanType.BOOLEAN;
import static org.apache.tsfile.read.common.type.DoubleType.DOUBLE;
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.StringType.STRING;
import static org.apache.tsfile.utils.RegexUtils.compileRegex;
Expand Down Expand Up @@ -330,10 +332,20 @@ protected ColumnTransformer visitLongLiteral(LongLiteral node, Context context)
context.cache.computeIfAbsent(
node,
e -> {
ConstantColumnTransformer columnTransformer =
new ConstantColumnTransformer(
INT64,
new LongColumn(1, Optional.empty(), new long[] {node.getParsedValue()}));
ConstantColumnTransformer columnTransformer;
if (node.getParsedValue() >= Integer.MIN_VALUE
&& node.getParsedValue() <= Integer.MAX_VALUE) {
columnTransformer =
new ConstantColumnTransformer(
INT32,
new IntColumn(
1, Optional.empty(), new int[] {(int) node.getParsedValue()}));
} else {
columnTransformer =
new ConstantColumnTransformer(
INT64,
new LongColumn(1, Optional.empty(), new long[] {node.getParsedValue()}));
}
context.leafList.add(columnTransformer);
return columnTransformer;
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.apache.iotdb.db.queryengine.plan.relational.sql.ast.IsNotNullPredicate;
import org.apache.iotdb.db.queryengine.plan.relational.sql.ast.IsNullPredicate;
import org.apache.iotdb.db.queryengine.plan.relational.sql.ast.LikePredicate;
import org.apache.iotdb.db.queryengine.plan.relational.sql.ast.Literal;
import org.apache.iotdb.db.queryengine.plan.relational.sql.ast.LogicalExpression;
import org.apache.iotdb.db.queryengine.plan.relational.sql.ast.NotExpression;
import org.apache.iotdb.db.queryengine.plan.relational.sql.ast.NullIfExpression;
Expand All @@ -48,9 +49,6 @@ public class ExpressionRewriter<C> {
protected Expression rewriteExpression(
Expression node, C context, ExpressionTreeRewriter<C> treeRewriter) {
return null;
// throw new IllegalStateException(
// String.format("%s is not supported in ExpressionRewriter yet",
// node.getClass().getName()));
}

public Expression rewriteFieldReference(
Expand Down Expand Up @@ -151,6 +149,11 @@ public Expression rewriteLikePredicate(
return rewriteExpression(node, context, treeRewriter);
}

public Expression rewriteLiteral(
Literal node, C context, ExpressionTreeRewriter<C> treeRewriter) {
return rewriteExpression(node, context, treeRewriter);
}

public Expression rewriteInPredicate(
InPredicate node, C context, ExpressionTreeRewriter<C> treeRewriter) {
return rewriteExpression(node, context, treeRewriter);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,14 @@ protected Expression visitIdentifier(Identifier node, Context<C> context) {

@Override
protected Expression visitLiteral(Literal node, Context<C> context) {
if (!context.isDefaultRewrite()) {
Expression result =
rewriter.rewriteLiteral(node, context.get(), ExpressionTreeRewriter.this);
if (result != null) {
return result;
}
}

return node;
}
}
Expand Down