# is not supporting to RIak Ts - riak-ts

while making query to Riak TS, my email contaning # symbol so it giving some problem like
SQL Lexer error <<"Unexpected token '#'.">>
then How we Resolve this problem.

Use below query.
SELECT SUM(steps),
registrationDate
FROM steps
WHERE
START >= 1482085800000
AND
START <= 1489775400000
AND userName = <<"hussain.shahzad250#gmail.com">>;

specially #Saranjith
Query will be now as given below
select start,end,steps from steps_record where start >= 1472495400000 and start <= 1490121000000 and userName = '<<"apolloprod120#gmail.com">>';
anyways Thanks #Saranjith, i tried with your given syntax in 2-3 ways after that i got this solved.

Related

Apache Drill Timestampdiff on Oracle DB

Hey everyone im relativly new to Apache Drill and im having troubles converting my Oracle specific sql scripts (pl/sql) to Drill based querys.
For example i have a Scripts who checks for processed data in the last X Days.
In this script im using the the sysdate function.
Here is my old script:
SELECT i.id,i.status,status_text,i.kunnr,i.bukrs,i.belnr,i.gjahr,event,i.sndprn,i.createdate,executedate,tstamp,v.typ_text,i.docnum,i.description, i.*
FROM in_job i JOIN vstatus_injob v ON i.id= v.id
WHERE 1=1
AND i.createdate > sysdate - 30.5
order by i.createdate desc;
When i looked up in terms of drill specific Datetime Diff functions i found "TIMESTAMPDIFF".
So here is my "drillified" script:
SELECT i.id, i.status, status_text, i.kunnr, i.bukrs, i.belnr, i.gjahr, i.event, i.sndprn, i.createdate, i.executedate, i.tstamp,v.typ_text,i.docnum,i.description,i.*
FROM SchemaNAME.IN_JOB i JOIN SchemaNAME.VSTATUS_INJOB v ON i.id=v.id
WHERE TIMESTAMPDIFF(DAY, CURRENT_TIMESTAMP, i.createdate) >=30
And the Error that is returned reads like this:
DATA_READ ERROR: The JDBC storage plugin failed while trying setup the SQL query.
By further inspection i can see the Oracle specific error that reads:
Caused by: java.sql.SQLSyntaxErrorException: ORA-00904: "TIMESTAMPDIFF": invalid ID
So now my question:
I thought apache drill replaces the function "TIMSTAMPDIFF" at runtime. But from what i can see in the logs its more like that Drill Hands over the Function Call "TIMESTAMPDIFF" to the Oracle database.
If thats true, how could i change my script to calculate the time difference (in days) and compare it to an int (ie 30 in the script).
If i use sysdate like above Apache Drill jumps in and says it doesnt know "sysdate".
How would you guyes handle that?
Thanks in advance and so long
:)
I have found a solution...
Just in Case someone (or even me in the future) is having a similar problem.
{
"queryType": "SQL",
"query": "select to_char(SELECT CURRENT_TIMESTAMP - INTERVAL XX MONTH FROM (VALUES(1)),'dd.MM.yy')"
}
With some to_char and the use of the CURRENT_TIMESTAMP - Interval Function Calls i can get everything i needed.
I took the query above packed it into an Grafana Variable, named it "timeStmpDiff" and then queried everything with an json Api Call to my Drill instance.
Basically:
"query" : "SELECT i.id, i.status, status_text, i.kunnr, i.bukrs, i.belnr, i.gjahr, i.event, i.sndprn, i.createdate, i.executedate, i.tstamp,v.typ_text,i.docnum,i.description,i.* FROM ${Schema}.IN_JOB i JOIN ${Schema}.VSTATUS_INJOB v ON i.id=v.id WHERE i.createdate >= '${timeStmpDiff}' order by i.createdate desc"
You can, of course query it in on go with an subselect.
But because i use grafana it made sense to me to bundle that in a Variable.

TOAD 10.6 Sql Error ORA - 01858: What is wrong with query?

Please help me identify the below issue. I have a canned query below and can't get it to run without getting this error:
SELECT * FROM TABLE(fdr_dal_txns.get_txn_trans_adjst_consol
(short_string_col('1BFV')
,'POST_DT'
,short_string_col('MCH','GP3', 'OTC')
,'01-may-2017'
,'30-june-2017'
))
WHERE trd_id_num IN ('17FHKBBSSML',
'17FHVBBRJD8')
What is obvious, is that you seem to be passing strings ('01-may-2017' is a string) where you should have passed dates. I'd suggest you to use date literals, such as
SELECT *
FROM TABLE (fdr_dal_txns.get_txn_trans_adjst_consol (
short_string_col ('1BFV'),
'POST_DT',
short_string_col ('MCH', 'GP3', 'OTC'),
DATE '2017-05-01', --'01-may-2017',
DATE '2017-06-30' --'30-june-2017'
))
WHERE trd_id_num IN ('17FHKBBSSML', '17FHVBBRJD8')
and see what happens. If it still doesn't help, you should provide much more details of what you're doing (because you told us close to nothing so far).

PostgreSQL : Operator does not exist: Integer < Interval

I have wrote a query so I can view people who are overdue an order based on their average order dates. The query is to be ran on a PostgreSQL database, and will be executed from a Java process.
However in the line :
CASE WHEN
(max(date_trunc('day', dateordered))-
min(date_trunc('day', dateordered)) ) /
count(distinct dateordered) + 5 <
date_trunc('day',now()) -
max(date_trunc('day', dateordered)) THEN 'ORDEROVERDUE' ELSE
null
END
I receive the error message :
Operator does not exist : integer < interval
I have read a lot of questions which have a similar issue, but none which seem to fix my particular issue.
If I alter my query to this :
CASE WHEN
(max(dateordered::date) - min(dateordered::date) )/
count(distinct dateordered) + 5 <
now()::date - max(dateordered::date) THEN
'ORDEROVERDUE' ELSE null
END
Then it runs on the database, however I can't get this syntax to work in my process in eclipse.
My understanding of SQL is letting me down. I understand the general reason behind the error, but I am unable to create a solution.
Is there a way of altering this line in a way which removes the error and I can still get the desired result?

Selecting entries whose `date_field < NOW()`

When I try to run the following query, it returns nothing:
Item::where(\DB::raw('date_field < NOW()'))->get()
The reason for this is, that is null is appended to the generated MySQL query like this:
SELECT * FROM items WHERE date_field < NOW() is null;
Why does the is null part get appended to the above query?
This is a known issue in Laravel and has been reported on their GitHub page. Use whereRaw() instead and pass a string:
Item::whereRaw('date_field < NOW()')->get()
No idea why the not null part gets appended. But I found a workaround.
Try this
Item::whereNotNull(\DB::raw('date_field < NOW()'))->get()
Of course, you may use built-in features like Carbon
Item::where('date_field', '<', Carbon\Carbon::now())->get()
Use it this way..
Item::where('date_field','<','NOW()')->get()
SELECT * FROM items WHERE date_field < GETDATE();

ORACLE ORA00907: Differences in connection string using OraOLEDB.Oracle vs TNS lookup via Oracle in OraClient10g_home3

I am using Oracle Client 10.2g and by changing my connection string to the Oracle database I now get error ORA00907 for some of my queries.
The code is executing within excel 2010 using VBA and I can run 20+ quires without error using the following connection string:
ServerConnectionString="Driver={Oracle in OraClient10g_home1};Dbq=DBNAME;Uid=USERNAME;Pwd=PASSWORD;"
With OpenR2DBConnection
.ConnectionTimeout = ConnectionTimeout
.Open ServerConnectionString
.Execute "ALTER SESSION SET NLS_DATE_FORMAT = 'DD/MM/YYYY'"
.CommandTimeout = CommandTimeout
End With
By changing the connection string only to:
ServerConnectionString="Provider=OraOLEDB.Oracle;Data Source=(<<<data exact translation from TNSNAMES file for the DBNAME>>>);User id=USERNAME;Password=PASSWORD;"
2 of the 20+ queries fail with ORA-00907: missing right parenthesis
One of the Queries that fails (refracted):
select n1.name,n1.sdate,n1.edate,n1.note as crnote,n1.cdate ,n1.pri
from
(
select n.name,n.sdate,n.edate,n.note,n.cdate,n.pri , RANK() OVER (PARTITION BY n.sdate,pri ORDER BY (n.adate - n.cdate) asc,n.pri asc) RANK
from
(
select mmpe.name,mmpe.sdate,mmpe.edate,mmpe.cannote as note,mmpe.cdate,mmip.crdate as adate,mp.pri
from mmpe ,mmmip mmip, mp
where <<clauses1>>
and mmpe.name in (<<list of strings>>)
and mmip.name(+) = mmpe.name
and <<more clauses2>>
union
Select mmip.name,mmip.sdate,greatest(<<formula>>) as edate , <<create note>> as note ,mmip.crdate as cdate, td.adate,mp.pri
From mi , mmip,td, mp
Where <<clauses3>>
and mi.name in (<<list of strings>>)
union all
Select mmip.name,mmip.sdate,mmip.edate as edate , <<create note>> as note ,mmip.crdate as cdate , td.adate,mp.pri
From mi , mmip,td, mp
Where <<clauses4>>
and mi.name in (<<list of strings>>)
union
Select mmip.name,mmip.sdate,td.cddate-1 as edate , <<create note>> as note, mmip.crdate as cdate,mmip.crdate as adate,mp.pri
From mi , mmip,td, mp
Where <<clauses4>>
and mi.name in (<<list of strings>>)
) n
) n1
where rank = 1
order by 6,2,5;
I have tested that the Query runs correctly in Oracle SQL Developer.
I have verified that prior to Executing the query the SQL statements are identical for both connection strings.
The other query that fails is also using a union and rank function but it is not the only one.
The reason I wish to use the OraOLEDB.Oracle connection is that I am attempting to remove my reliance on the tnsnames.ora files as from time to time I add new database instances and want to avoid all my users having to update this file in the oracle directory.
Lastly the ORACLE database is version 8.
Any help would be greatly appreciated,
Thanks in advance!
Updated: Removed typo error
OK I've work it out.
Thanks to all those that spent any time thinking about it.
When I refracted the example above I removed inline comments denoted by '--'.
It was these comments that caused the ORA-00907 error with the OraOLEDB.Oracle driver.
So the fix is simple: Remove comments from the SQL command!
Thanks again!