You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Azure Data Factory数据流中Cosmos DB日期比较参数失效问题

ADF数据流LastRunTimestamp参数不生效的解决办法

问题核心:你在source的query里把$LastRunTimestamp放在单引号里,ADF会把它当成普通字符串,不会替换成实际传入的参数值,导致查询条件等于没起作用。

解决步骤:

  • 用concat函数拼接查询语句,把参数值正确嵌入SQL中,同时给时间戳加上单引号(符合Cosmos DB查询语法要求)。
  • 修改数据流脚本里的query行,替换成如下写法:
    query: concat("SELECT c.Id, c.Discriminator, c.PartitionKey, c.InsertDateTime, c.UpdateDateTime FROM c where c.Discriminator = 'D1' AND c.InsertDateTime > '", $LastRunTimestamp, "'"),
    
  • 验证参数传递:你已经在derivedColumn1里加了LastTimestamp = $LastRunTimestamp,可以通过数据预览查看这个字段的值,确认参数是否正确传入数据流。

另外,你之前尝试的concat写法存在语法错误——重复写了AND c.InsertDateTime >,且没有给参数包裹单引号,导致生成的SQL要么语法错误,要么参数没被正确解析。

修改后的完整source部分脚本示例:

source(output(
          Id as integer,
          UpdateDateTime as string,
          PartitionKey as integer,
          Discriminator as string,
          InsertDateTime as string
     ),
     allowSchemaDrift: true,
     validateSchema: false,
     limit: 100,
     query: concat("SELECT c.Id, c.Discriminator, c.PartitionKey, c.InsertDateTime, c.UpdateDateTime FROM c where c.Discriminator = 'D1' AND c.InsertDateTime > '", $LastRunTimestamp, "'"),
     format: 'documentQuery',
     systemColumns: false) ~> source1

这样修改后,ADF会正确解析$LastRunTimestamp参数,将实际传入的时间戳值替换到查询语句中,生成符合要求的Cosmos DB查询,就能正常过滤数据了。

内容的提问来源于stack exchange,提问作者BlakeB9

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.16 01:16:08