Search in sources :

Example 11 with HiveVariableSource

use of org.apache.hadoop.hive.conf.HiveVariableSource in project hive by apache.

the class ResetProcessor method resetToDefault.

private static CommandProcessorResponse resetToDefault(SessionState ss, String varname) {
    varname = varname.trim();
    try {
        String nonErrorMessage = null;
        if (varname.startsWith(SystemVariables.HIVECONF_PREFIX)) {
            String propName = varname.substring(SystemVariables.HIVECONF_PREFIX.length());
            nonErrorMessage = SetProcessor.setConf(varname, propName, getConfVar(propName).getDefaultValue(), false);
        } else if (varname.startsWith(SystemVariables.METACONF_PREFIX)) {
            String propName = varname.substring(SystemVariables.METACONF_PREFIX.length());
            HiveConf.ConfVars confVars = getConfVar(propName);
            Hive.get(ss.getConf()).setMetaConf(propName, new VariableSubstitution(new HiveVariableSource() {

                @Override
                public Map<String, String> getHiveVariable() {
                    return SessionState.get().getHiveVariables();
                }
            }).substitute(ss.getConf(), confVars.getDefaultValue()));
        } else {
            String defaultVal = getConfVar(varname).getDefaultValue();
            nonErrorMessage = SetProcessor.setConf(varname, varname, defaultVal, true);
            if (varname.equals(HiveConf.ConfVars.HIVE_SESSION_HISTORY_ENABLED.toString())) {
                SessionState.get().updateHistory(Boolean.parseBoolean(defaultVal), ss);
            }
        }
        return nonErrorMessage == null ? new CommandProcessorResponse(0) : new CommandProcessorResponse(0, Lists.newArrayList(nonErrorMessage));
    } catch (Exception e) {
        return new CommandProcessorResponse(1, e.getMessage(), "42000", e instanceof IllegalArgumentException ? null : e);
    }
}
Also used : VariableSubstitution(org.apache.hadoop.hive.conf.VariableSubstitution) HiveVariableSource(org.apache.hadoop.hive.conf.HiveVariableSource)

Example 12 with HiveVariableSource

use of org.apache.hadoop.hive.conf.HiveVariableSource in project hive by apache.

the class SetProcessor method setConf.

/**
 * @return A console message that is not strong enough to fail the command (e.g. deprecation).
 */
static String setConf(SessionState ss, String varname, String key, String varvalue, boolean register) throws IllegalArgumentException {
    String result = null;
    HiveConf conf = ss.getConf();
    String value = new VariableSubstitution(new HiveVariableSource() {

        @Override
        public Map<String, String> getHiveVariable() {
            return ss.getHiveVariables();
        }
    }).substitute(conf, varvalue);
    if (conf.getBoolVar(HiveConf.ConfVars.HIVECONFVALIDATION)) {
        HiveConf.ConfVars confVars = HiveConf.getConfVars(key);
        if (confVars != null) {
            if (!confVars.isType(value)) {
                StringBuilder message = new StringBuilder();
                message.append("'SET ").append(varname).append('=').append(varvalue);
                message.append("' FAILED because ").append(key).append(" expects ");
                message.append(confVars.typeString()).append(" type value.");
                throw new IllegalArgumentException(message.toString());
            }
            String fail = confVars.validate(value);
            if (fail != null) {
                StringBuilder message = new StringBuilder();
                message.append("'SET ").append(varname).append('=').append(varvalue);
                message.append("' FAILED in validation : ").append(fail).append('.');
                throw new IllegalArgumentException(message.toString());
            }
        } else if (!removedConfigs.contains(key) && key.startsWith("hive.")) {
            throw new IllegalArgumentException("hive configuration " + key + " does not exists.");
        }
    }
    conf.verifyAndSet(key, value);
    if (HiveConf.ConfVars.HIVE_EXECUTION_ENGINE.varname.equals(key)) {
        if (!"spark".equals(value)) {
            ss.closeSparkSession();
        }
        if ("mr".equals(value)) {
            result = HiveConf.generateMrDeprecationWarning();
            LOG.warn(result);
        }
    }
    if (register) {
        ss.getOverriddenConfigurations().put(key, value);
    }
    return result;
}
Also used : VariableSubstitution(org.apache.hadoop.hive.conf.VariableSubstitution) HiveVariableSource(org.apache.hadoop.hive.conf.HiveVariableSource) HiveConf(org.apache.hadoop.hive.conf.HiveConf) MetadataTypedColumnsetSerDe.defaultNullString(org.apache.hadoop.hive.serde2.MetadataTypedColumnsetSerDe.defaultNullString)

Example 13 with HiveVariableSource

use of org.apache.hadoop.hive.conf.HiveVariableSource in project hive by apache.

the class CompileProcessor method parse.

/**
 * Parses the supplied command
 * @param ss
 * @throws CompileProcessorException if the code can not be compiled or the jar can not be made
 */
@VisibleForTesting
void parse(SessionState ss) throws CompileProcessorException {
    if (ss != null) {
        command = new VariableSubstitution(new HiveVariableSource() {

            @Override
            public Map<String, String> getHiveVariable() {
                return SessionState.get().getHiveVariables();
            }
        }).substitute(ss.getConf(), command);
    }
    if (command == null || command.length() == 0) {
        throw new CompileProcessorException("Command was empty");
    }
    StringBuilder toCompile = new StringBuilder();
    int startPosition = 0;
    int endPosition = -1;
    /* TODO Escape handling may be changed by a follow on.
     * The largest issue is ; which are treated as statement
     * terminators for the cli. Once the cli is fixed this
     * code should be re-investigated
     */
    while (command.charAt(startPosition++) != '`' && startPosition < command.length()) {
    }
    if (startPosition == command.length()) {
        throw new CompileProcessorException(SYNTAX);
    }
    for (int i = startPosition; i < command.length(); i++) {
        if (command.charAt(i) == '\\') {
            toCompile.append(command.charAt(i + 1));
            i = i + 1;
            continue;
        } else if (command.charAt(i) == '`') {
            endPosition = i;
            break;
        } else {
            toCompile.append(command.charAt(i));
        }
    }
    if (endPosition == -1) {
        throw new CompileProcessorException(SYNTAX);
    }
    StringTokenizer st = new StringTokenizer(command.substring(endPosition + 1), " ");
    if (st.countTokens() != 4) {
        throw new CompileProcessorException(SYNTAX);
    }
    String shouldBeAs = st.nextToken();
    if (!shouldBeAs.equalsIgnoreCase(AS)) {
        throw new CompileProcessorException(SYNTAX);
    }
    setLang(st.nextToken());
    if (!lang.equalsIgnoreCase(GROOVY)) {
        throw new CompileProcessorException("Can not compile " + lang + ". Hive can only compile " + GROOVY);
    }
    String shouldBeNamed = st.nextToken();
    if (!shouldBeNamed.equalsIgnoreCase(NAMED)) {
        throw new CompileProcessorException(SYNTAX);
    }
    setNamed(st.nextToken());
    setCode(toCompile.toString());
}
Also used : StringTokenizer(java.util.StringTokenizer) VariableSubstitution(org.apache.hadoop.hive.conf.VariableSubstitution) HiveVariableSource(org.apache.hadoop.hive.conf.HiveVariableSource) Map(java.util.Map) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 14 with HiveVariableSource

use of org.apache.hadoop.hive.conf.HiveVariableSource in project hive by apache.

the class DfsProcessor method run.

@Override
public CommandProcessorResponse run(String command) {
    try {
        SessionState ss = SessionState.get();
        command = new VariableSubstitution(new HiveVariableSource() {

            @Override
            public Map<String, String> getHiveVariable() {
                return SessionState.get().getHiveVariables();
            }
        }).substitute(ss.getConf(), command);
        String[] tokens = splitCmd(command);
        CommandProcessorResponse authErrResp = CommandUtil.authorizeCommand(ss, HiveOperationType.DFS, Arrays.asList(tokens));
        if (authErrResp != null) {
            // there was an authorization issue
            return authErrResp;
        }
        PrintStream oldOut = System.out;
        if (ss != null && ss.out != null) {
            System.setOut(ss.out);
        }
        int ret = dfs.run(tokens);
        if (ret != 0) {
            console.printError("Command " + command + " failed with exit code = " + ret);
        }
        System.setOut(oldOut);
        return new CommandProcessorResponse(ret, null, null, dfsSchema);
    } catch (Exception e) {
        console.printError("Exception raised from DFSShell.run " + e.getLocalizedMessage(), org.apache.hadoop.util.StringUtils.stringifyException(e));
        return new CommandProcessorResponse(1);
    }
}
Also used : SessionState(org.apache.hadoop.hive.ql.session.SessionState) PrintStream(java.io.PrintStream) VariableSubstitution(org.apache.hadoop.hive.conf.VariableSubstitution) HiveVariableSource(org.apache.hadoop.hive.conf.HiveVariableSource) Map(java.util.Map) HiveException(org.apache.hadoop.hive.ql.metadata.HiveException)

Aggregations

HiveVariableSource (org.apache.hadoop.hive.conf.HiveVariableSource)14 VariableSubstitution (org.apache.hadoop.hive.conf.VariableSubstitution)14 Map (java.util.Map)10 SessionState (org.apache.hadoop.hive.ql.session.SessionState)5 HiveConf (org.apache.hadoop.hive.conf.HiveConf)4 IOException (java.io.IOException)3 HiveException (org.apache.hadoop.hive.ql.metadata.HiveException)3 MetadataTypedColumnsetSerDe.defaultNullString (org.apache.hadoop.hive.serde2.MetadataTypedColumnsetSerDe.defaultNullString)3 PrintStream (java.io.PrintStream)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 CliSessionState (org.apache.hadoop.hive.cli.CliSessionState)2 LogInitializationException (org.apache.hadoop.hive.common.LogUtils.LogInitializationException)2 FieldSchema (org.apache.hadoop.hive.metastore.api.FieldSchema)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 SQLException (java.sql.SQLException)1 SimpleDateFormat (java.text.SimpleDateFormat)1 HashMap (java.util.HashMap)1