use of com.yahoo.elide.datastores.aggregation.queryengines.sql.ConnectionDetails in project elide by yahoo.
the class SQLUnitTest method init.
public static void init(SQLDialect sqlDialect, Set<Optimizer> optimizers, MetaDataStore metaDataStore) {
Properties properties = new Properties();
properties.put("driverClassName", "org.h2.Driver");
String jdbcUrl = "jdbc:h2:mem:db1;DB_CLOSE_DELAY=-1" + ";NON_KEYWORDS=VALUE,USER" + ";DATABASE_TO_UPPER=FALSE" + getCompatabilityMode(sqlDialect.getDialectType());
properties.put("jdbcUrl", jdbcUrl);
HikariConfig config = new HikariConfig(properties);
DataSource dataSource = new HikariDataSource(config);
try (Connection h2Conn = dataSource.getConnection()) {
h2Conn.createStatement().execute("RUNSCRIPT FROM 'classpath:prepare_tables.sql'");
} catch (SQLException e) {
((HikariDataSource) dataSource).close();
throw new IllegalStateException(e);
}
SQLUnitTest.metaDataStore = metaDataStore;
dictionary = EntityDictionary.builder().build();
dictionary.bindEntity(PlayerStatsWithView.class);
dictionary.bindEntity(PlayerStatsView.class);
dictionary.bindEntity(PlayerStats.class);
dictionary.bindEntity(Country.class);
dictionary.bindEntity(SubCountry.class);
dictionary.bindEntity(Player.class);
dictionary.bindEntity(CountryView.class);
dictionary.bindEntity(CountryViewNested.class);
dictionary.bindEntity(Continent.class);
dictionary.bindEntity(GameRevenue.class);
filterParser = RSQLFilterDialect.builder().dictionary(dictionary).build();
// Manually register the serdes because we are not running a complete Elide service.
CoerceUtil.register(Day.class, new Day.DaySerde());
CoerceUtil.register(Hour.class, new Hour.HourSerde());
CoerceUtil.register(ISOWeek.class, new ISOWeek.ISOWeekSerde());
CoerceUtil.register(Minute.class, new Minute.MinuteSerde());
CoerceUtil.register(Month.class, new Month.MonthSerde());
CoerceUtil.register(Quarter.class, new Quarter.QuarterSerde());
CoerceUtil.register(Second.class, new Second.SecondSerde());
CoerceUtil.register(Week.class, new Week.WeekSerde());
CoerceUtil.register(Year.class, new Year.YearSerde());
metaDataStore.populateEntityDictionary(dictionary);
// Need to provide details for connections used by all available models.
Map<String, ConnectionDetails> connectionDetailsMap = new HashMap<>();
connectionDetailsMap.put("mycon", new ConnectionDetails(dataSource, sqlDialect));
connectionDetailsMap.put("SalesDBConnection", new ConnectionDetails(DUMMY_DATASOURCE, sqlDialect));
Function<String, ConnectionDetails> connectionLookup = (name) -> connectionDetailsMap.getOrDefault(name, new ConnectionDetails(dataSource, sqlDialect));
engine = new SQLQueryEngine(metaDataStore, connectionLookup, optimizers, new DefaultQueryPlanMerger(metaDataStore), new DefaultQueryValidator(metaDataStore.getMetadataDictionary()));
playerStatsTable = (SQLTable) metaDataStore.getTable("playerStats", NO_VERSION);
videoGameTable = (SQLTable) metaDataStore.getTable("videoGame", NO_VERSION);
playerStatsViewTable = (SQLTable) metaDataStore.getTable("playerStatsView", NO_VERSION);
playerStatsViewTableArgs = new HashMap<>();
playerStatsViewTableArgs.put("rating", Argument.builder().name("overallRating").value("Great").build());
playerStatsViewTableArgs.put("minScore", Argument.builder().name("minScore").value("0").build());
}
use of com.yahoo.elide.datastores.aggregation.queryengines.sql.ConnectionDetails in project elide by yahoo.
the class AggregationDataStoreIntegrationTest method createHarness.
@Override
protected DataStoreTestHarness createHarness() {
HikariConfig config = new HikariConfig(File.separator + "jpah2db.properties");
DataSource defaultDataSource = new HikariDataSource(config);
SQLDialect defaultDialect = SQLDialectFactory.getDefaultDialect();
ConnectionDetails defaultConnectionDetails = new ConnectionDetails(defaultDataSource, defaultDialect);
Properties prop = new Properties();
prop.put("javax.persistence.jdbc.driver", config.getDriverClassName());
prop.put("javax.persistence.jdbc.url", config.getJdbcUrl());
EntityManagerFactory emf = Persistence.createEntityManagerFactory("aggregationStore", prop);
Map<String, ConnectionDetails> connectionDetailsMap = new HashMap<>();
// Add an entry for "mycon" connection which is not from hjson
connectionDetailsMap.put("mycon", defaultConnectionDetails);
// Add connection details fetched from hjson
VALIDATOR.getElideSQLDBConfig().getDbconfigs().forEach(dbConfig -> connectionDetailsMap.put(dbConfig.getName(), new ConnectionDetails(getDataSource(dbConfig, getDBPasswordExtractor()), SQLDialectFactory.getDialect(dbConfig.getDialect()))));
return new AggregationDataStoreTestHarness(emf, defaultConnectionDetails, connectionDetailsMap, VALIDATOR);
}
use of com.yahoo.elide.datastores.aggregation.queryengines.sql.ConnectionDetails in project elide by yahoo.
the class MetaDataStoreIntegrationTest method createHarness.
@Override
protected DataStoreTestHarness createHarness() {
HikariConfig config = new HikariConfig(File.separator + "jpah2db.properties");
DataSource defaultDataSource = new HikariDataSource(config);
SQLDialect defaultDialect = SQLDialectFactory.getDefaultDialect();
ConnectionDetails defaultConnectionDetails = new ConnectionDetails(defaultDataSource, defaultDialect);
Properties prop = new Properties();
prop.put("javax.persistence.jdbc.driver", config.getDriverClassName());
prop.put("javax.persistence.jdbc.url", config.getJdbcUrl());
EntityManagerFactory emf = Persistence.createEntityManagerFactory("aggregationStore", prop);
Map<String, ConnectionDetails> connectionDetailsMap = new HashMap<>();
// Add an entry for "mycon" connection which is not from hjson
connectionDetailsMap.put("mycon", defaultConnectionDetails);
// Add connection details fetched from hjson
VALIDATOR.getElideSQLDBConfig().getDbconfigs().forEach(dbConfig -> connectionDetailsMap.put(dbConfig.getName(), new ConnectionDetails(getDataSource(dbConfig, getDBPasswordExtractor()), SQLDialectFactory.getDialect(dbConfig.getDialect()))));
return new AggregationDataStoreTestHarness(emf, defaultConnectionDetails, connectionDetailsMap, VALIDATOR);
}
use of com.yahoo.elide.datastores.aggregation.queryengines.sql.ConnectionDetails 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);
}
use of com.yahoo.elide.datastores.aggregation.queryengines.sql.ConnectionDetails 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()));
}
Aggregations