zwy991114 opened a new pull request, #71306:
URL: https://github.com/apache/doris/pull/71306

   <!-- Recommended: develop the change with the develop-with-evidence skill 
and write this description with the doris-pr-description skill, both from 
https://github.com/apache/doris-skills (the doris-skills submodule of this 
repository). -->
   
   ### Background
   
   Doris selects a SQL dialect parser from the session's `sql_dialect` setting. 
Spark SQL conversion currently relies on a separately deployed HTTP conversion 
service; without it, the generic plugin path ultimately falls back to native 
Doris parsing.
     This PR introduces an embedded Spark parser and conversion boundary inside 
FE, ahead of the query plan builders.
   
   ### What problem does this PR solve?
   
   Issue Number: #71304
   Related PR: None
   PR Type: Feature
   
   Problem Summary:
   
   Users who want Spark-compatible SQL conversion in Doris must currently 
deploy an external conversion component, while a failed conversion can allow a 
Spark query to be reinterpreted as Doris SQL. This PR adds an embedded Spark 
3.4.3 parser, explicit query/native routing, and typed conversion failures for 
sessions using `sql_dialect=spark`. Most of the diff is the vendored grammar 
and its routing/parser tests. Plan builders are deliberately deferred, so valid 
Spark queries return an explicit unsupported error rather than executing in 
this stage; existing HTTP conversion behavior is preserved when configured.
   ### Details
   
    - **Change map:** +4006 in 18 files: +3200 production code and +806 FE unit 
tests, with no generated test output or documentation files. The production 
code has four parts:
       1. Vendored Spark 3.4.3 lexer and parser grammars (+2257), retaining 
upstream provenance in each file.
       2. Token-based statement routing (+374 in `SparkDispatchClassifier`) and 
the single-statement parser facade (+164).
       3. Dialect integration and converter skeleton (+129 in `NereidsParser` 
and `SparkSqlDialectConverter`), plus typed failure classes (+216).
       4. Five routing and conversion-outcome counters (+20 in `MetricRepo`).
    - **Scope:** Parse Spark query-shaped statements using the vendored Spark 
3.4.3 grammar, route selected non-query statements to the native parser, and 
distinguish invalid syntax, unsupported features, converter errors, and 
successful conversion. Valid queries and `INSERT ... SELECT` currently return 
`SparkDialectUnsupportedException`; no Spark query plan conversion or execution 
is supported yet. Non-query routing, including DDL and `INSERT ... VALUES`, 
uses Doris semantics by explicit  policy. `SPARK2`, backend functions, and 
Spark runtime integration are out of scope.
     - **Design:** Use an embedded converter only for `Dialect.SPARK` when 
`sql_converter_service_url` is empty. A Spark-lexer-based classifier prevents 
queries from reaching native parsing because conversion failed, while the 
single-statement Spark parser rejects multi-statement payloads containing a 
query. Keep the existing plugin loop and native fallback when an HTTP service 
is configured, rather than introducing a second conversion fallback. 
     - **Usage:** Enable the existing session setting and leave the HTTP 
service unconfigured:
   
       ```sql
       SET sql_dialect = 'spark';
       SELECT 1;
   
       The parser accepts the query, but this stage returns Unsupported Spark 
SQL feature: query plan conversion is not available in the routing 
infrastructure with a source position. Non-query statements such as SHOW TABLES 
continue through the native parser.
     - Default behavior: sql_dialect and sql_converter_service_url keep their 
existing defaults. The embedded path is selected only by explicitly setting 
Spark dialect without an HTTP service. retry_origin_sql_on_convert_fail cannot 
enable native fallback on this path. Five new Prometheus counters report native 
routing, conversion success, invalid syntax, unsupported features, and 
converter errors.
     - Compatibility: Native parsing is unchanged for non-Spark sessions, and 
Spark/non-Spark plugin behavior is unchanged when an HTTP conversion service is 
configured. Without that service, Spark query failures are now explicit instead 
of falling back to native parsing. There are no Thrift, metadata, image, 
storage, or BE protocol changes, so mixed-version FE/BE deployment, existing 
tables, and downgrade are unaffected. The grammar preserves its Apache License 
header and Spark provenance.
     
   ### Testing
   
     - bash run-fe-ut.sh --run 
org.apache.doris.nereids.parser.spark.SparkDispatchClassifierTest,org.apache.doris.nereids.parser.spark.SparkParserTest,org.apache.doris.nereids.parser.spark.SparkSqlDialectConverterTest,org.apache.doris.nereids.parser.Nerei
       dsParserSparkDialectTest: run locally on a629d64d36e; 30 tests passed, 0 
failures, and the Maven reactor completed with BUILD SUCCESS. Covers 
representative grammar parsing, case-insensitive keywords, concurrent parsing, 
syntax locations,
       multi-statement rejection, routing boundaries, typed failures, and 
configured-HTTP compatibility.
     - No end-to-end Spark query execution or Spark/Doris result-equivalence 
testing was performed because this PR intentionally does not include plan 
builders.
   
   ### Notes for Reviewers
   
   
     - Start with NereidsParser.parseSQLWithDialect for the compatibility 
boundary, then SparkDispatchClassifier for routing and SparkSqlDialectConverter 
for the deliberately incomplete conversion boundary.
     - The native route is an explicit scope decision for non-query statements, 
not a retry after Spark conversion fails. 
     - The parser facade's handling of ambiguous FROM projections is 
intentionally limited in this stage and will be revisited with plan conversion; 
these parser tests do not establish Spark result compatibility.
   
   ### Release note
   
     Add embedded Spark SQL parsing and query-routing infrastructure for 
sql_dialect=spark when no HTTP conversion service is configured. Spark queries 
currently return an explicit unsupported error; query execution will be 
introduced separately.
   
   ### Check List (For Author)
   
   - Behavior changed: Yes (see Details)
   - Does this need documentation: No
   - Pre-submission status: Ready
   
   ### AI Disclosure
   
   <!-- Tool: the agent and model, or None. Generated: the parts it wrote 
(code, tests, this description), or None. Human review: what you reviewed of 
the generated parts, or "Not applicable" without AI tools. You may add "- 
Prompts:" to summarize how you directed the agent. -->
   
   - Tool: Claude Code (Kimi-K3.1-Pro-Highspeed)
   - Generated: Code migrated from an internal repository and this PR 
description
   - Human review: The author reviewed the migrated parser and routing code, 
checked the unit tests, and revised this PR description.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to