use of org.apache.hadoop.hive.conf.VariableSubstitution in project hive by apache.
the class LlapCacheResourceProcessor method run.
@Override
public CommandProcessorResponse run(String command) throws CommandProcessorException {
SessionState ss = SessionState.get();
command = new VariableSubstitution(() -> SessionState.get().getHiveVariables()).substitute(ss.getConf(), command);
String[] tokens = command.split("\\s+");
if (tokens.length < 1) {
throw new CommandProcessorException("LLAP Cache Processor Helper Failed: Command arguments are empty.");
}
String[] params = Arrays.copyOfRange(tokens, 1, tokens.length);
try {
return llapCacheCommandHandler(ss, params);
} catch (CommandProcessorException e) {
throw e;
} catch (Exception e) {
throw new CommandProcessorException("LLAP Cache Processor Helper Failed: " + e.getMessage());
}
}
use of org.apache.hadoop.hive.conf.VariableSubstitution in project hive by apache.
the class ResetProcessor method resetToDefault.
private static CommandProcessorResponse resetToDefault(SessionState ss, String varname) throws CommandProcessorException {
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 new CommandProcessorResponse(null, nonErrorMessage);
} catch (Exception e) {
Throwable exception = e instanceof IllegalArgumentException ? null : e;
throw new CommandProcessorException(1, -1, e.getMessage(), "42000", exception);
}
}
use of org.apache.hadoop.hive.conf.VariableSubstitution in project hive by apache.
the class AbstractCoreBlobstoreCliDriver method setupUniqueTestPath.
/**
* Generates a unique test path for this particular CliDriver in the following form:
* ${test.blobstore.path}/CoreBlobstore[Negative]CliDriver/20160101.053046.332-{random number 000-999}
* 20160101.053046.332 represents the current datetime:
* {year}{month}{day}.{hour}{minute}{second}.{millisecond}
* Random integer 000-999 included to avoid collisions when two test runs are started at the same millisecond with
* the same ${test.blobstore.path} (possible if test runs are controlled by an automated system)
*/
private void setupUniqueTestPath() {
String testBlobstorePath = new VariableSubstitution(new HiveVariableSource() {
@Override
public Map<String, String> getHiveVariable() {
return null;
}
}).substitute(new HiveConf(), qt.getConf().get(HCONF_TEST_BLOBSTORE_PATH));
testBlobstorePath = HiveTestEnvSetup.ensurePathEndsInSlash(testBlobstorePath);
// name of child class
testBlobstorePath += HiveTestEnvSetup.ensurePathEndsInSlash(this.getClass().getSimpleName());
String uid = new SimpleDateFormat("yyyyMMdd.HHmmss.SSS").format(Calendar.getInstance().getTime()) + "-" + String.format("%03d", (int) (Math.random() * 999));
testBlobstorePathUnique = testBlobstorePath + uid;
qt.getQOutProcessor().addPatternWithMaskComment(testBlobstorePathUnique, String.format("### %s ###", HCONF_TEST_BLOBSTORE_PATH));
}
use of org.apache.hadoop.hive.conf.VariableSubstitution in project hive by apache.
the class CliDriver method run.
public int run(String[] args) throws Exception {
OptionsProcessor oproc = new OptionsProcessor();
if (!oproc.process_stage1(args)) {
return 1;
}
// NOTE: It is critical to do this here so that log4j is reinitialized
// before any of the other core hive classes are loaded
boolean logInitFailed = false;
String logInitDetailMessage;
try {
logInitDetailMessage = LogUtils.initHiveLog4j();
} catch (LogInitializationException e) {
logInitFailed = true;
logInitDetailMessage = e.getMessage();
}
CliSessionState ss = new CliSessionState(new HiveConf(SessionState.class));
ss.in = System.in;
try {
ss.out = new SessionStream(System.out, true, StandardCharsets.UTF_8.name());
ss.info = new SessionStream(System.err, true, StandardCharsets.UTF_8.name());
ss.err = new CachingPrintStream(System.err, true, StandardCharsets.UTF_8.name());
} catch (UnsupportedEncodingException e) {
return 3;
}
if (!oproc.process_stage2(ss)) {
return 2;
}
if (!ss.getIsSilent()) {
if (logInitFailed) {
System.err.println(logInitDetailMessage);
} else {
SessionState.getConsole().printInfo(logInitDetailMessage);
}
}
// set all properties specified via command line
HiveConf conf = ss.getConf();
for (Map.Entry<Object, Object> item : ss.cmdProperties.entrySet()) {
conf.set((String) item.getKey(), (String) item.getValue());
ss.getOverriddenConfigurations().put((String) item.getKey(), (String) item.getValue());
}
// read prompt configuration and substitute variables.
prompt = conf.getVar(HiveConf.ConfVars.CLIPROMPT);
prompt = new VariableSubstitution(new HiveVariableSource() {
@Override
public Map<String, String> getHiveVariable() {
return SessionState.get().getHiveVariables();
}
}).substitute(conf, prompt);
prompt2 = spacesForString(prompt);
if (HiveConf.getBoolVar(conf, ConfVars.HIVE_CLI_TEZ_SESSION_ASYNC)) {
// Start the session in a fire-and-forget manner. When the asynchronously initialized parts of
// the session are needed, the corresponding getters and other methods will wait as needed.
SessionState.beginStart(ss, console);
} else {
SessionState.start(ss);
}
ss.updateThreadName();
// Initialize metadata provider class and trimmer
CalcitePlanner.warmup();
// Create views registry
HiveMaterializedViewsRegistry.get().init();
// init metastore client cache
if (HiveConf.getBoolVar(conf, ConfVars.MSC_CACHE_ENABLED)) {
HiveMetaStoreClientWithLocalCache.init(conf);
}
// execute cli driver work
try {
executeDriver(ss, conf, oproc);
return 0;
} catch (CommandProcessorException e) {
return e.getResponseCode();
} finally {
ss.resetThreadName();
ss.close();
}
}
Aggregations