Search in sources :

Example 1 with TableLikeStageableTableMetadata

use of org.apache.gobblin.data.management.conversion.hive.entities.TableLikeStageableTableMetadata in project incubator-gobblin by apache.

the class HiveMaterializerTest method testMaterializeTablePartition.

@Test
public void testMaterializeTablePartition() throws Exception {
    String destinationTable = "materializeTablePartition";
    File tmpDir = Files.createTempDir();
    tmpDir.deleteOnExit();
    WorkUnit workUnit = HiveMaterializer.viewMaterializationWorkUnit(this.dataset, HiveConverterUtils.StorageFormat.AVRO, new TableLikeStageableTableMetadata(this.dataset.getTable(), this.dbName, destinationTable, tmpDir.getAbsolutePath()), String.format("%s=part1", this.partitionColumn));
    HiveMaterializer hiveMaterializer = new HiveMaterializer(getTaskContextForRun(workUnit));
    hiveMaterializer.run();
    Assert.assertEquals(hiveMaterializer.getWorkingState(), WorkUnitState.WorkingState.SUCCESSFUL);
    hiveMaterializer.commit();
    Assert.assertEquals(hiveMaterializer.getWorkingState(), WorkUnitState.WorkingState.SUCCESSFUL);
    List<List<String>> allTable = executeStatementAndGetResults(this.jdbcConnector, String.format("SELECT * FROM %s.%s", this.dbName, destinationTable), 3);
    Assert.assertEquals(allTable.size(), 4);
    Assert.assertEquals(allTable.stream().map(l -> l.get(0)).collect(Collectors.toList()), Lists.newArrayList("101", "102", "103", "104"));
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) WorkUnit(org.apache.gobblin.source.workunit.WorkUnit) TableLikeStageableTableMetadata(org.apache.gobblin.data.management.conversion.hive.entities.TableLikeStageableTableMetadata) File(java.io.File) Test(org.testng.annotations.Test)

Example 2 with TableLikeStageableTableMetadata

use of org.apache.gobblin.data.management.conversion.hive.entities.TableLikeStageableTableMetadata in project incubator-gobblin by apache.

the class HiveMaterializerTest method testMaterializeTable.

@Test
public void testMaterializeTable() throws Exception {
    String destinationTable = "materializeTable";
    File tmpDir = Files.createTempDir();
    tmpDir.deleteOnExit();
    WorkUnit workUnit = HiveMaterializer.viewMaterializationWorkUnit(this.dataset, HiveConverterUtils.StorageFormat.AVRO, new TableLikeStageableTableMetadata(this.dataset.getTable(), this.dbName, destinationTable, tmpDir.getAbsolutePath()), null);
    HiveMaterializer hiveMaterializer = new HiveMaterializer(getTaskContextForRun(workUnit));
    hiveMaterializer.run();
    Assert.assertEquals(hiveMaterializer.getWorkingState(), WorkUnitState.WorkingState.SUCCESSFUL);
    hiveMaterializer.commit();
    Assert.assertEquals(hiveMaterializer.getWorkingState(), WorkUnitState.WorkingState.SUCCESSFUL);
    List<List<String>> allTable = executeStatementAndGetResults(this.jdbcConnector, String.format("SELECT * FROM %s.%s", this.dbName, destinationTable), 3);
    Assert.assertEquals(allTable.size(), 8);
    Assert.assertEquals(allTable.stream().map(l -> l.get(0)).collect(Collectors.toList()), Lists.newArrayList("101", "102", "103", "104", "201", "202", "203", "204"));
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) WorkUnit(org.apache.gobblin.source.workunit.WorkUnit) TableLikeStageableTableMetadata(org.apache.gobblin.data.management.conversion.hive.entities.TableLikeStageableTableMetadata) File(java.io.File) Test(org.testng.annotations.Test)

Example 3 with TableLikeStageableTableMetadata

use of org.apache.gobblin.data.management.conversion.hive.entities.TableLikeStageableTableMetadata in project incubator-gobblin by apache.

the class HiveMaterializerTest method testCopyTable.

@Test
public void testCopyTable() throws Exception {
    String destinationTable = "copyTable";
    File tmpDir = Files.createTempDir();
    tmpDir.deleteOnExit();
    WorkUnit workUnit = HiveMaterializer.tableCopyWorkUnit(this.dataset, new TableLikeStageableTableMetadata(this.dataset.getTable(), this.dbName, destinationTable, tmpDir.getAbsolutePath()), String.format("%s=part1", this.partitionColumn));
    HiveMaterializer hiveMaterializer = new HiveMaterializer(getTaskContextForRun(workUnit));
    hiveMaterializer.run();
    Assert.assertEquals(hiveMaterializer.getWorkingState(), WorkUnitState.WorkingState.SUCCESSFUL);
    hiveMaterializer.commit();
    Assert.assertEquals(hiveMaterializer.getWorkingState(), WorkUnitState.WorkingState.SUCCESSFUL);
    List<List<String>> allTable = executeStatementAndGetResults(this.jdbcConnector, String.format("SELECT * FROM %s.%s", this.dbName, destinationTable), 3);
    Assert.assertEquals(allTable.size(), 4);
    Assert.assertEquals(allTable.stream().map(l -> l.get(0)).collect(Collectors.toList()), Lists.newArrayList("101", "102", "103", "104"));
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) WorkUnit(org.apache.gobblin.source.workunit.WorkUnit) TableLikeStageableTableMetadata(org.apache.gobblin.data.management.conversion.hive.entities.TableLikeStageableTableMetadata) File(java.io.File) Test(org.testng.annotations.Test)

Example 4 with TableLikeStageableTableMetadata

use of org.apache.gobblin.data.management.conversion.hive.entities.TableLikeStageableTableMetadata in project incubator-gobblin by apache.

the class HiveMaterializerTest method testMaterializeView.

@Test
public void testMaterializeView() throws Exception {
    String destinationTable = "materializeView";
    File tmpDir = Files.createTempDir();
    tmpDir.deleteOnExit();
    String viewName = "myView";
    this.jdbcConnector.executeStatements(String.format("CREATE VIEW %s.%s AS SELECT * FROM %s.%s WHERE name = 'foo'", this.dbName, viewName, this.dbName, this.sourceTableName));
    Table view;
    try (AutoReturnableObject<IMetaStoreClient> client = pool.getClient()) {
        view = new Table(client.get().getTable(this.dbName, viewName));
    }
    HiveDataset viewDataset = new HiveDataset(FileSystem.getLocal(new Configuration()), pool, view, new Properties());
    WorkUnit workUnit = HiveMaterializer.viewMaterializationWorkUnit(viewDataset, HiveConverterUtils.StorageFormat.AVRO, new TableLikeStageableTableMetadata(viewDataset.getTable(), this.dbName, destinationTable, tmpDir.getAbsolutePath()), null);
    HiveMaterializer hiveMaterializer = new HiveMaterializer(getTaskContextForRun(workUnit));
    hiveMaterializer.run();
    Assert.assertEquals(hiveMaterializer.getWorkingState(), WorkUnitState.WorkingState.SUCCESSFUL);
    hiveMaterializer.commit();
    Assert.assertEquals(hiveMaterializer.getWorkingState(), WorkUnitState.WorkingState.SUCCESSFUL);
    List<List<String>> allTable = executeStatementAndGetResults(this.jdbcConnector, String.format("SELECT * FROM %s.%s", this.dbName, destinationTable), 3);
    Assert.assertEquals(allTable.size(), 4);
    Assert.assertEquals(allTable.stream().map(l -> l.get(0)).collect(Collectors.toList()), Lists.newArrayList("101", "103", "201", "203"));
}
Also used : Table(org.apache.hadoop.hive.ql.metadata.Table) Configuration(org.apache.hadoop.conf.Configuration) IMetaStoreClient(org.apache.hadoop.hive.metastore.IMetaStoreClient) Properties(java.util.Properties) HiveDataset(org.apache.gobblin.data.management.copy.hive.HiveDataset) ArrayList(java.util.ArrayList) List(java.util.List) WorkUnit(org.apache.gobblin.source.workunit.WorkUnit) TableLikeStageableTableMetadata(org.apache.gobblin.data.management.conversion.hive.entities.TableLikeStageableTableMetadata) File(java.io.File) Test(org.testng.annotations.Test)

Example 5 with TableLikeStageableTableMetadata

use of org.apache.gobblin.data.management.conversion.hive.entities.TableLikeStageableTableMetadata in project incubator-gobblin by apache.

the class HiveMaterializerTest method testMaterializeQuery.

@Test
public void testMaterializeQuery() throws Exception {
    String destinationTable = "materializeQuery";
    File tmpDir = Files.createTempDir();
    tmpDir.deleteOnExit();
    WorkUnit workUnit = HiveMaterializer.queryResultMaterializationWorkUnit(String.format("SELECT * FROM %s.%s WHERE name = 'foo'", this.dbName, this.sourceTableName), HiveConverterUtils.StorageFormat.AVRO, new TableLikeStageableTableMetadata(this.dataset.getTable(), this.dbName, destinationTable, tmpDir.getAbsolutePath()));
    HiveMaterializer hiveMaterializer = new HiveMaterializer(getTaskContextForRun(workUnit));
    hiveMaterializer.run();
    Assert.assertEquals(hiveMaterializer.getWorkingState(), WorkUnitState.WorkingState.SUCCESSFUL);
    hiveMaterializer.commit();
    Assert.assertEquals(hiveMaterializer.getWorkingState(), WorkUnitState.WorkingState.SUCCESSFUL);
    List<List<String>> allTable = executeStatementAndGetResults(this.jdbcConnector, String.format("SELECT * FROM %s.%s", this.dbName, destinationTable), 3);
    Assert.assertEquals(allTable.size(), 4);
    Assert.assertEquals(allTable.stream().map(l -> l.get(0)).collect(Collectors.toList()), Lists.newArrayList("101", "103", "201", "203"));
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) WorkUnit(org.apache.gobblin.source.workunit.WorkUnit) TableLikeStageableTableMetadata(org.apache.gobblin.data.management.conversion.hive.entities.TableLikeStageableTableMetadata) File(java.io.File) Test(org.testng.annotations.Test)

Aggregations

File (java.io.File)5 ArrayList (java.util.ArrayList)5 List (java.util.List)5 TableLikeStageableTableMetadata (org.apache.gobblin.data.management.conversion.hive.entities.TableLikeStageableTableMetadata)5 WorkUnit (org.apache.gobblin.source.workunit.WorkUnit)5 Test (org.testng.annotations.Test)5 Properties (java.util.Properties)1 HiveDataset (org.apache.gobblin.data.management.copy.hive.HiveDataset)1 Configuration (org.apache.hadoop.conf.Configuration)1 IMetaStoreClient (org.apache.hadoop.hive.metastore.IMetaStoreClient)1 Table (org.apache.hadoop.hive.ql.metadata.Table)1