Thursday, 9 January 2014

string manupulation functions in ESQL

ESQL string manipulation functions

A list of the ESQL string manipulation functions that you can use.
Most of the following functions manipulate all string data types (BIT, BLOB, and CHARACTER). Exceptions to this are UPPER, LOWER, LCASE, UCASE, and SPACE, which operate only on character strings.
In these descriptions, the term singleton refers to a single part (BIT, BLOB, or CHARACTER) within a string of that type.
In addition to the functions that are described here, you can use the logical OR operator to perform various calculations on ESQL string manipulation values.
To concatenate two strings, use the ESQL string operator.
This section covers the following topics:
CONTAINS function

ENDSWITH function

LEFT function

LENGTH function

LOWER and LCASE functions

LTRIM function

OVERLAY function

POSITION function

REPLACE function

REPLICATE function

RIGHT function

RTRIM function

SPACE function

STARTSWITH function

SUBSTRING function

TRANSLATE function

TRIM function

UPPER and UCASE functions

NAME and NAMESPACE



NAME
Use NAME to define an alias (an alternative name) by which a variable can be known.
Example 1:
-- The following statement gives Schema1 an alias of 'Joe'.
DECLARE Schema1 NAME 'Joe'; 
-- The following statement produces a field called 'Joe'.
SET OutputRoot.XMLNS.Data.Schema1 = 42;

-- The following statement inserts a value into a table called Table1
-- in the schema called 'Joe'.
INSERT INTO Database.Schema1.Table1 (Answer) VALUES 42;
Example 2:
-- At Module scope define ColourElementName and set it external
-- so that its default value of 'black' can be overridden as a UDP 
DECLARE ColourElementName EXTERNAL NAME 'black';


-- Use the ColourElementName in a function
CREATE FIRSTCHILD OF OutputRoot.XMLNSC.TestCase.ColourElementName
                     Domain('XMLNSC')
                     NAME 'Node1' VALUE '1';
If the owning message flow has been configured with a UDP named ColourElementName of type String, which has been given the value red, the following output message is generated:
<xml version="1.0"?>
<TestCase>
  <red>
    <Node1>1</Node1>
  </red>
NAMESPACE
Use NAMESPACE to define an alias (an alternative name) by which a namespace can be known.
Example:
This example illustrates a namespace declaration, its use as a SpaceId in a path, and its use as a character constant in a namespace expression:
       DECLARE prefixOne NAMESPACE 'http://www.example.com/PO1';

       -- On the right hand side of the assignment a namespace constant
       -- is being used as such while, on the left hand side, one is
       -- being used as an ordinary constant (that is, in an expression).

       SET OutputRoot.XMLNS.{prefixOne}:{'PurchaseOrder'} =
                      InputRoot.XMLNS.prefixOne:PurchaseOrder;
SHARED
Use SHARED to define a shared variable. Shared variables are private to the flow (if declared within a schema) or node (if declared within a module), but are shared between instances of the flow (threads). No type of variable is visible beyond the flow level; for example, you cannot share variables across execution groups.
You can use shared variables to implement an in-memory cache in the message flow; see Optimizing message flow response times. Shared variables have a long lifetime and are visible to multiple messages passing through a flow; see Long-lived variables.
Shared variables exist for the lifetime of the:
  • Execution group process
  • Flow or node, or
  • Node ESQL code that declares the variable
(whichever is the shortest). They are initialized when the first message passes through the flow or node after each broker startup.
You cannot define a shared variable within a function or procedure.
The advantages of shared variables, relative to databases, are that:
  • Write access is much faster.
  • Read access to small data structures is faster.
  • Access is direct; that is, there is no need to use a special function (SELECT) to get data, or special statements (INSERT, UPDATE, or DELETE) to modify data. You can refer to the data directly in expressions.
The advantages of databases, relative to shared variables, are that:
  • The data is persistent.
  • The data is changed transactionally.
These read-write variables are ideal for users who are prepared to sacrifice the persistence and transactional advantages of databases in order to obtain better performance, because they have a longer life than only one message and perform better than a database.
Because SHARED variables can be updated by multiple additional instances, you must ensure that you do not change SHARED variables that might cause unexpected results, for example, if the variable is being used as a counter.
As SHARED variables are initialized once on the first message through a node, it is possible to initialize a SHARED ROW variable once with the results from a Database query. The following code shows an example of this:
      CREATE SCHEMA testSchema
         DECLARE mySharedRow SHARED ROW;
         DECLARE initialized SHARED BOOLEAN myINIT();
 
         CREATE COMPUTE MODULE testModule
       
         CREATE FUNCTION Main() RETURNS BOOLEAN
         BEGIN
         SET OutputRoot.XMLNSC.Top.TEST.Result1 VALUE = initialized;
         SET OutputRoot.XMLNSC.Top.TEST.Result2 = mySharedRow;
       END;

     END MODULE;

     CREATE FUNCTION myINIT( ) RETURNS BOOLEAN
     BEGIN
         LOG EVENT VALUES('myINIT CALLED');
         SET mySharedRow.Top[] = SELECT A.MyCol1, A.MyCol2 from Database.Test AS A;
         RETURN TRUE;
     END;
You can prevent other instances seeing the intermediate stages of the data by using a BEGIN ATOMIC construct; see BEGIN ... END statement.
Your user program can make an efficient read, or write, copy of an input message in the input node by using shared-row variables, which simplifies the technique for handling large messages.
Restriction:
Subtrees cannot be copied directly from one shared row variable to another shared row variable. Subtrees can be copied indirectly by using a non-shared row variable. Scalar values extracted from one shared row variable (by using the FIELDVALUE function) can be copied to another shared row variable.

Tuesday, 7 January 2014

What is the difference between Return true & Return false?

return statements in esql code RETURN;
RETURN TRUE;
RETURN FALSE;
RETURN UNKNOWN;
RETURN ((priceTotal / numItems) > 42);


RETURN TRUE:
1- Propagate message to Out terminal(in case of compute and database nodes).
2- Propagate message to True terminal in case of FILTER node

RETURN FALSE: 
Stop propagation (compute node and database node) & 
Propagate message to False terminal (FILTER NODE) 

RETURN UNKNOWN: 
Propagate message to Unknown terminal OF FILTER NODE.
 

how to implement Request reply scenario in MQ?

In this scenario, the connector sends a message from the input link to the request queue, and then blocks and waits for the corresponding reply message on the reply queue. The connector repeats this procedure for all messages that arrive on the input link when the job runs. 
MQINPUT 
Creates a request message.
Sends the request message to the target queue Opens the 

MQOUT 
Target Queue in the Reply to queue property(set the property REPLY_TO_QUEUE).
Issues a call to receive the reply messages when the message identifier of the request message matches the correlation identifier of the reply message.

How to handle & find the error from cache terminal, how to catch the exception? After finding the error, where the error will get stored? How to check the Error in Analog?



If any exception happens in any of the node in a flow and the failure for that particular node is not wired , then the Exception will be reported back to the previous node in the flow which is having a catch terminal . So , you need to handle(by default it will not get stored any where. It will be available in the ExceptionList of the generated tree structure) that exception list by wiring the catch terminal as per your requirement and send back the proper error response to the service requester. The generated Exception list can be observed if you can have a debug launched.