[Feature](materialized-view) support some case unmached to materialized-view (#30036)
same column appears in key and value like select id,count(id) group by id; complex expr in sum select sum(if(xxx));
This commit is contained in:
@ -1066,6 +1066,11 @@ import_column_descs ::=
|
||||
columns.add(column);
|
||||
RESULT = columns;
|
||||
:}
|
||||
| import_column_descs:columns COMMA LPAREN import_column_desc:column RPAREN
|
||||
{:
|
||||
columns.add(column);
|
||||
RESULT = columns;
|
||||
:}
|
||||
;
|
||||
|
||||
import_column_desc ::=
|
||||
|
||||
@ -159,6 +159,7 @@ public class BinaryPredicate extends Predicate implements Writable {
|
||||
// for restoring
|
||||
public BinaryPredicate() {
|
||||
super();
|
||||
printSqlInParens = true;
|
||||
}
|
||||
|
||||
public BinaryPredicate(Operator op, Expr e1, Expr e2) {
|
||||
@ -169,6 +170,7 @@ public class BinaryPredicate extends Predicate implements Writable {
|
||||
children.add(e1);
|
||||
Preconditions.checkNotNull(e2);
|
||||
children.add(e2);
|
||||
printSqlInParens = true;
|
||||
}
|
||||
|
||||
public BinaryPredicate(Operator op, Expr e1, Expr e2, Type retType, NullableMode nullableMode) {
|
||||
@ -181,6 +183,7 @@ public class BinaryPredicate extends Predicate implements Writable {
|
||||
children.add(e2);
|
||||
fn = new Function(new FunctionName(op.name), Lists.newArrayList(e1.getType(), e2.getType()), retType,
|
||||
false, true, nullableMode);
|
||||
printSqlInParens = true;
|
||||
}
|
||||
|
||||
protected BinaryPredicate(BinaryPredicate other) {
|
||||
@ -188,6 +191,7 @@ public class BinaryPredicate extends Predicate implements Writable {
|
||||
op = other.op;
|
||||
slotIsleft = other.slotIsleft;
|
||||
isInferred = other.isInferred;
|
||||
printSqlInParens = true;
|
||||
}
|
||||
|
||||
public boolean isInferred() {
|
||||
|
||||
@ -1103,7 +1103,7 @@ public class SelectMaterializedIndexWithAggregate extends AbstractSelectMaterial
|
||||
}
|
||||
if (isInputSlotsContainsNone(
|
||||
predicates.stream().filter(e -> !indexConjuncts.contains(e.toSql())).collect(Collectors.toList()),
|
||||
slotsToReplace) && isInputSlotsContainsNone(groupingExprs, slotsToReplace)) {
|
||||
slotsToReplace)) {
|
||||
ImmutableSet<Slot> newRequiredSlots = requiredScanOutput.stream()
|
||||
.map(slot -> (Slot) ExpressionUtils.replace(slot, slotMap)).collect(ImmutableSet.toImmutableSet());
|
||||
return new AggRewriteResult(index, true, newRequiredSlots, exprRewriteMap);
|
||||
@ -1522,8 +1522,7 @@ public class SelectMaterializedIndexWithAggregate extends AbstractSelectMaterial
|
||||
if (result != sum) {
|
||||
return result;
|
||||
}
|
||||
Optional<Slot> slotOpt = ExpressionUtils.extractSlotOrCastOnSlot(sum.child(0));
|
||||
if (!sum.isDistinct() && slotOpt.isPresent()) {
|
||||
if (!sum.isDistinct()) {
|
||||
Expression expr = castIfNeed(sum.child(), BigIntType.INSTANCE);
|
||||
String sumColumn = normalizeName(CreateMaterializedViewStmt.mvColumnBuilder(AggregateType.SUM,
|
||||
CreateMaterializedViewStmt.mvColumnBuilder(expr.toSql())));
|
||||
@ -1532,7 +1531,9 @@ public class SelectMaterializedIndexWithAggregate extends AbstractSelectMaterial
|
||||
Slot sumSlot = context.checkContext.scan.getOutputByIndex(context.checkContext.index).stream()
|
||||
.filter(s -> sumColumn.equalsIgnoreCase(normalizeName(s.getName()))).findFirst()
|
||||
.orElseThrow(() -> new AnalysisException("cannot find sum slot when select mv"));
|
||||
context.exprRewriteMap.slotMap.put(slotOpt.get(), sumSlot);
|
||||
for (Slot slot : sum.child().getInputSlots()) {
|
||||
context.exprRewriteMap.slotMap.put(slot, sumSlot);
|
||||
}
|
||||
context.exprRewriteMap.projectExprMap.put(sum.child(), sumSlot);
|
||||
Sum newSum = new Sum(sumSlot);
|
||||
context.exprRewriteMap.aggFuncMap.put(sum, newSum);
|
||||
|
||||
@ -63,7 +63,7 @@ public class CancelExportStmtTest extends TestWithFeService {
|
||||
labelStringLiteral);
|
||||
CancelExportStmt stmt = new CancelExportStmt(null, labelBinaryPredicate);
|
||||
stmt.analyze(analyzer);
|
||||
Assertions.assertEquals("CANCEL EXPORT FROM testDb WHERE `label` = 'doris_test_label'",
|
||||
Assertions.assertEquals("CANCEL EXPORT FROM testDb WHERE (`label` = 'doris_test_label')",
|
||||
stmt.toString());
|
||||
|
||||
SlotRef labelSlotRefUpper = new SlotRef(null, "LABEL");
|
||||
@ -71,7 +71,7 @@ public class CancelExportStmtTest extends TestWithFeService {
|
||||
labelStringLiteral);
|
||||
CancelExportStmt stmtUpper = new CancelExportStmt(null, labelBinaryPredicateUpper);
|
||||
stmtUpper.analyze(analyzer);
|
||||
Assertions.assertEquals("CANCEL EXPORT FROM testDb WHERE `LABEL` = 'doris_test_label'",
|
||||
Assertions.assertEquals("CANCEL EXPORT FROM testDb WHERE (`LABEL` = 'doris_test_label')",
|
||||
stmtUpper.toString());
|
||||
|
||||
StringLiteral stateStringLiteral = new StringLiteral("PENDING");
|
||||
@ -79,7 +79,7 @@ public class CancelExportStmtTest extends TestWithFeService {
|
||||
stateStringLiteral);
|
||||
stmt = new CancelExportStmt(null, stateBinaryPredicate);
|
||||
stmt.analyze(analyzer);
|
||||
Assertions.assertEquals("CANCEL EXPORT FROM testDb WHERE `state` = 'PENDING'", stmt.toString());
|
||||
Assertions.assertEquals("CANCEL EXPORT FROM testDb WHERE (`state` = 'PENDING')", stmt.toString());
|
||||
|
||||
LikePredicate labelLikePredicate = new LikePredicate(LikePredicate.Operator.LIKE, labelSlotRef,
|
||||
labelStringLiteral);
|
||||
@ -93,7 +93,7 @@ public class CancelExportStmtTest extends TestWithFeService {
|
||||
stmt = new CancelExportStmt(null, compoundAndPredicate);
|
||||
stmt.analyze(analyzer);
|
||||
Assertions.assertEquals(
|
||||
"CANCEL EXPORT FROM testDb WHERE `label` = 'doris_test_label' AND `state` = 'PENDING'",
|
||||
"CANCEL EXPORT FROM testDb WHERE (`label` = 'doris_test_label') AND (`state` = 'PENDING')",
|
||||
stmt.toString());
|
||||
|
||||
CompoundPredicate compoundOrPredicate = new CompoundPredicate(Operator.OR, labelBinaryPredicate,
|
||||
@ -101,7 +101,7 @@ public class CancelExportStmtTest extends TestWithFeService {
|
||||
stmt = new CancelExportStmt(null, compoundOrPredicate);
|
||||
stmt.analyze(analyzer);
|
||||
Assertions.assertEquals(
|
||||
"CANCEL EXPORT FROM testDb WHERE `label` = 'doris_test_label' OR `state` = 'PENDING'",
|
||||
"CANCEL EXPORT FROM testDb WHERE (`label` = 'doris_test_label') OR (`state` = 'PENDING')",
|
||||
stmt.toString());
|
||||
}
|
||||
|
||||
|
||||
@ -64,7 +64,7 @@ public class CancelLoadStmtTest extends TestWithFeService {
|
||||
labelStringLiteral);
|
||||
CancelLoadStmt stmt = new CancelLoadStmt(null, labelBinaryPredicate);
|
||||
stmt.analyze(analyzer);
|
||||
Assertions.assertEquals("CANCEL LOAD FROM testDb WHERE `label` = 'doris_test_label'",
|
||||
Assertions.assertEquals("CANCEL LOAD FROM testDb WHERE (`label` = 'doris_test_label')",
|
||||
stmt.toString());
|
||||
|
||||
SlotRef labelSlotRefUpper = new SlotRef(null, "LABEL");
|
||||
@ -72,7 +72,7 @@ public class CancelLoadStmtTest extends TestWithFeService {
|
||||
labelStringLiteral);
|
||||
CancelLoadStmt stmtUpper = new CancelLoadStmt(null, labelBinaryPredicateUpper);
|
||||
stmtUpper.analyze(analyzer);
|
||||
Assertions.assertEquals("CANCEL LOAD FROM testDb WHERE `LABEL` = 'doris_test_label'",
|
||||
Assertions.assertEquals("CANCEL LOAD FROM testDb WHERE (`LABEL` = 'doris_test_label')",
|
||||
stmtUpper.toString());
|
||||
|
||||
StringLiteral stateStringLiteral = new StringLiteral("LOADING");
|
||||
@ -80,7 +80,7 @@ public class CancelLoadStmtTest extends TestWithFeService {
|
||||
stateStringLiteral);
|
||||
stmt = new CancelLoadStmt(null, stateBinaryPredicate);
|
||||
stmt.analyze(analyzer);
|
||||
Assertions.assertEquals("CANCEL LOAD FROM testDb WHERE `state` = 'LOADING'", stmt.toString());
|
||||
Assertions.assertEquals("CANCEL LOAD FROM testDb WHERE (`state` = 'LOADING')", stmt.toString());
|
||||
|
||||
LikePredicate labelLikePredicate = new LikePredicate(LikePredicate.Operator.LIKE, labelSlotRef,
|
||||
labelStringLiteral);
|
||||
@ -94,7 +94,7 @@ public class CancelLoadStmtTest extends TestWithFeService {
|
||||
stmt = new CancelLoadStmt(null, compoundAndPredicate);
|
||||
stmt.analyze(analyzer);
|
||||
Assertions.assertEquals(
|
||||
"CANCEL LOAD FROM testDb WHERE `label` = 'doris_test_label' AND `state` = 'LOADING'",
|
||||
"CANCEL LOAD FROM testDb WHERE (`label` = 'doris_test_label') AND (`state` = 'LOADING')",
|
||||
stmt.toString());
|
||||
|
||||
CompoundPredicate compoundOrPredicate = new CompoundPredicate(Operator.OR, labelBinaryPredicate,
|
||||
@ -102,7 +102,7 @@ public class CancelLoadStmtTest extends TestWithFeService {
|
||||
stmt = new CancelLoadStmt(null, compoundOrPredicate);
|
||||
stmt.analyze(analyzer);
|
||||
Assertions.assertEquals(
|
||||
"CANCEL LOAD FROM testDb WHERE `label` = 'doris_test_label' OR `state` = 'LOADING'",
|
||||
"CANCEL LOAD FROM testDb WHERE (`label` = 'doris_test_label') OR (`state` = 'LOADING')",
|
||||
stmt.toString());
|
||||
|
||||
// test match
|
||||
|
||||
@ -127,9 +127,9 @@ public class DataDescriptionTest {
|
||||
desc = new DataDescription("testTable", null, Lists.newArrayList("abc.txt"),
|
||||
Lists.newArrayList("col1", "col2"), new Separator(","), "csv", null, false, null, null, whereExpr, LoadTask.MergeType.MERGE, whereExpr, null, null);
|
||||
desc.analyze("testDb");
|
||||
Assert.assertEquals("MERGE DATA INFILE ('abc.txt') INTO TABLE testTable COLUMNS TERMINATED BY ',' FORMAT AS 'csv' (col1, col2) WHERE 1 = 1 DELETE ON 1 = 1", desc.toString());
|
||||
Assert.assertEquals("1 = 1", desc.getWhereExpr().toSql());
|
||||
Assert.assertEquals("1 = 1", desc.getDeleteCondition().toSql());
|
||||
Assert.assertEquals("MERGE DATA INFILE ('abc.txt') INTO TABLE testTable COLUMNS TERMINATED BY ',' FORMAT AS 'csv' (col1, col2) WHERE (1 = 1) DELETE ON (1 = 1)", desc.toString());
|
||||
Assert.assertEquals("(1 = 1)", desc.getWhereExpr().toSql());
|
||||
Assert.assertEquals("(1 = 1)", desc.getDeleteCondition().toSql());
|
||||
Assert.assertEquals(",", desc.getColumnSeparator());
|
||||
|
||||
desc = new DataDescription("testTable", null, Lists.newArrayList("abc.txt", "bcd.txt"),
|
||||
@ -168,7 +168,7 @@ public class DataDescriptionTest {
|
||||
.newArrayList((Expr) predicate));
|
||||
desc.analyze("testDb");
|
||||
String sql = "APPEND DATA INFILE ('abc.txt') INTO TABLE testTable PARTITIONS (p1, p2) (k2, k3)"
|
||||
+ " SET (`k1` = alignment_timestamp('day', `k2`))";
|
||||
+ " SET ((`k1` = alignment_timestamp('day', `k2`)))";
|
||||
Assert.assertEquals(sql, desc.toString());
|
||||
|
||||
// replace_value func
|
||||
@ -183,7 +183,7 @@ public class DataDescriptionTest {
|
||||
false, Lists.newArrayList((Expr) predicate));
|
||||
desc.analyze("testDb");
|
||||
sql = "APPEND DATA INFILE ('abc.txt') INTO TABLE testTable PARTITIONS (p1, p2) (k2, k3)"
|
||||
+ " SET (`k1` = replace_value('-', '10'))";
|
||||
+ " SET ((`k1` = replace_value('-', '10')))";
|
||||
Assert.assertEquals(sql, desc.toString());
|
||||
|
||||
// replace_value null
|
||||
@ -198,7 +198,7 @@ public class DataDescriptionTest {
|
||||
.newArrayList((Expr) predicate));
|
||||
desc.analyze("testDb");
|
||||
sql = "APPEND DATA INFILE ('abc.txt') INTO TABLE testTable PARTITIONS (p1, p2) (k2, k3)"
|
||||
+ " SET (`k1` = replace_value('', NULL))";
|
||||
+ " SET ((`k1` = replace_value('', NULL)))";
|
||||
Assert.assertEquals(sql, desc.toString());
|
||||
|
||||
// data from table and set bitmap_dict
|
||||
@ -210,7 +210,7 @@ public class DataDescriptionTest {
|
||||
"testHiveTable", false, Lists.newArrayList(predicate),
|
||||
null, LoadTask.MergeType.APPEND, null, null);
|
||||
desc.analyze("testDb");
|
||||
sql = "APPEND DATA FROM TABLE testHiveTable INTO TABLE testTable PARTITIONS (p1, p2) SET (`k1` = bitmap_dict(`k2`))";
|
||||
sql = "APPEND DATA FROM TABLE testHiveTable INTO TABLE testTable PARTITIONS (p1, p2) SET ((`k1` = bitmap_dict(`k2`)))";
|
||||
Assert.assertEquals(sql, desc.toSql());
|
||||
|
||||
Map<String, String> properties = Maps.newHashMap();
|
||||
@ -409,7 +409,7 @@ public class DataDescriptionTest {
|
||||
+ "COLUMNS TERMINATED BY '010203' "
|
||||
+ "LINES TERMINATED BY '040506' "
|
||||
+ "(k1, k2, v1) "
|
||||
+ "SET (`k1` = bitmap_dict('day', `k2`))";
|
||||
+ "SET ((`k1` = bitmap_dict('day', `k2`)))";
|
||||
Assert.assertEquals(sql, desc.toSql());
|
||||
}
|
||||
|
||||
|
||||
@ -60,11 +60,11 @@ public class DeleteStmtTest {
|
||||
Assert.assertEquals("testDb", deleteStmt.getDbName());
|
||||
Assert.assertEquals("testTbl", deleteStmt.getTableName());
|
||||
Assert.assertEquals(Lists.newArrayList("partition"), deleteStmt.getPartitionNames());
|
||||
Assert.assertEquals("DELETE FROM `testDb`.`testTbl` PARTITION (partition) WHERE `k1` = 'abc'",
|
||||
Assert.assertEquals("DELETE FROM `testDb`.`testTbl` PARTITION (partition) WHERE (`k1` = 'abc')",
|
||||
deleteStmt.toSql());
|
||||
|
||||
deleteStmt = new DeleteStmt(new TableName(internalCtl, "testDb", "testTbl"), null, wherePredicate);
|
||||
Assert.assertEquals("DELETE FROM `testDb`.`testTbl` WHERE `k1` = 'abc'",
|
||||
Assert.assertEquals("DELETE FROM `testDb`.`testTbl` WHERE (`k1` = 'abc')",
|
||||
deleteStmt.toSql());
|
||||
}
|
||||
|
||||
|
||||
@ -301,9 +301,9 @@ public class SelectStmtTest {
|
||||
String commonExpr2 = "`t3`.`k3` = `t1`.`k3`";
|
||||
String commonExpr3 = "`t1`.`k1` = `t5`.`k1`";
|
||||
String commonExpr4 = "t5`.`k2` = 'United States'";
|
||||
String betweenExpanded1 = "CAST(CAST(`t1`.`k4` AS DECIMALV3(12, 2)) AS INT) >= 100 AND CAST(CAST(`t1`.`k4` AS DECIMALV3(12, 2)) AS INT) <= 150";
|
||||
String betweenExpanded2 = "CAST(CAST(`t1`.`k4` AS DECIMALV3(12, 2)) AS INT) >= 50 AND CAST(CAST(`t1`.`k4` AS DECIMALV3(12, 2)) AS INT) <= 100";
|
||||
String betweenExpanded3 = "`t1`.`k4` >= 50 AND `t1`.`k4` <= 250";
|
||||
String betweenExpanded1 = "(CAST(CAST(`t1`.`k4` AS DECIMALV3(12, 2)) AS INT) >= 100) AND (CAST(CAST(`t1`.`k4` AS DECIMALV3(12, 2)) AS INT) <= 150)";
|
||||
String betweenExpanded2 = "(CAST(CAST(`t1`.`k4` AS DECIMALV3(12, 2)) AS INT) >= 50) AND (CAST(CAST(`t1`.`k4` AS DECIMALV3(12, 2)) AS INT) <= 100)";
|
||||
String betweenExpanded3 = "(`t1`.`k4` >= 50) AND (`t1`.`k4` <= 250)";
|
||||
|
||||
String rewrittenSql = stmt.toSql();
|
||||
Assert.assertTrue(rewrittenSql.contains(commonExpr1));
|
||||
@ -347,17 +347,17 @@ public class SelectStmtTest {
|
||||
SelectStmt stmt2 = (SelectStmt) UtFrameUtils.parseAndAnalyzeStmt(sql2, ctx);
|
||||
stmt2.rewriteExprs(new Analyzer(ctx.getEnv(), ctx).getExprRewriter());
|
||||
String fragment3 =
|
||||
"(((`t1`.`k4` >= 50 AND `t1`.`k4` <= 300) AND `t2`.`k2` IN ('United States', 'United States1') "
|
||||
"((((`t1`.`k4` >= 50) AND (`t1`.`k4` <= 300)) AND `t2`.`k2` IN ('United States', 'United States1') "
|
||||
+ "AND `t2`.`k3` IN ('CO', 'IL', 'MN', 'OH', 'MT', 'NM', 'TX', 'MO', 'MI')) "
|
||||
+ "AND `t1`.`k1` = `t2`.`k3` AND `t2`.`k2` = 'United States' "
|
||||
+ "AND `t2`.`k3` IN ('CO', 'IL', 'MN') AND `t1`.`k4` >= 100 AND `t1`.`k4` <= 200 "
|
||||
+ "AND (`t1`.`k1` = `t2`.`k3`) AND (`t2`.`k2` = 'United States') "
|
||||
+ "AND `t2`.`k3` IN ('CO', 'IL', 'MN') AND (`t1`.`k4` >= 100) AND (`t1`.`k4` <= 200) "
|
||||
+ "OR "
|
||||
+ "`t1`.`k1` = `t2`.`k1` AND `t2`.`k2` = 'United States1' "
|
||||
+ "AND `t2`.`k3` IN ('OH', 'MT', 'NM') AND `t1`.`k4` >= 150 AND `t1`.`k4` <= 300 "
|
||||
+ "(`t1`.`k1` = `t2`.`k1`) AND (`t2`.`k2` = 'United States1') "
|
||||
+ "AND `t2`.`k3` IN ('OH', 'MT', 'NM') AND (`t1`.`k4` >= 150) AND (`t1`.`k4` <= 300) "
|
||||
+ "OR "
|
||||
+ "`t1`.`k1` = `t2`.`k1` AND `t2`.`k2` = 'United States' "
|
||||
+ "(`t1`.`k1` = `t2`.`k1`) AND (`t2`.`k2` = 'United States') "
|
||||
+ "AND `t2`.`k3` IN ('TX', 'MO', 'MI') "
|
||||
+ "AND `t1`.`k4` >= 50 AND `t1`.`k4` <= 250)";
|
||||
+ "AND (`t1`.`k4` >= 50) AND (`t1`.`k4` <= 250))";
|
||||
Assert.assertTrue(stmt2.toSql().contains(fragment3));
|
||||
|
||||
String sql3 = "select\n"
|
||||
@ -370,7 +370,7 @@ public class SelectStmtTest {
|
||||
SelectStmt stmt3 = (SelectStmt) UtFrameUtils.parseAndAnalyzeStmt(sql3, ctx);
|
||||
stmt3.rewriteExprs(new Analyzer(ctx.getEnv(), ctx).getExprRewriter());
|
||||
Assert.assertFalse(
|
||||
stmt3.toSql().contains("`t1`.`k1` = `t2`.`k3` OR `t1`.`k1` = `t2`.`k3` OR" + " `t1`.`k1` = `t2`.`k3`"));
|
||||
stmt3.toSql().contains("(`t1`.`k1` = `t2`.`k3`) OR (`t1`.`k1` = `t2`.`k3`) OR" + " (`t1`.`k1` = `t2`.`k3`)"));
|
||||
|
||||
String sql4 = "select\n"
|
||||
+ " avg(t1.k4)\n"
|
||||
@ -381,7 +381,7 @@ public class SelectStmtTest {
|
||||
+ " t1.k1 = t2.k2 or t1.k1 = t2.k3 or t1.k1 = t2.k3";
|
||||
SelectStmt stmt4 = (SelectStmt) UtFrameUtils.parseAndAnalyzeStmt(sql4, ctx);
|
||||
stmt4.rewriteExprs(new Analyzer(ctx.getEnv(), ctx).getExprRewriter());
|
||||
Assert.assertTrue(stmt4.toSql().contains("`t1`.`k1` = `t2`.`k2` OR `t1`.`k1` = `t2`.`k3`"));
|
||||
Assert.assertTrue(stmt4.toSql().contains("(`t1`.`k1` = `t2`.`k2`) OR (`t1`.`k1` = `t2`.`k3`)"));
|
||||
|
||||
String sql5 = "select\n"
|
||||
+ " avg(t1.k4)\n"
|
||||
@ -435,7 +435,7 @@ public class SelectStmtTest {
|
||||
SelectStmt stmt9 = (SelectStmt) UtFrameUtils.parseAndAnalyzeStmt(sql9, ctx);
|
||||
stmt9.rewriteExprs(new Analyzer(ctx.getEnv(), ctx).getExprRewriter());
|
||||
Assert.assertTrue(
|
||||
stmt9.toSql().contains("`k1` = 'shutdown' AND `k4` < 1 OR `k1` = 'switchOff' AND `k4` >= 1"));
|
||||
stmt9.toSql().contains("(`k1` = 'shutdown') AND (`k4` < 1) OR (`k1` = 'switchOff') AND (`k4` >= 1)"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -528,21 +528,21 @@ public class SelectStmtTest {
|
||||
String sql1 = "SELECT /*+ SET_VAR(enable_nereids_planner=true, ENABLE_FALLBACK_TO_ORIGINAL_PLANNER=false) */ * FROM db1.table1 LEFT ANTI JOIN db1.table2 ON db1.table1.siteid = db1.table2.siteid;";
|
||||
String explain = dorisAssert.query(sql1).explainQuery();
|
||||
Assert.assertTrue(explain
|
||||
.contains("PREDICATES: __DORIS_DELETE_SIGN__ = 0"));
|
||||
.contains("__DORIS_DELETE_SIGN__ = 0"));
|
||||
Assert.assertFalse(explain.contains("other predicates:"));
|
||||
String sql2 = "SELECT /*+ SET_VAR(enable_nereids_planner=false) */ * FROM db1.table1 JOIN db1.table2 ON db1.table1.siteid = db1.table2.siteid;";
|
||||
explain = dorisAssert.query(sql2).explainQuery();
|
||||
Assert.assertTrue(explain
|
||||
.contains("PREDICATES: `db1`.`table1`.`__DORIS_DELETE_SIGN__` = 0"));
|
||||
.contains("`db1`.`table1`.`__DORIS_DELETE_SIGN__` = 0"));
|
||||
Assert.assertTrue(explain
|
||||
.contains("PREDICATES: `db1`.`table2`.`__DORIS_DELETE_SIGN__` = 0"));
|
||||
.contains("`db1`.`table2`.`__DORIS_DELETE_SIGN__` = 0"));
|
||||
Assert.assertFalse(explain.contains("other predicates:"));
|
||||
String sql3 = "SELECT /*+ SET_VAR(enable_nereids_planner=false) */ * FROM db1.table1";
|
||||
Assert.assertTrue(dorisAssert.query(sql3).explainQuery()
|
||||
.contains("PREDICATES: `db1`.`table1`.`__DORIS_DELETE_SIGN__` = 0"));
|
||||
.contains("`db1`.`table1`.`__DORIS_DELETE_SIGN__` = 0"));
|
||||
String sql4 = " SELECT /*+ SET_VAR(enable_nereids_planner=false) */ * FROM db1.table1 table2";
|
||||
Assert.assertTrue(dorisAssert.query(sql4).explainQuery()
|
||||
.contains("PREDICATES: `table2`.`__DORIS_DELETE_SIGN__` = 0"));
|
||||
.contains("`table2`.`__DORIS_DELETE_SIGN__` = 0"));
|
||||
new MockUp<Util>() {
|
||||
@Mock
|
||||
public boolean showHiddenColumns() {
|
||||
|
||||
@ -78,7 +78,7 @@ public class ShowAlterStmtTest {
|
||||
ShowAlterStmt stmt = new ShowAlterStmt(ShowAlterStmt.AlterType.COLUMN, null, binaryPredicate, null,
|
||||
new LimitElement(1, 2));
|
||||
stmt.analyzeSyntax(analyzer);
|
||||
Assert.assertEquals("SHOW ALTER TABLE COLUMN FROM `testDb` WHERE `TableName` = \'abc\' LIMIT 1, 2",
|
||||
Assert.assertEquals("SHOW ALTER TABLE COLUMN FROM `testDb` WHERE (`TableName` = \'abc\') LIMIT 1, 2",
|
||||
stmt.toString());
|
||||
}
|
||||
|
||||
@ -89,7 +89,7 @@ public class ShowAlterStmtTest {
|
||||
BinaryPredicate binaryPredicate = new BinaryPredicate(Operator.EQ, slotRef, stringLiteral);
|
||||
ShowAlterStmt stmt = new ShowAlterStmt(ShowAlterStmt.AlterType.COLUMN, null, binaryPredicate, null, null);
|
||||
stmt.analyzeSyntax(analyzer);
|
||||
Assert.assertEquals("SHOW ALTER TABLE COLUMN FROM `testDb` WHERE `CreateTime` = \'2019-12-04 00:00:00\'",
|
||||
Assert.assertEquals("SHOW ALTER TABLE COLUMN FROM `testDb` WHERE (`CreateTime` = \'2019-12-04 00:00:00\')",
|
||||
stmt.toString());
|
||||
}
|
||||
}
|
||||
|
||||
@ -78,7 +78,7 @@ public class ShowBackupStmtTest {
|
||||
new BinaryPredicate(BinaryPredicate.Operator.EQ, new SlotRef(new TableName("a.b.c"), "snapshotname"),
|
||||
new StringLiteral("FINISHED")));
|
||||
stmt.analyze(analyzer);
|
||||
Assertions.assertEquals(stmt.toSql(), "SHOW BACKUP WHERE `a`.`b`.`c`.`snapshotname` = 'FINISHED'");
|
||||
Assertions.assertEquals(stmt.toSql(), "SHOW BACKUP WHERE (`a`.`b`.`c`.`snapshotname` = 'FINISHED')");
|
||||
|
||||
stmt = new ShowBackupStmt("",
|
||||
new LikePredicate(Operator.LIKE, new SlotRef(new TableName("a.b.c"), "snapshotname"),
|
||||
|
||||
@ -53,7 +53,7 @@ public class ShowExportStmtTest {
|
||||
|
||||
stmt = new ShowExportStmt(null, binaryPredicate, null, new LimitElement(10));
|
||||
stmt.analyze(analyzer);
|
||||
Assert.assertEquals("SHOW EXPORT FROM `testDb` WHERE `label` = 'abc' LIMIT 10", stmt.toString());
|
||||
Assert.assertEquals("SHOW EXPORT FROM `testDb` WHERE (`label` = 'abc') LIMIT 10", stmt.toString());
|
||||
Assert.assertFalse(stmt.isLabelUseLike());
|
||||
|
||||
StringLiteral stringLiteralLike = new StringLiteral("ab%");
|
||||
@ -67,7 +67,7 @@ public class ShowExportStmtTest {
|
||||
BinaryPredicate statePredicate = new BinaryPredicate(Operator.EQ, new SlotRef(null, "state"), new StringLiteral("PENDING"));
|
||||
stmt = new ShowExportStmt(null, statePredicate, null, new LimitElement(10));
|
||||
stmt.analyze(analyzer);
|
||||
Assert.assertEquals("SHOW EXPORT FROM `testDb` WHERE `state` = 'PENDING' LIMIT 10", stmt.toString());
|
||||
Assert.assertEquals("SHOW EXPORT FROM `testDb` WHERE (`state` = 'PENDING') LIMIT 10", stmt.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@ -99,7 +99,7 @@ public class ShowLoadStmtTest {
|
||||
BinaryPredicate binaryPredicate = new BinaryPredicate(Operator.EQ, slotRef, stringLiteral);
|
||||
stmt = new ShowLoadStmt(null, binaryPredicate, null, new LimitElement(10));
|
||||
stmt.analyze(analyzer);
|
||||
Assert.assertEquals("SHOW LOAD FROM `testDb` WHERE `label` = \'abc\' LIMIT 10", stmt.toString());
|
||||
Assert.assertEquals("SHOW LOAD FROM `testDb` WHERE (`label` = \'abc\') LIMIT 10", stmt.toString());
|
||||
|
||||
StringLiteral stringLiteralLike = new StringLiteral("ab%");
|
||||
LikePredicate likePredicate = new LikePredicate(LikePredicate.Operator.LIKE, slotRef, stringLiteralLike);
|
||||
@ -111,7 +111,7 @@ public class ShowLoadStmtTest {
|
||||
BinaryPredicate statePredicate = new BinaryPredicate(Operator.EQ, new SlotRef(null, "state"), new StringLiteral("PENDING"));
|
||||
stmt = new ShowLoadStmt(null, statePredicate, null, new LimitElement(10));
|
||||
stmt.analyze(analyzer);
|
||||
Assert.assertEquals("SHOW LOAD FROM `testDb` WHERE `state` = \'PENDING\' LIMIT 10", stmt.toString());
|
||||
Assert.assertEquals("SHOW LOAD FROM `testDb` WHERE (`state` = \'PENDING\') LIMIT 10", stmt.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@ -100,7 +100,7 @@ public class ShowPartitionsStmtTest {
|
||||
BinaryPredicate binaryPredicate = new BinaryPredicate(BinaryPredicate.Operator.GT, slotRef, stringLiteral);
|
||||
ShowPartitionsStmt stmt = new ShowPartitionsStmt(new TableName(internalCtl, "testDb", "testTable"), binaryPredicate, null, null, false);
|
||||
stmt.analyzeImpl(analyzer);
|
||||
Assert.assertEquals("SHOW PARTITIONS FROM `testDb`.`testTable` WHERE `LastConsistencyCheckTime` > '2019-12-22 10:22:11'", stmt.toString());
|
||||
Assert.assertEquals("SHOW PARTITIONS FROM `testDb`.`testTable` WHERE (`LastConsistencyCheckTime` > '2019-12-22 10:22:11')", stmt.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -259,7 +259,7 @@ public class ShowPartitionsStmtTest {
|
||||
ShowPartitionsStmt stmt = new ShowPartitionsStmt(new TableName("hms", "hms", "testTable"),
|
||||
binaryPredicate, null, null, false);
|
||||
Assertions.assertEquals(stmt.toSql(), "SHOW PARTITIONS FROM `hms`.`testTable` "
|
||||
+ "WHERE `PartitionName` = 'part=part1'");
|
||||
+ "WHERE (`PartitionName` = 'part=part1')");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -67,7 +67,7 @@ public class ShowResourcesStmtTest {
|
||||
BinaryPredicate binaryPredicate = new BinaryPredicate(Operator.EQ, slotRef, stringLiteral);
|
||||
stmt = new ShowResourcesStmt(binaryPredicate, null, new LimitElement(10));
|
||||
stmt.analyze(analyzer);
|
||||
Assert.assertEquals("SHOW RESOURCES WHERE `name` = \'abc\' LIMIT 10", stmt.toString());
|
||||
Assert.assertEquals("SHOW RESOURCES WHERE (`name` = \'abc\') LIMIT 10", stmt.toString());
|
||||
|
||||
LikePredicate likePredicate = new LikePredicate(org.apache.doris.analysis.LikePredicate.Operator.LIKE,
|
||||
slotRef, stringLiteral);
|
||||
|
||||
@ -41,7 +41,7 @@ public class SqlModeTest {
|
||||
} catch (Exception e) {
|
||||
Assert.fail(e.getMessage());
|
||||
}
|
||||
Assert.assertEquals("SELECT * FROM `db1`.`tbl1` WHERE `name` = 'BILL GATES'", selectStmt.toSql());
|
||||
Assert.assertEquals("SELECT * FROM `db1`.`tbl1` WHERE (`name` = 'BILL GATES')", selectStmt.toSql());
|
||||
|
||||
parser = new SqlParser(new SqlScanner(new StringReader(stmt), SqlModeHelper.MODE_DEFAULT));
|
||||
try {
|
||||
@ -49,7 +49,7 @@ public class SqlModeTest {
|
||||
} catch (Exception e) {
|
||||
Assert.fail(e.getMessage());
|
||||
}
|
||||
Assert.assertEquals("SELECT * FROM `db1`.`tbl1` WHERE `name` = 'BILL GATES'", selectStmt.toSql());
|
||||
Assert.assertEquals("SELECT * FROM `db1`.`tbl1` WHERE (`name` = 'BILL GATES')", selectStmt.toSql());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@ -185,7 +185,7 @@ public class CreateViewTest {
|
||||
alter1 = (View) db.getTableOrDdlException("alter1");
|
||||
Assert.assertEquals(
|
||||
"WITH test1_cte(w1, w2) AS (SELECT `k1`, `k2` FROM `test`.`tbl1`) "
|
||||
+ "SELECT `w1` AS `c1`, sum(`w2`) AS `c2` FROM `test1_cte` WHERE `w1` > 10 GROUP BY `w1` "
|
||||
+ "SELECT `w1` AS `c1`, sum(`w2`) AS `c2` FROM `test1_cte` WHERE (`w1` > 10) GROUP BY `w1` "
|
||||
+ "ORDER BY `w1` ASC NULLS FIRST",
|
||||
alter1.getInlineViewDef());
|
||||
}
|
||||
|
||||
@ -437,7 +437,7 @@ public class PlannerTest extends TestWithFeService {
|
||||
stmtExecutor.execute();
|
||||
Planner planner = stmtExecutor.planner();
|
||||
String plan = planner.getExplainString(new ExplainOptions(false, false, false));
|
||||
Assertions.assertTrue(plan.contains("PREDICATES: `k1` = 1\n"));
|
||||
Assertions.assertTrue(plan.contains("`k1` = 1"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -459,7 +459,7 @@ public class PlannerTest extends TestWithFeService {
|
||||
stmtExecutor.execute();
|
||||
Planner planner = stmtExecutor.planner();
|
||||
String plan = planner.getExplainString(new ExplainOptions(false, false, false));
|
||||
Assertions.assertTrue(plan.contains("PREDICATES: `k1` = 1 AND `k2` = 1\n"));
|
||||
Assertions.assertTrue(plan.contains("(`k1` = 1) AND (`k2` = 1)"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -471,7 +471,7 @@ public class PlannerTest extends TestWithFeService {
|
||||
stmtExecutor.execute();
|
||||
Planner planner = stmtExecutor.planner();
|
||||
String plan = planner.getExplainString(new ExplainOptions(false, false, false));
|
||||
Assertions.assertTrue(plan.contains("PREDICATES: `k1` = 1\n"));
|
||||
Assertions.assertTrue(plan.contains("`k1` = 1"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@ -493,7 +493,7 @@ public class QueryPlanTest extends TestWithFeService {
|
||||
|
||||
assertSQLPlanOrErrorMsgContains(
|
||||
"select count(*) from test.bitmap_table where id2 = 1;",
|
||||
"Unsupported bitmap type in expression: `id2` = 1"
|
||||
"Unsupported bitmap type in expression: (`id2` = 1)"
|
||||
);
|
||||
|
||||
}
|
||||
@ -547,7 +547,7 @@ public class QueryPlanTest extends TestWithFeService {
|
||||
|
||||
assertSQLPlanOrErrorMsgContains(
|
||||
"select count(*) from test.hll_table where id2 = 1",
|
||||
"Hll type dose not support operand: `id2` = 1"
|
||||
"Hll type dose not support operand: (`id2` = 1)"
|
||||
);
|
||||
}
|
||||
|
||||
@ -732,8 +732,8 @@ public class QueryPlanTest extends TestWithFeService {
|
||||
+ "left join join2 on join1.id = join2.id\n"
|
||||
+ "and join1.id > 1;";
|
||||
String explainString = getSQLPlanOrErrorMsg("explain " + sql);
|
||||
Assert.assertTrue(explainString.contains("other join predicates: <slot 12> <slot 0> > 1"));
|
||||
Assert.assertFalse(explainString.contains("PREDICATES: `join1`.`id` > 1"));
|
||||
Assert.assertTrue(explainString.contains("<slot 12> <slot 0> > 1"));
|
||||
Assert.assertFalse(explainString.contains("`join1`.`id` > 1"));
|
||||
|
||||
/*
|
||||
// test left join: right table where predicate.
|
||||
@ -752,8 +752,8 @@ public class QueryPlanTest extends TestWithFeService {
|
||||
+ "left join join2 on join1.id = join2.id\n"
|
||||
+ "and join2.id > 1;";
|
||||
explainString = getSQLPlanOrErrorMsg("explain " + sql);
|
||||
Assert.assertTrue(explainString.contains("PREDICATES: `join2`.`id` > 1"));
|
||||
Assert.assertFalse(explainString.contains("PREDICATES: `join1`.`id` > 1"));
|
||||
Assert.assertTrue(explainString.contains("`join2`.`id` > 1"));
|
||||
Assert.assertFalse(explainString.contains("`join1`.`id` > 1"));
|
||||
|
||||
/*
|
||||
// test inner join: left table where predicate, both push down left table and right table
|
||||
@ -770,8 +770,8 @@ public class QueryPlanTest extends TestWithFeService {
|
||||
+ "join join2 on join1.id = join2.id\n"
|
||||
+ "and join1.id > 1;";
|
||||
explainString = getSQLPlanOrErrorMsg("explain " + sql);
|
||||
Assert.assertTrue(explainString.contains("PREDICATES: `join1`.`id` > 1"));
|
||||
Assert.assertTrue(explainString.contains("PREDICATES: `join2`.`id` > 1"));
|
||||
Assert.assertTrue(explainString.contains("`join1`.`id` > 1"));
|
||||
Assert.assertTrue(explainString.contains("`join2`.`id` > 1"));
|
||||
|
||||
/*
|
||||
// test inner join: right table where predicate, both push down left table and right table
|
||||
@ -788,8 +788,8 @@ public class QueryPlanTest extends TestWithFeService {
|
||||
|
||||
+ "join join2 on join1.id = join2.id\n" + "and 1 < join2.id;";
|
||||
explainString = getSQLPlanOrErrorMsg("explain " + sql);
|
||||
Assert.assertTrue(explainString.contains("PREDICATES: `join1`.`id` > 1"));
|
||||
Assert.assertTrue(explainString.contains("PREDICATES: `join2`.`id` > 1"));
|
||||
Assert.assertTrue(explainString.contains("`join1`.`id` > 1"));
|
||||
Assert.assertTrue(explainString.contains("`join2`.`id` > 1"));
|
||||
|
||||
sql = "select /*+ SET_VAR(enable_nereids_planner=false) */ *\n from join1\n"
|
||||
+ "join join2 on join1.id = join2.value\n"
|
||||
@ -803,31 +803,31 @@ public class QueryPlanTest extends TestWithFeService {
|
||||
+ "left anti join join2 on join1.id = join2.id\n"
|
||||
+ "and join2.id > 1;";
|
||||
explainString = getSQLPlanOrErrorMsg("explain " + sql);
|
||||
Assert.assertTrue(explainString.contains("PREDICATES: `join2`.`id` > 1"));
|
||||
Assert.assertFalse(explainString.contains("PREDICATES: `join1`.`id` > 1"));
|
||||
Assert.assertTrue(explainString.contains("`join2`.`id` > 1"));
|
||||
Assert.assertFalse(explainString.contains("`join1`.`id` > 1"));
|
||||
|
||||
// test semi join, right table join predicate, only push to right table
|
||||
sql = "select /*+ SET_VAR(enable_nereids_planner=false) */ *\n from join1\n"
|
||||
+ "left semi join join2 on join1.id = join2.id\n"
|
||||
+ "and join2.id > 1;";
|
||||
explainString = getSQLPlanOrErrorMsg("explain " + sql);
|
||||
Assert.assertTrue(explainString.contains("PREDICATES: `join2`.`id` > 1"));
|
||||
Assert.assertTrue(explainString.contains("PREDICATES: `join1`.`id` > 1"));
|
||||
Assert.assertTrue(explainString.contains("`join2`.`id` > 1"));
|
||||
Assert.assertTrue(explainString.contains("`join1`.`id` > 1"));
|
||||
|
||||
// test anti join, left table join predicate, left table couldn't push down
|
||||
sql = "select /*+ SET_VAR(enable_nereids_planner=false) */ *\n from join1\n"
|
||||
+ "left anti join join2 on join1.id = join2.id\n"
|
||||
+ "and join1.id > 1;";
|
||||
explainString = getSQLPlanOrErrorMsg("explain " + sql);
|
||||
Assert.assertTrue(explainString.contains("other join predicates: <slot 7> <slot 0> > 1"));
|
||||
Assert.assertFalse(explainString.contains("PREDICATES: `join1`.`id` > 1"));
|
||||
Assert.assertTrue(explainString.contains("<slot 7> <slot 0> > 1"));
|
||||
Assert.assertFalse(explainString.contains("`join1`.`id` > 1"));
|
||||
|
||||
// test semi join, left table join predicate, only push to left table
|
||||
sql = "select /*+ SET_VAR(enable_nereids_planner=false) */ *\n from join1\n"
|
||||
+ "left semi join join2 on join1.id = join2.id\n"
|
||||
+ "and join1.id > 1;";
|
||||
explainString = getSQLPlanOrErrorMsg("explain " + sql);
|
||||
Assert.assertTrue(explainString.contains("PREDICATES: `join1`.`id` > 1"));
|
||||
Assert.assertTrue(explainString.contains("`join1`.`id` > 1"));
|
||||
|
||||
/*
|
||||
// test anti join, left table where predicate, only push to left table
|
||||
@ -1036,15 +1036,15 @@ public class QueryPlanTest extends TestWithFeService {
|
||||
public void testOrCompoundPredicateFold() throws Exception {
|
||||
String queryStr = "explain select /*+ SET_VAR(enable_nereids_planner=false) */ * from baseall where (k1 > 1) or (k1 > 1 and k2 < 1)";
|
||||
String explainString = getSQLPlanOrErrorMsg(queryStr);
|
||||
Assert.assertTrue(explainString.contains("PREDICATES: (`k1` > 1)\n"));
|
||||
Assert.assertTrue(explainString.contains("`k1` > 1"));
|
||||
|
||||
queryStr = "explain select /*+ SET_VAR(enable_nereids_planner=false) */ * from baseall where (k1 > 1 and k2 < 1) or (k1 > 1)";
|
||||
explainString = getSQLPlanOrErrorMsg(queryStr);
|
||||
Assert.assertTrue(explainString.contains("PREDICATES: `k1` > 1\n"));
|
||||
Assert.assertTrue(explainString.contains("`k1` > 1"));
|
||||
|
||||
queryStr = "explain select /*+ SET_VAR(enable_nereids_planner=false) */ * from baseall where (k1 > 1) or (k1 > 1)";
|
||||
explainString = getSQLPlanOrErrorMsg(queryStr);
|
||||
Assert.assertTrue(explainString.contains("PREDICATES: (`k1` > 1)\n"));
|
||||
Assert.assertTrue(explainString.contains("`k1` > 1"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -1677,7 +1677,7 @@ public class QueryPlanTest extends TestWithFeService {
|
||||
//default format
|
||||
String sql = "select /*+ SET_VAR(enable_nereids_planner=false) */ * from test1 where from_unixtime(query_time) > '2021-03-02 10:01:28'";
|
||||
String explainString = getSQLPlanOrErrorMsg("EXPLAIN " + sql);
|
||||
Assert.assertTrue(explainString.contains("PREDICATES: `query_time` <= 253402271999 AND `query_time` > 1614650488"));
|
||||
Assert.assertTrue(explainString.contains("(`query_time` <= 253402271999) AND (`query_time` > 1614650488)"));
|
||||
}
|
||||
|
||||
@Disabled
|
||||
@ -1811,7 +1811,7 @@ public class QueryPlanTest extends TestWithFeService {
|
||||
// false or e ==> e
|
||||
String sql1 = "select /*+ SET_VAR(enable_nereids_planner=false) */ * from test.test1 where 2=-2 OR query_time=0;";
|
||||
String explainString1 = getSQLPlanOrErrorMsg("EXPLAIN " + sql1);
|
||||
Assert.assertTrue(explainString1.contains("PREDICATES: `query_time` = 0"));
|
||||
Assert.assertTrue(explainString1.contains("`query_time` = 0"));
|
||||
|
||||
//true or e ==> true
|
||||
String sql2 = "select /*+ SET_VAR(enable_nereids_planner=false) */ * from test.test1 where -5=-5 OR query_time=0;";
|
||||
@ -1826,18 +1826,18 @@ public class QueryPlanTest extends TestWithFeService {
|
||||
//e or false ==> e
|
||||
String sql4 = "select /*+ SET_VAR(enable_nereids_planner=false) */ * from test.test1 where -5!=-5 OR query_time=0;";
|
||||
String explainString4 = getSQLPlanOrErrorMsg("EXPLAIN " + sql4);
|
||||
Assert.assertTrue(explainString4.contains("PREDICATES: `query_time` = 0"));
|
||||
Assert.assertTrue(explainString4.contains("`query_time` = 0"));
|
||||
|
||||
|
||||
// true and e ==> e
|
||||
String sql5 = "select /*+ SET_VAR(enable_nereids_planner=false) */ * from test.test1 where -5=-5 AND query_time=0;";
|
||||
String explainString5 = getSQLPlanOrErrorMsg("EXPLAIN " + sql5);
|
||||
Assert.assertTrue(explainString5.contains("PREDICATES: `query_time` = 0"));
|
||||
Assert.assertTrue(explainString5.contains("`query_time` = 0"));
|
||||
|
||||
// e and true ==> e
|
||||
String sql6 = "select /*+ SET_VAR(enable_nereids_planner=false) */ * from test.test1 where query_time=0 AND -5=-5;";
|
||||
String explainString6 = getSQLPlanOrErrorMsg("EXPLAIN " + sql6);
|
||||
Assert.assertTrue(explainString6.contains("PREDICATES: `query_time` = 0"));
|
||||
Assert.assertTrue(explainString6.contains("`query_time` = 0"));
|
||||
|
||||
// false and e ==> false
|
||||
String sql7 = "select /*+ SET_VAR(enable_nereids_planner=false) */ * from test.test1 where -5!=-5 AND query_time=0;";
|
||||
@ -1852,12 +1852,12 @@ public class QueryPlanTest extends TestWithFeService {
|
||||
// (false or expr1) and (false or expr2) ==> expr1 and expr2
|
||||
String sql9 = "select /*+ SET_VAR(enable_nereids_planner=false) */ * from test.test1 where (-2=2 or query_time=2) and (-2=2 or stmt_id=2);";
|
||||
String explainString9 = getSQLPlanOrErrorMsg("EXPLAIN " + sql9);
|
||||
Assert.assertTrue(explainString9.contains("PREDICATES: `query_time` = 2 AND `stmt_id` = 2"));
|
||||
Assert.assertTrue(explainString9.contains("(`query_time` = 2) AND (`stmt_id` = 2)"));
|
||||
|
||||
// false or (expr and true) ==> expr
|
||||
String sql10 = "select /*+ SET_VAR(enable_nereids_planner=false) */ * from test.test1 where (2=-2) OR (query_time=0 AND 1=1);";
|
||||
String explainString10 = getSQLPlanOrErrorMsg("EXPLAIN " + sql10);
|
||||
Assert.assertTrue(explainString10.contains("PREDICATES: `query_time` = 0"));
|
||||
Assert.assertTrue(explainString10.contains("`query_time` = 0"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -1885,11 +1885,11 @@ public class QueryPlanTest extends TestWithFeService {
|
||||
+ " \"max_file_size\" = \"500MB\" );";
|
||||
String explainStr = getSQLPlanOrErrorMsg("EXPLAIN " + sql);
|
||||
if (Config.enable_date_conversion) {
|
||||
Assert.assertTrue(explainStr.contains("PREDICATES: `date` >= '2021-10-07' AND"
|
||||
+ " `date` <= '2021-10-11'"));
|
||||
Assert.assertTrue(explainStr.contains("(`date` >= '2021-10-07') AND"
|
||||
+ " (`date` <= '2021-10-11')"));
|
||||
} else {
|
||||
Assert.assertTrue(explainStr.contains("PREDICATES: `date` >= '2021-10-07 00:00:00' AND"
|
||||
+ " `date` <= '2021-10-11 00:00:00'"));
|
||||
Assert.assertTrue(explainStr.contains("(`date` >= '2021-10-07 00:00:00') AND"
|
||||
+ " (`date` <= '2021-10-11 00:00:00')"));
|
||||
}
|
||||
}
|
||||
|
||||
@ -2237,7 +2237,7 @@ public class QueryPlanTest extends TestWithFeService {
|
||||
|
||||
sql = "SELECT /*+ SET_VAR(enable_nereids_planner=false) */ * from test1 where (query_time = 1 or query_time = 2 or scan_bytes = 2) and scan_bytes in (2, 3)";
|
||||
explainString = UtFrameUtils.getSQLPlanOrErrorMsg(connectContext, "EXPLAIN " + sql);
|
||||
Assert.assertTrue(explainString.contains("PREDICATES: `query_time` IN (1, 2) OR `scan_bytes` = 2 AND `scan_bytes` IN (2, 3)\n"));
|
||||
Assert.assertTrue(explainString.contains("PREDICATES: `query_time` IN (1, 2) OR (`scan_bytes` = 2) AND `scan_bytes` IN (2, 3)\n"));
|
||||
|
||||
sql = "SELECT /*+ SET_VAR(enable_nereids_planner=false) */ * from test1 where (query_time = 1 or query_time = 2) and (scan_bytes = 2 or scan_bytes = 3)";
|
||||
explainString = UtFrameUtils.getSQLPlanOrErrorMsg(connectContext, "EXPLAIN " + sql);
|
||||
@ -2254,7 +2254,7 @@ public class QueryPlanTest extends TestWithFeService {
|
||||
connectContext.getSessionVariable().setRewriteOrToInPredicateThreshold(100);
|
||||
sql = "SELECT /*+ SET_VAR(enable_nereids_planner=false) */ * from test1 where query_time = 1 or query_time = 2 or query_time in (3, 4)";
|
||||
explainString = UtFrameUtils.getSQLPlanOrErrorMsg(connectContext, "EXPLAIN " + sql);
|
||||
Assert.assertTrue(explainString.contains("PREDICATES: `query_time` = 1 OR `query_time` = 2 OR `query_time` IN (3, 4)\n"));
|
||||
Assert.assertTrue(explainString.contains("PREDICATES: (`query_time` = 1) OR (`query_time` = 2) OR `query_time` IN (3, 4)\n"));
|
||||
connectContext.getSessionVariable().setRewriteOrToInPredicateThreshold(2);
|
||||
|
||||
sql = "SELECT /*+ SET_VAR(enable_nereids_planner=false) */ * from test1 where (query_time = 1 or query_time = 2) and query_time in (3, 4)";
|
||||
@ -2264,7 +2264,7 @@ public class QueryPlanTest extends TestWithFeService {
|
||||
//test we can handle `!=` and `not in`
|
||||
sql = "select /*+ SET_VAR(enable_nereids_planner=false) */ * from test1 where (query_time = 1 or query_time = 2 or query_time!= 3 or query_time not in (5, 6))";
|
||||
explainString = UtFrameUtils.getSQLPlanOrErrorMsg(connectContext, "EXPLAIN " + sql);
|
||||
Assert.assertTrue(explainString.contains("PREDICATES: `query_time` IN (1, 2) OR `query_time` != 3 OR `query_time` NOT IN (5, 6)\n"));
|
||||
Assert.assertTrue(explainString.contains("PREDICATES: `query_time` IN (1, 2) OR (`query_time` != 3) OR `query_time` NOT IN (5, 6)\n"));
|
||||
|
||||
//test we can handle merge 2 or more columns
|
||||
sql = "select /*+ SET_VAR(enable_nereids_planner=false) */ * from test1 where (query_time = 1 or query_time = 2 or scan_rows = 3 or scan_rows = 4)";
|
||||
@ -2284,8 +2284,8 @@ public class QueryPlanTest extends TestWithFeService {
|
||||
+ " or (db not in ('x', 'y')) ";
|
||||
explainString = UtFrameUtils.getSQLPlanOrErrorMsg(connectContext, "EXPLAIN " + sql);
|
||||
Assert.assertTrue(explainString.contains(
|
||||
"PREDICATES: `query_id` = `client_ip` "
|
||||
+ "AND (`stmt_id` IN (1, 2, 3) OR `user` = 'abc' AND `state` IN ('a', 'b', 'c', 'd')) "
|
||||
"PREDICATES: (`query_id` = `client_ip`) "
|
||||
+ "AND (`stmt_id` IN (1, 2, 3) OR (`user` = 'abc') AND `state` IN ('a', 'b', 'c', 'd')) "
|
||||
+ "OR (`db` NOT IN ('x', 'y'))\n"));
|
||||
|
||||
//ExtractCommonFactorsRule may generate more expr, test the rewriteOrToIn applied on generated exprs
|
||||
@ -2293,7 +2293,7 @@ public class QueryPlanTest extends TestWithFeService {
|
||||
explainString = UtFrameUtils.getSQLPlanOrErrorMsg(connectContext, "EXPLAIN " + sql);
|
||||
Assert.assertTrue(explainString.contains(
|
||||
"PREDICATES: `state` IN ('a', 'b') AND `stmt_id` IN (1, 2) AND"
|
||||
+ " `stmt_id` = 1 AND `state` = 'a' OR `stmt_id` = 2 AND `state` = 'b'\n"
|
||||
+ " (`stmt_id` = 1) AND (`state` = 'a') OR (`stmt_id` = 2) AND (`state` = 'b')\n"
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
@ -62,7 +62,7 @@ public class RepeatNodeTest extends TestWithFeService {
|
||||
String explainString1 = getSQLPlanOrErrorMsg("explain " + sql1);
|
||||
System.out.println(explainString1);
|
||||
Assertions.assertTrue(explainString1.contains(
|
||||
"output slots: `if(`c`.`id` > 0, 1, 0)`, ``p`.`name``, ``c`.`cost``, ``GROUPING_ID``"));
|
||||
"output slots: `if((`c`.`id` > 0), 1, 0)`, ``p`.`name``, ``c`.`cost``, ``GROUPING_ID``"));
|
||||
|
||||
String sql2 = "select /*+ SET_VAR(enable_nereids_planner=false) */ (id + 1) id_, name, sum(cost) from mycost group by grouping sets((id_, name),());";
|
||||
String explainString2 = getSQLPlanOrErrorMsg("explain " + sql2);
|
||||
|
||||
@ -132,7 +132,7 @@ public class TableFunctionPlanTest {
|
||||
Assert.assertTrue(UtFrameUtils.checkPlanResultContainsNode(explainString, 1, "TABLE FUNCTION NODE"));
|
||||
Assert.assertTrue(
|
||||
explainString.contains("table function: explode_split(`db1`.`tbl1`.`k2`, ',')"));
|
||||
Assert.assertTrue(explainString.contains("PREDICATES: `e1` = '1'"));
|
||||
Assert.assertTrue(explainString.contains("`e1` = '1'"));
|
||||
Assert.assertTrue(explainString.contains("tuple ids: 0 1"));
|
||||
Assert.assertTrue(explainString.contains("TupleDescriptor{id=1, tbl=tmp, byteSize=32}"));
|
||||
Assert.assertTrue(explainString.contains("SlotDescriptor{id=1, col=e1, colUniqueId=-1, type=VARCHAR"));
|
||||
@ -153,7 +153,7 @@ public class TableFunctionPlanTest {
|
||||
Assert.assertTrue(explainString.contains("TupleDescriptor{id=1, tbl=tmp, byteSize=32}"));
|
||||
Assert.assertTrue(explainString.contains("SlotDescriptor{id=1, col=e1, colUniqueId=-1, type=VARCHAR"));
|
||||
Assert.assertTrue(UtFrameUtils.checkPlanResultContainsNode(explainString, 0, "OlapScanNode"));
|
||||
Assert.assertTrue(explainString.contains("PREDICATES: `k1` = 1"));
|
||||
Assert.assertTrue(explainString.contains("`k1` = 1"));
|
||||
}
|
||||
|
||||
/* Case6 multi lateral view
|
||||
@ -508,8 +508,8 @@ public class TableFunctionPlanTest {
|
||||
+ " where k1 in (select k2 from db1.table_for_view);";
|
||||
String explainString = UtFrameUtils.getSQLPlanOrErrorMsg(ctx, sql, true);
|
||||
Assert.assertTrue(explainString.contains("join op: LEFT SEMI JOIN(BROADCAST)"));
|
||||
Assert.assertTrue(explainString.contains("equal join conjunct: `k1` = `k2`"));
|
||||
Assert.assertTrue(!explainString.contains("equal join conjunct: `k2` = `k2`"));
|
||||
Assert.assertTrue(explainString.contains("`k1` = `k2`"));
|
||||
Assert.assertTrue(!explainString.contains("`k2` = `k2`"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@ -269,7 +269,7 @@ public class PolicyTest extends TestWithFeService {
|
||||
createPolicy("CREATE ROW POLICY test_row_policy4 ON test.table1 AS PERMISSIVE TO test_policy USING (k2 = 1)");
|
||||
String queryStr = "EXPLAIN select /*+ SET_VAR(enable_nereids_planner=false) */ * from test.table1";
|
||||
String explainString = getSQLPlanOrErrorMsg(queryStr);
|
||||
Assertions.assertTrue(explainString.contains("`k1` = 1 AND `k2` = 1 AND `k2` = 2 OR `k2` = 1"));
|
||||
Assertions.assertTrue(explainString.contains("(`k1` = 1) AND (`k2` = 1) AND (`k2` = 2) OR (`k2` = 1)"));
|
||||
dropPolicy("DROP ROW POLICY test_row_policy1 ON test.table1");
|
||||
dropPolicy("DROP ROW POLICY test_row_policy2 ON test.table1");
|
||||
dropPolicy("DROP ROW POLICY test_row_policy3 ON test.table1");
|
||||
@ -283,7 +283,7 @@ public class PolicyTest extends TestWithFeService {
|
||||
createPolicy("CREATE ROW POLICY test_row_policy4 ON test.table1 AS PERMISSIVE TO test_policy USING (k2 = 1)");
|
||||
String queryStr = "EXPLAIN select * from test.table1";
|
||||
String explainString = getSQLPlanOrErrorMsg(queryStr);
|
||||
Assertions.assertTrue(explainString.contains("k2[#1] IN (1, 2) AND k1[#0] = 1"));
|
||||
Assertions.assertTrue(explainString.contains("k2[#1] IN (1, 2) AND (k1[#0] = 1)"));
|
||||
dropPolicy("DROP ROW POLICY test_row_policy1 ON test.table1");
|
||||
dropPolicy("DROP ROW POLICY test_row_policy3 ON test.table1");
|
||||
dropPolicy("DROP ROW POLICY test_row_policy4 ON test.table1");
|
||||
@ -295,16 +295,16 @@ public class PolicyTest extends TestWithFeService {
|
||||
createPolicy("CREATE ROW POLICY test_row_policy2 ON test.table1 AS RESTRICTIVE TO test_policy USING (k2 = 1)");
|
||||
String joinSql
|
||||
= "select /*+ SET_VAR(enable_nereids_planner=false) */ * from table1 join table2 on table1.k1=table2.k1";
|
||||
Assertions.assertTrue(getSQLPlanOrErrorMsg(joinSql).contains("PREDICATES: `k1` = 1 AND `k2` = 1"));
|
||||
Assertions.assertTrue(getSQLPlanOrErrorMsg(joinSql).contains("(`k1` = 1) AND (`k2` = 1)"));
|
||||
String unionSql
|
||||
= "select /*+ SET_VAR(enable_nereids_planner=false) */ * from table1 union select * from table2";
|
||||
Assertions.assertTrue(getSQLPlanOrErrorMsg(unionSql).contains("PREDICATES: `k1` = 1 AND `k2` = 1"));
|
||||
Assertions.assertTrue(getSQLPlanOrErrorMsg(unionSql).contains("(`k1` = 1) AND (`k2` = 1)"));
|
||||
String subQuerySql
|
||||
= "select /*+ SET_VAR(enable_nereids_planner=false) */ * from table2 where k1 in (select k1 from table1)";
|
||||
Assertions.assertTrue(getSQLPlanOrErrorMsg(subQuerySql).contains("PREDICATES: `k1` = 1 AND `k2` = 1"));
|
||||
Assertions.assertTrue(getSQLPlanOrErrorMsg(subQuerySql).contains("(`k1` = 1) AND (`k2` = 1)"));
|
||||
String aliasSql
|
||||
= "select /*+ SET_VAR(enable_nereids_planner=false) */ * from table1 t1 join table2 t2 on t1.k1=t2.k1";
|
||||
Assertions.assertTrue(getSQLPlanOrErrorMsg(aliasSql).contains("PREDICATES: `t1`.`k1` = 1 AND `t1`.`k2` = 1"));
|
||||
Assertions.assertTrue(getSQLPlanOrErrorMsg(aliasSql).contains("(`t1`.`k1` = 1) AND (`t1`.`k2` = 1)"));
|
||||
dropPolicy("DROP ROW POLICY test_row_policy1 ON test.table1");
|
||||
dropPolicy("DROP ROW POLICY test_row_policy2 ON test.table1");
|
||||
}
|
||||
@ -314,13 +314,13 @@ public class PolicyTest extends TestWithFeService {
|
||||
createPolicy("CREATE ROW POLICY test_row_policy1 ON test.table1 AS RESTRICTIVE TO test_policy USING (k1 = 1)");
|
||||
createPolicy("CREATE ROW POLICY test_row_policy2 ON test.table1 AS RESTRICTIVE TO test_policy USING (k2 = 1)");
|
||||
String joinSql = "select * from table1 join table2 on table1.k1=table2.k1";
|
||||
Assertions.assertTrue(getSQLPlanOrErrorMsg(joinSql).contains("PREDICATES: k1 = 1 AND k2 = 1"));
|
||||
Assertions.assertTrue(getSQLPlanOrErrorMsg(joinSql).contains("PREDICATES: (k1 = 1) AND (k2 = 1)"));
|
||||
String unionSql = "select * from table1 union select * from table2";
|
||||
Assertions.assertTrue(getSQLPlanOrErrorMsg(unionSql).contains("PREDICATES: k1 = 1 AND k2 = 1"));
|
||||
Assertions.assertTrue(getSQLPlanOrErrorMsg(unionSql).contains("PREDICATES: (k1 = 1) AND (k2 = 1)"));
|
||||
String subQuerySql = "select * from table2 where k1 in (select k1 from table1)";
|
||||
Assertions.assertTrue(getSQLPlanOrErrorMsg(subQuerySql).contains("PREDICATES: k1 = 1 AND k2 = 1"));
|
||||
Assertions.assertTrue(getSQLPlanOrErrorMsg(subQuerySql).contains("PREDICATES: (k1 = 1) AND (k2 = 1)"));
|
||||
String aliasSql = "select * from table1 t1 join table2 t2 on t1.k1=t2.k1";
|
||||
Assertions.assertTrue(getSQLPlanOrErrorMsg(aliasSql).contains("PREDICATES: k1 = 1 AND k2 = 1"));
|
||||
Assertions.assertTrue(getSQLPlanOrErrorMsg(aliasSql).contains("PREDICATES: (k1 = 1) AND (k2 = 1)"));
|
||||
dropPolicy("DROP ROW POLICY test_row_policy1 ON test.table1");
|
||||
dropPolicy("DROP ROW POLICY test_row_policy2 ON test.table1");
|
||||
}
|
||||
|
||||
@ -671,7 +671,7 @@ public class OlapQueryCacheTest {
|
||||
|
||||
cache.rewriteSelectStmt(newRangeList);
|
||||
sql = ca.getRewriteStmt().getWhereClause().toSql();
|
||||
Assert.assertEquals(sql, "`date` >= 20200114 AND `date` <= 20200115");
|
||||
Assert.assertEquals(sql, "(`date` >= 20200114) AND (`date` <= 20200115)");
|
||||
} catch (Exception e) {
|
||||
LOG.warn("ex={}", e);
|
||||
Assert.fail(e.getMessage());
|
||||
@ -713,7 +713,7 @@ public class OlapQueryCacheTest {
|
||||
hitRange = range.buildDiskPartitionRange(newRangeList);
|
||||
cache.rewriteSelectStmt(newRangeList);
|
||||
sql = ca.getRewriteStmt().getWhereClause().toSql();
|
||||
Assert.assertEquals(sql, "`eventdate` >= '2020-01-14' AND `eventdate` <= '2020-01-15'");
|
||||
Assert.assertEquals(sql, "(`eventdate` >= '2020-01-14') AND (`eventdate` <= '2020-01-15')");
|
||||
} catch (Exception e) {
|
||||
LOG.warn("ex={}", e);
|
||||
Assert.fail(e.getMessage());
|
||||
@ -856,7 +856,7 @@ public class OlapQueryCacheTest {
|
||||
cache.rewriteSelectStmt(newRangeList);
|
||||
|
||||
sql = ca.getRewriteStmt().getWhereClause().toSql();
|
||||
Assert.assertEquals(sql, "`eventdate` >= '2020-01-13' AND `eventdate` <= '2020-01-15'");
|
||||
Assert.assertEquals(sql, "(`eventdate` >= '2020-01-13') AND (`eventdate` <= '2020-01-15')");
|
||||
|
||||
List<PartitionRange.PartitionSingle> updateRangeList = range.buildUpdatePartitionRange();
|
||||
Assert.assertEquals(updateRangeList.size(), 2);
|
||||
@ -886,7 +886,7 @@ public class OlapQueryCacheTest {
|
||||
|
||||
cache.rewriteSelectStmt(null);
|
||||
LOG.warn("Nokey multi={}", cache.getNokeyStmt().getWhereClause().toSql());
|
||||
Assert.assertEquals(cache.getNokeyStmt().getWhereClause().toSql(), "`eventid` = 1");
|
||||
Assert.assertEquals(cache.getNokeyStmt().getWhereClause().toSql(), "(`eventid` = 1)");
|
||||
|
||||
PartitionRange range = cache.getPartitionRange();
|
||||
boolean flag = range.analytics();
|
||||
@ -904,7 +904,7 @@ public class OlapQueryCacheTest {
|
||||
cache.rewriteSelectStmt(newRangeList);
|
||||
sql = ca.getRewriteStmt().getWhereClause().toSql();
|
||||
LOG.warn("MultiPredicate={}", sql);
|
||||
Assert.assertEquals(sql, "`eventdate` > '2020-01-13' AND `eventdate` < '2020-01-16' AND `eventid` = 1");
|
||||
Assert.assertEquals(sql, "(`eventdate` > '2020-01-13') AND (`eventdate` < '2020-01-16') AND (`eventid` = 1)");
|
||||
} catch (Exception e) {
|
||||
LOG.warn("multi ex={}", e);
|
||||
Assert.fail(e.getMessage());
|
||||
@ -929,7 +929,7 @@ public class OlapQueryCacheTest {
|
||||
PartitionCache cache = (PartitionCache) ca.getCache();
|
||||
cache.rewriteSelectStmt(null);
|
||||
LOG.warn("Join nokey={}", cache.getNokeyStmt().getWhereClause().toSql());
|
||||
Assert.assertEquals(cache.getNokeyStmt().getWhereClause().toSql(), "`eventid` = 1");
|
||||
Assert.assertEquals(cache.getNokeyStmt().getWhereClause().toSql(), "(`eventid` = 1)");
|
||||
|
||||
PartitionRange range = cache.getPartitionRange();
|
||||
boolean flag = range.analytics();
|
||||
@ -947,8 +947,8 @@ public class OlapQueryCacheTest {
|
||||
cache.rewriteSelectStmt(newRangeList);
|
||||
sql = ca.getRewriteStmt().getWhereClause().toSql();
|
||||
LOG.warn("Join rewrite={}", sql);
|
||||
Assert.assertEquals(sql, "`appevent`.`eventdate` >= '2020-01-14'"
|
||||
+ " AND `appevent`.`eventdate` <= '2020-01-15' AND `eventid` = 1");
|
||||
Assert.assertEquals(sql, "(`appevent`.`eventdate` >= '2020-01-14')"
|
||||
+ " AND (`appevent`.`eventdate` <= '2020-01-15') AND (`eventid` = 1)");
|
||||
} catch (Exception e) {
|
||||
LOG.warn("Join ex={}", e);
|
||||
Assert.fail(e.getMessage());
|
||||
@ -976,7 +976,7 @@ public class OlapQueryCacheTest {
|
||||
Assert.assertEquals(cache.getNokeyStmt().toSql(),
|
||||
"SELECT <slot 7> `eventdate` AS `eventdate`, <slot 8> sum(`pv`) AS `sum(``pv``)` "
|
||||
+ "FROM (SELECT <slot 3> `eventdate` AS `eventdate`, <slot 4> count(`userid`) AS `pv` "
|
||||
+ "FROM `testDb`.`appevent` WHERE `eventid` = 1 GROUP BY `eventdate`) tbl "
|
||||
+ "FROM `testDb`.`appevent` WHERE (`eventid` = 1) GROUP BY `eventdate`) tbl "
|
||||
+ "GROUP BY `eventdate`");
|
||||
|
||||
PartitionRange range = cache.getPartitionRange();
|
||||
@ -998,8 +998,8 @@ public class OlapQueryCacheTest {
|
||||
Assert.assertEquals(sql,
|
||||
"SELECT <slot 7> `eventdate` AS `eventdate`, <slot 8> sum(`pv`) AS `sum(``pv``)` "
|
||||
+ "FROM (SELECT <slot 3> `eventdate` AS `eventdate`, <slot 4> count(`userid`) AS `pv` "
|
||||
+ "FROM `testDb`.`appevent` WHERE `eventdate` > '2020-01-13' "
|
||||
+ "AND `eventdate` < '2020-01-16' AND `eventid` = 1 GROUP BY `eventdate`) tbl "
|
||||
+ "FROM `testDb`.`appevent` WHERE (`eventdate` > '2020-01-13') "
|
||||
+ "AND (`eventdate` < '2020-01-16') AND (`eventid` = 1) GROUP BY `eventdate`) tbl "
|
||||
+ "GROUP BY `eventdate`");
|
||||
} catch (Exception e) {
|
||||
LOG.warn("sub ex={}", e);
|
||||
@ -1051,8 +1051,8 @@ public class OlapQueryCacheTest {
|
||||
SqlCache sqlCache = (SqlCache) ca.getCache();
|
||||
String cacheKey = sqlCache.getSqlWithViewStmt();
|
||||
Assert.assertEquals(cacheKey, "SELECT <slot 2> `eventdate` AS `eventdate`, <slot 3> count(`userid`) "
|
||||
+ "AS `count(``userid``)` FROM `testDb`.`appevent` WHERE `eventdate` >= '2020-01-12' "
|
||||
+ "AND `eventdate` <= '2020-01-14' GROUP BY `eventdate`|");
|
||||
+ "AS `count(``userid``)` FROM `testDb`.`appevent` WHERE (`eventdate` >= '2020-01-12') "
|
||||
+ "AND (`eventdate` <= '2020-01-14') GROUP BY `eventdate`|");
|
||||
Assert.assertEquals(selectedPartitionIds.size(), sqlCache.getSumOfPartitionNum());
|
||||
}
|
||||
|
||||
@ -1090,8 +1090,8 @@ public class OlapQueryCacheTest {
|
||||
Assert.assertEquals(cacheKey, "SELECT `testDb`.`view1`.`eventdate` AS `eventdate`, "
|
||||
+ "`testDb`.`view1`.`__count_1` AS `__count_1` FROM `testDb`.`view1`|"
|
||||
+ "SELECT `eventdate` AS `eventdate`, count(`userid`) AS `__count_1` FROM "
|
||||
+ "`testDb`.`appevent` WHERE `eventdate` >= '2020-01-12' AND "
|
||||
+ "`eventdate` <= '2020-01-14' GROUP BY `eventdate`");
|
||||
+ "`testDb`.`appevent` WHERE (`eventdate` >= '2020-01-12') AND "
|
||||
+ "(`eventdate` <= '2020-01-14') GROUP BY `eventdate`");
|
||||
Assert.assertEquals(selectedPartitionIds.size(), sqlCache.getSumOfPartitionNum());
|
||||
}
|
||||
|
||||
@ -1109,7 +1109,7 @@ public class OlapQueryCacheTest {
|
||||
String cacheKey = sqlCache.getSqlWithViewStmt();
|
||||
Assert.assertEquals(cacheKey, "SELECT * from testDb.view1|SELECT `eventdate` AS `eventdate`, "
|
||||
+ "count(`userid`) AS `__count_1` FROM `testDb`.`appevent` "
|
||||
+ "WHERE `eventdate` >= '2020-01-12' AND `eventdate` <= '2020-01-14' GROUP BY `eventdate`");
|
||||
+ "WHERE (`eventdate` >= '2020-01-12') AND (`eventdate` <= '2020-01-14') GROUP BY `eventdate`");
|
||||
Assert.assertEquals(selectedPartitionIds.size(), sqlCache.getSumOfPartitionNum());
|
||||
}
|
||||
|
||||
@ -1135,7 +1135,7 @@ public class OlapQueryCacheTest {
|
||||
Assert.assertEquals(cacheKey, "SELECT `origin`.`eventdate` AS `eventdate`, "
|
||||
+ "`origin`.`userid` AS `userid` FROM (SELECT `view2`.`eventdate` AS `eventdate`, "
|
||||
+ "`view2`.`userid` AS `userid` FROM `testDb`.`view2` view2 "
|
||||
+ "WHERE `view2`.`eventdate` >= '2020-01-12' AND `view2`.`eventdate` <= '2020-01-14') origin|"
|
||||
+ "WHERE (`view2`.`eventdate` >= '2020-01-12') AND (`view2`.`eventdate` <= '2020-01-14')) origin|"
|
||||
+ "SELECT `eventdate` AS `eventdate`, `userid` AS `userid` FROM `testDb`.`appevent`");
|
||||
Assert.assertEquals(selectedPartitionIds.size(), sqlCache.getSumOfPartitionNum());
|
||||
}
|
||||
@ -1187,8 +1187,8 @@ public class OlapQueryCacheTest {
|
||||
Assert.assertEquals(cache.getSqlWithViewStmt(), "SELECT `testDb`.`view3`.`eventdate` "
|
||||
+ "AS `eventdate`, `testDb`.`view3`.`__count_1` AS `__count_1` "
|
||||
+ "FROM `testDb`.`view3`|SELECT `eventdate` AS `eventdate`, count(`userid`) "
|
||||
+ "AS `__count_1` FROM `testDb`.`appevent` WHERE `eventdate` >= '2020-01-12' "
|
||||
+ "AND `eventdate` <= '2020-01-15' GROUP BY `eventdate`");
|
||||
+ "AS `__count_1` FROM `testDb`.`appevent` WHERE (`eventdate` >= '2020-01-12') "
|
||||
+ "AND (`eventdate` <= '2020-01-15') GROUP BY `eventdate`");
|
||||
} catch (Exception e) {
|
||||
LOG.warn("ex={}", e);
|
||||
Assert.fail(e.getMessage());
|
||||
@ -1243,7 +1243,7 @@ public class OlapQueryCacheTest {
|
||||
Assert.assertEquals(cacheKey, "SELECT `testDb`.`view4`.`eventdate` AS `eventdate`, "
|
||||
+ "`testDb`.`view4`.`__count_1` AS `__count_1` FROM `testDb`.`view4`|"
|
||||
+ "SELECT `eventdate` AS `eventdate`, count(`userid`) AS `__count_1` FROM `testDb`.`view2` "
|
||||
+ "WHERE `eventdate` >= '2020-01-12' AND `eventdate` <= '2020-01-14' GROUP BY `eventdate`|"
|
||||
+ "WHERE (`eventdate` >= '2020-01-12') AND (`eventdate` <= '2020-01-14') GROUP BY `eventdate`|"
|
||||
+ "SELECT `eventdate` AS `eventdate`, `userid` AS `userid` FROM `testDb`.`appevent`");
|
||||
Assert.assertEquals(selectedPartitionIds.size(), sqlCache.getSumOfPartitionNum());
|
||||
}
|
||||
@ -1261,8 +1261,8 @@ public class OlapQueryCacheTest {
|
||||
SqlCache sqlCache = (SqlCache) ca.getCache();
|
||||
String cacheKey = sqlCache.getSqlWithViewStmt();
|
||||
Assert.assertEquals(cacheKey, "SELECT * from testDb.view4|SELECT `eventdate` AS `eventdate`, "
|
||||
+ "count(`userid`) AS `__count_1` FROM `testDb`.`view2` WHERE `eventdate` >= '2020-01-12' "
|
||||
+ "AND `eventdate` <= '2020-01-14' GROUP BY `eventdate`|SELECT `eventdate` AS `eventdate`, "
|
||||
+ "count(`userid`) AS `__count_1` FROM `testDb`.`view2` WHERE (`eventdate` >= '2020-01-12') "
|
||||
+ "AND (`eventdate` <= '2020-01-14') GROUP BY `eventdate`|SELECT `eventdate` AS `eventdate`, "
|
||||
+ "`userid` AS `userid` FROM `testDb`.`appevent`");
|
||||
Assert.assertEquals(selectedPartitionIds.size(), sqlCache.getSumOfPartitionNum());
|
||||
}
|
||||
@ -1326,7 +1326,7 @@ public class OlapQueryCacheTest {
|
||||
|
||||
cache.rewriteSelectStmt(newRangeList);
|
||||
sql = ca.getRewriteStmt().getWhereClause().toSql();
|
||||
Assert.assertEquals(sql, "`date` >= 20200114 AND `date` <= 20200115");
|
||||
Assert.assertEquals(sql, "(`date` >= 20200114) AND (`date` <= 20200115)");
|
||||
} catch (Exception e) {
|
||||
LOG.warn("ex={}", e);
|
||||
Assert.fail(e.getMessage());
|
||||
|
||||
@ -100,7 +100,7 @@ public class ExtractCommonFactorsRuleFunctionTest {
|
||||
public void testWideCommonFactorsWithOrPredicate() throws Exception {
|
||||
String query = "select /*+ SET_VAR(enable_nereids_planner=false) */ * from tb1 where tb1.k1 > 1000 or tb1.k1 < 200 or tb1.k1 = 300";
|
||||
String planString = dorisAssert.query(query).explainQuery();
|
||||
Assert.assertTrue(planString.contains("PREDICATES: `tb1`.`k1` = 300 OR `tb1`.`k1` > 1000 OR `tb1`.`k1` < 200"));
|
||||
Assert.assertTrue(planString.contains("(`tb1`.`k1` = 300) OR (`tb1`.`k1` > 1000) OR (`tb1`.`k1` < 200)"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -259,8 +259,8 @@ public class ExtractCommonFactorsRuleFunctionTest {
|
||||
Assert.assertTrue(planString.contains("`l_partkey` = `p_partkey`"));
|
||||
Assert.assertTrue(planString.contains("`l_shipmode` IN ('AIR', 'AIR REG')"));
|
||||
Assert.assertTrue(planString.contains("`l_shipinstruct` = 'DELIVER IN PERSON'"));
|
||||
Assert.assertTrue(planString.contains("`l_quantity` >= 9 AND `l_quantity` <= 19 "
|
||||
+ "OR `l_quantity` >= 20 AND `l_quantity` <= 36"));
|
||||
Assert.assertTrue(planString.contains("(`l_quantity` >= 9) AND (`l_quantity` <= 19) "
|
||||
+ "OR (`l_quantity` >= 20) AND (`l_quantity` <= 36)"));
|
||||
Assert.assertTrue(planString.contains("`p_size` >= 1"));
|
||||
Assert.assertTrue(planString.contains("`p_brand` IN ('Brand#11', 'Brand#21', 'Brand#32')"));
|
||||
Assert.assertTrue(planString.contains("`p_size` <= 15"));
|
||||
|
||||
@ -25,5 +25,5 @@
|
||||
3 [-1, 20, 0] [0, 1, 0]
|
||||
|
||||
-- !test_view_6 --
|
||||
v1 CREATE VIEW `v1` COMMENT 'VIEW' AS SELECT `error_code` AS `error_code`, 1 AS `__literal_1`, 'string' AS `__literal_2`, now() AS `__now_3`, dayofyear(`op_time`) AS `__dayofyear_4`, CAST(`source` AS BIGINT) AS `__cast_expr_5`, min(`timestamp`) OVER (ORDER BY `op_time` DESC NULLS LAST ROWS BETWEEN UNBOUNDED PRECEDING AND 1 FOLLOWING) AS `__min_6`, 1 > 2 AS `__binary_predicate_7`, (2 + 3) AS `__arithmetic_expr_8`, 1 IN (1, 2, 3, 4) AS `__in_predicate_9`, `remark` LIKE '%like' AS `__like_predicate_10`, CASE WHEN `remark` = 's' THEN 1 ELSE 2 END AS `__case_expr_11`, (TRUE | FALSE) AS `__arithmetic_expr_12` FROM `regression_test_ddl_p0`.`view_column_name_test`;
|
||||
v1 CREATE VIEW `v1` COMMENT 'VIEW' AS SELECT `error_code` AS `error_code`, 1 AS `__literal_1`, 'string' AS `__literal_2`, now() AS `__now_3`, dayofyear(`op_time`) AS `__dayofyear_4`, CAST(`source` AS BIGINT) AS `__cast_expr_5`, min(`timestamp`) OVER (ORDER BY `op_time` DESC NULLS LAST ROWS BETWEEN UNBOUNDED PRECEDING AND 1 FOLLOWING) AS `__min_6`, (1 > 2) AS `__binary_predicate_7`, (2 + 3) AS `__arithmetic_expr_8`, 1 IN (1, 2, 3, 4) AS `__in_predicate_9`, `remark` LIKE '%like' AS `__like_predicate_10`, CASE WHEN (`remark` = 's') THEN 1 ELSE 2 END AS `__case_expr_11`, (TRUE | FALSE) AS `__arithmetic_expr_12` FROM `regression_test_ddl_p0`.`view_column_name_test`;
|
||||
|
||||
|
||||
@ -13,3 +13,13 @@
|
||||
-- !select_mv --
|
||||
7
|
||||
|
||||
-- !select_mv --
|
||||
1 2
|
||||
2 1
|
||||
3 1
|
||||
|
||||
-- !select_mv --
|
||||
1 2
|
||||
2 2
|
||||
3 3
|
||||
|
||||
|
||||
@ -12,7 +12,7 @@ PLAN FRAGMENT 0
|
||||
|
||||
0:VOlapScanNode
|
||||
TABLE: regression_test_performance_p0.redundant_conjuncts(redundant_conjuncts), PREAGGREGATION: OFF. Reason: No AggregateInfo
|
||||
PREDICATES: `k1` = 1
|
||||
PREDICATES: (`k1` = 1)
|
||||
partitions=0/1 (), tablets=0/0, tabletList=
|
||||
cardinality=0, avgRowSize=8.0, numNodes=1
|
||||
pushAggOp=NONE
|
||||
@ -30,7 +30,7 @@ PLAN FRAGMENT 0
|
||||
|
||||
0:VOlapScanNode
|
||||
TABLE: regression_test_performance_p0.redundant_conjuncts(redundant_conjuncts), PREAGGREGATION: OFF. Reason: No AggregateInfo
|
||||
PREDICATES: `k1` = 1 OR `k1` = 2
|
||||
PREDICATES: (`k1` = 1) OR (`k1` = 2)
|
||||
partitions=0/1 (), tablets=0/0, tabletList=
|
||||
cardinality=0, avgRowSize=8.0, numNodes=1
|
||||
pushAggOp=NONE
|
||||
|
||||
@ -24,7 +24,7 @@ show_create_table_and_views_table CREATE TABLE `show_create_table_and_views_tabl
|
||||
3 1
|
||||
|
||||
-- !show --
|
||||
show_create_table_and_views_view CREATE VIEW `show_create_table_and_views_view` COMMENT 'VIEW' AS SELECT `user_id` AS `user_id`, `cost` AS `cost` FROM `show_create_table_and_views_db`.`show_create_table_and_views_table` WHERE `good_id` = 2; utf8 utf8_general_ci
|
||||
show_create_table_and_views_view CREATE VIEW `show_create_table_and_views_view` COMMENT 'VIEW' AS SELECT `user_id` AS `user_id`, `cost` AS `cost` FROM `show_create_table_and_views_db`.`show_create_table_and_views_table` WHERE (`good_id` = 2); utf8 utf8_general_ci
|
||||
|
||||
-- !select --
|
||||
1 47
|
||||
|
||||
@ -87,7 +87,7 @@ suite("test_clickhouse_jdbc_catalog", "p0,external,clickhouse,external_docker,ex
|
||||
order_qt_func_push """select * from ts where from_unixtime(ts,'yyyyMMdd') >= '2022-01-01';"""
|
||||
explain {
|
||||
sql("select * from ts where from_unixtime(ts,'yyyyMMdd') >= '2022-01-01';")
|
||||
contains """QUERY: SELECT "id", "ts" FROM "doris_test"."ts" WHERE (FROM_UNIXTIME("ts", '%Y%m%d') >= '2022-01-01')"""
|
||||
contains """QUERY: SELECT "id", "ts" FROM "doris_test"."ts" WHERE ((FROM_UNIXTIME("ts", '%Y%m%d') >= '2022-01-01'))"""
|
||||
}
|
||||
explain {
|
||||
sql("select * from ts where nvl(ts,null) >= '2022-01-01';")
|
||||
@ -96,7 +96,7 @@ suite("test_clickhouse_jdbc_catalog", "p0,external,clickhouse,external_docker,ex
|
||||
order_qt_func_push2 """select * from ts where ts <= unix_timestamp(from_unixtime(ts,'yyyyMMdd'));"""
|
||||
explain {
|
||||
sql("select * from ts where ts <= unix_timestamp(from_unixtime(ts,'yyyy-MM-dd'));")
|
||||
contains """QUERY: SELECT "id", "ts" FROM "doris_test"."ts" WHERE ("ts" <= toUnixTimestamp(FROM_UNIXTIME("ts", '%Y-%m-%d')))"""
|
||||
contains """QUERY: SELECT "id", "ts" FROM "doris_test"."ts" WHERE (("ts" <= toUnixTimestamp(FROM_UNIXTIME("ts", '%Y-%m-%d'))))"""
|
||||
}
|
||||
|
||||
order_qt_dt_with_tz """ select * from dt_with_tz order by id; """
|
||||
|
||||
@ -407,18 +407,18 @@ suite("test_mysql_jdbc_catalog", "p0,external,mysql,external_docker,external_doc
|
||||
explain {
|
||||
sql ("select k6, k8 from test1 where nvl(k6, null) = 1;")
|
||||
|
||||
contains "QUERY: SELECT `k6`, `k8` FROM `doris_test`.`test1` WHERE (ifnull(`k6`, NULL) = 1)"
|
||||
contains "QUERY: SELECT `k6`, `k8` FROM `doris_test`.`test1` WHERE ((ifnull(`k6`, NULL) = 1))"
|
||||
}
|
||||
explain {
|
||||
sql ("select k6, k8 from test1 where nvl(nvl(k6, null),null) = 1;")
|
||||
|
||||
contains "QUERY: SELECT `k6`, `k8` FROM `doris_test`.`test1` WHERE (ifnull(ifnull(`k6`, NULL), NULL) = 1)"
|
||||
contains "QUERY: SELECT `k6`, `k8` FROM `doris_test`.`test1` WHERE ((ifnull(ifnull(`k6`, NULL), NULL) = 1))"
|
||||
}
|
||||
sql """ set enable_ext_func_pred_pushdown = "false"; """
|
||||
explain {
|
||||
sql ("select k6, k8 from test1 where nvl(k6, null) = 1 and k8 = 1;")
|
||||
|
||||
contains "QUERY: SELECT `k6`, `k8` FROM `doris_test`.`test1` WHERE (`k8` = 1)"
|
||||
contains "QUERY: SELECT `k6`, `k8` FROM `doris_test`.`test1` WHERE ((`k8` = 1))"
|
||||
}
|
||||
sql """ set enable_ext_func_pred_pushdown = "true"; """
|
||||
} finally {
|
||||
|
||||
@ -82,7 +82,7 @@ suite("test_mysql_jdbc_catalog_nereids", "p0,external,mysql,external_docker,exte
|
||||
|
||||
explain {
|
||||
sql("""select id from ${ex_tb0} where id = 111;""")
|
||||
contains "WHERE (`id` = 111)"
|
||||
contains "WHERE ((`id` = 111))"
|
||||
}
|
||||
qt_ex_tb0_where """select id from ${ex_tb0} where id = 111;"""
|
||||
order_qt_ex_tb0 """ select id, name from ${ex_tb0} order by id; """
|
||||
|
||||
@ -137,7 +137,7 @@ suite("test_oracle_jdbc_catalog", "p0,external,oracle,external_docker,external_d
|
||||
// test nvl
|
||||
explain {
|
||||
sql("SELECT * FROM STUDENT WHERE nvl(score, 0) < 95;")
|
||||
contains """SELECT "ID", "NAME", "AGE", "SCORE" FROM "DORIS_TEST"."STUDENT" WHERE (nvl("SCORE", 0.0) < 95.0)"""
|
||||
contains """SELECT "ID", "NAME", "AGE", "SCORE" FROM "DORIS_TEST"."STUDENT" WHERE ((nvl("SCORE", 0.0) < 95.0))"""
|
||||
}
|
||||
|
||||
// for old planner
|
||||
|
||||
@ -38,6 +38,8 @@ suite ("testAggQueryOnAggMV1") {
|
||||
|
||||
|
||||
createMV("create materialized view emps_mv as select deptno, sum(salary), max(commission) from emps group by deptno ;")
|
||||
createMV("create materialized view emps_mv_count_key as select deptno, count(deptno) from emps group by deptno;")
|
||||
createMV("create materialized view emps_mv_if as select deptno, sum(if(empid = 1, empid, salary)) from emps group by deptno;")
|
||||
|
||||
sql """insert into emps values("2020-01-01",1,"a",1,1,1);"""
|
||||
|
||||
@ -59,4 +61,16 @@ suite ("testAggQueryOnAggMV1") {
|
||||
contains "(emps_mv)"
|
||||
}
|
||||
qt_select_mv "select sum(salary) as salary from emps;"
|
||||
|
||||
explain {
|
||||
sql("select deptno, count(deptno) from emps group by deptno order by deptno;")
|
||||
contains "(emps_mv_count_key)"
|
||||
}
|
||||
qt_select_mv "select deptno, count(deptno) from emps group by deptno order by deptno;"
|
||||
|
||||
explain {
|
||||
sql("select deptno, sum(if(empid = 1, empid, salary)) from emps group by deptno;")
|
||||
contains "(emps_mv_if)"
|
||||
}
|
||||
qt_select_mv "select deptno, sum(if(empid = 1, empid, salary)) from emps group by deptno order by deptno;"
|
||||
}
|
||||
@ -31,28 +31,28 @@ suite("test_infer_predicate") {
|
||||
|
||||
explain {
|
||||
sql "select * from infer_tb1 inner join infer_tb2 where infer_tb2.k1 = infer_tb1.k2 and infer_tb2.k1 = 1;"
|
||||
contains "PREDICATES: k2"
|
||||
contains "PREDICATES: (k2"
|
||||
}
|
||||
|
||||
explain {
|
||||
sql "select * from infer_tb1 inner join infer_tb2 where infer_tb1.k2 = infer_tb2.k1 and infer_tb2.k1 = 1;"
|
||||
contains "PREDICATES: k2"
|
||||
contains "PREDICATES: (k2"
|
||||
}
|
||||
|
||||
explain {
|
||||
sql "select * from infer_tb1 inner join infer_tb2 where cast(infer_tb2.k4 as int) = infer_tb1.k2 and infer_tb2.k4 = 1;"
|
||||
contains "PREDICATES: CAST(k2"
|
||||
contains "PREDICATES: (CAST(k2"
|
||||
}
|
||||
|
||||
explain {
|
||||
sql "select * from infer_tb1 inner join infer_tb3 where infer_tb3.k1 = infer_tb1.k2 and infer_tb3.k1 = '123';"
|
||||
notContains "PREDICATES: k2"
|
||||
notContains "PREDICATES: (k2"
|
||||
}
|
||||
|
||||
explain {
|
||||
sql "select * from infer_tb1 left join infer_tb2 on infer_tb1.k1 = infer_tb2.k3 left join infer_tb3 on " +
|
||||
"infer_tb2.k3 = infer_tb3.k2 where infer_tb1.k1 = 1;"
|
||||
contains "PREDICATES: k3"
|
||||
contains "PREDICATES: k2"
|
||||
contains "PREDICATES: (k3"
|
||||
contains "PREDICATES: (k2"
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user