/** * Builds the HCatCreateTableDesc. * * @return HCatCreateTableDesc * @throws HCatException */ public HCatCreateTableDesc build() throws HCatException { return new HCatCreateTableDesc(this.hcatTable, this.ifNotExists); }
@Override public void createTable(HCatCreateTableDesc createTableDesc) throws HCatException { try { hmsClient.createTable(createTableDesc.getHCatTable().toHiveTable()); } catch (AlreadyExistsException e) { if (!createTableDesc.getIfNotExists()) { throw new HCatException( "AlreadyExistsException while creating table.", e); } } catch (InvalidObjectException e) { throw new HCatException( "InvalidObjectException while creating table.", e); } catch (MetaException e) { throw new HCatException("MetaException while creating table.", e); } catch (NoSuchObjectException e) { throw new ObjectNotFoundException( "NoSuchObjectException while creating table.", e); } catch (TException e) { throw new ConnectionFailureException( "TException while creating table.", e); } catch (IOException e) { throw new HCatException("IOException while creating hive conf.", e); } }
try { HCatCreateTableDesc tableDesc = HCatCreateTableDesc .create(null, tableName, cols).fileFormat("rcfile").build(); client.createTable(tableDesc); } catch (Exception exp) { client.dropTable(null, newName, true); HCatCreateTableDesc tableDesc2 = HCatCreateTableDesc .create(null, newName, cols).fileFormat("rcfile").build(); client.createTable(tableDesc2); HCatTable newTable = client.getTable(null, newName);
@Override public void createTable(HCatCreateTableDesc createTableDesc) throws HCatException { try { hmsClient.createTable(createTableDesc.getHCatTable().toHiveTable()); } catch (AlreadyExistsException e) { if (!createTableDesc.getIfNotExists()) { throw new HCatException( "AlreadyExistsException while creating table.", e); } } catch (InvalidObjectException e) { throw new HCatException( "InvalidObjectException while creating table.", e); } catch (MetaException e) { throw new HCatException("MetaException while creating table.", e); } catch (NoSuchObjectException e) { throw new ObjectNotFoundException( "NoSuchObjectException while creating table.", e); } catch (TException e) { throw new ConnectionFailureException( "TException while creating table.", e); } catch (IOException e) { throw new HCatException("IOException while creating hive conf.", e); } }
@Test public void testCreateTableLike() throws Exception { HCatClient client = HCatClient.create(new Configuration(hcatConf)); String tableName = "tableone"; String cloneTable = "tabletwo"; client.dropTable(null, tableName, true); client.dropTable(null, cloneTable, 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); // create a new table similar to previous one. client.createTableLike(null, tableName, cloneTable, true, false, null); List<String> tables = client.listTableNamesByPattern(null, "table*"); assertTrue(tables.size() == 2); client.close(); }
/** * Builds the HCatCreateTableDesc. * * @return HCatCreateTableDesc * @throws HCatException */ public HCatCreateTableDesc build() throws HCatException { return new HCatCreateTableDesc(this.hcatTable, this.ifNotExists); }
@Override public void createTable(HCatCreateTableDesc createTableDesc) throws HCatException { try { hmsClient.createTable(createTableDesc.getHCatTable().toHiveTable()); } catch (AlreadyExistsException e) { if (!createTableDesc.getIfNotExists()) { throw new HCatException( "AlreadyExistsException while creating table.", e); } } catch (InvalidObjectException e) { throw new HCatException( "InvalidObjectException while creating table.", e); } catch (MetaException e) { throw new HCatException("MetaException while creating table.", e); } catch (NoSuchObjectException e) { throw new ObjectNotFoundException( "NoSuchObjectException while creating table.", e); } catch (TException e) { throw new ConnectionFailureException( "TException while creating table.", e); } catch (IOException e) { throw new HCatException("IOException while creating hive conf.", e); } }
@Test public void testGetMessageBusTopicName() throws Exception { try { HCatClient client = HCatClient.create(new Configuration(hcatConf)); String dbName = "testGetMessageBusTopicName_DBName"; String tableName = "testGetMessageBusTopicName_TableName"; client.dropDatabase(dbName, true, HCatClient.DropDBMode.CASCADE); client.createDatabase(HCatCreateDBDesc.create(dbName).build()); String messageBusTopicName = "MY.topic.name"; Map<String, String> tableProperties = new HashMap<String, String>(1); tableProperties.put(HCatConstants.HCAT_MSGBUS_TOPIC_NAME, messageBusTopicName); client.createTable(HCatCreateTableDesc.create(dbName, tableName, Arrays.asList(new HCatFieldSchema("foo", Type.STRING, ""))).tblProps(tableProperties).build()); assertEquals("MessageBus topic-name doesn't match!", messageBusTopicName, client.getMessageBusTopicName(dbName, tableName)); client.dropDatabase(dbName, true, HCatClient.DropDBMode.CASCADE); client.close(); } catch (Exception exception) { LOG.error("Unexpected exception.", exception); assertTrue("Unexpected exception:" + exception.getMessage(), false); } }
/** * Builds the HCatCreateTableDesc. * * @return HCatCreateTableDesc * @throws HCatException */ public HCatCreateTableDesc build() throws HCatException { return new HCatCreateTableDesc(this.hcatTable, this.ifNotExists); }
@Override public void createTable(HCatCreateTableDesc createTableDesc) throws HCatException { try { hmsClient.createTable(createTableDesc.getHCatTable().toHiveTable()); } catch (AlreadyExistsException e) { if (!createTableDesc.getIfNotExists()) { throw new HCatException( "AlreadyExistsException while creating table.", e); } } catch (InvalidObjectException e) { throw new HCatException( "InvalidObjectException while creating table.", e); } catch (MetaException e) { throw new HCatException("MetaException while creating table.", e); } catch (NoSuchObjectException e) { throw new ObjectNotFoundException( "NoSuchObjectException while creating table.", e); } catch (TException e) { throw new ConnectionFailureException( "TException while creating table.", e); } catch (IOException e) { throw new HCatException("IOException while creating hive conf.", e); } }
@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); } }
/** * Builds the HCatCreateTableDesc. * * @return HCatCreateTableDesc * @throws HCatException */ public HCatCreateTableDesc build() throws HCatException { return new HCatCreateTableDesc(this.hcatTable, this.ifNotExists); }
@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); } }
try { HCatCreateTableDesc tableDesc = HCatCreateTableDesc .create(null, tableName, cols).fileFormat("rcfile").build(); client.createTable(tableDesc); client.dropTable(null, newName, true); HCatCreateTableDesc tableDesc2 = HCatCreateTableDesc .create(null, newName, cols).fileFormat("rcfile").build(); client.createTable(tableDesc2); HCatTable newTable = client.getTable(null, newName);
@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(); }
Arrays.asList(new HCatFieldSchema(partitionColumn, Type.STRING, ""))); HCatTable table = new HCatTable(dbName, tableName).cols(columns).partCols(partitionColumns); client.createTable(HCatCreateTableDesc.create(table, false).build());
cols.add(new HCatFieldSchema("value", Type.STRING, "value comment")); HCatCreateTableDesc tableDesc = HCatCreateTableDesc .create(db, tableOne, cols).fileFormat("rcfile").build(); client.createTable(tableDesc); HCatTable table1 = client.getTable(db, tableOne); HCatCreateTableDesc tableDesc2 = HCatCreateTableDesc.create(db, tableTwo, cols).fieldsTerminatedBy('\001').escapeChar('\002').linesTerminatedBy('\003'). mapKeysTerminatedBy('\004').collectionItemsTerminatedBy('\005').nullDefinedAs('\006').build(); HCatCreateTableDesc tableDesc3 = HCatCreateTableDesc.create(db, tableThree, cols).fileFormat("orcfile").build(); client.createTable(tableDesc3);
client.createTable(HCatCreateTableDesc.create(table, false).build());
client.createTable(HCatCreateTableDesc.create(table, false).build());
.partCols(ptnCols) .fileFormat("sequenceFile"); HCatCreateTableDesc tableDesc = HCatCreateTableDesc.create(table, false).build(); client.createTable(tableDesc);