-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Dimension Field Tagging and Dynamic Dimension Field Serilization (#137)
- Loading branch information
1 parent
0381277
commit 2ae0605
Showing
14 changed files
with
265 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<prerequisites> | ||
<maven>3.0</maven> | ||
</prerequisites> | ||
|
||
<parent> | ||
<groupId>com.yahoo.fili</groupId> | ||
<artifactId>fili-parent-pom</artifactId> | ||
<version>0.7-SNAPSHOT</version> | ||
</parent> | ||
|
||
<artifactId>fili-navi</artifactId> | ||
<packaging>jar</packaging> | ||
<name>Fili: Navi Module</name> | ||
<description>Navi support module for Fili</description> | ||
|
||
<licenses> | ||
<license> | ||
<name>The Apache Software License, Version 2.0</name> | ||
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url> | ||
<distribution>repo</distribution> | ||
</license> | ||
</licenses> | ||
|
||
<properties> | ||
<checkstyle.config.location>../checkstyle-style.xml</checkstyle.config.location> | ||
<checkstyle.suppressions.location>../checkstyle-suppressions.xml</checkstyle.suppressions.location> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>com.yahoo.fili</groupId> | ||
<artifactId>fili-core</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.yahoo.fili</groupId> | ||
<artifactId>fili-core</artifactId> | ||
<type>test-jar</type> | ||
</dependency> | ||
</dependencies> | ||
</project> |
19 changes: 19 additions & 0 deletions
19
fili-navi/src/main/java/com/yahoo/bard/webservice/data/dimension/Tag.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// Copyright 2017 Yahoo Inc. | ||
// Licensed under the terms of the Apache license. Please see LICENSE.md file distributed with this work for terms. | ||
package com.yahoo.bard.webservice.data.dimension; | ||
|
||
import com.fasterxml.jackson.annotation.JsonValue; | ||
|
||
/** | ||
* Interface for tags used for tagging dimension fields to add additional properties implicitly specified by its name. | ||
*/ | ||
public interface Tag { | ||
|
||
/** | ||
* Gets the String representation of the tag. | ||
* | ||
* @return the String representation of the tag | ||
*/ | ||
@JsonValue | ||
String getName(); | ||
} |
18 changes: 18 additions & 0 deletions
18
fili-navi/src/main/java/com/yahoo/bard/webservice/data/dimension/TaggedDimensionField.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// Copyright 2017 Yahoo Inc. | ||
// Licensed under the terms of the Apache license. Please see LICENSE.md file distributed with this work for terms. | ||
package com.yahoo.bard.webservice.data.dimension; | ||
|
||
import java.util.Set; | ||
|
||
/** | ||
* Interface for Dimension fields that expects unique tags to be attached to it to add expressiveness. | ||
*/ | ||
public interface TaggedDimensionField extends DimensionField { | ||
|
||
/** | ||
* Get a set of tags associated to the current field. | ||
* | ||
* @return a list of tags | ||
*/ | ||
Set<? extends Tag> getTags(); | ||
} |
31 changes: 31 additions & 0 deletions
31
...src/main/java/com/yahoo/bard/webservice/data/dimension/impl/DefaultDimensionFieldTag.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// Copyright 2017 Yahoo Inc. | ||
// Licensed under the terms of the Apache license. Please see LICENSE.md file distributed with this work for terms. | ||
package com.yahoo.bard.webservice.data.dimension.impl; | ||
|
||
import com.yahoo.bard.webservice.data.dimension.Tag; | ||
import com.yahoo.bard.webservice.util.EnumUtils; | ||
|
||
/** | ||
* Default dimension field tag provided to match fili core concepts. | ||
*/ | ||
public enum DefaultDimensionFieldTag implements Tag { | ||
/** | ||
* Dimension field tag to match fili concept of a "key" field. | ||
*/ | ||
PRIMARY_KEY | ||
; | ||
|
||
private final String tagName; | ||
|
||
/** | ||
* Constructor, build name using camel cased enum name. | ||
*/ | ||
DefaultDimensionFieldTag() { | ||
this.tagName = EnumUtils.camelCase(name()); | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return tagName; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# Copyright 2017 Yahoo Inc. | ||
# Licensed under the terms of the Apache license. Please see LICENSE.md file distributed with this work for terms. | ||
|
||
#The name of this module (required) | ||
moduleName = fili-navi | ||
|
||
moduleDependencies = fili-core |
14 changes: 14 additions & 0 deletions
14
fili-navi/src/test/groovy/com/yahoo/bard/systemconfig/NaviModuleSetupSpec.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// Copyright 2017 Yahoo Inc. | ||
// Licensed under the terms of the Apache license. Please see LICENSE.md file distributed with this work for terms. | ||
package com.yahoo.bard.systemconfig | ||
|
||
/** | ||
* Basic module setup check test. | ||
*/ | ||
class NaviModuleSetupSpec extends ModuleSetupSpec { | ||
|
||
@Override | ||
String getModuleName() { | ||
return "fili-navi" | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
.../src/test/groovy/com/yahoo/bard/webservice/data/dimension/TaggedDimensionFieldSpec.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package com.yahoo.bard.webservice.data.dimension | ||
|
||
import static com.yahoo.bard.webservice.data.dimension.TestTaggedDimensionField.TEST_TWO_TAG | ||
import static com.yahoo.bard.webservice.data.dimension.TestTaggedDimensionField.TEST_ONE_TAG | ||
import static com.yahoo.bard.webservice.data.dimension.TestTaggedDimensionField.TEST_NO_TAG | ||
import static com.yahoo.bard.webservice.data.dimension.impl.DefaultDimensionFieldTag.PRIMARY_KEY | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper | ||
|
||
import spock.lang.Specification | ||
|
||
/** | ||
* Test tagged dimension field behavior and serialization. | ||
*/ | ||
class TaggedDimensionFieldSpec extends Specification { | ||
|
||
ObjectMapper objectMapper | ||
Tag mockTag | ||
DimensionField noTagField | ||
TaggedDimensionField oneTagField | ||
TaggedDimensionField twoTagField | ||
|
||
def setup() { | ||
objectMapper = new ObjectMapper() | ||
|
||
mockTag = Mock(Tag) | ||
mockTag.getName() >> "mockTag" | ||
|
||
noTagField = TEST_NO_TAG | ||
oneTagField = TEST_ONE_TAG | ||
twoTagField = TEST_TWO_TAG | ||
|
||
noTagField.setTags([] as Set<Tag>) | ||
oneTagField.setTags([PRIMARY_KEY] as Set<Tag>) | ||
twoTagField.setTags([PRIMARY_KEY, mockTag] as Set<Tag>) | ||
} | ||
|
||
def "Dimension field interface should behave correctly"() { | ||
expect: | ||
oneTagField.getName() == "testOneTag" | ||
oneTagField.getDescription() == "testOneTag description" | ||
oneTagField.getTags() == [PRIMARY_KEY] as Set | ||
twoTagField.getTags() == [PRIMARY_KEY, mockTag] as Set | ||
} | ||
|
||
def "Tagged dimension fields serialize as expected"() { | ||
expect: | ||
objectMapper.writeValueAsString(noTagField) == '{"name":"testNoTag","tags":[],"description":"testNoTag description"}' | ||
objectMapper.writeValueAsString(oneTagField) == '{"name":"testOneTag","tags":["primaryKey"],"description":"testOneTag description"}' | ||
objectMapper.writeValueAsString(twoTagField) == '{"name":"testTwoTag","tags":["primaryKey","mockTag"],"description":"testTwoTag description"}' | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
...navi/src/test/java/com/yahoo/bard/webservice/data/dimension/TestTaggedDimensionField.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// Copyright 2017 Yahoo Inc. | ||
// Licensed under the terms of the Apache license. Please see LICENSE.md file distributed with this work for terms. | ||
package com.yahoo.bard.webservice.data.dimension; | ||
|
||
import com.yahoo.bard.webservice.util.EnumUtils; | ||
|
||
import java.util.Collections; | ||
import java.util.Set; | ||
|
||
/** | ||
* Test implementation of TaggedDimensionField used in testings. | ||
*/ | ||
public enum TestTaggedDimensionField implements TaggedDimensionField { | ||
TEST_NO_TAG, | ||
TEST_ONE_TAG, | ||
TEST_TWO_TAG | ||
; | ||
|
||
private final String name; | ||
private Set<? extends Tag> tags; | ||
|
||
/** | ||
* Constructor. | ||
*/ | ||
TestTaggedDimensionField() { | ||
this.name = EnumUtils.camelCase(name()); | ||
this.tags = Collections.emptySet(); | ||
} | ||
|
||
public void setTags(Set<? extends Tag> tags) { | ||
this.tags = tags; | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return name; | ||
} | ||
|
||
@Override | ||
public String getDescription() { | ||
return getName() + " description"; | ||
} | ||
|
||
@Override | ||
public Set<? extends Tag> getTags() { | ||
return tags; | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
fili-navi/src/test/resources/testApplicationConfig.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# Copyright 2017 Yahoo Inc. | ||
# Licensed under the terms of the Apache license. Please see LICENSE.md file distributed with this work for terms. | ||
|
||
#The name of this module (required) | ||
moduleName = fili-navi | ||
|
||
moduleDependencies = fili-core |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters