Search in sources :

Example 6 with Field

use of com.yahoo.elide.core.type.Field in project elide by yahoo.

the class TableTypeTest method testMultipleTimeDimensionGrains.

@Test
void testMultipleTimeDimensionGrains() throws Exception {
    Table testTable = Table.builder().table("table1").name("Table").dimension(Dimension.builder().type(Type.TIME).definition("{{createdOn}}").name("createdOn").grain(Grain.builder().sql("some sql").type(Grain.GrainType.DAY).build()).grain(Grain.builder().sql("some other sql").type(Grain.GrainType.YEAR).build()).build()).build();
    TableType testType = new TableType(testTable);
    Field field = testType.getDeclaredField("createdOn");
    assertNotNull(field);
    Temporal temporal = field.getAnnotation(Temporal.class);
    assertEquals("UTC", temporal.timeZone());
    assertTrue(temporal.grains().length == 2);
    assertEquals("some sql", temporal.grains()[0].expression());
    assertEquals("some other sql", temporal.grains()[1].expression());
    assertEquals(TimeGrain.DAY, temporal.grains()[0].grain());
    assertEquals(TimeGrain.YEAR, temporal.grains()[1].grain());
}
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) Temporal(com.yahoo.elide.datastores.aggregation.annotation.Temporal) Test(org.junit.jupiter.api.Test)

Example 7 with Field

use of com.yahoo.elide.core.type.Field in project elide by yahoo.

the class TableTypeTest method testEnumeratedDimension.

@Test
void testEnumeratedDimension() throws Exception {
    Table testTable = Table.builder().table("table1").name("Table").dimension(Dimension.builder().name("dim1").type("ENUM_ORDINAL").values(Set.of("A", "B", "C")).build()).build();
    TableType testType = new TableType(testTable);
    Field field = testType.getDeclaredField("dim1");
    assertNotNull(field);
    Enumerated enumerated = field.getAnnotation(Enumerated.class);
    assertNotNull(enumerated);
    assertEquals(EnumType.ORDINAL, enumerated.value());
}
Also used : Field(com.yahoo.elide.core.type.Field) Enumerated(javax.persistence.Enumerated) Table(com.yahoo.elide.modelconfig.model.Table) FromTable(com.yahoo.elide.datastores.aggregation.queryengines.sql.annotation.FromTable) Test(org.junit.jupiter.api.Test)

Example 8 with Field

use of com.yahoo.elide.core.type.Field in project elide by yahoo.

the class TableTypeTest method testTimeDimensionAnnotations.

@Test
void testTimeDimensionAnnotations() throws Exception {
    Set<String> tags = new HashSet<>(Arrays.asList("tag1", "tag2"));
    Table testTable = Table.builder().table("table1").name("Table").dimension(Dimension.builder().type(Type.TIME).category("category1").definition("{{createdOn  }}").hidden(false).friendlyName("Created On").name("createdOn").readAccess("Admin").description("A time dimension").tags(tags).build()).build();
    TableType testType = new TableType(testTable);
    Field field = testType.getDeclaredField("createdOn");
    assertNotNull(field);
    ReadPermission readPermission = field.getAnnotation(ReadPermission.class);
    assertEquals("Admin", readPermission.expression());
    ColumnMeta columnMeta = field.getAnnotation(ColumnMeta.class);
    assertEquals("A time dimension", columnMeta.description());
    assertEquals("category1", columnMeta.category());
    assertEquals("Created On", columnMeta.friendlyName());
    assertEquals(CardinalitySize.UNKNOWN, columnMeta.size());
    assertEquals(tags, new HashSet<>(Arrays.asList(columnMeta.tags())));
    DimensionFormula dimensionFormula = field.getAnnotation(DimensionFormula.class);
    assertEquals("{{createdOn}}", dimensionFormula.value());
    Temporal temporal = field.getAnnotation(Temporal.class);
    assertEquals("UTC", temporal.timeZone());
    assertTrue(temporal.grains().length == 0);
}
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) Temporal(com.yahoo.elide.datastores.aggregation.annotation.Temporal) ReadPermission(com.yahoo.elide.annotation.ReadPermission) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Example 9 with Field

use of com.yahoo.elide.core.type.Field in project elide by yahoo.

the class TableTypeTest method testHiddenMeasure.

@Test
void testHiddenMeasure() throws Exception {
    Table testTable = Table.builder().table("table1").name("Table").measure(Measure.builder().name("measure1").type(Type.BOOLEAN).hidden(true).build()).build();
    TableType testType = new TableType(testTable);
    Field field = testType.getDeclaredField("measure1");
    assertNotNull(field);
    ColumnMeta columnMeta = field.getAnnotation(ColumnMeta.class);
    assertNotNull(columnMeta);
    assertTrue(columnMeta.isHidden());
}
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) Test(org.junit.jupiter.api.Test)

Example 10 with Field

use of com.yahoo.elide.core.type.Field in project elide by yahoo.

the class TableTypeTest method testDimensionTableValues.

@Test
void testDimensionTableValues() throws Exception {
    Set<String> values = new HashSet<>(Arrays.asList("DIM1", "DIM2"));
    Table testTable = Table.builder().table("table1").name("Table").dimension(Dimension.builder().type(Type.COORDINATE).name("location").values(values).build()).build();
    TableType testType = new TableType(testTable);
    Field field = testType.getDeclaredField("location");
    assertNotNull(field);
    ColumnMeta columnMeta = field.getAnnotation(ColumnMeta.class);
    assertEquals(values, new HashSet<>(Arrays.asList(columnMeta.values())));
}
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) 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