Skip to content

REST: Unable to create a partitioned Table #1567

@Fokko

Description

@Fokko

Apache Iceberg Rust version

0.5.1 (latest version)

Describe the bug

When creating a partitioned table:

let schema = Schema::builder()
        .with_schema_id(1)
        .with_fields(vec![
            NestedField::optional(1, "ts", Type::Primitive(PrimitiveType::Timestamp)).into(),
        ])
        .build()
        .unwrap();

let partition_spec = UnboundPartitionSpec::builder()
    .add_partition_field(1, "day", Transform::Day)
    .unwrap()
    .with_spec_id(0)
    .build();

let table_creation = TableCreation::builder()
    .name("test_append_date_partition_data_file".to_string())
    .schema(schema.clone())
    .partition_spec_opt(Some(partition_spec))
    .build();

let table = rest_catalog
    .create_table(ns.name(), table_creation)
    .await
    .unwrap();

I get the following error from the iceberg-rest-fixture docker container:

<meta http-equiv="Content-Type" content="text/html;charset=ISO-8859-1"/>
<title>Error 500 com.fasterxml.jackson.databind.JsonMappingException: Cannot parse to an integer value: field-id: null (through reference chain: org.apache.iceberg.rest.requests.CreateTableRequest[&quot;partition-spec&quot;])</title>
</head>
<body><h2>HTTP ERROR 500 com.fasterxml.jackson.databind.JsonMappingException: Cannot parse to an integer value: field-id: null (through reference chain: org.apache.iceberg.rest.requests.CreateTableRequest[&quot;partition-spec&quot;])</h2>
<table>
<tr><th>URI:</th><td>/v1/namespaces/591d3547-d420-426d-8f5a-6d9966b90a44/tables</td></tr>
<tr><th>STATUS:</th><td>500</td></tr>
<tr><th>MESSAGE:</th><td>com.fasterxml.jackson.databind.JsonMappingException: Cannot parse to an integer value: field-id: null (through reference chain: org.apache.iceberg.rest.requests.CreateTableRequest[&quot;partition-spec&quot;])</td></tr>
<tr><th>SERVLET:</th><td>org.apache.iceberg.rest.RESTCatalogServlet-5c30a9b0</td></tr>

I noticed that by default the field-IDs are None:

/// Add a new partition field to the partition spec from an unbound partition field.
pub fn add_partition_field(
self,
source_id: i32,
target_name: impl ToString,
transformation: Transform,
) -> Result<Self> {
let field = UnboundPartitionField {
source_id,
field_id: None,
name: target_name.to_string(),
transform: transformation,
};
self.add_partition_field_internal(field)
}

Should we assign them from 1000 and then increment?

I think the current API is confusing and will require users to assign field-IDs which is not super friendly. Thoughts @Xuanwo @liurenjie1024 @c-thiel ?

To Reproduce

No response

Expected behavior

No response

Willingness to contribute

None

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions