本文介绍了带调制符号的DocumentDB输入绑定的sqlQuery使函数失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Azure Functions上使用DocumentDB输入绑定.

I using the DocumentDB input bindings on Azure Functions.

今天,我指定了以下查询作为sqlQuery.

Today, I specified a following query as a sqlQuery.

SELECT c.id, c.created_at FROM c 
WHERE {epoch} - c.created_at_epoch >= 86400*31 
AND (CEILING({epoch}/86400) - CEILING(c.created_at_epoch / 86400)) % 31 = 0

然后,在触发功能时,我看到了以下错误.

Afterwards, I saw a following error when function is triggered.

2017-07-04T10:31:44.873 Function started (Id=95a2ab7a-8eb8-4568-b314-2c3b04a0eadf)
2017-07-04T10:31:49.544 Function completed (Failure, Id=95a2ab7a-8eb8-4568-b314-2c3b04a0eadf, Duration=4681ms)
2017-07-04T10:31:50.106 Exception while executing function: Functions.Bonus. Microsoft.Azure.WebJobs.Host: The '%' at position 148 does not have a closing '%'.

我想在sqlQuery中使用调制符号.我能怎么办?

I want to use a modulation symbol within sqlQuery. What can I?

最诚挚的问候.

2017-07-15(JST)附加.

2017-07-15(JST) Append.

今天,我尝试跟踪另一个查询以避免此问题.

And today, I tried following another query for avoid this issue.

SELECT c.id, c.created_at FROM c 
WHERE {epoch} - c.created_at_epoch >= 86400*31 AND 
(CEILING({epoch}/86400) - CEILING(c.created_at_epoch / 86400)) - 
(31 * 
    CEILING(
        (CEILING({epoch}/86400) - CEILING(c.created_at_epoch / 86400)) 
        / 31
    )
) = 0

以防万一,我尝试了在Cosmos DB上指定一个纪元= 1499218423的查询.

Just in case, I tried this query that is specified a epoch = 1499218423 on the Cosmos DB.

SELECT c.id, c.created_at FROM c 
WHERE 1499218423 - c.created_at_epoch >= 86400*31 AND 
(CEILING(1499218423/86400) - CEILING(c.created_at_epoch / 86400)) - 
(31 * 
    CEILING(
        (CEILING(1499218423/86400) - CEILING(c.created_at_epoch / 86400))
        / 31
    )
) = 0

结果是追随者.

[
  {
    "id": "70251cbf-44b3-4cd9-991f-81127ad78bca",
    "created_at": "2017-05-11 18:46:16"
  },
  {
    "id": "0fa31de2-4832-49ea-a0c6-b517d64ede85",
    "created_at": "2017-05-11 18:48:22"
  },
  {
    "id": "b9959d15-92e7-41c3-8eff-718c4ab2be6e",
    "created_at": "2017-05-11 19:01:43"
  }
]

看起来不错.然后,将其指定为sqlQuery并使用以下队列数据进行测试.

It looks fine. Then I specify it as sqlQuery and test with following queue data.

{"epoch":1499218423}

该函数的代码如下.

module.exports = function (context, myQueueItem) {
    context.log(context.bindings.members, myQueueItem);
    context.done();
};

不幸的是,我看到了以下结果.

Afetrwards, I saw following results.

2017-07-05T03:00:47.158 Function started (Id=e4d060b5-3ddc-4271-bf91-9f314e7e1148)
2017-07-05T03:00:47.408 [] { epoch: 1499871600 }
2017-07-05T03:00:47.408 Function completed (Success, Id=e4d060b5-3ddc-4271-bf91-9f314e7e1148, Duration=245ms)

它看起来绑定结果(作为context.bindings.members)的差异.

It looks differences in results of bindings(as context.bindings.members).

为什么会出现这种差异?

Why appeared this differences?

相关问题: Azure CosmosDB查询资源管理器的结果和Azure函数的结果

推荐答案

Azure功能配置中的调制符号(%)用于从应用程序设置中检索值.对于您的问题,建议您在应用设置中添加以下内容.

The modulation symbol(%) in Azure function configuration is used to retrieve values from app settings. For your issue, I suggest you add a item in app setting as following.

之后,可以在查询中使用%modulationsymbol%代替%,如下所示.

After that, you could use %modulationsymbol% instead of % in your query as following.

SELECT c.id, c.created_at FROM c 
WHERE {epoch} - c.created_at_epoch >= 86400*31 
AND (CEILING({epoch}/86400) - CEILING(c.created_at_epoch / 86400)) %modulationsymbol% 31 = 0

这篇关于带调制符号的DocumentDB输入绑定的sqlQuery使函数失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-30 00:22