Search in sources :

Example 21 with IDriver

use of org.apache.hadoop.hive.ql.IDriver in project hive by apache.

the class CliDriver method processLocalCmd.

int processLocalCmd(String cmd, CommandProcessor proc, CliSessionState ss) {
    boolean escapeCRLF = HiveConf.getBoolVar(conf, HiveConf.ConfVars.HIVE_CLI_PRINT_ESCAPE_CRLF);
    int ret = 0;
    if (proc != null) {
        if (proc instanceof IDriver) {
            IDriver qp = (IDriver) proc;
            PrintStream out = ss.out;
            long start = System.currentTimeMillis();
            if (ss.getIsVerbose()) {
                out.println(cmd);
            }
            ret = qp.run(cmd).getResponseCode();
            if (ret != 0) {
                qp.close();
                return ret;
            }
            // query has run capture the time
            long end = System.currentTimeMillis();
            double timeTaken = (end - start) / 1000.0;
            ArrayList<String> res = new ArrayList<String>();
            printHeader(qp, out);
            // print the results
            int counter = 0;
            try {
                if (out instanceof FetchConverter) {
                    ((FetchConverter) out).fetchStarted();
                }
                while (qp.getResults(res)) {
                    for (String r : res) {
                        if (escapeCRLF) {
                            r = EscapeCRLFHelper.escapeCRLF(r);
                        }
                        out.println(r);
                    }
                    counter += res.size();
                    res.clear();
                    if (out.checkError()) {
                        break;
                    }
                }
            } catch (IOException e) {
                console.printError("Failed with exception " + e.getClass().getName() + ":" + e.getMessage(), "\n" + org.apache.hadoop.util.StringUtils.stringifyException(e));
                ret = 1;
            }
            qp.close();
            if (out instanceof FetchConverter) {
                ((FetchConverter) out).fetchFinished();
            }
            console.printInfo("Time taken: " + timeTaken + " seconds" + (counter == 0 ? "" : ", Fetched: " + counter + " row(s)"));
        } else {
            String firstToken = tokenizeCmd(cmd.trim())[0];
            String cmd_1 = getFirstCmd(cmd.trim(), firstToken.length());
            if (ss.getIsVerbose()) {
                ss.out.println(firstToken + " " + cmd_1);
            }
            CommandProcessorResponse res = proc.run(cmd_1);
            if (res.getResponseCode() != 0) {
                ss.out.println("Query returned non-zero code: " + res.getResponseCode() + ", cause: " + res.getErrorMessage());
            }
            if (res.getConsoleMessages() != null) {
                for (String consoleMsg : res.getConsoleMessages()) {
                    console.printInfo(consoleMsg);
                }
            }
            ret = res.getResponseCode();
        }
    }
    return ret;
}
Also used : FetchConverter(org.apache.hadoop.hive.common.io.FetchConverter) CachingPrintStream(org.apache.hadoop.hive.common.io.CachingPrintStream) PrintStream(java.io.PrintStream) CommandProcessorResponse(org.apache.hadoop.hive.ql.processors.CommandProcessorResponse) ArrayList(java.util.ArrayList) IDriver(org.apache.hadoop.hive.ql.IDriver) IOException(java.io.IOException)

Example 22 with IDriver

use of org.apache.hadoop.hive.ql.IDriver in project hive by apache.

the class TestCliDriverMethods method headerPrintingTestDriver.

/**
 * Do the actual testing against a mocked CliDriver based on what type of schema
 *
 * @param mockSchema
 *          Schema to throw against test
 * @return Output that would have been sent to the user
 * @throws CommandNeedRetryException
 *           won't actually be thrown
 */
private PrintStream headerPrintingTestDriver(Schema mockSchema) {
    CliDriver cliDriver = new CliDriver();
    // We want the driver to try to print the header...
    Configuration conf = mock(Configuration.class);
    when(conf.getBoolean(eq(ConfVars.HIVE_CLI_PRINT_HEADER.varname), anyBoolean())).thenReturn(true);
    cliDriver.setConf(conf);
    IDriver proc = mock(IDriver.class);
    CommandProcessorResponse cpr = mock(CommandProcessorResponse.class);
    when(cpr.getResponseCode()).thenReturn(0);
    when(proc.run(anyString())).thenReturn(cpr);
    // and then see what happens based on the provided schema
    when(proc.getSchema()).thenReturn(mockSchema);
    CliSessionState mockSS = mock(CliSessionState.class);
    PrintStream mockOut = mock(PrintStream.class);
    mockSS.out = mockOut;
    cliDriver.processLocalCmd("use default;", proc, mockSS);
    return mockOut;
}
Also used : PrintStream(java.io.PrintStream) Configuration(org.apache.hadoop.conf.Configuration) CommandProcessorResponse(org.apache.hadoop.hive.ql.processors.CommandProcessorResponse) IDriver(org.apache.hadoop.hive.ql.IDriver)

Example 23 with IDriver

use of org.apache.hadoop.hive.ql.IDriver in project hive by apache.

the class TestHiveTestEnvSetup method afterClass.

@AfterClass
public static void afterClass() throws Exception {
    IDriver driver = createDriver();
    dropTables(driver);
}
Also used : IDriver(org.apache.hadoop.hive.ql.IDriver) AfterClass(org.junit.AfterClass)

Example 24 with IDriver

use of org.apache.hadoop.hive.ql.IDriver in project hive by apache.

the class TestCounterMapping method testUsageOfRuntimeInfo.

@Test
public void testUsageOfRuntimeInfo() throws ParseException {
    IDriver driver = createDriver();
    String query = "select sum(u) from tu where u>1";
    PlanMapper pm1 = getMapperForQuery(driver, query);
    List<FilterOperator> filters1 = pm1.getAll(FilterOperator.class);
    filters1.sort(OPERATOR_ID_COMPARATOR.reversed());
    FilterOperator filter1 = filters1.get(0);
    driver = createDriver();
    ((ReExecDriver) driver).setRuntimeStatsSource(new SimpleRuntimeStatsSource(pm1));
    PlanMapper pm2 = getMapperForQuery(driver, query);
    List<FilterOperator> filters2 = pm2.getAll(FilterOperator.class);
    filters2.sort(OPERATOR_ID_COMPARATOR.reversed());
    FilterOperator filter2 = filters2.get(0);
    assertEquals("original check", 7, filter1.getStatistics().getNumRows());
    assertEquals("optimized check", 6, filter2.getStatistics().getNumRows());
}
Also used : FilterOperator(org.apache.hadoop.hive.ql.exec.FilterOperator) SimpleRuntimeStatsSource(org.apache.hadoop.hive.ql.plan.mapper.SimpleRuntimeStatsSource) PlanMapper(org.apache.hadoop.hive.ql.plan.mapper.PlanMapper) IDriver(org.apache.hadoop.hive.ql.IDriver) ReExecDriver(org.apache.hadoop.hive.ql.reexec.ReExecDriver) Test(org.junit.Test)

Example 25 with IDriver

use of org.apache.hadoop.hive.ql.IDriver in project hive by apache.

the class TestCounterMapping method beforeClass.

@BeforeClass
public static void beforeClass() throws Exception {
    IDriver driver = createDriver();
    dropTables(driver);
    String[] cmds = { // @formatter:off
    "create table s (x int)", "insert into s values (1),(2),(3),(4),(5),(6),(7),(8),(9),(10)", "create table tu(id_uv int,id_uw int,u int)", "create table tv(id_uv int,v int)", "create table tw(id_uw int,w int)", "from s\n" + "insert overwrite table tu\n" + "        select x,x,x\n" + "        where x<=6 or x=10\n" + "insert overwrite table tv\n" + "        select x,x\n" + "        where x<=3 or x=10\n" + "insert overwrite table tw\n" + "        select x,x\n" + "" // @formatter:on
    };
    for (String cmd : cmds) {
        int ret = driver.run(cmd).getResponseCode();
        assertEquals("Checking command success", 0, ret);
    }
}
Also used : IDriver(org.apache.hadoop.hive.ql.IDriver) BeforeClass(org.junit.BeforeClass)

Aggregations

IDriver (org.apache.hadoop.hive.ql.IDriver)29 Test (org.junit.Test)11 PlanMapper (org.apache.hadoop.hive.ql.plan.mapper.PlanMapper)10 HiveConf (org.apache.hadoop.hive.conf.HiveConf)7 FilterOperator (org.apache.hadoop.hive.ql.exec.FilterOperator)5 CommandProcessorResponse (org.apache.hadoop.hive.ql.processors.CommandProcessorResponse)4 AfterClass (org.junit.AfterClass)4 BeforeClass (org.junit.BeforeClass)4 PrintStream (java.io.PrintStream)3 ArrayList (java.util.ArrayList)3 CliSessionState (org.apache.hadoop.hive.cli.CliSessionState)3 LinkGroup (org.apache.hadoop.hive.ql.plan.mapper.PlanMapper.LinkGroup)3 OperatorStatsReaderHook (org.apache.hadoop.hive.ql.stats.OperatorStatsReaderHook)3 IOException (java.io.IOException)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 LogInitializationException (org.apache.hadoop.hive.common.LogUtils.LogInitializationException)2 OperatorStats (org.apache.hadoop.hive.ql.stats.OperatorStats)2 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 SQLException (java.sql.SQLException)1