Search in sources :

Example 6 with SessionStream

use of org.apache.hadoop.hive.common.io.SessionStream in project hive by apache.

the class TestCliDriverMethods method testProcessSelectDatabase.

@Test
public void testProcessSelectDatabase() throws Exception {
    CliSessionState sessinState = new CliSessionState(new HiveConf());
    CliSessionState.start(sessinState);
    ByteArrayOutputStream data = new ByteArrayOutputStream();
    sessinState.err = new SessionStream(data);
    sessinState.database = "database";
    CliDriver driver = new CliDriver();
    try {
        driver.processSelectDatabase(sessinState);
        fail("shuld be exit");
    } catch (ExitException e) {
        e.printStackTrace();
        assertEquals(40000, e.getStatus());
    }
    assertTrue(data.toString().contains("FAILED: ParseException line 1:4 cannot recognize input near 'database'"));
}
Also used : SessionStream(org.apache.hadoop.hive.common.io.SessionStream) HiveConf(org.apache.hadoop.hive.conf.HiveConf) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.Test)

Example 7 with SessionStream

use of org.apache.hadoop.hive.common.io.SessionStream in project hive by apache.

the class SQLOperation method setupSessionIO.

private void setupSessionIO(SessionState sessionState) {
    try {
        // hive server's session input stream is not used
        sessionState.in = null;
        sessionState.out = new SessionStream(System.out, true, StandardCharsets.UTF_8.name());
        sessionState.info = new SessionStream(System.err, true, StandardCharsets.UTF_8.name());
        sessionState.err = new SessionStream(System.err, true, StandardCharsets.UTF_8.name());
    } catch (UnsupportedEncodingException e) {
        log.error("Error creating PrintStream", e);
        sessionState.out = null;
        sessionState.info = null;
        sessionState.err = null;
    }
}
Also used : SessionStream(org.apache.hadoop.hive.common.io.SessionStream) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 8 with SessionStream

use of org.apache.hadoop.hive.common.io.SessionStream in project hive by apache.

the class TestSetProcessor method setupTest.

@Before
public void setupTest() throws Exception {
    baos = new ByteArrayOutputStream();
    state.out = new SessionStream(baos);
    processor = new SetProcessor();
}
Also used : SessionStream(org.apache.hadoop.hive.common.io.SessionStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Before(org.junit.Before)

Example 9 with SessionStream

use of org.apache.hadoop.hive.common.io.SessionStream 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 10 with SessionStream

use of org.apache.hadoop.hive.common.io.SessionStream 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)

Aggregations

SessionStream (org.apache.hadoop.hive.common.io.SessionStream)14 HiveConf (org.apache.hadoop.hive.conf.HiveConf)9 UnsupportedEncodingException (java.io.UnsupportedEncodingException)5 CliSessionState (org.apache.hadoop.hive.cli.CliSessionState)5 Test (org.junit.Test)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 IOException (java.io.IOException)3 LogInitializationException (org.apache.hadoop.hive.common.LogUtils.LogInitializationException)3 CommandProcessorException (org.apache.hadoop.hive.ql.processors.CommandProcessorException)3 SessionState (org.apache.hadoop.hive.ql.session.SessionState)3 File (java.io.File)2 IDriver (org.apache.hadoop.hive.ql.IDriver)2 Before (org.junit.Before)2 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)2 FileNotFoundException (java.io.FileNotFoundException)1 FileOutputStream (java.io.FileOutputStream)1 PrintStream (java.io.PrintStream)1 Map (java.util.Map)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 CommandLine (org.apache.commons.cli.CommandLine)1