Search in sources :

Example 46 with Expression

use of org.teiid.query.sql.symbol.Expression in project teiid by teiid.

the class LanguageBridgeFactory method translate.

org.teiid.language.Comparison translate(DependentSetCriteria criteria) {
    Operator operator = Operator.EQ;
    org.teiid.language.Expression arg = null;
    final TupleBuffer tb = criteria.getDependentValueSource().getTupleBuffer();
    if (criteria.getValueExpression() instanceof Array) {
        Array array = (Array) criteria.getValueExpression();
        List<org.teiid.language.Expression> params = new ArrayList<org.teiid.language.Expression>();
        Class<?> baseType = null;
        for (Expression ex : array.getExpressions()) {
            if (baseType == null) {
                baseType = ex.getType();
            } else if (!baseType.equals(ex.getType())) {
                baseType = DataTypeManager.DefaultDataClasses.OBJECT;
            }
            params.add(createParameter(criteria, tb, ex));
        }
        arg = new org.teiid.language.Array(baseType, params);
    } else {
        Expression ex = criteria.getValueExpression();
        arg = createParameter(criteria, tb, ex);
    }
    if (this.dependentSets == null) {
        this.dependentSets = new HashMap<String, List<? extends List<?>>>();
    }
    this.dependentSets.put(criteria.getContextSymbol(), new TupleBufferList(tb));
    Comparison result = new org.teiid.language.Comparison(translate(criteria.getExpression()), arg, operator);
    return result;
}
Also used : Operator(org.teiid.language.Comparison.Operator) TupleBuffer(org.teiid.common.buffer.TupleBuffer) org.teiid.language(org.teiid.language) Array(org.teiid.query.sql.symbol.Array) SearchedCaseExpression(org.teiid.query.sql.symbol.SearchedCaseExpression) Expression(org.teiid.query.sql.symbol.Expression)

Example 47 with Expression

use of org.teiid.query.sql.symbol.Expression in project teiid by teiid.

the class LanguageBridgeFactory method translate.

AggregateFunction translate(AggregateSymbol symbol) {
    List<org.teiid.language.Expression> params = new ArrayList<org.teiid.language.Expression>(symbol.getArgs().length);
    for (Expression expression : symbol.getArgs()) {
        params.add(translate(expression));
    }
    String name = symbol.getAggregateFunction().name();
    if (symbol.getAggregateFunction() == AggregateSymbol.Type.USER_DEFINED) {
        name = symbol.getName();
    }
    AggregateFunction af = new AggregateFunction(name, symbol.isDistinct(), params, symbol.getType());
    af.setCondition(translate(symbol.getCondition()));
    af.setOrderBy(translate(symbol.getOrderBy(), false));
    return af;
}
Also used : SearchedCaseExpression(org.teiid.query.sql.symbol.SearchedCaseExpression) Expression(org.teiid.query.sql.symbol.Expression) org.teiid.language(org.teiid.language)

Example 48 with Expression

use of org.teiid.query.sql.symbol.Expression in project teiid by teiid.

the class BufferManagerImpl method getTypeClasses.

private static Class<?>[] getTypeClasses(final List<? extends Expression> elements) {
    Class<?>[] types = new Class[elements.size()];
    for (ListIterator<? extends Expression> i = elements.listIterator(); i.hasNext(); ) {
        Expression expr = i.next();
        Class<?> type = expr.getType();
        Assertion.isNotNull(type);
        types[i.previousIndex()] = type;
    }
    return types;
}
Also used : Expression(org.teiid.query.sql.symbol.Expression)

Example 49 with Expression

use of org.teiid.query.sql.symbol.Expression 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 50 with Expression

use of org.teiid.query.sql.symbol.Expression 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)

Aggregations

Expression (org.teiid.query.sql.symbol.Expression)257 ElementSymbol (org.teiid.query.sql.symbol.ElementSymbol)104 ArrayList (java.util.ArrayList)74 GroupSymbol (org.teiid.query.sql.symbol.GroupSymbol)54 Test (org.junit.Test)53 PlanNode (org.teiid.query.optimizer.relational.plantree.PlanNode)50 List (java.util.List)49 Constant (org.teiid.query.sql.symbol.Constant)38 SymbolMap (org.teiid.query.sql.util.SymbolMap)37 HashMap (java.util.HashMap)22 LinkedList (java.util.LinkedList)22 Criteria (org.teiid.query.sql.lang.Criteria)22 Map (java.util.Map)21 ClobType (org.teiid.core.types.ClobType)16 CompareCriteria (org.teiid.query.sql.lang.CompareCriteria)16 HashSet (java.util.HashSet)13 LinkedHashSet (java.util.LinkedHashSet)13 AliasSymbol (org.teiid.query.sql.symbol.AliasSymbol)13 SearchedCaseExpression (org.teiid.query.sql.symbol.SearchedCaseExpression)13 OrderBy (org.teiid.query.sql.lang.OrderBy)12