Search in sources :

Example 71 with CommandProcessorException

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

the class TestClientSideAuthorizationProvider method testSimplePrivileges.

@Test
public void testSimplePrivileges() throws Exception {
    String dbName = getTestDbName();
    String tblName = getTestTableName();
    String userName = ugi.getUserName();
    allowCreateDatabase(userName);
    driver.run("create database " + dbName);
    Database db = msc.getDatabase(dbName);
    String dbLocn = db.getLocationUri();
    disallowCreateDatabase(userName);
    validateCreateDb(db, dbName);
    disallowCreateInDb(dbName, userName, dbLocn);
    driver.run("use " + dbName);
    try {
        driver.run(String.format("create table %s (a string) partitioned by (b string)", tblName));
    } catch (CommandProcessorException e) {
        // failure from not having permissions to create table
        assertNoPrivileges(e);
    }
    allowCreateInDb(dbName, userName, dbLocn);
    driver.run("use " + dbName);
    driver.run(String.format("create table %s (a string) partitioned by (b string)", tblName));
    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());
    driver.run(String.format("select * from %s limit 10", tblName));
    try {
        driver.run(String.format("create table %s (a string) partitioned by (b string)", tblName + "mal"));
    } catch (CommandProcessorException e) {
        assertNoPrivileges(e);
    }
    disallowCreateInTbl(tbl.getTableName(), userName, tbl.getSd().getLocation());
    try {
        driver.run("alter table " + tblName + " add partition (b='2011')");
    } catch (CommandProcessorException e) {
        assertNoPrivileges(e);
    }
    InjectableDummyAuthenticator.injectMode(false);
    allowCreateInTbl(tbl.getTableName(), userName, tbl.getSd().getLocation());
    driver.run("alter table " + tblName + " add partition (b='2011')");
    allowDropOnTable(tblName, userName, tbl.getSd().getLocation());
    allowDropOnDb(dbName, userName, db.getLocationUri());
    driver.run("drop database if exists " + getTestDbName() + " cascade");
}
Also used : CommandProcessorException(org.apache.hadoop.hive.ql.processors.CommandProcessorException) Table(org.apache.hadoop.hive.metastore.api.Table) Database(org.apache.hadoop.hive.metastore.api.Database) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 72 with CommandProcessorException

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

the class CompactorTestUtil method executeStatementOnDriverAndReturnResults.

/**
 * Execute Hive CLI statement and get back result.
 * @param cmd arbitrary statement to execute
 * @param driver execution driver
 * @return the result of the query
 * @throws Exception failed to execute statement
 */
static List<String> executeStatementOnDriverAndReturnResults(String cmd, IDriver driver) throws Exception {
    LOG.debug("Executing: " + cmd);
    try {
        driver.run(cmd);
    } catch (CommandProcessorException e) {
        throw new IOException("Failed to execute \"" + cmd + "\". Driver returned: " + e);
    }
    List<String> rs = new ArrayList<>();
    driver.setMaxRows(400);
    driver.getResults(rs);
    return rs;
}
Also used : CommandProcessorException(org.apache.hadoop.hive.ql.processors.CommandProcessorException) ArrayList(java.util.ArrayList) IOException(java.io.IOException)

Example 73 with CommandProcessorException

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

the class AbstractCoreBlobstoreCliDriver method runTestHelper.

protected void runTestHelper(String tname, String fname, String fpath, boolean expectSuccess) {
    long startTime = System.currentTimeMillis();
    qt.getConf().set(HCONF_TEST_BLOBSTORE_PATH_UNIQUE, testBlobstorePathUnique);
    try {
        System.err.println("Begin query: " + fname);
        qt.setInputFile(fpath);
        qt.cliInit();
        try {
            qt.executeClient();
            if (!expectSuccess) {
                qt.failedQuery(null, 0, fname, debugHint);
            }
        } catch (CommandProcessorException e) {
            if (expectSuccess) {
                qt.failedQuery(e.getCause(), e.getResponseCode(), fname, debugHint);
            }
        }
        QTestProcessExecResult result = qt.checkCliDriverResults();
        if (result.getReturnCode() != 0) {
            String message = Strings.isNullOrEmpty(result.getCapturedOutput()) ? debugHint : "\r\n" + result.getCapturedOutput();
            qt.failedDiff(result.getReturnCode(), fname, message);
        }
    } catch (Exception e) {
        qt.failedWithException(e, fname, debugHint);
    }
    long elapsedTime = System.currentTimeMillis() - startTime;
    System.err.println("Done query: " + fname + " elapsedTime=" + elapsedTime / 1000 + "s");
    assertTrue("Test passed", true);
}
Also used : CommandProcessorException(org.apache.hadoop.hive.ql.processors.CommandProcessorException) QTestProcessExecResult(org.apache.hadoop.hive.ql.QTestProcessExecResult) CommandProcessorException(org.apache.hadoop.hive.ql.processors.CommandProcessorException)

Example 74 with CommandProcessorException

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

the class CoreNegativeCliDriver method runTest.

@Override
public void runTest(String tname, String fname, String fpath) throws Exception {
    long startTime = System.currentTimeMillis();
    try {
        System.err.println("Begin query: " + fname);
        qt.setInputFile(fpath);
        qt.cliInit();
        try {
            qt.executeClient();
            qt.failed(fname, QTestUtil.DEBUG_HINT);
        } catch (CommandProcessorException e) {
        // this is the expected outcome
        }
        QTestProcessExecResult result = qt.checkCliDriverResults();
        if (result.getReturnCode() != 0) {
            String message = Strings.isNullOrEmpty(result.getCapturedOutput()) ? QTestUtil.DEBUG_HINT : "\r\n" + result.getCapturedOutput();
            qt.failedDiff(result.getReturnCode(), fname, message);
        }
    } catch (AssumptionViolatedException e) {
        throw e;
    } catch (Error error) {
        QTestProcessExecResult qTestProcessExecResult = qt.checkNegativeResults(fname, error);
        if (qTestProcessExecResult.getReturnCode() != 0) {
            String message = Strings.isNullOrEmpty(qTestProcessExecResult.getCapturedOutput()) ? QTestUtil.DEBUG_HINT : "\r\n" + qTestProcessExecResult.getCapturedOutput();
            qt.failedDiff(qTestProcessExecResult.getReturnCode(), fname, message);
        }
    } catch (Exception e) {
        qt.failedWithException(e, fname, QTestUtil.DEBUG_HINT);
    }
    long elapsedTime = System.currentTimeMillis() - startTime;
    System.err.println("Done query: " + fname + " elapsedTime=" + elapsedTime / 1000 + "s");
    assertTrue("Test passed", true);
}
Also used : CommandProcessorException(org.apache.hadoop.hive.ql.processors.CommandProcessorException) AssumptionViolatedException(org.junit.internal.AssumptionViolatedException) QTestProcessExecResult(org.apache.hadoop.hive.ql.QTestProcessExecResult) CommandProcessorException(org.apache.hadoop.hive.ql.processors.CommandProcessorException) AssumptionViolatedException(org.junit.internal.AssumptionViolatedException)

Example 75 with CommandProcessorException

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

the class CoreKuduNegativeCliDriver method runTest.

@Override
public void runTest(String tname, String fname, String fpath) {
    long startTime = System.currentTimeMillis();
    try {
        System.err.println("Begin query: " + fname);
        qt.setInputFile(fpath);
        qt.cliInit();
        try {
            qt.executeClient();
            qt.failed(fname, null);
        } catch (CommandProcessorException e) {
        // this is the expected behaviour
        }
        QTestProcessExecResult result = qt.checkCliDriverResults();
        if (result.getReturnCode() != 0) {
            qt.failedDiff(result.getReturnCode(), fname, result.getCapturedOutput());
        }
    } catch (Exception e) {
        qt.failedWithException(e, fname, null);
    }
    long elapsedTime = System.currentTimeMillis() - startTime;
    System.err.println("Done query: " + fname + " elapsedTime=" + elapsedTime / 1000 + "s");
    assertTrue("Test passed", true);
}
Also used : CommandProcessorException(org.apache.hadoop.hive.ql.processors.CommandProcessorException) QTestProcessExecResult(org.apache.hadoop.hive.ql.QTestProcessExecResult) CommandProcessorException(org.apache.hadoop.hive.ql.processors.CommandProcessorException)

Aggregations

CommandProcessorException (org.apache.hadoop.hive.ql.processors.CommandProcessorException)85 Test (org.junit.Test)42 IOException (java.io.IOException)14 CommandProcessorResponse (org.apache.hadoop.hive.ql.processors.CommandProcessorResponse)14 Driver (org.apache.hadoop.hive.ql.Driver)12 ArrayList (java.util.ArrayList)10 HiveConf (org.apache.hadoop.hive.conf.HiveConf)10 QTestProcessExecResult (org.apache.hadoop.hive.ql.QTestProcessExecResult)9 Path (org.apache.hadoop.fs.Path)8 FileSystem (org.apache.hadoop.fs.FileSystem)7 CliSessionState (org.apache.hadoop.hive.cli.CliSessionState)6 File (java.io.File)5 IDriver (org.apache.hadoop.hive.ql.IDriver)5 FileNotFoundException (java.io.FileNotFoundException)4 LockException (org.apache.hadoop.hive.ql.lockmgr.LockException)4 HiveException (org.apache.hadoop.hive.ql.metadata.HiveException)4 UnsupportedEncodingException (java.io.UnsupportedEncodingException)3 Map (java.util.Map)3 Nullable (javax.annotation.Nullable)3 Database (org.apache.hadoop.hive.metastore.api.Database)3