Search in sources :

Example 16 with VariableSubstitution

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());
    }
}
Also used : SessionState(org.apache.hadoop.hive.ql.session.SessionState) VariableSubstitution(org.apache.hadoop.hive.conf.VariableSubstitution) MetadataTypedColumnsetSerDe.defaultNullString(org.apache.hadoop.hive.serde2.MetadataTypedColumnsetSerDe.defaultNullString) ParseException(org.apache.commons.cli.ParseException)

Example 17 with VariableSubstitution

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);
    }
}
Also used : VariableSubstitution(org.apache.hadoop.hive.conf.VariableSubstitution) HiveVariableSource(org.apache.hadoop.hive.conf.HiveVariableSource)

Example 18 with VariableSubstitution

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));
}
Also used : VariableSubstitution(org.apache.hadoop.hive.conf.VariableSubstitution) HiveVariableSource(org.apache.hadoop.hive.conf.HiveVariableSource) HiveConf(org.apache.hadoop.hive.conf.HiveConf) SimpleDateFormat(java.text.SimpleDateFormat)

Example 19 with VariableSubstitution

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();
    }
}
Also used : SessionState(org.apache.hadoop.hive.ql.session.SessionState) CommandProcessorException(org.apache.hadoop.hive.ql.processors.CommandProcessorException) VariableSubstitution(org.apache.hadoop.hive.conf.VariableSubstitution) HiveVariableSource(org.apache.hadoop.hive.conf.HiveVariableSource) UnsupportedEncodingException(java.io.UnsupportedEncodingException) CachingPrintStream(org.apache.hadoop.hive.common.io.CachingPrintStream) SessionStream(org.apache.hadoop.hive.common.io.SessionStream) LogInitializationException(org.apache.hadoop.hive.common.LogUtils.LogInitializationException) HiveConf(org.apache.hadoop.hive.conf.HiveConf) Map(java.util.Map)

Aggregations

VariableSubstitution (org.apache.hadoop.hive.conf.VariableSubstitution)19 HiveVariableSource (org.apache.hadoop.hive.conf.HiveVariableSource)16 Map (java.util.Map)12 SessionState (org.apache.hadoop.hive.ql.session.SessionState)7 IOException (java.io.IOException)5 MetadataTypedColumnsetSerDe.defaultNullString (org.apache.hadoop.hive.serde2.MetadataTypedColumnsetSerDe.defaultNullString)5 HiveConf (org.apache.hadoop.hive.conf.HiveConf)4 HiveException (org.apache.hadoop.hive.ql.metadata.HiveException)4 UnsupportedEncodingException (java.io.UnsupportedEncodingException)3 LogInitializationException (org.apache.hadoop.hive.common.LogUtils.LogInitializationException)3 FieldSchema (org.apache.hadoop.hive.metastore.api.FieldSchema)3 CommandProcessorException (org.apache.hadoop.hive.ql.processors.CommandProcessorException)3 ImmutableMap (com.google.common.collect.ImmutableMap)2 File (java.io.File)2 FileNotFoundException (java.io.FileNotFoundException)2 SQLException (java.sql.SQLException)2 ParseException (org.apache.commons.cli.ParseException)2 ShellCmdExecutor (org.apache.hadoop.hive.common.cli.ShellCmdExecutor)2 IDriver (org.apache.hadoop.hive.ql.IDriver)2 LockException (org.apache.hadoop.hive.ql.lockmgr.LockException)2