sqlQuery of DocumentDB input bindings with modulation symbol makes function's failure - azure

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

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

Related

Spark Dataframe timestamp column manipulation failing without any error message

aggregate = aggregate.withColumn('DaysSinceFirstUsage', when(months_between(current_date(), col('FirstUsage')) > 120, - (sys.maxsize - 1)).otherwise(days_between(current_date(), col('FirstUsage')))
aggregate = aggregate.withColumn('DaysSinceLastUsage', when(months_between(current_date(), col('LastUsage')) > 120, - (sys.maxsize - 1)).otherwise(days_between(current_date(), col('LastUsage')))
Silly mistake :)
Closing bracket at the end was missing and datediff was wrongly written as days_between. Query running fine after correction.
aggregate = aggregate.withColumn('DaysSinceFirstUsage', when(months_between(current_date(), col('FirstUsage')) > 120, - (sys.maxsize - 1)).otherwise(datediff(current_date(), col('FirstUsage'))))
aggregate = aggregate.withColumn('DaysSinceLastUsage', when(months_between(current_date(), col('LastUsage')) > 120, - (sys.maxsize - 1)).otherwise(datediff(current_date(), col('LastUsage'))))

Google Lighthouse Performance Calculator Formula

I'm trying to mimic Lighthouse performance calculator but I don't know the formula for it.
Say the weighted percentage from their website is:
FCP : 10%
SI : 10%
LCP : 25%
TTI : 10%
TBT : 30%
CLS : 15%
Given the weighted percentage above here's a sample value:
FCP : 1590 ms
SI : 4060 ms
LCP : 1590 ms
TTI : 9035 ms
TBT : 624 ms
CLS : 0.01
I compute it this way:
fcp_total = fcp_value * fcp_weighted_percentage;
si_total = si_value * si_weighted_percentage;
lcp_total = lcp_value * lcp_weighted_percentage;
tti_total = tti_value * tti_weighted_percentage;
tbt_total = tbt_value * tbt_weighted_percentage;
cls_total = cls_value * cls_weighted_percentage;
performance_score = fcp_total + si_total + lcp_total + tti_total + tbt_total + cls_total;
But I'm not getting the correct result like in this website. https://googlechrome.github.io/lighthouse/scorecalc/#FCP=1590&TTI=9035&SI=4060&TBT=624&LCP=1590&CLS=0.01&FMP=1590&device=desktop&version=9.4.0
Hope Someone can shed a light on this. Thank you.

MSSQL module converting return value to int?

We are using the MSSQL module with Node.js.
I am running the following query:
SELECT AVG((RAT_VALUE * 1.0)) FROM RAT WHERE RAT_PER_ID_FROM IS NOT NULL AND RAT_PER_ID_ABOUT = 139 AND RAT_USE = 'Y' AND RAT_ABOUT_ROLE = 'RS' AND RAT_DATE_INSERTED >= '10/1/2018' AND RAT_DATE_INSERTED < '10/1/2019'
If I run this against the database directly, it returns:
4.45
The output from MSSQL is:
4
The exact resultset returned is:
results { recordsets: [ [ [Object] ] ],
recordset: [ { '': 4 } ],
output: {},
rowsAffected: [ 1 ] }
In other words, MSSQL is always returning the value 4, instead of 4.45.
The column type od RAT_VALUE is INT in the database but I've tried changing it to DECIMAL(5, 2) without any luck.
I've tried explicitly returning a DECIMAL from the query like:
SELECT CAST(AVG((RAT_VALUE * 1.0)) AS DECIMAL(5, 2)) ...
But no luck there either.
It seems MSSQL is simply clipping and dropping the decimal part of any number, even numbers of Decimal types.
I even set the value as 4.75 in the database and returned it directly and it still returns 4.
Any ideas out there?

Query with multiple filters on Pandas

I want to execute this query.The query is " filtering data with 'Gas Oil/ Diesel Oil - Production' transaction and the year is greater than 2000 ". Firstly , i tried to execute my query with & operand and vectorized column selection without using if statement. But it did not work.After then , i found this query at below.This time i could not get any output.What do you think about my query problem ?.Thanks ...
if all(b['Commodity - Transaction'] == 'Gas Oil/ Diesel Oil - Production') and all(b[ b['Year'] >2000 ]):
print (b)
else:
print('did not find any values')
what's wrong with:
b.loc[(b['Commodity - Transaction'] == 'Gas Oil/ Diesel Oil - Production') & (b['Year'] >2000)]
?
You can try first create mask with contains and the create subset - use Boolean indexing:
print b[(b['Commodity - Transaction'].str.contains('Gas Oil/ Diesel Oil - Production')) &
(b['Year'] > 2000) ]

Iterating through a cursor in Sybase ASE seems to do multiple loops

I am creating a cursor using select statement that would return 4 values (18, 13, 14 and 15). I am trying to iterate through the cursor and display the value for now. I am expecting 4 print statements, but I see lot more than that.
Here is the code:
PRINT '***** *****'
GO
DECLARE curs CURSOR FOR
SELECT ID FROM CUSTOMER WHERE SSN LIKE '%1803'
GO
DECLARE #ID int
OPEN curs
FETCH NEXT curs INTO #ID
WHILE ##sqlstatus = 0
BEGIN
PRINT '* current value: %1! ', #ID
FETCH NEXT curs INTO #ID
END
CLOSE curs
DEALLOCATE CURSOR curs
GO
Here is the output:
***** *****
* current value: 18
* current value: 18
* current value: 13
* current value: 18
* current value: 13
* current value: 14
* current value: 18
* current value: 13
* current value: 14
* current value: 15
* current value: 18
* current value: 13
* current value: 14
* current value: 15
It seems like a simple iterate over cursor and I cannot understand why I am seeing so many print statements, I want to only see 18, 13, 14 and 15. I am using Sybase ASE 15.5 and Razor SQL client. Can someone help me with this?
* Edit *
I didn't see the issue when I used Sybase Central (for ASE). The results were inconsistent when I used other IDEs.
Firstly make sure you always use an order by with any SQL nowadays to ensure you get data back in the order you expect. You don't know how the database will optimise the query at the backend so be specific.
Also check a direct select and check how many rows match for 'SSN LIKE '%1803' to begin with to cross-check the rowcounts against the cursor.

Resources