Search in sources :

Example 1 with PostAggregationHandler

use of org.apache.pinot.core.query.reduce.PostAggregationHandler in project trino by trinodb.

the class DynamicTableBuilder method getAggregateTypes.

private static Map<String, PinotColumnNameAndTrinoType> getAggregateTypes(SchemaTableName schemaTableName, QueryContext queryContext, Map<String, ColumnHandle> columnHandles) {
    // A mapping from pinot expression to the returned pinot column name and trino type
    // Note: the column name is set by the PostAggregationHandler
    List<ExpressionContext> aggregateColumnExpressions = queryContext.getSelectExpressions().stream().filter(DynamicTableBuilder::hasAggregate).collect(toImmutableList());
    queryContext = new QueryContext.Builder().setAliasList(queryContext.getAliasList()).setSelectExpressions(aggregateColumnExpressions).build();
    DataSchema preAggregationSchema = getPreAggregationDataSchema(queryContext);
    PostAggregationHandler postAggregationHandler = new PostAggregationHandler(queryContext, preAggregationSchema);
    DataSchema postAggregtionSchema = postAggregationHandler.getResultDataSchema();
    ImmutableMap.Builder<String, PinotColumnNameAndTrinoType> aggregationTypesBuilder = ImmutableMap.builder();
    for (int index = 0; index < postAggregtionSchema.size(); index++) {
        aggregationTypesBuilder.put(// Quoting of identifiers is not done to match the corresponding column name in the ResultTable returned from Pinot. Quoting will be done by `DynamicTablePqlExtractor`.
        rewriteExpression(schemaTableName, aggregateColumnExpressions.get(index), columnHandles).toString(), new PinotColumnNameAndTrinoType(postAggregtionSchema.getColumnName(index), toTrinoType(postAggregtionSchema.getColumnDataType(index))));
    }
    return aggregationTypesBuilder.buildOrThrow();
}
Also used : DataSchema(org.apache.pinot.common.utils.DataSchema) ExpressionContext(org.apache.pinot.common.request.context.ExpressionContext) OrderByExpressionContext(org.apache.pinot.common.request.context.OrderByExpressionContext) PostAggregationHandler(org.apache.pinot.core.query.reduce.PostAggregationHandler) ImmutableMap(com.google.common.collect.ImmutableMap)

Aggregations

ImmutableMap (com.google.common.collect.ImmutableMap)1 ExpressionContext (org.apache.pinot.common.request.context.ExpressionContext)1 OrderByExpressionContext (org.apache.pinot.common.request.context.OrderByExpressionContext)1 DataSchema (org.apache.pinot.common.utils.DataSchema)1 PostAggregationHandler (org.apache.pinot.core.query.reduce.PostAggregationHandler)1