Package org.apache.hadoop.hive.ql.processors

Examples of org.apache.hadoop.hive.ql.processors.CommandProcessorResponse


  public CommandProcessorResponse run(String command) throws CommandNeedRetryException {
    errorMessage = null;
    SQLState = null;

    if (!validateConfVariables()) {
      return new CommandProcessorResponse(12, errorMessage, SQLState);
    }

    HiveDriverRunHookContext hookContext = new HiveDriverRunHookContextImpl(conf, command);
    // Get all the driver run hooks and pre-execute them.
    List<HiveDriverRunHook> driverRunHooks;
    try {
      driverRunHooks = getHooks(HiveConf.ConfVars.HIVE_DRIVER_RUN_HOOKS, HiveDriverRunHook.class);
      for (HiveDriverRunHook driverRunHook : driverRunHooks) {
          driverRunHook.preDriverRun(hookContext);
      }
    } catch (Exception e) {
      errorMessage = "FAILED: Hive Internal Error: " + Utilities.getNameMessage(e);
      SQLState = ErrorMsg.findSQLState(e.getMessage());
      console.printError(errorMessage + "\n"
          + org.apache.hadoop.util.StringUtils.stringifyException(e));
      return new CommandProcessorResponse(12, errorMessage, SQLState);
    }

    // Reset the perf logger
    PerfLogger perfLogger = PerfLogger.getPerfLogger(true);
    perfLogger.PerfLogBegin(LOG, PerfLogger.DRIVER_RUN);
    perfLogger.PerfLogBegin(LOG, PerfLogger.TIME_TO_SUBMIT);

    int ret = compile(command);
    if (ret != 0) {
      releaseLocks(ctx.getHiveLocks());
      return new CommandProcessorResponse(ret, errorMessage, SQLState);
    }

    boolean requireLock = false;
    boolean ckLock = checkLockManager();

    if (ckLock) {
      boolean lockOnlyMapred = HiveConf.getBoolVar(conf, HiveConf.ConfVars.HIVE_LOCK_MAPRED_ONLY);
      if(lockOnlyMapred) {
        Queue<Task<? extends Serializable>> taskQueue = new LinkedList<Task<? extends Serializable>>();
        taskQueue.addAll(plan.getRootTasks());
        while (taskQueue.peek() != null) {
          Task<? extends Serializable> tsk = taskQueue.remove();
          requireLock = requireLock || tsk.requireLock();
          if(requireLock) {
            break;
          }
          if (tsk instanceof ConditionalTask) {
            taskQueue.addAll(((ConditionalTask)tsk).getListTasks());
          }
          if(tsk.getChildTasks()!= null) {
            taskQueue.addAll(tsk.getChildTasks());
          }
          // does not add back up task here, because back up task should be the same
          // type of the original task.
        }
      } else {
        requireLock = true;
      }
    }

    if (requireLock) {
      ret = acquireReadWriteLocks();
      if (ret != 0) {
        releaseLocks(ctx.getHiveLocks());
        return new CommandProcessorResponse(ret, errorMessage, SQLState);
      }
    }

    ret = execute();
    if (ret != 0) {
      //if needRequireLock is false, the release here will do nothing because there is no lock
      releaseLocks(ctx.getHiveLocks());
      return new CommandProcessorResponse(ret, errorMessage, SQLState);
    }

    //if needRequireLock is false, the release here will do nothing because there is no lock
    releaseLocks(ctx.getHiveLocks());

    perfLogger.PerfLogEnd(LOG, PerfLogger.DRIVER_RUN);
    perfLogger.close(LOG, plan);

    // Take all the driver run hooks and post-execute them.
    try {
      for (HiveDriverRunHook driverRunHook : driverRunHooks) {
          driverRunHook.postDriverRun(hookContext);
      }
    } catch (Exception e) {
      errorMessage = "FAILED: Hive Internal Error: " + Utilities.getNameMessage(e);
      SQLState = ErrorMsg.findSQLState(e.getMessage());
      console.printError(errorMessage + "\n"
          + org.apache.hadoop.util.StringUtils.stringifyException(e));
      return new CommandProcessorResponse(12, errorMessage, SQLState);
    }

    return new CommandProcessorResponse(ret);
  }
View Full Code Here


            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());
            }
            ret = res.getResponseCode();
          }
        }
      } catch (CommandNeedRetryException e) {
        console.printInfo("Retry query with a different approach...");
        tryCount++;
View Full Code Here

    }

    /** Execute the query expecting success*/
    public void exec(String format, Object... args) throws Exception {
        String command = String.format(format, args);
        CommandProcessorResponse resp = hcatDriver.run(command);
        Assert.assertEquals(resp.getErrorMessage(), 0, resp.getResponseCode());
        Assert.assertEquals(resp.getErrorMessage(), null, resp.getErrorMessage());
    }
View Full Code Here

    }

    /** Execute the query expecting it to fail with AuthorizationException */
    public void execFail(String format, Object... args) throws Exception {
        String command = String.format(format, args);
        CommandProcessorResponse resp = hcatDriver.run(command);
        Assert.assertNotSame(resp.getErrorMessage(), 0, resp.getResponseCode());
        Assert.assertTrue((resp.getResponseCode() == 40000) || (resp.getResponseCode() == 403));
        if (resp.getErrorMessage() != null) {
            Assert.assertTrue(resp.getErrorMessage().contains("org.apache.hadoop.security.AccessControlException"));
        }
    }
View Full Code Here

        hcatDriver.run("create database " + dbName);
        hcatDriver.run("use " + dbName);
        hcatDriver.run("create table " + tblName + " (a int) partitioned by (b string) stored as RCFILE");

        CommandProcessorResponse response;

        response = hcatDriver.run("alter table " + tblName + " add partition (b='2') location '/tmp'");
        assertEquals(0, response.getResponseCode());
        assertNull(response.getErrorMessage());

        response = hcatDriver.run("alter table " + tblName + " set fileformat INPUTFORMAT 'org.apache.hadoop.hive.ql.io.RCFileInputFormat' OUTPUTFORMAT " +
                "'org.apache.hadoop.hive.ql.io.RCFileOutputFormat' inputdriver 'mydriver' outputdriver 'yourdriver'");
        assertEquals(0, response.getResponseCode());
        assertNull(response.getErrorMessage());

        hcatDriver.run("drop table " + tblName);
        hcatDriver.run("drop database " + dbName);
    }
View Full Code Here

    @Test
    public void testDescDB() throws CommandNeedRetryException, IOException {
        hcatDriver.run("drop database mydb cascade");
        assertEquals(0, hcatDriver.run("create database mydb").getResponseCode());
        CommandProcessorResponse resp = hcatDriver.run("describe database mydb");
        assertEquals(0, resp.getResponseCode());
        ArrayList<String> result = new ArrayList<String>();
        hcatDriver.getResults(result);
        assertTrue(result.get(0).contains("mydb.db"));
        hcatDriver.run("drop database mydb cascade");
    }
View Full Code Here

    }

    @Test
    public void testCreateTblWithLowerCasePartNames() throws CommandNeedRetryException, MetaException, TException, NoSuchObjectException {
        driver.run("drop table junit_sem_analysis");
        CommandProcessorResponse resp = driver.run("create table junit_sem_analysis (a int) partitioned by (B string) stored as TEXTFILE");
        assertEquals(resp.getResponseCode(), 0);
        assertEquals(null, resp.getErrorMessage());
        Table tbl = client.getTable(MetaStoreUtils.DEFAULT_DATABASE_NAME, TBL_NAME);
        assertEquals("Partition key name case problem", "b", tbl.getPartitionKeys().get(0).getName());
        driver.run("drop table junit_sem_analysis");
    }
View Full Code Here

        hcatDriver.run("drop table junit_sem_analysis");
    }

    @Test
    public void testUsNonExistentDB() throws CommandNeedRetryException {
        CommandProcessorResponse resp = hcatDriver.run("use no_such_db");
        assertEquals(1, resp.getResponseCode());
    }
View Full Code Here

        assertEquals(1, cols.size());
        assertTrue(cols.get(0).equals(new FieldSchema("a", "int", null)));
        assertEquals(RCFileInputFormat.class.getName(), tbl.getSd().getInputFormat());
        assertEquals(RCFileOutputFormat.class.getName(), tbl.getSd().getOutputFormat());

        CommandProcessorResponse resp = hcatDriver.run("create table if not exists junit_sem_analysis (a int) stored as RCFILE");
        assertEquals(0, resp.getResponseCode());
        assertNull(resp.getErrorMessage());
        tbl = client.getTable(MetaStoreUtils.DEFAULT_DATABASE_NAME, TBL_NAME);
        cols = tbl.getSd().getCols();
        assertEquals(1, cols.size());
        assertTrue(cols.get(0).equals(new FieldSchema("a", "int", null)));
        assertEquals(RCFileInputFormat.class.getName(), tbl.getSd().getInputFormat());
View Full Code Here

    @Test
    public void testAlterTblTouch() throws CommandNeedRetryException {

        hcatDriver.run("drop table junit_sem_analysis");
        hcatDriver.run("create table junit_sem_analysis (a int) partitioned by (b string) stored as RCFILE");
        CommandProcessorResponse response = hcatDriver.run("alter table junit_sem_analysis touch");
        assertEquals(0, response.getResponseCode());

        hcatDriver.run("alter table junit_sem_analysis touch partition (b='12')");
        assertEquals(0, response.getResponseCode());

        hcatDriver.run("drop table junit_sem_analysis");
    }
View Full Code Here

TOP

Related Classes of org.apache.hadoop.hive.ql.processors.CommandProcessorResponse

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.