Search in sources :

Example 6 with FunctionParameter

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

the class SystemSource method addBitFunction.

private void addBitFunction(String functionName, String description, String methodName, int parameters, String resultDescription) {
    FunctionParameter[] paramArray = null;
    if (parameters == 1) {
        paramArray = new FunctionParameter[] { // $NON-NLS-1$ //$NON-NLS-2$
        new FunctionParameter("integer", DataTypeManager.DefaultDataTypes.INTEGER, QueryPlugin.Util.getString("SystemSource.Bitfunc_arg1")) };
    } else if (parameters == 2) {
        paramArray = new FunctionParameter[] { // $NON-NLS-1$ //$NON-NLS-2$
        new FunctionParameter("integer1", DataTypeManager.DefaultDataTypes.INTEGER, QueryPlugin.Util.getString("SystemSource.Bitfunc2_arg1")), // $NON-NLS-1$ //$NON-NLS-2$
        new FunctionParameter("integer2", DataTypeManager.DefaultDataTypes.INTEGER, QueryPlugin.Util.getString("SystemSource.Bitfunc2_arg2")) };
    }
    functions.add(new FunctionMethod(functionName, description, NUMERIC, FUNCTION_CLASS, methodName, paramArray, // $NON-NLS-1$
    new FunctionParameter("result", DataTypeManager.DefaultDataTypes.INTEGER, resultDescription)));
}
Also used : FunctionMethod(org.teiid.metadata.FunctionMethod) FunctionParameter(org.teiid.metadata.FunctionParameter)

Example 7 with FunctionParameter

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

the class SystemSource method addQuarterFunction.

private void addQuarterFunction(String name, String methodName, String dateDesc, String timestampDesc, String returnType) {
    functions.add(new FunctionMethod(name, dateDesc, DATETIME, FUNCTION_CLASS, methodName, new FunctionParameter[] { // $NON-NLS-1$
    new FunctionParameter("date", DataTypeManager.DefaultDataTypes.DATE, dateDesc) }, // $NON-NLS-1$
    new FunctionParameter("result", returnType, dateDesc)));
    functions.add(new FunctionMethod(name, timestampDesc, DATETIME, FUNCTION_CLASS, methodName, new FunctionParameter[] { // $NON-NLS-1$
    new FunctionParameter("timestamp", DataTypeManager.DefaultDataTypes.TIMESTAMP, timestampDesc) }, // $NON-NLS-1$
    new FunctionParameter("result", returnType, timestampDesc)));
}
Also used : FunctionMethod(org.teiid.metadata.FunctionMethod) FunctionParameter(org.teiid.metadata.FunctionParameter)

Example 8 with FunctionParameter

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

the class SystemSource method addDateFunction.

private void addDateFunction(String name, String methodName, String dateDesc, String timestampDesc, String returnType) {
    functions.add(new FunctionMethod(name, dateDesc, DATETIME, FUNCTION_CLASS, methodName, new FunctionParameter[] { // $NON-NLS-1$
    new FunctionParameter("date", DataTypeManager.DefaultDataTypes.DATE, dateDesc) }, // $NON-NLS-1$
    new FunctionParameter("result", returnType, dateDesc)));
    functions.add(new FunctionMethod(name, timestampDesc, DATETIME, FUNCTION_CLASS, methodName, new FunctionParameter[] { // $NON-NLS-1$
    new FunctionParameter("timestamp", DataTypeManager.DefaultDataTypes.TIMESTAMP, timestampDesc) }, // $NON-NLS-1$
    new FunctionParameter("result", returnType, timestampDesc)));
}
Also used : FunctionMethod(org.teiid.metadata.FunctionMethod) FunctionParameter(org.teiid.metadata.FunctionParameter)

Example 9 with FunctionParameter

use of org.teiid.metadata.FunctionParameter 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 10 with FunctionParameter

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

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