|
11 | 11 | import stroom.pipeline.refdata.store.RefStoreEntry;
|
12 | 12 | import stroom.pipeline.refdata.store.RefStreamDefinition;
|
13 | 13 | import stroom.pipeline.refdata.store.offheapstore.TypedByteBuffer;
|
| 14 | +import stroom.util.NullSafe; |
14 | 15 | import stroom.util.logging.LambdaLogger;
|
15 | 16 | import stroom.util.logging.LambdaLoggerFactory;
|
16 | 17 | import stroom.util.logging.LogUtil;
|
@@ -107,17 +108,23 @@ public Optional<RefDataValue> getValue(final MapDefinition mapDefinition, final
|
107 | 108 | // just do the range lookup
|
108 | 109 | final long keyLong = Long.parseLong(key);
|
109 | 110 |
|
110 |
| - // look up our long key in the range store to see if it is part of a range |
111 |
| - NavigableMap<Range<Long>, RefDataValue> rangeSubMap = rangeValueNestedMap.get(mapDefinition); |
112 |
| - result = getValueByRange(rangeSubMap, keyLong); |
| 111 | + // Look up our long key in the range store to see if it is part of a range. |
| 112 | + // It is possible for an event stream to have no associated context stream, or |
| 113 | + // the context stream may not contain the map and/or key requested in the lookup |
| 114 | + final NavigableMap<Range<Long>, RefDataValue> rangeSubMap = rangeValueNestedMap.get(mapDefinition); |
| 115 | + if (NullSafe.hasEntries(rangeSubMap)) { |
| 116 | + result = getValueByRange(rangeSubMap, keyLong); |
| 117 | + } else { |
| 118 | + result = Optional.empty(); |
| 119 | + } |
113 | 120 |
|
114 | 121 | } catch (NumberFormatException e) {
|
115 | 122 | // key could not be converted to a long, either this mapdef has no ranges or
|
116 | 123 | // an invalid key was used. See if we have any ranges at all for this mapdef
|
117 | 124 | // to determine whether to error or not.
|
118 | 125 | boolean doesStoreContainRanges = rangeValueNestedMap.containsKey(mapDefinition);
|
119 | 126 | if (doesStoreContainRanges) {
|
120 |
| - // we have ranges for this map def so we would expect to be able to convert the key |
| 127 | + // we have ranges for this map def, so we would expect to be able to convert the key |
121 | 128 | throw new RuntimeException(LogUtil.message(
|
122 | 129 | "Key {} cannot be used with the range store as it cannot be converted to a long",
|
123 | 130 | key),
|
@@ -169,9 +176,7 @@ private Optional<RefDataValue> getValueByRange(final NavigableMap<Range<Long>, R
|
169 | 176 |
|
170 | 177 | // create a sub-set of the map starting at the key of interest or the next smallest
|
171 | 178 | // range from value. Note the map is reverse sorted to increase confusion.
|
172 |
| - |
173 | 179 | final SortedMap<Range<Long>, RefDataValue> tailMap = rangeSubMap.tailMap(startKey);
|
174 |
| - |
175 | 180 | for (Map.Entry<Range<Long>, RefDataValue> entry : tailMap.entrySet()) {
|
176 | 181 | // see if our key is in the found range
|
177 | 182 | if (entry.getKey().contains(key)) {
|
@@ -209,7 +214,7 @@ public List<RefStoreEntry> list(final int limit,
|
209 | 214 | throw new UnsupportedOperationException("Not yet implemented");
|
210 | 215 | }
|
211 | 216 |
|
212 |
| -// @Override |
| 217 | + // @Override |
213 | 218 | // public <T> T consumeEntryStream(final Function<Stream<RefStoreEntry>, T> streamFunction) {
|
214 | 219 | // throw new UnsupportedOperationException("Not yet implemented");
|
215 | 220 | // }
|
|
0 commit comments