Search in sources :

Example 6 with VariableSubstitution

use of org.apache.hadoop.hive.conf.VariableSubstitution in project hive by apache.

the class DeleteResourceProcessor method run.

@Override
public CommandProcessorResponse run(String command) throws CommandProcessorException {
    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>]*");
        throw new CommandProcessorException(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();
}
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 7 with VariableSubstitution

use of org.apache.hadoop.hive.conf.VariableSubstitution in project hive by apache.

the class ColumnStatsSemanticAnalyzer method genRewrittenQuery.

private static String genRewrittenQuery(Table tbl, List<String> colNames, List<String> colTypes, HiveConf conf, Map<String, String> partSpec, boolean isPartitionStats, boolean useTableValues) throws SemanticException {
    StringBuilder rewrittenQueryBuilder = new StringBuilder("select ");
    StringBuilder columnNamesBuilder = new StringBuilder();
    StringBuilder columnDummyValuesBuilder = new StringBuilder();
    for (int i = 0; i < colNames.size(); i++) {
        if (i > 0) {
            rewrittenQueryBuilder.append(" , ");
            columnNamesBuilder.append(" , ");
            columnDummyValuesBuilder.append(" , ");
        }
        final String columnName = unparseIdentifier(colNames.get(i), conf);
        final TypeInfo typeInfo = TypeInfoUtils.getTypeInfoFromTypeString(colTypes.get(i));
        genComputeStats(rewrittenQueryBuilder, conf, i, columnName, typeInfo);
        columnNamesBuilder.append(unparseIdentifier(columnName, conf));
        columnDummyValuesBuilder.append("cast(null as " + typeInfo.toString() + ")");
    }
    if (isPartitionStats) {
        for (FieldSchema fs : tbl.getPartCols()) {
            String identifier = unparseIdentifier(fs.getName(), conf);
            rewrittenQueryBuilder.append(" , ").append(identifier);
            columnNamesBuilder.append(" , ").append(identifier);
            columnDummyValuesBuilder.append(" , cast(null as ").append(TypeInfoUtils.getTypeInfoFromTypeString(fs.getType()).toString()).append(")");
        }
    }
    rewrittenQueryBuilder.append(" from ");
    if (useTableValues) {
        // TABLE(VALUES(cast(null as int),cast(null as string))) AS tablename(col1,col2)
        rewrittenQueryBuilder.append("table(values(");
        // Values
        rewrittenQueryBuilder.append(columnDummyValuesBuilder.toString());
        rewrittenQueryBuilder.append(")) as ");
        rewrittenQueryBuilder.append(unparseIdentifier(tbl.getTableName(), conf));
        rewrittenQueryBuilder.append("(");
        // Columns
        rewrittenQueryBuilder.append(columnNamesBuilder.toString());
        rewrittenQueryBuilder.append(")");
    } else {
        rewrittenQueryBuilder.append(unparseIdentifier(tbl.getDbName(), conf));
        rewrittenQueryBuilder.append(".");
        rewrittenQueryBuilder.append(unparseIdentifier(tbl.getTableName(), conf));
    }
    // query
    if (isPartitionStats) {
        rewrittenQueryBuilder.append(genPartitionClause(tbl, partSpec, conf));
    }
    String rewrittenQuery = rewrittenQueryBuilder.toString();
    rewrittenQuery = new VariableSubstitution(() -> SessionState.get().getHiveVariables()).substitute(conf, rewrittenQuery);
    return rewrittenQuery;
}
Also used : VariableSubstitution(org.apache.hadoop.hive.conf.VariableSubstitution) FieldSchema(org.apache.hadoop.hive.metastore.api.FieldSchema) PrimitiveTypeInfo(org.apache.hadoop.hive.serde2.typeinfo.PrimitiveTypeInfo) TypeInfo(org.apache.hadoop.hive.serde2.typeinfo.TypeInfo)

Example 8 with VariableSubstitution

use of org.apache.hadoop.hive.conf.VariableSubstitution in project hive by apache.

the class LlapClusterResourceProcessor 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 Cluster Processor Helper Failed: Command arguments are empty.");
    }
    String[] params = Arrays.copyOfRange(tokens, 1, tokens.length);
    try {
        return llapClusterCommandHandler(ss, params);
    } catch (Exception e) {
        throw new CommandProcessorException("LLAP Cluster 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 9 with VariableSubstitution

use of org.apache.hadoop.hive.conf.VariableSubstitution 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?
        throw new CommandProcessorException(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 new CommandProcessorResponse(null, 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 10 with VariableSubstitution

use of org.apache.hadoop.hive.conf.VariableSubstitution in project hive by apache.

the class ColumnStatsSemanticAnalyzer method genRewrittenQuery.

private String genRewrittenQuery(List<String> colNames, int numBitVectors, Map<String, String> partSpec, boolean isPartitionStats) throws SemanticException {
    StringBuilder rewrittenQueryBuilder = new StringBuilder("select ");
    String rewrittenQuery;
    for (int i = 0; i < colNames.size(); i++) {
        if (i > 0) {
            rewrittenQueryBuilder.append(" , ");
        }
        rewrittenQueryBuilder.append("compute_stats(`");
        rewrittenQueryBuilder.append(colNames.get(i));
        rewrittenQueryBuilder.append("` , ");
        rewrittenQueryBuilder.append(numBitVectors);
        rewrittenQueryBuilder.append(" )");
    }
    if (isPartitionStats) {
        for (FieldSchema fs : tbl.getPartCols()) {
            rewrittenQueryBuilder.append(" , `" + fs.getName() + "`");
        }
    }
    rewrittenQueryBuilder.append(" from `");
    rewrittenQueryBuilder.append(tbl.getDbName());
    rewrittenQueryBuilder.append("`.");
    rewrittenQueryBuilder.append("`" + tbl.getTableName() + "`");
    isRewritten = true;
    // query
    if (isPartitionStats) {
        rewrittenQueryBuilder.append(genPartitionClause(partSpec));
    }
    rewrittenQuery = rewrittenQueryBuilder.toString();
    rewrittenQuery = new VariableSubstitution(new HiveVariableSource() {

        @Override
        public Map<String, String> getHiveVariable() {
            return SessionState.get().getHiveVariables();
        }
    }).substitute(conf, rewrittenQuery);
    return rewrittenQuery;
}
Also used : VariableSubstitution(org.apache.hadoop.hive.conf.VariableSubstitution) FieldSchema(org.apache.hadoop.hive.metastore.api.FieldSchema) HiveVariableSource(org.apache.hadoop.hive.conf.HiveVariableSource) 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