Search in sources :

Example 1 with MetadataTableType

use of org.apache.iceberg.MetadataTableType in project iceberg by apache.

the class TestMetadataTablesWithPartitionEvolution method testMetadataTablesWithUnknownTransforms.

@Test
public void testMetadataTablesWithUnknownTransforms() {
    sql("CREATE TABLE %s (id bigint NOT NULL, category string, data string) USING iceberg", tableName);
    initTable();
    sql("INSERT INTO TABLE %s VALUES (1, 'a1', 'b1')", tableName);
    Table table = validationCatalog.loadTable(tableIdent);
    PartitionSpec unknownSpec = PartitionSpecParser.fromJson(table.schema(), "{ \"spec-id\": 1, \"fields\": [ { \"name\": \"id_zero\", \"transform\": \"zero\", \"source-id\": 1 } ] }");
    // replace the table spec to include an unknown transform
    TableOperations ops = ((HasTableOperations) table).operations();
    TableMetadata base = ops.current();
    ops.commit(base, base.updatePartitionSpec(unknownSpec));
    sql("REFRESH TABLE %s", tableName);
    for (MetadataTableType tableType : Arrays.asList(FILES, ALL_DATA_FILES, ENTRIES, ALL_ENTRIES)) {
        AssertHelpers.assertThrows("Should complain about the partition type", ValidationException.class, "Cannot build table partition type, unknown transforms", () -> loadMetadataTable(tableType));
    }
}
Also used : TableMetadata(org.apache.iceberg.TableMetadata) MetadataTableType(org.apache.iceberg.MetadataTableType) Table(org.apache.iceberg.Table) TableOperations(org.apache.iceberg.TableOperations) HasTableOperations(org.apache.iceberg.HasTableOperations) HasTableOperations(org.apache.iceberg.HasTableOperations) PartitionSpec(org.apache.iceberg.PartitionSpec) Test(org.junit.Test)

Example 2 with MetadataTableType

use of org.apache.iceberg.MetadataTableType in project iceberg by apache.

the class TestStaticTable method testCannotDoIncrementalScanOnMetadataTable.

@Test
public void testCannotDoIncrementalScanOnMetadataTable() {
    table.newAppend().appendFile(FILE_A).commit();
    for (MetadataTableType type : MetadataTableType.values()) {
        Table staticTable = getStaticTable(type);
        AssertHelpers.assertThrows("Static tables do not support incremental scans", UnsupportedOperationException.class, String.format("Cannot incrementally scan table of type %s", type), () -> staticTable.newScan().appendsAfter(1));
    }
}
Also used : MetadataTableType(org.apache.iceberg.MetadataTableType) Table(org.apache.iceberg.Table) Test(org.junit.Test)

Example 3 with MetadataTableType

use of org.apache.iceberg.MetadataTableType in project iceberg by apache.

the class TestStaticTable method testMetadataTables.

@Test
public void testMetadataTables() {
    for (MetadataTableType type : MetadataTableType.values()) {
        String enumName = type.name().replace("_", "").toLowerCase();
        Assert.assertTrue("Should be able to get MetadataTable of type : " + type, getStaticTable(type).getClass().getName().toLowerCase().contains(enumName));
    }
}
Also used : MetadataTableType(org.apache.iceberg.MetadataTableType) Test(org.junit.Test)

Example 4 with MetadataTableType

use of org.apache.iceberg.MetadataTableType in project iceberg by apache.

the class HadoopTables method load.

/**
 * Loads the table location from a FileSystem path location.
 *
 * @param location a path URI (e.g. hdfs:///warehouse/my_table/)
 * @return table implementation
 */
@Override
public Table load(String location) {
    Table result;
    Pair<String, MetadataTableType> parsedMetadataType = parseMetadataType(location);
    if (parsedMetadataType != null) {
        // Load a metadata table
        result = loadMetadataTable(parsedMetadataType.first(), location, parsedMetadataType.second());
    } else {
        // Load a normal table
        TableOperations ops = newTableOps(location);
        if (ops.current() != null) {
            result = new BaseTable(ops, location);
        } else {
            throw new NoSuchTableException("Table does not exist at location: %s", location);
        }
    }
    LOG.info("Table location loaded: {}", result.location());
    return result;
}
Also used : MetadataTableType(org.apache.iceberg.MetadataTableType) BaseTable(org.apache.iceberg.BaseTable) Table(org.apache.iceberg.Table) StaticTableOperations(org.apache.iceberg.StaticTableOperations) TableOperations(org.apache.iceberg.TableOperations) BaseTable(org.apache.iceberg.BaseTable) NoSuchTableException(org.apache.iceberg.exceptions.NoSuchTableException)

Example 5 with MetadataTableType

use of org.apache.iceberg.MetadataTableType in project drill by apache.

the class IcebergFormatLocationTransformer method transform.

@Override
public FileSelection transform(String location, Function<String, FileSelection> selectionFactory) {
    MetadataTableType metadataTableType = getMetadataTableType(location);
    location = StringUtils.substringBeforeLast(location, METADATA_SEPARATOR);
    FileSelection fileSelection = selectionFactory.apply(location);
    return fileSelection != null ? new IcebergMetadataFileSelection(fileSelection, metadataTableType) : null;
}
Also used : FileSelection(org.apache.drill.exec.store.dfs.FileSelection) MetadataTableType(org.apache.iceberg.MetadataTableType)

Aggregations

MetadataTableType (org.apache.iceberg.MetadataTableType)12 Table (org.apache.iceberg.Table)9 Test (org.junit.Test)9 TableOperations (org.apache.iceberg.TableOperations)3 HasTableOperations (org.apache.iceberg.HasTableOperations)2 Row (org.apache.spark.sql.Row)2 Set (java.util.Set)1 FileSelection (org.apache.drill.exec.store.dfs.FileSelection)1 BaseTable (org.apache.iceberg.BaseTable)1 CachingCatalog (org.apache.iceberg.CachingCatalog)1 PartitionSpec (org.apache.iceberg.PartitionSpec)1 SerializableTable (org.apache.iceberg.SerializableTable)1 Snapshot (org.apache.iceberg.Snapshot)1 StaticTableOperations (org.apache.iceberg.StaticTableOperations)1 TableMetadata (org.apache.iceberg.TableMetadata)1 TestableCachingCatalog (org.apache.iceberg.TestableCachingCatalog)1 Catalog (org.apache.iceberg.catalog.Catalog)1 TableIdentifier (org.apache.iceberg.catalog.TableIdentifier)1 NoSuchTableException (org.apache.iceberg.exceptions.NoSuchTableException)1 StructType (org.apache.spark.sql.types.StructType)1