Author |
Message
|
wbintegrator |
Posted: Sun Jan 18, 2009 11:19 pm Post subject: CALL procedure/submap - name known at runtime (variable) |
|
|
Voyager
Joined: 08 Feb 2006 Posts: 83
|
Hi everyone,
I need to call a submap programatically from esql - the name of the submap is retrieved from the LocalEnvironment as a [schema].[map_name] string,
for example, for the below code:
Code: |
DECLARE subMap CHAR 'submaps.standAloneMap';
|
how can I call the content of the variable 'subMap' which basically is a procedure that receives three arguments (source, target, inEnv) also known only at runtime?
I mean, is there a way to "dereference" the variable and pass it the above arguments? Guess it would look something like:
Code: |
CALL ${subMap}(source, target, inEnv);
|
Thanks for help,
Joseph |
|
Back to top |
|
 |
wbintegrator |
Posted: Mon Jan 19, 2009 11:17 pm Post subject: |
|
|
Voyager
Joined: 08 Feb 2006 Posts: 83
|
Does this sort of requirement seem feasible or am I asking "too much"?
Thanks. |
|
Back to top |
|
 |
mgk |
Posted: Tue Jan 20, 2009 12:43 am Post subject: |
|
|
 Padawan
Joined: 31 Jul 2003 Posts: 1642
|
Hi.
You do this with EVAL. Just remember that EVAL can be slow... _________________ MGK
The postings I make on this site are my own and don't necessarily represent IBM's positions, strategies or opinions. |
|
Back to top |
|
 |
wbintegrator |
Posted: Wed Jan 21, 2009 5:04 am Post subject: |
|
|
Voyager
Joined: 08 Feb 2006 Posts: 83
|
Much thanks for your answer mgk, it really seems to be exactly what I need.
However there also seems to be a problem invoking user defined procedures/functions via EVAL... The message is not written out, although there is no exception nor any message in the log regarding EVAL failure. I also tried user trace on the execution group but no reference to any error whatsoever.. I did succeed in executing built-in functions though. Any Ideas? |
|
Back to top |
|
 |
mgk |
Posted: Wed Jan 21, 2009 6:33 am Post subject: |
|
|
 Padawan
Joined: 31 Jul 2003 Posts: 1642
|
Try something like this (I wrote this years ago, but it should work):
Code: |
DECLARE procname CHAR;
SET procname = 'testproc';
EVAL('CALL ' || procname || '(InputRoot , OutputRoot)');
//create the procedure in the usual way
CREATE PROCEDURE testproc( IN IRoot REFERENCE, IN ORoot REFERENCE )
BEGIN
SET ORoot = IRoot;
SET ORoot.XMLNSC.TestCase.mgk.string = 'hello1';
END; |
_________________ MGK
The postings I make on this site are my own and don't necessarily represent IBM's positions, strategies or opinions. |
|
Back to top |
|
 |
wbintegrator |
Posted: Thu Jan 22, 2009 1:26 am Post subject: |
|
|
Voyager
Joined: 08 Feb 2006 Posts: 83
|
Thanks again mgk: I had s missing ';' in the eval expression.
So, user defined procedures seem to work OK.
As for my ultimate target, which is calling a submap (basically, an auto-generated procedure) I have not much success. There is no access to the WWW from our network so I'm typing is a snippet which shows the main idea of the desired result vs the problem that occurs:
schema (submap locattion): submaps
submap (procedure name): sample_submap
Desired result - Fails (ultimately, schema.submap_proc will be retrieved from WSRR at runtime)
Code: |
set evalExp = 'CALL submaps.sample_submap(source, target, inEnv);';
EVAL(evalExp ) -- FAILS
|
The weird "workaround" - Succeeds
Code: |
-- call the desired procedure normally before EVAL
CALL submaps.sample_submap(source, target, inEnv); -- WORKS
set evalExp = 'CALL submaps.sample_submap(source, target, inEnv);';
EVAL(evalExp ) -- WORKS
|
In the snippet I called 'The weird "workaround"', putting the normal esql CALL prior to EVAL, causes the EVAL to succeed, while when using EVAL only, as in the first snippet, I get an Exception saying "Unknown Function" some place in the Exception List tree. Do you see any logical reason for a thing like this to happen? (smells like a bug to me..) |
|
Back to top |
|
 |
mgk |
Posted: Thu Jan 22, 2009 1:48 am Post subject: |
|
|
 Padawan
Joined: 31 Jul 2003 Posts: 1642
|
Hello.
Thanks for your detailed explanation of what is happening, as I can now explain why you are seeing the results you do.
Essentially, all ESQL code in all schemas used by a compute/db/filter node is available in the toolkit for that node to use to. However, there is an "optimisation" step before deployment that is similar to linking in a C/C++ environment, whereby all "unreferenced functions and procedures" are removed from the schema(s) before the code is deployed to a given ESQL node. This is done to prevent huge ammounts of code being given to a compute node that may never actually be called.
Therefore, unless you have code that actually appears to call a function/procedure, it will not be present at runtime to be used by EVAL as this process can not know at deploytime what the EVAL statement will actually do (the string to EVALuate could come from a message for example). Thefore, any function/procedure ONLY called in an EVAL will not be present at runtime.
Given this, there is a way to bypass this process, without actually calling a function/procedure but still have it available for use by EVAL, and that is to pretend to call the necessary functions in code that can never actually be reached. For example in psudo code:
DECLARE myVar INTEGER 42;
IF myVar != 42 THEN
CALL func1()
CALL proc1()
--etc
END IF;
This way, the functions/procedure will be available to be called by EVAL at runtime, and the IF will never be entered, but it is enough to drag the definitions of the functions into the code given to the runtime.
I hope this helps...
Regards, _________________ MGK
The postings I make on this site are my own and don't necessarily represent IBM's positions, strategies or opinions. |
|
Back to top |
|
 |
wbintegrator |
Posted: Thu Jan 22, 2009 3:21 am Post subject: |
|
|
Voyager
Joined: 08 Feb 2006 Posts: 83
|
Thank you so much for your detailed answer - you are absolutely right and the trick with the unreachable 'if' does the work.
This optimization, however useful and desired in most cases, makes the code very ugly and even stupid as, if I will put the function hardcoded in an unreachable 'if' in order to have it deployed, then it loses much of its meaning as to being known at runtime only.
I wish there was a directive (import/include) that would tell the optimizer to deploy anyway..
I think an issue like this should be very well documented (in the EVAL section) by IBM as it is a bug-like non-intuitive fact.
Thank you again for you help and sparing my time from opening a PMR on a non-documented feature.
Joseph |
|
Back to top |
|
 |
mgk |
Posted: Thu Jan 22, 2009 3:33 am Post subject: |
|
|
 Padawan
Joined: 31 Jul 2003 Posts: 1642
|
You are of course correct about the lack of docs for this. I will get someone to look into improving it.
Quote: |
I wish there was a directive (import/include) that would tell the optimizer to deploy anyway.. |
Could you raise this as a feature through your IBM rep...?
Regards, _________________ MGK
The postings I make on this site are my own and don't necessarily represent IBM's positions, strategies or opinions. |
|
Back to top |
|
 |
wbintegrator |
Posted: Thu Jan 22, 2009 4:34 am Post subject: |
|
|
Voyager
Joined: 08 Feb 2006 Posts: 83
|
Quote: |
Could you raise this as a feature through your IBM rep...?
|
I will consider that. |
|
Back to top |
|
 |
|