Skip to content

Commit feed57f

Browse files
Handle missing cardinalities graciously in case of uninitialized dimension storage.
1 parent bdb3d60 commit feed57f

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,8 @@ Current
143143

144144
### Fixed:
145145

146+
- [Handle Number Format errors from empty or missing cardinality value](https://github.com/yahoo/fili/issues/549)
147+
146148
- [Fix ConstantMaker make method with LogicalMetricInfo class](https://github.com/yahoo/fili/pull/540)
147149
* The ConstantMaker make method needs to be rewritten with the LogicalMetricInfo class.
148150

fili-core/src/main/java/com/yahoo/bard/webservice/data/dimension/KeyValueStore.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,18 @@ public interface KeyValueStore extends Closeable {
4949
*/
5050
String get(@NotNull String key);
5151

52+
/**
53+
* Get the value for a key from store or provide a default
54+
*
55+
* @param key Key to get the value for
56+
* @param defaultValue A default value in case key is null
57+
*
58+
* @return the value for corresponding key
59+
*/
60+
default String getOrDefault(@NotNull String key, String defaultValue) {
61+
return get(key) == null ? defaultValue : get(key);
62+
}
63+
5264
/**
5365
* Get the health status of the store.
5466
*

fili-core/src/main/java/com/yahoo/bard/webservice/data/dimension/impl/LuceneSearchProvider.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,9 @@ public void setKeyValueStore(KeyValueStore keyValueStore) {
205205

206206
@Override
207207
public int getDimensionCardinality() {
208-
return Integer.parseInt(keyValueStore.get(DimensionStoreKeyUtils.getCardinalityKey()));
208+
return Integer.parseInt(
209+
keyValueStore.getOrDefault(DimensionStoreKeyUtils.getCardinalityKey(), "0")
210+
);
209211
}
210212

211213
@Override

0 commit comments

Comments
 (0)