public Table create(IMetaStoreClient client, Configuration conf) throws TException { Table t = build(conf); client.createTable(t); return t; }
@Test(expected = InvalidObjectException.class) public void testCreateTableInvalidTableName() throws Exception { Table table = testTables[0]; table.setTableName("test_table;"); client.createTable(table); }
@Test(expected = InvalidObjectException.class) public void testCreateTableNoSuchDatabase() throws Exception { Table table = testTables[0]; table.setDbName("no_such_database"); client.createTable(table); }
@Test(expected = MetaException.class) public void testCreateTableNullTableName() throws Exception { Table table = testTables[0]; table.setTableName(null); client.createTable(table); }
@Test(expected = MetaException.class) public void testCreateTableNullDatabase() throws Exception { Table table = testTables[0]; table.setDbName(null); client.createTable(table); }
@Test(expected = InvalidObjectException.class) public void testCreateTableEmptyName() throws Exception { Table table = testTables[0]; table.setTableName(""); client.createTable(table); }
@Test(expected = MetaException.class) public void testCreateTableNullStorageDescriptor() throws Exception { Table table = testTables[0]; table.setSd(null); client.createTable(table); }
@Test(expected = AlreadyExistsException.class) public void testCreateTableAlreadyExists() throws Exception { Table table = testTables[0]; table.unsetId(); client.createTable(table); }
@Test(expected = MetaException.class) public void testCreateTableInvalidStorageDescriptorNullColumnType() throws Exception { Table table = getNewTable(); table.getSd().getCols().get(0).setType(null); client.createTable(table); }
@Test(expected = InvalidObjectException.class) public void testCreateTableInvalidStorageDescriptorInvalidColumnType() throws Exception { Table table = getNewTable(); table.getSd().getCols().get(0).setType("xyz"); client.createTable(table); }
private TableMeta createTestTable(String dbName, String tableName, TableType type) throws Exception { Table table = createTable(dbName, tableName, type); client.createTable(table); TableMeta tableMeta = new TableMeta(dbName, tableName, type.name()); tableMeta.setCatName("hive"); return tableMeta; }
@Test(expected = MetaException.class) public void testCreateTableInvalidStorageDescriptorNullColumns() throws Exception { Table table = getNewTable(); table.getSd().setCols(null); client.createTable(table); }
@Test(expected = MetaException.class) public void testCreateTableInvalidStorageDescriptorNullSerdeInfo() throws Exception { Table table = getNewTable(); table.getSd().setSerdeInfo(null); client.createTable(table); }
private TableMeta createTestTable(String dbName, String tableName, TableType type, String comment) throws Exception { Table table = createTable(dbName, tableName, type); table.getParameters().put("comment", comment); client.createTable(table); TableMeta tableMeta = new TableMeta(dbName, tableName, type.name()); tableMeta.setComments(comment); tableMeta.setCatName("hive"); return tableMeta; }
public Table createTestAvroTable(String dbName, String tableName, String tableSdLoc, Optional<String> partitionFieldName, boolean ignoreDbCreation) throws Exception { if (!ignoreDbCreation) { createTestDb(dbName); } Table tbl = org.apache.hadoop.hive.ql.metadata.Table.getEmptyTable(dbName, tableName); tbl.getSd().setLocation(tableSdLoc); tbl.getSd().getSerdeInfo().setSerializationLib(AvroSerDe.class.getName()); tbl.getSd().getSerdeInfo().setParameters(ImmutableMap.of(HiveAvroSerDeManager.SCHEMA_URL, "/tmp/dummy")); if (partitionFieldName.isPresent()) { tbl.addToPartitionKeys(new FieldSchema(partitionFieldName.get(), "string", "some comment")); } this.localMetastoreClient.createTable(tbl); return tbl; }
private Table createTestTable(IMetaStoreClient client, String dbName, String tableName, List<String> partCols, boolean setPartitionLevelPrivilages) throws TException { TableBuilder builder = new TableBuilder() .setDbName(dbName) .setTableName(tableName) .addCol("id", "int") .addCol("name", "string"); partCols.forEach(col -> builder.addPartCol(col, "string")); Table table = builder.build(metaStore.getConf()); if (setPartitionLevelPrivilages) { table.putToParameters("PARTITION_LEVEL_PRIVILEGE", "true"); } client.createTable(table); return table; }
private Table createTestTable(IMetaStoreClient client, String dbName, String tableName, List<String> partCols, boolean setPartitionLevelPrivilages) throws TException { TableBuilder builder = new TableBuilder() .setDbName(dbName) .setTableName(tableName) .addCol("id", "int") .addCol("name", "string"); partCols.forEach(col -> builder.addPartCol(col, "string")); Table table = builder.build(metaStore.getConf()); if (setPartitionLevelPrivilages) { table.putToParameters("PARTITION_LEVEL_PRIVILEGE", "true"); } client.createTable(table); return table; }
private Table createTestTable(IMetaStoreClient client, String dbName, String tableName, List<String> partCols, boolean setPartitionLevelPrivilages) throws Exception { TableBuilder builder = new TableBuilder() .setDbName(dbName) .setTableName(tableName) .addCol("id", "int") .addCol("name", "string"); partCols.forEach(col -> builder.addPartCol(col, "string")); Table table = builder.build(metaStore.getConf()); if (setPartitionLevelPrivilages) { table.putToParameters("PARTITION_LEVEL_PRIVILEGE", "true"); } client.createTable(table); return table; }
public Table createTestAvroTable(String dbName, String tableName, String tableSdLoc, List<String> partitionFieldNames, boolean ignoreDbCreation) throws Exception { if (!ignoreDbCreation) { createTestDb(dbName); } Table tbl = org.apache.hadoop.hive.ql.metadata.Table.getEmptyTable(dbName, tableName); tbl.getSd().setLocation(tableSdLoc); tbl.getSd().getSerdeInfo().setParameters(ImmutableMap.of(HiveAvroSerDeManager.SCHEMA_URL, "/tmp/dummy")); for (String partitionFieldName : partitionFieldNames) { tbl.addToPartitionKeys(new FieldSchema(partitionFieldName, "string", "some comment")); } this.localMetastoreClient.createTable(tbl); return tbl; }
@Test public void testCreateTableDefaultLocationInSpecificDatabase() throws Exception { Table table = new Table(); StorageDescriptor sd = new StorageDescriptor(); List<FieldSchema> cols = new ArrayList<>(); table.setDbName(OTHER_DATABASE); table.setTableName("test_table_2"); cols.add(new FieldSchema("column_name", "int", null)); sd.setCols(cols); sd.setSerdeInfo(new SerDeInfo()); table.setSd(sd); client.createTable(table); Table createdTable = client.getTable(table.getDbName(), table.getTableName()); Assert.assertEquals("Storage descriptor location", metaStore.getWarehouseRoot() + "/" + table.getDbName() + ".db/" + table.getTableName(), createdTable.getSd().getLocation()); }