Skip to content

Commit e8b709e

Browse files
committed
Implement absolute time range in search command
Signed-off-by: Yuanchun Shen <yuanchu@amazon.com> Unit test search with absolute time range Signed-off-by: Yuanchun Shen <yuanchu@amazon.com> Rephrase timeRange and timeModifier Signed-off-by: Yuanchun Shen <yuanchu@amazon.com> Switch to earliest and latest udf Signed-off-by: Yuanchun Shen <yuanchu@amazon.com> Add a convert util Signed-off-by: Yuanchun Shen <yuanchu@amazon.com> Verify time correctness during coversion Signed-off-by: Yuanchun Shen <yuanchu@amazon.com> Fix quarter parsing bugs Signed-off-by: Yuanchun Shen <yuanchu@amazon.com> Fix week snap parsing Signed-off-by: Yuanchun Shen <yuanchu@amazon.com> Remove old implementation that translates time modifier to time filter Signed-off-by: Yuanchun Shen <yuanchu@amazon.com>
1 parent 48420be commit e8b709e

20 files changed

Lines changed: 1125 additions & 101 deletions

File tree

core/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ dependencies {
7474
testImplementation group: 'org.hamcrest', name: 'hamcrest-library', version: "${hamcrest_version}"
7575
testImplementation group: 'org.mockito', name: 'mockito-core', version: "${mockito_version}"
7676
testImplementation group: 'org.mockito', name: 'mockito-junit-jupiter', version: "${mockito_version}"
77+
testImplementation group: 'org.opensearch', name: 'opensearch', version: "${opensearch_version}"
7778
}
7879

7980
spotless {

core/src/main/java/org/opensearch/sql/calcite/CalciteRexNodeVisitor.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
import org.opensearch.sql.ast.expression.Cast;
4747
import org.opensearch.sql.ast.expression.Compare;
4848
import org.opensearch.sql.ast.expression.EqualTo;
49+
import org.opensearch.sql.ast.expression.Field;
4950
import org.opensearch.sql.ast.expression.Function;
5051
import org.opensearch.sql.ast.expression.In;
5152
import org.opensearch.sql.ast.expression.Interval;
@@ -67,6 +68,7 @@
6768
import org.opensearch.sql.ast.expression.subquery.InSubquery;
6869
import org.opensearch.sql.ast.expression.subquery.ScalarSubquery;
6970
import org.opensearch.sql.ast.tree.UnresolvedPlan;
71+
import org.opensearch.sql.calcite.plan.OpenSearchConstants;
7072
import org.opensearch.sql.calcite.utils.OpenSearchTypeFactory;
7173
import org.opensearch.sql.calcite.utils.PlanUtils;
7274
import org.opensearch.sql.common.utils.StringUtils;
@@ -365,6 +367,11 @@ public RexNode visitSpan(Span node, CalcitePlanContext context) {
365367
context.rexBuilder, BuiltinFunctionName.SPAN, field, value, unitNode);
366368
}
367369

370+
private RexNode referenceImplicitTimestampField(CalcitePlanContext context) {
371+
return analyze(
372+
new Field(new QualifiedName(OpenSearchConstants.IMPLICIT_FIELD_TIMESTAMP)), context);
373+
}
374+
368375
private boolean isTimeBased(SpanUnit unit) {
369376
return !(unit == NONE || unit == UNKNOWN);
370377
}

core/src/main/java/org/opensearch/sql/calcite/plan/OpenSearchConstants.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ public interface OpenSearchConstants {
2020

2121
String METADATA_FIELD_ROUTING = "_routing";
2222

23+
String IMPLICIT_FIELD_TIMESTAMP = "@timestamp";
24+
2325
java.util.Map<String, ExprType> METADATAFIELD_TYPE_MAP =
2426
Map.of(
2527
METADATA_FIELD_ID, ExprCoreType.STRING,

core/src/main/java/org/opensearch/sql/expression/function/udf/condition/EarliestFunction.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,6 @@ public static Boolean earliest(Object... inputs) {
6666
ZonedDateTime earliest =
6767
getRelativeZonedDateTime(
6868
expression, ZonedDateTime.ofInstant(clock.instant(), clock.getZone()));
69-
return earliest.isBefore(candidateDatetime);
69+
return !earliest.isAfter(candidateDatetime);
7070
}
7171
}

core/src/main/java/org/opensearch/sql/expression/function/udf/condition/LatestFunction.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,6 @@ public static Boolean latest(Object... inputs) {
6666
ZonedDateTime latest =
6767
getRelativeZonedDateTime(
6868
expression, ZonedDateTime.ofInstant(clock.instant(), clock.getZone()));
69-
return latest.isAfter(candidateDatetime);
69+
return !latest.isBefore(candidateDatetime);
7070
}
7171
}

0 commit comments

Comments
 (0)