Search in sources :

Example 16 with SessionState

use of org.apache.hadoop.hive.ql.session.SessionState in project hive by apache.

the class DeleteResourceProcessor method run.

@Override
public CommandProcessorResponse run(String command) {
    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 = command.split("\\s+");
    SessionState.ResourceType t;
    if (tokens.length < 1 || (t = SessionState.find_resource_type(tokens[0])) == null) {
        console.printError("Usage: delete [" + StringUtils.join(SessionState.ResourceType.values(), "|") + "] <value> [<value>]*");
        return new CommandProcessorResponse(1);
    }
    CommandProcessorResponse authErrResp = CommandUtil.authorizeCommand(ss, HiveOperationType.DELETE, Arrays.asList(tokens));
    if (authErrResp != null) {
        // there was an authorization issue
        return authErrResp;
    }
    if (tokens.length >= 2) {
        ss.delete_resources(t, Arrays.asList(Arrays.copyOfRange(tokens, 1, tokens.length)));
    } else {
        ss.delete_resources(t);
    }
    return new CommandProcessorResponse(0);
}
Also used : SessionState(org.apache.hadoop.hive.ql.session.SessionState) VariableSubstitution(org.apache.hadoop.hive.conf.VariableSubstitution) HiveVariableSource(org.apache.hadoop.hive.conf.HiveVariableSource) Map(java.util.Map)

Example 17 with SessionState

use of org.apache.hadoop.hive.ql.session.SessionState in project hive by apache.

the class ResetProcessor method run.

@Override
public CommandProcessorResponse run(String command) throws CommandNeedRetryException {
    SessionState ss = SessionState.get();
    CommandProcessorResponse authErrResp = CommandUtil.authorizeCommand(ss, HiveOperationType.RESET, Arrays.asList(command));
    if (authErrResp != null) {
        // there was an authorization issue
        return authErrResp;
    }
    command = command.trim();
    if (StringUtils.isBlank(command)) {
        resetOverridesOnly(ss);
        return new CommandProcessorResponse(0);
    }
    String[] parts = command.split("\\s+");
    boolean isDefault = false;
    List<String> varnames = new ArrayList<>(parts.length);
    for (String part : parts) {
        if (part.isEmpty())
            continue;
        if (DEFAULT_ARG.equals(part)) {
            isDefault = true;
        } else {
            varnames.add(part);
        }
    }
    if (varnames.isEmpty()) {
        return new CommandProcessorResponse(1, "No variable names specified", "42000");
    }
    String message = "";
    for (String varname : varnames) {
        if (isDefault) {
            if (!message.isEmpty()) {
                message += ", ";
            }
            message += varname;
            resetToDefault(ss, varname);
        } else {
            resetOverrideOnly(ss, varname);
        }
    }
    return new CommandProcessorResponse(0, isDefault ? Lists.newArrayList("Resetting " + message + " to default values") : null);
}
Also used : SessionState(org.apache.hadoop.hive.ql.session.SessionState) ArrayList(java.util.ArrayList)

Example 18 with SessionState

use of org.apache.hadoop.hive.ql.session.SessionState in project hive by apache.

the class SetProcessor method setVariable.

public static CommandProcessorResponse setVariable(String varname, String varvalue) throws Exception {
    SessionState ss = SessionState.get();
    if (varvalue.contains("\n")) {
        ss.err.println("Warning: Value had a \\n character in it.");
    }
    varname = varname.trim();
    String nonErrorMessage = null;
    if (varname.startsWith(ENV_PREFIX)) {
        ss.err.println("env:* variables can not be set.");
        // Should we propagate the error message properly?
        return new CommandProcessorResponse(1);
    } else if (varname.startsWith(SYSTEM_PREFIX)) {
        String propName = varname.substring(SYSTEM_PREFIX.length());
        System.getProperties().setProperty(propName, new VariableSubstitution(new HiveVariableSource() {

            @Override
            public Map<String, String> getHiveVariable() {
                return SessionState.get().getHiveVariables();
            }
        }).substitute(ss.getConf(), varvalue));
    } else if (varname.startsWith(HIVECONF_PREFIX)) {
        String propName = varname.substring(HIVECONF_PREFIX.length());
        nonErrorMessage = setConf(varname, propName, varvalue, false);
    } else if (varname.startsWith(HIVEVAR_PREFIX)) {
        String propName = varname.substring(HIVEVAR_PREFIX.length());
        ss.getHiveVariables().put(propName, new VariableSubstitution(new HiveVariableSource() {

            @Override
            public Map<String, String> getHiveVariable() {
                return SessionState.get().getHiveVariables();
            }
        }).substitute(ss.getConf(), varvalue));
    } else if (varname.startsWith(METACONF_PREFIX)) {
        String propName = varname.substring(METACONF_PREFIX.length());
        Hive hive = Hive.get(ss.getConf());
        hive.setMetaConf(propName, new VariableSubstitution(new HiveVariableSource() {

            @Override
            public Map<String, String> getHiveVariable() {
                return SessionState.get().getHiveVariables();
            }
        }).substitute(ss.getConf(), varvalue));
    } else {
        nonErrorMessage = setConf(varname, varname, varvalue, true);
        if (varname.equals(HiveConf.ConfVars.HIVE_SESSION_HISTORY_ENABLED.toString())) {
            SessionState.get().updateHistory(Boolean.parseBoolean(varvalue), ss);
        }
    }
    return nonErrorMessage == null ? new CommandProcessorResponse(0) : new CommandProcessorResponse(0, Lists.newArrayList(nonErrorMessage));
}
Also used : SessionState(org.apache.hadoop.hive.ql.session.SessionState) Hive(org.apache.hadoop.hive.ql.metadata.Hive) VariableSubstitution(org.apache.hadoop.hive.conf.VariableSubstitution) HiveVariableSource(org.apache.hadoop.hive.conf.HiveVariableSource) MetadataTypedColumnsetSerDe.defaultNullString(org.apache.hadoop.hive.serde2.MetadataTypedColumnsetSerDe.defaultNullString) TreeMap(java.util.TreeMap) Map(java.util.Map) SortedMap(java.util.SortedMap)

Example 19 with SessionState

use of org.apache.hadoop.hive.ql.session.SessionState in project hive by apache.

the class SetProcessor method run.

@Override
public CommandProcessorResponse run(String command) {
    SessionState ss = SessionState.get();
    String nwcmd = command.trim();
    if (nwcmd.equals("")) {
        dumpOptions(ss.getConf().getChangedProperties());
        return createProcessorSuccessResponse();
    }
    if (nwcmd.equals("-v")) {
        Properties properties = null;
        if (ss.getConf().getVar(HiveConf.ConfVars.HIVE_EXECUTION_ENGINE).equals("tez")) {
            Class<?> clazz;
            try {
                clazz = Class.forName("org.apache.tez.dag.api.TezConfiguration");
                Configuration tezConf = (Configuration) clazz.getConstructor(Configuration.class).newInstance(ss.getConf());
                properties = HiveConf.getProperties(tezConf);
            } catch (Exception e) {
                return new CommandProcessorResponse(1, e.getMessage(), "42000", e);
            }
        } else {
            properties = ss.getConf().getAllProperties();
        }
        dumpOptions(properties);
        return createProcessorSuccessResponse();
    }
    String[] part = new String[2];
    int eqIndex = nwcmd.indexOf('=');
    if (nwcmd.contains("=")) {
        if (eqIndex == nwcmd.length() - 1) {
            //x=
            part[0] = nwcmd.substring(0, nwcmd.length() - 1);
            part[1] = "";
        } else {
            //x=y
            part[0] = nwcmd.substring(0, eqIndex).trim();
            part[1] = nwcmd.substring(eqIndex + 1).trim();
        }
        if (part[0].equals("silent")) {
            ss.setIsSilent(getBoolean(part[1]));
            return new CommandProcessorResponse(0);
        }
        return executeSetVariable(part[0], part[1]);
    }
    try {
        return getVariable(nwcmd);
    } catch (Exception e) {
        return new CommandProcessorResponse(1, e.getMessage(), "42000", e);
    }
}
Also used : SessionState(org.apache.hadoop.hive.ql.session.SessionState) Configuration(org.apache.hadoop.conf.Configuration) MetadataTypedColumnsetSerDe.defaultNullString(org.apache.hadoop.hive.serde2.MetadataTypedColumnsetSerDe.defaultNullString) Properties(java.util.Properties)

Example 20 with SessionState

use of org.apache.hadoop.hive.ql.session.SessionState in project hive by apache.

the class SetProcessor method getVariable.

private CommandProcessorResponse getVariable(String varname) throws Exception {
    SessionState ss = SessionState.get();
    if (varname.equals("silent")) {
        ss.out.println("silent" + "=" + ss.getIsSilent());
        return createProcessorSuccessResponse();
    }
    if (varname.startsWith(SYSTEM_PREFIX)) {
        String propName = varname.substring(SYSTEM_PREFIX.length());
        String result = System.getProperty(propName);
        if (result != null) {
            if (isHidden(propName)) {
                ss.out.println(SYSTEM_PREFIX + propName + " is a hidden config");
            } else {
                ss.out.println(SYSTEM_PREFIX + propName + "=" + result);
            }
            return createProcessorSuccessResponse();
        } else {
            ss.out.println(propName + " is undefined as a system property");
            return new CommandProcessorResponse(1);
        }
    } else if (varname.indexOf(ENV_PREFIX) == 0) {
        String var = varname.substring(ENV_PREFIX.length());
        if (System.getenv(var) != null) {
            if (isHidden(var)) {
                ss.out.println(ENV_PREFIX + var + " is a hidden config");
            } else {
                ss.out.println(ENV_PREFIX + var + "=" + System.getenv(var));
            }
            return createProcessorSuccessResponse();
        } else {
            ss.out.println(varname + " is undefined as an environmental variable");
            return new CommandProcessorResponse(1);
        }
    } else if (varname.indexOf(HIVECONF_PREFIX) == 0) {
        String var = varname.substring(HIVECONF_PREFIX.length());
        if (ss.getConf().isHiddenConfig(var)) {
            ss.out.println(HIVECONF_PREFIX + var + " is a hidden config");
            return createProcessorSuccessResponse();
        }
        if (ss.getConf().get(var) != null) {
            ss.out.println(HIVECONF_PREFIX + var + "=" + ss.getConf().get(var));
            return createProcessorSuccessResponse();
        } else {
            ss.out.println(varname + " is undefined as a hive configuration variable");
            return new CommandProcessorResponse(1);
        }
    } else if (varname.indexOf(HIVEVAR_PREFIX) == 0) {
        String var = varname.substring(HIVEVAR_PREFIX.length());
        if (ss.getHiveVariables().get(var) != null) {
            ss.out.println(HIVEVAR_PREFIX + var + "=" + ss.getHiveVariables().get(var));
            return createProcessorSuccessResponse();
        } else {
            ss.out.println(varname + " is undefined as a hive variable");
            return new CommandProcessorResponse(1);
        }
    } else if (varname.indexOf(METACONF_PREFIX) == 0) {
        String var = varname.substring(METACONF_PREFIX.length());
        Hive hive = Hive.get(ss.getConf());
        String value = hive.getMetaConf(var);
        if (value != null) {
            ss.out.println(METACONF_PREFIX + var + "=" + value);
            return createProcessorSuccessResponse();
        } else {
            ss.out.println(varname + " is undefined as a hive meta variable");
            return new CommandProcessorResponse(1);
        }
    } else {
        dumpOption(varname);
        return createProcessorSuccessResponse();
    }
}
Also used : SessionState(org.apache.hadoop.hive.ql.session.SessionState) Hive(org.apache.hadoop.hive.ql.metadata.Hive) MetadataTypedColumnsetSerDe.defaultNullString(org.apache.hadoop.hive.serde2.MetadataTypedColumnsetSerDe.defaultNullString)

Aggregations

SessionState (org.apache.hadoop.hive.ql.session.SessionState)96 IOException (java.io.IOException)24 HiveConf (org.apache.hadoop.hive.conf.HiveConf)19 HiveException (org.apache.hadoop.hive.ql.metadata.HiveException)13 ArrayList (java.util.ArrayList)12 LinkedList (java.util.LinkedList)11 Path (org.apache.hadoop.fs.Path)11 CliSessionState (org.apache.hadoop.hive.cli.CliSessionState)11 MetaException (org.apache.hadoop.hive.metastore.api.MetaException)10 File (java.io.File)9 FileNotFoundException (java.io.FileNotFoundException)9 Map (java.util.Map)8 Test (org.junit.Test)8 PrintStream (java.io.PrintStream)7 ExecutionException (java.util.concurrent.ExecutionException)6 FileStatus (org.apache.hadoop.fs.FileStatus)6 URI (java.net.URI)5 FileSystem (org.apache.hadoop.fs.FileSystem)5 Driver (org.apache.hadoop.hive.ql.Driver)5 SerDeException (org.apache.hadoop.hive.serde2.SerDeException)5