Search in sources :

Example 1 with FunctionLibrary

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;
        }
    };
}
Also used : BasicQueryMetadataWrapper(org.teiid.query.metadata.BasicQueryMetadataWrapper) FunctionLibrary(org.teiid.query.function.FunctionLibrary)

Example 2 with 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();
}
Also used : FunctionTree(org.teiid.query.function.FunctionTree) FunctionLibrary(org.teiid.query.function.FunctionLibrary) FunctionMethod(org.teiid.metadata.FunctionMethod) TreeMap(java.util.TreeMap)

Example 3 with FunctionLibrary

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);
}
Also used : Function(org.teiid.query.sql.symbol.Function) Expression(org.teiid.query.sql.symbol.Expression) Constant(org.teiid.query.sql.symbol.Constant) FunctionLibrary(org.teiid.query.function.FunctionLibrary) FunctionDescriptor(org.teiid.query.function.FunctionDescriptor) Test(org.junit.Test)

Example 4 with FunctionLibrary

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);
}
Also used : ElementSymbol(org.teiid.query.sql.symbol.ElementSymbol) Function(org.teiid.query.sql.symbol.Function) Expression(org.teiid.query.sql.symbol.Expression) Constant(org.teiid.query.sql.symbol.Constant) FunctionLibrary(org.teiid.query.function.FunctionLibrary) FunctionDescriptor(org.teiid.query.function.FunctionDescriptor) Test(org.junit.Test)

Example 5 with FunctionLibrary

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);
}
Also used : ElementSymbol(org.teiid.query.sql.symbol.ElementSymbol) Function(org.teiid.query.sql.symbol.Function) Expression(org.teiid.query.sql.symbol.Expression) Constant(org.teiid.query.sql.symbol.Constant) FunctionLibrary(org.teiid.query.function.FunctionLibrary) FunctionDescriptor(org.teiid.query.function.FunctionDescriptor) Test(org.junit.Test)

Aggregations

FunctionLibrary (org.teiid.query.function.FunctionLibrary)10 FunctionDescriptor (org.teiid.query.function.FunctionDescriptor)7 Test (org.junit.Test)3 LanguageObject (org.teiid.query.sql.LanguageObject)3 Constant (org.teiid.query.sql.symbol.Constant)3 Expression (org.teiid.query.sql.symbol.Expression)3 Function (org.teiid.query.sql.symbol.Function)3 FunctionExecutionException (org.teiid.api.exception.query.FunctionExecutionException)2 BlockedException (org.teiid.common.buffer.BlockedException)2 FunctionTree (org.teiid.query.function.FunctionTree)2 ElementSymbol (org.teiid.query.sql.symbol.ElementSymbol)2 BigInteger (java.math.BigInteger)1 java.util (java.util)1 TreeMap (java.util.TreeMap)1 QueryValidatorException (org.teiid.api.exception.query.QueryValidatorException)1 Transform (org.teiid.core.types.Transform)1 FunctionMethod (org.teiid.metadata.FunctionMethod)1 SystemFunctionManager (org.teiid.query.function.SystemFunctionManager)1 UDFSource (org.teiid.query.function.UDFSource)1 BasicQueryMetadataWrapper (org.teiid.query.metadata.BasicQueryMetadataWrapper)1