use of org.teiid.language.TableReference 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.TableReference 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.TableReference 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.TableReference in project teiid by teiid.
the class JPQLSelectVisitor method handleJoin.
private JoinTable handleJoin(Join obj) throws TranslatorException {
TableReference left = obj.getLeftItem();
TableReference right = obj.getRightItem();
if ((left instanceof NamedTable) && (right instanceof NamedTable)) {
JoinTable join = handleJoin(obj.getJoinType(), left, right, true);
this.joins.add(join);
return join;
}
JoinTable leftJoin = null;
if (left instanceof Join) {
leftJoin = handleJoin((Join) left);
if (right instanceof NamedTable) {
JoinTable join = handleJoin(obj.getJoinType(), leftJoin, (NamedTable) right);
this.joins.add(join);
return join;
}
}
JoinTable rightJoin = null;
if (right instanceof Join) {
rightJoin = handleJoin((Join) right);
if (left instanceof NamedTable) {
JoinTable join = handleJoin(obj.getJoinType(), (NamedTable) left, rightJoin);
this.joins.add(join);
return join;
}
}
throw new TranslatorException(JPAPlugin.Util.gs(JPAPlugin.Event.TEIID14005));
}
Aggregations