4 Replies Latest reply on Mar 12, 2013 5:41 PM by Van Halbert

    Trying to define a UDF with variable arguments

    Van Halbert Master

      Here's the function defined in the dynamic VDB:

       

              CREATE VIRTUAL FUNCTION performRuleOnData(className string, returnMethodName string, returnIfNull string, VARIADIC z object ) RETURNS string OPTIONS (JAVA_CLASS 'org.jboss.teiid.businessrules.udf.RulesUDF',  JAVA_METHOD 'performRuleOnData', VARARGS 'true');

       

       

      Getting this warning (but maybe it should be an error):

       

      14:58:42,012 WARN  [org.teiid.PLANNER.RESOLVER] (teiid-async-threads - 3) TEIID31080 View Stocks.StockValidation validation error: QueryResolverException-TEIID30068 The function 'RulesUDF.performRuleOnData('org.jboss.teiid.quickstart.data.MarketData', 'getInvalidMessage', 'noMsg', txncursor.company_name, txncursor.symbol, txncursor.price)' is an unknown form.  Check that the function name and number of arguments is correct.

      14:58:42,012 WARN  [org.teiid.PLANNER.RESOLVER] (teiid-async-threads - 3) TEIID31073 Invalid functions; Translator metadata load Stocks []

       

       

      The class method is:

       

                public static Object performRuleOnData(final org.teiid.CommandContext commandContext, final String className, final String returnMethodName, final Object returnIfNull, final Object... arguments) {...}

       

       

      What am I missing or got wrong?

       

      Thanks.

       


        • 1. Re: Trying to define a UDF with variable arguments
          Ramesh Reddy Master

          How does your -vdb.xml file look like?

          • 2. Re: Trying to define a UDF with variable arguments
            Van Halbert Master

            <?xml version="1.0" encoding="UTF-8" standalone="yes"?>

            <vdb name="PortfolioBR" version="1">

             

                <description>Shows how to integrate drools rules with Teiid</description>

                  

                <property name="lib" value="org.jboss.teiid.businessrules.udf"></property>

                   

                <import-vdb name="Portfolio" version="1" import-data-policies="false"/>

                <model name="Stocks" type="VIRTUAL">

                    <metadata type="DDL"><![CDATA[

                   

                    CREATE VIRTUAL FUNCTION performRuleOnData(className string, returnMethodName string, returnIfNull string, VARIADIC z object ) RETURNS string OPTIONS (JAVA_CLASS 'org.jboss.teiid.businessrules.udf.RulesUDF',  JAVA_METHOD 'performRuleOnData', VARARGS 'true');

                   

                    CREATE VIEW StockPrices (

                        symbol string,

                        price bigdecimal

                        )

                        AS 

                           SELECT StockPrices.symbol, StockPrices.price

                            FROM (EXEC MarketData.getTextFiles('*.txt')) AS f,

                                TEXTTABLE(f.file COLUMNS symbol string, price bigdecimal HEADER) AS StockPrices;

                   

                   

                    CREATE VIEW Stock (

                        symbol string,

                        price bigdecimal,

                        company_name   varchar(256)

                        )

                        AS

                            SELECT  S.symbol, S.price, A.COMPANY_NAME

                                FROM StockPrices AS S, Accounts.PRODUCT AS A

                                WHERE S.symbol = A.SYMBOL;

             

                               

                    CREATE VIRTUAL PROCEDURE StockValidation() RETURNS (companyname varchar(256), symbol string(10), price bigdecimal, message varchar(256) )

                       AS

                    BEGIN

                        DECLARE String VARIABLES.msg;

                        CREATE LOCAL TEMPORARY TABLE TEMP (companyname string, symbol string, price bigdecimal, message string);

                        LOOP ON (SELECT Stock.symbol, Stock.price, Stock.company_name FROM Stock) AS txncursor

                        BEGIN

                            VARIABLES.msg = RulesUDF.performRuleOnData('org.jboss.teiid.quickstart.data.MarketData', 'getInvalidMessage', 'noMsg', txncursor.company_name, txncursor.symbol, txncursor.price);

                            IF(VARIABLES.msg <> 'NoMsg')

                            BEGIN

                                INSERT INTO TEMP (TEMP.companyname, TEMP.symbol, TEMP.price, TEMP.message) VALUES (txncursor.COMPANY_NAME, txncursor.symbol, txncursor.price, VARIABLES.msg);

                            END

                        END

                        SELECT TEMP.companyname, TEMP.symbol, TEMP.price, TEMP.message FROM TEMP;

                    END

                            

                    ]]> </metadata>

                </model>

            </vdb>

            • 3. Re: Trying to define a UDF with variable arguments
              Ramesh Reddy Master

              Change

               

              VARIABLES.msg = RulesUDF.performRuleOnData('org.jboss.teiid.quickstart.data.MarketData', 'getInvalidMessage', 'noMsg', txncursor.company_name, txncursor.symbol, txncursor.price);

               

              to

               

              VARIABLES.msg = Stocks.performRuleOnData('org.jboss.teiid.quickstart.data.MarketData', 'getInvalidMessage', 'noMsg', txncursor.company_name, txncursor.symbol, txncursor.price);

               

              Ramesh..

              • 4. Re: Trying to define a UDF with variable arguments
                Van Halbert Master

                Dang, after looking and looking, it didn't hit me to change the model reference.  Converting from 5.3 usage to 8.x, and the function model is no longer used.

                 

                Thanks

                 

                Van