Search in sources :

Example 1 with SortOrder

use of org.apache.iceberg.SortOrder in project hive by apache.

the class TestHiveCatalog method testCreateTableCustomSortOrder.

@Test
public void testCreateTableCustomSortOrder() {
    Schema schema = new Schema(required(1, "id", Types.IntegerType.get(), "unique ID"), required(2, "data", Types.StringType.get()));
    PartitionSpec spec = PartitionSpec.builderFor(schema).bucket("data", 16).build();
    SortOrder order = SortOrder.builderFor(schema).asc("id", NULLS_FIRST).build();
    TableIdentifier tableIdent = TableIdentifier.of(DB_NAME, "tbl");
    try {
        Table table = catalog.buildTable(tableIdent, schema).withPartitionSpec(spec).withSortOrder(order).create();
        SortOrder sortOrder = table.sortOrder();
        Assert.assertEquals("Order ID must match", 1, sortOrder.orderId());
        Assert.assertEquals("Order must have 1 field", 1, sortOrder.fields().size());
        Assert.assertEquals("Direction must match ", ASC, sortOrder.fields().get(0).direction());
        Assert.assertEquals("Null order must match ", NULLS_FIRST, sortOrder.fields().get(0).nullOrder());
        Transform<?, ?> transform = Transforms.identity(Types.IntegerType.get());
        Assert.assertEquals("Transform must match", transform, sortOrder.fields().get(0).transform());
    } finally {
        catalog.dropTable(tableIdent);
    }
}
Also used : TableIdentifier(org.apache.iceberg.catalog.TableIdentifier) Table(org.apache.iceberg.Table) Schema(org.apache.iceberg.Schema) SortOrder(org.apache.iceberg.SortOrder) PartitionSpec(org.apache.iceberg.PartitionSpec) Test(org.junit.Test)

Aggregations

PartitionSpec (org.apache.iceberg.PartitionSpec)1 Schema (org.apache.iceberg.Schema)1 SortOrder (org.apache.iceberg.SortOrder)1 Table (org.apache.iceberg.Table)1 TableIdentifier (org.apache.iceberg.catalog.TableIdentifier)1 Test (org.junit.Test)1