use of org.teiid.language.DerivedColumn in project teiid by teiid.
the class CoherenceVisitor method visit.
public void visit(Select query) {
super.visit(query);
Iterator<DerivedColumn> selectSymbolItr = query.getDerivedColumns().iterator();
attributeNames = new String[query.getDerivedColumns().size()];
attributeTypes = new Class[query.getDerivedColumns().size()];
int i = 0;
while (selectSymbolItr.hasNext()) {
Column e = getElementFromSymbol(selectSymbolItr.next());
attributeNames[i] = this.getNameFromElement(e);
attributeTypes[i] = e.getJavaType();
i++;
}
List<TableReference> tables = query.getFrom();
TableReference t = tables.get(0);
if (t instanceof NamedTable) {
Table group = ((NamedTable) t).getMetadataObject();
tableName = group.getName();
}
}
use of org.teiid.language.DerivedColumn in project teiid by teiid.
the class PhoenixExecutionFactory method translateCommand.
@Override
public List<?> translateCommand(Command command, ExecutionContext context) {
if (command instanceof SetQuery) {
SetQuery set = (SetQuery) command;
if (!set.isAll()) {
// distinct is not supported, convert to an inline view and add distinct
Select s = new Select();
s.setDistinct(true);
s.setDerivedColumns(new ArrayList<DerivedColumn>());
s.setOrderBy(set.getOrderBy());
for (DerivedColumn dc : set.getProjectedQuery().getDerivedColumns()) {
// it's expected that the columns will be aliases
Assertion.assertTrue(dc.getAlias() != null);
ColumnReference cr = new ColumnReference(null, dc.getAlias(), null, dc.getExpression().getType());
s.getDerivedColumns().add(new DerivedColumn(null, cr));
}
set.setOrderBy(null);
s.setLimit(set.getLimit());
set.setLimit(null);
set.setAll(true);
// $NON-NLS-1$
s.setFrom(Arrays.asList((TableReference) new DerivedTable(set, "x")));
return Arrays.asList(s);
}
}
return super.translateCommand(command, context);
}
use of org.teiid.language.DerivedColumn in project teiid by teiid.
the class YahooExecution method getNeededColumns.
/**
* @param select
* @return
* @throws TranslatorException
*/
static int[] getNeededColumns(List<DerivedColumn> select) throws TranslatorException {
int[] cols = new int[select.size()];
Iterator<DerivedColumn> iter = select.iterator();
for (int i = 0; iter.hasNext(); i++) {
DerivedColumn symbol = iter.next();
Expression expr = symbol.getExpression();
if (expr instanceof ColumnReference) {
Column element = ((ColumnReference) expr).getMetadataObject();
cols[i] = element.getPosition();
} else {
// $NON-NLS-1$
throw new TranslatorException(YahooPlugin.Util.getString("YahooExecution.Invalid_select_symbol", expr));
}
}
return cols;
}
use of org.teiid.language.DerivedColumn 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.DerivedColumn in project teiid by teiid.
the class ExcelQueryVisitor method visit.
@Override
public void visit(DerivedColumn obj) {
visitNode(obj.getExpression());
Column column = (Column) this.onGoingExpression.pop();
String str = column.getProperty(ExcelMetadataProcessor.CELL_NUMBER, false);
if (str == null) {
this.exceptions.add(new TranslatorException(ExcelPlugin.Event.TEIID23007, ExcelPlugin.Util.gs(ExcelPlugin.Event.TEIID23007, column.getName())));
return;
}
if (str.equalsIgnoreCase(ExcelMetadataProcessor.ROW_ID)) {
this.projectedColumns.add(-1);
} else {
this.projectedColumns.add(Integer.valueOf(str));
}
}
Aggregations