【问题标题】:cassandra migration from mysql (design schema for sortable query)从 mysql 迁移 cassandra(可排序查询的设计模式)
【发布时间】:2013-09-04 19:36:42
【问题描述】:

我有一个这样的数据库:

  • 图片
    • id (int)
    • 姓名(文字)
    • 图像(斑点)
    • create_date(日期时间)
    • 评论(文字)
    • 大小(整数)
    • 视图(整数)

表格图像包含带有元信息的jpg。 我可以在 MySQL 中进行排序(按视图、大小和创建日期)

如何对 Cassandra 做同样的事情?


我尝试了一些设计,例如: - 图片 - 标识(文本) - 名称(文字) - 图像(斑点)

  • image_by_size

    • id_image(文本)
    • 大小(整数)
  • image_by_view

    • id_image(文本)
    • 视图(整数)
  • image_by_create

    • id_image(文本)
    • create_date(时间戳)

但是当我不知道如何订购之前不知道“id”时......

我阅读了Select 2000 most recent log entries in cassandra table using CQL (Latest version),但我不知道如何将其移植到我的使用中...

【问题讨论】:

    标签: mysql cassandra database-schema cql


    【解决方案1】:

    一种解决方案:

    • 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);
    

    【讨论】:

    • Stackoverflow 旨在节省我们的时间:D。它也多次拯救了我的一天
    猜你喜欢
    • 1970-01-01
    • 2015-01-29
    • 2017-08-19
    • 2020-11-18
    • 2017-01-07
    • 2012-05-08
    • 2010-09-30
    • 2016-12-21
    • 1970-01-01
    相关资源
    最近更新 更多