Wso2 Stream Mongo Datetime join query - mongodb

I try to make a query between a stream (contains a datetime) and a store mongodb table on a datetime column.
define stream TriggerStream (lastexec string);
#info(name = 'ExtractData')
from TriggerStream as e right outer join OFFRELOG as o
on o.lastmodified> e.lastexec
select CLIC_OFFRELOG,lastmodified
insert into RECO_TEST;
I get no data from this query. Is there a way to cast datetime column in timsstamp format ?
Best regards,
Nicolas

The above query works only if the column(lastmodified) is of type long which is matched to a timestamp column of BSON type of long.
Siddhi-store-mongodb does not support date column out of the box. I have opened an issue in the Github repository to track this support.

Related

PostgreSQL function lags when passing a date from another table as argument

I created a function that retrieves data from multiple table and insert the result into a new table. I am passing few dates in the where clause to filter the applicable information. The dates are in timestamptz format. The query takes roughly a min to process. However when I make the change in the where clause to pass the date from another table, the query lags a lot. i.e.
My initial argument that doesn't lag is
where timestamp = '2022-01-05 04:00:00+00'
The lag is when I change this where clause to pass this date from another table.
where timestamp = select date_time from table_Test
The date_time in table_test is defined as timestamptz and the value is '2022-01-05 04:00:00+00'.
Any idea why the query lags when I pass the date argument from another table?
Thanks,

splitting the source data to have the specific data oracle

I have a source field from oracle db table data type VARCHAR2(512 CHAR) which is like this
%custId{str:hGl0EWJsRTwweerRkaaKsdKDsqKm0123}
%prod{str:BalanceAmount}%logistic{str:Logistic}%hiringdate{str:1999-02-28T11:10:11p}%custId{str:FpseikiD0Jt1L0Mskdww8oZBjU4La123}
but when i consider for my extract i must only consider only data with %cusId pull data and only this alphanumeric data has to be captured and populated for the extract , the problem is this is just one example from source there can be any number of combinations but i have to only consider %custId with
%custId{str:hGl0EWJsRTwweerRkaaKsdKDsqKm0123}
i need to use which function substr,lpad ?
after using the below query
SELECT
field,
REGEXP_SUBSTR(field, '%custId\{.*?\}') AS custId
FROM yourTable
where col_source='%prod{str:BalanceAmount}%logistic{str:Logistic}%hiringdate{str:1999-02-28T11:10:11p}%custId{str:FpseikiD0Jt1L0Mskdww8oZBjU4La123}'
Result
%custId{str:FpseikiD0Jt1L0Mskdww8oZBjU4La123}
but expected result
FpseikiD0Jt1L0Mskdww8oZBjU4La123
You may use REGEXP_SUBSTR here:
SELECT
field,
REGEXP_SUBSTR(field, '%custId\{(.*?)\}', 1, 1, NULL, 1) AS custId
FROM yourTable;

not able to perform comparison between two TIMESTAMP columns in apache beam

I'm trying to compare between two columns which are declared as TIMESTAMP datatype like below :
select a.*, ROUND(SUM(b.CausalValue),2) as GRPs from table1 a
left join table2 b
on a.Channel = b.Outlet and
a.SubBrand = b.SubBrand and
a.Event = b.SalesComponent and
b.Week >= a.PeriodStartDate and
b.Week <= a.PeriodEndDate
group by Vehicle,Campaign,Copy,Event,CatLib
Week, PeriodStartDate and PeriodEndDate are declared as TIMESTAMP and I'm not able to perform this operation.
What my understanding as of now is may be beamSql does not allow comparison between two TIMESTAMP columns.
Any idea ?
Correct, at the moment comparison of date, time, timestamp, interval types is not implemented yet
#Anton, #Andrew : Well I agree that this feature is not implemented yet and what I did is I replaced timestamp with Date datatype and then converted the date column into BigInt (using extract and concat functions of sql) and then did the comparison and it worked perfectly fine.
Thanks alot guys .

PostgreSQL does not order timestamp column correctly

I have a table in a PostgreSQL database with a column of TIMESTAMP WITHOUT TIME ZONE type. I need to order the records by this column and apparently PostgreSQL has some trouble doing it as both
...ORDER BY time_column
and
...ORDER BY time_column DESC
give me the same order of elements for my 3-element sample of records having the same time_column value, except the amount of milliseconds in it.
It seems that while sorting, it does not consider milliseconds in the value.
I am sure the milliseconds are in fact stored in the database because when I fetch the records, I can see them in my DateTime field.
When I first load all the records and then order them by the time_column in memory, the result is correct.
Am I missing some option to make the ordering behave correctly?
EDIT: I was apparently missing a lot. The problem was not in PostgreSQL, but in NHibernate stripping the milliseconds off the DateTime property.
It's a foolish notion that PostgreSQL wouldn't be able to sort timestamps correctly.
Run a quick test and rest asured:
CREATE TEMP TABLE t (x timestamp without time zone);
INSERT INTO t VALUES
('2012-03-01 23:34:19.879707')
,('2012-03-01 23:34:19.01386')
,('2012-03-01 23:34:19.738593');
SELECT x FROM t ORDER by x DESC;
SELECT x FROM t ORDER by x;
q.e.d.
Then try to find out, what's really happening in your query. If you can't, post a testcase and you will be helped presto pronto.
try cast your column to ::timestamp like that:
SELECT * FROM TABLE
ORDER BY time_column::timestamp

error in convert datetime from a text field

I have a subquery which converts a text coloumn into datetime. Since it is in text format there are coloumns wich contains bad data. I know the first answer would be to correct the data, I strongly agree that. I do not have the privileges to do that, unfortunately i have to deal with it.
below is my query
INNER JOIN TABLE XYZ
ON XYZ.COLOUMN1=YZX.COLOUMN2
LEFT JOIN ( SELECT ABC.stu_id
ABC.stu_name
CONVERT(DATETIME,LMN.startDate,111) STARTDATE
CONVERT(DATETIME,LMN.endDate,111) ENDDATE
FROM STUDENT ABC
INNER JOIN AN_STUDENT_TABLE LMN
ON ABC.stu_id=LMN.stu_id
WHERE ISDATE(startDate)=1
AND ISDATE(endDate)=1
GROUP BY ABC.stu_id,ABC.stu_name,STARTDATE,ENDDATE) DIN ON DIN.stu_id=LMNOP.stu_id
WHERE e.date BETWEEN DIN.STARTDATE AND DIN.ENDDATE
when i compare e.date with the startdate and enddate it fails giving me an well know error
"The conversion of a varchar data type to a datetime data type resulted in an out-of-range value."
what can be done to atleast skip those bad data records which cannot be converted?
I tried my best to figure this out but failed. Any help/advice appretiated!
Your ISDATE in the where clause does not necessarily filter out the bad dates before they are used in the conversion.
I think you should do this in two steps. First create a temp table or table variable that holds the rows from STUDENT where startDate and endDate is correct (use ISDATE for this) and then use that table in your actual query.