Skip to content

Support TYPEOF function with Calcite #3446

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

Merged
merged 8 commits into from
Mar 27, 2025

Conversation

LantaoJin
Copy link
Member

@LantaoJin LantaoJin commented Mar 19, 2025

Description

Support TYPEOF function with limitation:
Cannot distinguish OpenSearchDataTypes (it means only ExprCoreType works)

Because the Expression type firstly converted to calcite RelDataType and later converted back to ExprType, external information lost. For example, Text and Keyword are all evaluated to basic RelDataType with String SqlTypeName.

To address it we will support UDT #3322 first.

Related Issues

Resolves #3418

Check List

  • New functionality includes testing.
  • New functionality has been documented.
  • New functionality has javadoc added.
  • New functionality has a user manual doc added.
  • API changes companion pull request created.
  • Commits are signed per the DCO using --signoff.
  • Public documentation issue/PR created.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

@LantaoJin
Copy link
Member Author

LantaoJin commented Mar 19, 2025

The CI failure is weird. Do we have multiple Calcite dependencies now? (merged main branch) @penghuo
caused by conflicts, resolved.

@@ -250,6 +254,8 @@ static List<RexNode> translateArgument(
throw new IllegalArgumentException("Log cannot accept argument list: " + argList);
}
return LogArgs;
case "TYPEOF":
return List.of(context.rexBuilder.makeFlag(argList.getFirst().getType().getSqlTypeName()));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's confusing to invoke makeFlag here, why not using makeLiteral?

@@ -182,6 +183,9 @@ static SqlOperator translate(String op) {
return SqlStdOperatorTable.IS_NOT_NULL;
case "IS NULL":
return SqlStdOperatorTable.IS_NULL;
case "TYPEOF":
return TransferUserDefinedFunction(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe leave a TODO here to optimize this function to ImplementableFunction

Copy link
Collaborator

@qianheng-aws qianheng-aws Mar 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about return RexLiteral directly instead RexCall for TypeOf function? It also requires simple refactoring of this utils.

 context.rexBuilder.makeLiteral(
      OpenSearchTypeFactory.convertRelDataTypeToExprType(
               argList.getFirst().getType()).legacyTypeName());

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@LantaoJin LantaoJin marked this pull request as draft March 24, 2025 03:19
@LantaoJin LantaoJin changed the base branch from feature/calcite-engine to main March 24, 2025 03:20
Signed-off-by: Lantao Jin <[email protected]>
Signed-off-by: Lantao Jin <[email protected]>
Signed-off-by: Lantao Jin <[email protected]>
@LantaoJin
Copy link
Member Author

LantaoJin commented Mar 25, 2025

The IT NonFallbackCalciteSystemFunctionIT should pass after #3345 merged.

Now the CI passed due to we disabled all remote ITs

@LantaoJin LantaoJin marked this pull request as ready for review March 25, 2025 10:53
@LantaoJin
Copy link
Member Author

Failure are not related, addressed by #3482

@LantaoJin
Copy link
Member Author

cc @dai-chen @penghuo

@LantaoJin LantaoJin mentioned this pull request Mar 27, 2025
7 tasks
@penghuo
Copy link
Collaborator

penghuo commented Mar 27, 2025

Cannot distinguish OpenSearchDataTypes (it means only ExprCoreType works)

Not a concern, we should merge OpenSearchDataTypes with ExprCoreType.


@Override
public Object eval(Object... args) {
return args[0];
Copy link
Collaborator

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?

@penghuo penghuo merged commit 347fa55 into opensearch-project:main Mar 27, 2025
22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
calcite calcite migration releated
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[FEATURE] Migrate existing TYPEOF function with Calcite engine
4 participants