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();
}
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());
}
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());
}
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);
}
}
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);
}
}
Aggregations