Search in sources :

Example 6 with DerivedColumn

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();
    }
}
Also used : NamedTable(org.teiid.language.NamedTable) TableReference(org.teiid.language.TableReference) NamedTable(org.teiid.language.NamedTable) Table(org.teiid.metadata.Table) Column(org.teiid.metadata.Column) DerivedColumn(org.teiid.language.DerivedColumn) DerivedColumn(org.teiid.language.DerivedColumn)

Example 7 with DerivedColumn

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);
}
Also used : TableReference(org.teiid.language.TableReference) SetQuery(org.teiid.language.SetQuery) DerivedTable(org.teiid.language.DerivedTable) Select(org.teiid.language.Select) DerivedColumn(org.teiid.language.DerivedColumn) ColumnReference(org.teiid.language.ColumnReference)

Example 8 with DerivedColumn

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;
}
Also used : Expression(org.teiid.language.Expression) Column(org.teiid.metadata.Column) DerivedColumn(org.teiid.language.DerivedColumn) TranslatorException(org.teiid.translator.TranslatorException) DerivedColumn(org.teiid.language.DerivedColumn) ColumnReference(org.teiid.language.ColumnReference)

Example 9 with DerivedColumn

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;
}
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 10 with DerivedColumn

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));
    }
}
Also used : Column(org.teiid.metadata.Column) DerivedColumn(org.teiid.language.DerivedColumn) TranslatorException(org.teiid.translator.TranslatorException)

Aggregations

DerivedColumn (org.teiid.language.DerivedColumn)14 Select (org.teiid.language.Select)9 ColumnReference (org.teiid.language.ColumnReference)7 ArrayList (java.util.ArrayList)5 NamedTable (org.teiid.language.NamedTable)4 Column (org.teiid.metadata.Column)4 TableReference (org.teiid.language.TableReference)3 List (java.util.List)2 org.teiid.language (org.teiid.language)2 Literal (org.teiid.language.Literal)2 SetQuery (org.teiid.language.SetQuery)2 Table (org.teiid.metadata.Table)2 TranslatorException (org.teiid.translator.TranslatorException)2 Iterator (java.util.Iterator)1 Properties (java.util.Properties)1 Test (org.junit.Test)1 ClobImpl (org.teiid.core.types.ClobImpl)1 ClobType (org.teiid.core.types.ClobType)1 GeometryType (org.teiid.core.types.GeometryType)1 Comparison (org.teiid.language.Comparison)1