From 62d4ced4dd2fc6fe49b9c3d19f949fe8f19e38ae Mon Sep 17 00:00:00 2001 From: Gian Merlino Date: Mon, 28 Sep 2015 21:17:44 -0400 Subject: [PATCH] Separate ListColumnIncluderator cache key parts with nul bytes --- .../metadata/ListColumnIncluderator.java | 3 ++- .../metadata/SegmentMetadataQueryTest.java | 22 +++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/processing/src/main/java/io/druid/query/metadata/metadata/ListColumnIncluderator.java b/processing/src/main/java/io/druid/query/metadata/metadata/ListColumnIncluderator.java index 1c169284cfe..3a7e86202a4 100644 --- a/processing/src/main/java/io/druid/query/metadata/metadata/ListColumnIncluderator.java +++ b/processing/src/main/java/io/druid/query/metadata/metadata/ListColumnIncluderator.java @@ -64,12 +64,13 @@ public class ListColumnIncluderator implements ColumnIncluderator for (String column : this.columns) { final byte[] bytes = StringUtils.toUtf8(column); columns.add(bytes); - size += bytes.length; + size += bytes.length + 1; } final ByteBuffer bytes = ByteBuffer.allocate(size).put(LIST_CACHE_PREFIX); for (byte[] column : columns) { bytes.put(column); + bytes.put((byte) 0xff); } return bytes.array(); diff --git a/processing/src/test/java/io/druid/query/metadata/SegmentMetadataQueryTest.java b/processing/src/test/java/io/druid/query/metadata/SegmentMetadataQueryTest.java index 535793c5dcc..98064720f8d 100644 --- a/processing/src/test/java/io/druid/query/metadata/SegmentMetadataQueryTest.java +++ b/processing/src/test/java/io/druid/query/metadata/SegmentMetadataQueryTest.java @@ -375,4 +375,26 @@ public class SegmentMetadataQueryTest Assert.assertEquals(expectedSegments2.get(i).getInterval(), filteredSegments2.get(i).getInterval()); } } + + @Test + public void testCacheKeyWithListColumnIncluderator() + { + SegmentMetadataQuery oneColumnQuery = Druids.newSegmentMetadataQueryBuilder() + .dataSource("testing") + .toInclude(new ListColumnIncluderator(Arrays.asList("foo"))) + .build(); + + SegmentMetadataQuery twoColumnQuery = Druids.newSegmentMetadataQueryBuilder() + .dataSource("testing") + .toInclude(new ListColumnIncluderator(Arrays.asList("fo", "o"))) + .build(); + + final byte[] oneColumnQueryCacheKey = new SegmentMetadataQueryQueryToolChest(null).getCacheStrategy(oneColumnQuery) + .computeCacheKey(oneColumnQuery); + + final byte[] twoColumnQueryCacheKey = new SegmentMetadataQueryQueryToolChest(null).getCacheStrategy(twoColumnQuery) + .computeCacheKey(twoColumnQuery); + + Assert.assertFalse(Arrays.equals(oneColumnQueryCacheKey, twoColumnQueryCacheKey)); + } }