hive的变量传递设置
来源:互联网 发布:中国高铁发展知乎 编辑:程序博客网 时间:2024/05/21 15:39
hive的变量传递设置
今天同事在oozie的workflow中执行一个hive查询,但是直接就报异常:Variable substitution depth too large:40,从网上查询可知,可以确认是由于语句中使用了过多的变量导致,在hive以前的版本中,这个限制是写死的40个,查询Hive的最新的原代码,虽然判断的位置的提示信息已经变化,但是原理一样:
### org.apache.hadoop.hive.ql.parse.VariableSubstitution:
public String substitute(HiveConf conf, String expr) { if (expr == null) { return expr; } if (HiveConf.getBoolVar(conf, ConfVars.HIVEVARIABLESUBSTITUTE)) { l4j.debug("Substitution is on: " + expr); } else { return expr; } int depth = HiveConf.getIntVar(conf, ConfVars.HIVEVARIABLESUBSTITUTEDEPTH); return substitute(conf, expr, depth); }
如果开启hive.variable.substitute(默认开启),则使用SystemVariables的substitute方法和hive.variable.substitute.depth(默认为40)进行进一步的判断:
protected final String substitute(Configuration conf, String expr, int depth) { Matcher match = varPat.matcher(""); String eval = expr; StringBuilder builder = new StringBuilder(); int s = 0; for (; s <= depth; s++) { match.reset(eval); builder.setLength(0); int prev = 0; boolean found = false; while (match.find(prev)) { String group = match.group(); String var = group.substring(2, group.length() - 1); // remove ${ .. } String substitute = getSubstitute(conf, var); if (substitute == null) { substitute = group; // append as-is } else { found = true; } builder.append(eval.substring(prev, match.start())).append(substitute); prev = match.end(); } if (!found) { return eval; } builder.append(eval.substring(prev)); eval = builder.toString(); } if (s > depth) { throw new IllegalStateException( "Variable substitution depth is deeper than " + depth + " for expression " + expr); } return eval; }
如果使用的${}参数超过hive.variable.substitute.depth的数量,则直接抛出异常,所以我们在语句的前面直接加上set hive.variable.substitute.depth=100; 问题解决!
set命令的执行是在CommandProcessor实现类SetProcessor里具体执行,但是substitute语句同时也会在CompileProcessor中调用,也就是在hive语句编译时就调用了,所以oozie在使用时调用beeline执行语句时,compile阶段就报出异常。
但是为什么Hue直接执行这个语句时没有问题? 因为hue在执行hive时使用的是python开发的beeswax,而beeswax是自己直接处理了这些变量,使用变量实际的值替换变量后再提交给hive执行:
def substitute_variables(input_data, substitutions): """ Replaces variables with values from substitutions. """ def f(value): if not isinstance(value, basestring): return value new_value = Template(value).safe_substitute(substitutions) if new_value != value: LOG.debug("Substituted %s -> %s" % (repr(value), repr(new_value))) return new_value return recursive_walk(f, input_data)
- hive的变量传递设置
- hive变量传递的源码实现
- hive 传递外部变量的方式
- Hive程序传递变量
- hive变量传递
- 向Hive程序传递变量的三种方法
- php-变量的传递
- 传递变量的地址
- 函数变量的传递
- 设置hive的环境变量
- hive 设置的坑
- hive的压缩设置
- Hive下的变量使用
- Hive下的变量使用
- Hive下变量的使用
- hive下变量的使用
- perl 子程序传递参数不同类型变量 设置
- hive 变量
- ecshop常见错误的处理方法
- 翼支付门户CAS单点登录相关介绍
- 算法:动态规划
- WifiP2pSettings工作流程
- CheckBox和RadioButton
- hive的变量传递设置
- log4j WARN No appenders could be found for logger
- 传说中的比较高级一点的UI(201547)
- 多企业培训活动的签到法宝——神奇的二维码
- Cocos2d-JS自定义粒子系统
- 什么使我成为网商“战役”的常胜将军?
- 做一个略调皮的个人博客--菜单篇
- 项目运行过程中修改.properties文件问题
- CNN神经网络层次分析