flink-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fhueske <...@git.apache.org>
Subject [GitHub] flink pull request #5218: [FLINK-8331][core] FieldParser do not correctly se...
Date Sun, 31 Dec 2017 10:12:05 GMT
Github user fhueske commented on a diff in the pull request:

    https://github.com/apache/flink/pull/5218#discussion_r159137345
  
    --- Diff: flink-core/src/test/java/org/apache/flink/types/parser/ParserTestBase.java ---
    @@ -407,26 +407,47 @@ public void testStaticParseMethodWithInvalidValues() {
     	@Test
     	public void testEmptyFieldInIsolation() {
     		try {
    -			String [] emptyStrings = new String[] {"|"};
    +			FieldParser<T> parser = getParser();
    +
    +			byte[] bytes = "|".getBytes(ConfigConstants.DEFAULT_CHARSET);
    +			int numRead = parser.parseField(bytes, 0, bytes.length, new byte[]{'|'}, parser.createValue());
    +
    +			assertEquals(FieldParser.ParseErrorState.EMPTY_COLUMN, parser.getErrorState());
    +
    +			if (this.allowsEmptyField()) {
    +				assertTrue("Parser declared the empty string as invalid.", numRead != -1);
    +				assertEquals("Invalid number of bytes read returned.", bytes.length, numRead);
    +			} else {
    +				assertTrue("Parser accepted the empty string.", numRead == -1);
    +			}
    +		} catch (Exception e) {
    +			System.err.println(e.getMessage());
    +			e.printStackTrace();
    +			fail("Test erroneous: " + e.getMessage());
    +		}
    +	}
    +
    +	@Test
    +	public void testTailingEmptyField() {
    +		try {
    +			String[] tailingEmptyFieldStrings = new String[]{"a|", "a||"};
     
     			FieldParser<T> parser = getParser();
     
    -			for (String emptyString : emptyStrings) {
    -				byte[] bytes = emptyString.getBytes(ConfigConstants.DEFAULT_CHARSET);
    -				int numRead = parser.parseField(bytes, 0, bytes.length, new byte[]{'|'}, parser.createValue());
    +			for (String tailingEmptyFieldString : tailingEmptyFieldStrings) {
    +				byte[] bytes = tailingEmptyFieldString.getBytes(ConfigConstants.DEFAULT_CHARSET);
    +				int numRead = parser.parseField(bytes, 1, bytes.length, new byte[]{'|'}, parser.createValue());
     
     				assertEquals(FieldParser.ParseErrorState.EMPTY_COLUMN, parser.getErrorState());
     
    -				if(this.allowsEmptyField()) {
    +				if (this.allowsEmptyField()) {
    --- End diff --
    
    Yes, you are right. I misinterpreted the `allowsEmptyField()` method. We need to keep
it.


---

Mime
View raw message