use of com.yahoo.elide.datastores.aggregation.query.ColumnProjection in project elide by yahoo.
the class HasColumnArgsVisitorTest method testJoinWithLogicalReferenceThatReferencesPhysical.
@Test
public void testJoinWithLogicalReferenceThatReferencesPhysical() throws Exception {
SQLTable table = metaDataStore.getTable(ClassType.of(TableC.class));
ColumnProjection projection = table.getColumnProjection("joinWithPhysicalToPhysical");
assertFalse(matches(table, projection));
}
use of com.yahoo.elide.datastores.aggregation.query.ColumnProjection in project elide by yahoo.
the class EntityProjectionTranslatorTest method testBasicTranslation.
@Test
public void testBasicTranslation() {
EntityProjectionTranslator translator = new EntityProjectionTranslator(engine, playerStatsTable, basicProjection, scope, true);
Query query = translator.getQuery();
assertEquals(playerStatsTable, query.getSource());
assertEquals(1, query.getMetricProjections().size());
String actual = query.getMetricProjections().stream().map(MetricProjection::getAlias).findFirst().orElse(null);
assertEquals("lowScore", actual);
assertEquals(1, query.getAllDimensionProjections().size());
List<ColumnProjection> dimensions = new ArrayList<>(query.getAllDimensionProjections());
assertEquals("overallRating", dimensions.get(0).getName());
}
use of com.yahoo.elide.datastores.aggregation.query.ColumnProjection in project elide by yahoo.
the class ColumnArgumentValidator method verifyLogicalReference.
private void verifyLogicalReference(LogicalReference reference) {
SQLTable sqlTable = (SQLTable) reference.getSource();
ColumnProjection columnProj = reference.getColumn();
// This will have dependent column's defined arguments merged with pinned arguments used to invoke this column.
Map<String, Argument> mergedArguments = columnProj.getArguments();
Column refColumn = sqlTable.getColumn(Column.class, columnProj.getName());
verifyPinnedArguments(mergedArguments, refColumn, String.format(errorMsgPrefix + "Type mismatch of Fixed value provided for Dependent Column: '%s' in table: '%s'. ", refColumn.getName(), sqlTable.getName()));
refColumn.getArgumentDefinitions().forEach(argDef -> {
String argName = argDef.getName();
if (column.hasArgumentDefinition(argName)) {
if (argDef.getType() != column.getArgumentDefinition(argName).getType()) {
throw new IllegalStateException(String.format(errorMsgPrefix + "Argument type mismatch. Dependent Column: '%s' in table: '%s' has same" + " Argument: '%s' with type '%s'.", refColumn.getName(), sqlTable.getName(), argName, argDef.getType()));
}
} else if (StringUtils.isBlank(argDef.getDefaultValue().toString()) && StringUtils.isBlank(mergedArguments.get(argName).getValue().toString())) {
throw new IllegalStateException(String.format(errorMsgPrefix + "Argument '%s' with type '%s' is not defined but is required for" + " Dependent Column: '%s' in table: '%s'.", argName, argDef.getType(), refColumn.getName(), sqlTable.getName()));
}
});
}
use of com.yahoo.elide.datastores.aggregation.query.ColumnProjection in project elide by yahoo.
the class SQLMetricProjection method nest.
@Override
public Pair<ColumnProjection, Set<ColumnProjection>> nest(Queryable source, MetaDataStore metaDataStore, boolean joinInOuter) {
SQLDialect dialect = source.getConnectionDetails().getDialect();
String sql = toSQL(source, metaDataStore);
SqlParser sqlParser = SqlParser.create(sql, CalciteUtils.constructParserConfig(dialect));
SqlNode node;
try {
node = sqlParser.parseExpression();
} catch (SqlParseException e) {
throw new IllegalStateException(e);
}
CalciteInnerAggregationExtractor innerExtractor = new CalciteInnerAggregationExtractor(dialect);
List<List<String>> innerAggExpressions = node.accept(innerExtractor);
List<List<String>> innerAggLabels = innerAggExpressions.stream().map(list -> list.stream().map((expression) -> getAggregationLabel(dialect.getCalciteDialect(), expression)).collect(Collectors.toList())).collect(Collectors.toList());
Set<ColumnProjection> innerAggProjections = new LinkedHashSet<>();
Iterator<String> labelIt = innerAggLabels.stream().flatMap(List::stream).iterator();
Iterator<String> expressionIt = innerAggExpressions.stream().flatMap(List::stream).iterator();
while (labelIt.hasNext() && expressionIt.hasNext()) {
String innerAggExpression = expressionIt.next();
String innerAggLabel = labelIt.next();
innerAggProjections.add(SQLMetricProjection.builder().projected(true).name(innerAggLabel).alias(innerAggLabel).expression(innerAggExpression).columnType(columnType).valueType(valueType).arguments(arguments).build());
}
CalciteOuterAggregationExtractor outerExtractor = new CalciteOuterAggregationExtractor(dialect, innerAggLabels);
SqlNode transformedParseTree = node.accept(outerExtractor);
String outerAggExpression = transformedParseTree.toSqlString(dialect.getCalciteDialect()).getSql();
// replace INNER_AGG_... with {{$INNER_AGG...}}
outerAggExpression = outerAggExpression.replaceAll(dialect.getBeginQuote() + "?(" + getAggregationLabelPrefix(dialect.getCalciteDialect()) + "\\w+)" + dialect.getEndQuote() + "?", "{{\\$" + "$1" + "}}");
String columnId = source.isRoot() ? getName() : getAlias();
boolean inProjection = source.getColumnProjection(columnId, arguments, true) != null;
ColumnProjection outerProjection = SQLMetricProjection.builder().projected(inProjection).expression(outerAggExpression).name(name).alias(alias).valueType(valueType).columnType(columnType).arguments(arguments).build();
return Pair.of(outerProjection, innerAggProjections);
}
use of com.yahoo.elide.datastores.aggregation.query.ColumnProjection in project elide by yahoo.
the class LogicalReferenceExtractorTest method testLogicalReference.
@Test
public void testLogicalReference() {
ColumnProjection playerLevel = playerStats.getColumnProjection("playerLevel");
List<Reference> references = parser.parse(playerStats, playerLevel.getExpression());
assertTrue(references.size() == 1);
ReferenceExtractor<LogicalReference> extractor = new ReferenceExtractor(LogicalReference.class, metaDataStore, ReferenceExtractor.Mode.SAME_QUERY);
Set<LogicalReference> logicalReferences = references.get(0).accept(extractor);
assertEquals(1, logicalReferences.size());
assertTrue(logicalReferences.contains(LogicalReference.builder().source(playerStats).column(playerStats.getColumnProjection("overallRating")).reference(PhysicalReference.builder().source(playerStats).name("overallRating").build()).build()));
}
Aggregations