@Test public void testNullNotNullKeywords() throws Exception { String sql = "SELECT * FROM " + DATA_SERVICE_NAME + " WHERE column1 IS NOT NULL AND column2 IS NULL"; DataServiceExecutor executor = new DataServiceExecutor.Builder(new SQL(sql), dataService, context) .serviceTrans(serviceTrans) .sqlTransGenerator(sqlTransGenerator) .genTrans(genTrans) .build(); Condition condition = executor.getSql().getWhereCondition().getCondition(); Condition condition1 = condition.getCondition(0); Condition condition2 = condition.getCondition(1); assertEquals("column1", condition1.getLeftValuename()); assertNull(condition1.getRightExact()); assertEquals(Condition.FUNC_NOT_NULL, condition1.getFunction()); assertEquals("column2", condition2.getLeftValuename()); assertNull(condition2.getRightExact()); assertEquals(Condition.FUNC_NULL, condition2.getFunction()); }
@Test public void testConditionResolution() throws Exception { RowMeta rowMeta = new RowMeta(); rowMeta.addValueMeta(new ValueMetaString("aString")); rowMeta.addValueMeta(new ValueMetaInteger("anInt")); rowMeta.addValueMeta(new ValueMetaDate("aDate")); String query = "SELECT * FROM " + DATA_SERVICE_NAME + " WHERE anInt = 2 AND aDate IN ('2014-12-05','2008-01-01')"; when(transMeta.getStepFields(DATA_SERVICE_STEP)).thenReturn(rowMeta); DataServiceExecutor executor = new DataServiceExecutor.Builder(new SQL(query), dataService, context) .serviceTrans(transMeta) .prepareExecution(false) .build(); Condition condition = executor.getSql().getWhereCondition().getCondition(); Calendar calendar = Calendar.getInstance(); calendar.clear(); calendar.set(2014, Calendar.DECEMBER, 5); assertThat( condition.evaluate(rowMeta, new Object[] {"value", 2L, calendar.getTime()}), is(true)); assertThat(condition.evaluate(rowMeta, new Object[] {"value", 2L, new Date()}), is(false)); }
@Test public void testWithLazyConversion() throws Exception { RowMeta rowMeta = new RowMeta(); ValueMetaInterface vm = new ValueMetaString("aBinaryStoredString"); vm.setStorageType(ValueMetaInterface.STORAGE_TYPE_BINARY_STRING); vm.setStorageMetadata(new ValueMetaString()); rowMeta.addValueMeta(vm); String query = "SELECT * FROM " + DATA_SERVICE_NAME + " WHERE aBinaryStoredString = 'value'"; when(transMeta.getStepFields(DATA_SERVICE_STEP)).thenReturn(rowMeta); DataServiceExecutor executor = new DataServiceExecutor.Builder(new SQL(query), dataService, context) .serviceTrans(new Trans(transMeta)) .prepareExecution(false) .build(); executor .getSql() .getWhereCondition() .getCondition() .evaluate(rowMeta, new Object[] {"value".getBytes()}); }