@Test public void testDropTableException() throws Exception { HCatClient client = HCatClient.create(new Configuration(hcatConf)); String tableName = "tableToBeDropped"; boolean isExceptionCaught = false; client.dropTable(null, tableName, true); try { client.dropTable(null, tableName, false); } catch (Exception exp) { isExceptionCaught = true; assertTrue(exp instanceof HCatException); LOG.info("Drop Table Exception: " + exp.getCause()); } finally { client.close(); assertTrue("The expected exception was never thrown.", isExceptionCaught); } }
@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(); }
client.dropTable(null, newName, true); HCatCreateTableDesc tableDesc2 = HCatCreateTableDesc .create(null, newName, cols).fileFormat("rcfile").build();
@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(); }
String tableName = "Temptable"; boolean isExceptionCaught = false; client.dropTable(null, tableName, true); ArrayList<HCatFieldSchema> cols = new ArrayList<HCatFieldSchema>(); cols.add(new HCatFieldSchema("id", Type.INT, "id columns")); assertTrue(exp instanceof HCatException); String newName = "goodTable"; client.dropTable(null, newName, true); HCatCreateTableDesc tableDesc2 = HCatCreateTableDesc .create(null, newName, cols).fileFormat("rcfile").build();
client.dropTable(db, tableOne, true); HCatCreateTableDesc tableDesc2 = HCatCreateTableDesc.create(db, tableTwo, cols).fieldsTerminatedBy('\001').escapeChar('\002').linesTerminatedBy('\003').
/** * 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); }
public void dropTable(String db, String table, boolean ifExists) throws Exception { hcatClient.dropTable(db, table, ifExists); List<String> tables = hcatClient.listTableNamesByPattern(db, "*"); assertFalse(tables.contains(table)); }
@Override public boolean delete(URI uri, Configuration conf) throws LauncherException { HCatClient client = getHCatClient(uri, conf); try { HCatURI hcatURI = new HCatURI(uri.toString()); if (!hcatURI.getPartitionMap().isEmpty()) { client.dropPartitions(hcatURI.getDb(), hcatURI.getTable(), hcatURI.getPartitionMap(), true); } else { client.dropTable(hcatURI.getDb(), hcatURI.getTable(), true); } System.out.println("Dropped partitions for " + uri); return true; } catch (ConnectionFailureException e) { throw new LauncherException("Error trying to drop " + uri, e); } catch (HCatException e) { throw new LauncherException("Error trying to drop " + uri, e); } catch (URISyntaxException e) { throw new LauncherException("Error trying to drop " + uri, e); } finally { closeQuietly(client); } }
@Override public boolean delete(URI uri, Configuration conf) throws LauncherException { HCatClient client = getHCatClient(uri, conf); try { HCatURI hcatURI = new HCatURI(uri.toString()); if (!hcatURI.getPartitionMap().isEmpty()) { client.dropPartitions(hcatURI.getDb(), hcatURI.getTable(), hcatURI.getPartitionMap(), true); } else { client.dropTable(hcatURI.getDb(), hcatURI.getTable(), true); } System.out.println("Dropped partitions for " + uri); return true; } catch (ConnectionFailureException e) { throw new LauncherException("Error trying to drop " + uri, e); } catch (HCatException e) { throw new LauncherException("Error trying to drop " + uri, e); } catch (URISyntaxException e) { throw new LauncherException("Error trying to drop " + uri, e); } finally { closeQuietly(client); } }
@Override public void delete(URI uri, Context context) throws URIHandlerException { HCatClient client = ((HCatContext) context).getHCatClient(); try { HCatURI hcatUri = new HCatURI(uri); if (!hcatUri.getPartitionMap().isEmpty()) { client.dropPartitions(hcatUri.getDb(), hcatUri.getTable(), hcatUri.getPartitionMap(), true); } else { client.dropTable(hcatUri.getDb(), hcatUri.getTable(), true); } } catch (URISyntaxException e) { throw new HCatAccessorException(ErrorCode.E1501, e); } catch (HCatException e) { throw new HCatAccessorException(ErrorCode.E1501, e); } }
@Override public void delete(URI uri, Context context) throws URIHandlerException { HCatClient client = ((HCatContext) context).getHCatClient(); try { HCatURI hcatUri = new HCatURI(uri); if (!hcatUri.getPartitionMap().isEmpty()) { client.dropPartitions(hcatUri.getDb(), hcatUri.getTable(), hcatUri.getPartitionMap(), true); } else { client.dropTable(hcatUri.getDb(), hcatUri.getTable(), true); } } catch (URISyntaxException e) { throw new HCatAccessorException(ErrorCode.E1501, e); } catch (HCatException e) { throw new HCatAccessorException(ErrorCode.E1501, e); } }
@Override public void delete(URI uri, Configuration conf, String user) throws URIHandlerException { HCatClientWithToken client = null; HCatClient hCatClient = null; try { HCatURI hcatUri = new HCatURI(uri); client = getHCatClient(uri, conf, user); hCatClient = client.getHCatClient(); if (!hcatUri.getPartitionMap().isEmpty()) { hCatClient.dropPartitions(hcatUri.getDb(), hcatUri.getTable(), hcatUri.getPartitionMap(), true); } else { hCatClient.dropTable(hcatUri.getDb(), hcatUri.getTable(), true); } } catch (URISyntaxException e){ throw new HCatAccessorException(ErrorCode.E1501, e); } catch (HCatException e) { throw new HCatAccessorException(ErrorCode.E1501, e); } finally { closeQuietly(hCatClient, client != null ? client.getDelegationToken() : null, true); } }
@Override public void delete(URI uri, Configuration conf, String user) throws URIHandlerException { HCatClientWithToken client = null; HCatClient hCatClient = null; try { HCatURI hcatUri = new HCatURI(uri); client = getHCatClient(uri, conf, user); hCatClient = client.getHCatClient(); if (!hcatUri.getPartitionMap().isEmpty()) { hCatClient.dropPartitions(hcatUri.getDb(), hcatUri.getTable(), hcatUri.getPartitionMap(), true); } else { hCatClient.dropTable(hcatUri.getDb(), hcatUri.getTable(), true); } } catch (URISyntaxException e){ throw new HCatAccessorException(ErrorCode.E1501, e); } catch (HCatException e) { throw new HCatAccessorException(ErrorCode.E1501, e); } finally { closeQuietly(hCatClient, client != null ? client.getDelegationToken() : null, true); } }