Skip to content
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

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

LantaoJin
Copy link
Member

@LantaoJin LantaoJin commented Mar 19, 2025

Description

Support TYPEOF function with limitation:

  1. Cannot distinguish KEYWORD and TEXT
  2. 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.

Signed-off-by: Lantao Jin <[email protected]>
@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
Contributor

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
Contributor

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
Contributor

@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());

@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
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.

2 participants