Dynamic expression evaluater

I have a dynamic expression of this sort:
{ (( A || B ) && ( C || D )) || E }
where A,B,C,D,E...(and so on) are boolean variables and the operators between them keep changing.
How can i do this through some methods?

If the expression is valid java syntax, then consider writing a piece of code that writes a piece of java with a method containing your expression, and where the letters in the expressions are local variables.
Then invoke the compiler on the generated code using Runtime.exec, load the class and use it.
How fast is this process you might ask? The slowest I have seen was one and a half second on a 550 MHz PIII W2K PC, the fastest was down around 0.01 second, on a recent Athlon with SCSI disks and Linux.
Of course as soon as the class is loaded it is a method call like any other one, so if you want to invoke the expression many times with different values the runtime cost is only the cost of as many method calls, you don't have to regenerate the java again until you change the expression.
You can trade simplicity of implementation for load time speed by generating the class file directly without using java source code as an interim format. O'Reilly has a book on how to write "assembler" for the JVM that explains how to do this. You won't be touching the disk system at all, but will be writing the bytes of a class definition directly to the ClassLoader.defineClass method

Similar Messages

  • Follow-up Dynamic expression in interface

    I created this thread so I can give credits to anyone helps me on this.
    I tried to follow the following thread and got some errors.
    Dynamic expression in interface
    When I execute the interface alone with out Java procedure(<@=result@>) its working.
    In the package the first step is Java procedure. The second step is the interface. When I execute the package its failing at the interface level even if I don't call the procedure result in the interface. Any idea.
    Dev - Yes I am using the same context
    -app

    When I right click and execute its working without the Java Procedure result in the interface.
    When I execute as a package I am getting same error message with or with out the procedure variable in the interface at the step "Insert flow into I$ table"
    Following is the command from the execution tab where its failing.
    insert into STAGING.I$_DYNAMIC_TABLE_1
         SRC_TAB_COLUMN,
         SRC_TAB_COLUMN_VALUE,
         PRODUCT_NAME,
         PRODUCT_NAME_1
    select
         DYNAMIC_TABLE.SRC_TAB_COLUMN,
         DYNAMIC_TABLE.SRC_TAB_COLUMN_VALUE,
         DYNAMIC_TABLE.PRODUCT_NAME,
         <@=result@>
    from      STAGING.DYNAMIC_TABLE DYNAMIC_TABLE
    where     
         (1=1)

  • How to use the Dynamic Expression in BRFplus

    Hi Experts
                   I am new to BRFplus. Can you give any document on BRFplus how to use the Dynamic Expression.
    Thankyou
    Venkat

    OK I tried it and worked but for one condition:
    WHERE DECODE (E.qualification_sid, 1104,
         (TO_DATE(E.RANK_DATE, 'DD-MM-RR')+(365*M.spe_per)+1),
         (TO_DATE(E.RANK_DATE, 'DD-MM-RR')+(365*M.mili_yea_per)+1))
         BETWEEN TO_DATE('01-07-2011', 'DD-MM-RR') AND TO_DATE('31-07-2011', 'DD-MM-RR')
    But how to put two conditions for the same Expression:
    WHERE DECODE ((E.qualification_sid, 1104) AND (E.RANK_SID, 8),
         (TO_DATE(E.RANK_DATE, 'DD-MM-RR')+(365*M.spe_per)+1),
         (TO_DATE(E.RANK_DATE, 'DD-MM-RR')+(365*M.mili_yea_per)+1))
         BETWEEN TO_DATE('01-07-2011', 'DD-MM-RR') AND TO_DATE('31-07-2011', 'DD-MM-RR')
    The previous code gives me this error: missing right parenthesis

  • Expression​.Evaluate(​) - how to use it with propertyob​ject?

    Hi,
    I code in a process model callback and would like to evaluate an expression with the Runstate.Caller context.
    I found the method 
    Expression.Evaluate (
    evaluationContext, evaluationOptions = EvalOption_NoOptions)
    This is exactly what I need. However, if I have a CallingStep.Expr, which is a expression, I can't access the Evaluate() function. It is not available, only the PropertyObjects functions are.
    How can I cast it to be an Expression so I can access the function Evaluate?!
    I though I could do:
    Runstate.CallingStep.Expr.Evaluate(Runstate.Caller​, 0x0)
    This would return the expression evaluated in the caller context as a PropertyObject.
    But it's not the case, I'm missing something so TS know Runstate.CallingStep.Expr is an Expression... even if I add it to Watch panel, it shows it's an expression...
    Thank you.
    Solved!
    Go to Solution.

    I have an object of type Expression (from what I understand and from what the watch panel is showing) and I was expecting to be able to use the Evaluate() function.
    Expression.Evaluate(seqContext, options)
    But it seems that it's a propertyobject because only the function of this type are available.
    I've attached a screenshot. Thank you.
    Attachments:
    watchPanel.PNG ‏14 KB

  • Dynamic expression in interface

    Hi All
    Could someone share a way how to create dynamic expression in ODI interface. Eg. I have metadata and want to build case expression on its basis and use it in interface.
    I have tried several possibilities:
    1) Use Java program in mapping expression.
    But during interface steps creation getJDBCConnection() method returns null for both SRC and DEST.
    Is there is a way how to connect to database?
    2) Generate expression in procedure and use it in interface
    Is there is a way how to pass string from procedure to interface?
    3) Use variable to generate expression
    Pure SQL is not enough to generate my expression, I need cycles, ifs etc.
    4) Use special IKM which replace some substitution symbols with generated expression.
    Well if there is no other choise I'll pick this up but don't want to have additional special KM.
    Could someone propose other solution or workaround for listed?
    Many thanks in advance!
    Oleg Ivanov

    Dev -
    I followed this thread and thought I'll try it in my end. Did the following.
    1)Created a procedure and pasted your code (changed the table name to mine)
    2)Created an interface and connected my source and target. In one of the target columns I put <@=result@>
    3)created a package and brought procedure and interface.
    When I executed the procedure ran successfully but failed at the interface level. I am getting the following error message.
    17008 : null : java.sql.SQLException: Closed Connection
    java.sql.SQLException: Closed Connection
         at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:125)
         at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:162)
         at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:227)
         at oracle.jdbc.driver.PhysicalConnection.prepareStatement(PhysicalConnection.java:753)
         at oracle.jdbc.driver.PhysicalConnection.prepareStatement(PhysicalConnection.java:670)
         at com.sunopsis.sql.SnpsQuery.a(SnpsQuery.java)
         at com.sunopsis.sql.SnpsQuery.a(SnpsQuery.java)
         at com.sunopsis.sql.SnpsQuery.updateExecStatement(SnpsQuery.java)
         at com.sunopsis.sql.SnpsQuery.executeQuery(SnpsQuery.java)
         at com.sunopsis.dwg.dbobj.SnpSessTaskSql.execCollOrders(SnpSessTaskSql.java)
         at com.sunopsis.dwg.dbobj.SnpSessTaskSql.treatTaskTrt(SnpSessTaskSql.java)
         at com.sunopsis.dwg.dbobj.SnpSessTaskSqlI.treatTaskTrt(SnpSessTaskSqlI.java)
         at com.sunopsis.dwg.dbobj.SnpSessTaskSql.treatTask(SnpSessTaskSql.java)
         at com.sunopsis.dwg.dbobj.SnpSessStep.treatSessStep(SnpSessStep.java)
         at com.sunopsis.dwg.dbobj.SnpSession.treatSession(SnpSession.java)
         at com.sunopsis.dwg.cmd.DwgCommandSession.treatCommand(DwgCommandSession.java)
         at com.sunopsis.dwg.cmd.DwgCommandBase.execute(DwgCommandBase.java)
         at com.sunopsis.dwg.cmd.e.j(e.java)
         at com.sunopsis.dwg.cmd.h.z(h.java)
         at com.sunopsis.dwg.cmd.e.run(e.java)
         at java.lang.Thread.run(Unknown Source)

  • [nQSError: 42015] Cannot function ship the following expression: Evaluate(

    Hi,
    I am getting the following error when using evaluate function
    State: HY000. Code: 10058. [NQODBC] [SQL_STATE: HY000] [nQSError: 10058] A general error has occurred. [nQSError: 42015] Cannot function ship the following expression: Evaluate( TO_CHAR(%1),D907.c2) . (HY000)
    The syntax I had used in the column expression was
    EVALUATE('TO_CHAR(%1)' AS CHAR,"SA table"."Prior Quarter QTD Dollars")
    I am not sure why this is error is occurring because I have successfully used this syntax before. This is an example syntax I had used in another report and it is working well even now
    CAST(EVALUATE('TO_CHAR(%1,%2)' AS CHAR,ROUND(("table1"."QTD Actuals")/1000,0) ,'$9,999,999,999,999,990') AS CHAR)

    I had to use Case and CAST functions to achieve the same logic. I have raised a TAR with Oracle for this issue. Still waiting to hear from them. Using Case and CAST achieved the result but since there is a bug in 10.1.3.4.0 where download will fail if the query generated is more than 64kb, we are upgrading to 10.1.3.4.1.

  • Dynamic Expression

    Hello, My name is Alejandro Arango
    My problem is that i want to make expression dynamic, with that i mean the following:
    I want to be able to change an expression in a assign Statement from concat("var1") to concat("var2") and the expression is obtained from a service so the message in the assign can be changed dynamically without having to recompile and redeploy the BPEL process. The idea is to separte the message template from the bpel process.
    Thx BPEL Team

    Hey Clemens thanks for the reply and also i hope you had an esplendid vacation on Croatia. Back to the topic.
    The need for Dynamic Expression is due for many factors
    - Bug or a Behavior in Oracle BPEL Designer (JDeveloper) that constantly reformat the bpel process file so it always clears the line feeds and carrier returns making almost imposible to mantain the messages inside the bpel process (messages for notification pourposes).
    - Separate the message template from the process, so the message can be updated without having to compile again the bpel proceess for the simple reason to change a simple word in the message (Like Apache Velocity, where u have a template for creating dynamic messages)
    I know that this is more like a feature request rather than a simple or need bug fix.
    Also i want to know if it is possible to implement a java class that can obtain the bpel process variables outside the scope of the java:exec part. Look the example for more clarification:
    XYZprocess.bpel
    <process name="XYZprocess"
    <bpelx:exec name="getVariableData" language="Java" version="1.4">
    <![CDATA[
    // This will create a string based on the template given in the file
    String data = Template.generateMessageFromFile("template.txt", this);
    ]]>
    <process/>
    Template.java
    Class Template
    public static String generateMessageFromFile(String file, BPELXExecLet process)
    Element element1 = (Element) process.getVariableData("var1");
    Element element2 = (Element) process.getVariableData("var2");
    return element1.toString() + element2.toString() ;
    The idea is to fill the element1 and element2 variable with the variable of the bpel process. One dificult is that the class of the bpel process (BPELXExecLet) all the API methods are porotected so it can be only executed inside the bpelx:exec tag and not outside of this scope.
    Thanks You.

  • Cannot function ship the following expression: Evaluate

    hello
    i used a db function in rpd
    EVALUATE('X.F_REPLACE_NEG_VAL_TO_ZERO(%1)' AS DOUBLE PRECISION , "Stock"."Fact - Inventory"."Vol")
    the functions purpose is to put to zero the measure in case its <0
    when i use this measure in answers it works fine; however when i add a measure from another facts table into the report i get the following error:
    "Cannot function ship the following expression: Evaluate( X.F_REPLACE_NEG_VAL_TO_ZERO(%1),D902.c6) "
    this is a multifacts area, the dimensions used in the report are common for both facts tables (report runs fine with either measures from facts table 1 or from facts table 2); only error is when i put both measures together;
    i went through many threads here but could not find any solution that could be applied to above
    id appreciate any suggestions
    thanks
    rgds

    hello,
    i ran some more tests and apparently this is not related to this particular function i.e. even if i use
    evaluate('to_number'(1%)','column') it still throws an error
    can evaluate be used in multifacts areas?

  • Jstl: ExpressionEvaluator.evaluate  versus  Expression.evaluate

    Hi,
    Reading the jstl API, I noticed the method ExpressionEvaluator.evaluate().
    On the other hand, ExpressionEvaluator also returns an Expression, which has its own evaluation method: Expression.evaluate().
    Isn't this redundant ? Which method would be used on which occasion ?
    Also, I was wondering: do I understand correctly, that one could override the ExpressionEvaluator ? So if I write my own evaluator, I could make it so that "${2+2}" evaluates to, say, "5" ?
    Thanks very much.

    Hi,
    Reading the jstl API, I noticed the method ExpressionEvaluator.evaluate().
    On the other hand, ExpressionEvaluator also returns an Expression, which has its own evaluation method: Expression.evaluate().
    Isn't this redundant ? Which method would be used on which occasion ?
    Also, I was wondering: do I understand correctly, that one could override the ExpressionEvaluator ? So if I write my own evaluator, I could make it so that "${2+2}" evaluates to, say, "5" ?
    Thanks very much.

  • Dynamic Expression Evaluation in AS 3

    Hi all,
    AS 2 had the eval() function, but it was removed in AS 3. Does anyone know of a way to dynamically evaluate an expression in AS 3+?
    I'm trying to impliment a feature that allows a user to define the behavior of a component based on the evaluation of an expression (composed of  conditional, logical and grouping operators which operate on constants and remote data sources).
    Any ideas how one might do that using the current Flex toolset and or 3rd party libs?
    Thanks in advance,
    Carl
    PS - Anyone ever use this libarary:
    http://code.google.com/p/flexeval/
    Doesn't seem like there is much activity there.

    U can use it like any other netui tag.
    Kunal Mittal

  • Conditional Split - Expression Evaluates to Null

    Hi everyone!
    I'm using a conditional split to discriminate modified records. My expression looks like this:
    col1_source != col1_dest || col2_source != col2_des.....and so on. I use OLE DB Command afterward to update modified records.
    It all works fine if no columns evaluate to null. If any (source or dest.) evaluates to null, component fails.
    Any tips how to solve a problem?
    It has to work like this:
    If colX_source is null and colX_dest is not null --> Update
    If colX_source is not null and colX_dest is null --> Update
    If both colX_source and colX_dest are null --> No update
    p.s. i apologize if a similar thread exists, I haven't found something of use to me.

    Thank you both for a quick response.
    I understood the derived column idea but not the isnull idea. 
    If I want to cover all the cases in which I want the update to execute, my expression (if I haven’t missunderstood sth) should look like this: 
    isNull(col1_source) && !IsNull(col1_dest) || !isNull(col1_source) && IsNull(col1_dest) || col1_source != col1_dest
    Isn’t it true that again, the last part of the expression col1_source != col1_dest evaluates to null if one of the columns is null? And that the only solution to the problem is a derived column which transforms null values in “”?
    I’m new to SSIS and slowly learning that programming logic is not always the SSIS logic.
     

  • Dynamic expression evaluation in netui:param

    Hi,
    Is there any way to send dynamic values(numbers) to <netui:param> tag 'value' attribute, pl. let me know as soon as possible.
    Thanks in Advance,
    sugan

    U can use it like any other netui tag.
    Kunal Mittal

  • Dynamic boolean expression evaluation

    Hey everyone,
    We have a table that consists of a couple key columns and a column containing a boolean expression. We want to select a number of rows based on the key columns and evaluate the boolean expression in the expression column for each, only returning the first row wherein the boolean expression evaluates to true.
    We are using a context to inject the test variables into the boolean expressions and currently we are selecting all the key rows in a PL/SQL procedure and going through the cursor evaluating each of the boolean expressions with an execute immediate.
    The expressions are currently formated in the columns as anonymous PL/SQL blocks that, when called, will either return true or false to the PL/SQL procedure. Upon returning true, the procedure stops looping and returns true to the caller.
    Psuedo-code would be:
    - set-up sys_context with condition variables
    - create cursor for: select * from expression_tbl et where <key matches>
    - begin loop through cursor
    - execute immediate cursor_row.expression using out :out_is_true
    - if out_is_true = 'Y' then return true
    - loop
    - return false
    The expressions (anonymous PL/SQL blocks) from the table look something like this:
    begin if ((''||sys_context('ctx', '1')||'' = 'FL') AND (''||sys_context('ctx', '3')||'' BETWEEN 1619 AND 4598) ) then :1 := 'Y'; end if; end;
    This works, but it seems like I should be able to do this another way and potentially extract more performance.
    So...a couple questions:
    1) I have read on ask Tom that a dynamic select statement (rather than an anonymous PL/SQL block) can evaulate the boolean expressions. I.E. rather than use an execute immediate clause on an anonymous PL/SQL block contained in the expression column, I would make the expression column compatible with a where clause and create this dynamic SQL query: 'select count(*) from dual where ' || expression. I would then execute that query and if it returns a row then the expression is true, otherwise it is false. My question is, does anyone think the performance of parsing the SQL and executing it would be better than that of executing an anonymous PL/SQL block for every row? Tom said that the SQL could incur a lot of hard-parses and kill performance, but how deathly is the constant compilation of anonymous PL/SQL blocks as shown above in comparison?
    2) Would there be any benefit to pulling the execute routines out of the PL/SQL block and issuing a query such as the following:
    select * from expression_tbl et where <key matches> AND pkg.eval_routine(et.expression) = 'Y' AND rownum <= 1.
    I realize that the evaulating routine would then need to either perform an execute immediate on et.expression (if we keep the current method in place) or formulate the dynamic SQL statement and execute it. But, could this be faster than doing the same loop through rows explicitely in PL/SQL?
    Doing this would trim my PL/SQL down to:
    - set up sys_context
    - execute the above select statmenet
    - if a row is returned then return true otherwise return false
    Seems more elegant, but the peformance is all that matters.
    3) Is there any built-in routine that I may be able to replace pkg.eval_routine from 2 with that would evaulate boolean expressions for me? Or any other way to inline the idea from 1 with 2? I can't think of one given the dynamic nature of the beast, but...maybe there's something I missed.
    Thanks everyone! Hopefully I've expressed myself clearly.

    Brian - According to Tom Kyte Doing PL/SQL inside Execute Immediate should be faster as you are already within the context of a PL/SQL engine. If we choose to do it in SQL then the PL/SQL engine has to hand it over to the SQL Engine for executing the dynamic Select statements and so might be a little slower. But I am not sure if the difference can be quantifiable unless u do your own test of both evaluators and run them for like a few thousand times in a loop.
    If you are using 10g R2 - you might want to look into DBMS_RLMGR package which is the API for the Oracle's version of the embedded business rule manager.
    I looked into it but it didn't fit our needs as its deficient with respect to rule versioning and effective and until date based business rule enforcement/ validation.
    After taking a shot at designing something home grown I feel its not that difficult to construct one that fit our needs inclusive of the features( rule versioning, effective and until dates) that I listed above as deficiencies in the Oracle embedded rule engine.
    If you don't have those requirements may be using the Business Rule manager API of 10g R2 might not be a bad anticipating it will be improved in future versions.
    Regards
    -Suren

  • SSRS dynamic image expression not working

    Hi All;
    All my below dynamic expression not wrking
    =iif(First(Fields!new_mainValue.Value,
    "DataSet1")="ABC",True,False)
    Any help much appreciated
    Thanks
    Pradnya07

    Below worked for me 
    =iif(First(Fields!new_mainValue.Value,
    "DataSet1")="ABC",False,True)

  • Beginner - can't get EL expressions to evaluate...

    I am running Tomcat 5.5 on Windows. I am trying to get a JSP page that
    contains an expression like: ${1+2+3}
    but, it doesnt evaluate. None of those $ expressions evaluate. I get
    output of ${1+2+3} when wanted to see '6'.
    I have added the current jstl.jar and standard.jar to the WEB-INF/lib.
    I have copied TLD files to their locations. and the jstl core libraries
    and such work fine. Its just the EL that isnt evaluating.
    Any ideas? thanks.

    Update your web.xml file to be version 2.4
    If your web.xml starts with this:
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
    <web-app>Replace it with this
    <?xml version="1.0" encoding="ISO-8859-1"?>
    <web-app xmlns="http://java.sun.com/xml/ns/j2ee"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
        version="2.4">For more common issues on JSTL, read [url http://forum.java.sun.com/thread.jspa?threadID=629437&tstart=0] this post reply #6

Maybe you are looking for