diff --git a/connectors/odata/translator-odata4/src/main/java/org/teiid/translator/odata4/ODataFilterVisitor.java b/connectors/odata/translator-odata4/src/main/java/org/teiid/translator/odata4/ODataFilterVisitor.java index 3b741226cd..54d3ac0007 100644 --- a/connectors/odata/translator-odata4/src/main/java/org/teiid/translator/odata4/ODataFilterVisitor.java +++ b/connectors/odata/translator-odata4/src/main/java/org/teiid/translator/odata4/ODataFilterVisitor.java @@ -115,6 +115,10 @@ private BaseColumn setCurrentExpression(Expression leftExpression) { } else { currentExpression = null; } + //we are really looking for the native type, if it's not set then don't bother + if (currentExpression != null && currentExpression.getNativeType() == null) { + currentExpression = null; + } return old; } @@ -124,16 +128,10 @@ protected void appendRightComparison(Comparison obj) { @Override public void visit(IsNull obj) { - if (obj.isNegated()) { - this.filter.append(NOT.toLowerCase()).append(Tokens.LPAREN); - } appendNested(obj.getExpression()); this.filter.append(Tokens.SPACE); - this.filter.append("eq").append(Tokens.SPACE); //$NON-NLS-1$ + this.filter.append(obj.isNegated()?"ne":"eq").append(Tokens.SPACE); //$NON-NLS-1$ //$NON-NLS-2$ this.filter.append(NULL.toLowerCase()); - if (obj.isNegated()) { - this.filter.append(Tokens.RPAREN); - } } private void appendNested(Expression ex) { diff --git a/connectors/odata/translator-odata4/src/test/java/org/teiid/translator/odata4/TestODataSQLVistor.java b/connectors/odata/translator-odata4/src/test/java/org/teiid/translator/odata4/TestODataSQLVistor.java index 427fe8b0ca..523399676c 100644 --- a/connectors/odata/translator-odata4/src/test/java/org/teiid/translator/odata4/TestODataSQLVistor.java +++ b/connectors/odata/translator-odata4/src/test/java/org/teiid/translator/odata4/TestODataSQLVistor.java @@ -225,7 +225,7 @@ public void testOrderByMultiple() throws Exception { @Test public void testisNotNull() throws Exception { helpExecute("SELECT UserName FROM People WHERE UserName is NOT NULL", - "People?$select=UserName&$filter=not(UserName eq null)"); + "People?$select=UserName&$filter=UserName ne null"); } @Test @@ -253,7 +253,13 @@ public void testSelectFromNavigationTable2() throws Exception { public void testSelectFromComplexTable() throws Exception { helpExecute("SELECT * FROM People_AddressInfo where Address = 'foo'", "People?$select=UserName,AddressInfo&$filter=AddressInfo/Address eq 'foo'"); - } + } + + @Test + public void testConvert() throws Exception { + helpExecute("select username from People where convert(gender, integer) = 1", + "People?$select=UserName&$filter=cast(Gender,Edm.Int32) eq 1"); + } } diff --git a/olingo/src/test/java/org/teiid/olingo/TestODataIntegration.java b/olingo/src/test/java/org/teiid/olingo/TestODataIntegration.java index affb51e721..59268a9922 100644 --- a/olingo/src/test/java/org/teiid/olingo/TestODataIntegration.java +++ b/olingo/src/test/java/org/teiid/olingo/TestODataIntegration.java @@ -288,6 +288,15 @@ public void testFilterExpression() throws Exception { response = http.GET(baseURL + "/loopy/vm1/G1?$filter=true"); assertEquals(200, response.getStatus()); } + + @Test + public void testFilterIsNotNull() throws Exception { + //should work, but does not due to https://issues.apache.org/jira/browse/OLINGO-1245 + //ContentResponse response = http.GET(baseURL + "/loopy/vm1/G1?$filter=not(" + Encoder.encode("e1 eq null") +")"); + + ContentResponse response = http.GET(baseURL + "/loopy/vm1/G1?$filter=" + Encoder.encode("e1 ne null")); + assertEquals(response.getContentAsString(), 200, response.getStatus()); + } @Test public void testEntitySet() throws Exception {