use of com.yahoo.elide.core.type.Field in project elide by yahoo.
the class TableTypeTest method testJoinField.
@Test
void testJoinField() throws Exception {
Table testTable1 = Table.builder().name("table1").join(Join.builder().definition("{{id }} = {{ table2.id}}").kind(Join.Kind.TOONE).type(Join.Type.INNER).name("join1").to("table2.dim2").build()).build();
Table testTable2 = Table.builder().name("table2").dimension(Dimension.builder().name("dim2").type(Type.BOOLEAN).build()).build();
TableType testType1 = new TableType(testTable1);
TableType testType2 = new TableType(testTable2);
Map<String, com.yahoo.elide.core.type.Type<?>> tables = new HashMap<>();
tables.put("table1", testType1);
tables.put("table2", testType2);
testType1.resolveJoins(tables);
Field field = testType1.getDeclaredField("join1");
assertNotNull(field);
com.yahoo.elide.datastores.aggregation.annotation.Join join = field.getAnnotation(com.yahoo.elide.datastores.aggregation.annotation.Join.class);
assertEquals(INNER, join.type());
assertEquals("{{id}} = {{table2.id}}", join.value());
}
use of com.yahoo.elide.core.type.Field in project elide by yahoo.
the class TableTypeTest method testGetAndSetField.
@Test
void testGetAndSetField() throws Exception {
Table testTable = Table.builder().dimension(Dimension.builder().name("dim1").type(Type.BOOLEAN).build()).build();
TableType testType = new TableType(testTable);
DynamicModelInstance testTypeInstance = testType.newInstance();
Field field = testType.getDeclaredField("dim1");
field.set(testTypeInstance, true);
assertTrue((Boolean) field.get(testTypeInstance));
field.set(testTypeInstance, false);
assertFalse((Boolean) field.get(testTypeInstance));
}
use of com.yahoo.elide.core.type.Field in project elide by yahoo.
the class TableTypeTest method testIdField.
@Test
void testIdField() throws Exception {
Table testTable = Table.builder().table("table1").name("Table").build();
TableType testType = new TableType(testTable);
assertTrue(testType.getFields().length == 1);
Field field = testType.getDeclaredField("id");
assertNotNull(field);
Id id = field.getAnnotation(Id.class);
assertNotNull(id);
}
use of com.yahoo.elide.core.type.Field in project elide by yahoo.
the class TableTypeTest method testInvalidResolver.
@Test
void testInvalidResolver() throws Exception {
Table testTable = Table.builder().table("table1").name("Table").measure(Measure.builder().name("measure1").type(Type.BOOLEAN).maker("does.not.exist.class").build()).build();
TableType testType = new TableType(testTable);
Field field = testType.getDeclaredField("measure1");
MetricFormula metricFormula = field.getAnnotation(MetricFormula.class);
assertThrows(IllegalStateException.class, () -> metricFormula.maker());
}
use of com.yahoo.elide.core.type.Field in project elide by yahoo.
the class TableTypeTest method testDimensionAnnotations.
@Test
void testDimensionAnnotations() throws Exception {
Set<String> tags = new HashSet<>(Arrays.asList("tag1", "tag2"));
Table testTable = Table.builder().table("table1").name("Table").dimension(Dimension.builder().type(Type.TEXT).category("category1").definition("{{region}}").hidden(false).friendlyName("Region").name("region").readAccess("Admin").description("A dimension").tags(tags).cardinality("small").tableSource(TableSource.builder().table("region").column("id").build()).build()).build();
TableType testType = new TableType(testTable);
Field field = testType.getDeclaredField("region");
assertNotNull(field);
ReadPermission readPermission = field.getAnnotation(ReadPermission.class);
assertEquals("Admin", readPermission.expression());
ColumnMeta columnMeta = field.getAnnotation(ColumnMeta.class);
assertEquals("A dimension", columnMeta.description());
assertEquals("category1", columnMeta.category());
assertEquals("Region", columnMeta.friendlyName());
assertEquals(CardinalitySize.SMALL, columnMeta.size());
assertEquals(tags, new HashSet<>(Arrays.asList(columnMeta.tags())));
DimensionFormula dimensionFormula = field.getAnnotation(DimensionFormula.class);
assertEquals("{{region}}", dimensionFormula.value());
}
Aggregations