PIG:如何删除列名中的“::”

PIG: How to remove '::' in the column name

我有一个像下面这样的猪关系:

最终= {input_md5::type: chararray,input_md5::name: chararray,input_md5::id: long,input_md5::age: chararray,test_1:: type: chararray,test_2::name:chararray}

我正在尝试存储与配置单元 table 相关的所有列 input_md5。 像所有 input_md5::type: chararray,input_md5::name: chararray,input_md5::id: long,input_md5::age: chararray 不参加 test_1:: type: chararray,test_2::name:chararray

pig 中是否有任何命令仅过滤 input_md5 的列。如下所示:

STORE= FOREACH FINAL GENERATE all input_md5::type . 我知道猪有 :

FOREACH FINAL GENERATE all input_md5::type as type 语法,但我有很多列,所以我不能在我的代码中使用 as

因为当我尝试: STORE= FOREACH FINAL GENERATE input_md5::type .. bus_input_md5::name;

Pig 抛出一个错误:

org.apache.hive.hcatalog.common.HCatException : 2007 : Invalid column position in partition schema : Expected column <type> at position 1, found column <input_md5::type>

提前致谢,

已解决此问题,修复方法如下:

创建具有如下过滤条件的关系:

DUMMY_RELATION= FILTER SOURCE_TABLE BY type== '';(我拿了一个名为 type 的列,这可以通过 table 中的任何列进行过滤,重要的是我们需要它的架构)

FINAL_DATASET= UNION DUMMY_RELATION,SCHEMA_1,SCHEMA_2;

(这个新的 DUMMY_RELATIONn 应该放在并集的第一位) 现在你不再有 :: 运算符并且你的列名将匹配配置单元 table 的列名,前提是你的源 table(到 DUMMY_RELATION)和目标 table 具有相同的列顺序。

感谢我自己:)

我就是这样实现Neethu的例子的。可能有错别字,但它展示了如何实现这个想法。

tableA = LOAD 'default.tableA' USING org.apache.hive.hcatalog.pig.HCatLoader();
tableB = LOAD 'default.tableB' USING org.apache.hive.hcatalog.pig.HCatLoader();

--load empty table
finalTable = LOAD 'default.finalTable' USING org.apache.hive.hcatalog.pig.HCatLoader();

--example operations that end up with '::' in column names
g = group tableB by (id);
j = JOIN tableA by id LEFT, g by group;
result = foreach j generate tableA::id, tableA::col2, g::tableB;

--union empty finalTable and result
result2 = union finalTable, result;

--bob's your uncle
STORE result2 INTO 'finalTable' USING org.apache.hive.hcatalog.pig.HCatStorer();

感谢 Neethu!