Search in sources :

Example 41 with MetaDataStore

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

the class LoopCountryB method testCrossClassReferenceLoop.

@Test
public void testCrossClassReferenceLoop() {
    MetaDataStore metaDataStore = new MetaDataStore(DefaultClassScanner.getInstance(), getClassType(Sets.newLinkedHashSet(Arrays.asList(LoopCountryA.class, LoopCountryB.class))), true);
    IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, () -> new SQLQueryEngine(metaDataStore, (unused) -> DUMMY_CONNECTION));
    String exception1 = "Formula reference loop found: loopCountryA.inUsa->loopCountryB.inUsa->loopCountryA.inUsa";
    String exception2 = "Formula reference loop found: loopCountryB.inUsa->loopCountryA.inUsa->loopCountryB.inUsa";
    assertTrue(exception1.equals(exception.getMessage()) || exception2.equals(exception.getMessage()));
}
Also used : SQLQueryEngine(com.yahoo.elide.datastores.aggregation.queryengines.sql.SQLQueryEngine) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) SQLDialectFactory(com.yahoo.elide.datastores.aggregation.queryengines.sql.dialects.SQLDialectFactory) Entity(javax.persistence.Entity) Setter(lombok.Setter) Arrays(java.util.Arrays) ManyToOne(javax.persistence.ManyToOne) SQLQueryEngine(com.yahoo.elide.datastores.aggregation.queryengines.sql.SQLQueryEngine) DefaultClassScanner(com.yahoo.elide.core.utils.DefaultClassScanner) JoinColumn(javax.persistence.JoinColumn) Include(com.yahoo.elide.annotation.Include) Formula(org.hibernate.annotations.Formula) DimensionFormula(com.yahoo.elide.datastores.aggregation.annotation.DimensionFormula) Sets(com.google.common.collect.Sets) ConnectionDetails(com.yahoo.elide.datastores.aggregation.queryengines.sql.ConnectionDetails) Test(org.junit.jupiter.api.Test) TypeHelper.getClassType(com.yahoo.elide.core.utils.TypeHelper.getClassType) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) HikariDataSource(com.zaxxer.hikari.HikariDataSource) Data(lombok.Data) MetaDataStore(com.yahoo.elide.datastores.aggregation.metadata.MetaDataStore) Id(javax.persistence.Id) MetaDataStore(com.yahoo.elide.datastores.aggregation.metadata.MetaDataStore) Test(org.junit.jupiter.api.Test)

Example 42 with MetaDataStore

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

the class MetricFormulaTest method testReferenceLoop.

@Test
public void testReferenceLoop() {
    MetaDataStore metaDataStore = new MetaDataStore(DefaultClassScanner.getInstance(), Sets.newHashSet(ClassType.of(MeasureLoop.class)), true);
    IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, () -> new SQLQueryEngine(metaDataStore, (unused) -> DUMMY_CONNECTION));
    assertTrue(exception.getMessage().startsWith("Formula reference loop found:"));
}
Also used : SQLQueryEngine(com.yahoo.elide.datastores.aggregation.queryengines.sql.SQLQueryEngine) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) Test(org.junit.jupiter.api.Test) SQLQueryEngine(com.yahoo.elide.datastores.aggregation.queryengines.sql.SQLQueryEngine) DUMMY_CONNECTION(com.yahoo.elide.datastores.aggregation.annotation.dimensionformula.DimensionFormulaTest.DUMMY_CONNECTION) DefaultClassScanner(com.yahoo.elide.core.utils.DefaultClassScanner) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) MetaDataStore(com.yahoo.elide.datastores.aggregation.metadata.MetaDataStore) ClassType(com.yahoo.elide.core.type.ClassType) Sets(com.google.common.collect.Sets) MetaDataStore(com.yahoo.elide.datastores.aggregation.metadata.MetaDataStore) Test(org.junit.jupiter.api.Test)

Example 43 with MetaDataStore

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

the class SQLUnitTest method init.

public static void init(SQLDialect dialect) {
    MetaDataStore metaDataStore = new MetaDataStore(DefaultClassScanner.getInstance(), getClassType(DefaultClassScanner.getInstance().getAnnotatedClasses("example", Include.class)), false);
    init(dialect, new HashSet<>(), metaDataStore);
}
Also used : MetaDataStore(com.yahoo.elide.datastores.aggregation.metadata.MetaDataStore)

Example 44 with MetaDataStore

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

the class JoinPathTest method init.

@BeforeAll
public static void init() {
    Set<Type<?>> models = new HashSet<>();
    models.add(ClassType.of(PlayerStats.class));
    models.add(ClassType.of(CountryView.class));
    models.add(ClassType.of(Country.class));
    models.add(ClassType.of(SubCountry.class));
    models.add(ClassType.of(Player.class));
    models.add(ClassType.of(PlayerRanking.class));
    models.add(ClassType.of(CountryViewNested.class));
    models.add(ClassType.of(PlayerStatsWithView.class));
    EntityDictionary dictionary = EntityDictionary.builder().build();
    models.stream().forEach(dictionary::bindEntity);
    store = new MetaDataStore(dictionary.getScanner(), models, true);
    store.populateEntityDictionary(dictionary);
    DataSource mockDataSource = mock(DataSource.class);
    // The query engine populates the metadata store with actual tables.
    new SQLQueryEngine(store, (unused) -> new ConnectionDetails(mockDataSource, SQLDialectFactory.getDefaultDialect()));
}
Also used : SQLQueryEngine(com.yahoo.elide.datastores.aggregation.queryengines.sql.SQLQueryEngine) Player(example.Player) CountryViewNested(example.dimensions.CountryViewNested) MetaDataStore(com.yahoo.elide.datastores.aggregation.metadata.MetaDataStore) ConnectionDetails(com.yahoo.elide.datastores.aggregation.queryengines.sql.ConnectionDetails) PlayerStats(example.PlayerStats) SubCountry(example.dimensions.SubCountry) DataSource(javax.sql.DataSource) ClassType(com.yahoo.elide.core.type.ClassType) Type(com.yahoo.elide.core.type.Type) PlayerStatsWithView(example.PlayerStatsWithView) PlayerRanking(example.PlayerRanking) SubCountry(example.dimensions.SubCountry) Country(example.dimensions.Country) CountryView(example.dimensions.CountryView) EntityDictionary(com.yahoo.elide.core.dictionary.EntityDictionary) HashSet(java.util.HashSet) BeforeAll(org.junit.jupiter.api.BeforeAll)

Example 45 with MetaDataStore

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

the class ElideStandaloneSettings method getQueryEngine.

/**
 * Gets the QueryEngine for elide.
 * @param metaDataStore MetaDataStore object.
 * @param defaultConnectionDetails default DataSource Object and SQLDialect Object.
 * @param dynamicConfiguration Optional dynamic config.
 * @param dataSourceConfiguration DataSource Configuration.
 * @param dbPasswordExtractor Password Extractor Implementation.
 * @return QueryEngine object initialized.
 */
default QueryEngine getQueryEngine(MetaDataStore metaDataStore, ConnectionDetails defaultConnectionDetails, Optional<DynamicConfiguration> dynamicConfiguration, DataSourceConfiguration dataSourceConfiguration, DBPasswordExtractor dbPasswordExtractor) {
    if (dynamicConfiguration.isPresent()) {
        Map<String, ConnectionDetails> connectionDetailsMap = new HashMap<>();
        dynamicConfiguration.get().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()));
    }
    return new SQLQueryEngine(metaDataStore, (unused) -> defaultConnectionDetails);
}
Also used : ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler) Arrays(java.util.Arrays) DynamicConfiguration(com.yahoo.elide.modelconfig.DynamicConfiguration) 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) RSQLFilterDialect(com.yahoo.elide.core.filter.dialect.RSQLFilterDialect) ClassScanner(com.yahoo.elide.core.utils.ClassScanner) AggregateBeforeJoinOptimizer(com.yahoo.elide.datastores.aggregation.queryengines.sql.query.AggregateBeforeJoinOptimizer) Map(java.util.Map) ResourceConfig(org.glassfish.jersey.server.ResourceConfig) 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) SQLDialectFactory(com.yahoo.elide.datastores.aggregation.queryengines.sql.dialects.SQLDialectFactory) 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) Info(io.swagger.models.Info) ConnectionDetails(com.yahoo.elide.datastores.aggregation.queryengines.sql.ConnectionDetails) 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) ServiceLocator(org.glassfish.hk2.api.ServiceLocator) MetaDataStore(com.yahoo.elide.datastores.aggregation.metadata.MetaDataStore) Slf4jLogger(com.yahoo.elide.core.audit.Slf4jLogger) ErrorMapper(com.yahoo.elide.core.exceptions.ErrorMapper) SQLQueryEngine(com.yahoo.elide.datastores.aggregation.queryengines.sql.SQLQueryEngine) ElideSettingsBuilder(com.yahoo.elide.ElideSettingsBuilder) Swagger(io.swagger.models.Swagger) Session(org.hibernate.Session) HashMap(java.util.HashMap) MultiplexManager(com.yahoo.elide.datastores.multiplex.MultiplexManager) Function(java.util.function.Function) ArrayList(java.util.ArrayList) NonJtaTransaction(com.yahoo.elide.datastores.jpa.transaction.NonJtaTransaction) HashSet(java.util.HashSet) DBPasswordExtractor(com.yahoo.elide.modelconfig.DBPasswordExtractor) Injector(com.yahoo.elide.core.dictionary.Injector) NO_VERSION(com.yahoo.elide.core.dictionary.EntityDictionary.NO_VERSION) JpaDataStore(com.yahoo.elide.datastores.jpa.JpaDataStore) ElideSettings(com.yahoo.elide.ElideSettings) 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) Check(com.yahoo.elide.core.security.checks.Check) Properties(java.util.Properties) DefaultQueryValidator(com.yahoo.elide.datastores.aggregation.DefaultQueryValidator) 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) AuditLogger(com.yahoo.elide.core.audit.AuditLogger) Type(com.yahoo.elide.core.type.Type) Collections(java.util.Collections) DocEndpoint(com.yahoo.elide.swagger.resources.DocEndpoint) SQLQueryEngine(com.yahoo.elide.datastores.aggregation.queryengines.sql.SQLQueryEngine) DefaultQueryValidator(com.yahoo.elide.datastores.aggregation.DefaultQueryValidator) AggregateBeforeJoinOptimizer(com.yahoo.elide.datastores.aggregation.queryengines.sql.query.AggregateBeforeJoinOptimizer) HashMap(java.util.HashMap) ConnectionDetails(com.yahoo.elide.datastores.aggregation.queryengines.sql.ConnectionDetails) DefaultQueryPlanMerger(com.yahoo.elide.datastores.aggregation.query.DefaultQueryPlanMerger)

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