[ 
https://issues.apache.org/jira/browse/HUDI-8898?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Y Ethan Guo updated HUDI-8898:
------------------------------
    Description: 
The INSERT SQL statement with a subset of columns fails on Hudi table in Spark 
3.5; the same succeeds in Spark 3.4.

Create table:
{code:java}
spark.sql(
  s"""
     |create table $tableName (
     |  id int,
     |  dt string,
     |  name string,
     |  price double,
     |  ts long
     |) using hudi
     | tblproperties (primaryKey = 'id')
     | $createTablePartitionClause
     | location '$tablePath'
   """.stripMargin) {code}
INSERT INTO with a subset of columns
{code:java}
spark.sql(
      s"""
         | insert into $tableName (dt, ts, name, id)
         | values ('2025-01-04', 4000, 'a4', 4)
        """.stripMargin){code}
It fails with
{code:java}
[INSERT_COLUMN_ARITY_MISMATCH.NOT_ENOUGH_DATA_COLUMNS] Cannot write to 
`spark_catalog`.`default`.`h1`, the reason is not enough data columns:
Table columns: `id`, `name`, `price`, `ts`, `dt`.
Data columns: `dt`, `ts`, `name`, `id`.
org.apache.spark.sql.AnalysisException: 
[INSERT_COLUMN_ARITY_MISMATCH.NOT_ENOUGH_DATA_COLUMNS] Cannot write to 
`spark_catalog`.`default`.`h1`, the reason is not enough data columns:
Table columns: `id`, `name`, `price`, `ts`, `dt`.
Data columns: `dt`, `ts`, `name`, `id`.
    at 
org.apache.spark.sql.errors.QueryCompilationErrors$.cannotWriteNotEnoughColumnsToTableError(QueryCompilationErrors.scala:2126)
    at 
org.apache.spark.sql.catalyst.analysis.TableOutputResolver$.resolveOutputColumns(TableOutputResolver.scala:70)
    at 
org.apache.spark.sql.HoodieSpark3CatalystPlanUtils.resolveOutputColumns(HoodieSpark3CatalystPlanUtils.scala:51)
    at 
org.apache.spark.sql.HoodieSpark3CatalystPlanUtils.resolveOutputColumns$(HoodieSpark3CatalystPlanUtils.scala:46)
    at 
org.apache.spark.sql.HoodieSpark35CatalystPlanUtils$.resolveOutputColumns(HoodieSpark35CatalystPlanUtils.scala:32)
    at 
org.apache.spark.sql.hudi.command.InsertIntoHoodieTableCommand$.coerceQueryOutputColumns(InsertIntoHoodieTableCommand.scala:168)
    at 
org.apache.spark.sql.hudi.command.InsertIntoHoodieTableCommand$.alignQueryOutput(InsertIntoHoodieTableCommand.scala:145)
    at 
org.apache.spark.sql.hudi.command.InsertIntoHoodieTableCommand$.run(InsertIntoHoodieTableCommand.scala:99)
    at 
org.apache.spark.sql.hudi.command.InsertIntoHoodieTableCommand.run(InsertIntoHoodieTableCommand.scala:62)
 {code}

  was:
The 

Create table:
{code:java}
spark.sql(
  s"""
     |create table $tableName (
     |  id int,
     |  dt string,
     |  name string,
     |  price double,
     |  ts long
     |) using $format
     | tblproperties (primaryKey = 'id')
     | $createTablePartitionClause
     | location '$tablePath'
   """.stripMargin) {code}
INSERT INTO with a subset of columns
{code:java}
spark.sql(
      s"""
         | insert into $tableName (dt, ts, name, id)
         | values ('2025-01-04', 4000, 'a4', 4)
        """.stripMargin){code}
It fails with
{code:java}
[INSERT_COLUMN_ARITY_MISMATCH.NOT_ENOUGH_DATA_COLUMNS] Cannot write to 
`spark_catalog`.`default`.`h1`, the reason is not enough data columns:
Table columns: `id`, `name`, `price`, `ts`, `dt`.
Data columns: `dt`, `ts`, `name`, `id`.
org.apache.spark.sql.AnalysisException: 
[INSERT_COLUMN_ARITY_MISMATCH.NOT_ENOUGH_DATA_COLUMNS] Cannot write to 
`spark_catalog`.`default`.`h1`, the reason is not enough data columns:
Table columns: `id`, `name`, `price`, `ts`, `dt`.
Data columns: `dt`, `ts`, `name`, `id`.
    at 
org.apache.spark.sql.errors.QueryCompilationErrors$.cannotWriteNotEnoughColumnsToTableError(QueryCompilationErrors.scala:2126)
    at 
org.apache.spark.sql.catalyst.analysis.TableOutputResolver$.resolveOutputColumns(TableOutputResolver.scala:70)
    at 
org.apache.spark.sql.HoodieSpark3CatalystPlanUtils.resolveOutputColumns(HoodieSpark3CatalystPlanUtils.scala:51)
    at 
org.apache.spark.sql.HoodieSpark3CatalystPlanUtils.resolveOutputColumns$(HoodieSpark3CatalystPlanUtils.scala:46)
    at 
org.apache.spark.sql.HoodieSpark35CatalystPlanUtils$.resolveOutputColumns(HoodieSpark35CatalystPlanUtils.scala:32)
    at 
org.apache.spark.sql.hudi.command.InsertIntoHoodieTableCommand$.coerceQueryOutputColumns(InsertIntoHoodieTableCommand.scala:168)
    at 
org.apache.spark.sql.hudi.command.InsertIntoHoodieTableCommand$.alignQueryOutput(InsertIntoHoodieTableCommand.scala:145)
    at 
org.apache.spark.sql.hudi.command.InsertIntoHoodieTableCommand$.run(InsertIntoHoodieTableCommand.scala:99)
    at 
org.apache.spark.sql.hudi.command.InsertIntoHoodieTableCommand.run(InsertIntoHoodieTableCommand.scala:62)
 {code}


> Support INSERT SQL statement with a subset of columns in Spark 3.5
> ------------------------------------------------------------------
>
>                 Key: HUDI-8898
>                 URL: https://issues.apache.org/jira/browse/HUDI-8898
>             Project: Apache Hudi
>          Issue Type: Sub-task
>            Reporter: Y Ethan Guo
>            Assignee: Y Ethan Guo
>            Priority: Blocker
>             Fix For: 1.0.1
>
>
> The INSERT SQL statement with a subset of columns fails on Hudi table in 
> Spark 3.5; the same succeeds in Spark 3.4.
> Create table:
> {code:java}
> spark.sql(
>   s"""
>      |create table $tableName (
>      |  id int,
>      |  dt string,
>      |  name string,
>      |  price double,
>      |  ts long
>      |) using hudi
>      | tblproperties (primaryKey = 'id')
>      | $createTablePartitionClause
>      | location '$tablePath'
>    """.stripMargin) {code}
> INSERT INTO with a subset of columns
> {code:java}
> spark.sql(
>       s"""
>          | insert into $tableName (dt, ts, name, id)
>          | values ('2025-01-04', 4000, 'a4', 4)
>         """.stripMargin){code}
> It fails with
> {code:java}
> [INSERT_COLUMN_ARITY_MISMATCH.NOT_ENOUGH_DATA_COLUMNS] Cannot write to 
> `spark_catalog`.`default`.`h1`, the reason is not enough data columns:
> Table columns: `id`, `name`, `price`, `ts`, `dt`.
> Data columns: `dt`, `ts`, `name`, `id`.
> org.apache.spark.sql.AnalysisException: 
> [INSERT_COLUMN_ARITY_MISMATCH.NOT_ENOUGH_DATA_COLUMNS] Cannot write to 
> `spark_catalog`.`default`.`h1`, the reason is not enough data columns:
> Table columns: `id`, `name`, `price`, `ts`, `dt`.
> Data columns: `dt`, `ts`, `name`, `id`.
>     at 
> org.apache.spark.sql.errors.QueryCompilationErrors$.cannotWriteNotEnoughColumnsToTableError(QueryCompilationErrors.scala:2126)
>     at 
> org.apache.spark.sql.catalyst.analysis.TableOutputResolver$.resolveOutputColumns(TableOutputResolver.scala:70)
>     at 
> org.apache.spark.sql.HoodieSpark3CatalystPlanUtils.resolveOutputColumns(HoodieSpark3CatalystPlanUtils.scala:51)
>     at 
> org.apache.spark.sql.HoodieSpark3CatalystPlanUtils.resolveOutputColumns$(HoodieSpark3CatalystPlanUtils.scala:46)
>     at 
> org.apache.spark.sql.HoodieSpark35CatalystPlanUtils$.resolveOutputColumns(HoodieSpark35CatalystPlanUtils.scala:32)
>     at 
> org.apache.spark.sql.hudi.command.InsertIntoHoodieTableCommand$.coerceQueryOutputColumns(InsertIntoHoodieTableCommand.scala:168)
>     at 
> org.apache.spark.sql.hudi.command.InsertIntoHoodieTableCommand$.alignQueryOutput(InsertIntoHoodieTableCommand.scala:145)
>     at 
> org.apache.spark.sql.hudi.command.InsertIntoHoodieTableCommand$.run(InsertIntoHoodieTableCommand.scala:99)
>     at 
> org.apache.spark.sql.hudi.command.InsertIntoHoodieTableCommand.run(InsertIntoHoodieTableCommand.scala:62)
>  {code}



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to