Cassandra 大于 '>' 问题

You*_*hky 1 cassandra nosql

在 Cassandra 中,我试图使用>= 操作从表中检索文本数据,但是,尽管尝试使用=它返回成功,但未检索到任何内容

这是查询示例

select * from s.vechile_information  where datetimelong >= '1493215758000' and vechile_customerid = '123' and vechileId = '32' allow filetring;  
Run Code Online (Sandbox Code Playgroud)

但是当删除>它工作正常

   select * from s.vechile_information  where datetimelong = '1493215758000' and vechile_customerid = '123' and vechileId = '32' allow filetring;
Run Code Online (Sandbox Code Playgroud)

这是表结构

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'};
Run Code Online (Sandbox Code Playgroud)

在跟踪另一种情况后,问题仍然存在,我想知道为什么会出现这种行为。

这是新的表结构

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'};
Run Code Online (Sandbox Code Playgroud)

select语句如下。

select * from fcs.devicetracking_log where customerId='179_gov'    and regionid='0000015b648d225c-0242ac11000e0001' and dateTime>='1493208398000' allow filtering; 
Run Code Online (Sandbox Code Playgroud)

但在使用=它的情况下

并且当添加更多条件或删除 regionid 时它会正常工作

and vehiclesystemid='0000015b64937c79-0242ac1100090001' 
Run Code Online (Sandbox Code Playgroud)

谁能帮我 ?这是生产问题

que*_*ire 5

一般来说,你不应该ALLOW FILTERING在生产中使用。见解释

为了能够对其进行范围查询,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)
) ;
Run Code Online (Sandbox Code Playgroud)

请记住,如果您希望能够进行范围查询,则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 引入了可能适合您的用例的物化视图。这样你就可以避免多次插入。