Search in sources :

Example 21 with SQLQueryEngine

use of com.yahoo.elide.datastores.aggregation.queryengines.sql.SQLQueryEngine in project elide by yahoo.

the class TableArgumentValidatorTest method testArgumentValues.

@Test
public void testArgumentValues() {
    Table mainTable = mainTableBuilder.argument(Argument.builder().name("testArg").type(Type.INTEGER).values(Sets.newHashSet("1", "2.5")).defaultValue("").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. Value: '2.5' for Argument 'testArg' with Type 'INTEGER' is invalid.", 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 22 with SQLQueryEngine

use of com.yahoo.elide.datastores.aggregation.queryengines.sql.SQLQueryEngine 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 23 with SQLQueryEngine

use of com.yahoo.elide.datastores.aggregation.queryengines.sql.SQLQueryEngine 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 24 with SQLQueryEngine

use of com.yahoo.elide.datastores.aggregation.queryengines.sql.SQLQueryEngine 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 25 with SQLQueryEngine

use of com.yahoo.elide.datastores.aggregation.queryengines.sql.SQLQueryEngine 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)25 SQLQueryEngine (com.yahoo.elide.datastores.aggregation.queryengines.sql.SQLQueryEngine)25 DefaultQueryPlanMerger (com.yahoo.elide.datastores.aggregation.query.DefaultQueryPlanMerger)21 HashSet (java.util.HashSet)21 Test (org.junit.jupiter.api.Test)19 QueryPlanMerger (com.yahoo.elide.datastores.aggregation.query.QueryPlanMerger)16 Table (com.yahoo.elide.modelconfig.model.Table)16 DefaultClassScanner (com.yahoo.elide.core.utils.DefaultClassScanner)7 ConnectionDetails (com.yahoo.elide.datastores.aggregation.queryengines.sql.ConnectionDetails)7 SQLDialectFactory (com.yahoo.elide.datastores.aggregation.queryengines.sql.dialects.SQLDialectFactory)6 Arrays (java.util.Arrays)6 ClassType (com.yahoo.elide.core.type.ClassType)5 DefaultQueryValidator (com.yahoo.elide.datastores.aggregation.DefaultQueryValidator)5 EntityDictionary (com.yahoo.elide.core.dictionary.EntityDictionary)4 Type (com.yahoo.elide.core.type.Type)4 Include (com.yahoo.elide.annotation.Include)3 DataStore (com.yahoo.elide.core.datastore.DataStore)3 RSQLFilterDialect (com.yahoo.elide.core.filter.dialect.RSQLFilterDialect)3 ClassScanner (com.yahoo.elide.core.utils.ClassScanner)3 TypeHelper.getClassType (com.yahoo.elide.core.utils.TypeHelper.getClassType)3