Search in sources :

Example 6 with PartitionSpec

use of org.apache.iceberg.PartitionSpec in project presto by prestodb.

the class TestPartitionFields method partitionSpec.

private static PartitionSpec partitionSpec(Consumer<PartitionSpec.Builder> consumer) {
    Schema schema = new Schema(NestedField.required(1, "order_key", LongType.get()), NestedField.required(2, "ts", TimestampType.withoutZone()), NestedField.required(3, "price", DoubleType.get()), NestedField.optional(4, "comment", StringType.get()), NestedField.optional(5, "notes", ListType.ofRequired(6, StringType.get())));
    PartitionSpec.Builder builder = PartitionSpec.builderFor(schema);
    consumer.accept(builder);
    return builder.build();
}
Also used : Schema(org.apache.iceberg.Schema) PartitionSpec(org.apache.iceberg.PartitionSpec)

Example 7 with PartitionSpec

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

the class HiveCreateReplaceTableTest method testReplaceTableTxn.

@Test
public void testReplaceTableTxn() {
    catalog.createTable(TABLE_IDENTIFIER, SCHEMA, SPEC, tableLocation, Maps.newHashMap());
    Assert.assertTrue("Table should exist", catalog.tableExists(TABLE_IDENTIFIER));
    Transaction txn = catalog.newReplaceTableTransaction(TABLE_IDENTIFIER, SCHEMA, false);
    txn.commitTransaction();
    Table table = catalog.loadTable(TABLE_IDENTIFIER);
    PartitionSpec v1Expected = PartitionSpec.builderFor(table.schema()).alwaysNull("id", "id").withSpecId(1).build();
    Assert.assertEquals("Table should have a spec with one void field", v1Expected, table.spec());
}
Also used : Table(org.apache.iceberg.Table) Transaction(org.apache.iceberg.Transaction) PartitionSpec(org.apache.iceberg.PartitionSpec) Test(org.junit.Test)

Example 8 with PartitionSpec

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

the class HiveCreateReplaceTableTest method testCreateOrReplaceTableTxnTableExists.

@Test
public void testCreateOrReplaceTableTxnTableExists() {
    catalog.createTable(TABLE_IDENTIFIER, SCHEMA, SPEC, tableLocation, Maps.newHashMap());
    Assert.assertTrue("Table should exist", catalog.tableExists(TABLE_IDENTIFIER));
    Transaction txn = catalog.newReplaceTableTransaction(TABLE_IDENTIFIER, SCHEMA, true);
    txn.commitTransaction();
    Table table = catalog.loadTable(TABLE_IDENTIFIER);
    PartitionSpec v1Expected = PartitionSpec.builderFor(table.schema()).alwaysNull("id", "id").withSpecId(1).build();
    Assert.assertEquals("Table should have a spec with one void field", v1Expected, table.spec());
}
Also used : Table(org.apache.iceberg.Table) Transaction(org.apache.iceberg.Transaction) PartitionSpec(org.apache.iceberg.PartitionSpec) Test(org.junit.Test)

Example 9 with PartitionSpec

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

the class TestHiveCatalog method testCreateTableDefaultSortOrder.

@Test
public void testCreateTableDefaultSortOrder() {
    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();
    TableIdentifier tableIdent = TableIdentifier.of(DB_NAME, "tbl");
    try {
        Table table = catalog.createTable(tableIdent, schema, spec);
        Assert.assertEquals("Order ID must match", 0, table.sortOrder().orderId());
        Assert.assertTrue("Order must unsorted", table.sortOrder().isUnsorted());
    } finally {
        catalog.dropTable(tableIdent);
    }
}
Also used : TableIdentifier(org.apache.iceberg.catalog.TableIdentifier) Table(org.apache.iceberg.Table) Schema(org.apache.iceberg.Schema) PartitionSpec(org.apache.iceberg.PartitionSpec) Test(org.junit.Test)

Example 10 with PartitionSpec

use of org.apache.iceberg.PartitionSpec 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)63 Table (org.apache.iceberg.Table)40 Test (org.junit.Test)39 Schema (org.apache.iceberg.Schema)38 TableIdentifier (org.apache.iceberg.catalog.TableIdentifier)19 Record (org.apache.iceberg.data.Record)19 List (java.util.List)10 ArrayList (java.util.ArrayList)9 FileFormat (org.apache.iceberg.FileFormat)9 FieldSchema (org.apache.hadoop.hive.metastore.api.FieldSchema)8 IOException (java.io.IOException)7 ImmutableList (org.apache.iceberg.relocated.com.google.common.collect.ImmutableList)7 UpdateSchema (org.apache.iceberg.UpdateSchema)6 Path (org.apache.hadoop.fs.Path)5 BaseTable (org.apache.iceberg.BaseTable)5 DataFile (org.apache.iceberg.DataFile)5 PartitionField (org.apache.iceberg.PartitionField)4 Types (org.apache.iceberg.types.Types)4 HdfsContext (com.facebook.presto.hive.HdfsContext)3 PrestoException (com.facebook.presto.spi.PrestoException)3