2017-04-26 329 views
0

我試圖用>=操作檢索表中的文本數據,但是,沒有檢索雖然試圖用=它成功返回卡桑德拉大於「>」問題卡桑德拉

這是查詢的樣本

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' 

任何一個能幫助我嗎? 這是一個生產問題

+0

你的表格結構是什麼? –

+0

@AshrafulIslam我用表結構編輯了這個問題,因爲它太長而不能寫在評論上了。 –

+0

你正在使用哪個cassandra版本? 我已經插入了這個數據INSERT INTO vehicle_information(vehicle_customerid,vehicleid,datetimelong)VALUES('123','32','1493215758000');'並用'select * from vehicle_information查詢where'datetimelong> ='1493215758000'和vehicle_customerid ='123'和vehicleid ='32'ALLOW FILTERING;'返回結果 –

回答

2

一般來說,你不應該在生產中使用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這可能適合您的使用情況。通過這個你可以避免多次插入。

+0

你能看到我最後編輯和最後一個表格結構並回答我嗎?我試圖讓設計可以運行這個查詢。 –

+0

爲什麼你再次創建二級索引?您還應該避免在生產中使用二級索引....查詢的結果是什麼? – questionare

+0

它工作時,我從主鍵中刪除vehiclesystemid,我刪除了二級索引,謝謝 –