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;
}
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);
}
}
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);
}
}
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());
}
}
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;
}
Aggregations