Search in sources :

Example 1 with DerivedColumn

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

the class TestMongoDBQueryExecution method testGeoFunctionInWhereWithGeometry.

@Test
public void testGeoFunctionInWhereWithGeometry() throws Exception {
    Table table = this.utility.createRuntimeMetadata().getTable("northwind.Categories");
    NamedTable namedTable = new NamedTable("Categories", "g0", table);
    ColumnReference colRef = new ColumnReference(namedTable, "CategoryName", table.getColumnByName("CategoryName"), String.class);
    DerivedColumn col = new DerivedColumn("CategoryName", colRef);
    Select select = new Select();
    select.setDerivedColumns(Arrays.asList(col));
    List<TableReference> tables = new ArrayList<TableReference>();
    tables.add(namedTable);
    select.setFrom(tables);
    final GeometryType geo = GeometryUtils.geometryFromClob(new ClobType(new ClobImpl("POLYGON ((1.0 2.0,3.0 4.0,5.0 6.0,1.0 2.0))")));
    Function function = new // $NON-NLS-1$
    Function(// $NON-NLS-1$
    "mongo.geoWithin", // $NON-NLS-1$
    Arrays.asList(colRef, new Literal(geo, GeometryType.class)), // $NON-NLS-2$
    Boolean.class);
    function.setMetadataObject(getFunctionMethod("mongo.geoWithin"));
    Comparison c = new Comparison(function, new Literal(true, Boolean.class), Comparison.Operator.EQ);
    select.setWhere(c);
    DBCollection dbCollection = helpExecute(select, new String[] { "Categories" }, 2);
    BasicDBObjectBuilder builder = new BasicDBObjectBuilder();
    builder.push("CategoryName");
    // $NON-NLS-1$
    builder.push("$geoWithin");
    // $NON-NLS-1$
    builder.add("$geometry", "{\"type\":\"Polygon\",\"coordinates\":[[[1.0,2.0],[3.0,4.0],[5.0,6.0],[1.0,2.0]]]}");
    BasicDBObject result = new BasicDBObject();
    result.append("CategoryName", "$CategoryName");
    List<DBObject> pipeline = buildArray(new BasicDBObject("$match", builder.get()), new BasicDBObject("$project", result));
    Mockito.verify(dbCollection).aggregate(Mockito.eq(pipeline), Mockito.any(AggregationOptions.class));
}
Also used : NamedTable(org.teiid.language.NamedTable) NamedTable(org.teiid.language.NamedTable) Table(org.teiid.metadata.Table) ArrayList(java.util.ArrayList) ClobType(org.teiid.core.types.ClobType) GeometryType(org.teiid.core.types.GeometryType) Function(org.teiid.language.Function) TableReference(org.teiid.language.TableReference) Comparison(org.teiid.language.Comparison) Literal(org.teiid.language.Literal) Select(org.teiid.language.Select) DerivedColumn(org.teiid.language.DerivedColumn) ClobImpl(org.teiid.core.types.ClobImpl) ColumnReference(org.teiid.language.ColumnReference) Test(org.junit.Test)

Example 2 with DerivedColumn

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

the class MockConnector method createResultSetExecution.

@Override
public ResultSetExecution createResultSetExecution(QueryExpression query, ExecutionContext executionContext, RuntimeMetadata metadata, Object connection) throws TranslatorException {
    Properties groupProps = new Properties();
    // $NON-NLS-1$ //$NON-NLS-2$
    groupProps.setProperty("customName", "CustomTableA");
    NamedTable group = (NamedTable) query.getProjectedQuery().getFrom().get(0);
    AbstractMetadataRecord groupMD = group.getMetadataObject();
    TestCase.assertEquals(groupProps, groupMD.getProperties());
    DerivedColumn symbl = query.getProjectedQuery().getDerivedColumns().get(0);
    ColumnReference element = (ColumnReference) symbl.getExpression();
    Column elementMD = element.getMetadataObject();
    Properties elementProps = new Properties();
    // $NON-NLS-1$ //$NON-NLS-2$
    elementProps.setProperty("customPosition", "11");
    TestCase.assertEquals(0, elementMD.getLength());
    // $NON-NLS-1$
    TestCase.assertEquals("Foo", elementMD.getDefaultValue());
    // $NON-NLS-1$
    TestCase.assertEquals("TrimNulls", elementMD.getFormat());
    TestCase.assertEquals(String.class, elementMD.getJavaType());
    TestCase.assertEquals(null, elementMD.getMaximumValue());
    TestCase.assertEquals(null, elementMD.getMinimumValue());
    // $NON-NLS-1$
    TestCase.assertEquals("COLUMN1", elementMD.getNameInSource());
    // $NON-NLS-1$
    TestCase.assertEquals("STR", elementMD.getNativeType());
    TestCase.assertEquals(NullType.Nullable, elementMD.getNullType());
    TestCase.assertEquals(0, elementMD.getPosition());
    TestCase.assertEquals(0, elementMD.getPrecision());
    TestCase.assertEquals(0, elementMD.getScale());
    TestCase.assertEquals(SearchType.Searchable, elementMD.getSearchType());
    TestCase.assertEquals(false, elementMD.isAutoIncremented());
    TestCase.assertEquals(true, elementMD.isCaseSensitive());
    TestCase.assertEquals(elementProps, elementMD.getProperties());
    DerivedColumn symbl2 = query.getProjectedQuery().getDerivedColumns().get(1);
    ColumnReference element2 = (ColumnReference) symbl2.getExpression();
    Column elementMD2 = element2.getMetadataObject();
    Properties elementProps2 = new Properties();
    // $NON-NLS-1$ //$NON-NLS-2$
    elementProps2.setProperty("customPosition", "12");
    TestCase.assertEquals(10, elementMD2.getLength());
    // $NON-NLS-1$
    TestCase.assertEquals("23", elementMD2.getDefaultValue());
    // $NON-NLS-1$
    TestCase.assertEquals("YesFormat", elementMD2.getFormat());
    TestCase.assertEquals(Integer.class, elementMD2.getJavaType());
    // $NON-NLS-1$
    TestCase.assertEquals("1", elementMD2.getMaximumValue());
    // $NON-NLS-1$
    TestCase.assertEquals("100", elementMD2.getMinimumValue());
    // $NON-NLS-1$
    TestCase.assertEquals("COLUMN2", elementMD2.getNameInSource());
    // $NON-NLS-1$
    TestCase.assertEquals("INT", elementMD2.getNativeType());
    TestCase.assertEquals(NullType.No_Nulls, elementMD2.getNullType());
    TestCase.assertEquals(1, elementMD2.getPosition());
    TestCase.assertEquals(0, elementMD2.getPrecision());
    TestCase.assertEquals(10, elementMD2.getScale());
    TestCase.assertEquals(SearchType.Searchable, elementMD2.getSearchType());
    TestCase.assertEquals(true, elementMD2.isAutoIncremented());
    TestCase.assertEquals(false, elementMD2.isCaseSensitive());
    TestCase.assertEquals(elementProps2, elementMD2.getProperties());
    ResultSetExecution exec = Mockito.mock(ResultSetExecution.class);
    Mockito.stub(exec.next()).toReturn(null);
    return exec;
}
Also used : NamedTable(org.teiid.language.NamedTable) ResultSetExecution(org.teiid.translator.ResultSetExecution) Column(org.teiid.metadata.Column) DerivedColumn(org.teiid.language.DerivedColumn) Properties(java.util.Properties) AbstractMetadataRecord(org.teiid.metadata.AbstractMetadataRecord) DerivedColumn(org.teiid.language.DerivedColumn) ColumnReference(org.teiid.language.ColumnReference)

Example 3 with DerivedColumn

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

the class TestElement method getElement.

public Column getElement(String groupName, String elementName, TranslationUtility transUtil) throws Exception {
    // $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)

Example 4 with DerivedColumn

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

the class LanguageBridgeFactory method setProjected.

private void setProjected(QueryExpression qe) {
    if (qe instanceof Select) {
        Select select = (Select) qe;
        for (DerivedColumn dc : select.getDerivedColumns()) {
            dc.setProjected(true);
        }
    } else {
        org.teiid.language.SetQuery sq = (org.teiid.language.SetQuery) qe;
        setProjected(sq.getLeftQuery());
        setProjected(sq.getRightQuery());
    }
}
Also used : SetQuery(org.teiid.query.sql.lang.SetQuery) Select(org.teiid.language.Select) org.teiid.language(org.teiid.language) DerivedColumn(org.teiid.language.DerivedColumn)

Example 5 with DerivedColumn

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

the class LanguageBridgeFactory method translate.

/* Query */
Select translate(Query query) {
    With with = translate(query.getWith());
    List<Expression> symbols = query.getSelect().getSymbols();
    List<DerivedColumn> translatedSymbols = new ArrayList<DerivedColumn>(symbols.size());
    for (Iterator<Expression> i = symbols.iterator(); i.hasNext(); ) {
        Expression symbol = i.next();
        String alias = null;
        if (symbol instanceof AliasSymbol) {
            alias = ((AliasSymbol) symbol).getOutputName();
            symbol = ((AliasSymbol) symbol).getSymbol();
        }
        org.teiid.language.Expression iExp = translate(symbol);
        DerivedColumn selectSymbol = new DerivedColumn(alias, iExp);
        translatedSymbols.add(selectSymbol);
    }
    List<TableReference> items = null;
    if (query.getFrom() != null) {
        List<FromClause> clauses = query.getFrom().getClauses();
        items = new ArrayList<TableReference>(clauses.size());
        for (Iterator<FromClause> i = clauses.iterator(); i.hasNext(); ) {
            items.add(translate(i.next()));
        }
    }
    Select q = new Select(translatedSymbols, query.getSelect().isDistinct(), items, translate(query.getCriteria()), translate(query.getGroupBy()), translate(query.getHaving()), translate(query.getOrderBy(), false));
    q.setLimit(translate(query.getLimit()));
    q.setWith(with);
    return q;
}
Also used : org.teiid.language(org.teiid.language) AliasSymbol(org.teiid.query.sql.symbol.AliasSymbol) SearchedCaseExpression(org.teiid.query.sql.symbol.SearchedCaseExpression) Expression(org.teiid.query.sql.symbol.Expression) Select(org.teiid.language.Select) DerivedColumn(org.teiid.language.DerivedColumn)

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