【问题标题】:The IN operator is provided with too many operands; number of operands: 119 dynamodbIN 运算符提供的操作数过多;操作数:119 dynamodb
【发布时间】:2018-02-13 09:09:06
【问题描述】:

尝试在 dynamodb 中使用 IN 操作,但出现以下错误。谁能帮我提供替代解决方案?

变量参数 = {

TableName : "table_name",
FilterExpression : "id IN ("+Object.keys(profileIdObject).toString()+ ")",
ExpressionAttributeValues : profileIdObject

};

错误:: {

  "message": "Invalid FilterExpression: The IN operator is provided with too many operands; number of operands: 119",
  "code": "ValidationException",
  "time": "2018-02-13T08:48:02.597Z",
  "statusCode": 400,
  "retryable": false,
  "retryDelay": 25.08276239472692

}

【问题讨论】:

    标签: amazon-dynamodb dynamo-local


    【解决方案1】:

    根据文档:

    IN 比较器的最大操作数为 100

    在这里找到:https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Limits.html#limits-expression-parameters

    您需要分多批执行查询/扫描,在您的情况下,第一批中有 100 个 Object.keys(profileIdObject).toString(),第二批中有 19 个。然后合并结果。

    【讨论】:

      【解决方案2】:

      根据 dynamodb 文档,IN 比较器的最大操作数数为 100

      所以你可以分成很多操作,比如:

      FilterExpression : "id IN (1,2,3, ....) OR id IN (101,102,103,...) ..."

      使用此功能:

      let getFilterExp = function (x) {
          let arr = []
          let currentIndex = 0
          let counter = 0
          let max = 99
      
          arr[currentIndex] = {}
      
          for (let y in x) {
              if (counter < max) {
                  arr[currentIndex][y] = x[y]
                  counter++
              }
              else {
                  currentIndex++
                  arr[currentIndex] = {}
                  arr[currentIndex][y] = x[y]
                  counter = 0
              }
          }
      
          let exp = ''
          for (let i = 0; i < arr.length; i++) {
              if (i == 0) {
                  exp += "id IN (" + Object.keys(arr[i]).toString() + ")"
              }
              else {
                  exp += " OR id IN (" + Object.keys(arr[i]).toString() + ") "
              }
          }
      
          return exp
      }
      

      在您的情况下,x 是 profileIdObject

      let filterExp = getFilterExp(profileIdObject )
      

      【讨论】:

        猜你喜欢
        • 2018-02-11
        • 1970-01-01
        • 1970-01-01
        • 2011-10-22
        • 2020-05-20
        • 2013-04-21
        • 1970-01-01
        • 2017-10-14
        • 1970-01-01
        相关资源
        最近更新 更多