Skip to content

Commit e548ad2

Browse files
committed
Merge branch '4636-fix-ut' into issues/4636
Signed-off-by: Yuanchun Shen <yuanchu@amazon.com>
2 parents 90b6309 + ea06ab0 commit e548ad2

11 files changed

Lines changed: 853 additions & 314 deletions

File tree

api/src/test/java/org/opensearch/sql/api/transpiler/UnifiedQueryTranspilerTest.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,9 @@ public void testToSqlWithCustomDialect() {
4343
UnifiedQueryTranspiler customTranspiler =
4444
UnifiedQueryTranspiler.builder().dialect(OpenSearchSparkSqlDialect.DEFAULT).build();
4545
String actualSql = customTranspiler.toSql(plan);
46-
String expectedSql =
47-
normalize(
48-
"SELECT *\nFROM `catalog`.`employees`\nWHERE TRY_CAST(`name` AS DOUBLE) = 1.230E2");
46+
String expectedSql = normalize("SELECT *\nFROM `catalog`.`employees`\nWHERE `name` = 123");
4947
assertEquals(
50-
"Transpiled query using OpenSearchSparkSqlDialect should translate SAFE_CAST to TRY_CAST",
48+
"Numeric types can be implicitly coerced to string with OpenSearchSparkSqlDialect",
5149
expectedSql,
5250
actualSql);
5351
}

opensearch/src/test/java/org/opensearch/sql/opensearch/request/PredicateAnalyzerTest.java

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -831,15 +831,42 @@ void isNullOr_ScriptPushDown() throws ExpressionNotAnalyzableException {
831831
.add("a", builder.getTypeFactory().createSqlType(SqlTypeName.BIGINT))
832832
.add("b", builder.getTypeFactory().createSqlType(SqlTypeName.VARCHAR))
833833
.build();
834-
// PPL IS_EMPTY is translated to OR(IS_NULL(arg), IS_EMPTY(arg))
834+
// PPL IS_EMPTY is translated to OR(IS_NULL(arg), EQUALS("")) (not IS_EMPTY because IS_EMPTY is
835+
// only for collections)
835836
RexNode call = PPLFuncImpTable.INSTANCE.resolve(builder, BuiltinFunctionName.IS_EMPTY, field2);
836837
Hook.CURRENT_TIME.addThread((Consumer<Holder<Long>>) h -> h.set(0L));
837838
QueryExpression expression =
838839
PredicateAnalyzer.analyzeExpression(call, schema, fieldTypes, rowType, cluster);
839840
assert (expression
840841
.builder()
841842
.toString()
842-
.contains("\"lang\" : \"opensearch_compounded_script\""));
843+
.contains(
844+
"""
845+
"should" : [
846+
{
847+
"bool" : {
848+
"must_not" : [
849+
{
850+
"exists" : {
851+
"field" : "b",
852+
"boost" : 1.0
853+
}
854+
}
855+
],
856+
"adjust_pure_negative" : true,
857+
"boost" : 1.0
858+
}
859+
},
860+
{
861+
"term" : {
862+
"b.keyword" : {
863+
"value" : "",
864+
"boost" : 1.0
865+
}
866+
}
867+
}
868+
]\
869+
"""));
843870
}
844871

845872
@Test

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
import org.opensearch.sql.calcite.CalciteRelNodeVisitor;
4747
import org.opensearch.sql.calcite.SysLimit;
4848
import org.opensearch.sql.calcite.validate.OpenSearchSparkSqlDialect;
49+
import org.opensearch.sql.calcite.validate.converters.PplRelToSqlNodeConverter;
4950
import org.opensearch.sql.common.setting.Settings;
5051
import org.opensearch.sql.datasource.DataSourceService;
5152
import org.opensearch.sql.exception.ExpressionEvaluationException;
@@ -65,7 +66,7 @@ public CalcitePPLAbstractTest(CalciteAssert.SchemaSpec... schemaSpecs) {
6566
this.config = config(schemaSpecs);
6667
this.dataSourceService = mock(DataSourceService.class);
6768
this.planTransformer = new CalciteRelNodeVisitor(dataSourceService);
68-
this.converter = new RelToSqlConverter(OpenSearchSparkSqlDialect.DEFAULT);
69+
this.converter = new PplRelToSqlNodeConverter(OpenSearchSparkSqlDialect.DEFAULT);
6970
this.settings = mock(Settings.class);
7071
}
7172

0 commit comments

Comments
 (0)