無法透過 Hive 映射到 Cassandra 查看數據

無法透過 Hive 映射到 Cassandra 查看數據

透過 Sqoop 將資料從 Oracle DB 載入到 Cassandra 後,我可以透過 Cassandra 和 Hive 查看資料。有人告訴我,這樣做時,每個文件都會產生 2 個文件,從而產生空間問題。為了解決這個問題,我將該表刪除到 Hive 中並建立了一個外部表,並將其對應到 Cassandra 中的列族。但我無法查看 Hive 表中的任何資料。我正在使用 Datastax Enterprise 3.0.1。使用 Sqoop,我將表「test」從 Oracle DB 遷移到鍵空間「test_keyspace」中同名的 Cassandra 列族。我可以使用以下命令透過 cassandra-cli 查看資料:list test;

在 cqlsh 中描述列族給出了以下結果:

CREATE TABLE test (
rowkey text PRIMARY KEY,
bar text,
gump bigint,
home text,
note text,
pay text
) WITH
comment='' AND
comparator=text AND
read_repair_chance=0.100000 AND
gc_grace_seconds=864000 AND
default_validation=text AND
min_compaction_threshold=4 AND
max_compaction_threshold=32 AND
replication_on_write='true' AND
compaction_strategy_class='SizeTieredCompactionStrategy' AND compression_parameters:stable_compression='SnappyCompressor';

我用來建立 Hive 表的命令是:

CREATE external TABLE test (
rowkey string,
bar string,
gump string,
home string,
note string,
pay string
)
STORED BY 'org.apache.hadoop.hive.cassandra.CassandraStorageHandler'
TBLPROPERTIES ( "cassandra.ks.name" = "test_keyspace" );

當我在 Hive 中鍵入「顯示表」時,會列出該表。但是「select * from test」將表中的所有值顯示為 NULL,除了行鍵。

有人知道解決辦法嗎?

答案1

嘗試像這樣建立表:

CREATE external TABLE test (
    rowkey string,
    bar string,
    gump string,
    home string,
    note string,
    pay string
)
STORED BY 'org.apache.hadoop.hive.cassandra.CassandraStorageHandler'
WITH SERDEPROPERTIES("cql.primarykey"="rowkey"
TBLPROPERTIES ( "cassandra.ks.name" = "test_keyspace", "cassandra.cql.type"="text, text, text, text, text, text" );

相關內容