use of io.trino.plugin.pinot.PinotColumnHandle in project trino by trinodb.
the class ImplementApproxDistinct method rewrite.
@Override
public Optional<AggregateExpression> rewrite(AggregateFunction aggregateFunction, Captures captures, RewriteContext<Void> context) {
Variable argument = captures.get(ARGUMENT);
PinotColumnHandle columnHandle = (PinotColumnHandle) context.getAssignment(argument.getName());
return Optional.of(new AggregateExpression("distinctcounthll", identifierQuote.apply(columnHandle.getColumnName()), false));
}
use of io.trino.plugin.pinot.PinotColumnHandle in project trino by trinodb.
the class ImplementSum method rewrite.
@Override
public Optional<AggregateExpression> rewrite(AggregateFunction aggregateFunction, Captures captures, RewriteContext<Void> context) {
Variable argument = captures.get(ARGUMENT);
PinotColumnHandle columnHandle = (PinotColumnHandle) context.getAssignment(argument.getName());
return Optional.of(new AggregateExpression(aggregateFunction.getFunctionName(), identifierQuote.apply(columnHandle.getColumnName()), true));
}
use of io.trino.plugin.pinot.PinotColumnHandle in project trino by trinodb.
the class PinotClient method fromResultTable.
@VisibleForTesting
public static ResultsIterator fromResultTable(BrokerResponseNative brokerResponse, List<PinotColumnHandle> columnHandles, int groupByClauses) {
requireNonNull(brokerResponse, "brokerResponse is null");
requireNonNull(columnHandles, "columnHandles is null");
ResultTable resultTable = brokerResponse.getResultTable();
String[] columnNames = resultTable.getDataSchema().getColumnNames();
Map<String, Integer> columnIndices = IntStream.range(0, columnNames.length).boxed().collect(toImmutableMap(i -> columnNames[i].toLowerCase(ENGLISH), identity()));
int[] indices = new int[columnNames.length];
int[] inverseIndices = new int[columnNames.length];
for (int i = 0; i < columnHandles.size(); i++) {
String columnName = columnHandles.get(i).getColumnName().toLowerCase(ENGLISH);
indices[i] = requireNonNull(columnIndices.get(columnName), format("column index for '%s' was not found", columnName));
inverseIndices[indices[i]] = i;
}
List<Object[]> rows = resultTable.getRows();
// If returning from a global aggregation (no grouping columns) over an empty table, NULL-out all aggregation function results except for `count()`
if (groupByClauses == 0 && brokerResponse.getNumDocsScanned() == 0 && resultTable.getRows().size() == 1) {
Object[] originalRow = getOnlyElement(resultTable.getRows());
Object[] newRow = new Object[originalRow.length];
for (int i = 0; i < originalRow.length; i++) {
if (!columnHandles.get(inverseIndices[i]).isReturnNullOnEmptyGroup()) {
newRow[i] = originalRow[i];
}
}
rows = ImmutableList.of(newRow);
}
return new ResultsIterator(rows, indices);
}
Aggregations