【问题标题】:can we use more than one cassandra CQL collections ( set,list,map )in a single query?我们可以在单个查询中使用多个 cassandra CQL 集合(set、list、map)吗?
【发布时间】:2020-03-03 11:51:06
【问题描述】:
create table seller(
    seller_id int primary key,
    seller_name text,
    seller_email set<text>, 
    seller_address map<text>, 
    seller_phone list<text>,
    product_id int,
    product_title_text,
    product_description text,
    product_trackno int,
    product_bidoption text,
    bid_startdate date,
    bid_closedate date,
    bid_startprice int,
    bid_withdrawdate date);

    SyntaxException: line 1:110 mismatched input '>' expecting ',' (...<text>,
        seller_address map<text[>],...)

为了执行应该进行哪些更改?

【问题讨论】:

    标签: cassandra cql cqlsh


    【解决方案1】:

    当然可以,但需要进行一些调整:

    1) 如果列的类型没有通过下划线链接到列名,这会有所帮助。而不是:

    product_title_text,
    

    这将起作用:

    product_title text,
    

    2) 您还需要为地图集合提供这两种类型。而不是:

    seller_address map<TEXT>,
    

    这将起作用:

    seller_address map<TEXT,TEXT>, 
    

    完整的 CQL:

    create table seller(
      seller_id int primary key,
      seller_name text,
      seller_email set<TEXT>,
      seller_address map<TEXT,TEXT>, 
      seller_phone list<TEXT>, 
      product_id int,
      product_title text,
      product_description text,
      product_trackno int,
      product_bidoption text,
      bid_startdate date,
      bid_closedate date,
      bid_startprice int,
      bid_withdrawdate date);
    

    另外,您真的只打算通过seller_id 查询此表吗?如果没有,您可能需要重新考虑主键定义。

    【讨论】: