@Test public void testNot() { Fields[] fields = new Fields[]{new Fields( 0 ), new Fields( 1 )}; Filter[] filters = new Filter[]{new BooleanFilter( true ), new BooleanFilter( true )}; Filter filter = new Not( new Or( fields, filters ) ); assertFalse( invokeFilter( filter, new Tuple( 1, 2 ) ) ); filters = new Filter[]{new BooleanFilter( true ), new BooleanFilter( false )}; filter = new Not( new Or( fields, filters ) ); assertFalse( invokeFilter( filter, new Tuple( 1, 2 ) ) ); filters = new Filter[]{new BooleanFilter( false ), new BooleanFilter( true )}; filter = new Not( new Or( fields, filters ) ); assertFalse( invokeFilter( filter, new Tuple( 1, 2 ) ) ); filters = new Filter[]{new BooleanFilter( false ), new BooleanFilter( false )}; filter = new Not( new Or( fields, filters ) ); assertTrue( invokeFilter( filter, new Tuple( 1, 2 ) ) ); }
@Test public void testComplexLogicOr() throws Exception { copyFromLocal( inputFileLhs ); Tap source = getPlatform().getDelimitedFile( new Fields( "num", "char" ), " ", inputFileLhs ); Pipe pipe = new Pipe( "test" ); Filter filter = new Not( new Or( 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/complexlogicor" ), SinkMode.REPLACE ); Flow flow = getPlatform().getFlowConnector().connect( source, sink, pipe ); flow.complete(); validateLength( flow, 4, 2, Pattern.compile( "(1\t.)|(.\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 testComplexLogicXor() throws Exception { copyFromLocal( inputFileLhs ); Tap source = getPlatform().getDelimitedFile( new Fields( "num", "char" ), " ", inputFileLhs ); Pipe pipe = new Pipe( "test" ); Filter filter = new Not( new Xor( 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/complexlogicxor" ), SinkMode.REPLACE ); Flow flow = getPlatform().getFlowConnector().connect( source, sink, pipe ); flow.complete(); validateLength( flow, 3, 2, Pattern.compile( "(1\t.)|(.\ta)" ) ); }
@Test public void testComplexLogicXor() throws Exception { copyFromLocal( inputFileLhs ); Tap source = getPlatform().getDelimitedFile( new Fields( "num", "char" ), " ", inputFileLhs ); Pipe pipe = new Pipe( "test" ); Filter filter = new Not( new Xor( 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/complexlogicxor" ), SinkMode.REPLACE ); Flow flow = getPlatform().getFlowConnector().connect( source, sink, pipe ); flow.complete(); validateLength( flow, 3, 2, Pattern.compile( "(1\t.)|(.\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 testComplexLogicOr() throws Exception { copyFromLocal( inputFileLhs ); Tap source = getPlatform().getDelimitedFile( new Fields( "num", "char" ), " ", inputFileLhs ); Pipe pipe = new Pipe( "test" ); Filter filter = new Not( new Or( 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/complexlogicor" ), SinkMode.REPLACE ); Flow flow = getPlatform().getFlowConnector().connect( source, sink, pipe ); flow.complete(); validateLength( flow, 4, 2, Pattern.compile( "(1\t.)|(.\ta)" ) ); }