Search in sources :

Example 61 with CliSessionState

use of org.apache.hadoop.hive.cli.CliSessionState in project hive by apache.

the class TestMetastoreVersion method testVersionMatching.

/**
 * Test that with verification enabled, hive works when the correct schema is already populated
 * @throws Exception
 */
@Test
public void testVersionMatching() throws Exception {
    System.setProperty(HiveConf.ConfVars.METASTORE_SCHEMA_VERIFICATION.toString(), "false");
    hiveConf = new HiveConf(this.getClass());
    SessionState.start(new CliSessionState(hiveConf));
    driver = DriverFactory.newDriver(hiveConf);
    try {
        driver.run("show tables");
        assert false;
    } catch (CommandProcessorException e) {
    // this is expected
    }
    ObjectStore.setSchemaVerified(false);
    hiveConf.setBoolVar(HiveConf.ConfVars.METASTORE_SCHEMA_VERIFICATION, true);
    hiveConf = new HiveConf(this.getClass());
    setVersion(hiveConf, metastoreSchemaInfo.getHiveSchemaVersion());
    driver = DriverFactory.newDriver(hiveConf);
    driver.run("show tables");
}
Also used : CommandProcessorException(org.apache.hadoop.hive.ql.processors.CommandProcessorException) HiveConf(org.apache.hadoop.hive.conf.HiveConf) CliSessionState(org.apache.hadoop.hive.cli.CliSessionState) Test(org.junit.Test)

Example 62 with CliSessionState

use of org.apache.hadoop.hive.cli.CliSessionState in project hive by apache.

the class BaseReplicationScenariosAcidTables method prepareInc2AcidData.

void prepareInc2AcidData(String dbName, HiveConf hiveConf) throws Throwable {
    IDriver driver = DriverFactory.newDriver(hiveConf);
    SessionState.start(new CliSessionState(hiveConf));
    runUsingDriver(driver, "use " + dbName);
    runUsingDriver(driver, "insert into t1 values (3)");
    runUsingDriver(driver, "insert into t5 values (4444)");
}
Also used : IDriver(org.apache.hadoop.hive.ql.IDriver) CliSessionState(org.apache.hadoop.hive.cli.CliSessionState)

Example 63 with CliSessionState

use of org.apache.hadoop.hive.cli.CliSessionState in project hive by apache.

the class TestHiveHistory method testQueryloglocParentDirNotExist.

@Test
public void testQueryloglocParentDirNotExist() throws Exception {
    String parentTmpDir = tmpdir + "/HIVE2654";
    Path parentDirPath = new Path(parentTmpDir);
    try {
        fs.delete(parentDirPath, true);
    } catch (Exception e) {
    }
    try {
        String actualDir = parentTmpDir + "/test";
        HiveConf conf = new HiveConf(SessionState.class);
        conf.set(HiveConf.ConfVars.HIVEHISTORYFILELOC.toString(), actualDir);
        SessionState ss = new CliSessionState(conf);
        HiveHistory hiveHistory = new HiveHistoryImpl(ss);
        Path actualPath = new Path(actualDir);
        if (!fs.exists(actualPath)) {
            fail("Query location path is not exist :" + actualPath.toString());
        }
    } finally {
        try {
            fs.delete(parentDirPath, true);
        } catch (Exception e) {
        }
    }
}
Also used : Path(org.apache.hadoop.fs.Path) CliSessionState(org.apache.hadoop.hive.cli.CliSessionState) SessionState(org.apache.hadoop.hive.ql.session.SessionState) HiveConf(org.apache.hadoop.hive.conf.HiveConf) CliSessionState(org.apache.hadoop.hive.cli.CliSessionState) LogInitializationException(org.apache.hadoop.hive.common.LogUtils.LogInitializationException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Test(org.junit.Test)

Example 64 with CliSessionState

use of org.apache.hadoop.hive.cli.CliSessionState in project hive by apache.

the class TestHiveHistory method testSimpleQuery.

/**
 * Check history file output for this query.
 */
@Test
public void testSimpleQuery() {
    new LineageInfo();
    try {
        // before any of the other core hive classes are loaded
        try {
            LogUtils.initHiveLog4j();
        } catch (LogInitializationException e) {
        }
        HiveConf hconf = new HiveConf(SessionState.class);
        hconf.setBoolVar(ConfVars.HIVE_SESSION_HISTORY_ENABLED, true);
        CliSessionState ss = new CliSessionState(hconf);
        ss.in = System.in;
        try {
            ss.out = new SessionStream(System.out, true, "UTF-8");
            ss.err = new SessionStream(System.err, true, "UTF-8");
        } catch (UnsupportedEncodingException e) {
            System.exit(3);
        }
        SessionState.start(ss);
        String cmd = "select a.key+1 from src a";
        IDriver d = DriverFactory.newDriver(conf);
        d.run(cmd);
        HiveHistoryViewer hv = new HiveHistoryViewer(SessionState.get().getHiveHistory().getHistFileName());
        Map<String, QueryInfo> jobInfoMap = hv.getJobInfoMap();
        Map<String, TaskInfo> taskInfoMap = hv.getTaskInfoMap();
        if (jobInfoMap.size() != 1) {
            fail("jobInfo Map size not 1");
        }
        if (taskInfoMap.size() != 1) {
            fail("jobInfo Map size not 1");
        }
        cmd = (String) jobInfoMap.keySet().toArray()[0];
        QueryInfo ji = jobInfoMap.get(cmd);
        if (!ji.hm.get(Keys.QUERY_NUM_TASKS.name()).equals("1")) {
            fail("Wrong number of tasks");
        }
    } catch (Exception e) {
        e.printStackTrace();
        fail("Failed");
    }
}
Also used : UnsupportedEncodingException(java.io.UnsupportedEncodingException) QueryInfo(org.apache.hadoop.hive.ql.history.HiveHistory.QueryInfo) LineageInfo(org.apache.hadoop.hive.ql.tools.LineageInfo) CliSessionState(org.apache.hadoop.hive.cli.CliSessionState) LogInitializationException(org.apache.hadoop.hive.common.LogUtils.LogInitializationException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) TaskInfo(org.apache.hadoop.hive.ql.history.HiveHistory.TaskInfo) SessionStream(org.apache.hadoop.hive.common.io.SessionStream) LogInitializationException(org.apache.hadoop.hive.common.LogUtils.LogInitializationException) IDriver(org.apache.hadoop.hive.ql.IDriver) HiveConf(org.apache.hadoop.hive.conf.HiveConf) Test(org.junit.Test)

Example 65 with CliSessionState

use of org.apache.hadoop.hive.cli.CliSessionState in project hive by apache.

the class TestCommands method setUpBeforeClass.

@BeforeClass
public static void setUpBeforeClass() throws Exception {
    TestHCatClient.startMetaStoreServer();
    hconf = TestHCatClient.getConf();
    hconf.set(HiveConf.ConfVars.SEMANTIC_ANALYZER_HOOK.varname, "");
    hconf.set(HiveConf.ConfVars.REPL_RUN_DATA_COPY_TASKS_ON_TARGET.varname, "false");
    hconf.setVar(HiveConf.ConfVars.HIVE_AUTHORIZATION_MANAGER, "org.apache.hadoop.hive.ql.security.authorization.plugin.sqlstd.SQLStdHiveAuthorizerFactory");
    TEST_PATH = System.getProperty("test.warehouse.dir", "/tmp") + Path.SEPARATOR + TestCommands.class.getCanonicalName() + "-" + System.currentTimeMillis();
    Path testPath = new Path(TEST_PATH);
    FileSystem fs = FileSystem.get(testPath.toUri(), hconf);
    fs.mkdirs(testPath);
    driver = DriverFactory.newDriver(hconf);
    SessionState.start(new CliSessionState(hconf));
    client = HCatClient.create(hconf);
}
Also used : Path(org.apache.hadoop.fs.Path) FileSystem(org.apache.hadoop.fs.FileSystem) CliSessionState(org.apache.hadoop.hive.cli.CliSessionState) BeforeClass(org.junit.BeforeClass)

Aggregations

CliSessionState (org.apache.hadoop.hive.cli.CliSessionState)69 HiveConf (org.apache.hadoop.hive.conf.HiveConf)48 Before (org.junit.Before)19 File (java.io.File)16 HiveMetaStoreClient (org.apache.hadoop.hive.metastore.HiveMetaStoreClient)14 SessionState (org.apache.hadoop.hive.ql.session.SessionState)11 Test (org.junit.Test)11 Path (org.apache.hadoop.fs.Path)9 BeforeClass (org.junit.BeforeClass)9 Driver (org.apache.hadoop.hive.ql.Driver)8 IDriver (org.apache.hadoop.hive.ql.IDriver)7 CliDriver (org.apache.hadoop.hive.cli.CliDriver)6 UnsupportedEncodingException (java.io.UnsupportedEncodingException)5 LogInitializationException (org.apache.hadoop.hive.common.LogUtils.LogInitializationException)5 SessionStream (org.apache.hadoop.hive.common.io.SessionStream)5 CommandProcessorException (org.apache.hadoop.hive.ql.processors.CommandProcessorException)5 FileNotFoundException (java.io.FileNotFoundException)4 PrintStream (java.io.PrintStream)4 Map (java.util.Map)4 FileSystem (org.apache.hadoop.fs.FileSystem)4