Esper decorate events based on event property value - esper

I'm new to Esper and have the following question. Is it possible to decorate an event property based on the value of another property.
For example when in the below example the status property has the value cleared I want a different string value for notification then when the status property is empty. Is this possible?
I have the following statement:
create schema IT(host string, status string, severity string, notification string);
#Name('Out') insert into OutputAlerts
select host, severity, status, 'Test value' as notification from IT where host regexp '(?i)SERVER1' AND severity regexp '(?i)critical'
And the following events:
IT={host='SERVER1', severity='Critical', status='cleared'}
IT={host='SERVER1', severity='Critical', status=''}

The "case" can do this in SQL 92.
Doc link http://espertech.com/esper/release-5.3.0/esper-reference/html_single/index.html#epl-single-row-function-ref-case
select (case when status is null or status.length() = 0 then "empty" else "nonempty") as notification from ...

Related

Snowflake Procedure (Assigning a value to the Variable in Task)

Would you please tell me how to assign a value to the variable on the Task? Here's the detailed scenario of what I'm trying to accomplish and what the error is.
To get the latest query_id of the below SQL statement, I am creating the following function.
CREATE OR REPLACE FUNCTION rejected_records_queryid()
RETURNS varchar
AS 'select query_id from snowflake.account_usage.query_history where QUERY_TEXT LIKE \'select 1, 2%\' AND EXECUTION_STATUS=\'SUCCESS\' order by START_TIME desc limit 1';
If I run this manually, the function works perfectly,
set qid = rejected_records_queryid();
Session variable value:
select $qid;
Please refer attached screenshot for the output.
Pic1
However, if I use the Task, the return values of the function will not be assigned to the session variable,
CREATE OR REPLACE TASK rejected_records_queryid1
WAREHOUSE = COMPUTE_WH
SCHEDULE = '1 MINUTE'
AS
set qid2 = rejected_records_queryid();
Change the task mode to resume,
ALTER TASK rejected_records_queryid1 RESUME;
The following error message appears after I check the value of the qid2 after Task run,
SQL compilation error: error line 1 at position 7 Session variable '$QID2' does not exist
Attached screenshot for the error message In order to use it in the below sql, I need the qid2 value to be assigned from the Task,
select * from table(result_scan($qid2))
Pic2
I would appreciate any help on how to assign the value to the variable in TASK or any other workarounds.

Query field using variable

I am writing a stored procedure where I want to pass in the field name and data then in the procedure use the field name to reference to field to insert / update:
BEGIN
INSERT INTO trainees (txtTrainee, _field) VALUES (_txtTrainee, _data)
ON DUPLICATE KEY UPDAYE _field=VALUES(_field);
END
The parameters passed into the procedure are:
_txtTrainee, this is a TEXT field and contains the host name to use
_field, this is a TEXT field and contains the field name to modify
_data, this is a VARCHAR(16) and contains the data to insert or update
I can see I need some kind of translation function to get the contents of _field.
I'm using MariaDB 10.8
The solution is to use a prepared statement:
BEGIN
SET #SQL = CONCAT("INSERT INTO trainees (txtTrainee,?)",
"VALUES(?,?)",
"ON DUPLICATE KEY UPDATE ?=VALUES(?)");
PREPARE stmt FROM #SQL;
EXECUTE stmt USING _field,_txtTrainee,_data,_field,_field;
END

How to write a SELECT for a field of type "quantity" in SET_GET_ENTITY method?

I want to select a single row with all columns from my table zbookings. zbookings table has a structure based on zbooking data structure - see tables below.
Table ZBOOKINGS:
Structure ZBOOKING:
My BOOKINGSET_GET_ENTITY method:
method BOOKINGSET_GET_ENTITY.
DATA: ls_keytab TYPE LINE OF /IWBEP/T_MGW_NAME_VALUE_PAIR,
i_carrid TYPE string,
i_connid TYPE string,
i_fldate TYPE string,
i_bookid TYPE string.
LOOP AT it_key_tab INTO ls_keytab.
CASE ls_keytab-name.
WHEN 'Carrid'.
i_carrid = ls_keytab-value.
WHEN 'Connid'.
i_connid = ls_keytab-value.
WHEN 'Fldate'.
i_fldate = ls_keytab-value.
WHEN 'Bookid'.
i_bookid = ls_keytab-value.
ENDCASE.
ENDLOOP.
SELECT SINGLE *
INTO CORRESPONDING FIELDS OF er_entity
FROM ybookings AS a
WHERE
a~carrid = i_carrid AND
a~connid = i_connid AND
a~fldate = i_fldate AND
a~bookid = i_bookid.
endmethod.
I tested it via SAP Gateway Client. It's OK when I remove column luggweight from my SELECT SINGLE * statement. However when I select all columns via SELECT SINGLE *, then it outputs an error
Runtime Error: 'SAPSQL_PARSER_TODO_WARNING'`
<?xml version="1.0" encoding="UTF-8"?>
<error>
<code>SAPSQL_PARSER_TODO_WARNING</code>
<message>Runtime Error: 'SAPSQL_PARSER_TODO_WARNING'.
The OData request processing has been abnormal terminated. If "Runtime Error"
is not initial, launch transaction ST22 for details and analysis. Otherwise,
launch transaction SM21 for system log analysis.</message>
<timestamp>20190905144432</timestamp>
</error>
As you can see the problem is with luggweight field which is of quantity type and its typing method is Type ref to. When I check my BOOKINGSET_GET_ENTITY method via ctr+F2 it outputs a warning:
The database field or the result type of the aggregate function LUGGWEIGHT and the component "LUGGWEIGHT" of "ER_ENTITY" are not compatible.
How should I modify my SELECT query / BOOKINGSET_GET_ENTITY method for it to work?
Luggweight field's typing method should be set to Types (not Type ref to) when creating / modifying zbooking data structure.

When I run sql query there is no alert

This code insert the record into the basetable without alert.
CurrentDb.Execute _
"INSERT INTO basetable(clName,clId,clGender) VALUES('test','123','');"
I expected this code should pop alert up because the clGender field set to be "required", but no alert. Could you please tell me where I was wrong.
You can use:
DoCmd.RunSQL " Insert ... "
though that may be too much.
The reason you didn't get an alert is because you supplied a value for clGender. In table design view there are two relevant properties: Required and Allow zero length. Your clGender field has both of these set to true. The Required setting means that you can't save the record with this field as Null but in your insert statement you haven't specified Null, you've specified an empty string, which is allowed by the Allow zero length setting.
[EDIT]
Sorry, just realised what's going on. The Execute method doesn't give you any feedback directly. However you can use the RecordsAffected property to see if it did what you expected.
Dim db As DAO.Database
Set db = CurrentDb()
db.Execute "INSERT INTO basetable(clName,clId,clGender) VALUES('test','123','')"
If db.RecordsAffected = 0 Then
MsgBox "Insert failed"
End If
Set db = Nothing

How to retrieve a value from a recordset that is not a return value or output parameter using vb6

I have a stored proc on an existing 3rd party application (SQL 2005) that I wish to interact with.
It is an insert statement followed by a select statement as follows;
Set #CustomerId = Cast(SCOPE_IDENTITY() As [int])
Select #CustomerId
Using VB6 how do I access the value of #CustomerID?
set rs = cmd.Execute
is not returning a resultset as expected...
[Edit]
rs.Fields.Count is 0.
Any attempt to access the resulting recordset, like rs(0).Value simply causes an "Item not found..." error.
I would guess that your stored procedure is returning more than one recordset.
If this is the case, you can use the NextRecordset() method to iterate through them.
MSDN:
If a row-returning command executes successfully but returns no records,
the returned Recordset object will be
open but empty. Test for this case by
verifying that the BOF and EOF
properties are both True.
If a non–row-returning command executes successfully, the returned
Recordset object will be closed, which
you can verify by testing the State
property on the Recordset.
When there are no more results, recordset will be set to Nothing.
This means I would suggest something like this to solve your problem:
Set rs = cmd.Execute
''# fetch the first value of the last recordset
Do Until rs Is Nothing
If rs.State = adStateOpen Then
If Not (rs.BOF And rs.EOF) Then
''# You can do a different sanity check here, or none at all
If rs.Fields(0).Type = adInteger Then
CustomerId = rs.Fields(0).Value
End If
End If
End If
Set rs = rs.NextRecordSet
Loop
MsgBox CustomerId

Resources