Search in sources :

Example 16 with HiveVariableSource

use of org.apache.hadoop.hive.conf.HiveVariableSource 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

HiveVariableSource (org.apache.hadoop.hive.conf.HiveVariableSource)16 VariableSubstitution (org.apache.hadoop.hive.conf.VariableSubstitution)16 Map (java.util.Map)12 IOException (java.io.IOException)5 SessionState (org.apache.hadoop.hive.ql.session.SessionState)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 CommandProcessorException (org.apache.hadoop.hive.ql.processors.CommandProcessorException)3 MetadataTypedColumnsetSerDe.defaultNullString (org.apache.hadoop.hive.serde2.MetadataTypedColumnsetSerDe.defaultNullString)3 ImmutableMap (com.google.common.collect.ImmutableMap)2 File (java.io.File)2 FileNotFoundException (java.io.FileNotFoundException)2 SQLException (java.sql.SQLException)2 ShellCmdExecutor (org.apache.hadoop.hive.common.cli.ShellCmdExecutor)2 FieldSchema (org.apache.hadoop.hive.metastore.api.FieldSchema)2 IDriver (org.apache.hadoop.hive.ql.IDriver)2 LockException (org.apache.hadoop.hive.ql.lockmgr.LockException)2 AuthorizationException (org.apache.hadoop.hive.ql.metadata.AuthorizationException)2