NoahKusaba opened a new issue, #132:
URL: https://github.com/apache/datafusion-iceberg/issues/132

   ### Describe the bug
   
   `INSERT INTO` an unpartitioned table fails at planning when the table sets 
`write.datafusion.fanout.enabled=false`:
   
   ```
   Error during planning: Partition column '_partition' not found in schema. 
Ensure the plan has been extended with partition values using 
project_with_partition.
   ```
   
   `insert_into` adds the `_partition` column only for partitioned tables, but 
sorts by it whenever fanout is disabled:
   
   
https://github.com/apache/datafusion-iceberg/blob/865c0813864fdf2d416eda4bd77d09ea1918f374/crates/datafusion/src/table_provider/catalog_table_provider.rs#L195-L230
   
   For an unpartitioned table the input has no `_partition` column, so 
`sort_by_partition` returns the error above. The table can't be written to 
through this crate at all.
   
   ### To Reproduce
   
   ```rust
   let fixtures = FixtureCatalog::try_new().await?;
   let schema = Schema::builder()
       .with_fields(vec![
           NestedField::required(1, "id", 
Type::Primitive(PrimitiveType::Int)).into(),
           NestedField::required(2, "val", 
Type::Primitive(PrimitiveType::Int)).into(),
       ])
       .build()?;
   fixtures
       .table(TableIdent::from_strs(["ns", "t"])?, schema)
       .property("write.datafusion.fanout.enabled", "false")
       .create()
       .await?;
   let ctx = SessionContext::new();
   ctx.register_catalog(
       "c",
       Arc::new(IcebergCatalogProvider::try_new(fixtures.catalog()).await?),
   );
   ctx.sql("INSERT INTO c.ns.t VALUES (1, 10), (2, 
20)").await?.collect().await?;
   ```
   
   The `collect` fails with the error above. The same table partitioned by 
`identity(id)` inserts both rows.
   
   ### Expected behavior
   
   The insert writes both rows and returns a count of 2. The fanout setting 
only chooses between `FanoutWriter` and `ClusteredWriter` for partitioned 
tables. An unpartitioned table always uses `UnpartitionedWriter`, which needs 
no sort:
   
   
https://github.com/apache/datafusion-iceberg/blob/865c0813864fdf2d416eda4bd77d09ea1918f374/crates/datafusion/src/write/task_writer.rs#L129-L130
   
   Skipping the sort for unpartitioned tables would fix it.
   
   ### Additional context
   
   - No test sets `write.datafusion.fanout.enabled`, which is how this went 
unnoticed.
   - #38 is a different failure with fanout disabled: on partitioned tables, 
the optimizer removes the partition sort.
   


-- 
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