Skip to content
Merged
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 @@ -497,7 +497,8 @@ public LogicalPlan visitAD(AD node, AnalysisContext context) {
currentEnv.define(new Symbol(Namespace.FIELD_NAME, RCF_ANOMALOUS), ExprCoreType.BOOLEAN);
} else {
currentEnv.define(new Symbol(Namespace.FIELD_NAME, RCF_ANOMALY_GRADE), ExprCoreType.DOUBLE);
currentEnv.define(new Symbol(Namespace.FIELD_NAME, RCF_TIMESTAMP), ExprCoreType.TIMESTAMP);
currentEnv.define(new Symbol(Namespace.FIELD_NAME,
(String) node.getArguments().get(TIME_FIELD).getValue()), ExprCoreType.TIMESTAMP);
}
return new LogicalAD(child, options);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,14 @@
import static org.opensearch.sql.ast.tree.Sort.SortOption.DEFAULT_ASC;
import static org.opensearch.sql.ast.tree.Sort.SortOrder;
import static org.opensearch.sql.data.model.ExprValueUtils.integerValue;
import static org.opensearch.sql.data.type.ExprCoreType.ARRAY;
import static org.opensearch.sql.data.type.ExprCoreType.BOOLEAN;
import static org.opensearch.sql.data.type.ExprCoreType.DOUBLE;
import static org.opensearch.sql.data.type.ExprCoreType.INTEGER;
import static org.opensearch.sql.data.type.ExprCoreType.LONG;
import static org.opensearch.sql.data.type.ExprCoreType.STRING;
import static org.opensearch.sql.data.type.ExprCoreType.STRUCT;
import static org.opensearch.sql.data.type.ExprCoreType.TIMESTAMP;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
Expand Down Expand Up @@ -64,12 +67,14 @@
import org.opensearch.sql.exception.SemanticCheckException;
import org.opensearch.sql.expression.DSL;
import org.opensearch.sql.expression.HighlightExpression;
import org.opensearch.sql.expression.NamedExpression;
import org.opensearch.sql.expression.config.ExpressionConfig;
import org.opensearch.sql.expression.window.WindowDefinition;
import org.opensearch.sql.planner.logical.LogicalAD;
import org.opensearch.sql.planner.logical.LogicalMLCommons;
import org.opensearch.sql.planner.logical.LogicalPlan;
import org.opensearch.sql.planner.logical.LogicalPlanDSL;
import org.opensearch.sql.planner.logical.LogicalProject;
import org.opensearch.sql.planner.logical.LogicalRelation;
import org.opensearch.sql.planner.physical.catalog.CatalogTable;
import org.springframework.context.annotation.Configuration;
Expand Down Expand Up @@ -956,6 +961,41 @@ public void ad_fitRCF_relation() {
);
}

@Test
public void ad_fitRCF_relation_with_time_field() {
Map<String, Literal> argumentMap = new HashMap<String, Literal>() {{
put("shingle_size", new Literal(8, DataType.INTEGER));
put("time_decay", new Literal(0.0001, DataType.DOUBLE));
put("time_field", new Literal("ts", DataType.STRING));
}};

LogicalPlan actual = analyze(AstDSL.project(
new AD(AstDSL.relation("schema"), argumentMap), AstDSL.allFields()));
assertTrue(((LogicalProject) actual).getProjectList().size() >= 3);
assertTrue(((LogicalProject) actual).getProjectList()
.contains(DSL.named("score", DSL.ref("score", DOUBLE))));
assertTrue(((LogicalProject) actual).getProjectList()
.contains(DSL.named("anomaly_grade", DSL.ref("anomaly_grade", DOUBLE))));
assertTrue(((LogicalProject) actual).getProjectList()
.contains(DSL.named("ts", DSL.ref("ts", TIMESTAMP))));
}

@Test
public void ad_fitRCF_relation_without_time_field() {
Map<String, Literal> argumentMap = new HashMap<>() {{
put("shingle_size", new Literal(8, DataType.INTEGER));
put("time_decay", new Literal(0.0001, DataType.DOUBLE));
}};

LogicalPlan actual = analyze(AstDSL.project(
new AD(AstDSL.relation("schema"), argumentMap), AstDSL.allFields()));
assertTrue(((LogicalProject) actual).getProjectList().size() >= 2);
assertTrue(((LogicalProject) actual).getProjectList()
.contains(DSL.named("score", DSL.ref("score", DOUBLE))));
assertTrue(((LogicalProject) actual).getProjectList()
.contains(DSL.named("anomalous", DSL.ref("anomalous", BOOLEAN))));
}

@Test
public void table_function() {
assertAnalyzeEqual(new LogicalRelation("query_range", table),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public class TestConfig {
.put(STRING_TYPE_MISSING_VALUE_FIELD, ExprCoreType.STRING)
.put("struct_value", ExprCoreType.STRUCT)
.put("array_value", ExprCoreType.ARRAY)
.put("timestamp_value", ExprCoreType.TIMESTAMP)
.build();

@Bean
Expand Down