/** * Remove all keys associated with the store. * <p> * This is mainly used for tests; the Redis command used to get the associated keys (KEYS) is rather expensive and * shouldn't be run frequently. */ public void removeAllKeys() { removeAllKeys(storeName); }
@Override public boolean isHealthy() { // If we know we're not healthy, don't bother pinging. if (!redisIsHealthy) { return false; } ping(); return redisIsHealthy; }
/** * Constructs an AvroDimensionRowParser object based on the DimensionFieldNameMapper object. * * @param dimensionFieldNameMapper Object that defines the dimension field name transformations */ public AvroDimensionRowParser(DimensionFieldNameMapper dimensionFieldNameMapper) { this.dimensionFieldNameMapper = memoize(dimensionFieldNameMapper); }
/** * Make a DimensionRow by setting all of the field values to the given value. * * @param value Value for dimension fields * @return a DimensionRow */ private DimensionRow makeDimensionRow(String value) { LinkedHashMap<DimensionField, String> map = new LinkedHashMap<>(); for (DimensionField dimensionField: dimension.getDimensionFields()) { map.put(dimensionField, value); } return new DimensionRow(dimension.getKey(), map); }
/** * A default implementation of the converter method which uses underscore as a separator. * * @return an instance of DimensionFieldNameMapper */ static DimensionFieldNameMapper underscoreSeparatedConverter () { return (dimension, dimensionField) -> (dimension.getApiName() + "_" + dimensionField.getName()).toUpperCase(Locale.ENGLISH); } }
/** * Constructor. * Uses the given dimension's name for column name. * * @param dimension The column's corresponding dimension */ public DimensionColumn(@NotNull Dimension dimension) { super(dimension.getApiName()); this.dimension = dimension; }
/** * Get a dimension row given an id. * * @param value dimension id to look up * * @return dimension row if exists else null */ public DimensionRow findDimensionRowByKeyValue(String value) { return dimension.findDimensionRowByKeyValue(value); }
/** * Gets the number of distinct dimension rows (assuming the key field is unique) in the index. * * @param refresh If true, clear any cached cardinality and recalculate before returning. * * @return The number of dimension rows for this dimension */ default int getDimensionCardinality(boolean refresh) { // If no caching is done, simply delegate return getDimensionCardinality(); }
@Override public String toString() { return "{dim:'" + getName() + "'}"; } }
/** * Constructor. * * @param dimensions Set of Dimension values to add */ public DimensionDictionary(Set<Dimension> dimensions) { this(); addAll(dimensions); }
/** * Adds dimension row values to a dimension. * * @param dimension The dimension to add the row to. * @param dimensionRow The dimension row to be added. */ default void updateDimensionWithValue(Dimension dimension, DimensionRow dimensionRow) { dimension.addDimensionRow(dimensionRow); } }
/** * Build a connection to a Redis provider. * * @param storeName The second part of the prefix to keyspace names for this store * @param pool A pool of Jedis connection instances * @param redisNamespace The first part of the prefix to the keyspace names for this store */ public RedisStore(String storeName, JedisPool pool, String redisNamespace) { this.pool = pool; this.storeName = storeName; this.redisIsHealthy = true; this.redisNamespace = redisNamespace; open(); }
/** * Adds all of the dimensions in the specified collection to the dictionary. * * @param dimensions collection of dimensions to add * * @return <tt>true</tt> if the dictionary changed as a result of the call * @see Set#addAll(Collection) */ public boolean addAll(Collection<? extends Dimension> dimensions) { boolean flag = false; for (Dimension dimension : dimensions) { flag = add(dimension) || flag; } return flag; }
/** * Tell the dimension it's been updated. * * @param dimension The dimension to update saying it's been loaded. */ default void updateDimension(Dimension dimension) { dimension.setLastUpdated(DateTime.now()); }
@Override public DateTime getLastUpdated() { String lastUpdatedString = keyValueStore.get(lastUpdatedKey); if (lastUpdatedString == null) { return null; } else { return DateTime.parse(lastUpdatedString); } }
/** * Constructor. * * @param description Human-consumable description of the field */ BardDimensionField(String description) { this.description = description; camelName = EnumUtils.camelCase(name()); }
@Override public String toString() { return String.format("%s|%s-%s%s", dimension.getApiName(), dimensionField, operation, values); } }
@Override public void open() { ping(); }
@Override public int getCardinality() { return searchProvider.getDimensionCardinality(); }