Search in sources :

Example 1 with Condition

use of org.teiid.language.Condition in project teiid by teiid.

the class ODataQuery method processFilter.

protected String processFilter(Condition condition) throws TranslatorException {
    List<Condition> crits = LanguageUtil.separateCriteriaByAnd(condition);
    if (!crits.isEmpty()) {
        for (Iterator<Condition> iter = crits.iterator(); iter.hasNext(); ) {
            Condition crit = iter.next();
            ODataFilterVisitor visitor = new ODataFilterVisitor(this.executionFactory, this.metadata, this);
            visitor.appendFilter(crit);
        }
    }
    StringBuilder sb = new StringBuilder();
    if (this.rootDocument.getFilter() != null) {
        sb.append(this.rootDocument.getFilter());
    }
    for (ODataDocumentNode use : this.complexTables) {
        if (use.getFilter() != null) {
            if (sb.length() > 0) {
                sb.append(" and ");
            }
            sb.append(use.getFilter());
        }
    }
    return sb.length() == 0 ? null : sb.toString();
}
Also used : Condition(org.teiid.language.Condition)

Example 2 with Condition

use of org.teiid.language.Condition in project teiid by teiid.

the class ConcatFunctionModifier method translate.

@Override
public List<?> translate(Function function) {
    Expression a = function.getParameters().get(0);
    Expression b = function.getParameters().get(1);
    List<Condition> crits = new ArrayList<Condition>();
    Literal nullValue = langFactory.createLiteral(null, TypeFacility.RUNTIME_TYPES.STRING);
    if (isNull(a)) {
        return Arrays.asList(nullValue);
    } else if (!isNotNull(a)) {
        crits.add(langFactory.createIsNullCriteria(a, false));
    }
    if (isNull(b)) {
        return Arrays.asList(nullValue);
    } else if (!isNotNull(b)) {
        crits.add(langFactory.createIsNullCriteria(b, false));
    }
    Condition crit = null;
    if (crits.isEmpty()) {
        return null;
    } else if (crits.size() == 1) {
        crit = crits.get(0);
    } else {
        crit = langFactory.createAndOr(Operator.OR, crits.get(0), crits.get(1));
    }
    List<SearchedWhenClause> cases = Arrays.asList(langFactory.createSearchedWhenCondition(crit, nullValue));
    return Arrays.asList(langFactory.createSearchedCaseExpression(cases, function, TypeFacility.RUNTIME_TYPES.STRING));
}
Also used : Condition(org.teiid.language.Condition) SearchedWhenClause(org.teiid.language.SearchedWhenClause) Expression(org.teiid.language.Expression) Literal(org.teiid.language.Literal) ArrayList(java.util.ArrayList)

Example 3 with Condition

use of org.teiid.language.Condition in project teiid by teiid.

the class TestLanguageUtil method convertCriteria.

private Condition convertCriteria(String criteriaStr) {
    // Create ICriteria from criteriaStr
    TranslationUtility util = FakeTranslationFactory.getInstance().getBQTTranslationUtility();
    // $NON-NLS-1$
    String sql = "SELECT IntKey FROM BQT1.SmallA WHERE " + criteriaStr;
    Select query = (Select) util.parseCommand(sql);
    Condition criteria = query.getWhere();
    return criteria;
}
Also used : Condition(org.teiid.language.Condition) TranslationUtility(org.teiid.cdk.api.TranslationUtility) Select(org.teiid.language.Select)

Example 4 with Condition

use of org.teiid.language.Condition in project teiid by teiid.

the class CoherenceUpdateExecution method updateChildObject.

private void updateChildObject(Table t) throws TranslatorException {
    List<ForeignKey> fks = t.getForeignKeys();
    ForeignKey fk = fks.get(0);
    Table parentTable = fk.getParent();
    // the name of the method to obtain the collection is the nameInSource of the foreginKey
    String parentToChildMethod = fk.getNameInSource();
    if (parentToChildMethod == null) {
        // $NON-NLS-1$
        final String msg = CoherencePlugin.Util.getString("CoherenceUpdateExecution.noNameInSourceForForeingKey", new Object[] { fk.getName() });
        throw new TranslatorException(msg);
    }
    // there must only be 1 column in the primary key
    String parentColName = visitor.getNameFromElement(fk.getPrimaryKey().getColumns().get(0));
    List<SetClause> updateList = ((Update) command).getChanges();
    Condition criteria = ((Update) command).getWhere();
    ColumnReference leftElement;
    Expression rightExpr;
    String nameLeftElement;
    Object valueRightExpr;
    // API).
    for (int i = 0; i < updateList.size(); i++) {
        SetClause setClause = updateList.get(i);
        // trust that connector API is right and left side
        // will always be an IElement
        leftElement = setClause.getSymbol();
        // call utility method to get NameInSource/Name for element
        nameLeftElement = visitor.getNameFromElement(leftElement.getMetadataObject());
        // get right expression - if it is not a literal we
        // can't handle that so throw an exception
        rightExpr = setClause.getValue();
        // if (!(rightExpr instanceof Literal)) {
        // final String msg = CoherencePlugin.Util.getString("LDAPUpdateExecution.valueNotLiteralError",nameLeftElement); //$NON-NLS-1$
        // throw new TranslatorException(msg);
        // }
        valueRightExpr = ((Literal) rightExpr).getValue();
    // add in the modification as a replacement - meaning
    // any existing value(s) for this attribute will
    // be replaced by the new value.  If the attribute
    // didn't exist, it will automatically be created
    // TODO - since null is a valid attribute
    // value, we don't do any special handling of it right
    // now.  But maybe null should mean to delete an
    // attribute?
    }
}
Also used : Condition(org.teiid.language.Condition) Table(org.teiid.metadata.Table) ForeignKey(org.teiid.metadata.ForeignKey) Update(org.teiid.language.Update) Expression(org.teiid.language.Expression) TranslatorException(org.teiid.translator.TranslatorException) SetClause(org.teiid.language.SetClause) ColumnReference(org.teiid.language.ColumnReference)

Example 5 with Condition

use of org.teiid.language.Condition in project teiid by teiid.

the class TeradataSQLConversionVisitor method visit.

@Override
public void visit(In obj) {
    List<Expression> exprs = obj.getRightExpressions();
    boolean decompose = false;
    for (Expression expr : exprs) {
        if (!(expr instanceof Literal)) {
            decompose = true;
            break;
        }
    }
    if (decompose) {
        List<Expression> literals = new ArrayList<Expression>();
        Comparison.Operator opCode = obj.isNegated() ? Comparison.Operator.NE : Comparison.Operator.EQ;
        if (exprs.size() > 1) {
            Condition left = null;
            for (Expression expr : obj.getRightExpressions()) {
                if (expr instanceof Literal) {
                    literals.add(expr);
                } else {
                    if (left == null) {
                        left = LanguageFactory.INSTANCE.createCompareCriteria(opCode, obj.getLeftExpression(), expr);
                    } else {
                        left = LanguageFactory.INSTANCE.createAndOr(obj.isNegated() ? Operator.AND : Operator.OR, left, LanguageFactory.INSTANCE.createCompareCriteria(opCode, obj.getLeftExpression(), expr));
                    }
                }
            }
            if (!literals.isEmpty()) {
                left = LanguageFactory.INSTANCE.createAndOr(obj.isNegated() ? Operator.AND : Operator.OR, left, new In(obj.getLeftExpression(), literals, obj.isNegated()));
            }
            buffer.append(Tokens.LPAREN);
            super.visit((AndOr) left);
            buffer.append(Tokens.RPAREN);
        } else {
            super.visit(LanguageFactory.INSTANCE.createCompareCriteria(opCode, obj.getLeftExpression(), exprs.get(0)));
        }
    } else {
        super.visit(obj);
    }
}
Also used : Condition(org.teiid.language.Condition) Expression(org.teiid.language.Expression) Comparison(org.teiid.language.Comparison) In(org.teiid.language.In) Literal(org.teiid.language.Literal) ArrayList(java.util.ArrayList)

Aggregations

Condition (org.teiid.language.Condition)8 Expression (org.teiid.language.Expression)3 ArrayList (java.util.ArrayList)2 Comparison (org.teiid.language.Comparison)2 Literal (org.teiid.language.Literal)2 HashSet (java.util.HashSet)1 TranslationUtility (org.teiid.cdk.api.TranslationUtility)1 ColumnReference (org.teiid.language.ColumnReference)1 In (org.teiid.language.In)1 SearchedWhenClause (org.teiid.language.SearchedWhenClause)1 Select (org.teiid.language.Select)1 SetClause (org.teiid.language.SetClause)1 Update (org.teiid.language.Update)1 ForeignKey (org.teiid.metadata.ForeignKey)1 Table (org.teiid.metadata.Table)1 TranslatorException (org.teiid.translator.TranslatorException)1