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