Search in sources :

Example 46 with FunctionMethod

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

the class SystemSource method addIfNullFunction.

private void addIfNullFunction(String valueType) {
    FunctionMethod nvl = new // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    FunctionMethod(// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    "ifnull", // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    QueryPlugin.Util.getString("SystemSource.Ifnull_desc"), // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    MISCELLANEOUS, // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    FUNCTION_CLASS, // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    "ifnull", new FunctionParameter[] { // $NON-NLS-1$ //$NON-NLS-2$
    new FunctionParameter("value", valueType, QueryPlugin.Util.getString("SystemSource.Ifnull_arg1")), // $NON-NLS-1$ //$NON-NLS-2$
    new FunctionParameter("valueIfNull", valueType, QueryPlugin.Util.getString("SystemSource.Ifnull_arg2")) }, // $NON-NLS-1$ //$NON-NLS-2$
    new FunctionParameter("result", valueType, QueryPlugin.Util.getString("SystemSource.Ifnull_result")));
    nvl.setNullOnNull(false);
    functions.add(nvl);
}
Also used : FunctionMethod(org.teiid.metadata.FunctionMethod) FunctionParameter(org.teiid.metadata.FunctionParameter)

Example 47 with FunctionMethod

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

the class TestFunctionMetadataReader method testLoadFunctionMethods.

public void testLoadFunctionMethods() throws Exception {
    List<FunctionMethod> fns = FunctionMetadataReader.loadFunctionMethods(new FileInputStream(UnitTestUtil.getTestDataPath() + File.separator + "udf.xmi"));
    assertEquals(3, fns.size());
    for (FunctionMethod m : fns) {
        if (m.getName().equals("GetSystemProperty")) {
            assertEquals("MyFunctions", m.getCategory());
            assertEquals("com.metamatrix.dqp.embedded.udf.MyFunctions", m.getInvocationClass());
            assertEquals("getProperty", m.getInvocationMethod());
            assertEquals(PushDown.CAN_PUSHDOWN, m.getPushdown());
            assertEquals(Determinism.DETERMINISTIC, m.getDeterminism());
            assertNull(m.getDescription());
            assertEquals(1, m.getInputParameterCount());
            FunctionParameter in = m.getInputParameters().get(0);
            assertEquals("prop", in.getName());
            assertEquals("string", in.getType());
            assertNull(in.getDescription());
            assertNotNull(m.getOutputParameter());
            assertEquals(FunctionParameter.OUTPUT_PARAMETER_NAME, m.getOutputParameter().getName());
            assertEquals("string", m.getOutputParameter().getType());
        } else if (m.getName().equals("getpushdown")) {
            assertEquals("MyFunctions", m.getCategory());
            assertEquals("com.metamatrix.dqp.embedded.udf.MyFunctions", m.getInvocationClass());
            assertEquals("getPropertyNoArgs", m.getInvocationMethod());
            assertEquals(PushDown.CANNOT_PUSHDOWN, m.getPushdown());
            assertEquals(Determinism.DETERMINISTIC, m.getDeterminism());
            assertNull(m.getDescription());
            assertEquals(0, m.getInputParameterCount());
            assertNotNull(m.getOutputParameter());
            assertEquals(FunctionParameter.OUTPUT_PARAMETER_NAME, m.getOutputParameter().getName());
            assertEquals("string", m.getOutputParameter().getType());
        } else if (m.getName().equals("getxyz")) {
            assertEquals("MyFunctions", m.getCategory());
            assertEquals("com.metamatrix.dqp.embedded.udf.MyFunctions", m.getInvocationClass());
            assertEquals("getPropertyNoArgs", m.getInvocationMethod());
            assertEquals(PushDown.CAN_PUSHDOWN, m.getPushdown());
            assertEquals(Determinism.NONDETERMINISTIC, m.getDeterminism());
            assertNull(m.getDescription());
            assertEquals(0, m.getInputParameterCount());
            assertNotNull(m.getOutputParameter());
            assertEquals(FunctionParameter.OUTPUT_PARAMETER_NAME, m.getOutputParameter().getName());
            assertEquals("string", m.getOutputParameter().getType());
        } else {
            fail("unknown method");
        }
    }
}
Also used : FunctionMethod(org.teiid.metadata.FunctionMethod) FileInputStream(java.io.FileInputStream) FunctionParameter(org.teiid.metadata.FunctionParameter)

Example 48 with FunctionMethod

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

the class TestFunctionTree method testMultiPartName.

@Test
public void testMultiPartName() throws Exception {
    FunctionMethod method = new FunctionMethod(// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    "x.y.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));
    assertNotNull(fl.findFunction("dummy", new Class<?>[] { DataTypeManager.DefaultDataClasses.VARBINARY }));
    assertNotNull(fl.findFunction("y.dummy", new Class<?>[] { DataTypeManager.DefaultDataClasses.VARBINARY }));
}
Also used : FunctionMethod(org.teiid.metadata.FunctionMethod) FunctionParameter(org.teiid.metadata.FunctionParameter) Test(org.junit.Test)

Example 49 with FunctionMethod

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

the class TestFunctionTree method testNullCategory.

@Test
public void testNullCategory() {
    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.MUST_PUSHDOWN, // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    "nonexistentClass", // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    "noMethod", new ArrayList<FunctionParameter>(0), // $NON-NLS-1$
    new FunctionParameter("output", DataTypeManager.DefaultDataTypes.STRING), false, Determinism.DETERMINISTIC);
    Collection<org.teiid.metadata.FunctionMethod> list = Arrays.asList(method);
    FunctionMetadataSource fms = Mockito.mock(FunctionMetadataSource.class);
    Mockito.stub(fms.getFunctionMethods()).toReturn(list);
    FunctionTree ft = new FunctionTree("foo", fms);
    assertEquals(1, ft.getFunctionsInCategory(FunctionCategoryConstants.MISCELLANEOUS).size());
}
Also used : FunctionMethod(org.teiid.metadata.FunctionMethod) FunctionParameter(org.teiid.metadata.FunctionParameter) Test(org.junit.Test)

Example 50 with FunctionMethod

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

the class TestFunctionMethod method testEquivalence1.

@Test
public void testEquivalence1() {
    // $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);
    UnitTestUtil.helpTestEquivalence(0, m1, m1);
}
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