-
Notifications
You must be signed in to change notification settings - Fork 151
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support TYPEOF
function with Calcite
#3446
Changes from all commits
c9f4b9f
0f7fb93
fd37cdc
c24a6a4
fc18898
2ea8434
803baf6
caafbf2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.sql.calcite.udf.systemUDF; | ||
|
||
import org.opensearch.sql.calcite.udf.UserDefinedFunction; | ||
|
||
public class TypeOfFunction implements UserDefinedFunction { | ||
|
||
@Override | ||
public Object eval(Object... args) { | ||
return args[0]; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ | |
package org.opensearch.sql.calcite.utils; | ||
|
||
import static java.lang.Math.E; | ||
import static org.opensearch.sql.calcite.utils.OpenSearchTypeFactory.getLegacyTypeName; | ||
import static org.opensearch.sql.calcite.utils.UserDefinedFunctionUtils.*; | ||
|
||
import java.math.BigDecimal; | ||
|
@@ -30,6 +31,7 @@ | |
import org.opensearch.sql.calcite.udf.mathUDF.EulerFunction; | ||
import org.opensearch.sql.calcite.udf.mathUDF.ModFunction; | ||
import org.opensearch.sql.calcite.udf.mathUDF.SqrtFunction; | ||
import org.opensearch.sql.calcite.udf.systemUDF.TypeOfFunction; | ||
import org.opensearch.sql.calcite.udf.textUDF.LocateFunction; | ||
import org.opensearch.sql.calcite.udf.textUDF.ReplaceFunction; | ||
|
||
|
@@ -197,6 +199,10 @@ static SqlOperator translate(String op) { | |
return SqlStdOperatorTable.IS_NOT_NULL; | ||
case "IS NULL": | ||
return SqlStdOperatorTable.IS_NULL; | ||
case "TYPEOF": | ||
// TODO optimize this function to ImplementableFunction | ||
return TransferUserDefinedFunction( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe leave a TODO here to optimize this function to ImplementableFunction There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about return
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
TypeOfFunction.class, "typeof", ReturnTypes.VARCHAR_2000_NULLABLE); | ||
// TODO Add more, ref RexImpTable | ||
default: | ||
throw new IllegalArgumentException("Unsupported operator: " + op); | ||
|
@@ -268,6 +274,11 @@ static List<RexNode> translateArgument( | |
throw new IllegalArgumentException("Log cannot accept argument list: " + argList); | ||
} | ||
return LogArgs; | ||
case "TYPEOF": | ||
return List.of( | ||
context.rexBuilder.makeLiteral( | ||
getLegacyTypeName( | ||
argList.getFirst().getType().getSqlTypeName(), context.queryType))); | ||
default: | ||
return argList; | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.sql.calcite.utils; | ||
|
||
import org.opensearch.sql.ast.expression.IntervalUnit; | ||
import org.opensearch.sql.ast.expression.SpanUnit; | ||
|
||
public interface PlanUtils { | ||
|
||
static SpanUnit intervalUnitToSpanUnit(IntervalUnit unit) { | ||
return switch (unit) { | ||
case MICROSECOND -> SpanUnit.MILLISECOND; | ||
case SECOND -> SpanUnit.SECOND; | ||
case MINUTE -> SpanUnit.MINUTE; | ||
case HOUR -> SpanUnit.HOUR; | ||
case DAY -> SpanUnit.DAY; | ||
case WEEK -> SpanUnit.WEEK; | ||
case MONTH -> SpanUnit.MONTH; | ||
case QUARTER -> SpanUnit.QUARTER; | ||
case YEAR -> SpanUnit.YEAR; | ||
case UNKNOWN -> SpanUnit.UNKNOWN; | ||
default -> throw new UnsupportedOperationException("Unsupported interval unit: " + unit); | ||
}; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just curious here returns the argument value instead of its type?