Search in sources :

Example 1 with BaseColumn

use of org.teiid.metadata.BaseColumn in project teiid by teiid.

the class ODataFilterVisitor method setCurrentExpression.

private BaseColumn setCurrentExpression(Expression leftExpression) {
    BaseColumn old = currentExpression;
    if (leftExpression instanceof ColumnReference) {
        ColumnReference cr = (ColumnReference) leftExpression;
        currentExpression = cr.getMetadataObject();
    } else if (leftExpression instanceof Function) {
        Function function = (Function) leftExpression;
        currentExpression = function.getMetadataObject().getOutputParameter();
    } else {
        currentExpression = null;
    }
    // we are really looking for the native type, if it's not set then don't bother
    if (currentExpression != null && currentExpression.getNativeType() == null) {
        currentExpression = null;
    }
    return old;
}
Also used : BaseColumn(org.teiid.metadata.BaseColumn)

Example 2 with BaseColumn

use of org.teiid.metadata.BaseColumn in project teiid by teiid.

the class ODataFilterVisitor method visit.

@Override
public void visit(Function obj) {
    if (this.ef.getFunctionModifiers().containsKey(obj.getName())) {
        List<?> parts = this.ef.getFunctionModifiers().get(obj.getName()).translate(obj);
        if (parts != null) {
            // $NON-NLS-1$
            throw new AssertionError("not supported");
        }
    }
    String name = obj.getName();
    List<Expression> args = obj.getParameters();
    if (isInfixFunction(name)) {
        this.filter.append(Tokens.LPAREN);
        if (args != null) {
            for (int i = 0; i < args.size(); i++) {
                append(args.get(i));
                if (i < (args.size() - 1)) {
                    this.filter.append(Tokens.SPACE);
                    this.filter.append(infixFunctions.get(name));
                    this.filter.append(Tokens.SPACE);
                }
            }
        }
        this.filter.append(Tokens.RPAREN);
    } else {
        FunctionMethod method = obj.getMetadataObject();
        if (name.startsWith(method.getCategory())) {
            name = name.substring(method.getCategory().length() + 1);
        }
        this.filter.append(name).append(Tokens.LPAREN);
        if (name.equals("cast")) {
            append(args.get(0));
            this.filter.append(Tokens.COMMA);
            Literal literal = (Literal) args.get(1);
            String type = ODataTypeManager.odataType((String) literal.getValue()).getFullQualifiedName().getFullQualifiedNameAsString();
            this.filter.append(type);
        } else {
            if (args != null && args.size() != 0) {
                if (SourceSystemFunctions.ENDSWITH.equalsIgnoreCase(name)) {
                    append(args.get(1));
                    this.filter.append(Tokens.COMMA);
                    append(args.get(0));
                } else {
                    BaseColumn old = currentExpression;
                    for (int i = 0; i < args.size(); i++) {
                        currentExpression = method.getInputParameters().get(Math.min(i, method.getInputParameters().size() - 1));
                        append(args.get(i));
                        if (i < args.size() - 1) {
                            this.filter.append(Tokens.COMMA);
                        }
                    }
                    currentExpression = old;
                }
            }
        }
        this.filter.append(Tokens.RPAREN);
    }
}
Also used : FunctionMethod(org.teiid.metadata.FunctionMethod) BaseColumn(org.teiid.metadata.BaseColumn)

Example 3 with BaseColumn

use of org.teiid.metadata.BaseColumn in project teiid by teiid.

the class ODataFilterVisitor method visit.

@Override
public void visit(Comparison obj) {
    append(obj.getLeftExpression());
    this.filter.append(Tokens.SPACE);
    switch(obj.getOperator()) {
        case EQ:
            // $NON-NLS-1$
            this.filter.append("eq");
            break;
        case NE:
            // $NON-NLS-1$
            this.filter.append("ne");
            break;
        case LT:
            // $NON-NLS-1$
            this.filter.append("lt");
            break;
        case LE:
            // $NON-NLS-1$
            this.filter.append("le");
            break;
        case GT:
            // $NON-NLS-1$
            this.filter.append("gt");
            break;
        case GE:
            // $NON-NLS-1$
            this.filter.append("ge");
            break;
    }
    this.filter.append(Tokens.SPACE);
    BaseColumn old = setCurrentExpression(obj.getLeftExpression());
    appendRightComparison(obj);
    this.currentExpression = old;
}
Also used : BaseColumn(org.teiid.metadata.BaseColumn)

Aggregations

BaseColumn (org.teiid.metadata.BaseColumn)3 FunctionMethod (org.teiid.metadata.FunctionMethod)1