zwy991114 opened a new issue, #71304: URL: https://github.com/apache/doris/issues/71304
### Search before asking - [x] I had searched in the [issues](https://github.com/apache/doris/issues?q=is%3Aissue) and found no similar issues. ### Description ### Background Doris currently supports Spark SQL dialect conversion through `DialectConverterPlugin` and an external HTTP conversion service. This requires users to deploy and operate an additional component and introduces network communication into the SQL conversion path. The existing plugin flow is intentionally fail-open: if conversion fails or produces no result, the original SQL may be parsed natively by Doris. While this behavior is useful for compatibility with existing dialect plugins, it is not suitable for a Spark converter intended to preserve Spark semantics. For example: 1. A statement is valid Spark SQL but uses an unsupported Spark feature. 2. Conversion fails or produces no result. 3. The original statement happens to be accepted by the Doris parser. 4. Doris executes it with different semantics instead of reporting the conversion limitation. ### Motivation An embedded Spark SQL dialect converter would allow Doris to: - Eliminate the need to deploy a separate conversion component for the embedded path. - Parse Spark SQL using an explicit Spark grammar baseline. - Build Nereids logical plans directly instead of generating Doris SQL text for another parse. - Keep Spark-specific syntax and semantic transformations inside the converter. - Report unsupported features and conversion failures explicitly rather than silently executing the original SQL with Doris semantics. - Provide a conversion path that could be reused for other Spark-compatible SQL sources in future work. The existing external HTTP conversion service would remain supported for compatibility. The initial scope would be deliberately limited and would not attempt to provide full Spark SQL or Spark runtime compatibility in one change. ### Proposed design ```text sql_dialect=spark | v NereidsParser.parseSQLWithDialect | +-- sql_converter_service_url is configured | --> existing plugin loop and native fallback, unchanged | +-- No HTTP conversion service configured | v Token-based statement classifier using the vendored Spark lexer | +-- Non-query statement --> native Doris parser (explicit scope decision) | +-- Query-shaped statement --> embedded SparkSqlDialectConverter | v Vendored Spark lexer/parser | v Spark-specific plan builders | v Unbound Nereids LogicalPlan | v Normal Nereids analysis/optimization/execution ``` ### Proposed stages 1. Routing infrastructure - Vendor the Spark grammar. - Add the parser facade, statement classifier, and conversion error types. - Add routing metrics and unit tests. - Return an explicit unsupported error for valid queries until plan conversion is available. 2. Embedded converter - Implement query and expression plan builders. - Define the initially supported query subset. - Add plan-level tests and differential tests against Apache Spark for executable statements. 3. Function support - Add mappings only where the required Doris backend behavior exists. - Verify signatures, return types, coercion, and null behavior. 4. Additional Spark semantics - Add Spark-local expression transformations without changing unrelated native behavior. 5. Future reuse - Evaluate stored Spark view definitions and other use cases separately. ### Use case This feature is intended for users who want to submit Spark-compatible SQL to Doris without deploying and operating a separate SQL conversion service. Typical scenarios include: - Running a supported subset of Spark SQL directly through Doris FE. - Reusing existing Spark SQL statements when migrating analytical workloads from Spark SQL to Doris. - Supporting applications or SQL tools that generate Spark-compatible SQL. - Keeping Spark-specific parsing and conversion logic inside Doris, with clear errors for syntax or features that are not yet supported. The initial implementation will support only a defined subset of Spark SQL. It is not intended to run Spark DataFrame or RDD workloads, provide Spark cluster functionality, or guarantee full Spark SQL compatibility. ### Related issues _No response_ ### Are you willing to submit PR? - [x] Yes I am willing to submit a PR! ### Code of Conduct - [x] I agree to follow this project's [Code of Conduct](https://www.apache.org/foundation/policies/conduct) -- 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]
