I am using below execution plan to populate my hazelcast backed event table.
Problem is, how can I reuse this existing hazelcast backed event table from another execution plan ?
It is a followup question for another similar question.
#Import('users:1.0.0')
define stream users (meta_name string, correlation_id int);
#from(eventtable = 'hazelcast', cluster.name = 'cluster_a', cluster.password = 'pass#cluster_a')
define table UserTable (name string, id int) ;
from users
select meta_name as name, correlation_id as id
insert OVERWRITE UserTable
on UserTable.id == id;
You can use same collection.name in both execution plans. You don't need to use cluster.name and cluster.password. Refer to following example;
Execution Plan 1
#Plan:name('TestIn')
#Import('dataIn:1.0.0')
define stream dataIn (id int, name string);
#from(eventtable = 'hazelcast', collection.name='hzTable')
define table hzTable (id int, name string);
from dataIn
insert into hzTable;
Execution Plan 2
#Plan:name('TestOut')
#Export('dataOut:1.0.0')
define stream dataOut (id int, name string);
#from(eventtable = 'hazelcast', collection.name='hzTable')
define table hzTable (id int, name string);
define trigger periodicTrigger at every 2 sec;
from periodicTrigger join hzTable
select hzTable.id as id, hzTable.name as name
insert into dataOut;
Related
The code i'm using is like this
CREATE TABLE EMPLOYEE (
empId INTEGER PRIMARY KEY,
username TEXT NOT NULL,
userrole TEXT NOT NULL,
roles TEXT NOT NULL,
accesses TEXT NOT NULL
);
INSERT INTO EMPLOYEE VALUES (0001, 'Clark','President', 'Admin','privileged');
INSERT INTO EMPLOYEE VALUES (0002, 'Dave','sales rep', 'Operational role','not privileged');
INSERT INTO EMPLOYEE VALUES (0003, 'Ava','finance manager', 'Managerial role','privileged');
SELECT * FROM EMPLOYEE;
ALTER TABLE EMPLOYEE
ADD COLUMN permissions VARCHAR;
DO
$do$
BEGIN
IF EMPLOYEE.roles='Admin' THEN
IF EMPLOYEE.accesses='privileged' THEN
SET permissions = 'GRANTED';
else
IF EMPLOYEE.roles='Operational role' THEN
IF EMPLOYEE.accesses='not privileged' THEN
SET permissions = 'GRANTED';
else
IF EMPLOYEE.roles='Managerial role' THEN
IF EMPLOYEE.accesses='not privileged' THEN
SET permissions = 'GRANTED';
else
SET permissions = 'REVOKED';
END IF;
END
$do$;
SELECT * FROM EMPLOYEE;
Do you need in this:
SELECT *,
CASE WHEN (roles, accesses) IN ( ('Admin','privileged'),
('Operational role','not privileged'),
('Managerial role','not privileged') )
THEN 'GRANTED'
ELSE 'REVOKED'
END AS permissions
FROM employee;
?
Given a given MySQL table
DESC tabl_foo;
--------------------------------
Field Type Null Key Default Extra
-----------------------------------------------------------------
fooId varchar(15) NO PRI NULL
FooDate date YES MUL NULL
I need to update FooDate for a given row. So I tried this code :
query->SQL->Add("UPDATE tbl_foo SET FooDate = :FooDate WHERE fooId = :id"):
// both arguments are AnsiString
query->Parameters->FindParam("id")->Value = FoodId;
query->Parameters->FindParam("FooDate")->Value = FooDate;
query->ExecSQL();
However, this fails
Incorrect date value: "" for folumn FooDate at row 1
It turns out that FooDate may be an empty string (or { data:NULL }), and MySQL does not like that. So, I tried setting Null() :
if (FooDate.IsEmpty())
query->Parameters->FindParam("FooDate")->Value = Null();
else
query->Parameters->FindParam("FooDate")->Value = FooDate;
But then I get this error :
Parameter object is improperly defined. Inconsistent or incomplete information was provided.
What should be the value to set for MySQL NULL?
To make the update the system needs to know the types of the parameters. It can deduce the type from the variant you apply, and MySQL can do certain conversions for you, but it's always best to specify the data type.
So what you would need is something like:
if((pParam=query->Parameters->FindParam("FooDate"))!=NULL)
{
pParam->DataType=ftDate;
if(FooDate.IsEmpty())
{
pParam->Value=Null();
}
else
{
pParam->Value=FooDate;
}
}
You may want to look at keeping FooDate as a TDateTime, but you will need to detect NULL dates properly.
I have created a student table in .cpp.
static const char student[] = R"sql(
CREATE TABLE if not exists student(
id VARCHAR(44) NOT NULL,
name varchar NOT NULL,
);
)sql";
I am adding some data in this table from another class. I know data has been added to this table, but I want to print all value from this table for verification.
then I write this statement,
static const char print_student[]="select * from student";
how can I print student table' data in CPP? I am using sqlite3 db.
Trying to update table by user specified values. But the values are not getting updated.
cout<<"\nEnter Ac No"<<endl;
cin>>ac;
cout<<"\nEnter Amount"<<endl;
cin>>amt;
/* Create merged SQL statement */
sql = "UPDATE RECORDS set BAL = '%d' where ACCOUNT_NO = '%d'",amt, ac;
/* Execute SQL statement */
rc = sqlite3_exec(db, sql, callback, (void*)data, &zErrMsg);
If I replace BAL and ACCOUNT_NO by some integer value instead of place holder then it is working fine.
Your sql string is not being created properly.
If you expect this code
sql = "UPDATE RECORDS set BAL = '%d' where ACCOUNT_NO = '%d'",amt, ac;
to result in
"UPDATE RECORDS set BAL = '1' where ACCOUNT_NO = '2'"
where
amt= 1 and ac = 2 then you need to use a string formatting call like this.
// the buffer where your sql statement will live
char sql[1024];
// write the SQL statment with values into the buffer
_snprintf(sql,sizeof(sql)-1, "UPDATE RECORDS set BAL = '%d' where ACCOUNT_NO = '%d'",amt, ac);
buff[sizeof(sql)-1]='\0';
On your particular platform _snprintf(...) might be snprintf(..) or another similarly named function. Also your compiler may warn about buffer manipulation security vulnerabilities. Choose the appropriate substitute for your needs
I have Items class:
#Entity
#Table(name ="Items")
Class Items{
#ID
private long id;
private String upc;
private long itemNo;
private int qty;
-----
}
I need to make below sql statement from JPAQuery of QueryDSL.
select itemNo, upc, count(*) t from Items group by ITEM_NO, UPC order by t;
QueryDSL sample needs modification for order by clause:
QItems items = QItems.items;
query.from(items)
.groupBy(items.itemNo,items.upc)
.orderby(<Dont Know How to sort on count>).list(items.itemNo,items.upc,items.count());
Need help to draft this query properly?
This should work
NumberPath<Long> count = Expressions.numberPath(Long.class, "c");
QItems items = QItems.items;
query.from(items)
.groupBy(items.itemNo,items.upc)
.orderby(count.asc())
.list(items.itemNo,items.upc,items.count().as(count));