Skip to content
Closed
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 @@ -182,7 +182,7 @@ private static Expression replace(

private static void collectConst(Expression expr, Map<String, Expression> constMap,
Map<String, TExpr> tExprMap, IdGenerator<ExprId> idGenerator) {
if (expr.isConstant() && !shouldSkipFold(expr)) {
if (expr.isConstant() && !expr.isLiteral() && !expr.anyMatch(e -> shouldSkipFold((Expression) e))) {
String id = idGenerator.getNextId().toString();
constMap.put(id, expr);
Expr staleExpr;
Expand All @@ -208,11 +208,6 @@ private static void collectConst(Expression expr, Map<String, Expression> constM

// Some expressions should not do constant folding
private static boolean shouldSkipFold(Expression expr) {
// Skip literal expr
if (expr.isLiteral()) {
return true;
}

// Frontend can not represent those types
if (expr.getDataType().isAggStateType() || expr.getDataType().isObjectType()
|| expr.getDataType().isVariantType() || expr.getDataType().isTimeLikeType()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,32 @@
import org.apache.doris.analysis.IntLiteral;
import org.apache.doris.catalog.Function.NullableMode;
import org.apache.doris.catalog.Type;
import org.apache.doris.common.AnalysisException;
import org.apache.doris.nereids.exceptions.AnalysisException;
import org.apache.doris.nereids.trees.expressions.BitNot;
import org.apache.doris.nereids.trees.expressions.MatchAny;
import org.apache.doris.nereids.trees.expressions.literal.IntegerLiteral;
import org.apache.doris.nereids.trees.expressions.literal.NullLiteral;
import org.apache.doris.nereids.trees.expressions.literal.VarcharLiteral;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

public class ExpressionTranslatorTest {

@Test
public void testUnaryArithmetic() throws AnalysisException {
public void testUnaryArithmetic() throws Exception {
BitNot bitNot = new BitNot(new IntegerLiteral(1));
ExpressionTranslator translator = ExpressionTranslator.INSTANCE;
Expr actual = translator.visitUnaryArithmetic(bitNot, null);
Expr expected = new ArithmeticExpr(Operator.BITNOT,
new IntLiteral(1, Type.INT), null, Type.INT, NullableMode.DEPEND_ON_ARGUMENT);
Assertions.assertEquals(actual, expected);
}

@Test
public void testMatch() {
MatchAny matchAny = new MatchAny(new VarcharLiteral("collections"), new NullLiteral());
ExpressionTranslator translator = ExpressionTranslator.INSTANCE;
Assertions.assertThrows(AnalysisException.class, () -> translator.visitMatch(matchAny, null));
}
}