2
votes

I using the DocumentDB input bindings on Azure Functions.

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 '%'.

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

Best regards.


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

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

That's result is followings.

[
  {
    "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"
  }
]

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

{"epoch":1499218423}

And code of the function is followings.

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)

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

Why appeared this differences?

Related question : Deferences among the Azure CosmosDB Query Explorer's results and the Azure Functions results

1

1 Answers

0
votes

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

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.

enter image description here

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