use of com.yahoo.elide.datastores.aggregation.metadata.MetaDataStore in project elide by yahoo.
the class SQLQueryEngine method toPageTotalSQL.
/**
* Takes a SQLQuery and creates a new clone that instead returns the total number of records of the original
* query.
*
* @param query The client query
* @param sql The generated SQL query
* @param sqlDialect the SQL dialect
* @return A new query that returns the total number of records.
*/
private NativeQuery toPageTotalSQL(Query query, NativeQuery sql, SQLDialect sqlDialect) {
// TODO: refactor this method
String groupByDimensions = query.getAllDimensionProjections().stream().map(SQLColumnProjection.class::cast).filter(SQLColumnProjection::isProjected).map((column) -> column.toSQL(query, metaDataStore)).collect(Collectors.joining(", "));
if (groupByDimensions.isEmpty()) {
// Metric projection without group by dimension will return onely 1 record.
return null;
}
NativeQuery innerQuery = NativeQuery.builder().projectionClause(groupByDimensions).fromClause(sql.getFromClause()).joinClause(sql.getJoinClause()).whereClause(sql.getWhereClause()).groupByClause(String.format("GROUP BY %s", groupByDimensions)).havingClause(sql.getHavingClause()).build();
return NativeQuery.builder().projectionClause("COUNT(*)").fromClause(QueryTranslator.getFromClause("(" + innerQuery + ")", applyQuotes("pagination_subquery", sqlDialect), sqlDialect)).build();
}
use of com.yahoo.elide.datastores.aggregation.metadata.MetaDataStore in project elide by yahoo.
the class AggregateBeforeJoinOptimizerTest method init.
@BeforeAll
public static void init() {
MetaDataStore metaDataStore = new MetaDataStore(DefaultClassScanner.getInstance(), getClassType(dictionary.getScanner().getAnnotatedClasses("example", Include.class)), false);
Set<Optimizer> optimizers = new HashSet<>(Arrays.asList(new AggregateBeforeJoinOptimizer(metaDataStore)));
init(new H2Dialect(), optimizers, metaDataStore);
}
use of com.yahoo.elide.datastores.aggregation.metadata.MetaDataStore in project elide by yahoo.
the class ColumnArgumentValidatorTest method testMissingRequiredColumnArgsForDepenedentColumnCase1.
@Test
public void testMissingRequiredColumnArgsForDepenedentColumnCase1() {
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.dependentArg1}} end").argument(Argument.builder().name("dependentArg1").type(Type.INTEGER).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 'dependentArg1' with type 'INTEGER' is not defined but is" + " required for Dependent Column: 'dim2' in table: 'namespace_MainTable'.", e.getMessage());
// If 'dim2' is invoked using SQL helper, must not complain.
mainTable = mainTableBuilder.dimension(Dimension.builder().name("dim1").type(Type.BOOLEAN).values(Collections.emptySet()).tags(Collections.emptySet()).definition("start {{$$column.args.mainArg1}} blah {{sql column='dim2[dependentArg1:123]'}} end").argument(mainArg1).build()).dimension(Dimension.builder().name("dim2").type(Type.BOOLEAN).values(Collections.emptySet()).tags(Collections.emptySet()).definition("{{$dim2}} blah {{$$column.args.dependentArg1}} end").argument(Argument.builder().name("dependentArg1").type(Type.INTEGER).values(Collections.emptySet()).defaultValue("").build()).build()).build();
tables = new HashSet<>();
tables.add(mainTable);
MetaDataStore metaDataStore1 = new MetaDataStore(DefaultClassScanner.getInstance(), tables, this.namespaceConfigs, true);
assertDoesNotThrow(() -> new SQLQueryEngine(metaDataStore1, connectionLookup, optimizers, merger, queryValidator));
}
use of com.yahoo.elide.datastores.aggregation.metadata.MetaDataStore in project elide by yahoo.
the class ColumnArgumentValidatorTest method testUndefinedColumnArgsInColumnDefinition.
@Test
public void testUndefinedColumnArgsInColumnDefinition() {
Table mainTable = mainTableBuilder.dimension(Dimension.builder().name("dim1").type(Type.BOOLEAN).values(Collections.emptySet()).tags(Collections.emptySet()).definition("start {{$$column.args.mainArg1}} blah {{$$column.args.mainArg2}} end").argument(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);
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.metadata.MetaDataStore in project elide by yahoo.
the class AggregationDataStoreTestHarness method getDataStore.
@Override
public DataStore getDataStore() {
AggregationDataStore.AggregationDataStoreBuilder aggregationDataStoreBuilder = AggregationDataStore.builder();
ClassScanner scanner = DefaultClassScanner.getInstance();
MetaDataStore metaDataStore;
if (validator != null) {
metaDataStore = new MetaDataStore(scanner, validator.getElideTableConfig().getTables(), validator.getElideNamespaceConfig().getNamespaceconfigs(), true);
aggregationDataStoreBuilder.dynamicCompiledClasses(metaDataStore.getDynamicTypes());
} else {
metaDataStore = new MetaDataStore(scanner, true);
}
AggregationDataStore aggregationDataStore = aggregationDataStoreBuilder.queryEngine(new SQLQueryEngine(metaDataStore, (name) -> connectionDetailsMap.getOrDefault(name, defaultConnectionDetails), new HashSet<>(Arrays.asList(new AggregateBeforeJoinOptimizer(metaDataStore))), new DefaultQueryPlanMerger(metaDataStore), new DefaultQueryValidator(metaDataStore.getMetadataDictionary()))).queryLogger(new Slf4jQueryLogger()).build();
Consumer<EntityManager> txCancel = em -> em.unwrap(Session.class).cancelQuery();
DataStore jpaStore = new JpaDataStore(() -> entityManagerFactory.createEntityManager(), em -> new NonJtaTransaction(em, txCancel));
return new MultiplexManager(jpaStore, metaDataStore, aggregationDataStore);
}
Aggregations