Skip to content

Commit 0e191dd

Browse files
committed
Add comment
Signed-off-by: Tomoyuki Morita <[email protected]>
1 parent 89c1b86 commit 0e191dd

File tree

1 file changed

+14
-17
lines changed

1 file changed

+14
-17
lines changed

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

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -92,24 +92,11 @@ public Expression implement(
9292
default -> throw new IllegalArgumentException(
9393
String.format("Unsupported expr type: %s", exprSqlType.getExprType()));
9494
};
95-
ScalarFunctionImpl function =
96-
(ScalarFunctionImpl)
97-
ScalarFunctionImpl.create(
98-
Types.lookupMethod(
99-
SpanFunction.class, methodName, String.class, int.class, String.class));
100-
return function.getImplementor().implement(translator, call, RexImpTable.NullAs.NULL);
95+
return implementEvalFunction(methodName, translator, call);
10196
} else if (SqlTypeUtil.isCharacter(fieldType)) {
102-
// if first argument is string, consider it as timestamp
103-
ScalarFunctionImpl function =
104-
(ScalarFunctionImpl)
105-
ScalarFunctionImpl.create(
106-
Types.lookupMethod(
107-
SpanFunction.class,
108-
"evalTimestamp",
109-
String.class,
110-
int.class,
111-
String.class));
112-
return function.getImplementor().implement(translator, call, RexImpTable.NullAs.NULL);
97+
// If first argument is string, consider it contains timestamp as string.
98+
// (timestamp in dynamic fields will fall into this case)
99+
return implementEvalFunction("evalTimestamp", translator, call);
113100
}
114101
throw new IllegalArgumentException(
115102
String.format(
@@ -118,6 +105,16 @@ public Expression implement(
118105
}
119106
}
120107

108+
private static Expression implementEvalFunction(
109+
String methodName, RexToLixTranslator translator, RexCall call) {
110+
ScalarFunctionImpl function =
111+
(ScalarFunctionImpl)
112+
ScalarFunctionImpl.create(
113+
Types.lookupMethod(
114+
SpanFunction.class, methodName, String.class, int.class, String.class));
115+
return function.getImplementor().implement(translator, call, RexImpTable.NullAs.NULL);
116+
}
117+
121118
@Strict
122119
public static Object evalDate(
123120
@Parameter(name = "value") String value,

0 commit comments

Comments
 (0)