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