Search in sources :

Example 1 with CardinalitySize

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

the class TableType method buildAnnotations.

private static Map<Class<? extends Annotation>, Annotation> buildAnnotations(Dimension dimension) {
    Map<Class<? extends Annotation>, Annotation> annotations = new HashMap<>();
    annotations.put(ColumnMeta.class, new ColumnMeta() {

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

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

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

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

        @Override
        public TableSource tableSource() {
            return buildTableSource(dimension.getTableSource());
        }

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

        @Override
        public String[] values() {
            return dimension.getValues().toArray(new String[0]);
        }

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

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

        @Override
        public CardinalitySize size() {
            if (dimension.getCardinality() == null || dimension.getCardinality().isEmpty()) {
                return CardinalitySize.UNKNOWN;
            }
            return CardinalitySize.valueOf(dimension.getCardinality().toUpperCase(Locale.ENGLISH));
        }
    });
    annotations.put(DimensionFormula.class, new DimensionFormula() {

        @Override
        public ArgumentDefinition[] arguments() {
            return getArgumentDefinitions(dimension.getArguments());
        }

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

        @Override
        public String value() {
            return trimColumnReferences(dimension.getDefinition());
        }
    });
    String readPermission = dimension.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;
            }
        });
    }
    if (dimension.getType().toUpperCase(Locale.ROOT).equals(ENUM_ORDINAL)) {
        annotations.put(Enumerated.class, getEnumeratedAnnotation(EnumType.ORDINAL));
    }
    if (dimension.getType().toUpperCase(Locale.ROOT).equals(TIME)) {
        annotations.put(Temporal.class, new Temporal() {

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

            @Override
            public TimeGrainDefinition[] grains() {
                int numGrains = dimension.getGrains() == null ? 0 : dimension.getGrains().size();
                TimeGrainDefinition[] definitions = new TimeGrainDefinition[numGrains];
                for (int idx = 0; idx < numGrains; idx++) {
                    Grain grain = dimension.getGrains().get(idx);
                    definitions[idx] = new TimeGrainDefinition() {

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

                        @Override
                        public TimeGrain grain() {
                            if (grain.getType() == null) {
                                return TimeGrain.DAY;
                            }
                            return TimeGrain.valueOf(grain.getType().name());
                        }

                        @Override
                        public String expression() {
                            String sql = grain.getSql();
                            if (StringUtils.isEmpty(sql)) {
                                return "{{$$column.expr}}";
                            }
                            return grain.getSql();
                        }
                    };
                }
                return definitions;
            }

            @Override
            public String timeZone() {
                return "UTC";
            }
        });
    }
    return annotations;
}
Also used : CardinalitySize(com.yahoo.elide.datastores.aggregation.annotation.CardinalitySize) HashMap(java.util.HashMap) Grain(com.yahoo.elide.modelconfig.model.Grain) TimeGrain(com.yahoo.elide.datastores.aggregation.metadata.enums.TimeGrain) Annotation(java.lang.annotation.Annotation) TableSource(com.yahoo.elide.datastores.aggregation.annotation.TableSource) 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) TimeGrainDefinition(com.yahoo.elide.datastores.aggregation.annotation.TimeGrainDefinition)

Example 2 with CardinalitySize

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

the class TableType method buildAnnotations.

private static Map<Class<? extends Annotation>, Annotation> buildAnnotations(Measure measure) {
    Map<Class<? extends Annotation>, Annotation> annotations = new HashMap<>();
    annotations.put(ColumnMeta.class, new ColumnMeta() {

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

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

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

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

        @Override
        public TableSource tableSource() {
            return buildTableSource(null);
        }

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

        @Override
        public String[] values() {
            return new String[0];
        }

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

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

        @Override
        public CardinalitySize size() {
            return CardinalitySize.UNKNOWN;
        }
    });
    annotations.put(MetricFormula.class, new MetricFormula() {

        @Override
        public ArgumentDefinition[] arguments() {
            return getArgumentDefinitions(measure.getArguments());
        }

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

        @Override
        public String value() {
            if (measure.getDefinition() != null) {
                return trimColumnReferences(measure.getDefinition());
            } else {
                return "";
            }
        }

        @Override
        public Class<? extends MetricProjectionMaker> maker() {
            if (measure.getMaker() == null || measure.getMaker().isEmpty()) {
                return DefaultMetricProjectionMaker.class;
            }
            try {
                return (Class<? extends MetricProjectionMaker>) Class.forName(measure.getMaker());
            } catch (ClassNotFoundException e) {
                throw new IllegalStateException(e);
            }
        }
    });
    String readPermission = measure.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) MetricFormula(com.yahoo.elide.datastores.aggregation.annotation.MetricFormula) MetricProjectionMaker(com.yahoo.elide.datastores.aggregation.query.MetricProjectionMaker) DefaultMetricProjectionMaker(com.yahoo.elide.datastores.aggregation.query.DefaultMetricProjectionMaker) HashMap(java.util.HashMap) Annotation(java.lang.annotation.Annotation) TableSource(com.yahoo.elide.datastores.aggregation.annotation.TableSource) ColumnMeta(com.yahoo.elide.datastores.aggregation.annotation.ColumnMeta) ReadPermission(com.yahoo.elide.annotation.ReadPermission)

Example 3 with CardinalitySize

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

the class TableType method buildIdField.

private static Field buildIdField() {
    Map<Class<? extends Annotation>, Annotation> annotations = new HashMap<>();
    annotations.put(Id.class, new Id() {

        @Override
        public Class<? extends Annotation> annotationType() {
            return Id.class;
        }
    });
    annotations.put(GeneratedValue.class, new GeneratedValue() {

        @Override
        public GenerationType strategy() {
            return GenerationType.AUTO;
        }

        @Override
        public String generator() {
            return "";
        }

        @Override
        public Class<? extends Annotation> annotationType() {
            return GeneratedValue.class;
        }
    });
    annotations.put(ColumnMeta.class, new ColumnMeta() {

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

        @Override
        public String friendlyName() {
            return "Row Number";
        }

        @Override
        public String description() {
            return "Row number for each record returned by a query.";
        }

        @Override
        public String category() {
            return null;
        }

        @Override
        public TableSource tableSource() {
            return buildTableSource(null);
        }

        @Override
        public String[] tags() {
            return new String[0];
        }

        @Override
        public String[] values() {
            return new String[0];
        }

        @Override
        public boolean isHidden() {
            return false;
        }

        @Override
        public String filterTemplate() {
            return "";
        }

        @Override
        public CardinalitySize size() {
            return CardinalitySize.UNKNOWN;
        }
    });
    return new FieldType("id", LONG_TYPE, annotations);
}
Also used : CardinalitySize(com.yahoo.elide.datastores.aggregation.annotation.CardinalitySize) HashMap(java.util.HashMap) Annotation(java.lang.annotation.Annotation) GenerationType(javax.persistence.GenerationType) GeneratedValue(javax.persistence.GeneratedValue) TableSource(com.yahoo.elide.datastores.aggregation.annotation.TableSource) ColumnMeta(com.yahoo.elide.datastores.aggregation.annotation.ColumnMeta) Id(javax.persistence.Id)

Example 4 with CardinalitySize

use of com.yahoo.elide.datastores.aggregation.annotation.CardinalitySize 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)

Aggregations

CardinalitySize (com.yahoo.elide.datastores.aggregation.annotation.CardinalitySize)4 Annotation (java.lang.annotation.Annotation)4 HashMap (java.util.HashMap)4 ReadPermission (com.yahoo.elide.annotation.ReadPermission)3 ColumnMeta (com.yahoo.elide.datastores.aggregation.annotation.ColumnMeta)3 TableSource (com.yahoo.elide.datastores.aggregation.annotation.TableSource)3 DimensionFormula (com.yahoo.elide.datastores.aggregation.annotation.DimensionFormula)1 MetricFormula (com.yahoo.elide.datastores.aggregation.annotation.MetricFormula)1 TableMeta (com.yahoo.elide.datastores.aggregation.annotation.TableMeta)1 Temporal (com.yahoo.elide.datastores.aggregation.annotation.Temporal)1 TimeGrainDefinition (com.yahoo.elide.datastores.aggregation.annotation.TimeGrainDefinition)1 TimeGrain (com.yahoo.elide.datastores.aggregation.metadata.enums.TimeGrain)1 DefaultMetricProjectionMaker (com.yahoo.elide.datastores.aggregation.query.DefaultMetricProjectionMaker)1 MetricProjectionMaker (com.yahoo.elide.datastores.aggregation.query.MetricProjectionMaker)1 FromSubquery (com.yahoo.elide.datastores.aggregation.queryengines.sql.annotation.FromSubquery)1 FromTable (com.yahoo.elide.datastores.aggregation.queryengines.sql.annotation.FromTable)1 Grain (com.yahoo.elide.modelconfig.model.Grain)1 GeneratedValue (javax.persistence.GeneratedValue)1 GenerationType (javax.persistence.GenerationType)1 Id (javax.persistence.Id)1