-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Support Venice Primitive keys & add tests * Fix template reuse
- Loading branch information
Showing
8 changed files
with
97 additions
and
7 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
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
43 changes: 43 additions & 0 deletions
43
hoptimator-util/src/test/java/com/linkedin/hoptimator/util/TestTemplate.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,43 @@ | ||
package com.linkedin.hoptimator.util; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
public class TestTemplate { | ||
|
||
@Test | ||
public void testRender() { | ||
Template.Environment env = new Template.SimpleEnvironment() | ||
.with("name", "name") | ||
.with("nameUpper", "name") | ||
.with("nameLower", "NAME") | ||
.with("multiline", "1\n2\n3\n") | ||
.with("multilineUpper", "a\nb\nc\n") | ||
.with("other", "test"); | ||
|
||
String template = "{{keys:KEY}}\n" | ||
+ "{{keyPrefix:}}\n" | ||
+ "{{name:default}}\n" | ||
+ "{{nameUpper toUpperCase}}\n" | ||
+ "{{nameLower toLowerCase}}\n" | ||
+ "{{multiline concat}}\n" | ||
+ "{{multilineUpper concat toUpperCase}}\n" | ||
+ "{{other unknown}}\n"; | ||
|
||
String renderedTemplate = new Template.SimpleTemplate(template).render(env); | ||
List<String> renderedTemplates = Arrays.asList(renderedTemplate.split("\n")); | ||
assertEquals(8, renderedTemplates.size()); | ||
assertEquals("KEY", renderedTemplates.get(0)); | ||
assertEquals("", renderedTemplates.get(1)); | ||
assertEquals("name", renderedTemplates.get(2)); | ||
assertEquals("NAME", renderedTemplates.get(3)); | ||
assertEquals("name", renderedTemplates.get(4)); | ||
assertEquals("123", renderedTemplates.get(5)); | ||
assertEquals("ABC", renderedTemplates.get(6)); | ||
assertEquals("test", renderedTemplates.get(7)); | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
hoptimator-util/src/test/java/com/linkedin/hoptimator/util/planner/TestPipelineRel.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,39 @@ | ||
package com.linkedin.hoptimator.util.planner; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import org.apache.calcite.rel.type.RelDataTypeFactory; | ||
import org.apache.calcite.rel.type.RelDataTypeSystem; | ||
import org.apache.calcite.sql.type.SqlTypeFactoryImpl; | ||
import org.apache.calcite.sql.type.SqlTypeName; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static com.linkedin.hoptimator.util.planner.PipelineRel.Implementor.addKeysAsOption; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
public class TestPipelineRel { | ||
|
||
@Test | ||
public void testKeyOptions() { | ||
RelDataTypeFactory typeFactory = new SqlTypeFactoryImpl(RelDataTypeSystem.DEFAULT); | ||
RelDataTypeFactory.Builder primitiveKeyBuilder = new RelDataTypeFactory.Builder(typeFactory); | ||
primitiveKeyBuilder.add("KEY", SqlTypeName.VARCHAR); | ||
primitiveKeyBuilder.add("intField", SqlTypeName.INTEGER); | ||
Map<String, String> keyOptions = addKeysAsOption(new HashMap<>(), primitiveKeyBuilder.build()); | ||
assertTrue(keyOptions.isEmpty()); | ||
|
||
RelDataTypeFactory.Builder keyBuilder = new RelDataTypeFactory.Builder(typeFactory); | ||
keyBuilder.add("keyInt", SqlTypeName.INTEGER); | ||
keyBuilder.add("keyString", SqlTypeName.VARCHAR); | ||
RelDataTypeFactory.Builder recordBuilder = new RelDataTypeFactory.Builder(typeFactory); | ||
recordBuilder.add("intField", SqlTypeName.INTEGER); | ||
recordBuilder.add("KEY", keyBuilder.build()); | ||
keyOptions = addKeysAsOption(new HashMap<>(), recordBuilder.build()); | ||
assertEquals(3, keyOptions.size()); | ||
assertEquals("KEY_keyInt;KEY_keyString", keyOptions.get("keys")); | ||
assertEquals("KEY_", keyOptions.get("keyPrefix")); | ||
assertEquals("RECORD", keyOptions.get("keyType")); | ||
} | ||
} |