Search in sources :

Example 56 with CliSessionState

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

the class TestHCatStorerMulti method setUp.

@Before
public void setUp() throws Exception {
    assumeTrue(!TestUtil.shouldSkip(storageFormat, DISABLED_STORAGE_FORMATS));
    if (driver == null) {
        HiveConf hiveConf = new HiveConf(this.getClass());
        hiveConf.set(HiveConf.ConfVars.PREEXECHOOKS.varname, "");
        hiveConf.set(HiveConf.ConfVars.POSTEXECHOOKS.varname, "");
        hiveConf.set(HiveConf.ConfVars.HIVE_SUPPORT_CONCURRENCY.varname, "false");
        hiveConf.set(HiveConf.ConfVars.METASTOREWAREHOUSE.varname, TEST_WAREHOUSE_DIR);
        hiveConf.setVar(HiveConf.ConfVars.HIVEMAPREDMODE, "nonstrict");
        hiveConf.setVar(HiveConf.ConfVars.HIVE_AUTHORIZATION_MANAGER, "org.apache.hadoop.hive.ql.security.authorization.plugin.sqlstd.SQLStdHiveAuthorizerFactory");
        driver = DriverFactory.newDriver(hiveConf);
        SessionState.start(new CliSessionState(hiveConf));
    }
    cleanup();
}
Also used : HiveConf(org.apache.hadoop.hive.conf.HiveConf) CliSessionState(org.apache.hadoop.hive.cli.CliSessionState) Before(org.junit.Before)

Example 57 with CliSessionState

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

the class TestCLIAuthzSessionContext method beforeTest.

@BeforeClass
public static void beforeTest() throws Exception {
    HiveConf conf = new HiveConf();
    conf.setVar(ConfVars.HIVE_AUTHORIZATION_MANAGER, MockedHiveAuthorizerFactory.class.getName());
    conf.setVar(ConfVars.HIVE_AUTHENTICATOR_MANAGER, SessionStateUserAuthenticator.class.getName());
    conf.setBoolVar(ConfVars.HIVE_AUTHORIZATION_ENABLED, true);
    conf.setBoolVar(ConfVars.HIVE_SUPPORT_CONCURRENCY, false);
    // once SessionState for thread is set, CliDriver picks conf from it
    CliSessionState ss = new CliSessionState(conf);
    ss.err = new SessionStream(System.err);
    ss.out = new SessionStream(System.out);
    SessionState.start(ss);
    TestCLIAuthzSessionContext.driver = new CliDriver();
}
Also used : SessionStream(org.apache.hadoop.hive.common.io.SessionStream) SessionStateUserAuthenticator(org.apache.hadoop.hive.ql.security.SessionStateUserAuthenticator) HiveConf(org.apache.hadoop.hive.conf.HiveConf) CliSessionState(org.apache.hadoop.hive.cli.CliSessionState) CliDriver(org.apache.hadoop.hive.cli.CliDriver) BeforeClass(org.junit.BeforeClass)

Example 58 with CliSessionState

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

the class TestMetastoreVersion method testMetastoreVersion.

/**
 * Test that with no verification, and record verification enabled, hive populates the schema
 * and version correctly
 * @throws Exception
 */
@Test
public void testMetastoreVersion() throws Exception {
    // let the schema and version be auto created
    System.setProperty(HiveConf.ConfVars.METASTORE_SCHEMA_VERIFICATION.toString(), "false");
    System.setProperty(HiveConf.ConfVars.METASTORE_SCHEMA_VERIFICATION_RECORD_VERSION.toString(), "true");
    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
    }
    // correct version stored by Metastore during startup
    assertEquals(metastoreSchemaInfo.getHiveSchemaVersion(), getVersion(hiveConf));
    setVersion(hiveConf, "foo");
    assertEquals("foo", getVersion(hiveConf));
}
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 59 with CliSessionState

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

the class TestMetastoreVersion method testVersionMisMatch.

/**
 * Store garbage version in metastore and verify that hive fails when verification is on
 * @throws Exception
 */
@Test
public void testVersionMisMatch() 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);
    driver.run("show tables");
    ObjectStore.setSchemaVerified(false);
    System.setProperty(HiveConf.ConfVars.METASTORE_SCHEMA_VERIFICATION.toString(), "true");
    hiveConf = new HiveConf(this.getClass());
    setVersion(hiveConf, "fooVersion");
    SessionState.start(new CliSessionState(hiveConf));
    driver = DriverFactory.newDriver(hiveConf);
    try {
        driver.run("show tables");
        assert false;
    } catch (CommandProcessorException e) {
    // this is expected
    }
}
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 60 with CliSessionState

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

the class TestMetastoreVersion method testVersionRestriction.

/**
 * Test schema verification property
 * @throws Exception
 */
@Test
public void testVersionRestriction() throws Exception {
    System.setProperty(HiveConf.ConfVars.METASTORE_SCHEMA_VERIFICATION.toString(), "true");
    hiveConf = new HiveConf(this.getClass());
    assertTrue(hiveConf.getBoolVar(HiveConf.ConfVars.METASTORE_SCHEMA_VERIFICATION));
    assertFalse(hiveConf.getBoolVar(HiveConf.ConfVars.METASTORE_AUTO_CREATE_ALL));
    // session creation should fail since the schema didn't get created
    try {
        SessionState.start(new CliSessionState(hiveConf));
        Hive.get(hiveConf).getMSC();
        fail("An exception is expected since schema is not created.");
    } catch (Exception re) {
        LOG.info("Exception in testVersionRestriction: " + re, re);
        String msg = HiveStringUtils.stringifyException(re);
        assertTrue("Expected 'Version information not found in metastore' in: " + msg, msg.contains("Version information not found in metastore"));
    }
}
Also used : HiveConf(org.apache.hadoop.hive.conf.HiveConf) CliSessionState(org.apache.hadoop.hive.cli.CliSessionState) MetaException(org.apache.hadoop.hive.metastore.api.MetaException) CommandProcessorException(org.apache.hadoop.hive.ql.processors.CommandProcessorException) Test(org.junit.Test)

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