Parse `WITH ... AS [NOT] MATERIALIZED` in `GenericDialect`, `DuckDbDialect` and `SQLiteDialect`

Ouverte
#2,622 0 commentaires 0 réactions 0 personnes assignées Voir sur GitHub

Les mainteneurs répondent en général sous 1 jour

Personne n'a encore pris cette issue.

  • #2708 par @princejain756 — fermée sans fusion

Évaluation

Difficulté
3/5
Temps estimé
1-2 jours
Accessibilité débutants
72/100
Type d'issue
Fonctionnalité
Clarté
Clairement spécifiée
Activité
Active
Stack technique
rust

Piste de recherche

Start by reading Parser::parse_cte and the Dialect implementations for PostgreSqlDialect, GenericDialect, DuckDbDialect, and SQLiteDialect. Check the parser tests for CTE syntax and run the relevant test suite. Done means WITH ... AS MATERIALIZED and AS NOT MATERIALIZED parse in all four dialects while existing dialect behavior remains covered.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Description

DuckDB PostgreSQL SQLite

WITH x AS [NOT] MATERIALIZED (...) is parsed only by PostgreSqlDialect. With GenericDialect (and all other dialects) the parser returns an error.

use sqlparser::dialect::{GenericDialect, PostgreSqlDialect};
use sqlparser::parser::Parser;

let sql = "WITH c AS MATERIALIZED (SELECT 1) SELECT * FROM c";
assert!(Parser::parse_sql(&PostgreSqlDialect {}, sql).is_ok());
// sql parser error: Expected: (, found: MATERIALIZED
assert!(Parser::parse_sql(&GenericDialect {}, sql).is_err());

The cause is the dialect check in Parser::parse_cte:

let mut is_materialized = None;
if dialect_of!(self is PostgreSqlDialect) {
    if self.parse_keyword(Keyword::MATERIALIZED) {
        is_materialized = Some(CteAsMaterialized::Materialized);
    } else if self.parse_keywords(&[Keyword::NOT, Keyword::MATERIALIZED]) {
        is_materialized = Some(CteAsMaterialized::NotMaterialized);
    }
}
Why

DataFusion is adding support for the directive in https://github.com/apache/datafusion/pull/25580 (issue https://github.com/apache/datafusion/issues/17737). The default dialect of DataFusion is GenericDialect, so users must change the dialect to PostgreSQL to use it.

DuckDB and SQLite accept the same syntax in the same position, so DuckDbDialect and SQLiteDialect should also parse it.

Proposal

Replace the dialect_of! check with a dialect method, for example Dialect::supports_cte_materialized(), that returns true for PostgreSqlDialect, GenericDialect, DuckDbDialect and SQLiteDialect.

MATERIALIZED directly after AS and before ( is not ambiguous with other syntax, so the change is small.

Langage dominant
Rust
Étoiles
3.5k
Forks
805
Merge moyen
2 j 3 h
PR mergées (30 j)
116

Préparer son environnement

  • Aucun Dockerfile ni fichier Docker Compose
  • Propose un modèle de pull request
  • Aucun guide de contribution

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Autres issues de apache/datafusion-sqlparser-rs

Toutes les issues de apache/datafusion-sqlparser-rs

Issues similaires

Plus d'issues Rust

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.