Example #1
0
  // Generate the beeline args per hive conf and execute the given script
  public void runBeeLine(String sqlScriptFile) throws IOException {
    List<String> argList = new ArrayList<String>();
    argList.add("-u");
    argList.add(HiveSchemaHelper.getValidConfVar(ConfVars.METASTORECONNECTURLKEY, hiveConf));
    argList.add("-d");
    argList.add(HiveSchemaHelper.getValidConfVar(ConfVars.METASTORE_CONNECTION_DRIVER, hiveConf));
    argList.add("-n");
    argList.add(userName);
    argList.add("-p");
    argList.add(passWord);
    argList.add("-f");
    argList.add(sqlScriptFile);

    // run the script using Beeline
    BeeLine beeLine = new BeeLine();
    if (!verbose) {
      beeLine.setOutputStream(new PrintStream(new NullOutputStream()));
      beeLine.getOpts().setSilent(true);
    }
    beeLine.getOpts().setAllowMultiLineCommand(false);
    beeLine.getOpts().setIsolation("TRANSACTION_READ_COMMITTED");
    int status = beeLine.begin(argList.toArray(new String[0]), null);
    if (status != 0) {
      throw new IOException("Schema script failed, errorcode " + status);
    }
  }
Example #2
0
 /** Update the options after connection is established in CLI mode. */
 public void updateBeeLineOptsFromConf() {
   if (!beeLine.isBeeLine()) {
     if (conf == null) {
       conf = beeLine.getCommands().getHiveConf(false);
     }
     setForce(HiveConf.getBoolVar(conf, HiveConf.ConfVars.CLIIGNOREERRORS));
   }
 }
Example #3
0
 public boolean getShowHeader() {
   if (beeLine.isBeeLine()) {
     return showHeader;
   } else {
     boolean header;
     HiveConf conf = beeLine.getCommands().getHiveConf(true);
     header = HiveConf.getBoolVar(conf, HiveConf.ConfVars.HIVE_CLI_PRINT_HEADER);
     return header;
   }
 }
Example #4
0
 public boolean set(String key, String value, boolean quiet) {
   try {
     beeLine.getReflector().invoke(this, "set" + key, new Object[] {value});
     return true;
   } catch (Exception e) {
     if (!quiet) {
       beeLine.error(beeLine.loc("error-setting", new Object[] {key, e}));
     }
     return false;
   }
 }
Example #5
0
 public void save(OutputStream out) throws IOException {
   try {
     Properties props = toProperties();
     // don't save maxwidth: it is automatically set based on
     // the terminal configuration
     props.remove(PROPERTY_PREFIX + "maxwidth");
     props.store(out, beeLine.getApplicationTitle());
   } catch (Exception e) {
     beeLine.handleException(e);
   }
 }
Example #6
0
  public Properties toProperties()
      throws IllegalAccessException, InvocationTargetException, ClassNotFoundException {
    Properties props = new Properties();

    String[] names = propertyNames();
    for (int i = 0; names != null && i < names.length; i++) {
      Object o = beeLine.getReflector().invoke(this, "get" + names[i], new Object[0]);
      props.setProperty(PROPERTY_PREFIX + names[i], o == null ? "" : o.toString());
    }
    beeLine.debug("properties: " + props.toString());
    return props;
  }
Example #7
0
 @Override
 public int complete(String buf, int pos, List cand) {
   try {
     return new StringsCompleter(propertyNames()).complete(buf, pos, cand);
   } catch (Exception e) {
     beeLine.handleException(e);
     return -1;
   }
 }
Example #8
0
 public void setOutputFormat(String outputFormat) {
   if (outputFormat.equalsIgnoreCase("csv") || outputFormat.equalsIgnoreCase("tsv")) {
     beeLine.info("Format " + outputFormat + " is deprecated, please use " + outputFormat + "2");
   }
   this.outputFormat = outputFormat;
 }