cassandra where子句作为元组

cqoc49vn  于 2021-06-13  发布在  Cassandra
关注(0)|答案(1)|浏览(307)
Table12
CustomerId   CampaignID
  1              1
  1              2
  2              3
  1              3
  4              2                   
  4              4
  5              5
val CustomerToCampaign = ((1,1),(1,2),(2,3),(1,3),(4,2),(4,4),(5,5))

有没有可能像这样写一个查询

select CustomerId, CampaignID  from Table12 where (CustomerId, CampaignID) in (CustomerToCampaign_1, CustomerToCampaign_2)

???
因此,输入是一个元组,但列不是元组,而是单个列。

kyvafyod

kyvafyod1#

当然,有可能。但只在聚类键上。这意味着我需要使用其他东西作为分区键或“bucket”。对于本例,我将假设营销活动是时间敏感的,通过使用“month”作为bucket(分区),我们将获得良好的分发和方便的查询。

CREATE TABLE stackoverflow.customertocampaign (
    campaign_month int,
    customer_id int,
    campaign_id int,
    customer_name text,
    PRIMARY KEY (campaign_month, customer_id, campaign_id)
);

现在,我可以了 INSERT 你的报告中描述的数据 CustomerToCampaign 变量。然后,这个查询工作:

aploetz@cqlsh:stackoverflow> SELECT campaign_month, customer_id, campaign_id
                             FROM customertocampaign WHERE campaign_month=202004 
                             AND (customer_id,campaign_id) = (1,2);

 campaign_month | customer_id | campaign_id
----------------+-------------+-------------
         202004 |           1 |           2

(1 rows)

相关问题