Search in sources :

Example 11 with Field

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());
}
Also used : Field(com.yahoo.elide.core.type.Field) EnumType(javax.persistence.EnumType) Type(com.yahoo.elide.modelconfig.model.Type) Table(com.yahoo.elide.modelconfig.model.Table) FromTable(com.yahoo.elide.datastores.aggregation.queryengines.sql.annotation.FromTable) HashMap(java.util.HashMap) Test(org.junit.jupiter.api.Test)

Example 12 with Field

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));
}
Also used : Field(com.yahoo.elide.core.type.Field) Table(com.yahoo.elide.modelconfig.model.Table) FromTable(com.yahoo.elide.datastores.aggregation.queryengines.sql.annotation.FromTable) Test(org.junit.jupiter.api.Test)

Example 13 with Field

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);
}
Also used : Field(com.yahoo.elide.core.type.Field) Table(com.yahoo.elide.modelconfig.model.Table) FromTable(com.yahoo.elide.datastores.aggregation.queryengines.sql.annotation.FromTable) Id(javax.persistence.Id) Test(org.junit.jupiter.api.Test)

Example 14 with Field

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());
}
Also used : Field(com.yahoo.elide.core.type.Field) Table(com.yahoo.elide.modelconfig.model.Table) FromTable(com.yahoo.elide.datastores.aggregation.queryengines.sql.annotation.FromTable) MetricFormula(com.yahoo.elide.datastores.aggregation.annotation.MetricFormula) Test(org.junit.jupiter.api.Test)

Example 15 with Field

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());
}
Also used : Field(com.yahoo.elide.core.type.Field) Table(com.yahoo.elide.modelconfig.model.Table) FromTable(com.yahoo.elide.datastores.aggregation.queryengines.sql.annotation.FromTable) ColumnMeta(com.yahoo.elide.datastores.aggregation.annotation.ColumnMeta) DimensionFormula(com.yahoo.elide.datastores.aggregation.annotation.DimensionFormula) ReadPermission(com.yahoo.elide.annotation.ReadPermission) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Aggregations

Field (com.yahoo.elide.core.type.Field)16 FromTable (com.yahoo.elide.datastores.aggregation.queryengines.sql.annotation.FromTable)12 Table (com.yahoo.elide.modelconfig.model.Table)12 Test (org.junit.jupiter.api.Test)12 ColumnMeta (com.yahoo.elide.datastores.aggregation.annotation.ColumnMeta)6 Method (com.yahoo.elide.core.type.Method)4 HashSet (java.util.HashSet)4 ReadPermission (com.yahoo.elide.annotation.ReadPermission)3 AccessibleObject (com.yahoo.elide.core.type.AccessibleObject)2 DimensionFormula (com.yahoo.elide.datastores.aggregation.annotation.DimensionFormula)2 MetricFormula (com.yahoo.elide.datastores.aggregation.annotation.MetricFormula)2 Temporal (com.yahoo.elide.datastores.aggregation.annotation.Temporal)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 InvalidAttributeException (com.yahoo.elide.core.exceptions.InvalidAttributeException)1 Serde (com.yahoo.elide.core.utils.coerce.converters.Serde)1 Type (com.yahoo.elide.modelconfig.model.Type)1 HashMap (java.util.HashMap)1 EnumType (javax.persistence.EnumType)1 Enumerated (javax.persistence.Enumerated)1 Id (javax.persistence.Id)1