Search in sources :

Example 61 with Expression

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

the class IdentifierFunctionModifier method translate.

public List<?> translate(Function function) {
    List<Object> objs = new ArrayList<Object>();
    List<Expression> parms = function.getParameters();
    objs.add(function.getName().substring(function.getName().indexOf('_') + 1));
    objs.add(SQLConstants.Tokens.LPAREN);
    for (Iterator<Expression> iter = parms.iterator(); iter.hasNext(); ) {
        Expression expr = iter.next();
        if (expr instanceof ColumnReference) {
            boolean dotAll = false;
            boolean useSelector = false;
            ColumnReference cr = (ColumnReference) expr;
            Column c = cr.getMetadataObject();
            if (c != null) {
                if ("\"mode:properties\"".equalsIgnoreCase(c.getSourceName())) {
                    // $NON-NLS-1$
                    dotAll = true;
                    useSelector = true;
                } else if ("\"jcr:path\"".equalsIgnoreCase(c.getSourceName())) {
                    // $NON-NLS-1$
                    useSelector = true;
                }
            }
            if (useSelector) {
                NamedTable nt = ((ColumnReference) expr).getTable();
                if (nt.getCorrelationName() != null) {
                    objs.add(nt.getCorrelationName());
                } else {
                    objs.add(nt);
                }
            } else {
                objs.add(expr);
            }
            if (dotAll) {
                // $NON-NLS-1$
                objs.add(".*");
            }
        } else {
            objs.add(expr);
        }
        if (iter.hasNext()) {
            // $NON-NLS-1$
            objs.add(", ");
        }
    }
    objs.add(SQLConstants.Tokens.RPAREN);
    return objs;
}
Also used : NamedTable(org.teiid.language.NamedTable) Expression(org.teiid.language.Expression) Column(org.teiid.metadata.Column) ArrayList(java.util.ArrayList) ColumnReference(org.teiid.language.ColumnReference)

Aggregations

Expression (org.teiid.language.Expression)61 ArrayList (java.util.ArrayList)18 ExpressionValueSource (org.teiid.language.ExpressionValueSource)18 Literal (org.teiid.language.Literal)17 TranslatorException (org.teiid.translator.TranslatorException)16 ColumnReference (org.teiid.language.ColumnReference)14 Function (org.teiid.language.Function)13 Column (org.teiid.metadata.Column)12 Insert (org.teiid.language.Insert)11 List (java.util.List)10 Table (org.teiid.metadata.Table)9 BigInteger (java.math.BigInteger)7 Test (org.junit.Test)7 Parameter (org.teiid.language.Parameter)7 Iterator (java.util.Iterator)5 Comparison (org.teiid.language.Comparison)5 Connection (java.sql.Connection)4 PreparedStatement (java.sql.PreparedStatement)4 FakeExecutionContextImpl (org.teiid.dqp.internal.datamgr.FakeExecutionContextImpl)4 NamedTable (org.teiid.language.NamedTable)4