Search in sources :

Example 31 with ColumnReference

use of org.teiid.language.ColumnReference 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)

Example 32 with ColumnReference

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

the class TestMetadataObject method getElementID.

// ################ TEST ELEMENT METADATAID ######################
public Column getElementID(String groupName, String elementName, TranslationUtility transUtil) {
    // $NON-NLS-1$ //$NON-NLS-2$
    Select query = (Select) transUtil.parseCommand("SELECT " + elementName + " FROM " + groupName);
    DerivedColumn symbol = query.getDerivedColumns().get(0);
    ColumnReference element = (ColumnReference) symbol.getExpression();
    return element.getMetadataObject();
}
Also used : Select(org.teiid.language.Select) DerivedColumn(org.teiid.language.DerivedColumn) ColumnReference(org.teiid.language.ColumnReference)

Example 33 with ColumnReference

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

the class TestCollectorVisitor method test1.

@Test
public void test1() {
    // $NON-NLS-1$
    NamedTable g1 = new NamedTable("g1", null, null);
    // $NON-NLS-1$
    ColumnReference e1 = new ColumnReference(g1, "e1", null, String.class);
    // $NON-NLS-1$ //$NON-NLS-2$
    helpTestElementsUsedByGroups(e1, new String[] { "g1.e1" }, new String[] { "g1" });
}
Also used : NamedTable(org.teiid.language.NamedTable) ColumnReference(org.teiid.language.ColumnReference) Test(org.junit.Test)

Example 34 with ColumnReference

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

the class TestCollectorVisitor method example1.

public LanguageObject example1() {
    // $NON-NLS-1$
    NamedTable g = new NamedTable("g1", null, null);
    List symbols = new ArrayList();
    // $NON-NLS-1$
    symbols.add(new ColumnReference(g, "e1", null, String.class));
    // $NON-NLS-1$ //$NON-NLS-2$
    Function function = new Function("length", Arrays.asList(new ColumnReference(g, "e2", null, String.class)), Integer.class);
    symbols.add(function);
    List groups = new ArrayList();
    groups.add(g);
    Select q = new Select(symbols, false, groups, null, null, null, null);
    return q;
}
Also used : NamedTable(org.teiid.language.NamedTable) Function(org.teiid.language.Function) ArrayList(java.util.ArrayList) Select(org.teiid.language.Select) ArrayList(java.util.ArrayList) List(java.util.List) ColumnReference(org.teiid.language.ColumnReference)

Example 35 with ColumnReference

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

the class TestCollectorVisitor method test2.

@Test
public void test2() {
    // $NON-NLS-1$
    NamedTable g1 = new NamedTable("g1", null, null);
    // $NON-NLS-1$
    ColumnReference e1 = new ColumnReference(g1, "e1", null, String.class);
    // $NON-NLS-1$
    ColumnReference e2 = new ColumnReference(g1, "e2", null, String.class);
    Comparison cc = new Comparison(e1, e2, Operator.EQ);
    // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    helpTestElementsUsedByGroups(cc, new String[] { "g1.e1", "g1.e2" }, new String[] { "g1" });
}
Also used : NamedTable(org.teiid.language.NamedTable) Comparison(org.teiid.language.Comparison) ColumnReference(org.teiid.language.ColumnReference) Test(org.junit.Test)

Aggregations

ColumnReference (org.teiid.language.ColumnReference)35 Expression (org.teiid.language.Expression)14 NamedTable (org.teiid.language.NamedTable)13 Column (org.teiid.metadata.Column)12 ArrayList (java.util.ArrayList)11 TranslatorException (org.teiid.translator.TranslatorException)11 ExpressionValueSource (org.teiid.language.ExpressionValueSource)10 Literal (org.teiid.language.Literal)10 Table (org.teiid.metadata.Table)10 DerivedColumn (org.teiid.language.DerivedColumn)8 Test (org.junit.Test)7 Select (org.teiid.language.Select)6 Insert (org.teiid.language.Insert)5 List (java.util.List)4 Iterator (java.util.Iterator)3 Function (org.teiid.language.Function)3 Parameter (org.teiid.language.Parameter)3 SetQuery (org.teiid.language.SetQuery)3 RuntimeMetadata (org.teiid.metadata.RuntimeMetadata)3 DataNotAvailableException (org.teiid.translator.DataNotAvailableException)3