while query to Riak timeseries databse i am getting SQL Parser error - riak

I am getting this as a problem:
{0,riak_ql_parser, <<"Used group as a measure of time in 712903232group. Only s, m, h and d are allowed.
My Query:
select memberId,COUNT(memberId) from Emp18 where start>1478925732000 and start< 1478925939000 and end>1478913322000 and memberId<712903232 group by memberId;
but I am getting response with following query:
select memberId,COUNT(memberId) from Emp18 where start>1478925732000 and start< 1478925939000 and end>1478913322000 and memberId<712903232;
and I am getting output as :
+---------+-----+---------------+
|memberId |steps|COUNT(memberId)|
+---------+-----+---------------+
|712903230| 350 | 4 |
+---------+-----+---------------+

Related

Kusto calculate the minutes since last event

I am converting a Splunk Dasboard to a Kusto Dash board
Below is the Splubk Query that give me the minites since as 60
index=V source=c:\\files\\build\\* | head 1 | eval minutesSince=round((now() - _indextime)/60,0) | table minutesSince
I try to create the same in Kusto but the time is not matching gives me 0 minutesSince. But the Data is the same in Splunk and Kusto. Not sure what part of the Query should I correct. Thanks for the support.
| extend minutesSince = (now() - ingestion_time())/60
| project minutesSince,BuildId
| limit 1```
you could try something like the following:
for the entire table:
TableName
| summarize minutes_since_last_ingestion = (now() - max(ingestion_time())) / 1m
or, per record:
TableName
| extend minutes_since_ingestion = (now() - ingestion_time()) / 1m

Syntax error when using count in loop

I am trying to run a loop where I count the total in each file under the variable _merge, and then count certain outcomes of _merge, such as _merge=1 and so on. I then want to calculate percentages by dividing each instance of _merge by the total under _merge.
Below is my code:
/*define local list*/
local ward_names B C D E FN FS GS HE
/*loop for each dbase*/
foreach file of local ward_names {
use "../../../cleaning/sra/output/`file'_ward_CTS_Merged.dta", clear
count if _merge
local ward_count=r(N)
count if _merge==1
local count_master=r(N)
count if _merge==2
local count_using=r(N)
count if _merge==3
local count_match=r(N)
clear
set obs 1
g ward_count='ward_count'
g count_master=`count_master'
g count_using=`count_using'
g count_match=`count_match'
g ward= "`file'"
save "../temp/`file'_collapsed_diagnostics.dta", replace
clear
The code was running fine until I tried to add the total count for each ward file:
g ward_count='ward_count'
'ward_count' invalid name
Is this a syntax error or something more severe?
You need to use ` instead of ' when you refer to a local macro:
generate ward_count = `ward_count'
EDIT:
As per #NickCox's recommendation you can improve your code by using the tabulate command with its matcell() option to get the counts all at once:
tabulate _merge, matcell(A)
_merge | Freq. Percent Cum.
------------------------+-----------------------------------
master only (1) | 1 16.67 16.67
matched (3) | 5 83.33 100.00
------------------------+-----------------------------------
Total | 6 100.00
matrix list A
A[2,1]
c1
r1 1
r2 5
So you could then do the following:
generate count_master = A[1,1]
generate count_match = A[2,1]

Running embedded R code in Oracle raise error

I am a newbie in Oracle R embedded execution.
well, I have following code registered as
BEGIN
sys.rqScriptDrop('TSFORECAST');
SYS.RQSCRIPTCREATE('TSFORECAST',
'function(dat){
require(ORE)
require(forecast)
myts <- ts(dat,frequency=12)
model <- auto.arima(myts)
fmodel <- forecast(model)
fm = data.frame(fmodel$mean, fmodel$upper,fmodel$lower)
names(fm) <- c("mean","l80","l95","u80","u95")
return(fm)
}'
);
END;
as I execute the function for the first time with this code:
select *
from table(
rqTableEval(
cursor(select balance from tmp_30),
cursor(select 1 as "ore.connect" from dual),
'select 1 mean, 1 l80, 1 l95, 1 u80, 1 u95 from dual',
'TSFORECAST'
)
)
it generates the results I expected. But after that it will never produce any result but instead it raises this error:
ORA-20000: RQuery error
Error in (function () :
unused arguments (width = 480, bg = "white", type = "raster")
ORA-06512: at "RQSYS.RQTABLEEVALIMPL", line 112
ORA-06512: at "RQSYS.RQTABLEEVALIMPL", line 109
20000. 00000 - "%s"
*Cause: The stored procedure 'raise_application_error'
was called which causes this error to be generated.
*Action: Correct the problem as described in the error message or contact
the application administrator or DBA for more information.
I have searched this error but could not find anything helpful. Can anyone help me with this error?

How to Count the Number of Distinct Values in a Data Frame Column with a Condition in R

I have a data frame that looks like this:
date timestamp transfer ID IP Address Username Encryption File Bytes Speed DateTimeStamp
1 20160525 08:22:06.838 F798256B 10.199.194.38:57708 wei2dt - "" 264 "1.62 seconds (1.30 kilobits/sec)" 20160525 08:22:06.838
2 20160525 08:28:26.920 F798256C 10.19.105.15:57708 wei2dt - "isi_audit_log.dmp-sv.tmp" 69 "0.29 seconds (1.93 kilobits/sec)" 20160525 08:28:26.920
3 20160525 08:28:26.923 F798256D 10.19.105.15:57708 wei2dt - "isi_audit_log.dmp-sv.met" 0 "Unable to stat isi_audit_log.dmp-sv.met: No such file or directory" 20160525 08:28:26.923
4 20160525 08:28:26.933 F798256E 10.19.105.15:57708 wei2dt - "CG0009 1364_GT_report.txt" 34 "0.01 seconds (34.0 kilobits/sec)" 20160525 08:28:26.933
I want to count the number of users (usernames) that were online at a certain time. Essentially, I want to check every five minutes or so how many users were active. I need to use the DateTimestamp column to create my intervals and utilize it as a condition to count the number of distinct users at that period of time. I've tried using a while loop to do something of the sort, but it did not work. Are there any suggestions on how I should go about this?
With dplyr
df %>% mutate(timeInt=cut(DateTimeStamp,breaks="5 min")) %>%
group_by(timeInt) %>% summarise(numberUniqueUsers=length(unique(Username)))

Debugging SQLite R*tree

I have an SQLite database containing an R*tree virtual table. This table is behaving rather oddly and I'm at a loss as to what is wrong. I would appreciate any pointers to aspects I could investigate!
> dbGetQuery(con, 'PRAGMA integrity_check')
integrity_check
1 ok
It seems fine...
> dbGetQuery(con, 'SELECT * FROM peakLoc LIMIT 5')
peakID scanStart scanEnd mzMin mzMax
1 18481 5540 5904 435.1880 435.2095
2 18429 5555 5644 408.7411 408.7459
3 18251 5621 5710 432.7190 432.7285
4 16415 6081 6173 432.2292 432.2470
5 16391 6089 6351 454.1823 454.1960
The general look of the R*tree table
> dbGetQuery(con, 'SELECT MIN(scanEnd), MAX(scanEnd) FROM peakLoc')
MIN(scanEnd) MAX(scanEnd)
1 51 19369
The bounds of scanEnd
> dbGetQuery(con, 'SELECT * FROM peakLoc WHERE scanEnd > 5000 LIMIT 5')
peakID scanStart scanEnd mzMin mzMax
1 20987 4839 6284 410.1729 410.2035
2 6705 9827 10132 738.8564 738.8674
3 15190 6482 6756 615.3235 615.3395
4 15189 6482 6756 509.2193 509.2258
5 12001 7449 7710 855.4534 855.4631
So far so good...
> dbGetQuery(con, 'SELECT * FROM peakLoc WHERE scanEnd > 6000 LIMIT 5')
[1] peakID scanStart scanEnd mzMin mzMax
<0 rows> (or 0-length row.names)
Where are the records?
The same is happening for the other columns with bigger-than once the comparator gets to an arbitrary large number. This behaviour is only present in the R*tree table - the regular tables works fine...
Have I stumbled upon a constraint in the R*tree module that I do not know about? All records in the R*tree comes from one big insert and I have not touched the underlying tables that the R*tree relies on...
edit:
On request from CL I've tried to create a reproducible example. At least on my system the following produces an R*tree with the same behaviour:
set.seed(1)
library(RSQLite)
con <- dbConnect(dbDriver('SQLite'), ':memory:')
dbGetQuery(con, 'CREATE VIRTUAL TABLE test USING rtree(id, xmin, xmax, ymin, ymax)')
x <- abs(rnorm(100))
y <- abs(rnorm(100))
data <- data.frame(id=1:100, xmin=x, xmax=x+2, ymin=y, ymax=y+3)
dbGetPreparedQuery(con, 'INSERT INTO test VALUES ($id, $xmin, $xmax, $ymin, $ymax)', bind.data=data)
dbGetQuery(con, 'SELECT max(xmax) FROM test')
dbGetQuery(con, 'SELECT * FROM test WHERE xmax > 4 LIMIT 5')
dbGetQuery(con, 'SELECT * FROM test WHERE +xmax > 4 LIMIT 5')
edit 2:
A database created with the commands given in the first edit can be downloaded from this link:
https://dl.dropboxusercontent.com/u/2323585/testdb.sqlite

Resources