Search in sources :

Example 71 with TableBuilder

use of org.apache.hadoop.hive.metastore.client.builder.TableBuilder in project hive by apache.

the class TestSessionHiveMetastoreClientGetPartitionsTempTable method createTestTable.

@Override
protected Table createTestTable(IMetaStoreClient client, String dbName, String tableName, List<String> partCols, boolean setPartitionLevelPrivileges) throws TException {
    TableBuilder builder = new TableBuilder().setDbName(dbName).setTableName(tableName).addCol("id", "int").addCol("name", "string").setTemporary(true);
    partCols.forEach(col -> builder.addPartCol(col, "string"));
    Table table = builder.build(conf);
    if (setPartitionLevelPrivileges) {
        table.putToParameters(PART_PRIV, "true");
    }
    client.createTable(table);
    return table;
}
Also used : Table(org.apache.hadoop.hive.metastore.api.Table) TableBuilder(org.apache.hadoop.hive.metastore.client.builder.TableBuilder)

Example 72 with TableBuilder

use of org.apache.hadoop.hive.metastore.client.builder.TableBuilder in project hive by apache.

the class TestSchemaToolCatalogOps method moveTable.

@Test
public void moveTable() throws TException, HiveMetaException {
    String toCatName = "moveTableCat";
    String toDbName = "moveTableDb";
    String tableName = "moveTableTable";
    String partVal = "moveTableKey";
    new CatalogBuilder().setName(toCatName).setLocation("file:///tmp").create(client);
    new DatabaseBuilder().setCatalogName(toCatName).setName(toDbName).create(client, conf);
    Table table = new TableBuilder().setTableName(tableName).addCol("a", "int").addPartCol("p", "string").create(client, conf);
    new PartitionBuilder().inTable(table).addValue(partVal).addToTable(client, conf);
    String argsMoveTable = String.format("-moveTable %s -fromCatalog %s -toCatalog %s -fromDatabase %s -toDatabase %s", tableName, DEFAULT_CATALOG_NAME, toCatName, DEFAULT_DATABASE_NAME, toDbName);
    execute(new SchemaToolTaskMoveTable(), argsMoveTable);
    Table fetchedTable = client.getTable(toCatName, toDbName, tableName);
    Assert.assertNotNull(fetchedTable);
    Assert.assertEquals(toCatName.toLowerCase(), fetchedTable.getCatName());
    Assert.assertEquals(toDbName.toLowerCase(), fetchedTable.getDbName());
    Partition fetchedPart = client.getPartition(toCatName, toDbName, tableName, Collections.singletonList(partVal));
    Assert.assertNotNull(fetchedPart);
    Assert.assertEquals(toCatName.toLowerCase(), fetchedPart.getCatName());
    Assert.assertEquals(toDbName.toLowerCase(), fetchedPart.getDbName());
    Assert.assertEquals(tableName.toLowerCase(), fetchedPart.getTableName());
}
Also used : DatabaseBuilder(org.apache.hadoop.hive.metastore.client.builder.DatabaseBuilder) Partition(org.apache.hadoop.hive.metastore.api.Partition) Table(org.apache.hadoop.hive.metastore.api.Table) PartitionBuilder(org.apache.hadoop.hive.metastore.client.builder.PartitionBuilder) CatalogBuilder(org.apache.hadoop.hive.metastore.client.builder.CatalogBuilder) TableBuilder(org.apache.hadoop.hive.metastore.client.builder.TableBuilder) Test(org.junit.Test)

Example 73 with TableBuilder

use of org.apache.hadoop.hive.metastore.client.builder.TableBuilder in project hive by apache.

the class TestSchemaToolCatalogOps method moveTableToNonExistentDb.

@Test
public void moveTableToNonExistentDb() throws TException, HiveMetaException {
    String tableName = "doomedToWander";
    new TableBuilder().setTableName(tableName).addCol("a", "int").create(client, conf);
    try {
        String argsMoveTable = String.format("-moveTable %s -fromCatalog %s -toCatalog %s -fromDatabase %s -toDatabase nosuch", tableName, DEFAULT_CATALOG_NAME, DEFAULT_CATALOG_NAME, DEFAULT_DATABASE_NAME);
        execute(new SchemaToolTaskMoveTable(), argsMoveTable);
        Assert.fail("Attempt to move table to non-existent table should have failed.");
    } catch (HiveMetaException e) {
    // good
    }
    // Make sure nothing really moved
    Set<String> tableNames = new HashSet<>(client.getAllTables(DEFAULT_CATALOG_NAME, DEFAULT_DATABASE_NAME));
    Assert.assertTrue(tableNames.contains(tableName.toLowerCase()));
}
Also used : HiveMetaException(org.apache.hadoop.hive.metastore.HiveMetaException) TableBuilder(org.apache.hadoop.hive.metastore.client.builder.TableBuilder) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 74 with TableBuilder

use of org.apache.hadoop.hive.metastore.client.builder.TableBuilder in project hive by apache.

the class TestSchemaToolCatalogOps method moveTableWithExistingTableOfSameNameAlreadyInTargetDatabase.

@Test
public void moveTableWithExistingTableOfSameNameAlreadyInTargetDatabase() throws TException, HiveMetaException {
    String toDbName = "clobberTableDb";
    String tableName = "clobberTableTable";
    Database toDb = new DatabaseBuilder().setName(toDbName).create(client, conf);
    new TableBuilder().setTableName(tableName).addCol("a", "int").create(client, conf);
    new TableBuilder().inDb(toDb).setTableName(tableName).addCol("b", "varchar(32)").create(client, conf);
    try {
        String argsMoveTable = String.format("-moveTable %s -fromCatalog %s -toCatalog %s -fromDatabase %s -toDatabase %s", tableName, DEFAULT_CATALOG_NAME, DEFAULT_CATALOG_NAME, DEFAULT_DATABASE_NAME, toDbName);
        execute(new SchemaToolTaskMoveTable(), argsMoveTable);
        Assert.fail("Attempt to move table should have failed.");
    } catch (HiveMetaException e) {
    // good
    }
    // Make sure nothing really moved
    Set<String> tableNames = new HashSet<>(client.getAllTables(DEFAULT_CATALOG_NAME, DEFAULT_DATABASE_NAME));
    Assert.assertTrue(tableNames.contains(tableName.toLowerCase()));
    // Make sure the table in the target database didn't get clobbered
    Table fetchedTable = client.getTable(DEFAULT_CATALOG_NAME, toDbName, tableName);
    Assert.assertEquals("b", fetchedTable.getSd().getCols().get(0).getName());
}
Also used : DatabaseBuilder(org.apache.hadoop.hive.metastore.client.builder.DatabaseBuilder) Table(org.apache.hadoop.hive.metastore.api.Table) Database(org.apache.hadoop.hive.metastore.api.Database) HiveMetaException(org.apache.hadoop.hive.metastore.HiveMetaException) TableBuilder(org.apache.hadoop.hive.metastore.client.builder.TableBuilder) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 75 with TableBuilder

use of org.apache.hadoop.hive.metastore.client.builder.TableBuilder in project hive by apache.

the class TestMetaStoreMultipleEncryptionZones method dropExternalTableWithoutEncryptionZonesForCm.

@Test
public void dropExternalTableWithoutEncryptionZonesForCm() throws Throwable {
    String dbName = "simpdb2";
    String tblName = "simptbl";
    String typeName = "Person";
    silentDropDatabase(dbName);
    new DatabaseBuilder().setName(dbName).addParam("repl.source.for", "1, 2, 3").create(client, hiveConf);
    client.dropType(typeName);
    Type typ1 = new Type();
    typ1.setName(typeName);
    typ1.setFields(new ArrayList<>(2));
    typ1.getFields().add(new FieldSchema("name", ColumnType.STRING_TYPE_NAME, ""));
    typ1.getFields().add(new FieldSchema("income", ColumnType.INT_TYPE_NAME, ""));
    client.createType(typ1);
    new TableBuilder().setDbName(dbName).setTableName(tblName).setCols(typ1.getFields()).setNumBuckets(1).addBucketCol("name").addTableParam("EXTERNAL", "true").addTableParam("external.table.purge", "true").addStorageDescriptorParam("test_param_1", "Use this for comments etc").create(client, hiveConf);
    Table tbl = client.getTable(dbName, tblName);
    Assert.assertNotNull(tbl);
    Path dirDb = new Path(warehouse.getWhRoot(), dbName + ".db");
    warehouseFs.mkdirs(dirDb);
    Path dirTbl1 = new Path(dirDb, tblName);
    warehouseFs.mkdirs(dirTbl1);
    Path part11 = new Path(dirTbl1, "part1");
    createFile(part11, "testClearer11");
    boolean exceptionThrown = false;
    try {
        client.dropTable(dbName, tblName);
    } catch (Exception e) {
        exceptionThrown = true;
    }
    assertFalse(exceptionThrown);
    assertFalse(warehouseFs.exists(part11));
    try {
        client.getTable(dbName, tblName);
    } catch (NoSuchObjectException e) {
        exceptionThrown = true;
    }
    assertTrue(exceptionThrown);
}
Also used : Path(org.apache.hadoop.fs.Path) DatabaseBuilder(org.apache.hadoop.hive.metastore.client.builder.DatabaseBuilder) Type(org.apache.hadoop.hive.metastore.api.Type) RecycleType(org.apache.hadoop.hive.metastore.ReplChangeManager.RecycleType) Table(org.apache.hadoop.hive.metastore.api.Table) FieldSchema(org.apache.hadoop.hive.metastore.api.FieldSchema) NoSuchObjectException(org.apache.hadoop.hive.metastore.api.NoSuchObjectException) TableBuilder(org.apache.hadoop.hive.metastore.client.builder.TableBuilder) MetaException(org.apache.hadoop.hive.metastore.api.MetaException) TException(org.apache.thrift.TException) IOException(java.io.IOException) RemoteException(org.apache.hadoop.ipc.RemoteException) NoSuchObjectException(org.apache.hadoop.hive.metastore.api.NoSuchObjectException) InvalidOperationException(org.apache.hadoop.hive.metastore.api.InvalidOperationException) Test(org.junit.Test)

Aggregations

TableBuilder (org.apache.hadoop.hive.metastore.client.builder.TableBuilder)136 Table (org.apache.hadoop.hive.metastore.api.Table)111 Test (org.junit.Test)92 DatabaseBuilder (org.apache.hadoop.hive.metastore.client.builder.DatabaseBuilder)81 Database (org.apache.hadoop.hive.metastore.api.Database)40 Partition (org.apache.hadoop.hive.metastore.api.Partition)36 NoSuchObjectException (org.apache.hadoop.hive.metastore.api.NoSuchObjectException)35 PartitionBuilder (org.apache.hadoop.hive.metastore.client.builder.PartitionBuilder)33 MetastoreCheckinTest (org.apache.hadoop.hive.metastore.annotation.MetastoreCheckinTest)31 FieldSchema (org.apache.hadoop.hive.metastore.api.FieldSchema)30 ArrayList (java.util.ArrayList)28 MetaException (org.apache.hadoop.hive.metastore.api.MetaException)27 SourceTable (org.apache.hadoop.hive.metastore.api.SourceTable)25 CatalogBuilder (org.apache.hadoop.hive.metastore.client.builder.CatalogBuilder)23 Path (org.apache.hadoop.fs.Path)19 Catalog (org.apache.hadoop.hive.metastore.api.Catalog)19 Type (org.apache.hadoop.hive.metastore.api.Type)19 InvalidOperationException (org.apache.hadoop.hive.metastore.api.InvalidOperationException)17 TException (org.apache.thrift.TException)16 IOException (java.io.IOException)15