Search in sources :

Example 11 with FunctionMethod

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

the class FakeFunctionMetadataSource method getFunctionMethods.

public Collection<org.teiid.metadata.FunctionMethod> getFunctionMethods() {
    List<org.teiid.metadata.FunctionMethod> methods = new ArrayList<org.teiid.metadata.FunctionMethod>();
    methods.add(new // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    FunctionMethod(// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    "xyz", // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    "", // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    "misc", // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    PushDown.MUST_PUSHDOWN, // $NON-NLS-1$
    FakeFunctionMetadataSource.class.getName(), // $NON-NLS-1$
    "xyz", null, new FunctionParameter("out", "integer"), true, // $NON-NLS-1$ //$NON-NLS-2$
    Determinism.DETERMINISTIC));
    // $NON-NLS-1$  //$NON-NLS-2$
    FunctionParameter p1 = new FunctionParameter("astring", "string");
    // $NON-NLS-1$  //$NON-NLS-2$
    FunctionParameter result = new FunctionParameter("trimstring", "string");
    // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
    FunctionMethod method = new FunctionMethod("MYRTRIM", "", "", FakeFunctionMetadataSource.class.getName(), "myrtrim", new FunctionParameter[] { p1 }, result);
    method.setPushdown(PushDown.CAN_PUSHDOWN);
    methods.add(method);
    // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    FunctionMethod method2 = new FunctionMethod("misc.namespace.func", "", "", null, null, new FunctionParameter[] { p1 }, result);
    method2.setPushdown(PushDown.MUST_PUSHDOWN);
    methods.add(method2);
    // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    FunctionMethod method3 = new FunctionMethod("parsedate_", "", "", null, null, new FunctionParameter[] { p1 }, new FunctionParameter("", DataTypeManager.DefaultDataTypes.DATE));
    method3.setPushdown(PushDown.MUST_PUSHDOWN);
    methods.add(method3);
    // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    FunctionMethod method4 = new FunctionMethod("FIRST_VALUE", "", "", null, null, new FunctionParameter[] { p1 }, result);
    method4.setPushdown(PushDown.MUST_PUSHDOWN);
    method4.setAggregateAttributes(new AggregateAttributes());
    methods.add(method4);
    return methods;
}
Also used : ArrayList(java.util.ArrayList) FunctionMethod(org.teiid.metadata.FunctionMethod) AggregateAttributes(org.teiid.metadata.AggregateAttributes) FunctionParameter(org.teiid.metadata.FunctionParameter)

Example 12 with FunctionMethod

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

the class TestFunctionTree method testVarbinary.

@Test
public void testVarbinary() throws Exception {
    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.CANNOT_PUSHDOWN, // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    TestFunctionTree.class.getName(), // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    "toString", // $NON-NLS-1$
    Arrays.asList(new FunctionParameter("in", DataTypeManager.DefaultDataTypes.VARBINARY)), // $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));
    FunctionDescriptor fd = fl.findFunction("dummy", new Class<?>[] { DataTypeManager.DefaultDataClasses.VARBINARY });
    String hello = "hello";
    assertEquals(hello, fd.invokeFunction(new Object[] { new BinaryType(hello.getBytes()) }, null, null));
}
Also used : BinaryType(org.teiid.core.types.BinaryType) FunctionMethod(org.teiid.metadata.FunctionMethod) FunctionParameter(org.teiid.metadata.FunctionParameter) Test(org.junit.Test)

Example 13 with FunctionMethod

use of org.teiid.metadata.FunctionMethod 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 14 with FunctionMethod

use of org.teiid.metadata.FunctionMethod 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 15 with FunctionMethod

use of org.teiid.metadata.FunctionMethod 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)

Aggregations

FunctionMethod (org.teiid.metadata.FunctionMethod)63 FunctionParameter (org.teiid.metadata.FunctionParameter)31 Test (org.junit.Test)15 ArrayList (java.util.ArrayList)9 Schema (org.teiid.metadata.Schema)6 TransformationMetadata (org.teiid.query.metadata.TransformationMetadata)6 IOException (java.io.IOException)5 MetadataStore (org.teiid.metadata.MetadataStore)5 List (java.util.List)4 TeiidRuntimeException (org.teiid.core.TeiidRuntimeException)4 BasicSourceCapabilities (org.teiid.query.optimizer.capabilities.BasicSourceCapabilities)4 Collection (java.util.Collection)3 HashMap (java.util.HashMap)3 LinkedList (java.util.LinkedList)3 XMLStreamException (javax.xml.stream.XMLStreamException)3 ConnectorManager (org.teiid.dqp.internal.datamgr.ConnectorManager)3 DeployVDBParameter (org.teiid.jdbc.FakeServer.DeployVDBParameter)3 AggregateAttributes (org.teiid.metadata.AggregateAttributes)3 Procedure (org.teiid.metadata.Procedure)3 UDFSource (org.teiid.query.function.UDFSource)3