卡桑德拉大于'>'问题

时间:2017-04-26 14:57:15

标签: cassandra nosql

在Cassandra我试图使用>=操作从表中检索文本数据但是,虽然尝试使用=但它没有检索到它成功返回

这是查询样本

select * from s.vechile_information  where datetimelong >= '1493215758000' and vechile_customerid = '123' and vechileId = '32' allow filetring;  

但删除>时效果很好

   select * from s.vechile_information  where datetimelong = '1493215758000' and vechile_customerid = '123' and vechileId = '32' allow filetring;

这是表结构

CREATE TABLE fcs.vehicle_information (
    vehicle_customerId text,
    vehicleid text,
    cityid text,
    cityname text,
    citynamear text,
    createdby text,
    dateTimeLong text,
    description text,
    driverid text,
    drivername text,
    drivernamear text,
    groupofvehicles text,
    groupofvehiclesystemid text,
    insexpirygregoriandate bigint,
    name text,
    namear text,
    platenumber text,

   vehiclestatus text,
    PRIMARY KEY (vehicle_customerId, vehicleid)
) ;
CREATE CUSTOM INDEX dateTimeLongvehicle_information ON fcs.vehicle_information (dateTimeLong) USING 'org.apache.cassandra.index.sasi.SASIIndex' WITH OPTIONS = {'analyzer_class' : 'org.apache.cassandra.index.sasi.analyzer.NonTokenizingAnalyzer', 'case_sensitive' : 'false'};
经过追踪的另一个场景问题仍然存在,我想知道为什么会出现这种情况。

这是新表结构

CREATE TABLE fcs.devicetracking_log (
    customerid text,
    vehiclesystemid text,
    datetime text,
    uniqueid text,
    logaction int,
    logid uuid,
    cid int,
    altitude double,
    angle double,
    assignmentname text,
    assignmentsystemid text,
    cityid text,
    cityname text,
    citynamear text,
    coloronmap text,
    departmentid text,
    departmentname text,
    departmentnamear text,
    departmentsystemid text,
    device text,
    direction double,
    drivername text,
    drivernamear text,
    driversystemid text,
    groupofvehicles text,
    groupofvehiclesystemid text,
    gsm_signal bigint,
    id text,
    lastcid int,
    lastidledate bigint,
    lastoverspeednotificationtime bigint,
    laststoppeddate bigint,
    latitude double,
    longitude double,
    message_id bigint,
    mileage double,
    overspeedallowedperiod int,
    overspeedmaximumspeed int,
    receivingdate bigint,
    regionid text,
    regionname text,
    regionnamear text,
    report text,
    rtc_datetime bigint,
    rtctime bigint,
    satellites int,
    speed double,
    uid text,
    valid text,
    vehiclename text,
    vehiclenamear text,
    vehicleplatenumber text,
    PRIMARY KEY (customerid, vehiclesystemid, datetime, uniqueid, logaction, logid, cid)
) ;
CREATE CUSTOM INDEX ciddevicetrackinglog ON fcs.devicetracking_log (cid) USING 'org.apache.cassandra.index.sasi.SASIIndex' WITH OPTIONS = {'analyzer_class' : 'org.apache.cassandra.index.sasi.analyzer.NonTokenizingAnalyzer', 'case_sensitive' : 'false'};
CREATE CUSTOM INDEX citydevicetracking_log ON fcs.devicetracking_log (cityid) USING 'org.apache.cassandra.index.sasi.SASIIndex' WITH OPTIONS = {'analyzer_class' : 'org.apache.cassandra.index.sasi.analyzer.NonTokenizingAnalyzer', 'case_sensitive' : 'false'};
CREATE CUSTOM INDEX datetimedevicetrackinglog ON fcs.devicetracking_log (datetime) USING 'org.apache.cassandra.index.sasi.SASIIndex' WITH OPTIONS = {'analyzer_class' : 'org.apache.cassandra.index.sasi.analyzer.NonTokenizingAnalyzer', 'case_sensitive' : 'false'};
CREATE CUSTOM INDEX departmentdevicetracking_log ON fcs.devicetracking_log (departmentid) USING 'org.apache.cassandra.index.sasi.SASIIndex' WITH OPTIONS = {'analyzer_class' : 'org.apache.cassandra.index.sasi.analyzer.NonTokenizingAnalyzer', 'case_sensitive' : 'false'};
CREATE CUSTOM INDEX regiondevicetracking_log ON fcs.devicetracking_log (regionid) USING 'org.apache.cassandra.index.sasi.SASIIndex' WITH OPTIONS = {'analyzer_class' : 'org.apache.cassandra.index.sasi.analyzer.NonTokenizingAnalyzer', 'case_sensitive' : 'false'};
CREATE CUSTOM INDEX speeddevicetracking_log ON fcs.devicetracking_log (speed) USING 'org.apache.cassandra.index.sasi.SASIIndex' WITH OPTIONS = {'analyzer_class' : 'org.apache.cassandra.index.sasi.analyzer.NonTokenizingAnalyzer', 'case_sensitive' : 'false'};
CREATE CUSTOM INDEX vehiclenameardevicetracking_log ON fcs.devicetracking_log (vehiclenamear) USING 'org.apache.cassandra.index.sasi.SASIIndex' WITH OPTIONS = {'analyzer_class' : 'org.apache.cassandra.index.sasi.analyzer.NonTokenizingAnalyzer', 'case_sensitive' : 'false'};
CREATE CUSTOM INDEX vehiclenamedevicetrackinglog ON fcs.devicetracking_log (vehiclename) USING 'org.apache.cassandra.index.sasi.SASIIndex' WITH OPTIONS = {'analyzer_class' : 'org.apache.cassandra.index.sasi.analyzer.NonTokenizingAnalyzer', 'case_sensitive' : 'false'};
CREATE CUSTOM INDEX vehiclesystemiddevicetrackinglog ON fcs.devicetracking_log (vehiclesystemid) USING 'org.apache.cassandra.index.sasi.SASIIndex' WITH OPTIONS = {'analyzer_class' : 'org.apache.cassandra.index.sasi.analyzer.NonTokenizingAnalyzer', 'case_sensitive' : 'false'};

select语句如下。

select * from fcs.devicetracking_log where customerId='179_gov'    and regionid='0000015b648d225c-0242ac11000e0001' and dateTime>='1493208398000' allow filtering; 

但如果使用=,则可以使用

并且在添加一个条件或删除regionid时也可以正常工作

and vehiclesystemid='0000015b64937c79-0242ac1100090001' 

任何人都可以帮助我吗? 这是一个生产问题

1 个答案:

答案 0 :(得分:3)

通常,您不应在生产中使用ALLOW FILTERINGSee as explanation

为了能够在dateTimeLong上进行范围查询,它需要成为您密钥的一部分。在cassandra中,您通常会尝试通过查询创建表。这意味着在您的方案中,您可以创建另一个表,其中dateTimeLong将成为您的密钥的一部分。

CREATE TABLE fcs.vehicle_information_byDateTime (
    vehicle_customerId text,
    vehicleid text,
    cityid text,
    cityname text,
    citynamear text,
    createdby text,
    dateTimeLong text,
    description text,
    driverid text,
    drivername text,
    drivernamear text,
    groupofvehicles text,
    groupofvehiclesystemid text,
    insexpirygregoriandate bigint,
    name text,
    namear text,
    platenumber text,

   vehiclestatus text,
    PRIMARY KEY (vehicle_customerId, vehicleid, dateTime)
) ;

请注意,如果您希望能够在dateTime上进行范围查询,则需要指定vehicleid

我们假设(customerid,(vehiclesystemid,datetime))是你的复合键。 customerid是您必须指定的主键。

如果你知道的话:

select * from s.vechile_information where vechile_customerid = '123' AND vehiclesystemid >= '32';

这将完美无缺。这是由cassandra如何在磁盘上存储数据的性质引入的。主键指定群集中数据的位置。群集列vehiclesystemid, datetime指定 数据存储在磁盘上。

如果您现在想要对datetime进行范围查询,可以先指定vehiclesystemid来执行此操作:

select * from s.vechile_information where vechile_customerid = '123' AND vehiclesystemid = '32' AND datetime >= '1493215758000';

插入新数据时,您必须将其插入两个表中。

使用Cassandra 3时,已经引入了materialized views,这可能适合您的用例。这样你就可以避免多次插入。