Search in sources :

Example 11 with FunctionParameter

use of org.teiid.metadata.FunctionParameter in project teiid by teiid.

the class TestFunctionTree method testLoadErrors.

@Test
public void testLoadErrors() {
    FunctionMethod method = new FunctionMethod(// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    "dummy", // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    null, // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    null, // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    PushDown.CAN_PUSHDOWN, // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    null, // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    "noMethod", new ArrayList<FunctionParameter>(0), new FunctionParameter("output", DataTypeManager.DefaultDataTypes.STRING), false, // $NON-NLS-1$
    Determinism.DETERMINISTIC);
    // allowed, since we're not validating the class
    new FunctionLibrary(RealMetadataFactory.SFM.getSystemFunctions(), new FunctionTree("foo", new UDFSource(Arrays.asList(method))));
    // should fail, no class
    try {
        new FunctionLibrary(RealMetadataFactory.SFM.getSystemFunctions(), new FunctionTree("foo", new UDFSource(Arrays.asList(method)), true));
        fail();
    } catch (TeiidRuntimeException e) {
        assertEquals("TEIID31123 Could not load non-FOREIGN UDF \"dummy\", since both invocation class and invocation method are required.", e.getMessage());
    }
    method.setInvocationClass("nonexistantClass");
    // should fail, no class
    try {
        new FunctionLibrary(RealMetadataFactory.SFM.getSystemFunctions(), new FunctionTree("foo", new UDFSource(Arrays.asList(method)), true));
        fail();
    } catch (TeiidRuntimeException e) {
    }
    method.setInvocationClass(TestFunctionTree.class.getName());
    // should fail, no method
    try {
        new FunctionLibrary(RealMetadataFactory.SFM.getSystemFunctions(), new FunctionTree("foo", new UDFSource(Arrays.asList(method)), true));
        fail();
    } catch (TeiidRuntimeException e) {
    }
    method.setInvocationMethod("testLoadErrors");
    // should fail, not void
    try {
        new FunctionLibrary(RealMetadataFactory.SFM.getSystemFunctions(), new FunctionTree("foo", new UDFSource(Arrays.asList(method)), true));
        fail();
    } catch (TeiidRuntimeException e) {
    }
    method.setInvocationMethod("x");
    // should fail, not public
    try {
        new FunctionLibrary(RealMetadataFactory.SFM.getSystemFunctions(), new FunctionTree("foo", new UDFSource(Arrays.asList(method)), true));
        fail();
    } catch (TeiidRuntimeException e) {
    }
    method.setInvocationMethod("z");
    // should fail, not static
    try {
        new FunctionLibrary(RealMetadataFactory.SFM.getSystemFunctions(), new FunctionTree("foo", new UDFSource(Arrays.asList(method)), true));
        fail();
    } catch (TeiidRuntimeException e) {
    }
    method.setInvocationMethod("y");
    // valid!
    new FunctionLibrary(RealMetadataFactory.SFM.getSystemFunctions(), new FunctionTree("foo", new UDFSource(Arrays.asList(method)), true));
}
Also used : FunctionMethod(org.teiid.metadata.FunctionMethod) TeiidRuntimeException(org.teiid.core.TeiidRuntimeException) FunctionParameter(org.teiid.metadata.FunctionParameter) Test(org.junit.Test)

Example 12 with FunctionParameter

use of org.teiid.metadata.FunctionParameter in project teiid by teiid.

the class TestFunctionTree method testMultiPartNameSystemConflict.

@Test
public void testMultiPartNameSystemConflict() throws Exception {
    FunctionMethod method = new FunctionMethod("x.concat", null, null, PushDown.MUST_PUSHDOWN, null, null, // $NON-NLS-1$
    Arrays.asList(new FunctionParameter("in", DataTypeManager.DefaultDataTypes.STRING), new FunctionParameter("in", DataTypeManager.DefaultDataTypes.STRING)), // $NON-NLS-1$
    new FunctionParameter("output", DataTypeManager.DefaultDataTypes.STRING), true, Determinism.DETERMINISTIC);
    FunctionTree sys = RealMetadataFactory.SFM.getSystemFunctions();
    FunctionLibrary fl = new FunctionLibrary(sys, new FunctionTree("foo", new UDFSource(Arrays.asList(method)), true));
    fl.determineNecessaryConversions("concat", DataTypeManager.DefaultDataClasses.STRING, new Expression[] { new Constant(1), new Constant(2) }, new Class[] { DataTypeManager.DefaultDataClasses.INTEGER, DataTypeManager.DefaultDataClasses.INTEGER }, false);
}
Also used : Constant(org.teiid.query.sql.symbol.Constant) FunctionMethod(org.teiid.metadata.FunctionMethod) FunctionParameter(org.teiid.metadata.FunctionParameter) Test(org.junit.Test)

Example 13 with FunctionParameter

use of org.teiid.metadata.FunctionParameter in project teiid by teiid.

the class TestFunctionMethod method testEquivalence3.

@Test
public void testEquivalence3() {
    // $NON-NLS-1$ //$NON-NLS-2$
    FunctionParameter p1 = new FunctionParameter("in", "string");
    // $NON-NLS-1$ //$NON-NLS-2$
    FunctionParameter pout = new FunctionParameter("out", "string");
    FunctionMethod m1 = new // $NON-NLS-1$ //$NON-NLS-2$
    FunctionMethod(// $NON-NLS-1$ //$NON-NLS-2$
    "length", // $NON-NLS-1$ //$NON-NLS-2$
    "", // $NON-NLS-1$ //$NON-NLS-2$
    FunctionCategoryConstants.STRING, // $NON-NLS-1$ //$NON-NLS-2$
    "com.metamatrix.query.function.FunctionMethods", // $NON-NLS-1$ //$NON-NLS-2$
    "length", new FunctionParameter[] { p1 }, pout);
    // $NON-NLS-1$ //$NON-NLS-2$
    FunctionParameter p2 = new FunctionParameter("in", "string");
    // $NON-NLS-1$ //$NON-NLS-2$
    FunctionParameter pout2 = new FunctionParameter("out", "integer");
    FunctionMethod m2 = new // $NON-NLS-1$ //$NON-NLS-2$
    FunctionMethod(// $NON-NLS-1$ //$NON-NLS-2$
    "length", // $NON-NLS-1$ //$NON-NLS-2$
    "", // $NON-NLS-1$ //$NON-NLS-2$
    FunctionCategoryConstants.STRING, // $NON-NLS-1$ //$NON-NLS-2$
    "com.metamatrix.query.function.FunctionMethods", // $NON-NLS-1$ //$NON-NLS-2$
    "length", new FunctionParameter[] { p2 }, pout2);
    UnitTestUtil.helpTestEquivalence(0, m1, m2);
}
Also used : FunctionMethod(org.teiid.metadata.FunctionMethod) FunctionParameter(org.teiid.metadata.FunctionParameter) Test(org.junit.Test)

Example 14 with FunctionParameter

use of org.teiid.metadata.FunctionParameter in project teiid by teiid.

the class TestFunctionMethod method testEquivalence2.

@Test
public void testEquivalence2() {
    // $NON-NLS-1$ //$NON-NLS-2$
    FunctionParameter p1 = new FunctionParameter("in", "string");
    // $NON-NLS-1$ //$NON-NLS-2$
    FunctionParameter pout = new FunctionParameter("out", "string");
    FunctionMethod m1 = new // $NON-NLS-1$ //$NON-NLS-2$
    FunctionMethod(// $NON-NLS-1$ //$NON-NLS-2$
    "length", // $NON-NLS-1$ //$NON-NLS-2$
    "", // $NON-NLS-1$ //$NON-NLS-2$
    FunctionCategoryConstants.STRING, // $NON-NLS-1$ //$NON-NLS-2$
    "com.metamatrix.query.function.FunctionMethods", // $NON-NLS-1$ //$NON-NLS-2$
    "length", new FunctionParameter[] { p1 }, pout);
    // $NON-NLS-1$ //$NON-NLS-2$
    FunctionParameter p2 = new FunctionParameter("in", "integer");
    // $NON-NLS-1$ //$NON-NLS-2$
    FunctionParameter pout2 = new FunctionParameter("out", "string");
    FunctionMethod m2 = new // $NON-NLS-1$ //$NON-NLS-2$
    FunctionMethod(// $NON-NLS-1$ //$NON-NLS-2$
    "length", // $NON-NLS-1$ //$NON-NLS-2$
    "", // $NON-NLS-1$ //$NON-NLS-2$
    FunctionCategoryConstants.STRING, // $NON-NLS-1$ //$NON-NLS-2$
    "com.metamatrix.query.function.FunctionMethods", // $NON-NLS-1$ //$NON-NLS-2$
    "length", new FunctionParameter[] { p2 }, pout2);
    UnitTestUtil.helpTestEquivalence(1, m1, m2);
}
Also used : FunctionMethod(org.teiid.metadata.FunctionMethod) FunctionParameter(org.teiid.metadata.FunctionParameter) Test(org.junit.Test)

Example 15 with FunctionParameter

use of org.teiid.metadata.FunctionParameter in project teiid by teiid.

the class TestAggregateProcessing method addAgg.

private FunctionMethod addAgg(Schema s, String name, Class<?> clazz, String returns) {
    FunctionMethod fm = new FunctionMethod();
    fm.setName(name);
    fm.setInvocationClass(clazz.getName());
    fm.setInvocationMethod("addInput");
    FunctionParameter fp = new FunctionParameter();
    fp.setType(DataTypeManager.DefaultDataTypes.INTEGER);
    fp.setName("arg");
    fp.setVarArg(true);
    fm.getInputParameters().add(fp);
    FunctionParameter fpout = new FunctionParameter();
    fpout.setType(returns);
    fpout.setName("outp");
    fm.setOutputParameter(fpout);
    AggregateAttributes aa = new AggregateAttributes();
    fm.setAggregateAttributes(aa);
    s.getFunctions().put(fm.getName(), fm);
    return fm;
}
Also used : FunctionMethod(org.teiid.metadata.FunctionMethod) AggregateAttributes(org.teiid.metadata.AggregateAttributes) FunctionParameter(org.teiid.metadata.FunctionParameter)

Aggregations

FunctionParameter (org.teiid.metadata.FunctionParameter)36 FunctionMethod (org.teiid.metadata.FunctionMethod)31 Test (org.junit.Test)9 Collection (java.util.Collection)3 HashMap (java.util.HashMap)3 DeployVDBParameter (org.teiid.jdbc.FakeServer.DeployVDBParameter)3 ArrayList (java.util.ArrayList)2 AggregateAttributes (org.teiid.metadata.AggregateAttributes)2 FileInputStream (java.io.FileInputStream)1 Method (java.lang.reflect.Method)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Before (org.junit.Before)1 BeforeClass (org.junit.BeforeClass)1 UserDefinedAggregate (org.teiid.UserDefinedAggregate)1 FunctionExecutionException (org.teiid.api.exception.query.FunctionExecutionException)1 FunctionMetadataException (org.teiid.api.exception.query.FunctionMetadataException)1 TeiidRuntimeException (org.teiid.core.TeiidRuntimeException)1 BinaryType (org.teiid.core.types.BinaryType)1 ReflectionHelper (org.teiid.core.util.ReflectionHelper)1