Handling null values with wso2 CEP - wso2

I want to update event table (RDBMS) using additional condition that one column in that is not null. Table name is MSISDNProfileDB and it's in oracle db.
from incomingStream#window.length(1)
select correlation_MSISDN as MSISDN,
INTERACTION_DT as INTERACTION_DT
update MSISDNProfileDB
on MSISDNProfileDB.MSISDN == MSISDN
and not(MSISDNProfileDB.column1 is null);
it validates the code, but does not update INTERACTION_DT. For testing purposes, I changed it to check if the column is null, and manually remove data from column1.
from incomingStream#window.length(1)
select correlation_MSISDN as MSISDN,
INTERACTION_DT as INTERACTION_DT
update MSISDNProfileDB
on MSISDNProfileDB.MSISDN == MSISDN
and MSISDNProfileDB.column1 is null;
...and it still doesnt work. But when I change column value to 1 and do this:
from incomingStream#window.length(1)
select correlation_MSISDN as MSISDN,
INTERACTION_DT as INTERACTION_DT
update MSISDNProfileDB
on MSISDNProfileDB.MSISDN == MSISDN
and MSISDNProfileDB.column1 == '1';
it works! So, conclusion is that cep has problem with null values from oracle db. Does anyone knows how are null values handled?
Kind Regards,
Stefan

I came across a similar problem with MySQL. The issue seems to be in the way CEP parse Siddhi query into SQL. I did a quick fix for that, and it worked for my scenario. It should work in your case too, but haven't tested with Oracle though. To use the fix (assuming you are using CEP 4.2.0);
Delete siddhi-extension-event-table_3.1.2.jar from <cep>/repository/components/plugins/ directory.
Add compiled jar to <cep>/repository/components/lib/ diectory.
Use following query;
from incomingStream
select
correlation_MSISDN as MSISDN,
INTERACTION_DT as INTERACTION_DT
update MSISDNProfileDB
on MSISDNProfileDB.MSISDN == MSISDN and not (MSISDNProfileDB.column1 is null);

Related

Code (using Patch function) to save update from PowerApps to SQL table not working

this is my code in PowerApps:
OnSelect = Patch(ProjectTrackerPowerApps, {ProjectTrackerID: First([#PowerBIIntegration].Data).ProjectTrackerID, 'Meeting Notes':TextInput1.Text } )
where ProjectTrackerPowerApps is the SQL table name, and "Meeting Notes" is the field in PowerApps that is being edited and the edits are to be read back to the SQL table using the OnSelect Code.
But it's not working, i.e. I don't see the changes in the SQL table.
I also tried this other code - slightly different than the 1st but it also didn't work:
OnSelect = Patch(ProjectTrackerPowerApps, defaults(ProjectTrackerPowerApps), {Field:Screen1.Selected.ProjectTrackerID})
Can you please review the code and help me correct so it works?
Thanks!

Need to apply filter on using OR condition

I have Dataset in PowerBI as below.
In PowerBI Desktop I want to filter records of below table based on condition described below.
ProjectName ReleaseDate UserReleaseDate
PROJ-1 12/09/2019 null
PROJ-2 null 02/02/2019
PROJ-3 07/07/2018 null
Date are in DD/MM/YYYY format.
I want to filter those records where
(ReleaseDate OR UserReleaseDate is IsInNextNYears(1))
You pretty much just do exactly what you described.
Table.SelectRows(YourTable, each (Date.IsInNextNYears([ReleaseDate], 1) or Date.IsInNextNYears([UserReleaseDate], 1)))
If you use any filter operation on a column in Power Query it will automatically create a Table.SelectRows step that you can edit to do what you want instead.

Query to replace specific date range in a column

I have a table that houses information uploaded from a template (via another application). Well i noticed that the year was wrong (code in the application issue) and caused about 3000 lines of incorrect dates. My question is, how would i write a query to replace all the 20150101 (incorrect date) with 20160101 (correct date)? I am pretty sure its the UPDATE routine but i am not a SQL programmer so i am a tad lost. I am using latest SSMS.
Table: TRANS_USER_FORECAST_EDITS_FROM_EXCEL
Column Name: mo_day_year
DO A SELECT FIRST TO SEE HOW MANY RECORD YOU NEED TO UPDATE..
SELECT * FROM TRANS_USER_FORECAST_EDITS_FROM_EXCEL
WHERE mo_day_year = '20150101'
THEN COPY YOUR RESULT AND RUN THE QUERY BELOW TO UPDATE ALL THE RECORDS.
BEGIN TRAN
UPDATE TRANS_USER_FORECAST_EDITS_FROM_EXCEL SET mo_day_year = '20160101'
WHERE mo_day_year = '20150101'
COMMIT
As you noted, it's indeed an update statement:
UPDATE TRANS_USER_FORECAST_EDITS_FROM_EXCEL
SET mo_day_year = 20150101
WHERE mo_day_year = 20160101

updating DATETIME causes sqlite error on BB10

I created my table with this query
CREATE TABLE SETTINGS(NAME VARCHAR(1050), VALUE VARCHAR(1550),CREATE_DATE_TIME DATETIME,UPDATE_DATE_TIME DATETIME, PRIMARY KEY(NAME))
Then I inserted data like this
INSERT INTO SETTINGS(NAME, VALUE ,CREATE_DATE_TIME ,UPDATE_DATE_TIME) VALUES('CellIDKey','Android#MoblLe.NAv',DATETIME('NOW'), DATETIME('NOW'))
At this point it works fine. Now if I want to run an update query like this,
UPDATE SETTINGS SET VALUE='Android#AfriG1s.MoblLe.NAv' CREATE_DATE_TIME=DATETIME('NOW') WHERE NAME='CellIDKey'
It shows the following error on console
QSqlError::type= "QSqlError::ConnectionError" , QSqlError::number= -1 , databaseText= "No query" , driverText= "Unable to fetch row"
But if I run this update query like this,
UPDATE SETTINGS SET VALUE='Android#AfriG1s.MoblLe.NAv' WHERE NAME='CellIDKey'
Now it works fine. I don't know what is wrong with the DATETIME('NOW') statement on update query.
This is not valid SQL:
UPDATE SETTINGS SET VALUE='Android#AfriG1s.MoblLe.NAv' CREATE_DATE_TIME=DATETIME('NOW') WHERE NAME='CellIDKey'
-- ---------------------------------------------------^ Missing comma!
The individual assignments in a SET need to be separated by commas like this:
UPDATE SETTINGS
SET VALUE='Android#AfriG1s.MoblLe.NAv', -- This comma is needed
CREATE_DATE_TIME=DATETIME('NOW')
WHERE NAME='CellIDKey'

Doctrine2 - use fulltext and MyIsam

I am building an app in Symfony2, using Doctrine2 with mysql. I would like to use a fulltext search. I can't find much on how to implement this - right now I'm stuck on how to set the table engine to myisam.
It seems that it's not possible to set the table type using annotations. Also, if I did it manually by running an "ALTER TABLE" query, I'm not sure if Doctrine2 will continue to work properly - does it depend on the InnoDB foreign keys?
Is there a better place to ask these questions?
INTRODUCTION
Doctrine2 uses InnoDB which supports Foreign Keys used in Doctrine associations. But as MyISAM does not support this yet, you can not use MyISAM to manage Doctrine Entities.
On the other side, MySQL v5.6, currently in development, will bring the support of InnoDB FTS and so will enable the Full-Text search in InnoDB tables.
SOLUTIONS
So there are two solutions :
Using the MySQL v5.6 at your own risks and hacking a bit Doctrine to implement a MATCH AGAINST method : link in french... (I could translate if needed but there still are bugs and I would not recommend this solution)
As described by quickshifti, creating a MyISAM table with fulltext index just to perform the search on. As Doctrine2 allows native SQL requests and as you can map this request to an entity (details here).
EXAMPLE FOR THE 2nd SOLUTION
Consider the following tables :
table 'user' : InnoDB [id, name, email]
table 'search_user : MyISAM [user_id, name -> FULLTEXT]
Then you just have to write a search request with a JOIN and mapping (in a repository) :
<?php
public function searchUser($string) {
// 1. Mapping
$rsm = new ResultSetMapping();
$rsm->addEntityResult('Acme\DefaultBundle\Entity\User', 'u');
$rsm->addFieldResult('u', 'id', 'id');
$rsm->addFieldResult('u', 'name', 'name');
$rsm->addFieldResult('u', 'email', 'email');
// 2. Native SQL
$sql = 'SELECT u.id, u.name FROM search_user AS s JOIN user AS u ON s.user_id = u.id WHERE MATCH(s.name) AGAINST($string IN BOOLEAN MODE)> 0;
// 3. Run the query
$query = $this->_em->createNativeQuery($sql, $rsm);
// 4. Get the results as Entities !
$results = $query->getResult();
return $results;
}
?>
But the FULLTEXT index needs to stay up-to-date. Instead of using a cron task, you can add triggers (INSERT, UPDATE and DELETE) like this :
CREATE TRIGGER trigger_insert_search_user
AFTER INSERT ON user
FOR EACH ROW
INSERT INTO search_user SET user_id=NEW.id, name=NEW.name;
CREATE TRIGGER trigger_update_search_user
AFTER UPDATE ON user
FOR EACH ROW
UPDATE search_user SET name=name WHERE user_id=OLD.id;
CREATE TRIGGER trigger_delete_search_user
AFTER DELETE ON user
FOR EACH ROW
DELETE FROM search_user WHERE user_id=OLD.id;
So that your search_user table will always get the last changes.
Of course, this is just an example, I wanted to keep it simple, and I know this query could be done with a LIKE.
Doctrine ditched the fulltext Searchable feature from v1 on the move to Doctrine2. You will likely have to roll your own support for a fulltext search in Doctrine2.
I'm considering using migrations to generate the tables themselves, running the search queries w/ the native SQL query option to get sets of ids that refer to tables managed by Doctrine, then using said sets of ids to hydrate records normally through Doctrine.
Will probly cron something periodic to update the fulltext tables.