@Test public void testRenameTable() throws Exception { HCatClient client = HCatClient.create(new Configuration(hcatConf)); String tableName = "temptable"; String newName = "mytable"; client.dropTable(null, tableName, true); client.dropTable(null, newName, true); ArrayList<HCatFieldSchema> cols = new ArrayList<HCatFieldSchema>(); cols.add(new HCatFieldSchema("id", Type.INT, "id columns")); cols.add(new HCatFieldSchema("value", Type.STRING, "id columns")); HCatCreateTableDesc tableDesc = HCatCreateTableDesc .create(null, tableName, cols).fileFormat("rcfile").build(); client.createTable(tableDesc); client.renameTable(null, tableName, newName); try { client.getTable(null, tableName); } catch (HCatException exp) { assertTrue("Unexpected exception message: " + exp.getMessage(), exp.getMessage().contains("NoSuchObjectException while fetching table")); } HCatTable newTable = client.getTable(null, newName); assertTrue(newTable != null); assertTrue(newTable.getTableName().equals(newName)); client.close(); }
.create(null, newName, cols).fileFormat("rcfile").build(); client.createTable(tableDesc2); HCatTable newTable = client.getTable(null, newName); assertTrue(newTable != null); assertTrue(newTable.getTableName().equalsIgnoreCase(newName));
@Test public void testPartitionSchema() throws Exception { try { HCatClient client = HCatClient.create(new Configuration(hcatConf)); final String dbName = "myDb"; final String tableName = "myTable"; client.dropDatabase(dbName, true, HCatClient.DropDBMode.CASCADE); client.createDatabase(HCatCreateDBDesc.create(dbName).build()); List<HCatFieldSchema> columnSchema = Arrays.asList(new HCatFieldSchema("foo", Type.INT, ""), new HCatFieldSchema("bar", Type.STRING, "")); List<HCatFieldSchema> partitionSchema = Arrays.asList(new HCatFieldSchema("dt", Type.STRING, ""), new HCatFieldSchema("grid", Type.STRING, "")); client.createTable(HCatCreateTableDesc.create(dbName, tableName, columnSchema).partCols(partitionSchema).build()); HCatTable table = client.getTable(dbName, tableName); List<HCatFieldSchema> partitionColumns = table.getPartCols(); assertArrayEquals("Didn't get expected partition-schema back from the HCatTable.", partitionSchema.toArray(), partitionColumns.toArray()); client.dropDatabase(dbName, false, HCatClient.DropDBMode.CASCADE); } catch (Exception unexpected) { LOG.error("Unexpected exception!", unexpected); assertTrue("Unexpected exception! " + unexpected.getMessage(), false); } }
@Test public void testUpdateTableSchema() throws Exception { try { HCatClient client = HCatClient.create(new Configuration(hcatConf)); final String dbName = "testUpdateTableSchema_DBName"; final String tableName = "testUpdateTableSchema_TableName"; client.dropDatabase(dbName, true, HCatClient.DropDBMode.CASCADE); client.createDatabase(HCatCreateDBDesc.create(dbName).build()); List<HCatFieldSchema> oldSchema = Arrays.asList(new HCatFieldSchema("foo", Type.INT, ""), new HCatFieldSchema("bar", Type.STRING, "")); client.createTable(HCatCreateTableDesc.create(dbName, tableName, oldSchema).build()); List<HCatFieldSchema> newSchema = Arrays.asList(new HCatFieldSchema("completely", Type.DOUBLE, ""), new HCatFieldSchema("new", Type.STRING, ""), new HCatFieldSchema("fields", Type.STRING, "")); client.updateTableSchema(dbName, tableName, newSchema); assertArrayEquals(newSchema.toArray(), client.getTable(dbName, tableName).getCols().toArray()); client.dropDatabase(dbName, false, HCatClient.DropDBMode.CASCADE); } catch (Exception exception) { LOG.error("Unexpected exception.", exception); assertTrue("Unexpected exception: " + exception.getMessage(), false); } }
client.createTable(tableDesc); client.getTable("foo", tableName); } catch (Exception exp) { isExceptionCaught = true; .create(null, newName, cols).fileFormat("rcfile").build(); client.createTable(tableDesc2); HCatTable newTable = client.getTable(null, newName); assertTrue(newTable != null); assertTrue(newTable.getTableName().equalsIgnoreCase(newName));
.create(db, tableOne, cols).fileFormat("rcfile").build(); client.createTable(tableDesc); HCatTable table1 = client.getTable(db, tableOne); assertTrue(table1.getInputFileFormat().equalsIgnoreCase( RCFileInputFormat.class.getName())); mapKeysTerminatedBy('\004').collectionItemsTerminatedBy('\005').nullDefinedAs('\006').build(); client.createTable(tableDesc2); HCatTable table2 = client.getTable(db, tableTwo); assertTrue("Expected TextInputFormat, but got: " + table2.getInputFileFormat(), table2.getInputFileFormat().equalsIgnoreCase(TextInputFormat.class.getName())); tableThree, cols).fileFormat("orcfile").build(); client.createTable(tableDesc3); HCatTable table3 = client.getTable(db, tableThree); assertTrue(table3.getInputFileFormat().equalsIgnoreCase( OrcInputFormat.class.getName()));
table = client.getTable(dbName, tableName); assertNotNull("The created just now can't be null.", table);
table = client.getTable(dbName, tableName); assertNotNull("Table couldn't be queried for. ", table);
table = client.getTable(dbName, tableName);
HCatTable t1 = client.getTable(dbName, tableName); assertNotNull(t1); HCatTable t2 = client.getTable(dbName,tableName); assertNotNull(t2); HCatTable t_del = client.getTable(dbName, tableName); } catch (Exception e) { onfe = e; HCatTable t3 = client.getTable(dbName, tableName); assertNotNull(t3); HCatTable t_del = client.getTable(dbName, tableName); } catch (Exception e) { onfe2 = e;
/** * This test tests that a plain table instantiation matches what hive says an * empty table create should look like. * @throws Exception */ @Test public void testEmptyTableInstantiation() throws Exception { HCatClient client = HCatClient.create(new Configuration(hcatConf)); String dbName = "default"; String tblName = "testEmptyCreate"; ArrayList<HCatFieldSchema> cols = new ArrayList<HCatFieldSchema>(); cols.add(new HCatFieldSchema("id", Type.INT, "id comment")); cols.add(new HCatFieldSchema("value", Type.STRING, "value comment")); client.dropTable(dbName, tblName, true); // Create a minimalistic table client.createTable(HCatCreateTableDesc .create(new HCatTable(dbName, tblName).cols(cols), false) .build()); HCatTable tCreated = client.getTable(dbName, tblName); org.apache.hadoop.hive.metastore.api.Table emptyTable = Table.getEmptyTable(dbName, tblName); Map<String, String> createdProps = tCreated.getTblProps(); Map<String, String> emptyProps = emptyTable.getParameters(); mapEqualsContainedIn(emptyProps, createdProps); // Test sd params - we check that all the parameters in an empty table // are retained as-is. We may add beyond it, but not change values for // any parameters that hive defines for an empty table. Map<String, String> createdSdParams = tCreated.getSerdeParams(); Map<String, String> emptySdParams = emptyTable.getSd().getSerdeInfo().getParameters(); mapEqualsContainedIn(emptySdParams, createdSdParams); }
sourceTable = sourceMetaStore().getTable(dbName, tableName); assertNotNull("Table couldn't be queried for. ", sourceTable); targetTable = targetMetaStore().getTable(dbName, tableName); assertEquals("Table after deserialization should have been identical to sourceTable.", HCatTable.NO_DIFF, sourceTable.diff(targetTable)); .serdeParam(serdeConstants.FIELD_DELIM, Character.toString('\001')); sourceMetaStore().updateTableSchema(dbName, tableName, sourceTable); sourceTable = sourceMetaStore().getTable(dbName, tableName); targetTable = targetMetaStore().getTable(dbName, tableName);
HCatTable table2Created = sourceMetastore.getTable(dbName,tblName2);
HCatTable tableCreated = client.getTable(dbName, tableName); assertNotNull(tableCreated);
sourceTable = sourceMetaStore().getTable(dbName, tableName); assertNotNull("Table couldn't be queried for. ", sourceTable); targetTable = targetMetaStore().getTable(dbName, tableName); .serdeParam(serdeConstants.FIELD_DELIM, Character.toString('\001')); sourceMetaStore().updateTableSchema(dbName, tableName, sourceTable); sourceTable = sourceMetaStore().getTable(dbName, tableName);
sourceTable = sourceMetaStore().getTable(dbName, tableName); assertNotNull("Table couldn't be queried for. ", sourceTable); targetTable = targetMetaStore().getTable(dbName, tableName); .serdeParam(serdeConstants.FIELD_DELIM, Character.toString('\001')); sourceMetaStore().updateTableSchema(dbName, tableName, sourceTable); sourceTable = sourceMetaStore().getTable(dbName, tableName);