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