Skip to content

Commit ae78fda

Browse files
committed
fix the UTs
Signed-off-by: Jialiang Liang <jiallian@amazon.com>
1 parent ad43837 commit ae78fda

2 files changed

Lines changed: 16 additions & 6 deletions

File tree

ppl/src/test/java/org/opensearch/sql/ppl/calcite/CalcitePPLAbstractTest.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,13 @@
2222
import lombok.Getter;
2323
import org.apache.calcite.plan.Contexts;
2424
import org.apache.calcite.plan.RelTraitDef;
25+
import org.apache.calcite.plan.hep.HepPlanner;
26+
import org.apache.calcite.plan.hep.HepProgram;
27+
import org.apache.calcite.plan.hep.HepProgramBuilder;
2528
import org.apache.calcite.rel.RelNode;
2629
import org.apache.calcite.rel.rel2sql.RelToSqlConverter;
2730
import org.apache.calcite.rel.rel2sql.SqlImplementor;
31+
import org.apache.calcite.rel.rules.FilterMergeRule;
2832
import org.apache.calcite.schema.SchemaPlus;
2933
import org.apache.calcite.sql.SqlNode;
3034
import org.apache.calcite.sql.parser.SqlParser;
@@ -101,10 +105,19 @@ public RelNode getRelNode(String ppl) {
101105
Query query = (Query) plan(pplParser, ppl);
102106
planTransformer.analyze(query.getPlan(), context);
103107
RelNode root = context.relBuilder.build();
108+
root = mergeAdjacentFilters(root);
104109
System.out.println(root.explain());
105110
return root;
106111
}
107112

113+
private RelNode mergeAdjacentFilters(RelNode relNode) {
114+
HepProgram program =
115+
new HepProgramBuilder().addRuleInstance(FilterMergeRule.Config.DEFAULT.toRule()).build();
116+
HepPlanner planner = new HepPlanner(program);
117+
planner.setRoot(relNode);
118+
return planner.findBestExp();
119+
}
120+
108121
private Node plan(PPLSyntaxParser parser, String query) {
109122
final AstStatementBuilder builder =
110123
new AstStatementBuilder(

ppl/src/test/java/org/opensearch/sql/ppl/calcite/CalcitePPLTrendlineTest.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,8 @@ public void testTrendlineMultipleFields() {
7676
+ " DEPTNO_trendline=[CASE(>(COUNT() OVER (ROWS 1 PRECEDING), 1), /(SUM($7) OVER (ROWS"
7777
+ " 1 PRECEDING), CAST(COUNT($7) OVER (ROWS 1 PRECEDING)):DOUBLE NOT NULL),"
7878
+ " null:NULL)])\n"
79-
+ " LogicalFilter(condition=[IS NOT NULL($7)])\n"
80-
+ " LogicalFilter(condition=[IS NOT NULL($5)])\n"
81-
+ " LogicalTableScan(table=[[scott, EMP]])\n";
79+
+ " LogicalFilter(condition=[AND(IS NOT NULL($5), IS NOT NULL($7))])\n"
80+
+ " LogicalTableScan(table=[[scott, EMP]])\n";
8281
verifyLogical(root, expectedLogical);
8382

8483
String expectedSparkSql =
@@ -89,10 +88,8 @@ public void testTrendlineMultipleFields() {
8988
+ " BETWEEN 1 PRECEDING AND CURRENT ROW)) > 1 THEN (SUM(`DEPTNO`) OVER (ROWS BETWEEN 1"
9089
+ " PRECEDING AND CURRENT ROW)) / CAST(COUNT(`DEPTNO`) OVER (ROWS BETWEEN 1 PRECEDING"
9190
+ " AND CURRENT ROW) AS DOUBLE) ELSE NULL END `DEPTNO_trendline`\n"
92-
+ "FROM (SELECT *\n"
9391
+ "FROM `scott`.`EMP`\n"
94-
+ "WHERE `SAL` IS NOT NULL) `t`\n"
95-
+ "WHERE `DEPTNO` IS NOT NULL";
92+
+ "WHERE `SAL` IS NOT NULL AND `DEPTNO` IS NOT NULL";
9693
verifyPPLToSparkSQL(root, expectedSparkSql);
9794
}
9895
}

0 commit comments

Comments
 (0)