Skip to content

Commit

Permalink
add ut & rt
Browse files Browse the repository at this point in the history
  • Loading branch information
liutang123 committed Aug 28, 2024
1 parent 6da217e commit ca49001
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@

import org.apache.doris.nereids.analyzer.UnboundSlot;
import org.apache.doris.nereids.analyzer.UnboundStar;
import org.apache.doris.nereids.datasets.tpch.AnalyzeCheckTestBase;
import org.apache.doris.nereids.exceptions.AnalysisException;
import org.apache.doris.nereids.exceptions.ParseException;
import org.apache.doris.nereids.pattern.PatternDescriptor;
import org.apache.doris.nereids.trees.plans.logical.LogicalOlapScan;
import org.apache.doris.nereids.trees.plans.logical.LogicalProject;
import org.apache.doris.nereids.util.MemoPatternMatchSupported;
Expand All @@ -31,7 +34,20 @@
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

class SelectExceptTest implements MemoPatternMatchSupported {
class SelectExceptTest extends AnalyzeCheckTestBase implements MemoPatternMatchSupported {

@Override
protected void runBeforeAll() throws Exception {
createDatabase("test");
connectContext.setDatabase("test");
String t = "create table t1("
+ "id int, \n"
+ "value int)\n"
+ "distributed by hash(id) buckets 1\n"
+ "properties('replication_num' = '1');";
createTables(t);
}

@Test
void testExcept() {
LogicalOlapScan olapScan = PlanConstructor.newLogicalOlapScan(0, "t1", 1);
Expand Down Expand Up @@ -79,5 +95,32 @@ void testParse() {
String sql5 = "select * except(v1 + v2, v3 as k3) from t1";
Assertions.assertThrows(ParseException.class, () -> PlanChecker.from(MemoTestUtils.createConnectContext())
.parse(sql5));

String sql6 = "select * except(id name) from t1";
Assertions.assertThrows(ParseException.class, () -> PlanChecker.from(MemoTestUtils.createConnectContext())
.parse(sql6));
}

@Test
public void testExceptAnalyze() {
PatternDescriptor expected = logicalAggregate(
logicalProject(
logicalOlapScan()
).when(proj -> proj.getProjects().size() == 2)
).when(agg -> agg.getOutputExpressions().size() == 2
&& agg.getOutputExpression(0).getName().equals("id")
&& agg.getOutputExpression(1).getName().equals("value")
&& agg.getGroupByExpressions().size() == 1
);
String sql1 = "select * except(value), sum(value) as value from t1 group by id";
PlanChecker.from(connectContext)
.parse(sql1).analyze().matches(expected);

String sql2 = "select * except(value), sum(value) as value from t1 group by 1";
PlanChecker.from(connectContext)
.parse(sql2).analyze().matches(expected);

String sql3 = "select * except(id, value) from t1"; // All slots in * EXCEPT clause are excepted
Assertions.assertThrows(AnalysisException.class, () -> PlanChecker.from(connectContext).parse(sql3).analyze());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.apache.doris.nereids.analyzer.UnboundSlot;
import org.apache.doris.nereids.analyzer.UnboundStar;
import org.apache.doris.nereids.datasets.tpch.AnalyzeCheckTestBase;
import org.apache.doris.nereids.exceptions.AnalysisException;
import org.apache.doris.nereids.exceptions.ParseException;
import org.apache.doris.nereids.trees.plans.logical.LogicalOlapScan;
import org.apache.doris.nereids.trees.plans.logical.LogicalProject;
Expand Down Expand Up @@ -88,6 +89,11 @@ void testReplace() {
String sql6 = "select * replace (1 as fake) from t1";
Assertions.assertThrows(NereidsException.class,
() -> PlanChecker.from(connectContext).checkPlannerResult(sql6));

// agg not support replace
String sql7 = "select * replace (v2 + 1 as v2) from t2 group by id, k1, v2";
Assertions.assertThrows(NereidsException.class,
() -> PlanChecker.from(connectContext).checkPlannerResult(sql7));
}

@Test
Expand All @@ -104,7 +110,6 @@ public void testReplace2() {
.matches(
logicalProject(
logicalOlapScan()
// ).when(proj -> proj.getReplaces().size() == 1
).when(proj -> proj.getProjects().get(0).getName().equals("id"))
);
}
Expand Down
9 changes: 9 additions & 0 deletions regression-test/data/correctness/test_select_except.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
-- This file is automatically generated. You should know what you did if you want to edit this
-- !except_agg --
1 5
2 4

-- !except_agg_ordinal --
1 5
2 4

13 changes: 13 additions & 0 deletions regression-test/suites/correctness/test_select_except.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,19 @@ suite("test_select_except") {
"""
exception "errCode"
}
test {
sql """
select * except (siteid, citycode, username, pv) from tbl_select_except"""
exception "errCode"
}
qt_except_agg """
select * except (siteid, username, pv), sum(pv)
from tbl_select_except
group by citycode order by citycode"""
qt_except_agg_ordinal """
select * except (siteid, username, pv), sum(pv)
from tbl_select_except
group by 1 order by citycode"""
} finally {
sql "drop table if exists tbl_select_except"
}
Expand Down

0 comments on commit ca49001

Please sign in to comment.