ASG
IBM
Zystems
Cressida
Icon
Netflexity
 
  MQSeries.net
Search  Search       Tech Exchange      Education      Certifications      Library      Info Center      SupportPacs      LinkedIn  Search  Search                                                                   FAQ  FAQ   Usergroups  Usergroups
 
Register  ::  Log in Log in to check your private messages
 
RSS Feed - WebSphere MQ Support RSS Feed - Message Broker Support

MQSeries.net Forum Index » WebSphere Message Broker (ACE) Support » Query in esql

Post new topic  Reply to topic Goto page 1, 2  Next
 Query in esql « View previous topic :: View next topic » 
Author Message
PRKUMAR
PostPosted: Tue Jan 21, 2014 8:11 am    Post subject: Query in esql Reply with quote

Apprentice

Joined: 04 Sep 2012
Posts: 36

There is an XML message like below:
<Industry>
<Department id='01'></Department>
<Department id='02'></Department>
<Department id='03'></Department>
<Department id='04'></Department>
</Industry>
I would like to know the occurrence number of Department in <Industry> where id = '03'. In the above example, the occurrence number is 3( 3rd child)
I can do this using esql like below:

SET deptCount = CARDINALITY(InputRoot.XMLNSC.Industry.Department[]);
SET deptIndex = 1;
D: WHILE( deptIndex <= deptCount) DO
IF (Industry.Department.(XMLNSC.Attribute)id = '3') THEN
LEAVE D;
END IF;
SET deptIndex = deptIndex + 1;
END WHILE;

Now, deptIndex contains value as '3'.
Is there any function available or using SELECT statement can we retrieve this value ? instead of writing the code like above?
Please help me in minimizing the above process.
Code:
Back to top
View user's profile Send private message
Vitor
PostPosted: Tue Jan 21, 2014 9:06 am    Post subject: Re: Query in esql Reply with quote

Grand High Poobah

Joined: 11 Nov 2005
Posts: 26093
Location: Texas, USA

PRKUMAR wrote:

I would like to know the occurrence number of Department in <Industry> where id = '03'. In the above example, the occurrence number is 3( 3rd child)


Why? What business value does that give you? The only valid reason for knowing what the index has is to allow you to access the data in that child, and SELECT does that.
_________________
Honesty is the best policy.
Insanity is the best defence.
Back to top
View user's profile Send private message
PRKUMAR
PostPosted: Tue Jan 21, 2014 10:33 am    Post subject: Reply with quote

Apprentice

Joined: 04 Sep 2012
Posts: 36

Hi Vitor,
First of all thanks for your response.
The business value is something more than I specified above. I have given just brief info only. I am getting input as CSV file having more than 500 records. I need to construct a single output XML message having four departments having id's ranging from 1 to 4. The input csv records may not come in particular order. Based on some value of input csv record, i need to map the record elements to one of the department. In this scenario, I am looking for a simpler kind of logic for to find particular department.
Input: CSV, Output: XML, MB Version: 8.0.0.1
Back to top
View user's profile Send private message
Vitor
PostPosted: Tue Jan 21, 2014 11:18 am    Post subject: Reply with quote

Grand High Poobah

Joined: 11 Nov 2005
Posts: 26093
Location: Texas, USA

PRKUMAR wrote:
In this scenario, I am looking for a simpler kind of logic for to find particular department.


Which is exactly the scenario I postulated above, as it's the most common reason people think they need an index.

So what you are trying to do is SELECT the element where the attibute has a given value (3 in your example) and process the data associated with it (presumably in the format of child elements).

Notice how I've put the solution in CAPS
_________________
Honesty is the best policy.
Insanity is the best defence.
Back to top
View user's profile Send private message
dogorsy
PostPosted: Wed Jan 22, 2014 2:03 am    Post subject: Reply with quote

Knight

Joined: 13 Mar 2013
Posts: 553
Location: Home Office

According to your original post, your input is an XML message. Subsequently you said it is a CSV file with more than 500 records. If you are not clear about what your input is, it is extremely difficult to find a solution , either by yourself or anyone in this forum.

If your input is a CSV file, then probably you will be reading one record at a time. You may also want to read the whole file, but that needs to be decided by you, and will affect the logic in your compute node.
Back to top
View user's profile Send private message
kimbert
PostPosted: Wed Jan 22, 2014 3:18 am    Post subject: Reply with quote

Jedi Council

Joined: 29 Jul 2003
Posts: 5542
Location: Southampton

The simplest solution is four SELECT statements ( one per department ).

That will only work if you are reading the entire file. If you need to process the file one record at a time ( in order to keep memory usage nice and low ) then you will need to build up the output one record at a time.

Either way, I don't think it will help to know the index of a particular array element. If you want to construct OutputRoot.XMLNSC field-by-field then you could maintain four REFERENCE variables and use CREATE NEXTSIBLING statements to append records to each output array.
_________________
Before you criticize someone, walk a mile in their shoes. That way you're a mile away, and you have their shoes too.
Back to top
View user's profile Send private message
mqsiuser
PostPosted: Thu Jan 23, 2014 6:45 am    Post subject: Re: Query in esql Reply with quote

Yatiri

Joined: 15 Apr 2008
Posts: 637
Location: Germany

PRKUMAR wrote:
There is an XML message like below:
<Industry>
<Department id='01'></Department>
<Department id='02'></Department>
<Department id='03'></Department>
<Department id='04'></Department>
</Industry>

Is there any function available or using SELECT statement can we retrieve this value ? instead of writing the code like above?


I guess you want to get to that element... and you shouldn't do that by getting it's index (with CARDINALITY) and then accessing it (by using INDEX ("Department[3]")... you can, but there are other ways, which result in a significant better performance!
Also quering (with SELECT ...) may (does likely) reduce performance. Quering is great when working with databases, but not for message transformation.
I guess it gets applied too often (for msg transformation), because people know it from databases (you may know it from there).

You can use "myOutStructure.{id}.myField" or write custom code (using references, as kimbert suggests) or probably by "moving to it (on the output root) based on a condition (or create, when missing)". Your condition is that "id is equal to something (e.g. 01, 02, 03, 04, ...)".
_________________
Just use REFERENCEs
Back to top
View user's profile Send private message
Vitor
PostPosted: Thu Jan 23, 2014 6:59 am    Post subject: Re: Query in esql Reply with quote

Grand High Poobah

Joined: 11 Nov 2005
Posts: 26093
Location: Texas, USA

mqsiuser wrote:
Also quering (with SELECT ...) may (does likely) reduce performance. Quering is great when working with databases, but not for message transformation.


Cite your sources.

SELECT (as provided by WMB) is built for handling a message tree and is highly performant.
_________________
Honesty is the best policy.
Insanity is the best defence.
Back to top
View user's profile Send private message
dogorsy
PostPosted: Thu Jan 23, 2014 7:01 am    Post subject: Re: Query in esql Reply with quote

Knight

Joined: 13 Mar 2013
Posts: 553
Location: Home Office

mqsiuser wrote:

Also quering (with SELECT ...) may (does likely) reduce performance.

Pardon me ?!!... can you justify that ?!
Back to top
View user's profile Send private message
mqsiuser
PostPosted: Thu Jan 23, 2014 7:46 am    Post subject: Reply with quote

Yatiri

Joined: 15 Apr 2008
Posts: 637
Location: Germany

Ah, sorry, it is "if you repeatedly query your input-message (to build the/one output msg), then this will (likely) reduce performance".

If you manage to build your output based on a single SELECT-clause, bravo , then it's like vitor says !
_________________
Just use REFERENCEs
Back to top
View user's profile Send private message
dogorsy
PostPosted: Thu Jan 23, 2014 7:51 am    Post subject: Reply with quote

Knight

Joined: 13 Mar 2013
Posts: 553
Location: Home Office

mqsiuser wrote:
Ah, sorry, it is "if you repeatedly query your input-message (to build the/one output msg), then this will (likely) reduce performance".

If you manage to build your output based on a single SELECT-clause, bravo , then it's like vitor says !


??? I am still at a loss, what are you proposing ?!!

And by the way ( before Vitor bites you ), it is Vitor with uppercase V.
Back to top
View user's profile Send private message
Vitor
PostPosted: Thu Jan 23, 2014 7:55 am    Post subject: Reply with quote

Grand High Poobah

Joined: 11 Nov 2005
Posts: 26093
Location: Texas, USA

dogorsy wrote:
??? I am still at a loss, what are you proposing ?!!


Me too

dogorsy wrote:
And by the way ( before Vitor bites you ), it is Vitor with uppercase V.


I'm good; at least he didn't add a "c".
_________________
Honesty is the best policy.
Insanity is the best defence.
Back to top
View user's profile Send private message
kimbert
PostPosted: Thu Jan 23, 2014 7:57 am    Post subject: Reply with quote

Jedi Council

Joined: 29 Jul 2003
Posts: 5542
Location: Southampton

Just for PRKUMAR's benefit ( because he is probably getting completely confused by the last few posts )...

mqsiuser is very, very focused on performance. He is concerned that executing four SELECT statements will be slower than some other, single-statement solution. I'm not sure what solution he has in mind, but I am sure that four SELECTs will not kill the performance of your message flow. Unless you have some fairly stringent QoS requirements.

@mqsiuser: In many message flows, transformation of the message tree does not dominate the performance of the flow. Reducing CPU usage is sometimes very important, but not always.
_________________
Before you criticize someone, walk a mile in their shoes. That way you're a mile away, and you have their shoes too.
Back to top
View user's profile Send private message
mqsiuser
PostPosted: Thu Jan 23, 2014 8:00 am    Post subject: Reply with quote

Yatiri

Joined: 15 Apr 2008
Posts: 637
Location: Germany

kimbert wrote:
The simplest solution is four SELECT statements ( one per department ).

That will go into the message 4 times. With references you will go into your message only ONCE (if done right). If this is just a simple example (and the OP told, that the actual file has 500 rows), then that matters: The time it takes to go into a message 4 times is about 4 times more than if you go through (with a reference) ONE time .

I don't understand, why this isn't obvious.

Exceptions may apply
_________________
Just use REFERENCEs
Back to top
View user's profile Send private message
dogorsy
PostPosted: Thu Jan 23, 2014 8:11 am    Post subject: Reply with quote

Knight

Joined: 13 Mar 2013
Posts: 553
Location: Home Office

mqsiuser wrote:
The time it takes to go into a message 4 times is about 4 times more than if you go through (with a reference) ONE time

Is that so ? can you provide evidence ?
I do not support that view ( an neither performance tests ).
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic  Reply to topic Goto page 1, 2  Next Page 1 of 2

MQSeries.net Forum Index » WebSphere Message Broker (ACE) Support » Query in esql
Jump to:  



You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Protected by Anti-Spam ACP
 
 


Theme by Dustin Baccetti
Powered by phpBB © 2001, 2002 phpBB Group

Copyright © MQSeries.net. All rights reserved.