|
6 | 6 | package org.opensearch.sql.expression.function.udf.datetime; |
7 | 7 |
|
8 | 8 | import java.util.List; |
9 | | -import org.apache.calcite.DataContext; |
10 | 9 | import org.apache.calcite.adapter.enumerable.NotNullImplementor; |
11 | 10 | import org.apache.calcite.adapter.enumerable.NullPolicy; |
12 | 11 | import org.apache.calcite.adapter.enumerable.RexToLixTranslator; |
@@ -50,24 +49,31 @@ public Expression implement( |
50 | 49 | SqlTypeName dateType = |
51 | 50 | OpenSearchTypeFactory.convertRelDataTypeToSqlTypeName( |
52 | 51 | 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()); |
60 | 55 |
|
61 | | - public static Object lastDay(String date, SqlTypeName dateType, DataContext propertyContext) { |
62 | | - FunctionProperties properties = |
63 | | - UserDefinedFunctionUtils.restoreFunctionProperties(propertyContext); |
64 | 56 | if (SqlTypeName.TIME.equals(dateType)) { |
65 | | - return DateTimeFunctions.exprLastDayToday(properties.getQueryStartClock()) |
66 | | - .valueForCalcite(); |
| 57 | + return Expressions.call(LastDayImplementor.class, "lastDayToday", functionProperties); |
67 | 58 | } |
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(); |
71 | 77 | } |
72 | 78 | } |
73 | 79 | } |
0 commit comments