Skip to content

Commit decd30d

Browse files
committed
add java doc
Signed-off-by: xinyual <xinyual@amazon.com>
1 parent 5d0f9b8 commit decd30d

1 file changed

Lines changed: 24 additions & 1 deletion

File tree

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

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,14 @@ private static String normalizeUnit(String rawUnit) {
306306
}
307307
}
308308

309+
/**
310+
* The function add cast for date-related target node
311+
*
312+
* @param candidate The candidate node
313+
* @param context calcite context
314+
* @param castTarget the target cast type
315+
* @return the rexnode after casting
316+
*/
309317
public static RexNode transferCompareForDateRelated(
310318
RexNode candidate, CalcitePlanContext context, SqlTypeName castTarget) {
311319
if (!(Objects.isNull(castTarget))) {
@@ -335,15 +343,30 @@ public static RexNode transferCompareForDateRelated(
335343
return candidate;
336344
}
337345

346+
/**
347+
* The function find the target cast type according to the left and right node. When the two node
348+
* are both related to date with different type, cast to timestamp
349+
*
350+
* @param left
351+
* @param right
352+
* @return
353+
*/
338354
public static SqlTypeName findCastType(RexNode left, RexNode right) {
339355
SqlTypeName leftType = returnCorrespondingSqlType(left);
340356
SqlTypeName rightType = returnCorrespondingSqlType(right);
341-
if (leftType != null && rightType != null) {
357+
if (leftType != null && rightType != null && rightType != leftType) {
342358
return SqlTypeName.TIMESTAMP;
343359
}
344360
return leftType == null ? rightType : leftType;
345361
}
346362

363+
/**
364+
* Find corresponding cast type according to the node's type. If they're not related to the date,
365+
* return null
366+
*
367+
* @param node the candidate node
368+
* @return the sql type name
369+
*/
347370
public static SqlTypeName returnCorrespondingSqlType(RexNode node) {
348371
if (node.getType() instanceof ExprSqlType) {
349372
OpenSearchTypeFactory.ExprUDT udt = ((ExprSqlType) node.getType()).getUdt();

0 commit comments

Comments
 (0)