Search in sources :

Example 1 with TableMeta

use of com.yahoo.elide.datastores.aggregation.annotation.TableMeta in project elide by yahoo.

the class TableType method buildAnnotations.

private static Map<Class<? extends Annotation>, Annotation> buildAnnotations(Table table) {
    Map<Class<? extends Annotation>, Annotation> annotations = new HashMap<>();
    annotations.put(Include.class, getIncludeAnnotation(table));
    if (table.getSql() != null && !table.getSql().isEmpty()) {
        annotations.put(FromSubquery.class, new FromSubquery() {

            @Override
            public Class<? extends Annotation> annotationType() {
                return FromSubquery.class;
            }

            @Override
            public String sql() {
                return table.getSql();
            }

            @Override
            public String dbConnectionName() {
                return table.getDbConnectionName();
            }
        });
    } else {
        annotations.put(FromTable.class, new FromTable() {

            @Override
            public Class<? extends Annotation> annotationType() {
                return FromTable.class;
            }

            @Override
            public String name() {
                String tableName = table.getTable();
                if (table.getSchema() != null && !table.getSchema().isEmpty()) {
                    return table.getSchema() + "." + tableName;
                }
                return tableName;
            }

            @Override
            public String dbConnectionName() {
                return table.getDbConnectionName();
            }
        });
    }
    annotations.put(TableMeta.class, new TableMeta() {

        @Override
        public Class<? extends Annotation> annotationType() {
            return TableMeta.class;
        }

        @Override
        public String friendlyName() {
            return table.getFriendlyName();
        }

        @Override
        public String description() {
            return table.getDescription();
        }

        @Override
        public String category() {
            return table.getCategory();
        }

        @Override
        public String[] hints() {
            return table.getHints().toArray(new String[0]);
        }

        @Override
        public String[] tags() {
            return table.getTags().toArray(new String[0]);
        }

        @Override
        public String filterTemplate() {
            return table.getFilterTemplate();
        }

        @Override
        public boolean isFact() {
            return table.getIsFact();
        }

        @Override
        public boolean isHidden() {
            return table.getHidden() != null && table.getHidden();
        }

        @Override
        public CardinalitySize size() {
            if (table.getCardinality() == null || table.getCardinality().isEmpty()) {
                return CardinalitySize.UNKNOWN;
            }
            return CardinalitySize.valueOf(table.getCardinality().toUpperCase(Locale.ENGLISH));
        }

        @Override
        public ArgumentDefinition[] arguments() {
            return getArgumentDefinitions(table.getArguments());
        }
    });
    String readPermission = table.getReadAccess();
    if (StringUtils.isNotEmpty(readPermission)) {
        annotations.put(ReadPermission.class, new ReadPermission() {

            @Override
            public Class<? extends Annotation> annotationType() {
                return ReadPermission.class;
            }

            @Override
            public String expression() {
                return readPermission;
            }
        });
    }
    return annotations;
}
Also used : CardinalitySize(com.yahoo.elide.datastores.aggregation.annotation.CardinalitySize) HashMap(java.util.HashMap) FromSubquery(com.yahoo.elide.datastores.aggregation.queryengines.sql.annotation.FromSubquery) FromTable(com.yahoo.elide.datastores.aggregation.queryengines.sql.annotation.FromTable) TableMeta(com.yahoo.elide.datastores.aggregation.annotation.TableMeta) ReadPermission(com.yahoo.elide.annotation.ReadPermission) Annotation(java.lang.annotation.Annotation)

Example 2 with TableMeta

use of com.yahoo.elide.datastores.aggregation.annotation.TableMeta in project elide by yahoo.

the class TableTypeTest method testHiddenTableAnnotations.

@Test
void testHiddenTableAnnotations() throws Exception {
    Table testTable = Table.builder().cardinality("medium").description("A test table").friendlyName("foo").table("table1").name("Table").hidden(true).schema("db1").category("category1").build();
    TableType testType = new TableType(testTable);
    Include include = (Include) testType.getAnnotation(Include.class);
    assertNotNull(include);
    TableMeta tableMeta = (TableMeta) testType.getAnnotation(TableMeta.class);
    assertNotNull(tableMeta);
    assertTrue(tableMeta.isHidden());
}
Also used : Table(com.yahoo.elide.modelconfig.model.Table) FromTable(com.yahoo.elide.datastores.aggregation.queryengines.sql.annotation.FromTable) Include(com.yahoo.elide.annotation.Include) TableMeta(com.yahoo.elide.datastores.aggregation.annotation.TableMeta) Test(org.junit.jupiter.api.Test)

Example 3 with TableMeta

use of com.yahoo.elide.datastores.aggregation.annotation.TableMeta in project elide by yahoo.

the class TableTypeTest method testTableAnnotations.

@Test
void testTableAnnotations() throws Exception {
    Set<String> tags = new HashSet<>(Arrays.asList("tag1", "tag2"));
    Set<String> hints = new HashSet<>(Arrays.asList("hint1", "hint2"));
    Table testTable = Table.builder().cardinality("medium").description("A test table").friendlyName("foo").table("table1").name("Table").schema("db1").category("category1").readAccess("Admin").dbConnectionName("dbConn").isFact(true).filterTemplate("a==b").tags(tags).hints(hints).build();
    TableType testType = new TableType(testTable);
    Include include = (Include) testType.getAnnotation(Include.class);
    assertEquals("Table", include.name());
    FromTable fromTable = (FromTable) testType.getAnnotation(FromTable.class);
    assertEquals("db1.table1", fromTable.name());
    assertEquals("dbConn", fromTable.dbConnectionName());
    TableMeta tableMeta = (TableMeta) testType.getAnnotation(TableMeta.class);
    assertEquals("foo", tableMeta.friendlyName());
    assertEquals(CardinalitySize.MEDIUM, tableMeta.size());
    assertEquals("A test table", tableMeta.description());
    assertEquals("category1", tableMeta.category());
    assertTrue(tableMeta.isFact());
    assertEquals(tags, new HashSet<>(Arrays.asList(tableMeta.tags())));
    assertEquals(hints, new HashSet<>(Arrays.asList(tableMeta.hints())));
    assertEquals("a==b", tableMeta.filterTemplate());
    ReadPermission readPermission = (ReadPermission) testType.getAnnotation(ReadPermission.class);
    assertEquals("Admin", readPermission.expression());
}
Also used : Table(com.yahoo.elide.modelconfig.model.Table) FromTable(com.yahoo.elide.datastores.aggregation.queryengines.sql.annotation.FromTable) Include(com.yahoo.elide.annotation.Include) FromTable(com.yahoo.elide.datastores.aggregation.queryengines.sql.annotation.FromTable) TableMeta(com.yahoo.elide.datastores.aggregation.annotation.TableMeta) ReadPermission(com.yahoo.elide.annotation.ReadPermission) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Aggregations

TableMeta (com.yahoo.elide.datastores.aggregation.annotation.TableMeta)3 FromTable (com.yahoo.elide.datastores.aggregation.queryengines.sql.annotation.FromTable)3 Include (com.yahoo.elide.annotation.Include)2 ReadPermission (com.yahoo.elide.annotation.ReadPermission)2 Table (com.yahoo.elide.modelconfig.model.Table)2 Test (org.junit.jupiter.api.Test)2 CardinalitySize (com.yahoo.elide.datastores.aggregation.annotation.CardinalitySize)1 FromSubquery (com.yahoo.elide.datastores.aggregation.queryengines.sql.annotation.FromSubquery)1 Annotation (java.lang.annotation.Annotation)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1