use of com.yahoo.elide.datastores.aggregation.queryengines.sql.SQLQueryEngine 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.SQLQueryEngine in project elide by yahoo.
the class ColumnArgumentValidatorTest method testColumnArgsTypeMismatchForDepenedentColumn.
@Test
public void testColumnArgsTypeMismatchForDepenedentColumn() {
Table mainTable = mainTableBuilder.dimension(Dimension.builder().name("dim1").type(Type.BOOLEAN).values(Collections.emptySet()).tags(Collections.emptySet()).definition("start {{$$column.args.mainArg1}} blah {{dim2}} end").argument(mainArg1).build()).dimension(Dimension.builder().name("dim2").type(Type.BOOLEAN).values(Collections.emptySet()).tags(Collections.emptySet()).definition("{{$dim2}} blah {{$$column.args.mainArg1}} end").argument(Argument.builder().name("mainArg1").type(Type.TEXT).values(Collections.emptySet()).defaultValue("").build()).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 column arguments for column: dim1 in table: namespace_MainTable. Argument type mismatch. Dependent Column: 'dim2' in table: 'namespace_MainTable'" + " has same Argument: 'mainArg1' with type 'TEXT'.", e.getMessage());
}
use of com.yahoo.elide.datastores.aggregation.queryengines.sql.SQLQueryEngine in project elide by yahoo.
the class ColumnArgumentValidatorTest method testUndefinedColumnArgsInJoinExpression.
@Test
public void testUndefinedColumnArgsInJoinExpression() {
Table mainTable = mainTableBuilder.join(Join.builder().name("join").namespace("namespace").to("JoinTable").definition("start {{$$column.args.mainArg2}} blah").build()).dimension(Dimension.builder().name("dim1").type(Type.BOOLEAN).values(Collections.emptySet()).tags(Collections.emptySet()).definition("start {{$$column.args.mainArg1}} blah {{join.$joinCol}} end").argument(mainArg1).build()).build();
Set<Table> tables = new HashSet<>();
tables.add(mainTable);
tables.add(joinTableBuilder.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 column arguments for column: dim1 in table: namespace_MainTable. Argument 'mainArg2' is not defined but found '{{$$column.args.mainArg2}}'.", e.getMessage());
}
use of com.yahoo.elide.datastores.aggregation.queryengines.sql.SQLQueryEngine in project elide by yahoo.
the class ColumnArgumentValidatorTest method testRequiredColumnArgsInFilterTemplate.
@Test
public void testRequiredColumnArgsInFilterTemplate() {
Table mainTable = mainTableBuilder.dimension(Dimension.builder().name("dim1").type(Type.BOOLEAN).values(Collections.emptySet()).tags(Collections.emptySet()).definition("start {{$$column.args.mainArg1}} end").filterTemplate("dim1=={{mainArg1}}").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);
assertDoesNotThrow(() -> new SQLQueryEngine(metaDataStore, connectionLookup, optimizers, merger, queryValidator));
}
use of com.yahoo.elide.datastores.aggregation.queryengines.sql.SQLQueryEngine in project elide by yahoo.
the class ColumnArgumentValidatorTest method testMissingRequiredColumnArgsForDepenedentColumnCase2.
@Test
public void testMissingRequiredColumnArgsForDepenedentColumnCase2() {
Table mainTable = mainTableBuilder.join(Join.builder().name("join").namespace("namespace").to("JoinTable").definition("start {{$$column.args.mainArg1}} blah {{join.$joinCol}} end").build()).dimension(Dimension.builder().name("dim1").type(Type.BOOLEAN).values(Collections.emptySet()).tags(Collections.emptySet()).definition("start {{$$column.args.mainArg1}} blah {{join.joinCol}} end").argument(mainArg1).build()).build();
Table joinTable = joinTableBuilder.dimension(Dimension.builder().name("joinCol").type(Type.BOOLEAN).values(Collections.emptySet()).tags(Collections.emptySet()).definition("{{$joinCol}} blah {{$$column.args.joinArg1}} end").argument(Argument.builder().name("joinArg1").type(Type.INTEGER).values(Collections.emptySet()).defaultValue("").build()).build()).build();
Set<Table> tables = new HashSet<>();
tables.add(mainTable);
tables.add(joinTable);
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 column arguments for column: dim1 in table: namespace_MainTable. Argument 'joinArg1' with type 'INTEGER' is not defined but is" + " required for Dependent Column: 'joinCol' in table: 'namespace_JoinTable'.", e.getMessage());
// If 'join.joinCol' is invoked using SQL helper, must not complain.
mainTable = mainTableBuilder.join(Join.builder().name("join").namespace("namespace").to("JoinTable").definition("start {{$$column.args.mainArg1}} blah {{join.$joinCol}} end").build()).dimension(Dimension.builder().name("dim1").type(Type.BOOLEAN).values(Collections.emptySet()).tags(Collections.emptySet()).definition("start {{$$column.args.mainArg1}} blah {{sql from='join' column='joinCol[joinArg1:123]'}} end").argument(mainArg1).build()).build();
tables = new HashSet<>();
tables.add(mainTable);
tables.add(joinTable);
MetaDataStore metaDataStore1 = new MetaDataStore(DefaultClassScanner.getInstance(), tables, this.namespaceConfigs, true);
assertDoesNotThrow(() -> new SQLQueryEngine(metaDataStore1, connectionLookup, optimizers, merger, queryValidator));
}
Aggregations