Skip to content

Commit d8d81a6

Browse files
committed
Signed-off-by: xinyual <xinyual@amazon.com>
1 parent b9331be commit d8d81a6

10 files changed

Lines changed: 252 additions & 21 deletions

File tree

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

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
import static org.opensearch.sql.ast.expression.SpanUnit.NONE;
1212
import static org.opensearch.sql.ast.expression.SpanUnit.UNKNOWN;
1313
import static org.opensearch.sql.calcite.utils.OpenSearchTypeFactory.TYPE_FACTORY;
14+
import static org.opensearch.sql.utils.DateTimeUtils.findCastType;
15+
import static org.opensearch.sql.utils.DateTimeUtils.transferCompareForDateRelated;
1416

1517
import java.math.BigDecimal;
1618
import java.util.ArrayList;
@@ -69,15 +71,13 @@
6971
import org.opensearch.sql.ast.expression.subquery.InSubquery;
7072
import org.opensearch.sql.ast.expression.subquery.ScalarSubquery;
7173
import org.opensearch.sql.ast.tree.UnresolvedPlan;
72-
import org.opensearch.sql.calcite.type.ExprSqlType;
7374
import org.opensearch.sql.calcite.utils.OpenSearchTypeFactory;
7475
import org.opensearch.sql.calcite.utils.PlanUtils;
7576
import org.opensearch.sql.common.utils.StringUtils;
7677
import org.opensearch.sql.data.type.ExprType;
7778
import org.opensearch.sql.exception.CalciteUnsupportedException;
7879
import org.opensearch.sql.exception.SemanticCheckException;
7980
import org.opensearch.sql.expression.function.BuiltinFunctionName;
80-
import org.opensearch.sql.expression.function.PPLBuiltinOperators;
8181
import org.opensearch.sql.expression.function.PPLFuncImpTable;
8282

8383
@RequiredArgsConstructor
@@ -218,28 +218,12 @@ public RexNode visitIn(In node, CalcitePlanContext context) {
218218
public RexNode visitCompare(Compare node, CalcitePlanContext context) {
219219
RexNode leftCandidate = analyze(node.getLeft(), context);
220220
RexNode rightCandidate = analyze(node.getRight(), context);
221-
Boolean whetherCompareByTime =
222-
leftCandidate.getType() instanceof ExprSqlType
223-
|| rightCandidate.getType() instanceof ExprSqlType;
224-
225-
final RexNode left =
226-
transferCompareForDateRelated(leftCandidate, context, whetherCompareByTime);
227-
final RexNode right =
228-
transferCompareForDateRelated(rightCandidate, context, whetherCompareByTime);
221+
SqlTypeName castTarget = findCastType(leftCandidate, rightCandidate);
222+
final RexNode left = transferCompareForDateRelated(leftCandidate, context, castTarget);
223+
final RexNode right = transferCompareForDateRelated(rightCandidate, context, castTarget);
229224
return PPLFuncImpTable.INSTANCE.resolve(context.rexBuilder, node.getOperator(), left, right);
230225
}
231226

232-
private RexNode transferCompareForDateRelated(
233-
RexNode candidate, CalcitePlanContext context, boolean whetherCompareByTime) {
234-
if (whetherCompareByTime) {
235-
RexNode transferredStringNode =
236-
context.rexBuilder.makeCall(PPLBuiltinOperators.TIMESTAMP, candidate);
237-
return transferredStringNode;
238-
} else {
239-
return candidate;
240-
}
241-
}
242-
243227
@Override
244228
public RexNode visitBetween(Between node, CalcitePlanContext context) {
245229
RexNode value = analyze(node.getValue(), context);

core/src/main/java/org/opensearch/sql/utils/DateTimeUtils.java

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55

66
package org.opensearch.sql.utils;
77

8+
import static org.opensearch.sql.calcite.utils.OpenSearchTypeFactory.ExprUDT.EXPR_DATE;
9+
import static org.opensearch.sql.calcite.utils.OpenSearchTypeFactory.ExprUDT.EXPR_TIME;
10+
import static org.opensearch.sql.calcite.utils.OpenSearchTypeFactory.ExprUDT.EXPR_TIMESTAMP;
11+
812
import java.time.Instant;
913
import java.time.LocalDate;
1014
import java.time.LocalDateTime;
@@ -15,11 +19,18 @@
1519
import java.time.format.DateTimeParseException;
1620
import java.time.temporal.ChronoUnit;
1721
import java.util.Locale;
22+
import java.util.Objects;
1823
import java.util.regex.Pattern;
1924
import lombok.experimental.UtilityClass;
25+
import org.apache.calcite.rex.RexNode;
26+
import org.apache.calcite.sql.type.SqlTypeName;
27+
import org.opensearch.sql.calcite.CalcitePlanContext;
28+
import org.opensearch.sql.calcite.type.ExprSqlType;
29+
import org.opensearch.sql.calcite.utils.OpenSearchTypeFactory;
2030
import org.opensearch.sql.data.model.ExprTimeValue;
2131
import org.opensearch.sql.data.model.ExprValue;
2232
import org.opensearch.sql.expression.function.FunctionProperties;
33+
import org.opensearch.sql.expression.function.PPLBuiltinOperators;
2334

2435
@UtilityClass
2536
public class DateTimeUtils {
@@ -357,4 +368,82 @@ private static String normalizeUnit(String rawUnit) {
357368
throw new IllegalArgumentException("Unsupported unit alias: " + rawUnit);
358369
}
359370
}
371+
372+
/**
373+
* The function add cast for date-related target node
374+
*
375+
* @param candidate The candidate node
376+
* @param context calcite context
377+
* @param castTarget the target cast type
378+
* @return the rexnode after casting
379+
*/
380+
public static RexNode transferCompareForDateRelated(
381+
RexNode candidate, CalcitePlanContext context, SqlTypeName castTarget) {
382+
if (!(Objects.isNull(castTarget))) {
383+
switch (castTarget) {
384+
case DATE:
385+
if (!(candidate.getType() instanceof ExprSqlType
386+
&& ((ExprSqlType) candidate.getType()).getUdt() == EXPR_DATE)) {
387+
return context.rexBuilder.makeCall(PPLBuiltinOperators.DATE, candidate);
388+
}
389+
break;
390+
case TIME:
391+
if (!(candidate.getType() instanceof ExprSqlType
392+
&& ((ExprSqlType) candidate.getType()).getUdt() == EXPR_TIME)) {
393+
return context.rexBuilder.makeCall(PPLBuiltinOperators.TIME, candidate);
394+
}
395+
break;
396+
case TIMESTAMP:
397+
if (!(candidate.getType() instanceof ExprSqlType
398+
&& ((ExprSqlType) candidate.getType()).getUdt() == EXPR_TIMESTAMP)) {
399+
return context.rexBuilder.makeCall(PPLBuiltinOperators.TIMESTAMP, candidate);
400+
}
401+
break;
402+
default:
403+
return candidate;
404+
}
405+
}
406+
return candidate;
407+
}
408+
409+
/**
410+
* The function find the target cast type according to the left and right node. When the two node
411+
* are both related to date with different type, cast to timestamp
412+
*
413+
* @param left
414+
* @param right
415+
* @return
416+
*/
417+
public static SqlTypeName findCastType(RexNode left, RexNode right) {
418+
SqlTypeName leftType = returnCorrespondingSqlType(left);
419+
SqlTypeName rightType = returnCorrespondingSqlType(right);
420+
if (leftType != null && rightType != null && rightType != leftType) {
421+
return SqlTypeName.TIMESTAMP;
422+
}
423+
return leftType == null ? rightType : leftType;
424+
}
425+
426+
/**
427+
* Find corresponding cast type according to the node's type. If they're not related to the date,
428+
* return null
429+
*
430+
* @param node the candidate node
431+
* @return the sql type name
432+
*/
433+
public static SqlTypeName returnCorrespondingSqlType(RexNode node) {
434+
if (node.getType() instanceof ExprSqlType) {
435+
OpenSearchTypeFactory.ExprUDT udt = ((ExprSqlType) node.getType()).getUdt();
436+
switch (udt) {
437+
case EXPR_DATE:
438+
return SqlTypeName.DATE;
439+
case EXPR_TIME:
440+
return SqlTypeName.TIME;
441+
case EXPR_TIMESTAMP:
442+
return SqlTypeName.TIMESTAMP;
443+
default:
444+
return null;
445+
}
446+
}
447+
return null;
448+
}
360449
}

integ-test/src/test/java/org/opensearch/sql/ppl/ExplainIT.java

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ public class ExplainIT extends PPLIntegTestCase {
1919
public void init() throws Exception {
2020
super.init();
2121
loadIndex(Index.ACCOUNT);
22+
loadIndex(Index.BANK);
23+
loadIndex(Index.DATE_FORMATS);
2224
}
2325

2426
@Test
@@ -57,6 +59,52 @@ public void testFilterPushDownExplain() throws IOException {
5759
+ "| fields age"));
5860
}
5961

62+
@Test
63+
public void testFilterByCompareStringTimestampPushDownExplain() throws IOException {
64+
String expected =
65+
isCalciteEnabled()
66+
? loadFromFile(
67+
"expectedOutput/calcite/explain_filter_push_compare_timestamp_string.json")
68+
: loadFromFile("expectedOutput/ppl/explain_filter_push_compare_timestamp_string.json");
69+
70+
assertJsonEqualsIgnoreId(
71+
expected,
72+
explainQueryToString(
73+
"source=opensearch-sql_test_index_bank"
74+
+ "| where birthdate > '2016-12-08 00:00:00.000000000' "
75+
+ "| where birthdate < '2018-11-09 00:00:00.000000000' "));
76+
}
77+
78+
@Test
79+
public void testFilterByCompareStringDatePushDownExplain() throws IOException {
80+
String expected =
81+
isCalciteEnabled()
82+
? loadFromFile("expectedOutput/calcite/explain_filter_push_compare_date_string.json")
83+
: loadFromFile("expectedOutput/ppl/explain_filter_push_compare_date_string.json");
84+
85+
assertJsonEqualsIgnoreId(
86+
expected,
87+
explainQueryToString(
88+
"source=opensearch-sql_test_index_date_formats | fields yyyy-MM-dd"
89+
+ "| where yyyy-MM-dd > '2016-12-08 00:00:00.123456789' "
90+
+ "| where yyyy-MM-dd < '2018-11-09 00:00:00.000000000' "));
91+
}
92+
93+
@Test
94+
public void testFilterByCompareStringTimePushDownExplain() throws IOException {
95+
String expected =
96+
isCalciteEnabled()
97+
? loadFromFile("expectedOutput/calcite/explain_filter_push_compare_time_string.json")
98+
: loadFromFile("expectedOutput/ppl/explain_filter_push_compare_time_string.json");
99+
100+
assertJsonEqualsIgnoreId(
101+
expected,
102+
explainQueryToString(
103+
"source=opensearch-sql_test_index_date_formats | fields custom_time"
104+
+ "| where custom_time > '2016-12-08 12:00:00.123456789' "
105+
+ "| where custom_time < '2018-11-09 19:00:00.123456789' "));
106+
}
107+
60108
@Test
61109
public void testFilterAndAggPushDownExplain() throws IOException {
62110
String expected =
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"calcite" : {
3+
"logical" : "LogicalFilter(condition=[<($0, DATE('2018-11-09 00:00:00.000000000':VARCHAR))])\n LogicalFilter(condition=[>($0, DATE('2016-12-08 00:00:00.123456789':VARCHAR))])\n LogicalProject(yyyy-MM-dd=[$83])\n CalciteLogicalIndexScan(table=[[OpenSearch, opensearch-sql_test_index_date_formats]])\n",
4+
"physical" : "CalciteEnumerableIndexScan(table=[[OpenSearch, opensearch-sql_test_index_date_formats]], PushDownContext=[[PROJECT->[yyyy-MM-dd], FILTER->>($0, '2016-12-08'), FILTER-><($0, '2018-11-09')], OpenSearchRequestBuilder(sourceBuilder={\"from\":0,\"timeout\":\"1m\",\"query\":{\"bool\":{\"filter\":[{\"range\":{\"yyyy-MM-dd\":{\"from\":\"2016-12-08\",\"to\":null,\"include_lower\":false,\"include_upper\":true,\"boost\":1.0}}},{\"range\":{\"yyyy-MM-dd\":{\"from\":null,\"to\":\"2018-11-09\",\"include_lower\":true,\"include_upper\":false,\"boost\":1.0}}}],\"adjust_pure_negative\":true,\"boost\":1.0}},\"_source\":{\"includes\":[\"yyyy-MM-dd\"],\"excludes\":[]},\"sort\":[{\"_doc\":{\"order\":\"asc\"}}]}, requestedTotalSize=2147483647, pageSize=null, startFrom=0)])\n"
5+
}
6+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"calcite" : {
3+
"logical" : "LogicalFilter(condition=[<($0, TIME('2018-11-09 19:00:00.123456789':VARCHAR))])\n LogicalFilter(condition=[>($0, TIME('2016-12-08 12:00:00.123456789':VARCHAR))])\n LogicalProject(custom_time=[$49])\n CalciteLogicalIndexScan(table=[[OpenSearch, opensearch-sql_test_index_date_formats]])\n",
4+
"physical" : "CalciteEnumerableIndexScan(table=[[OpenSearch, opensearch-sql_test_index_date_formats]], PushDownContext=[[PROJECT->[custom_time], FILTER->>($0, '12:00:00.123456789'), FILTER-><($0, '19:00:00.123456789')], OpenSearchRequestBuilder(sourceBuilder={\"from\":0,\"timeout\":\"1m\",\"query\":{\"bool\":{\"filter\":[{\"range\":{\"custom_time\":{\"from\":\"12:00:00.123456789\",\"to\":null,\"include_lower\":false,\"include_upper\":true,\"boost\":1.0}}},{\"range\":{\"custom_time\":{\"from\":null,\"to\":\"19:00:00.123456789\",\"include_lower\":true,\"include_upper\":false,\"boost\":1.0}}}],\"adjust_pure_negative\":true,\"boost\":1.0}},\"_source\":{\"includes\":[\"custom_time\"],\"excludes\":[]},\"sort\":[{\"_doc\":{\"order\":\"asc\"}}]}, requestedTotalSize=2147483647, pageSize=null, startFrom=0)])\n"
5+
}
6+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"calcite" : {
3+
"logical" : "LogicalProject(account_number=[$0], firstname=[$1], address=[$2], birthdate=[$3], gender=[$4], city=[$5], lastname=[$6], balance=[$7], employer=[$8], state=[$9], age=[$10], email=[$11], male=[$12])\n LogicalFilter(condition=[<($3, TIMESTAMP('2018-11-09 00:00:00.000000000':VARCHAR))])\n LogicalFilter(condition=[>($3, TIMESTAMP('2016-12-08 00:00:00.000000000':VARCHAR))])\n CalciteLogicalIndexScan(table=[[OpenSearch, opensearch-sql_test_index_bank]])\n",
4+
"physical" : "CalciteEnumerableIndexScan(table=[[OpenSearch, opensearch-sql_test_index_bank]], PushDownContext=[[PROJECT->[account_number, firstname, address, birthdate, gender, city, lastname, balance, employer, state, age, email, male], FILTER->>($3, '2016-12-08 00:00:00'), FILTER-><($3, '2018-11-09 00:00:00')], OpenSearchRequestBuilder(sourceBuilder={\"from\":0,\"timeout\":\"1m\",\"query\":{\"bool\":{\"filter\":[{\"range\":{\"birthdate\":{\"from\":\"2016-12-08T00:00:00.000Z\",\"to\":null,\"include_lower\":false,\"include_upper\":true,\"boost\":1.0}}},{\"range\":{\"birthdate\":{\"from\":null,\"to\":\"2018-11-09T00:00:00.000Z\",\"include_lower\":true,\"include_upper\":false,\"boost\":1.0}}}],\"adjust_pure_negative\":true,\"boost\":1.0}},\"_source\":{\"includes\":[\"account_number\",\"firstname\",\"address\",\"birthdate\",\"gender\",\"city\",\"lastname\",\"balance\",\"employer\",\"state\",\"age\",\"email\",\"male\"],\"excludes\":[]},\"sort\":[{\"_doc\":{\"order\":\"asc\"}}]}, requestedTotalSize=2147483647, pageSize=null, startFrom=0)])\n"
5+
}
6+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"root" : {
3+
"name" : "ProjectOperator",
4+
"description" : {
5+
"fields" : "[yyyy-MM-dd]"
6+
},
7+
"children" : [ {
8+
"name" : "FilterOperator",
9+
"description" : {
10+
"conditions" : "and(<(yyyy-MM-dd, cast_to_date(\"2018-11-09 00:00:00.000000000\")), >(yyyy-MM-dd, cast_to_date(\"2016-12-08 00:00:00.123456789\")))"
11+
},
12+
"children" : [ {
13+
"name" : "ProjectOperator",
14+
"description" : {
15+
"fields" : "[yyyy-MM-dd]"
16+
},
17+
"children" : [ {
18+
"name" : "OpenSearchIndexScan",
19+
"description" : {
20+
"request" : "OpenSearchQueryRequest(indexName=opensearch-sql_test_index_date_formats, sourceBuilder={\"from\":0,\"size\":10000,\"timeout\":\"1m\",\"_source\":{\"includes\":[\"yyyy-MM-dd\"],\"excludes\":[]}}, needClean=true, searchDone=false, pitId=s9y3QQEmb3BlbnNlYXJjaC1zcWxfdGVzdF9pbmRleF9kYXRlX2Zvcm1hdHMWNXlYSjJyR1VScENzVW9JcWpHMS12ZwAWak9VTVBiNnNRemFNR015bERWWWdRUQAAAAAAAAAAARZtQUN3TWs2d1FXbUZsbnNxYl9KbHNnARY1eVhKMnJHVVJwQ3NVb0lxakcxLXZnAAA=, cursorKeepAlive=1m, searchAfter=null, searchResponse=null)"
21+
},
22+
"children" : [ ]
23+
} ]
24+
} ]
25+
} ]
26+
}
27+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"root" : {
3+
"name" : "ProjectOperator",
4+
"description" : {
5+
"fields" : "[custom_time]"
6+
},
7+
"children" : [ {
8+
"name" : "FilterOperator",
9+
"description" : {
10+
"conditions" : "and(<(custom_time, cast_to_time(\"2018-11-09 19:00:00.123456789\")), >(custom_time, cast_to_time(\"2016-12-08 12:00:00.123456789\")))"
11+
},
12+
"children" : [ {
13+
"name" : "ProjectOperator",
14+
"description" : {
15+
"fields" : "[custom_time]"
16+
},
17+
"children" : [ {
18+
"name" : "OpenSearchIndexScan",
19+
"description" : {
20+
"request" : "OpenSearchQueryRequest(indexName=opensearch-sql_test_index_date_formats, sourceBuilder={\"from\":0,\"size\":10000,\"timeout\":\"1m\",\"_source\":{\"includes\":[\"custom_time\"],\"excludes\":[]}}, needClean=true, searchDone=false, pitId=s9y3QQEmb3BlbnNlYXJjaC1zcWxfdGVzdF9pbmRleF9kYXRlX2Zvcm1hdHMWM2VGc1RiM2VRV0NYeFJyRGpMTHI1QQAWdXpkcXIzSWZSbU9xZDdrNzk2b3JkdwAAAAAAAAAAARZJUno2SEQ1RVN6Uy1JeGN4RE9HeUtBARYzZUZzVGIzZVFXQ1h4UnJEakxMcjVBAAA=, cursorKeepAlive=1m, searchAfter=null, searchResponse=null)"
21+
},
22+
"children" : [ ]
23+
} ]
24+
} ]
25+
} ]
26+
}
27+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"root" : {
3+
"name" : "ProjectOperator",
4+
"description" : {
5+
"fields" : "[account_number, firstname, address, birthdate, gender, city, lastname, balance, employer, state, age, email, male]"
6+
},
7+
"children" : [ {
8+
"name" : "OpenSearchIndexScan",
9+
"description" : {
10+
"request" : "OpenSearchQueryRequest(indexName=opensearch-sql_test_index_bank, sourceBuilder={\"from\":0,\"size\":10000,\"timeout\":\"1m\",\"query\":{\"bool\":{\"filter\":[{\"range\":{\"birthdate\":{\"from\":null,\"to\":1541721600000,\"include_lower\":true,\"include_upper\":false,\"boost\":1.0}}},{\"range\":{\"birthdate\":{\"from\":1481155200000,\"to\":null,\"include_lower\":false,\"include_upper\":true,\"boost\":1.0}}}],\"adjust_pure_negative\":true,\"boost\":1.0}},\"_source\":{\"includes\":[\"account_number\",\"firstname\",\"address\",\"birthdate\",\"gender\",\"city\",\"lastname\",\"balance\",\"employer\",\"state\",\"age\",\"email\",\"male\"],\"excludes\":[]},\"sort\":[{\"_doc\":{\"order\":\"asc\"}}]}, needClean=true, searchDone=false, pitId=s9y3QQEeb3BlbnNlYXJjaC1zcWxfdGVzdF9pbmRleF9iYW5rFmtHVFBVZFdaVEVTdzh4ZFVDYlFiU2cAFk8tSmZBa2hpUXRHOEFVTGdnMmxYUncAAAAAAAAAAAEWOFZwckxjWGhUaXVYRVBRWXptNFlQdwEWa0dUUFVkV1pURVN3OHhkVUNiUWJTZwAA, cursorKeepAlive=1m, searchAfter=null, searchResponse=null)"
11+
},
12+
"children" : [ ]
13+
} ]
14+
}
15+
}

opensearch/src/main/java/org/opensearch/sql/opensearch/request/PredicateAnalyzer.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,14 @@
6262
import org.apache.calcite.sql.type.SqlTypeName;
6363
import org.apache.calcite.util.NlsString;
6464
import org.apache.calcite.util.Sarg;
65+
import org.opensearch.index.mapper.DateFieldMapper;
6566
import org.opensearch.index.query.BoolQueryBuilder;
6667
import org.opensearch.index.query.QueryBuilder;
6768
import org.opensearch.index.query.RangeQueryBuilder;
6869
import org.opensearch.sql.calcite.plan.OpenSearchConstants;
70+
import org.opensearch.sql.calcite.type.ExprSqlType;
71+
import org.opensearch.sql.calcite.utils.OpenSearchTypeFactory;
72+
import org.opensearch.sql.data.model.ExprTimestampValue;
6973
import org.opensearch.sql.data.type.ExprType;
7074
import org.opensearch.sql.opensearch.data.type.OpenSearchDataType.MappingType;
7175
import org.opensearch.sql.opensearch.data.type.OpenSearchTextType;
@@ -1070,6 +1074,8 @@ Object value() {
10701074
return doubleValue();
10711075
} else if (isBoolean()) {
10721076
return booleanValue();
1077+
} else if (isTimestamp()) {
1078+
return timestampValueForPushDown();
10731079
} else if (isString()) {
10741080
return RexLiteral.stringValue(literal);
10751081
} else {
@@ -1097,6 +1103,14 @@ public boolean isSarg() {
10971103
return SqlTypeName.SARG.getName().equalsIgnoreCase(literal.getTypeName().getName());
10981104
}
10991105

1106+
public boolean isTimestamp() {
1107+
if (literal.getType() instanceof ExprSqlType) {
1108+
ExprSqlType exprSqlType = (ExprSqlType) literal.getType();
1109+
return exprSqlType.getUdt() == OpenSearchTypeFactory.ExprUDT.EXPR_TIMESTAMP;
1110+
}
1111+
return false;
1112+
}
1113+
11001114
long longValue() {
11011115
return ((Number) literal.getValue()).longValue();
11021116
}
@@ -1113,6 +1127,15 @@ String stringValue() {
11131127
return RexLiteral.stringValue(literal);
11141128
}
11151129

1130+
String timestampValueForPushDown() {
1131+
ExprTimestampValue exprTimestampValue =
1132+
new ExprTimestampValue(RexLiteral.stringValue(literal));
1133+
return DateFieldMapper.getDefaultDateTimeFormatter()
1134+
.format(
1135+
exprTimestampValue.timestampValue()); // format using opensearch default formatter as
1136+
// https://github.com/opensearch-project/sql/pull/3442
1137+
}
1138+
11161139
List<Object> sargValue() {
11171140
final Sarg sarg = requireNonNull(literal.getValueAs(Sarg.class), "Sarg");
11181141
final RelDataType type = literal.getType();

0 commit comments

Comments
 (0)