DataServiceExecutor { public SQL getSql() { return sql; } private  DataServiceExecutor( Builder builder ); static void writeMetadata( DataOutputStream dos, String... metadatas ); DataServiceExecutor executeQuery( final DataOutputStream dos ); DataServiceExecutor executeQuery( Observer<RowMetaAndData> consumer ); DataServiceExecutor executeStreamingQuery( final Observer<List<RowMetaAndData>> streamingConsumer, boolean pollingMode ); String getStreamingGenTransCacheKey(); DataServiceExecutor executeDefaultQuery( final Observer<RowMetaAndData> consumer ); DataServiceExecutor executeQuery(); void executeListeners( ExecutionPoint... stages ); RowProducer addRowProducer(); void waitUntilFinished(); TransMeta getServiceTransMeta(); TransMeta getGenTransMeta(); DataServiceMeta getService(); Trans getServiceTrans(); Trans getGenTrans(); String getServiceName(); Map<String, String> getParameters(); String getId(); Boolean hasErrors(); static String calculateTransname( SQL sql, boolean isService ); void stop( boolean stopTrans ); boolean isStopped(); SQL getSql(); String getResultStepName(); int getRowLimit(); int getServiceRowLimit(); ListMultimap<ExecutionPoint, Runnable> getListenerMap();  }
@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 COUNT(aString), aString FROM " + DATA_SERVICE_NAME + " WHERE anInt = 2 AND aDate IN ('2014-12-05','2008-01-01')" + " GROUP BY aString HAVING COUNT(aString) > 2"; when( transMeta.getStepFields( DATA_SERVICE_STEP ) ).thenReturn( rowMeta ); DataServiceExecutor executor = new DataServiceExecutor.Builder( new SQL( query ), dataService, context ). serviceTrans( transMeta ). 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 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 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 ) ). build(); executor.getSql().getWhereCondition().getCondition().evaluate( rowMeta, new Object[] { "value".getBytes() } ); }