Skip to content

Commit 1f93871

Browse files
committed
Refactor: Move type comparison earlier in last day function implementation
Signed-off-by: Yuanchun Shen <yuanchu@amazon.com>
1 parent ac030e4 commit 1f93871

1 file changed

Lines changed: 22 additions & 16 deletions

File tree

core/src/main/java/org/opensearch/sql/expression/function/udf/datetime/LastDayFunction.java

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
package org.opensearch.sql.expression.function.udf.datetime;
77

88
import java.util.List;
9-
import org.apache.calcite.DataContext;
109
import org.apache.calcite.adapter.enumerable.NotNullImplementor;
1110
import org.apache.calcite.adapter.enumerable.NullPolicy;
1211
import org.apache.calcite.adapter.enumerable.RexToLixTranslator;
@@ -50,24 +49,31 @@ public Expression implement(
5049
SqlTypeName dateType =
5150
OpenSearchTypeFactory.convertRelDataTypeToSqlTypeName(
5251
call.getOperands().getFirst().getType());
53-
return Expressions.call(
54-
LastDayImplementor.class,
55-
"lastDay",
56-
translatedOperands.getFirst(),
57-
Expressions.constant(dateType),
58-
translator.getRoot());
59-
}
52+
Expression functionProperties =
53+
Expressions.call(
54+
UserDefinedFunctionUtils.class, "restoreFunctionProperties", translator.getRoot());
6055

61-
public static Object lastDay(String date, SqlTypeName dateType, DataContext propertyContext) {
62-
FunctionProperties properties =
63-
UserDefinedFunctionUtils.restoreFunctionProperties(propertyContext);
6456
if (SqlTypeName.TIME.equals(dateType)) {
65-
return DateTimeFunctions.exprLastDayToday(properties.getQueryStartClock())
66-
.valueForCalcite();
57+
return Expressions.call(LastDayImplementor.class, "lastDayToday", functionProperties);
6758
}
68-
ExprValue timestampValue =
69-
DateTimeApplyUtils.transferInputToExprTimestampValue(date, dateType, properties);
70-
return DateTimeFunctions.exprLastDay(timestampValue).valueForCalcite();
59+
60+
Expression timestampValue =
61+
Expressions.call(
62+
DateTimeApplyUtils.class,
63+
"transferInputToExprTimestampValue",
64+
translatedOperands.getFirst(),
65+
Expressions.constant(dateType),
66+
functionProperties);
67+
return Expressions.call(LastDayImplementor.class, "lastDay", timestampValue);
68+
}
69+
70+
public static String lastDayToday(FunctionProperties properties) {
71+
return (String)
72+
DateTimeFunctions.exprLastDayToday(properties.getQueryStartClock()).valueForCalcite();
73+
}
74+
75+
public static String lastDay(ExprValue timestampValue) {
76+
return (String) DateTimeFunctions.exprLastDay(timestampValue).valueForCalcite();
7177
}
7278
}
7379
}

0 commit comments

Comments
 (0)