Uploaded image for project: 'Spark'
  1. Spark
  2. SPARK-42702

Support parameterized CTE

    XMLWordPrintableJSON

Details

    • New Feature
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • 3.4.0
    • 3.4.1
    • SQL
    • None

    Description

      Support named parameters in named common table expressions (CTE). At the moment, such queries failed:

      CREATE TABLE tbl(namespace STRING) USING parquet
      INSERT INTO tbl SELECT 'abc'
      WITH transitions AS (
        SELECT * FROM tbl WHERE namespace = :namespace
      ) SELECT * FROM transitions 

      w/ the following error:

      [UNBOUND_SQL_PARAMETER] Found the unbound parameter: `namespace`. Please, fix `args` and provide a mapping of the parameter to a SQL literal.; line 3 pos 38;
      'WithCTE
      :- 'CTERelationDef 0, false
      :  +- 'SubqueryAlias transitions
      :     +- 'Project [*]
      :        +- 'Filter (namespace#3 = parameter(namespace))
      :           +- SubqueryAlias spark_catalog.default.tbl
      :              +- Relation spark_catalog.default.tbl[namespace#3] parquet
      +- 'Project [*]
         +- 'SubqueryAlias transitions
            +- 'CTERelationRef 0, falseorg.apache.spark.sql.AnalysisException: [UNBOUND_SQL_PARAMETER] Found the unbound parameter: `namespace`. Please, fix `args` and provide a mapping of the parameter to a SQL literal.; line 3 pos 38;
      'WithCTE
      :- 'CTERelationDef 0, false
      :  +- 'SubqueryAlias transitions
      :     +- 'Project [*]
      :        +- 'Filter (namespace#3 = parameter(namespace))
      :           +- SubqueryAlias spark_catalog.default.tbl
      :              +- Relation spark_catalog.default.tbl[namespace#3] parquet
      +- 'Project [*]
         +- 'SubqueryAlias transitions
            +- 'CTERelationRef 0, false    at org.apache.spark.sql.catalyst.analysis.package$AnalysisErrorAt.failAnalysis(package.scala:52)
          at org.apache.spark.sql.catalyst.analysis.CheckAnalysis.$anonfun$checkAnalysis0$5(CheckAnalysis.scala:339)
          at org.apache.spark.sql.catalyst.analysis.CheckAnalysis.$anonfun$checkAnalysis0$5$adapted(CheckAnalysis.scala:244) 

      Attachments

        Issue Links

          Activity

            People

              cloud_fan Wenchen Fan
              maxgekk Max Gekk
              Votes:
              0 Vote for this issue
              Watchers:
              6 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: