Search in sources :

Example 11 with DerivedColumn

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

the class HsqlExecutionFactory method translateCommand.

@Override
public List<?> translateCommand(Command command, ExecutionContext context) {
    if (command instanceof Select) {
        Select select = (Select) command;
        if (select.getFrom() == null || select.getFrom().isEmpty()) {
            List<Object> result = new ArrayList<Object>();
            // $NON-NLS-1$
            result.add("VALUES(");
            for (int i = 0; i < select.getDerivedColumns().size(); i++) {
                DerivedColumn dc = select.getDerivedColumns().get(i);
                if (i != 0) {
                    // $NON-NLS-1$
                    result.add(", ");
                }
                result.add(dc.getExpression());
            }
            // $NON-NLS-1$
            result.add(")");
            return result;
        }
    }
    return super.translateCommand(command, context);
}
Also used : Select(org.teiid.language.Select) ArrayList(java.util.ArrayList) DerivedColumn(org.teiid.language.DerivedColumn)

Example 12 with DerivedColumn

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

the class TestQueryImpl method testGetSelectSymbols.

public void testGetSelectSymbols() throws Exception {
    List symbols = example(false).getDerivedColumns();
    assertNotNull(symbols);
    assertEquals(4, symbols.size());
    for (Iterator i = symbols.iterator(); i.hasNext(); ) {
        assertTrue(i.next() instanceof DerivedColumn);
    }
}
Also used : Iterator(java.util.Iterator) List(java.util.List) ArrayList(java.util.ArrayList) DerivedColumn(org.teiid.language.DerivedColumn)

Example 13 with DerivedColumn

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

the class TestSelectSymbolImpl method testGetColumnDataTypes.

public void testGetColumnDataTypes() {
    Class<?>[] expectedResults = new Class[2];
    List<DerivedColumn> symbols = new ArrayList<DerivedColumn>();
    // $NON-NLS-1$//$NON-NLS-2$
    symbols.add(new DerivedColumn("c1", new Literal("3", DataTypeManager.DefaultDataClasses.STRING)));
    expectedResults[0] = DataTypeManager.DefaultDataClasses.STRING;
    // $NON-NLS-1$
    symbols.add(new DerivedColumn("c2", new Literal(new Integer(5), DataTypeManager.DefaultDataClasses.INTEGER)));
    expectedResults[1] = DataTypeManager.DefaultDataClasses.INTEGER;
    Select query = new Select(symbols, false, null, null, null, null, null);
    Class<?>[] results = query.getColumnTypes();
    assertEquals(results[0], expectedResults[0]);
    assertEquals(results[1], expectedResults[1]);
}
Also used : Literal(org.teiid.language.Literal) ArrayList(java.util.ArrayList) Select(org.teiid.language.Select) DerivedColumn(org.teiid.language.DerivedColumn)

Example 14 with DerivedColumn

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

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