use of org.teiid.metadata.FunctionParameter 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.FunctionParameter 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.FunctionParameter 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);
}
use of org.teiid.metadata.FunctionParameter in project teiid by teiid.
the class TestFunctionMethod method testEquivalence2.
@Test
public void testEquivalence2() {
// $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", "integer");
// $NON-NLS-1$ //$NON-NLS-2$
FunctionParameter pout2 = new FunctionParameter("out", "string");
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(1, m1, m2);
}
use of org.teiid.metadata.FunctionParameter in project teiid by teiid.
the class TestAggregateProcessing method addAgg.
private FunctionMethod addAgg(Schema s, String name, Class<?> clazz, String returns) {
FunctionMethod fm = new FunctionMethod();
fm.setName(name);
fm.setInvocationClass(clazz.getName());
fm.setInvocationMethod("addInput");
FunctionParameter fp = new FunctionParameter();
fp.setType(DataTypeManager.DefaultDataTypes.INTEGER);
fp.setName("arg");
fp.setVarArg(true);
fm.getInputParameters().add(fp);
FunctionParameter fpout = new FunctionParameter();
fpout.setType(returns);
fpout.setName("outp");
fm.setOutputParameter(fpout);
AggregateAttributes aa = new AggregateAttributes();
fm.setAggregateAttributes(aa);
s.getFunctions().put(fm.getName(), fm);
return fm;
}
Aggregations