Skip to content

[spark] Bind SQL parameters and time travel suffixes through the Paimon parser - #11696

Open
LuciferYang wants to merge 1 commit into
apache:masterfrom
LuciferYang:spark-parser-default-methods
Open

LuciferYang wants to merge 1 commit into
apache:masterfrom
LuciferYang:spark-parser-default-methods

Conversation

@LuciferYang

Copy link
Copy Markdown
Contributor

Purpose

Spark 4.1's ParserInterface.parsePlanWithParameters defaults to parsePlan, which drops the parameters. spark.sql(text, args), EXECUTE IMMEDIATE ... USING and Spark Connect use it, so markers in Spark-parsed statements failed with UNBOUND_SQL_PARAMETER with Paimon's extensions enabled. Spark 4.3's parseTemporalTableIdentifier default does not recognize the @v1 suffix, so spark.read.table("t@v1") failed to parse.

The change extracts parsePlanWithDelegate(sqlText)(delegateParse): Paimon commands and parser rules stay on that path, the 4.1/4.2 and 4.3 parsers forward parsePlanWithParameters to the delegate, 4.3 forwards parseTemporalTableIdentifier too, and the 3.4-4.1 CREATE TABLE LIKE fallback parses its rebuilt statement through the same function so TBLPROPERTIES keep the caller's arguments. Spark 4.0 and earlier bind after parsePlan and are unaffected.

Known limitation: CALL sys.* and tag DDL reject markers in Paimon's grammar; COPY INTO and materialized views re-parse their embedded query without the caller's arguments. Either needs a design decision; a materialized view definition lives in materialized-table.definition-query, a format Flink reads. Tracked in #11695.

Tests

ParserDelegationTest in paimon-spark-ut, plus a subclass in paimon-spark-4.2 that the 4.3 module compiles and runs too, covers:

  • spark.sql(text, args) with named arguments (including an INSERT) and with positional arguments;
  • Paimon parser rules on a plan parsed with arguments: CREATE TABLE IDENTIFIER(:t) LIKE ... creates the table in the Paimon catalog;
  • a catalog-qualified CREATE TABLE LIKE ... TBLPROPERTIES (...) bound by named and by positional arguments, asserting the stored table options;
  • EXECUTE IMMEDIATE ... USING with positional and named arguments;
  • spark.read.table("t@v1") and spark.table("t@v1") on Spark 4.3.

Cases that need a Spark version the suite does not run on are skipped with assume.

@Akash3121 Akash3121 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants