首页 > 解决方案 > 通过 cassandra 在 Zeppelin 中读取数据

问题描述

我在 Cassandra 的一张桌子上有问题。

CREATE TABLE tfm.foehis (hooe text, hodtac int, hohrac int, hoclic text,    hocdan text, hocdrs text, hocdsl text, hocol text, hocpny text, hodesf text, hodtcl int, hodtcm int, hodtea int, hodtra int, hodtrc int, hodtto date, hodtua int, hohrcl int, hohrcm int, hohrea int, hohrra int, hohrrc int, hohrua int, holinh text, holinr int, honrac int, honumr int, hoobs text, hotdsc int, hotour text, hotpac text, housca text, houscl text, huscm text, housea text, houser text, housra text, housrc text,PRIMARY KEY ((hooe, hodtac, hohrac), hoclic)) WITH CLUSTERING ORDER BY (hoclic ASC)
AND bloom_filter_fp_chance = 0.01
AND caching = {'keys': 'ALL', 'rows_per_partition': 'NONE'}
AND comment = ''
AND compaction = {'class': 'org.apache.cassandra.db.compaction.SizeTieredCompactionStrategy', 'max_threshold': '32', 'min_threshold': '4'}
AND compression = {'chunk_length_in_kb': '64', 'class': 'org.apache.cassandra.io.compress.LZ4Compressor'}
AND crc_check_chance = 1.0
AND dclocal_read_repair_chance = 0.1
AND default_time_to_live = 0
AND gc_grace_seconds = 864000
AND max_index_interval = 2048
AND memtable_flush_period_in_ms = 0
AND min_index_interval = 128
AND read_repair_chance = 0.0
AND speculative_retry = '99PERCENTILE';

当我尝试进行查询时出现一些错误。

cqlsh> select housca from tfm.foehis where hoclic=1101;

InvalidRequest: Error from server: code=2200 [Invalid query] message="Invalid INTEGER constant (1101) for "hoclic" of type text"

cqlsh> select housca from tfm.foehis where hoclic=MOBIDI;

SyntaxException: line 1:49 no viable alternative at input ';' (...from tfm.foehis where hoclic=[MOBIDI];)

cqlsh> select * from tfm.foehis where hoclic=MOBIDI;

SyntaxException: line 1:44 no viable alternative at input ';' (...from tfm.foehis where hoclic=[MOBIDI];)

cqlsh> select * from tfm.foehis where hoclic=1101;

InvalidRequest: Error from server: code=2200 [Invalid query] message="Invalid INTEGER constant (1101) for "hoclic" of type text"

甚至 1101 和 MOBIDI 都是hoclic.

在 Zeppelin 中,当我使用select * from tfm.foehis;出现所有数据时,我可以制作我想要的图形,但是当我引入这个新语句时select * from tfm.foehis where hoclic="${CLIENT=1101|MOBIDI}";

出现这个错误。

com.datastax.driver.core.exceptions.SyntaxError: line 1:46 no viable alternative at input ';' (...from tfm.foehis where hoclic=["singl]e";) at com.datastax.driver.core.exceptions.SyntaxError.copy(SyntaxError.java:58) at com.datastax.driver.core.exceptions.SyntaxError.copy(SyntaxError.java:24) ...

我认为问题是表的主键的定义,但我不知道如何解决它

标签: cassandra

解决方案


文本字段必须包含在单引号中,而不是包含在双引号中!并且根本没有使用引号 - 就像你的例子一样......

你的例子应该写成

select housca from tfm.foehis where hoclic='1101';
select housca from tfm.foehis where hoclic='MOBIDI';

请参阅CQL 文字的定义


推荐阅读