Pig:Relation 和 Schema 名称混淆
Posted
技术标签:
【中文标题】Pig:Relation 和 Schema 名称混淆【英文标题】:Pig:Relation and Schema name confusion 【发布时间】:2015-01-31 16:15:25 【问题描述】:在 Pig Latin 中;这按预期工作:
filtered = FILTER records BY age > 27;
但这会引发异常(当 >> DUMP 过滤时):
filtered = FILTER records BY records.age > 27;
这是例外:
java.lang.Exception: org.apache.pig.backend.executionengine.ExecException: ERROR 0: Scalar has more than one row in the output. 1st : (John,Wilk,27,M), 2nd :(Tri,Tim,27,F)
at org.apache.hadoop.mapred.LocalJobRunner$Job.run(LocalJobRunner.java:403)
Caused by: org.apache.pig.backend.executionengine.ExecException: ERROR 0: Scalar has more than one row in the output. 1st : (John,Wilk,27,M), 2nd :(Tri,Tim,27,F)
at org.apache.pig.impl.builtin.ReadScalars.exec(ReadScalars.java:119)
at org.apache.pig.backend.hadoop.executionengine.physicalLayer.expressionOperators.POUserFunc.getNext(POUserFunc.java:345)
at org.apache.pig.backend.hadoop.executionengine.physicalLayer.expressionOperators.POUserFunc.getNextInteger(POUserFunc.java:394)
at org.apache.pig.backend.hadoop.executionengine.physicalLayer.PhysicalOperator.getNext(PhysicalOperator.java:322)
at org.apache.pig.backend.hadoop.executionengine.physicalLayer.expressionOperators.GreaterThanExpr.getNextBoolean(GreaterThanExpr.java:74)
at org.apache.pig.backend.hadoop.executionengine.physicalLayer.relationalOperators.POFilter.getNextTuple(POFilter.java:144)
at org.apache.pig.backend.hadoop.executionengine.mapReduceLayer.PigGenericMapBase.runPipeline(PigGenericMapBase.java:282)
at org.apache.pig.backend.hadoop.executionengine.mapReduceLayer.PigGenericMapBase.map(PigGenericMapBase.java:277)
at org.apache.pig.backend.hadoop.executionengine.mapReduceLayer.PigGenericMapBase.map(PigGenericMapBase.java:64)
at org.apache.hadoop.mapreduce.Mapper.run(Mapper.java:145)
at org.apache.hadoop.mapred.MapTask.runNewMapper(MapTask.java:763)
at org.apache.hadoop.mapred.MapTask.run(MapTask.java:339)
at org.apache.hadoop.mapred.LocalJobRunner$Job$MapTaskRunnable.run(LocalJobRunner.java:235)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:744)
两者有什么区别?它们不一样吗?
【问题讨论】:
【参考方案1】:不,两个 stmts 是不同的。
第一个 stmt 完全有效,在这种情况下,pig 将遍历每一行并应用过滤器约束(年龄 > 27)。它是使用过滤器 stmts 的标准方式。
在第二种情况下,你使用dereference operator(.)
来访问字段,但是当你使用解引用操作符访问时,解引用操作符主要用于访问复杂数据类型(Tuples、Bags和Maps)的值然后猪的字段将always expect the scalar output
(即过滤条件后只有一个输出)不幸的是你的过滤条件(年龄> 27)返回more than one matching result
,这就是你得到“Scalar has more than one row in the output
”的原因
如果您的过滤条件(年龄>27)只返回一个输出,那么您的 stmt 是完全有效的。
【讨论】:
感谢您的解释。以上是关于Pig:Relation 和 Schema 名称混淆的主要内容,如果未能解决你的问题,请参考以下文章