Search in sources :

Example 11 with ColumnSpec

use of com.thinkbiganalytics.util.ColumnSpec in project kylo by Teradata.

the class TableMergeSyncSupportTest method testMergePartitionPKWithEmptyTargetTable.

@Test
public /**
 * Tests the merge partition with empty target table
 */
void testMergePartitionPKWithEmptyTargetTable() throws Exception {
    List<String> results = fetchEmployees(targetSchema, targetTable);
    assertEquals(0, results.size());
    ColumnSpec columnSpec1 = new ColumnSpec("id", "String", "", true, false, false);
    ColumnSpec columnSpec2 = new ColumnSpec("name", "String", "", false, false, false);
    ColumnSpec[] columnSpecs = Arrays.asList(columnSpec1, columnSpec2).toArray(new ColumnSpec[0]);
    // Call merge
    mergeSyncSupport.doPKMerge(sourceSchema, sourceTable, targetSchema, targetTable, spec, processingPartition, columnSpecs);
    // We should have 4 records
    results = fetchEmployees(targetSchema, targetTable);
    assertEquals(4, results.size());
}
Also used : ColumnSpec(com.thinkbiganalytics.util.ColumnSpec) Test(org.junit.Test)

Example 12 with ColumnSpec

use of com.thinkbiganalytics.util.ColumnSpec in project kylo by Teradata.

the class TableRegisterSupportTest method testProfileTableCreateS3.

@Test
public void testProfileTableCreateS3() {
    ColumnSpec[] specs = ColumnSpec.createFromString("id|bigint|my comment\nname|string\ncompany|string|some description\nzip|string\nphone|string\nemail|string\ncountry|string\nhired|date");
    ColumnSpec[] parts = ColumnSpec.createFromString("year|int\ncountry|string");
    TableRegisterConfiguration conf = new TableRegisterConfiguration("s3a://testBucket/model.db/", "s3a://testBucket/model.db/", "s3a://testBucket/app/warehouse/");
    TableRegisterSupport support = new TableRegisterSupport(connection, conf);
    String ddl = support.createDDL("bar", "employee", specs, parts, "ROW FORMAT SERDE 'org.apache.hadoop.hive.serde2.OpenCSVSerde'", "stored as orc", "tblproperties (\"orc.compress\"=\"SNAPPY\")", TableType.PROFILE);
    String expectedDDL = "CREATE TABLE IF NOT EXISTS `bar`.`employee_" + TableType.PROFILE.toString().toLowerCase() + "` ( `columnname` string,`metrictype` string,`metricvalue` string)   PARTITIONED BY (`processing_dttm` string)  stored as orc LOCATION 's3a://testBucket/model.db/bar/employee/" + TableType.PROFILE.toString().toLowerCase() + "'";
    assertEquals("DDL do not match", expectedDDL, ddl);
}
Also used : ColumnSpec(com.thinkbiganalytics.util.ColumnSpec) TableRegisterConfiguration(com.thinkbiganalytics.util.TableRegisterConfiguration) Test(org.junit.Test)

Example 13 with ColumnSpec

use of com.thinkbiganalytics.util.ColumnSpec in project kylo by Teradata.

the class TableRegisterSupportTest method testTableCreate.

@Test
public void testTableCreate() {
    ColumnSpec[] specs = ColumnSpec.createFromString("id|bigint|my comment\nname|string\ncompany|string|some description\nzip|string\nphone|string\nemail|string\ncountry|string\nhired|date");
    ColumnSpec[] parts = ColumnSpec.createFromString("year|int\ncountry|string");
    TableRegisterSupport support = new TableRegisterSupport(connection);
    TableType[] tableTypes = new TableType[] { TableType.FEED, TableType.INVALID, TableType.VALID, TableType.MASTER };
    for (TableType tableType : tableTypes) {
        String ddl = support.createDDL("bar", "employee", specs, parts, "ROW FORMAT SERDE 'org.apache.hadoop.hive.serde2.OpenCSVSerde'", "stored as orc", "tblproperties (\"orc.compress\"=\"SNAPPY\")", tableType);
        // Hack to make a legal file root
        ddl = ddl.replace("LOCATION '", "LOCATION '${hiveconf:MY.HDFS.DIR}");
        hiveShell.execute(ddl);
    }
}
Also used : ColumnSpec(com.thinkbiganalytics.util.ColumnSpec) TableType(com.thinkbiganalytics.util.TableType) Test(org.junit.Test)

Example 14 with ColumnSpec

use of com.thinkbiganalytics.util.ColumnSpec in project kylo by Teradata.

the class TableRegisterSupportTest method testRemovingColumns.

@Test
public void testRemovingColumns() {
    ColumnSpec[] feedSpecs = ColumnSpec.createFromString("id|string|my comment|0|0|0|id\n" + "name|string||0|0|0|name\n" + "company|string|some description|0|0|0|change_company\n" + "zip|string||0|0|0|zip_code\n" + "phone|string\n" + "email|string\n" + "country|string\n" + "hired|string");
    ColumnSpec[] targetSpecs = ColumnSpec.createFromString("id|bigint|my comment|0|0|0|id\n" + "name|string||0|0|0|name\n" + "change_company|string|some description|0|0|0|company\n" + "zip_code|string||0|0|0|zip\n" + "email|string\n" + "hired|date||0|0|0|hired");
    ColumnSpec[] parts = ColumnSpec.createFromString("year|int\ncountry|string");
    TableRegisterConfiguration conf = new TableRegisterConfiguration();
    TableRegisterSupport support = new TableRegisterSupport(connection, conf);
    ColumnSpec[] invalidColumnSpecs = support.adjustInvalidColumnSpec(feedSpecs, targetSpecs);
    assertEquals(targetSpecs.length, invalidColumnSpecs.length);
    Map<String, ColumnSpec> feedColumnSpecMap = Arrays.asList(feedSpecs).stream().collect(Collectors.toMap(ColumnSpec::getName, Function.identity()));
    for (ColumnSpec invalid : invalidColumnSpecs) {
        if (StringUtils.isNotBlank(invalid.getOtherColumnName())) {
            assertEquals(invalid.getDataType(), feedColumnSpecMap.get(invalid.getOtherColumnName()).getDataType());
        }
    }
    TableType[] tableTypes = new TableType[] { TableType.FEED, TableType.INVALID, TableType.VALID, TableType.MASTER };
    for (TableType tableType : tableTypes) {
        ColumnSpec[] useColumnSpecs = targetSpecs;
        if (tableType == TableType.INVALID) {
            useColumnSpecs = invalidColumnSpecs;
        } else if (tableType == TableType.FEED) {
            useColumnSpecs = feedSpecs;
        }
        String ddl = support.createDDL("source_table", "target_table", useColumnSpecs, parts, "ROW FORMAT SERDE 'org.apache.hadoop.hive.serde2.OpenCSVSerde'", "stored as orc", "tblproperties (\"orc.compress\"=\"SNAPPY\")", tableType);
        int i = 0;
    }
}
Also used : ColumnSpec(com.thinkbiganalytics.util.ColumnSpec) TableType(com.thinkbiganalytics.util.TableType) TableRegisterConfiguration(com.thinkbiganalytics.util.TableRegisterConfiguration) Test(org.junit.Test)

Aggregations

ColumnSpec (com.thinkbiganalytics.util.ColumnSpec)14 Test (org.junit.Test)9 TableRegisterConfiguration (com.thinkbiganalytics.util.TableRegisterConfiguration)5 TableType (com.thinkbiganalytics.util.TableType)5 StringUtils (org.apache.commons.lang3.StringUtils)5 PartitionSpec (com.thinkbiganalytics.util.PartitionSpec)4 SQLException (java.sql.SQLException)4 FlowFile (org.apache.nifi.flowfile.FlowFile)4 HiveUtils (com.thinkbiganalytics.hive.util.HiveUtils)3 ThriftService (com.thinkbiganalytics.nifi.v2.thrift.ThriftService)3 Connection (java.sql.Connection)3 Arrays (java.util.Arrays)3 HashSet (java.util.HashSet)3 List (java.util.List)3 ProcessException (org.apache.nifi.processor.exception.ProcessException)3 HiveShell (com.klarna.hiverunner.HiveShell)2 StandaloneHiveRunner (com.klarna.hiverunner.StandaloneHiveRunner)2 HiveProperties (com.klarna.hiverunner.annotations.HiveProperties)2 HiveRunnerSetup (com.klarna.hiverunner.annotations.HiveRunnerSetup)2 HiveSQL (com.klarna.hiverunner.annotations.HiveSQL)2