Merge branch 'cassandra-3.11' into trunk

This commit is contained in:
Mick Semb Wever 2018-05-18 12:36:17 +10:00
commit 43205143b4
No known key found for this signature in database
GPG Key ID: E91335D77E3E87CB
2 changed files with 32 additions and 4 deletions

View File

@ -85,12 +85,17 @@ public class DelimiterAnalyzer extends AbstractAnalyzer
CharBuffer readahead = cb.duplicate();
// loop until we see the next delimiter character, or reach end of data
while (readahead.hasRemaining() && readahead.get() != delimiter);
boolean readaheadRemaining;
while ((readaheadRemaining = readahead.hasRemaining()) && readahead.get() != delimiter);
char[] chars = new char[readahead.position() - cb.position() - (readahead.hasRemaining() ? 1 : 0)];
char[] chars = new char[readahead.position() - cb.position() - (readaheadRemaining ? 1 : 0)];
cb.get(chars);
Preconditions.checkState(!cb.hasRemaining() || cb.get() == delimiter);
return charset.encode(CharBuffer.wrap(chars));
return 0 < chars.length
? charset.encode(CharBuffer.wrap(chars))
// blank partition keys not permitted, ref ConcurrentRadixTree.putIfAbsent(..)
: computeNext();
}
};
}

View File

@ -54,7 +54,30 @@ public class DelimiterAnalyzerTest
while (analyzer.hasNext())
output.append(ByteBufferUtil.string(analyzer.next()) + (analyzer.hasNext() ? ' ' : ""));
Assert.assertTrue(testString.equals(output.toString()));
Assert.assertEquals(testString, output.toString());
Assert.assertFalse(testString.toLowerCase().equals(output.toString()));
}
@Test
public void testBlankEntries() throws Exception
{
DelimiterAnalyzer analyzer = new DelimiterAnalyzer();
analyzer.init(
new HashMap()
{{
put(DelimiterTokenizingOptions.DELIMITER, ",");
}},
UTF8Type.instance);
String testString = ",Nip,,,,it,,,in,,the,bud,,,";
ByteBuffer toAnalyze = ByteBuffer.wrap(testString.getBytes());
analyzer.reset(toAnalyze);
StringBuilder output = new StringBuilder();
while (analyzer.hasNext())
output.append(ByteBufferUtil.string(analyzer.next()) + (analyzer.hasNext() ? ',' : ""));
Assert.assertEquals("Nip,it,in,the,bud", output.toString());
Assert.assertFalse(testString.toLowerCase().equals(output.toString()));
}