Search in sources :

Example 16 with MetaDataStore

use of com.yahoo.elide.datastores.aggregation.metadata.MetaDataStore in project elide by yahoo.

the class TableArgumentValidatorTest method testTableArgsTypeMismatchForJoinTable.

@Test
public void testTableArgsTypeMismatchForJoinTable() {
    Table mainTable = mainTableBuilder.join(Join.builder().name("join").namespace("namespace").to("JoinTable").definition("start {{$$table.args.mainArg1}} end").build()).build();
    Set<Table> tables = new HashSet<>();
    tables.add(mainTable);
    tables.add(Table.builder().name("JoinTable").namespace("namespace").argument(Argument.builder().name("mainArg1").type(Type.TEXT).values(Collections.emptySet()).defaultValue("").build()).build());
    MetaDataStore metaDataStore = new MetaDataStore(DefaultClassScanner.getInstance(), tables, this.namespaceConfigs, true);
    QueryPlanMerger merger = new DefaultQueryPlanMerger(metaDataStore);
    Exception e = assertThrows(IllegalStateException.class, () -> new SQLQueryEngine(metaDataStore, connectionLookup, optimizers, merger, queryValidator));
    assertEquals("Failed to verify table arguments for table: namespace_MainTable. Argument type mismatch. Join table: 'namespace_JoinTable' has same Argument: 'mainArg1' with type 'TEXT'.", e.getMessage());
}
Also used : SQLQueryEngine(com.yahoo.elide.datastores.aggregation.queryengines.sql.SQLQueryEngine) DefaultQueryPlanMerger(com.yahoo.elide.datastores.aggregation.query.DefaultQueryPlanMerger) QueryPlanMerger(com.yahoo.elide.datastores.aggregation.query.QueryPlanMerger) Table(com.yahoo.elide.modelconfig.model.Table) MetaDataStore(com.yahoo.elide.datastores.aggregation.metadata.MetaDataStore) DefaultQueryPlanMerger(com.yahoo.elide.datastores.aggregation.query.DefaultQueryPlanMerger) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Example 17 with MetaDataStore

use of com.yahoo.elide.datastores.aggregation.metadata.MetaDataStore in project elide by yahoo.

the class TableArgumentValidatorTest method testUndefinedTableArgsInColumnDefinition.

@Test
public void testUndefinedTableArgsInColumnDefinition() {
    Table mainTable = mainTableBuilder.dimension(Dimension.builder().name("dim1").type(Type.BOOLEAN).values(Collections.emptySet()).tags(Collections.emptySet()).definition("start {{$$table.args.mainArg1}} blah {{$$table.args.mainArg2}} end").build()).build();
    Set<Table> tables = new HashSet<>();
    tables.add(mainTable);
    MetaDataStore metaDataStore = new MetaDataStore(DefaultClassScanner.getInstance(), tables, this.namespaceConfigs, true);
    QueryPlanMerger merger = new DefaultQueryPlanMerger(metaDataStore);
    Exception e = assertThrows(IllegalStateException.class, () -> new SQLQueryEngine(metaDataStore, connectionLookup, optimizers, merger, queryValidator));
    assertEquals("Failed to verify table arguments for table: namespace_MainTable. Argument 'mainArg2' is not defined but found '{{$$table.args.mainArg2}}' in definition of column: 'dim1'.", e.getMessage());
}
Also used : SQLQueryEngine(com.yahoo.elide.datastores.aggregation.queryengines.sql.SQLQueryEngine) DefaultQueryPlanMerger(com.yahoo.elide.datastores.aggregation.query.DefaultQueryPlanMerger) QueryPlanMerger(com.yahoo.elide.datastores.aggregation.query.QueryPlanMerger) Table(com.yahoo.elide.modelconfig.model.Table) MetaDataStore(com.yahoo.elide.datastores.aggregation.metadata.MetaDataStore) DefaultQueryPlanMerger(com.yahoo.elide.datastores.aggregation.query.DefaultQueryPlanMerger) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Example 18 with MetaDataStore

use of com.yahoo.elide.datastores.aggregation.metadata.MetaDataStore in project elide by yahoo.

the class ElideAutoConfiguration method buildQueryEngine.

/**
 * Create a QueryEngine instance for aggregation data store to use.
 * @param defaultDataSource DataSource for JPA.
 * @param dynamicConfig An instance of DynamicConfiguration.
 * @param settings Elide configuration settings.
 * @param dataSourceConfiguration DataSource Configuration
 * @param dbPasswordExtractor Password Extractor Implementation
 * @return An instance of a QueryEngine
 */
@Bean
@ConditionalOnMissingBean
@ConditionalOnProperty(name = "elide.aggregation-store.enabled", havingValue = "true")
@Scope(SCOPE_PROTOTYPE)
public QueryEngine buildQueryEngine(DataSource defaultDataSource, @Autowired(required = false) DynamicConfiguration dynamicConfig, ElideConfigProperties settings, ClassScanner scanner, DataSourceConfiguration dataSourceConfiguration, DBPasswordExtractor dbPasswordExtractor) {
    boolean enableMetaDataStore = settings.getAggregationStore().isEnableMetaDataStore();
    ConnectionDetails defaultConnectionDetails = new ConnectionDetails(defaultDataSource, SQLDialectFactory.getDialect(settings.getAggregationStore().getDefaultDialect()));
    if (isDynamicConfigEnabled(settings)) {
        MetaDataStore metaDataStore = new MetaDataStore(scanner, dynamicConfig.getTables(), dynamicConfig.getNamespaceConfigurations(), enableMetaDataStore);
        Map<String, ConnectionDetails> connectionDetailsMap = new HashMap<>();
        dynamicConfig.getDatabaseConfigurations().forEach(dbConfig -> {
            connectionDetailsMap.put(dbConfig.getName(), new ConnectionDetails(dataSourceConfiguration.getDataSource(dbConfig, dbPasswordExtractor), SQLDialectFactory.getDialect(dbConfig.getDialect())));
        });
        Function<String, ConnectionDetails> connectionDetailsLookup = (name) -> {
            if (StringUtils.isEmpty(name)) {
                return defaultConnectionDetails;
            }
            return Optional.ofNullable(connectionDetailsMap.get(name)).orElseThrow(() -> new IllegalStateException("ConnectionDetails undefined for connection: " + name));
        };
        return new SQLQueryEngine(metaDataStore, connectionDetailsLookup, new HashSet<>(Arrays.asList(new AggregateBeforeJoinOptimizer(metaDataStore))), new DefaultQueryPlanMerger(metaDataStore), new DefaultQueryValidator(metaDataStore.getMetadataDictionary()));
    }
    MetaDataStore metaDataStore = new MetaDataStore(scanner, enableMetaDataStore);
    return new SQLQueryEngine(metaDataStore, (unused) -> defaultConnectionDetails);
}
Also used : Arrays(java.util.Arrays) DynamicConfiguration(com.yahoo.elide.modelconfig.DynamicConfiguration) Autowired(org.springframework.beans.factory.annotation.Autowired) Role(com.yahoo.elide.core.security.checks.prefab.Role) StringUtils(org.apache.commons.lang3.StringUtils) ClassType(com.yahoo.elide.core.type.ClassType) DataSourceConfiguration(com.yahoo.elide.datastores.aggregation.queryengines.sql.DataSourceConfiguration) RefreshScope(org.springframework.cloud.context.config.annotation.RefreshScope) RSQLFilterDialect(com.yahoo.elide.core.filter.dialect.RSQLFilterDialect) DefaultJSONApiLinks(com.yahoo.elide.jsonapi.links.DefaultJSONApiLinks) ClassScanner(com.yahoo.elide.core.utils.ClassScanner) AggregateBeforeJoinOptimizer(com.yahoo.elide.datastores.aggregation.queryengines.sql.query.AggregateBeforeJoinOptimizer) EnableConfigurationProperties(org.springframework.boot.context.properties.EnableConfigurationProperties) Map(java.util.Map) JsonApiMapper(com.yahoo.elide.jsonapi.JsonApiMapper) AggregationDataStore(com.yahoo.elide.datastores.aggregation.AggregationDataStore) DefaultQueryPlanMerger(com.yahoo.elide.datastores.aggregation.query.DefaultQueryPlanMerger) TableExport(com.yahoo.elide.async.models.TableExport) TemplateConfigValidator(com.yahoo.elide.datastores.aggregation.validator.TemplateConfigValidator) Elide(com.yahoo.elide.Elide) SQLDialectFactory(com.yahoo.elide.datastores.aggregation.queryengines.sql.dialects.SQLDialectFactory) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) DynamicConfigValidator(com.yahoo.elide.modelconfig.validator.DynamicConfigValidator) Cache(com.yahoo.elide.datastores.aggregation.cache.Cache) DefaultClassScanner(com.yahoo.elide.core.utils.DefaultClassScanner) TimeZone(java.util.TimeZone) AsyncQuery(com.yahoo.elide.async.models.AsyncQuery) CaffeineCache(com.yahoo.elide.datastores.aggregation.cache.CaffeineCache) Set(java.util.Set) CoerceUtil(com.yahoo.elide.core.utils.coerce.CoerceUtil) EntityDictionary(com.yahoo.elide.core.dictionary.EntityDictionary) QueryRunners(com.yahoo.elide.graphql.QueryRunners) Info(io.swagger.models.Info) ConnectionDetails(com.yahoo.elide.datastores.aggregation.queryengines.sql.ConnectionDetails) Configuration(org.springframework.context.annotation.Configuration) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) EntityManagerFactory(javax.persistence.EntityManagerFactory) DataStore(com.yahoo.elide.core.datastore.DataStore) SwaggerBuilder(com.yahoo.elide.swagger.SwaggerBuilder) Optional(java.util.Optional) MetaDataStore(com.yahoo.elide.datastores.aggregation.metadata.MetaDataStore) Slf4jLogger(com.yahoo.elide.core.audit.Slf4jLogger) QueryLogger(com.yahoo.elide.datastores.aggregation.core.QueryLogger) ErrorMapper(com.yahoo.elide.core.exceptions.ErrorMapper) SQLQueryEngine(com.yahoo.elide.datastores.aggregation.queryengines.sql.SQLQueryEngine) TransactionRegistry(com.yahoo.elide.core.TransactionRegistry) SwaggerController(com.yahoo.elide.spring.controllers.SwaggerController) ElideSettingsBuilder(com.yahoo.elide.ElideSettingsBuilder) Session(org.hibernate.Session) AutowireCapableBeanFactory(org.springframework.beans.factory.config.AutowireCapableBeanFactory) HashMap(java.util.HashMap) MultiplexManager(com.yahoo.elide.datastores.multiplex.MultiplexManager) Function(java.util.function.Function) Scope(org.springframework.context.annotation.Scope) ArrayList(java.util.ArrayList) NonJtaTransaction(com.yahoo.elide.datastores.jpa.transaction.NonJtaTransaction) HashSet(java.util.HashSet) DBPasswordExtractor(com.yahoo.elide.modelconfig.DBPasswordExtractor) ConditionalOnExpression(org.springframework.boot.autoconfigure.condition.ConditionalOnExpression) Injector(com.yahoo.elide.core.dictionary.Injector) Qualifier(org.springframework.beans.factory.annotation.Qualifier) DataSource(javax.sql.DataSource) ConditionalOnProperty(org.springframework.boot.autoconfigure.condition.ConditionalOnProperty) CaffeineCacheMetrics(io.micrometer.core.instrument.binder.cache.CaffeineCacheMetrics) JpaDataStore(com.yahoo.elide.datastores.jpa.JpaDataStore) Slf4jQueryLogger(com.yahoo.elide.datastores.aggregation.core.Slf4jQueryLogger) QueryEngine(com.yahoo.elide.datastores.aggregation.QueryEngine) DEFAULT_LOGGER(com.yahoo.elide.datastores.jpa.JpaDataStore.DEFAULT_LOGGER) SCOPE_PROTOTYPE(org.springframework.beans.factory.config.BeanDefinition.SCOPE_PROTOTYPE) Check(com.yahoo.elide.core.security.checks.Check) DefaultQueryValidator(com.yahoo.elide.datastores.aggregation.DefaultQueryValidator) RefreshableElide(com.yahoo.elide.RefreshableElide) IOException(java.io.IOException) ConfigChecks(com.yahoo.elide.modelconfig.store.models.ConfigChecks) EntityManager(javax.persistence.EntityManager) ConfigDataStore(com.yahoo.elide.modelconfig.store.ConfigDataStore) Consumer(java.util.function.Consumer) MeterRegistry(io.micrometer.core.instrument.MeterRegistry) Type(com.yahoo.elide.core.type.Type) Bean(org.springframework.context.annotation.Bean) SQLQueryEngine(com.yahoo.elide.datastores.aggregation.queryengines.sql.SQLQueryEngine) HashMap(java.util.HashMap) MetaDataStore(com.yahoo.elide.datastores.aggregation.metadata.MetaDataStore) ConnectionDetails(com.yahoo.elide.datastores.aggregation.queryengines.sql.ConnectionDetails) DefaultQueryPlanMerger(com.yahoo.elide.datastores.aggregation.query.DefaultQueryPlanMerger) DefaultQueryValidator(com.yahoo.elide.datastores.aggregation.DefaultQueryValidator) AggregateBeforeJoinOptimizer(com.yahoo.elide.datastores.aggregation.queryengines.sql.query.AggregateBeforeJoinOptimizer) RefreshScope(org.springframework.cloud.context.config.annotation.RefreshScope) Scope(org.springframework.context.annotation.Scope) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Bean(org.springframework.context.annotation.Bean) ConditionalOnProperty(org.springframework.boot.autoconfigure.condition.ConditionalOnProperty)

Example 19 with MetaDataStore

use of com.yahoo.elide.datastores.aggregation.metadata.MetaDataStore in project elide by yahoo.

the class ElideStandaloneSettings method getDataStore.

/**
 * Gets the DataStore for elide.
 * @param metaDataStore MetaDataStore object.
 * @param aggregationDataStore AggregationDataStore object.
 * @param entityManagerFactory EntityManagerFactory object.
 * @return DataStore object initialized.
 */
default DataStore getDataStore(MetaDataStore metaDataStore, AggregationDataStore aggregationDataStore, EntityManagerFactory entityManagerFactory) {
    List<DataStore> stores = new ArrayList<>();
    DataStore jpaDataStore = new JpaDataStore(() -> entityManagerFactory.createEntityManager(), em -> new NonJtaTransaction(em, TXCANCEL, DEFAULT_LOGGER, true, true));
    stores.add(jpaDataStore);
    if (getAnalyticProperties().enableDynamicModelConfigAPI()) {
        stores.add(new ConfigDataStore(getAnalyticProperties().getDynamicConfigPath(), new TemplateConfigValidator(getClassScanner(), getAnalyticProperties().getDynamicConfigPath())));
    }
    stores.add(metaDataStore);
    stores.add(aggregationDataStore);
    return new MultiplexManager(stores.toArray(new DataStore[0]));
}
Also used : JpaDataStore(com.yahoo.elide.datastores.jpa.JpaDataStore) TemplateConfigValidator(com.yahoo.elide.datastores.aggregation.validator.TemplateConfigValidator) ConfigDataStore(com.yahoo.elide.modelconfig.store.ConfigDataStore) AggregationDataStore(com.yahoo.elide.datastores.aggregation.AggregationDataStore) DataStore(com.yahoo.elide.core.datastore.DataStore) MetaDataStore(com.yahoo.elide.datastores.aggregation.metadata.MetaDataStore) JpaDataStore(com.yahoo.elide.datastores.jpa.JpaDataStore) ConfigDataStore(com.yahoo.elide.modelconfig.store.ConfigDataStore) ArrayList(java.util.ArrayList) NonJtaTransaction(com.yahoo.elide.datastores.jpa.transaction.NonJtaTransaction) MultiplexManager(com.yahoo.elide.datastores.multiplex.MultiplexManager)

Example 20 with MetaDataStore

use of com.yahoo.elide.datastores.aggregation.metadata.MetaDataStore in project elide by yahoo.

the class SkipOptimizerTest method init.

@BeforeAll
public static void init() {
    MetaDataStore metaDataStore = new MetaDataStore(DefaultClassScanner.getInstance(), getClassType(DefaultClassScanner.getInstance().getAnnotatedClasses("example", Include.class)), false);
    Set<Optimizer> optimizers = new HashSet<>(Arrays.asList(optimizer));
    init(new H2Dialect(), optimizers, metaDataStore);
}
Also used : H2Dialect(com.yahoo.elide.datastores.aggregation.queryengines.sql.dialects.impl.H2Dialect) MetaDataStore(com.yahoo.elide.datastores.aggregation.metadata.MetaDataStore) Optimizer(com.yahoo.elide.datastores.aggregation.query.Optimizer) HashSet(java.util.HashSet) BeforeAll(org.junit.jupiter.api.BeforeAll)

Aggregations

MetaDataStore (com.yahoo.elide.datastores.aggregation.metadata.MetaDataStore)45 Test (org.junit.jupiter.api.Test)28 HashSet (java.util.HashSet)27 SQLQueryEngine (com.yahoo.elide.datastores.aggregation.queryengines.sql.SQLQueryEngine)25 DefaultQueryPlanMerger (com.yahoo.elide.datastores.aggregation.query.DefaultQueryPlanMerger)24 QueryPlanMerger (com.yahoo.elide.datastores.aggregation.query.QueryPlanMerger)19 Table (com.yahoo.elide.modelconfig.model.Table)17 Arrays (java.util.Arrays)9 Set (java.util.Set)9 Argument (com.yahoo.elide.core.request.Argument)8 List (java.util.List)8 Map (java.util.Map)8 EntityDictionary (com.yahoo.elide.core.dictionary.EntityDictionary)7 FilterExpression (com.yahoo.elide.core.filter.expression.FilterExpression)7 Type (com.yahoo.elide.core.type.Type)7 DefaultClassScanner (com.yahoo.elide.core.utils.DefaultClassScanner)7 DefaultQueryValidator (com.yahoo.elide.datastores.aggregation.DefaultQueryValidator)7 ConnectionDetails (com.yahoo.elide.datastores.aggregation.queryengines.sql.ConnectionDetails)7 Collectors (java.util.stream.Collectors)7 Query (com.yahoo.elide.datastores.aggregation.query.Query)6