【问题标题】:Running PIG scripts on Cassandra Table在 Cassandra 表上运行 PIG 脚本
【发布时间】:2013-07-29 13:15:10
【问题描述】:

我正在使用 带有补丁 5234 的 Cassandra-1.2 - Pig 无法访问通过 CQL3 创建的表 Hadoop - 1.1.2 猪 0.11.1

我在 Cassandra 有一张桌子

datatypetest (num int PRIMARY KEY, ascii ascii, blob blob, text text, varnum varint);

而datatypetest中的测试数据是

 num | ascii | blob   | text | varnum
-----+-------+--------+--------+------
  13 |   126 | 0x0003 | John | null

我运行了以下 PIG 脚本

test1 = LOAD 'cassandra://keyspace1/datatypetest' USING CassandraStorage() AS 
(num:int, columns: bag {T: tuple(name, value)});

并且在别名test1中输出如下

(12,{((),),((ascii),125),((blob),��),((text),deepak)})

正如你在输出中看到的,它不是下面的格式

(<row_key>,{(<column_name1>,<value1>),(<column_name2>,<value2>)})

内袋有一个元组,该元组有另一个内部元组,而我认为是键的第一个内部元组是空的。

我不能使用 columns.ascii 或 columns.blob 或 columns.text 来访问如下所示的列元组并获得异常

test2 = FOREACH test1 GENERATE num, columns.text;
2013-07-29 09:11:58,488 [main] ERROR org.apache.pig.tools.grunt.Grunt - 
ERROR 1200: Pig script failed to parse: 
<line 3, column 8> pig script failed to validate:    
org.apache.pig.impl.logicalLayer.FrontendException: ERROR 1128: 
Cannot find field text in name:tuple(),value:bytearray

如何访问列元组。 提前致谢。

【问题讨论】:

    标签: hadoop cassandra apache-pig cassandra-cli


    【解决方案1】:

    在引用使用 CQL3 创建的表时,不应使用 CassandraStorageCassandraStorage 类似于 Thrift API。访问 CQL3 表时,使用CqlStorage

    test1 = LOAD 'cql://keyspace1/datatypetest' USING CqlStorage();
    

    这应该为您提供列及其内容的名称/值元组。响应应如下所示:

    ((name,13),(ascii,126),(blob,"blobvalue"),(text,John))
    

    但是,返回的集合与CqlStorage 生成的架构之间似乎存在不匹配。 (See this question.)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-12-20
      • 1970-01-01
      • 2013-02-02
      • 2015-11-10
      • 1970-01-01
      • 2013-12-26
      • 1970-01-01
      相关资源
      最近更新 更多