use of org.teiid.query.function.FunctionLibrary in project teiid by teiid.
the class TranslationUtility method initWrapper.
private void initWrapper(QueryMetadataInterface acutalMetadata) {
functionLibrary = acutalMetadata.getFunctionLibrary();
this.functions.addAll(Arrays.asList(this.functionLibrary.getUserFunctions()));
metadata = new BasicQueryMetadataWrapper(acutalMetadata) {
@Override
public FunctionLibrary getFunctionLibrary() {
return functionLibrary;
}
};
}
use of org.teiid.query.function.FunctionLibrary in project teiid by teiid.
the class TableSystemTable method getChildren.
@Override
protected NavigableMap<String, FunctionMethod> getChildren(Schema s, TransformationMetadata metadata) {
// since there is no proper schema for a UDF model, no results will show up for legacy functions
if (s.getName().equals(CoreConstants.SYSTEM_MODEL)) {
// currently all system functions are contributed via alternative mechanisms
// system source, push down functions.
FunctionLibrary library = metadata.getFunctionLibrary();
FunctionTree tree = library.getSystemFunctions();
FunctionTree[] userFuncs = library.getUserFunctions();
TreeMap<String, FunctionMethod> functions = new TreeMap<String, FunctionMethod>(String.CASE_INSENSITIVE_ORDER);
for (FunctionTree userFunc : userFuncs) {
if (userFunc.getSchemaName().equals(CoreConstants.SYSTEM_MODEL)) {
functions.putAll(userFunc.getFunctionsByUuid());
}
}
functions.putAll(tree.getFunctionsByUuid());
return functions;
}
return s.getFunctions();
}
use of org.teiid.query.function.FunctionLibrary in project teiid by teiid.
the class TestResolver method testUser.
/**
* test jdbc USER method
*/
@Test
public void testUser() {
// String sql = "select intkey from SmallA where user() = 'bqt2'";
// Expected left expression
FunctionLibrary library = RealMetadataFactory.SFM.getSystemFunctionLibrary();
FunctionDescriptor fd = library.findFunction(FunctionLibrary.USER, new Class[] {});
Function user = new Function(fd.getName(), new Expression[] {});
user.setFunctionDescriptor(fd);
// Expected criteria
CompareCriteria expected = new CompareCriteria();
// Expected right expression
// $NON-NLS-1$
Expression e1 = new Constant("bqt2", String.class);
// Expected left expression
expected.setLeftExpression(user);
expected.setOperator(CompareCriteria.EQ);
expected.setRightExpression(e1);
// Resolve the query and check against expected objects
// $NON-NLS-1$
CompareCriteria actual = (CompareCriteria) helpResolveCriteria("user()='bqt2'");
// $NON-NLS-1$
assertEquals("Did not match expected criteria", expected, actual);
}
use of org.teiid.query.function.FunctionLibrary in project teiid by teiid.
the class TestResolver method testStringConversion2.
@Test
public void testStringConversion2() {
// Expected left expression
// $NON-NLS-1$
ElementSymbol e1 = new ElementSymbol("pm3.g1.e2");
e1.setType(DataTypeManager.DefaultDataClasses.DATE);
// Expected right expression
Class srcType = DataTypeManager.DefaultDataClasses.STRING;
String tgtTypeName = DataTypeManager.DefaultDataTypes.DATE;
// $NON-NLS-1$
Expression expression = new Constant("2003-02-27");
FunctionLibrary library = RealMetadataFactory.SFM.getSystemFunctionLibrary();
FunctionDescriptor fd = library.findFunction(FunctionLibrary.CONVERT, new Class[] { srcType, DataTypeManager.DefaultDataClasses.STRING });
Function conversion = new Function(fd.getName(), new Expression[] { expression, new Constant(tgtTypeName) });
conversion.setType(DataTypeManager.getDataTypeClass(tgtTypeName));
conversion.setFunctionDescriptor(fd);
conversion.makeImplicit();
// Expected criteria
CompareCriteria expected = new CompareCriteria();
expected.setLeftExpression(conversion);
expected.setOperator(CompareCriteria.EQ);
expected.setRightExpression(e1);
// Resolve the query and check against expected objects
// $NON-NLS-1$
CompareCriteria actual = (CompareCriteria) helpResolveCriteria("'2003-02-27'=pm3.g1.e2");
// if (! actual.getLeftExpression().equals(expected.getLeftExpression())) {
// fail("Left expressions not equal");
// } else if (!actual.getRightExpression().equals(expected.getRightExpression())) {
// fail("Right expressions not equal");
// }
// $NON-NLS-1$
assertEquals("Did not match expected criteria", expected, actual);
}
use of org.teiid.query.function.FunctionLibrary in project teiid by teiid.
the class TestResolver method testStringConversion1.
@Test
public void testStringConversion1() {
// Expected left expression
// $NON-NLS-1$
ElementSymbol e1 = new ElementSymbol("pm3.g1.e2");
e1.setType(DataTypeManager.DefaultDataClasses.DATE);
// Expected right expression
Class srcType = DataTypeManager.DefaultDataClasses.STRING;
String tgtTypeName = DataTypeManager.DefaultDataTypes.DATE;
// $NON-NLS-1$
Expression expression = new Constant("2003-02-27");
FunctionLibrary library = RealMetadataFactory.SFM.getSystemFunctionLibrary();
FunctionDescriptor fd = library.findFunction(FunctionLibrary.CONVERT, new Class[] { srcType, DataTypeManager.DefaultDataClasses.STRING });
Function conversion = new Function(fd.getName(), new Expression[] { expression, new Constant(tgtTypeName) });
conversion.setType(DataTypeManager.getDataTypeClass(tgtTypeName));
conversion.setFunctionDescriptor(fd);
conversion.makeImplicit();
// Expected criteria
CompareCriteria expected = new CompareCriteria();
expected.setLeftExpression(e1);
expected.setOperator(CompareCriteria.EQ);
expected.setRightExpression(conversion);
// Resolve the query and check against expected objects
// $NON-NLS-1$
CompareCriteria actual = (CompareCriteria) helpResolveCriteria("pm3.g1.e2='2003-02-27'");
// $NON-NLS-1$
assertEquals("Did not match expected criteria", expected, actual);
}
Aggregations