Skip to content

Conversation

@xiaochen-zhou
Copy link
Contributor

@xiaochen-zhou xiaochen-zhou commented Oct 25, 2025

See: [CALCITE-6469]

@xiaochen-zhou xiaochen-zhou changed the title [CALCITE-7246] UNNEST in spark should convert to EXPLODE/POSEXPLODE [CALCITE-7246] UNNEST in Spark should convert to EXPLODE/POSEXPLODE Oct 25, 2025
SqlUtil.unparseFunctionSyntax(SqlStdOperatorTable.POSITION, writer, call, false);
break;
case UNNEST:
if (call.getOperator() instanceof SqlUnnestOperator
Copy link
Contributor

Choose a reason for hiding this comment

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

Add two separate operators in SqlLibraryOperators: one for explode and one for posexplode

And use it like:

if (call.getOperator() instanceof SqlUnnestOperator && ((SqlUnnestOperator) call.getOperator()).withOrdinality ) {
  SqlCall posexplodeCall = SqlLibraryOperators.POSEXPLODE
           .createCall(SqlParserPos.ZERO, call.getOperandList());
      super.unparseCall(writer, posexplodeCall, leftPrec, rightPrec);
} else {
  SqlCall explodeCall = SqlLibraryOperators.EXPLODE
           .createCall(SqlParserPos.ZERO, call.getOperandList());
      super.unparseCall(writer, explodeCall, leftPrec, rightPrec);

}

Copy link
Contributor

Choose a reason for hiding this comment

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

That is mostly useful if he wants to support it in input programs; here he wants to use it when outputting SQL.

Copy link
Contributor

@dssysolyatin dssysolyatin Oct 28, 2025

Choose a reason for hiding this comment

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

Is the unparse logic different from the unparse logic of other function operators? If not, then there’s no need to create own mechanism to unparse a function call

trigger CI build

[CALCITE-7246] UNNEST in Spark should  convert to EXPLODE/POSEXPLODE
@sonarqubecloud
Copy link

@dssysolyatin
Copy link
Contributor

Also, you only covered the unparse part. It would be good to implement the parse part as well, so that explode/posexplode can be parsed and validated. Feel free to create a separate jira ticket for that if you don’t want to do it here

SqlUtil.unparseFunctionSyntax(SqlStdOperatorTable.POSITION, writer, call, false);
break;
case UNNEST:
if (call.getOperator() instanceof SqlUnnestOperator
Copy link
Contributor

Choose a reason for hiding this comment

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

That is mostly useful if he wants to support it in input programs; here he wants to use it when outputting SQL.

case UNNEST:
if (call.getOperator() instanceof SqlUnnestOperator
&& ((SqlUnnestOperator) call.getOperator()).withOrdinality) {
writer.keyword("POSEXPLODE");
Copy link
Contributor

Choose a reason for hiding this comment

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

this one is actually more tricky: I think the ordinality argument is swapped with the data argument in spark, So doing this won't work. You really have to rewrite the plan. You will have to validate this using a real program with data on spark.

@github-actions
Copy link

This pull request has been marked as stale due to 30 days of inactivity. It will be closed in 90 days if no further activity occurs. If you think that’s incorrect or this pull request requires a review, please simply write any comment. If closed, you can revive the PR at any time and @mention a reviewer or discuss it on the [email protected] list. Thank you for your contributions.

@github-actions github-actions bot added the stale label Nov 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants