use of com.yahoo.elide.datastores.aggregation.query.ColumnProjection in project elide by yahoo.
the class ColumnContext method get.
public Object get(Object key) {
String keyStr = key.toString();
// Physical References starts with $
if (keyStr.lastIndexOf('$') == 0) {
return resolvePhysicalReference(this, keyStr);
}
if (keyStr.equals(TBL_PREFIX)) {
return TableSubContext.tableSubContextBuilder().tableArguments(this.tableArguments).build();
}
if (keyStr.equals(COL_PREFIX)) {
return ColumnSubContext.columnSubContextBuilder().queryable(this.getQueryable()).alias(this.getAlias()).metaDataStore(this.getMetaDataStore()).column(this.getColumn()).tableArguments(this.getTableArguments()).build();
}
if (this.queryable.hasJoin(keyStr)) {
return getJoinContext(keyStr);
}
// Check if key exists in Map.
Object value = getOrDefault(key, null);
if (value != null) {
return value;
}
// In case of colA references colB and user query has both colA and colB,
// we should use default arguments for colB while resolving colA instead of user provided argument for colB.
// so taking colB's details from current queryable's source.
ColumnProjection column = this.getQueryable().getSource().getColumnProjection(keyStr);
if (column != null) {
ColumnProjection newColumn = column.withArguments(mergedArgumentMap(column.getArguments(), this.getColumn().getArguments()));
return getNewContext(this, newColumn).resolve(newColumn.getExpression());
}
throw new HandlebarsException(new Throwable("Couldn't find: " + keyStr));
}
use of com.yahoo.elide.datastores.aggregation.query.ColumnProjection in project elide by yahoo.
the class DefaultQueryValidator method validateHavingClause.
@Override
public void validateHavingClause(Query query) {
FilterExpression havingClause = query.getHavingFilter();
if (havingClause == null) {
return;
}
havingClause.accept(new PredicateExtractionVisitor()).forEach(predicate -> {
Path path = predicate.getPath();
if (path.getPathElements().size() > 1) {
throw new InvalidOperationException("Relationship traversal not supported for analytic queries.");
}
validatePredicate(query, predicate);
extractFilterProjections(query, havingClause).stream().forEach(projection -> {
Predicate<ColumnProjection> filterByNameAndArgs = (column) -> (column.getAlias().equals(projection.getAlias()) || column.getName().equals(projection.getName())) && column.getArguments().equals(projection.getArguments());
// Query by (alias or name) and arguments. The filter may or may not be using the alias.
if (query.getColumnProjection(filterByNameAndArgs) == null) {
Predicate<ColumnProjection> filterByName = (column) -> (column.getAlias().equals(projection.getAlias()) || column.getName().equals(projection.getName()));
// The column wasn't projected at all.
if (query.getColumnProjection(filterByName) == null) {
throw new InvalidOperationException(String.format("Post aggregation filtering on '%s' requires the field to be projected in the response", projection.getAlias()));
// The column was projected but arguments didn't match.
} else {
throw new InvalidOperationException(String.format("Post aggregation filtering on '%s' requires the field to be projected " + "in the response with matching arguments", projection.getAlias()));
}
}
});
});
}
use of com.yahoo.elide.datastores.aggregation.query.ColumnProjection in project elide by yahoo.
the class JoinExpressionExtractor method visitLogicalReference.
@Override
public Set<String> visitLogicalReference(LogicalReference reference) {
/**
* For the scenario: col1:{{col2}}, col2:{{col3}}, col3:{{join.col1}}
* Creating new visitor with new ColumnProjection.
*/
ColumnProjection newColumn = reference.getColumn();
ColumnContext newCtx = ColumnContext.builder().queryable(this.context.getQueryable()).alias(this.context.getAlias()).metaDataStore(this.context.getMetaDataStore()).column(newColumn).tableArguments(this.context.getTableArguments()).build();
JoinExpressionExtractor visitor = new JoinExpressionExtractor(newCtx);
reference.getReferences().forEach(ref -> {
joinExpressions.addAll(ref.accept(visitor));
});
return joinExpressions;
}
use of com.yahoo.elide.datastores.aggregation.query.ColumnProjection in project elide by yahoo.
the class HasJoinVisitorTest method testHasJoin.
@Test
void testHasJoin() {
Queryable source = mock(Queryable.class);
JoinPath path = mock(JoinPath.class);
ColumnProjection column = mock(ColumnProjection.class);
Reference reference = LogicalReference.builder().source(source).column(column).reference(PhysicalReference.builder().name("foo").source(source).build()).reference(JoinReference.builder().source(source).path(path).reference(PhysicalReference.builder().name("bar").source(source).build()).build()).build();
assertTrue(reference.accept(new HasJoinVisitor()));
}
use of com.yahoo.elide.datastores.aggregation.query.ColumnProjection in project elide by yahoo.
the class HasJoinVisitorTest method testLogicalColumnNoJoin.
@Test
void testLogicalColumnNoJoin() {
Queryable source = mock(Queryable.class);
ColumnProjection column = mock(ColumnProjection.class);
Reference reference = LogicalReference.builder().source(source).column(column).reference(PhysicalReference.builder().name("foo").source(source).build()).build();
assertFalse(reference.accept(new HasJoinVisitor()));
}
Aggregations