mirror of https://github.com/apache/cassandra
Merge branch 'cassandra-3.11' into trunk
This commit is contained in:
commit
43205143b4
|
|
@ -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();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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()));
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue