@Test public void testAnd() { Fields[] fields = new Fields[]{new Fields( 0 ), new Fields( 1 )}; Filter[] filters = new Filter[]{new BooleanFilter( true ), new BooleanFilter( true )}; Filter filter = new And( fields, filters ); assertTrue( invokeFilter( filter, new Tuple( 1, 2 ) ) ); filters = new Filter[]{new BooleanFilter( true ), new BooleanFilter( false )}; filter = new And( fields, filters ); assertFalse( invokeFilter( filter, new Tuple( 1, 2 ) ) ); filters = new Filter[]{new BooleanFilter( false ), new BooleanFilter( true )}; filter = new And( fields, filters ); assertFalse( invokeFilter( filter, new Tuple( 1, 2 ) ) ); filters = new Filter[]{new BooleanFilter( false ), new BooleanFilter( false )}; filter = new And( fields, filters ); assertFalse( invokeFilter( filter, new Tuple( 1, 2 ) ) ); }
@Test public void testComplexLogicAnd() throws Exception { copyFromLocal( inputFileLhs ); Tap source = getPlatform().getDelimitedFile( new Fields( "num", "char" ), " ", inputFileLhs ); Pipe pipe = new Pipe( "test" ); Filter filter = new Not( new And( new Fields( "num" ), new RegexFilter( "1", true, true ), new Fields( "char" ), new RegexFilter( "a", true, true ) ) ); // compounding the filter for the Fields.ALL case. pipe = new Each( pipe, filter ); pipe = new Each( pipe, new Fields( "num", "char" ), filter ); Tap sink = getPlatform().getDelimitedFile( Fields.ALL, " ", getOutputPath( "/regression/complexlogicand" ), SinkMode.REPLACE ); Flow flow = getPlatform().getFlowConnector().connect( source, sink, pipe ); flow.complete(); validateLength( flow, 1, 2, Pattern.compile( "1\ta" ) ); }
@Test public void testComplexLogicAnd() throws Exception { copyFromLocal( inputFileLhs ); Tap source = getPlatform().getDelimitedFile( new Fields( "num", "char" ), " ", inputFileLhs ); Pipe pipe = new Pipe( "test" ); Filter filter = new Not( new And( new Fields( "num" ), new RegexFilter( "1", true, true ), new Fields( "char" ), new RegexFilter( "a", true, true ) ) ); // compounding the filter for the Fields.ALL case. pipe = new Each( pipe, filter ); pipe = new Each( pipe, new Fields( "num", "char" ), filter ); Tap sink = getPlatform().getDelimitedFile( Fields.ALL, " ", getOutputPath( "/regression/complexlogicand" ), SinkMode.REPLACE ); Flow flow = getPlatform().getFlowConnector().connect( source, sink, pipe ); flow.complete(); validateLength( flow, 1, 2, Pattern.compile( "1\ta" ) ); }
@Test public void testAndExpression() { Fields inputFields = new Fields( "a", "b" ); ExpressionFilter f1 = new ExpressionFilter( "( 100f < a )", new String[]{"a"}, new Class<?>[]{Float.TYPE} ); ExpressionFilter f2 = new ExpressionFilter( "( 100f < b )", new String[]{"b"}, new Class<?>[]{Float.TYPE} ); And logic = new And( new Fields( "a" ), f1, new Fields( "b" ), f2 ); boolean[] results = invokeFilter( logic, new TupleEntry[]{ new TupleEntry( inputFields, new Tuple( "1", "10" ) ), new TupleEntry( inputFields, new Tuple( "2", "20" ) ) } ); assertFalse( results[ 0 ] ); assertFalse( results[ 1 ] ); } }
@Test public void testAndExpression() { Fields inputFields = new Fields( "a", "b" ); ExpressionFilter f1 = new ExpressionFilter( "( 100f < a )", new String[]{"a"}, new Class<?>[]{Float.TYPE} ); ExpressionFilter f2 = new ExpressionFilter( "( 100f < b )", new String[]{"b"}, new Class<?>[]{Float.TYPE} ); And logic = new And( new Fields( "a" ), f1, new Fields( "b" ), f2 ); boolean[] results = invokeFilter( logic, new TupleEntry[]{ new TupleEntry( inputFields, new Tuple( "1", "10" ) ), new TupleEntry( inputFields, new Tuple( "2", "20" ) ) } ); assertFalse( results[ 0 ] ); assertFalse( results[ 1 ] ); } }
@Test public void testLogicFilter() throws Exception { getPlatform().copyFromLocal( inputFileApache ); Tap source = getPlatform().getTextFile( inputFileApache ); Tap sink = getPlatform().getTextFile( getOutputPath( "logicfilter" ), SinkMode.REPLACE ); Pipe pipe = new Pipe( "test" ); Filter filter = new And( new RegexFilter( "^68.*$" ), new RegexFilter( "^1000.*$" ) ); pipe = new Each( pipe, new Fields( "line" ), filter ); Flow flow = getPlatform().getFlowConnector().connect( source, sink, pipe ); flow.complete(); validateLength( flow, 3 ); }
@Test public void testLogicFilter() throws Exception { getPlatform().copyFromLocal( inputFileApache ); Tap source = getPlatform().getTextFile( inputFileApache ); Tap sink = getPlatform().getTextFile( getOutputPath( "logicfilter" ), SinkMode.REPLACE ); Pipe pipe = new Pipe( "test" ); Filter filter = new And( new RegexFilter( "^68.*$" ), new RegexFilter( "^1000.*$" ) ); pipe = new Each( pipe, new Fields( "line" ), filter ); Flow flow = getPlatform().getFlowConnector().connect( source, sink, pipe ); flow.complete(); validateLength( flow, 3 ); }