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)));
}
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)));
}
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)));
}
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;
}
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));
}
Aggregations