我一再听说二级索引(在cassandra中)只是为了方便而不是为了获得更好的性能.建议在基数较低时使用二级索引的唯一情况(例如性别column为男性或女性的两个值)
考虑这个例子:
CREATE TABLE users (
userID uuid,
firstname text,
lastname text,
state text,
zip int,
PRIMARY KEY (userID)
);
Run Code Online (Sandbox Code Playgroud)
现在,除非我在users on上创建二级索引,否则我无法执行此查询firstname index
select * from users where firstname='john'
Run Code Online (Sandbox Code Playgroud)
如何对此表进行非规范化,以便我可以使用此查询:这是使用复合键的唯一有效方法吗?还有其他选择或建议吗?
CREATE TABLE users (
userID uuid,
firstname text,
lastname text,
state text,
zip int,
PRIMARY KEY (firstname,userID)
);
Run Code Online (Sandbox Code Playgroud) 我们使用Cassandra作为我们车队管理解决方案的数据历史记录.我们在卡桑德拉(Cassandra)有一张桌子,用于存储车辆行驶的详细信息.表结构如下
CREATE TABLE journeydetails(
bucketid text,
vehicleid text,
starttime timestamp,
stoptime timestamp,
travelduration bigint,
PRIMARY KEY (bucketid,vehicleid,starttime,travelduration)
);
Run Code Online (Sandbox Code Playgroud)
哪里:
我们想运行以下查询 - 获取车辆的所有行程 - 2015-12-1和2015-12-3之间的1234567,其行程持续时间大于30分钟
当我运行此查询时:
select * from journeydetails where bucketid in('2015-12') and vehicleid in('1234567')
and starttime > '2015-12-1 00:00:00' and starttime < '2015-12-3 23:59:59'
and travelduration > 1800000;
Run Code Online (Sandbox Code Playgroud)
我得到这个结果:
InvalidRequest: code=2200 [Invalid query] message="Clustering column "travelduration"
cannot be restricted (preceding column "starttime" is restricted by a …Run Code Online (Sandbox Code Playgroud) 由于有两种方法可以支持CQL3中的宽行.一种方法是使用复合键,另一种方法是使用Map,List和Set等集合.复合键方法可以有数百万列(转换为行).这解决了我们的一些用例.
但是,如果我们使用集合,我想知道集合是否存在限制,可以存储一定数量/数量的数据(就像之前的Thrift C*一样,支持最多20亿列)
向所有Cassandra专家提问.
我有一个有大约一百万条记录的列族.
我想以这样的方式查询这些记录,以便我能够执行Not-Equal-To某种操作.
我用Google搜索,似乎我必须使用某种方式Map-Reduce.
有人可以告诉我这方面有哪些选择.
在SQL中,我能够做到:
select getdate(), getdate() - 7
Run Code Online (Sandbox Code Playgroud)
返回当前日期以及当前日期 - 7天.我想在Cassandra CQL中实现相同的目标.我试过了:
select dateof(now())
Run Code Online (Sandbox Code Playgroud)
但这不起作用.它仅适用于插入而不适用于选择.我怎么能得到相同的?任何帮助,将不胜感激.
我正在使用Cassandra 1.2.5.在使用cassandra-cli在Cassandra中创建列族之后,是否可以使用cassandra-cli或CQL修改列族的主键?
具体来说,我目前有下表(来自CQL):
CREATE TABLE "table1" (
key blob,
column1 blob,
value blob,
PRIMARY KEY (key, column1)
);
Run Code Online (Sandbox Code Playgroud)
我希望该表如下,而不必删除并重新创建表:
CREATE TABLE "table1" (
key blob,
column1 blob,
value blob,
PRIMARY KEY (key)
);
Run Code Online (Sandbox Code Playgroud)
这可能通过cassandra-cli或CQL实现吗?
我想将列家族中的选定行复制到.csv文件中.copy命令可用于将列或整个表转储到没有where子句的文件.有没有办法在copy命令中使用where子句?
我想到的另一种方式是,
"插入table2()值(select * from table1 where <where_clause>);" 然后将table2转储到.csv,这也是不可能的.
任何帮助将非常感激.
我想验证行是否已添加到表中.什么cql语句会显示下表中的最后 n行?
表格说明如下:
cqlsh:timeseries> describe table option_data;
CREATE TABLE option_data (
ts bigint,
id text,
strike decimal,
callask decimal,
callbid decimal,
maturity timestamp,
putask decimal,
putbid decimal,
PRIMARY KEY ((ts), id, strike)
) WITH
bloom_filter_fp_chance=0.010000 AND
caching='KEYS_ONLY' AND
comment='' AND
dclocal_read_repair_chance=0.100000 AND
gc_grace_seconds=864000 AND
index_interval=128 AND
read_repair_chance=0.000000 AND
replicate_on_write='true' AND
populate_io_cache_on_flush='false' AND
default_time_to_live=0 AND
speculative_retry='99.0PERCENTILE' AND
memtable_flush_period_in_ms=0 AND
compaction={'class': 'SizeTieredCompactionStrategy'} AND
compression={'sstable_compression': 'LZ4Compressor'};
cqlsh:timeseries>
Run Code Online (Sandbox Code Playgroud) 在使用cqlsh实用程序(Mongo .pretty()的cql版本)时,有没有办法在Linux终端中对cql命令的结果进行美化?当输出正常显示时,读取结果变得非常困难,尤其是当存在嵌套文档和数组时