Search in sources :

Example 26 with ColumnReference

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

the class TestSetQueryImpl method example2.

public static SetQuery example2() throws Exception {
    // $NON-NLS-1$
    NamedTable group = new NamedTable("ted", null, null);
    // $NON-NLS-1$
    ColumnReference element = new ColumnReference(group, "nugent", null, String.class);
    DerivedColumn symbol = new DerivedColumn(null, element);
    List symbols = new ArrayList();
    symbols.add(symbol);
    List items = new ArrayList();
    items.add(group);
    // $NON-NLS-1$
    NamedTable group2 = new NamedTable("dave", null, null);
    // $NON-NLS-1$
    ColumnReference element2 = new ColumnReference(group2, "barry", null, String.class);
    DerivedColumn symbol2 = new DerivedColumn(null, element2);
    List symbols2 = new ArrayList();
    symbols2.add(symbol2);
    List items2 = new ArrayList();
    items2.add(group2);
    Select secondQuery = new Select(symbols2, false, items2, null, null, null, null);
    Select query = new Select(symbols, false, items, null, null, null, null);
    SetQuery setQuery = new SetQuery();
    setQuery.setOperation(SetQuery.Operation.UNION);
    setQuery.setAll(true);
    setQuery.setLeftQuery(query);
    setQuery.setRightQuery(secondQuery);
    return setQuery;
}
Also used : NamedTable(org.teiid.language.NamedTable) SetQuery(org.teiid.language.SetQuery) ArrayList(java.util.ArrayList) Select(org.teiid.language.Select) ArrayList(java.util.ArrayList) List(java.util.List) DerivedColumn(org.teiid.language.DerivedColumn) ColumnReference(org.teiid.language.ColumnReference)

Example 27 with ColumnReference

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

the class TestGroupByImpl method testGetElements.

public void testGetElements() throws Exception {
    GroupBy gb = example();
    assertNotNull(gb.getElements());
    assertEquals(4, gb.getElements().size());
    for (Iterator i = gb.getElements().iterator(); i.hasNext(); ) {
        assertTrue(i.next() instanceof ColumnReference);
    }
}
Also used : GroupBy(org.teiid.language.GroupBy) Iterator(java.util.Iterator) ColumnReference(org.teiid.language.ColumnReference)

Example 28 with ColumnReference

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

the class TestInsertImpl method testExpressionsInInsert.

public void testExpressionsInInsert() throws Exception {
    // $NON-NLS-1$
    Insert insert = example2("a.b");
    assertNotNull(insert.getColumns());
    assertEquals(1, insert.getColumns().size());
    for (Iterator i = insert.getColumns().iterator(); i.hasNext(); ) {
        assertTrue(i.next() instanceof ColumnReference);
    }
    assertNotNull(insert.getValueSource());
    assertEquals(1, ((ExpressionValueSource) insert.getValueSource()).getValues().size());
    for (Iterator i = ((ExpressionValueSource) insert.getValueSource()).getValues().iterator(); i.hasNext(); ) {
        assertTrue(i.next() instanceof Expression);
    }
}
Also used : Expression(org.teiid.language.Expression) Iterator(java.util.Iterator) Insert(org.teiid.language.Insert) ColumnReference(org.teiid.language.ColumnReference) ExpressionValueSource(org.teiid.language.ExpressionValueSource)

Example 29 with ColumnReference

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

the class SpreadsheetInsertVisitor method visit.

public void visit(Insert obj) {
    worksheetTitle = obj.getTable().getName();
    if (obj.getTable().getMetadataObject().getNameInSource() != null) {
        worksheetTitle = obj.getTable().getMetadataObject().getNameInSource();
    }
    worksheetKey = info.getWorksheetByName(worksheetTitle).getId();
    ExpressionValueSource evs = (ExpressionValueSource) obj.getValueSource();
    for (int i = 0; i < evs.getValues().size(); i++) {
        Expression e = evs.getValues().get(i);
        if (!(e instanceof Literal)) {
            throw new SpreadsheetOperationException("Only literals are allowed in the values section");
        }
        Literal l = (Literal) e;
        if (l.getValue() == null) {
            continue;
        }
        ColumnReference columnReference = obj.getColumns().get(i);
        columnNameValuePair.put(columnReference.getMetadataObject().getSourceName(), l.getValue());
    }
}
Also used : Expression(org.teiid.language.Expression) Literal(org.teiid.language.Literal) SpreadsheetOperationException(org.teiid.translator.google.api.SpreadsheetOperationException) ExpressionValueSource(org.teiid.language.ExpressionValueSource) ColumnReference(org.teiid.language.ColumnReference)

Example 30 with ColumnReference

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

the class InfinispanUpdateVisitor method buildInsertPayload.

private InfinispanDocument buildInsertPayload(Insert obj, List<Expression> values) {
    InfinispanDocument targetDocument = null;
    try {
        // table that insert issued for
        Table table = obj.getTable().getMetadataObject();
        Column pkColumn = getPrimaryKey();
        // create the top table parent document, where insert is actually being done at
        targetDocument = buildTargetDocument(table, true);
        // build the payload object from insert
        int elementCount = obj.getColumns().size();
        for (int i = 0; i < elementCount; i++) {
            ColumnReference columnReference = obj.getColumns().get(i);
            Column column = columnReference.getMetadataObject();
            Object value = null;
            if (values.get(i) instanceof Expression) {
                Expression expr = values.get(i);
                value = resolveExpressionValue(expr);
            } else {
                value = values.get(i);
            }
            updateDocument(targetDocument, column, value);
            if (column.equals(pkColumn) || pkColumn.equals(normalizePseudoColumn(column))) {
                targetDocument.setIdentifier(value);
            }
        }
        if (targetDocument.getIdentifier() == null) {
            this.exceptions.add(new TranslatorException(InfinispanPlugin.Util.gs(InfinispanPlugin.Event.TEIID25004, getParentTable().getName())));
        }
    } catch (NumberFormatException e) {
        this.exceptions.add(new TranslatorException(e));
    } catch (TranslatorException e) {
        this.exceptions.add(new TranslatorException(e));
    }
    return targetDocument;
}
Also used : Table(org.teiid.metadata.Table) InfinispanDocument(org.teiid.infinispan.api.InfinispanDocument) Column(org.teiid.metadata.Column) Expression(org.teiid.language.Expression) TranslatorException(org.teiid.translator.TranslatorException) ColumnReference(org.teiid.language.ColumnReference)

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