TableInputParameterGeneration implements ParameterGenerationService { protected String convertAtomicCondition( Condition condition, RowMeta paramsMeta, List<Object> params ) throws PushDownOptimizationException { String value = condition.getRightExactString(); String function = condition.getFunctionDesc(); String placeholder = "?"; switch ( condition.getFunction() ) { case Condition.FUNC_REGEXP: case Condition.FUNC_CONTAINS: case Condition.FUNC_STARTS_WITH: case Condition.FUNC_ENDS_WITH: case Condition.FUNC_TRUE: throw new PushDownOptimizationException( condition.getFunctionDesc() + " is not supported for push down." ); case Condition.FUNC_NOT_NULL: case Condition.FUNC_NULL: placeholder = ""; break; case Condition.FUNC_IN_LIST: Object[] inList = getInListArray( condition ); ValueMetaInterface inListValueMeta = getResolvedValueMeta( condition ); for ( int i = 0; i < inList.length; i++ ) { paramsMeta.addValueMeta( inListValueMeta ); params.add( inList [ i ] ); } placeholder = String.format( "(%s)", StringUtils.join( Collections.nCopies( inList.length, "?" ).iterator(), "," ) ); function = " IN "; break; default: if ( value == null ) { throw new PushDownOptimizationException( "Condition value can not be null: " + condition ); } paramsMeta.addValueMeta( getResolvedValueMeta( condition ) ); params.add( getResolvedValue( condition ) ); break; } return String.format( "%s %s %s", getQuotedFieldName( condition ), function, placeholder ); } TableInputParameterGeneration( ValueMetaResolver resolver ); @Override String getParameterDefault(); @Override OptimizationImpactInfo preview( Condition pushDownCondition, ParameterGeneration parameterGeneration, StepInterface stepInterface ); @Override void pushDown( Condition condition, ParameterGeneration parameterGeneration, StepInterface stepInterface );  }
@Test public void testConvertAtomicCondition() throws Exception { testFunctionType( Condition.FUNC_EQUAL, "field_name = ?", "value" ); testFunctionType( Condition.FUNC_NOT_EQUAL, "field_name <> ?", "value" ); testFunctionType( Condition.FUNC_NOT_EQUAL, "field_name <> ?", 123 ); testFunctionType( Condition.FUNC_SMALLER, "field_name < ?", 123 ); testFunctionType( Condition.FUNC_SMALLER_EQUAL, "field_name <= ?", 123 ); testFunctionType( Condition.FUNC_LARGER, "field_name > ?", 123 ); testFunctionType( Condition.FUNC_LARGER_EQUAL, "field_name >= ?", 123 ); testInListCondition( "value1;value2;value3", new String[] { "value1", "value2", "value3" }, "field_name IN (?,?,?)" ); testInListCondition( "value1;value2;value3;val ue4", new String[]{ "value1", "value2", "value3", "val ue4" }, "field_name IN (?,?,?,?)" ); testFunctionType( Condition.FUNC_LARGER_EQUAL, "field_name >= ?", 123 ); try { testFunctionType( Condition.FUNC_REGEXP, "field_name ~= ?", "123" ); fail( "Should have thrown exception" ); } catch ( PushDownOptimizationException e ) { assertTrue( e.getMessage().contains( "REGEXP" ) ); } testFunctionType( Condition.FUNC_NULL, "field_name IS NULL ", null ); testFunctionType( Condition.FUNC_NOT_NULL, "field_name IS NOT NULL ", null ); testFunctionType( Condition.FUNC_LIKE, "field_name LIKE ?", "MAT%CH" ); try { testFunctionType( Condition.FUNC_EQUAL, "field_name = 'value'", null ); fail( "Should have thrown exception" ); } catch ( PushDownOptimizationException e ) { assertThat( e.getMessage(), notNullValue() ); } }