Search in sources :

Example 76 with CommandProcessorResponse

use of org.apache.hadoop.hive.ql.processors.CommandProcessorResponse in project hive by apache.

the class AbstractHCatLoaderTest method executeStatementOnDriver.

/**
   * Execute Hive CLI statement
   * @param cmd arbitrary statement to execute
   */
static void executeStatementOnDriver(String cmd, Driver driver) throws IOException, CommandNeedRetryException {
    LOG.debug("Executing: " + cmd);
    CommandProcessorResponse cpr = driver.run(cmd);
    if (cpr.getResponseCode() != 0) {
        throw new IOException("Failed to execute \"" + cmd + "\". Driver returned " + cpr.getResponseCode() + " Error: " + cpr.getErrorMessage());
    }
}
Also used : CommandProcessorResponse(org.apache.hadoop.hive.ql.processors.CommandProcessorResponse) IOException(java.io.IOException)

Example 77 with CommandProcessorResponse

use of org.apache.hadoop.hive.ql.processors.CommandProcessorResponse in project hive by apache.

the class TestHCatLoaderComplexSchema method createTable.

private void createTable(String tablename, String schema, String partitionedBy) throws IOException, CommandNeedRetryException {
    String createTable;
    createTable = "create table " + tablename + "(" + schema + ") ";
    if ((partitionedBy != null) && (!partitionedBy.trim().isEmpty())) {
        createTable = createTable + "partitioned by (" + partitionedBy + ") ";
    }
    createTable = createTable + "stored as " + storageFormat;
    LOG.info("Creating table:\n {}", createTable);
    CommandProcessorResponse result = driver.run(createTable);
    int retCode = result.getResponseCode();
    if (retCode != 0) {
        throw new IOException("Failed to create table. [" + createTable + "], return code from hive driver : [" + retCode + " " + result.getErrorMessage() + "]");
    }
}
Also used : CommandProcessorResponse(org.apache.hadoop.hive.ql.processors.CommandProcessorResponse) IOException(java.io.IOException)

Example 78 with CommandProcessorResponse

use of org.apache.hadoop.hive.ql.processors.CommandProcessorResponse in project hive by apache.

the class TestCompactor method executeStatementOnDriver.

/**
   * Execute Hive CLI statement
   * @param cmd arbitrary statement to execute
   */
static void executeStatementOnDriver(String cmd, Driver driver) throws IOException, CommandNeedRetryException {
    LOG.debug("Executing: " + cmd);
    CommandProcessorResponse cpr = driver.run(cmd);
    if (cpr.getResponseCode() != 0) {
        throw new IOException("Failed to execute \"" + cmd + "\". Driver returned: " + cpr);
    }
}
Also used : CommandProcessorResponse(org.apache.hadoop.hive.ql.processors.CommandProcessorResponse) IOException(java.io.IOException)

Example 79 with CommandProcessorResponse

use of org.apache.hadoop.hive.ql.processors.CommandProcessorResponse in project hive by apache.

the class TestClientSideAuthorizationProvider method testSimplePrivileges.

public void testSimplePrivileges() throws Exception {
    String dbName = getTestDbName();
    String tblName = getTestTableName();
    String userName = ugi.getUserName();
    allowCreateDatabase(userName);
    CommandProcessorResponse ret = driver.run("create database " + dbName);
    assertEquals(0, ret.getResponseCode());
    Database db = msc.getDatabase(dbName);
    String dbLocn = db.getLocationUri();
    disallowCreateDatabase(userName);
    validateCreateDb(db, dbName);
    disallowCreateInDb(dbName, userName, dbLocn);
    driver.run("use " + dbName);
    ret = driver.run(String.format("create table %s (a string) partitioned by (b string)", tblName));
    // failure from not having permissions to create table
    assertNoPrivileges(ret);
    allowCreateInDb(dbName, userName, dbLocn);
    driver.run("use " + dbName);
    ret = driver.run(String.format("create table %s (a string) partitioned by (b string)", tblName));
    // now it succeeds.
    assertEquals(0, ret.getResponseCode());
    Table tbl = msc.getTable(dbName, tblName);
    validateCreateTable(tbl, tblName, dbName);
    String fakeUser = "mal";
    List<String> fakeGroupNames = new ArrayList<String>();
    fakeGroupNames.add("groupygroup");
    InjectableDummyAuthenticator.injectUserName(fakeUser);
    InjectableDummyAuthenticator.injectGroupNames(fakeGroupNames);
    InjectableDummyAuthenticator.injectMode(true);
    allowSelectOnTable(tbl.getTableName(), fakeUser, tbl.getSd().getLocation());
    ret = driver.run(String.format("select * from %s limit 10", tblName));
    assertEquals(0, ret.getResponseCode());
    ret = driver.run(String.format("create table %s (a string) partitioned by (b string)", tblName + "mal"));
    assertNoPrivileges(ret);
    disallowCreateInTbl(tbl.getTableName(), userName, tbl.getSd().getLocation());
    ret = driver.run("alter table " + tblName + " add partition (b='2011')");
    assertNoPrivileges(ret);
    InjectableDummyAuthenticator.injectMode(false);
    allowCreateInTbl(tbl.getTableName(), userName, tbl.getSd().getLocation());
    ret = driver.run("alter table " + tblName + " add partition (b='2011')");
    assertEquals(0, ret.getResponseCode());
    allowDropOnTable(tblName, userName, tbl.getSd().getLocation());
    allowDropOnDb(dbName, userName, db.getLocationUri());
    driver.run("drop database if exists " + getTestDbName() + " cascade");
}
Also used : Table(org.apache.hadoop.hive.metastore.api.Table) CommandProcessorResponse(org.apache.hadoop.hive.ql.processors.CommandProcessorResponse) Database(org.apache.hadoop.hive.metastore.api.Database) ArrayList(java.util.ArrayList)

Example 80 with CommandProcessorResponse

use of org.apache.hadoop.hive.ql.processors.CommandProcessorResponse in project hive by apache.

the class TestStorageBasedMetastoreAuthorizationDrops method dropDatabaseByOtherUser.

/**
   * Creates db and tries to drop as 'other' user
   * @param perm - permission for warehouse dir
   * @param expectedRet - expected return code for drop by other user
   * @throws Exception
   */
public void dropDatabaseByOtherUser(String perm, int expectedRet) throws Exception {
    String dbName = getTestDbName();
    setPermissions(clientHiveConf.getVar(ConfVars.METASTOREWAREHOUSE), perm);
    CommandProcessorResponse resp = driver.run("create database " + dbName);
    Assert.assertEquals(0, resp.getResponseCode());
    Database db = msc.getDatabase(dbName);
    validateCreateDb(db, dbName);
    InjectableDummyAuthenticator.injectMode(true);
    resp = driver.run("drop database " + dbName);
    Assert.assertEquals(expectedRet, resp.getResponseCode());
}
Also used : CommandProcessorResponse(org.apache.hadoop.hive.ql.processors.CommandProcessorResponse) Database(org.apache.hadoop.hive.metastore.api.Database)

Aggregations

CommandProcessorResponse (org.apache.hadoop.hive.ql.processors.CommandProcessorResponse)145 Test (org.junit.Test)92 ShowLocksResponseElement (org.apache.hadoop.hive.metastore.api.ShowLocksResponseElement)24 HCatBaseTest (org.apache.hive.hcatalog.mapreduce.HCatBaseTest)19 IOException (java.io.IOException)18 ArrayList (java.util.ArrayList)17 AddDynamicPartitions (org.apache.hadoop.hive.metastore.api.AddDynamicPartitions)8 Database (org.apache.hadoop.hive.metastore.api.Database)8 HiveConf (org.apache.hadoop.hive.conf.HiveConf)7 Table (org.apache.hadoop.hive.metastore.api.Table)7 Path (org.apache.hadoop.fs.Path)6 HiveException (org.apache.hadoop.hive.ql.metadata.HiveException)6 PigServer (org.apache.pig.PigServer)5 FieldSchema (org.apache.hadoop.hive.metastore.api.FieldSchema)4 Driver (org.apache.hadoop.hive.ql.Driver)4 IDriver (org.apache.hadoop.hive.ql.IDriver)4 LockException (org.apache.hadoop.hive.ql.lockmgr.LockException)4 PerfLogger (org.apache.hadoop.hive.ql.log.PerfLogger)4 ParseException (org.apache.hadoop.hive.ql.parse.ParseException)4 HashMap (java.util.HashMap)3