Skip to content

Commit

Permalink
TEIID-5296 adding a more compatible solution
Browse files Browse the repository at this point in the history
  • Loading branch information
shawkins committed Apr 24, 2018
1 parent 1fea122 commit 7536da7
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
Expand Up @@ -406,12 +406,12 @@ else if (isStringFunction(functionName)) {
&& isDateTimeFunction(functionName) ) {
BasicDBList newParams = new BasicDBList();
newParams.addAll((BasicDBList)expr.values().iterator().next());
newParams.add(null);
BasicDBObject nullCheck = new BasicDBObject("$eq", newParams);
newParams.add(false);
BasicDBObject nullCheck = new BasicDBObject("$ifNull", newParams);
newParams = new BasicDBList();
newParams.add(nullCheck);
newParams.add(null);
newParams.add(expr);
newParams.add(null);
expr = new BasicDBObject("$cond", newParams);
}

Expand Down
Expand Up @@ -208,7 +208,8 @@ public void testEmbedded() throws Exception {
@Test
public void testTimeFunction() throws Exception {
executeCmd("delete from TIME_TEST");
executeCmd("insert into TIME_TEST (e1, e2) values (1, null)");
executeCmd("insert into TIME_TEST (e1) values (0)"); //missing
executeCmd("insert into TIME_TEST (e1, e2) values (1, null)"); //null
MongoDBQueryExecution exec = (MongoDBQueryExecution)executeCmd("select * from TIME_TEST where YEAR(e2) = 1");
assertNull(exec.next());

Expand All @@ -217,6 +218,11 @@ public void testTimeFunction() throws Exception {
exec = (MongoDBQueryExecution)executeCmd("SELECT e2, second(e2) as sec FROM TIME_TEST WHERE second(e2) >= 0");
assertEquals(Arrays.asList(TimestampUtil.createTimestamp(101, 0, 1, 1, 2, 3, 0), 3), exec.next());

exec = (MongoDBQueryExecution)executeCmd("SELECT e1, e2, second(e2) as sec FROM TIME_TEST");
assertEquals(Arrays.asList(0, null, null), exec.next());
assertEquals(Arrays.asList(1, null, null), exec.next());
assertEquals(Arrays.asList(2, TimestampUtil.createTimestamp(101, 0, 1, 1, 2, 3, 0), 3), exec.next());

client.close();
}

Expand Down
Expand Up @@ -1109,16 +1109,16 @@ public void testDateFunction() throws Exception {

BasicDBList values = new BasicDBList();
values.add(0, "$e2");
values.add(1, null);
BasicDBObject isNull = new BasicDBObject("$eq", values);
values.add(1, false);
BasicDBObject isNull = new BasicDBObject("$ifNull", values);

BasicDBObject func = new BasicDBObject("$year", params);
BasicDBObject expr = buildCondition(isNull, null, func);
BasicDBObject expr = buildCondition(isNull, func, null);

BasicDBObject result = new BasicDBObject();
result.append( "_m0", expr);

//{ "$cond" : [ { "$eq" : [ "$e2" , null ]} , null , { "$year" : [ "$e2"]}]}
//{ "$cond" : [ { "$ifNull" : [ "$e2" , false ]} , { "$year" : [ "$e2"]}, null]}

List<DBObject> pipeline = buildArray(new BasicDBObject("$project", result));
Mockito.verify(dbCollection).aggregate(Mockito.eq(pipeline), Mockito.any(AggregationOptions.class));
Expand Down

0 comments on commit 7536da7

Please sign in to comment.