diff --git a/ppl-spark-integration/src/main/java/org/opensearch/sql/ppl/CatalystQueryPlanVisitor.java b/ppl-spark-integration/src/main/java/org/opensearch/sql/ppl/CatalystQueryPlanVisitor.java index 12c6ff4be..90df01e66 100644 --- a/ppl-spark-integration/src/main/java/org/opensearch/sql/ppl/CatalystQueryPlanVisitor.java +++ b/ppl-spark-integration/src/main/java/org/opensearch/sql/ppl/CatalystQueryPlanVisitor.java @@ -20,7 +20,6 @@ import org.apache.spark.sql.catalyst.expressions.InSubquery$; import org.apache.spark.sql.catalyst.expressions.LessThanOrEqual; import org.apache.spark.sql.catalyst.expressions.ListQuery$; -import org.apache.spark.sql.catalyst.expressions.Literal$; import org.apache.spark.sql.catalyst.expressions.MakeInterval$; import org.apache.spark.sql.catalyst.expressions.NamedExpression; import org.apache.spark.sql.catalyst.expressions.Predicate; @@ -29,7 +28,6 @@ import org.apache.spark.sql.catalyst.expressions.SortDirection; import org.apache.spark.sql.catalyst.expressions.SortOrder; import org.apache.spark.sql.catalyst.plans.logical.*; -import org.apache.spark.sql.catalyst.util.DataTypeJsonUtils$; import org.apache.spark.sql.execution.ExplainMode; import org.apache.spark.sql.execution.command.DescribeTableCommand; import org.apache.spark.sql.execution.command.ExplainCommand; @@ -49,7 +47,6 @@ import org.opensearch.sql.ast.expression.FieldsMapping; import org.opensearch.sql.ast.expression.Function; import org.opensearch.sql.ast.expression.In; -import org.opensearch.sql.ast.expression.IntervalUnit; import org.opensearch.sql.ast.expression.subquery.ExistsSubquery; import org.opensearch.sql.ast.expression.subquery.InSubquery; import org.opensearch.sql.ast.expression.Interval; @@ -107,7 +104,6 @@ import scala.collection.Seq; import java.util.ArrayList; -import java.util.Arrays; import java.util.List; import java.util.Objects; import java.util.Optional; @@ -119,6 +115,7 @@ import static java.util.List.of; import static org.opensearch.sql.expression.function.BuiltinFunctionName.EQUAL; import static org.opensearch.sql.ppl.CatalystPlanContext.findRelation; +import static org.opensearch.sql.ppl.utils.BuiltinFunctionTranslator.createIntervalArgs; import static org.opensearch.sql.ppl.utils.DataTypeTransformer.seq; import static org.opensearch.sql.ppl.utils.DataTypeTransformer.translate; import static org.opensearch.sql.ppl.utils.DedupeTransformer.retainMultipleDuplicateEvents; @@ -779,23 +776,6 @@ public Expression visitInterval(Interval node, CatalystPlanContext context) { return context.getNamedParseExpressions().push(interval); } - private Expression[] createIntervalArgs(IntervalUnit unit, Expression value) { - Expression[] args = new Expression[7]; - Arrays.fill(args, Literal$.MODULE$.apply(0)); - switch (unit) { - case YEAR: args[0] = value; break; - case MONTH: args[1] = value; break; - case WEEK: args[2] = value; break; - case DAY: args[3] = value; break; - case HOUR: args[4] = value; break; - case MINUTE: args[5] = value; break; - case SECOND: args[6] = value; break; - default: - throw new IllegalArgumentException("Unsupported Interval unit: " + unit); - } - return args; - } - @Override public Expression visitDedupe(Dedupe node, CatalystPlanContext context) { throw new IllegalStateException("Not Supported operation : Dedupe"); diff --git a/ppl-spark-integration/src/main/java/org/opensearch/sql/ppl/utils/BuiltinFunctionTranslator.java b/ppl-spark-integration/src/main/java/org/opensearch/sql/ppl/utils/BuiltinFunctionTranslator.java index 2f44bb287..d954b04b9 100644 --- a/ppl-spark-integration/src/main/java/org/opensearch/sql/ppl/utils/BuiltinFunctionTranslator.java +++ b/ppl-spark-integration/src/main/java/org/opensearch/sql/ppl/utils/BuiltinFunctionTranslator.java @@ -17,9 +17,11 @@ import org.apache.spark.sql.catalyst.expressions.TimestampDiff$; import org.apache.spark.sql.catalyst.expressions.ToUTCTimestamp$; import org.apache.spark.sql.catalyst.expressions.UnaryMinus$; +import org.opensearch.sql.ast.expression.IntervalUnit; import org.opensearch.sql.expression.function.BuiltinFunctionName; import scala.Option; +import java.util.Arrays; import java.util.List; import java.util.Map; import java.util.function.Function; @@ -199,4 +201,21 @@ static Expression builtinFunction(org.opensearch.sql.ast.expression.Function fun return new UnresolvedFunction(seq(name), seq(args), false, empty(),false); } } + + static Expression[] createIntervalArgs(IntervalUnit unit, Expression value) { + Expression[] args = new Expression[7]; + Arrays.fill(args, Literal$.MODULE$.apply(0)); + switch (unit) { + case YEAR: args[0] = value; break; + case MONTH: args[1] = value; break; + case WEEK: args[2] = value; break; + case DAY: args[3] = value; break; + case HOUR: args[4] = value; break; + case MINUTE: args[5] = value; break; + case SECOND: args[6] = value; break; + default: + throw new IllegalArgumentException("Unsupported Interval unit: " + unit); + } + return args; + } }