Skip to content

Commit

Permalink
Merge branch 'master' into issue-714-let-DimensionApiRequestMapper-th…
Browse files Browse the repository at this point in the history
…row-RequestValidationException-instead-of-BadApiRequestException
  • Loading branch information
QubitPi authored Jun 21, 2018
2 parents ee6bd25 + d743cc7 commit 910a9a2
Show file tree
Hide file tree
Showing 9 changed files with 99 additions and 7 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ pull request if there was one.

### Added:

- [Add storageStrategy as a field of the DimensionConfig class](https://github.com/yahoo/fili/issues/718)
* Adds getStorageStrategy as a field of the dimensionConfig class.
* Passes the storage strategy to the KeyValueStoreDimension Constructor

- [Add more tests to RegisteredLookupMetadataLoadTask](https://github.com/yahoo/fili/pull/673)
* Adds tests to make sure the load tasks can update status correctly.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.yahoo.bard.webservice.data.dimension.DimensionField;
import com.yahoo.bard.webservice.data.dimension.KeyValueStore;
import com.yahoo.bard.webservice.data.dimension.SearchProvider;
import com.yahoo.bard.webservice.data.dimension.metadata.StorageStrategy;

import java.util.LinkedHashSet;
import javax.validation.constraints.NotNull;
Expand All @@ -24,6 +25,7 @@ public class DefaultKeyValueStoreDimensionConfig implements DimensionConfig {
private final LinkedHashSet<DimensionField> defaultDimensionFields;
private final KeyValueStore keyValueStore;
private final SearchProvider searchProvider;
private final StorageStrategy storageStrategy;

/**
* Construct a DefaultKeyValueStoreDimensionConfig instance from dimension name, dimension fields and
Expand Down Expand Up @@ -59,6 +61,7 @@ public DefaultKeyValueStoreDimensionConfig(
this.defaultDimensionFields = defaultDimensionFields;
this.keyValueStore = keyValueStore;
this.searchProvider = searchProvider;
this.storageStrategy = StorageStrategy.LOADED;
}

/**
Expand Down Expand Up @@ -141,4 +144,9 @@ public KeyValueStore getKeyValueStore() {
public SearchProvider getSearchProvider() {
return searchProvider;
}

@Override
public StorageStrategy getStorageStrategy() {
return storageStrategy;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.yahoo.bard.webservice.data.dimension.KeyValueStore;
import com.yahoo.bard.webservice.data.dimension.SearchProvider;
import com.yahoo.bard.webservice.data.dimension.impl.KeyValueStoreDimension;
import com.yahoo.bard.webservice.data.dimension.metadata.StorageStrategy;

import java.util.LinkedHashSet;

Expand Down Expand Up @@ -50,6 +51,13 @@ public interface DimensionConfig {
*/
String getDescription();

/**
* The storage strategy for this dimension.
*
* @return The storage strategy of the dimension
*/
StorageStrategy getStorageStrategy();

/**
* The set of fields for this dimension.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ public KeyValueStoreDimension(DimensionConfig dimensionConfig) {
dimensionConfig.getSearchProvider(),
dimensionConfig.getDefaultDimensionFields(),
dimensionConfig.isAggregatable(),
StorageStrategy.LOADED
dimensionConfig.getStorageStrategy()
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package com.yahoo.bard.webservice.data.config.dimension
import com.yahoo.bard.webservice.data.dimension.DimensionDictionary
import com.yahoo.bard.webservice.data.dimension.impl.KeyValueStoreDimension
import com.yahoo.bard.webservice.data.dimension.impl.LookupDimension
import com.yahoo.bard.webservice.data.dimension.metadata.StorageStrategy
import spock.lang.Specification

/**
Expand Down Expand Up @@ -40,6 +41,19 @@ class TypeAwareDimensionLoadTaskSpec extends Specification {

then:
dimensionDictionary.findByApiName("color").getClass() == KeyValueStoreDimension.class

}

def "Test dimension loader for dimension with storageStrategy none"() {
given: "A Type Aware Dimension LoadTask with a list of dimension configurations"
TypeAwareDimensionLoader typeAwareDimensionLoader = new TypeAwareDimensionLoader(dimensionConfigurations)

when:
typeAwareDimensionLoader.loadDimensionDictionary(dimensionDictionary)

then:
dimensionDictionary.findByApiName("color").getStorageStrategy() == StorageStrategy.NONE
dimensionConfigurations.find({it.apiName == 'color'}).getStorageStrategy() == StorageStrategy.NONE
}

def "Test dimension loader for a dimension type that is not defined"() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class DimensionsServletComponentSpec extends Specification {
String expectedResponse = """{
"dimensions":
[
{"category": "General", "name": "color", "longName": "color", "uri": "http://localhost:${jerseyTestBinder.getHarness().getPort()}/dimensions/color", "cardinality": 0, "storageStrategy":"loaded"},
{"category": "General", "name": "color", "longName": "color", "uri": "http://localhost:${jerseyTestBinder.getHarness().getPort()}/dimensions/color", "cardinality": 0, "storageStrategy":"none"},
{"category": "General", "name": "shape", "longName": "shape", "uri": "http://localhost:${jerseyTestBinder.getHarness().getPort()}/dimensions/shape", "cardinality": 38, "storageStrategy":"loaded"},
{"category": "General", "name": "size", "longName": "size", "uri": "http://localhost:${jerseyTestBinder.getHarness().getPort()}/dimensions/size", "cardinality": 0, "storageStrategy":"loaded"},
{"category": "General", "name": "model", "longName": "model", "uri": "http://localhost:${jerseyTestBinder.getHarness().getPort()}/dimensions/model", "cardinality": 21, "storageStrategy":"loaded"},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -967,7 +967,7 @@ class ExpectedTablesFullViewEndpointSpec extends BaseTableServletComponentSpec {
"category": "General",
"longName": "color",
"name": "color",
"storageStrategy":"loaded",
"storageStrategy":"none",
"fields": [
{
"description":"Blue pigment",
Expand Down Expand Up @@ -1176,7 +1176,7 @@ class ExpectedTablesFullViewEndpointSpec extends BaseTableServletComponentSpec {
"category": "General",
"longName": "color",
"name": "color",
"storageStrategy":"loaded",
"storageStrategy":"none",
"fields": [
{
"description":"Blue pigment",
Expand Down Expand Up @@ -1371,7 +1371,7 @@ class ExpectedTablesFullViewEndpointSpec extends BaseTableServletComponentSpec {
"category": "General",
"longName": "color",
"name": "color",
"storageStrategy":"loaded",
"storageStrategy":"none",
"fields": [
{
"description":"Blue pigment",
Expand Down Expand Up @@ -1580,7 +1580,7 @@ class ExpectedTablesFullViewEndpointSpec extends BaseTableServletComponentSpec {
"category": "General",
"longName": "color",
"name": "color",
"storageStrategy":"loaded",
"storageStrategy":"none",
"fields": [
{
"description":"Blue pigment",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.yahoo.bard.webservice.data.dimension.DimensionField;
import com.yahoo.bard.webservice.data.dimension.KeyValueStore;
import com.yahoo.bard.webservice.data.dimension.SearchProvider;
import com.yahoo.bard.webservice.data.dimension.metadata.StorageStrategy;

import java.util.LinkedHashSet;

Expand All @@ -17,6 +18,7 @@ public class TestDimensionConfig implements DimensionConfig {
private final TestApiDimensionName apiName;
private final String physicalName;
private final String description;
private final StorageStrategy storageStrategy;

private LinkedHashSet<DimensionField> fields;
private LinkedHashSet<DimensionField> defaultFields;
Expand Down Expand Up @@ -48,6 +50,37 @@ public TestDimensionConfig(
this.searchProvider = searchProvider;
this.fields = fields;
this.defaultFields = defaultFields;
this.storageStrategy = StorageStrategy.LOADED;
}

/**
* Constructor.
*
* @param apiName API Name of the dimension
* @param physicalName Physical name of the dimension
* @param keyValueStore KeyValueStore for the dimension
* @param searchProvider SearchProvider for the dimension
* @param fields Fields of the dimension
* @param defaultFields Default fields of the dimension
* @param storageStrategy Storage Strategy of the dimension
*/
public TestDimensionConfig(
TestApiDimensionName apiName,
String physicalName,
KeyValueStore keyValueStore,
SearchProvider searchProvider,
LinkedHashSet<DimensionField> fields,
LinkedHashSet<DimensionField> defaultFields,
StorageStrategy storageStrategy
) {
this.apiName = apiName;
this.physicalName = physicalName;
this.description = apiName.asName();
this.keyValueStore = keyValueStore;
this.searchProvider = searchProvider;
this.fields = fields;
this.defaultFields = defaultFields;
this.storageStrategy = storageStrategy;
}

//CHECKSTYLE:OFF
Expand Down Expand Up @@ -129,4 +162,9 @@ public SearchProvider getSearchProvider() {
public String toString() {
return "Dimension Config: apiName: " + apiName + " physicalName: " + physicalName + " fields: " + fields;
}

@Override
public StorageStrategy getStorageStrategy() {
return storageStrategy;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import com.yahoo.bard.webservice.data.dimension.impl.LuceneSearchProviderManager;
import com.yahoo.bard.webservice.data.dimension.impl.NoOpSearchProviderManager;
import com.yahoo.bard.webservice.data.dimension.impl.ScanSearchProvider;
import com.yahoo.bard.webservice.data.dimension.metadata.StorageStrategy;
import com.yahoo.bard.webservice.util.EnumUtils;
import com.yahoo.bard.webservice.util.Utils;

Expand Down Expand Up @@ -52,7 +53,7 @@ public TestDimensions() {
dimensionNameConfigs = new LinkedHashMap<>();
dimensionNameConfigs.put(SIZE, TestDimensions.buildStandardDimensionConfig(SIZE));
dimensionNameConfigs.put(SHAPE, TestDimensions.buildStandardDimensionConfig(SHAPE));
dimensionNameConfigs.put(COLOR, TestDimensions.buildStandardDimensionConfig(COLOR));
dimensionNameConfigs.put(COLOR, TestDimensions.buildNonLoadedDimensionConfig(COLOR));
dimensionNameConfigs.put(OTHER,
new TestDimensionConfig(
OTHER,
Expand Down Expand Up @@ -109,6 +110,25 @@ protected static TestDimensionConfig buildStandardDimensionConfig(TestApiDimensi
);
}

/**
* Build a non-loaded dimension config.
*
* @param dimensionName Name of the dimension to build
*
* @return the standard dimension config
*/
protected static TestDimensionConfig buildNonLoadedDimensionConfig(TestApiDimensionName dimensionName) {
return new TestDimensionConfig(
dimensionName,
dimensionName.asName(),
getDefaultKeyValueStore(dimensionName),
getDefaultSearchProvider(),
getDefaultFields(),
getDefaultFields(),
StorageStrategy.NONE
);
}

/**
* Build a standard-config Lucene-backed dimension config.
*
Expand Down

0 comments on commit 910a9a2

Please sign in to comment.