Search in sources :

Example 16 with TableMetadataUnit

use of org.apache.drill.metastore.components.tables.TableMetadataUnit in project drill by apache.

the class TestTablesInputDataTransformer method testInvalidPartition.

@Test
public void testInvalidPartition() {
    TableMetadataUnit unit = TableMetadataUnit.builder().storagePlugin("dfs").workspace("tmp").tableName("nation").build();
    thrown.expect(IcebergMetastoreException.class);
    new InputDataTransformer<TableMetadataUnit>(metastoreSchema, partitionSchema, unitGetters).units(Collections.singletonList(unit)).execute();
}
Also used : InputDataTransformer(org.apache.drill.metastore.iceberg.transform.InputDataTransformer) TableMetadataUnit(org.apache.drill.metastore.components.tables.TableMetadataUnit) Test(org.junit.Test) IcebergBaseTest(org.apache.drill.metastore.iceberg.IcebergBaseTest)

Example 17 with TableMetadataUnit

use of org.apache.drill.metastore.components.tables.TableMetadataUnit in project drill by apache.

the class TestTablesOutputDataTransformer method testValidDataOneRecord.

@Test
public void testValidDataOneRecord() {
    Map<String, String> partitionKeys = new HashMap<>();
    partitionKeys.put("dir0", "2018");
    partitionKeys.put("dir1", "2019");
    List<String> partitionValues = Arrays.asList("a", "b", "c");
    Long lastModifiedTime = System.currentTimeMillis();
    Record record = GenericRecord.create(schema);
    record.setField("storagePlugin", "dfs");
    record.setField("workspace", "tmp");
    record.setField("tableName", "nation");
    record.setField("partitionKeys", partitionKeys);
    record.setField("partitionValues", partitionValues);
    record.setField("lastModifiedTime", lastModifiedTime);
    List<TableMetadataUnit> actualResult = new TablesOutputDataTransformer(unitSetters).columns(Arrays.asList("storagePlugin", "workspace", "tableName", "partitionKeys", "partitionValues", "lastModifiedTime")).records(Collections.singletonList(record)).execute();
    List<TableMetadataUnit> expectedResult = Collections.singletonList(TableMetadataUnit.builder().storagePlugin("dfs").workspace("tmp").tableName("nation").partitionKeys(partitionKeys).partitionValues(partitionValues).lastModifiedTime(lastModifiedTime).build());
    assertEquals(expectedResult, actualResult);
}
Also used : TableMetadataUnit(org.apache.drill.metastore.components.tables.TableMetadataUnit) HashMap(java.util.HashMap) Record(org.apache.iceberg.data.Record) GenericRecord(org.apache.iceberg.data.GenericRecord) Test(org.junit.Test) IcebergBaseTest(org.apache.drill.metastore.iceberg.IcebergBaseTest)

Example 18 with TableMetadataUnit

use of org.apache.drill.metastore.components.tables.TableMetadataUnit in project drill by apache.

the class TestTablesOutputDataTransformer method testValidDataSeveralRecords.

@Test
public void testValidDataSeveralRecords() {
    Record record1 = GenericRecord.create(schema);
    record1.setField("tableName", "a");
    Record record2 = GenericRecord.create(schema);
    record2.setField("tableName", "b");
    Record record3 = GenericRecord.create(schema);
    record3.setField("tableName", "c");
    List<TableMetadataUnit> actualResult = new TablesOutputDataTransformer(unitSetters).columns(Collections.singletonList("tableName")).records(Arrays.asList(record1, record2, record3)).execute();
    List<TableMetadataUnit> expectedResult = Arrays.asList(TableMetadataUnit.builder().tableName("a").build(), TableMetadataUnit.builder().tableName("b").build(), TableMetadataUnit.builder().tableName("c").build());
    assertEquals(expectedResult, actualResult);
}
Also used : TableMetadataUnit(org.apache.drill.metastore.components.tables.TableMetadataUnit) Record(org.apache.iceberg.data.Record) GenericRecord(org.apache.iceberg.data.GenericRecord) Test(org.junit.Test) IcebergBaseTest(org.apache.drill.metastore.iceberg.IcebergBaseTest)

Example 19 with TableMetadataUnit

use of org.apache.drill.metastore.components.tables.TableMetadataUnit in project drill by apache.

the class TablesOutputDataTransformer method execute.

@Override
public List<TableMetadataUnit> execute() {
    List<TableMetadataUnit> results = new ArrayList<>();
    for (Map<MethodHandle, Object> valueToSet : valuesToSet()) {
        TableMetadataUnit.Builder builder = TableMetadataUnit.builder();
        for (Map.Entry<MethodHandle, Object> entry : valueToSet.entrySet()) {
            try {
                entry.getKey().invokeWithArguments(builder, entry.getValue());
            } catch (Throwable e) {
                throw new IcebergMetastoreException(String.format("Unable to invoke setter for [%s] using [%s]", TableMetadataUnit.Builder.class.getSimpleName(), entry.getKey()), e);
            }
        }
        results.add(builder.build());
    }
    return results;
}
Also used : IcebergMetastoreException(org.apache.drill.metastore.iceberg.exceptions.IcebergMetastoreException) TableMetadataUnit(org.apache.drill.metastore.components.tables.TableMetadataUnit) ArrayList(java.util.ArrayList) Map(java.util.Map) MethodHandle(java.lang.invoke.MethodHandle)

Example 20 with TableMetadataUnit

use of org.apache.drill.metastore.components.tables.TableMetadataUnit in project drill by apache.

the class TestTablesInputDataTransformer method testValidDataOneRecord.

@Test
public void testValidDataOneRecord() {
    Map<String, String> partitionKeys = new HashMap<>();
    partitionKeys.put("dir0", "2018");
    partitionKeys.put("dir1", "2019");
    List<String> partitionValues = Arrays.asList("a", "b", "c");
    Long lastModifiedTime = System.currentTimeMillis();
    TableMetadataUnit unit = TableMetadataUnit.builder().storagePlugin("dfs").workspace("tmp").tableName("nation").metadataType(MetadataType.TABLE.name()).metadataIdentifier(MetadataInfo.GENERAL_INFO_KEY).partitionKeys(partitionKeys).partitionValues(partitionValues).lastModifiedTime(lastModifiedTime).build();
    InputDataTransformer<TableMetadataUnit> inputDataTransformer = new InputDataTransformer<>(TableMetadataUnit.SCHEMA.unitGetters());
    List<Document> documents = inputDataTransformer.units(Collections.singletonList(unit)).execute();
    Document tableRecord = new Document();
    tableRecord.append("storagePlugin", "dfs");
    tableRecord.append("workspace", "tmp");
    tableRecord.append("tableName", "nation");
    tableRecord.append("metadataType", "TABLE");
    tableRecord.append("metadataIdentifier", MetadataInfo.GENERAL_INFO_KEY);
    assertEquals(tableRecord, documents.get(0).get(MongoConfigConstants.ID));
    assertEquals(partitionKeys, documents.get(0).get("partitionKeys"));
    assertEquals(partitionValues, documents.get(0).get("partitionValues"));
    assertEquals(lastModifiedTime, documents.get(0).get("lastModifiedTime"));
}
Also used : InputDataTransformer(org.apache.drill.metastore.mongo.transform.InputDataTransformer) TableMetadataUnit(org.apache.drill.metastore.components.tables.TableMetadataUnit) HashMap(java.util.HashMap) Document(org.bson.Document) Test(org.junit.Test)

Aggregations

TableMetadataUnit (org.apache.drill.metastore.components.tables.TableMetadataUnit)33 Test (org.junit.Test)26 RdbmsBaseTest (org.apache.drill.metastore.rdbms.RdbmsBaseTest)9 HashMap (java.util.HashMap)8 IcebergBaseTest (org.apache.drill.metastore.iceberg.IcebergBaseTest)8 Document (org.bson.Document)6 Map (java.util.Map)5 GenericRecord (org.apache.iceberg.data.GenericRecord)5 Record (org.apache.iceberg.data.Record)5 ArrayList (java.util.ArrayList)4 SchemaPath (org.apache.drill.common.expression.SchemaPath)4 MetastoreTableInfo (org.apache.drill.metastore.components.tables.MetastoreTableInfo)4 TupleMetadata (org.apache.drill.exec.record.metadata.TupleMetadata)3 InputDataTransformer (org.apache.drill.metastore.iceberg.transform.InputDataTransformer)3 MetadataInfo (org.apache.drill.metastore.metadata.MetadataInfo)3 MetadataType (org.apache.drill.metastore.metadata.MetadataType)3 ColumnStatistics (org.apache.drill.metastore.statistics.ColumnStatistics)3 StatisticsHolder (org.apache.drill.metastore.statistics.StatisticsHolder)3 Condition (org.jooq.Condition)3 MethodHandle (java.lang.invoke.MethodHandle)2