通过cassandra在Zeppelin中读取数据

时间:2018-07-29 22:46:56

标签: cassandra

我在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) ...

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

1 个答案:

答案 0 :(得分:0)

文本字段必须包含在单引号中,而不包含在双引号中!而且根本没有使用引号-如您的示例...

您的示例应写为

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

请参见definition of CQL literals