2013-09-01 21 views
0

我有一個這樣的數據庫:卡桑德拉遷移(用於排序的查詢設計模式)

  • 圖像0​​
    • ID(INT)
    • 名(文本)
    • 圖像(BLOB )
    • create_date(datetime)
    • comment(text)
    • 大小(INT)
    • 視圖(INT)

表圖像包含具有元信息JPG。 我有能力在MySQL排序(按視圖,大小和create_date)

如何做到與Cassandra相同?


我嘗試一些設計,如: - 圖像 - ID(文本) - 名稱(文本) - 圖像(BLOB)

  • image_by_size

    • id_image (文字)
    • 尺寸(int)
  • image_by_view

    • id_image(文本)
    • 視圖(INT)
  • image_by_create

    • id_image(文本)
    • CREATE_DATE(時間戳)

但是當我不知道如何在不知道命令「ID」前...

我讀Select 2000 most recent log entries in cassandra table using CQL (Latest version),但我不知道如何端口這對我使用.. 。

回答

0

一種解決方案:

  • image_by_size

CREATE TABLE image_by_size 
(
    rowkey text, // arbitrary text, it can be 'IMAGE_BY_SIZE' for example 
    size int, 
    id_image text, 
    PRIMARY KEY (rowkey,size,id_image) 
); 

爲了通過大小列表圖像:

SELECT id_image FROM image_by_size WHERE rowkey='IMAGE_BY_SIZE' ORDER BY size DESC; 
  • 圖像由視圖

CREATE TABLE image_by_view 
    (
     rowkey text, // arbitrary text, it can be 'IMAGE_BY_VIEW' for example 
     view int, 
     id_image text, 
     PRIMARY KEY (rowkey,view,id_image) 
    ); 

爲了通過查看列表圖像:

SELECT id_image FROM image_by_view WHERE rowkey='IMAGE_BY_VIEW' ORDER BY size DESC; 
  • 圖像通過創建

CREATE TABLE image_by_create 
    (
     rowkey text, // arbitrary text, it can be 'IMAGE_BY_CREATE_DATE' for example 
     create_date timestamp, 
     id_image text, 
     PRIMARY KEY (rowkey,create_date,id_image) 
    ); 

爲了通過創建日期列表圖像:

SELECT id_image FROM image_by_create WHERE rowkey='IMAGE_BY_CREATE_DATE' ORDER BY create_date DESC; 

一個表溶液

由於尺寸,視圖和時間戳是數字,有可能只使用一個表,以索引全部

CREATE TABLE image_index 
(
    index_type text, // 'IMAGE_BY_SIZE', 'IMAGE_BY_VIEW' or 'IMAGE_BY_CREATE_DATE' 
    value bigint, 
    id_image text, 
    PRIMARY KEY (index_type,value,id_image) 
); 

索引圖像由大小

INSERT INTO image_index(index_type,value,id_image) VALUES('IMAGE_BY_SIZE',size_as_long,id_image); 

索引圖像通過視圖

INSERT INTO image_index(index_type,value,id_image) VALUES('IMAGE_BY_VIEW',view_as_long,id_image); 

索引圖像的創建日期

INSERT INTO image_index(index_type,value,id_image) VALUES('IMAGE_BY_CREATE_DATE',create_timestamp_as_long,id_image); 
+0

你救我的一天。 –

+0

Stackoverflow旨在保存我們的日子:D。它也多次拯救了我的一天 – doanduyhai