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);
}
}
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;
}
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());
}
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);
}
}
Aggregations