Skip to content

Commit

Permalink
TEIID-3553 preventing more ambiguities
Browse files Browse the repository at this point in the history
  • Loading branch information
shawkins committed Jul 6, 2015
1 parent 0d44db5 commit 34d0aee
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 12 deletions.
11 changes: 7 additions & 4 deletions odata/src/main/java/org/teiid/odata/ODataSQLBuilder.java
Expand Up @@ -910,11 +910,10 @@ public void visit(AggregateAllFunction expr) {

String tblName = ((EntitySimpleProperty)expr.getSource()).getPropertyName();
Table joinTable = findTable(tblName, this.metadata);
GroupSymbol joinGroup = new GroupSymbol(expr.getVariable(),tblName);

if (joinTable == null) {
throw new NotFoundException(ODataPlugin.Util.gs(ODataPlugin.Event.TEIID16009, tblName));
}
GroupSymbol joinGroup = new GroupSymbol(expr.getVariable(),joinTable.getFullName());

ODataAggregateAnyBuilder builder = new ODataAggregateAnyBuilder(expr,
this.resultEntityTable, this.resultEntityGroup, joinTable, joinGroup);
Expand All @@ -937,13 +936,17 @@ private Table findTable(String tableName, MetadataStore store) {
}
}
}
Table result = null;
for (Schema s : store.getSchemaList()) {
Table t = s.getTables().get(tableName);
if (t != null) {
return t;
if (result != null) {
throw new NotFoundException(ODataPlugin.Util.gs(ODataPlugin.Event.TEIID16017, tableName));
}
result = t;
}
}
return null;
return result;
}

private Column findColumn(Table table, String propertyName) {
Expand Down
4 changes: 2 additions & 2 deletions odata/src/main/resources/org/teiid/odata/i18n.properties
Expand Up @@ -21,7 +21,7 @@
#

TEIID16001=VDB {0} with version {1} not found
TEIID16002=Table '{0}' not included in metadata, due to lack of primary keys or unique keys
TEIID16002=Table "{0}" not included in metadata, due to lack of primary keys or unique keys
TEIID16003=Association is not found between entity {0} and {1}
TEIID16004=Entity {0} not found in the schema
TEIID16005=Property {0} not found in the entity {1}
Expand All @@ -36,4 +36,4 @@ TEIID16013=Error occurred producing OData result.
TEIID16014=Failed to register the VDB listener
TEIID16015=Incomplete key {1} specified for EntitySet "{0}"
TEIID16016=Insert into {0} success, but failed to retrieve auto generated keys from source, thus failed to show result entity; Supply the key values.
TEIID16017=Name '{0}' is ambiguous, please use a namespace/schema qualifier.
TEIID16017=Name "{0}" is ambiguous, please use a namespace/schema qualifier.
19 changes: 13 additions & 6 deletions odata/src/test/java/org/teiid/odata/TestODataSQLStringVisitor.java
Expand Up @@ -188,7 +188,7 @@ public void testOrderby() {
}

private void testSelect(String expected, String tableName, String filter, String select, String orderby, int top, String navProp, OEntityKey entityKey) throws Exception {
TransformationMetadata metadata = RealMetadataFactory.fromDDL(ObjectConverterUtil.convertFileToString(UnitTestUtil.getTestDataFile("northwind.ddl")), "northwind", "nw");
TransformationMetadata metadata = RealMetadataFactory.fromDDL("northwind", new RealMetadataFactory.DDLHolder("nw", ObjectConverterUtil.convertFileToString(UnitTestUtil.getTestDataFile("northwind.ddl"))), new RealMetadataFactory.DDLHolder("nw1", ObjectConverterUtil.convertFileToString(UnitTestUtil.getTestDataFile("northwind.ddl"))));
ODataSQLBuilder visitor = new ODataSQLBuilder(metadata.getMetadataStore(), false);
QueryInfo qi = buildQueryInfo(filter, select, orderby, top);
Query query = visitor.selectString(tableName, qi, entityKey, navProp, false);
Expand Down Expand Up @@ -276,6 +276,13 @@ public void testNavigationalQuery() throws Exception {
"nw.Orders(12)/nw.OrderDetails", OEntityKey.create(33));
}

@Test(expected=NotFoundException.class)
public void testNavigationalQueryAmbiguous() throws Exception {
testSelect(
"SELECT g1.EmployeeID, g1.OrderID, g1.CustomerID, g1.ShipVia FROM nw.Customers AS g0 INNER JOIN nw.Orders AS g1 ON g0.CustomerID = g1.CustomerID ORDER BY g1.OrderID",
"nw.Customers", null, "EmployeeID", null, -1, "Orders", null);
}


@Test
public void testEntityKeyQuery() throws Exception {
Expand All @@ -286,12 +293,12 @@ public void testEntityKeyQuery() throws Exception {
public void testFilterBasedAssosiation() throws Exception {
testSelect(
"SELECT g0.OrderID, g0.CustomerID, g0.EmployeeID, g0.ShipVia FROM nw.Orders AS g0 INNER JOIN nw.Customers AS g1 ON g0.CustomerID = g1.CustomerID WHERE g1.ContactName = 'Fred' ORDER BY g0.OrderID",
"nw.Orders", "Customers/ContactName eq 'Fred'", "OrderID",
"nw.Orders", "nw.Customers/ContactName eq 'Fred'", "OrderID",
null, -1, null, null);

testSelect(
"SELECT g0.ContactName, g0.CustomerID FROM nw.Customers AS g0 INNER JOIN nw.Orders AS g1 ON g0.CustomerID = g1.CustomerID WHERE g1.OrderID = 1 ORDER BY g0.CustomerID",
"nw.Customers", "Orders/OrderID eq 1", "ContactName",
"nw.Customers", "nw.Orders/OrderID eq 1", "ContactName",
null, -1, null, null);

}
Expand All @@ -308,15 +315,15 @@ public void testOrderByWithCriteria() throws Exception {
public void testAny() throws Exception {
testSelect(
"SELECT DISTINCT g0.OrderID, g0.CustomerID, g0.EmployeeID, g0.ShipVia FROM nw.Orders AS g0 INNER JOIN nw.OrderDetails AS ol ON g0.OrderID = ol.OrderID WHERE ol.Quantity > 10 ORDER BY g0.OrderID",
"nw.Orders", "OrderDetails/any(ol: ol/Quantity gt 10)",
"nw.Orders", "nw.OrderDetails/any(ol: ol/Quantity gt 10)",
"OrderID", null, -1, null, null);
}

@Test
public void testAll() throws Exception {
testSelect(
"SELECT g0.OrderID, g0.CustomerID, g0.EmployeeID, g0.ShipVia FROM nw.Orders AS g0 WHERE 10 < ALL (SELECT ol.Quantity FROM OrderDetails AS ol WHERE g0.OrderID = ol.OrderID) ORDER BY g0.OrderID",
"nw.Orders", "OrderDetails/all(ol: ol/Quantity gt 10)",
"SELECT g0.OrderID, g0.CustomerID, g0.EmployeeID, g0.ShipVia FROM nw.Orders AS g0 WHERE 10 < ALL (SELECT ol.Quantity FROM nw.OrderDetails AS ol WHERE g0.OrderID = ol.OrderID) ORDER BY g0.OrderID",
"nw.Orders", "nw.OrderDetails/all(ol: ol/Quantity gt 10)",
"OrderID", null, -1, null, null);
}

Expand Down

0 comments on commit 34d0aee

Please sign in to comment.