use of org.apache.hadoop.hive.metastore.HiveMetaException 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()));
}
use of org.apache.hadoop.hive.metastore.HiveMetaException in project hive by apache.
the class TestSchemaToolCatalogOps method execute.
private static void execute(SchemaToolTask task, String taskArgs) throws HiveMetaException {
try {
StrTokenizer tokenizer = new StrTokenizer(argsBase + taskArgs, ' ', '\"');
SchemaToolCommandLine cl = new SchemaToolCommandLine(tokenizer.getTokenArray(), null);
task.setCommandLineArguments(cl);
} catch (Exception e) {
throw new IllegalStateException("Could not parse comman line \n" + argsBase + taskArgs, e);
}
task.setHiveSchemaTool(schemaTool);
task.execute();
}
use of org.apache.hadoop.hive.metastore.HiveMetaException 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());
}
use of org.apache.hadoop.hive.metastore.HiveMetaException in project hive by apache.
the class TestSchemaToolForMetastore method execute.
private void execute(SchemaToolTask task, String taskArgs) throws HiveMetaException {
try {
StrTokenizer tokenizer = new StrTokenizer(argsBase + taskArgs, ' ', '\"');
SchemaToolCommandLine cl = new SchemaToolCommandLine(tokenizer.getTokenArray(), null);
task.setCommandLineArguments(cl);
} catch (Exception e) {
throw new IllegalStateException("Could not parse comman line \n" + argsBase + taskArgs, e);
}
task.setHiveSchemaTool(schemaTool);
task.execute();
}
use of org.apache.hadoop.hive.metastore.HiveMetaException in project hive by apache.
the class MetastoreSchemaTool method init.
@VisibleForTesting
public void init(String metastoreHome, String[] args, OptionGroup additionalOptions, Configuration conf) throws HiveMetaException {
try {
cmdLine = new SchemaToolCommandLine(args, additionalOptions);
} catch (ParseException e) {
System.err.println("Failed to parse command line. ");
throw new HiveMetaException(e);
}
if (metastoreHome == null || metastoreHome.isEmpty()) {
throw new HiveMetaException("No Metastore home directory provided");
}
this.conf = conf;
this.dbType = cmdLine.getDbType();
this.metaDbType = cmdLine.getMetaDbType();
NestedScriptParser parser = getDbCommandParser(dbType, metaDbType);
this.needsQuotedIdentifier = parser.needsQuotedIdentifier();
this.quoteCharacter = parser.getQuoteCharacter();
this.metaStoreSchemaInfo = MetaStoreSchemaInfoFactory.get(conf, metastoreHome, dbType);
// It is overridden by command line options if passed (-url and -driver)
if (dbType.equalsIgnoreCase(HiveSchemaHelper.DB_HIVE)) {
this.url = HiveSchemaHelper.EMBEDDED_HS2_URL;
this.driver = HiveSchemaHelper.HIVE_JDBC_DRIVER;
}
if (cmdLine.hasOption("userName")) {
setUserName(cmdLine.getOptionValue("userName"));
} else {
setUserName(getConf().get(MetastoreConf.ConfVars.CONNECTION_USER_NAME.getVarname()));
}
if (cmdLine.hasOption("passWord")) {
setPassWord(cmdLine.getOptionValue("passWord"));
} else {
try {
setPassWord(MetastoreConf.getPassword(getConf(), ConfVars.PWD));
} catch (IOException err) {
throw new HiveMetaException("Error getting metastore password", err);
}
}
if (cmdLine.hasOption("url")) {
setUrl(cmdLine.getOptionValue("url"));
}
if (cmdLine.hasOption("driver")) {
setDriver(cmdLine.getOptionValue("driver"));
}
if (cmdLine.hasOption("dryRun")) {
setDryRun(true);
}
if (cmdLine.hasOption("verbose")) {
setVerbose(true);
}
if (cmdLine.hasOption("dbOpts")) {
setDbOpts(cmdLine.getOptionValue("dbOpts"));
}
if (cmdLine.hasOption("validate") && cmdLine.hasOption("servers")) {
setValidationServers(cmdLine.getOptionValue("servers"));
}
if (cmdLine.hasOption("hiveUser")) {
setHiveUser(cmdLine.getOptionValue("hiveUser"));
}
if (cmdLine.hasOption("hivePassword")) {
setHivePasswd(cmdLine.getOptionValue("hivePassword"));
}
if (cmdLine.hasOption("hiveDb")) {
setHiveDb(cmdLine.getOptionValue("hiveDb"));
}
}
Aggregations