【问题标题】:How to include SQL select statement in dsbulk unload command如何在 dsbulk 卸载命令中包含 SQL 选择语句
【发布时间】:2022-06-21 17:54:24
【问题描述】:

我在 cassandra 中有一个巨大的 orderhistory 表,其中包含 2013 年的数据,但我只想卸载最后 12 个月的 orderhistory 数据,我使用下面的命令来卸载从 2013 年开始的所有数据并存储在路径 @987654321 @。如何修改以下语句,以便每次运行时它应该只选择最近 12 个月的数据?

dsbulk unload -k customer_data -t crawlsiteidentifiedpages -h '172.xx.xx.xxx' \
  -c json -url data/json/customer_data/orderhistory/data

【问题讨论】:

    标签: cassandra datastax dsbulk


    【解决方案1】:

    您需要删除选项-k-t,而是使用documentation 中所述的-query 选项,例如:

    dsbulk unload -query 'select * from ks.table where <your condition>'
    

    要确保卸载是并行化的,请确保您的条件包含类似and token(pkcol) &gt; :start and token(pkcol) &lt;= :end 的部分,其中pkcol 是分区列的名称(如果您有多个分区列,请以逗号分隔指定它们)。

    【讨论】:

    • 你好@Alex,我试过但没有工作: dsbulk unload -query "select * from ks.table where token(url) > :start and token(url) <= :end and lastupdatetime >= toTimestamp('2021-06-01 08:21:55.717') 允许过滤" -h '172.xx.xx.xxx, 172.xx.xx.xxx' -c json -url data/json/ks/table/data
    • 什么不起作用?请用错误更新您的帖子
    • 我收到此错误:失败:调用了未知的 CQL3 函数 toTimestamp。我无法弄清楚获取过去 12 个月的确切语法,我们将不胜感激
    【解决方案2】:

    您应该使用 -query 而不是 -t crawlsiteidentifiedpages 并提供 SELECT 查询,例如:

    -query "SELECT * FROM crawlsiteidentifiedpages WHERE token(pk) > :start and token(pk) <= :end and date > maxTimeuuid('2021-06-21+0000') ALLOW FILTERING"
    

    几点说明:

    1. 我假设您的表有一个分区键列pk 和一个date 类型timeuuid 的集群列——请相应地调整实际查询。
    2. WHERE 限制token(pk) &gt; :start and token(pk) &lt;= :end 允许 DSBulk 并行化操作并提高性能。
    3. WHERE 限制date &gt; maxTimeuuid('2021-06-21+0000') 是魔法发生的地方,它允许您仅选择最近 12 个月的数据。
    4. 很遗憾,您还需要在此类查询中添加ALLOW FILTERING,否则Cassandra 将拒绝该查询。

    【讨论】:

    • 非常感谢您,我需要其他帮助,每次运行此命令时,它都会创建 2 个 json 文件,无论数据大小。我的问题是,我如何控制文件的数量?假设我想要 5 个文件而不是 2 个?
    • 您需要添加 -maxConcurrentFiles 1
    猜你喜欢
    • 2020-07-28
    • 1970-01-01
    • 2017-08-22
    • 2021-02-09
    • 2022-11-29
    • 1970-01-01
    • 1970-01-01
    • 2020-10-24
    • 2016-07-07
    相关资源
    最近更新 更多