Search in sources :

Example 6 with PinotColumnHandle

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));
}
Also used : PinotColumnHandle(io.trino.plugin.pinot.PinotColumnHandle) Variable(io.trino.spi.expression.Variable) AggregateExpression(io.trino.plugin.pinot.query.AggregateExpression)

Example 7 with PinotColumnHandle

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));
}
Also used : PinotColumnHandle(io.trino.plugin.pinot.PinotColumnHandle) Variable(io.trino.spi.expression.Variable) AggregateExpression(io.trino.plugin.pinot.query.AggregateExpression)

Example 8 with PinotColumnHandle

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);
}
Also used : JsonProperty(com.fasterxml.jackson.annotation.JsonProperty) PinotConfig(io.trino.plugin.pinot.PinotConfig) JsonResponseHandler(io.airlift.http.client.JsonResponseHandler) UnaryOperator.identity(java.util.function.UnaryOperator.identity) AUTHORIZATION(com.google.common.net.HttpHeaders.AUTHORIZATION) ACCEPT(com.google.common.net.HttpHeaders.ACCEPT) DeserializationFeature(com.fasterxml.jackson.databind.DeserializationFeature) NonEvictableLoadingCache(io.trino.collect.cache.NonEvictableLoadingCache) UnexpectedResponseException(io.airlift.http.client.UnexpectedResponseException) Matcher(java.util.regex.Matcher) JsonCodecBinder(io.airlift.json.JsonCodecBinder) Schema(org.apache.pinot.spi.data.Schema) PINOT_UNABLE_TO_FIND_BROKER(io.trino.plugin.pinot.PinotErrorCode.PINOT_UNABLE_TO_FIND_BROKER) PinotSessionProperties(io.trino.plugin.pinot.PinotSessionProperties) Map(java.util.Map) URI(java.net.URI) ENGLISH(java.util.Locale.ENGLISH) ForPinot(io.trino.plugin.pinot.ForPinot) ImmutableMap(com.google.common.collect.ImmutableMap) Collectors(java.util.stream.Collectors) StandardCharsets(java.nio.charset.StandardCharsets) String.format(java.lang.String.format) Preconditions.checkState(com.google.common.base.Preconditions.checkState) CacheLoader(com.google.common.cache.CacheLoader) SafeCaches.buildNonEvictableCache(io.trino.collect.cache.SafeCaches.buildNonEvictableCache) List(java.util.List) ImmutableMap.toImmutableMap(com.google.common.collect.ImmutableMap.toImmutableMap) JsonCodec.listJsonCodec(io.airlift.json.JsonCodec.listJsonCodec) JsonCodecFactory(io.airlift.json.JsonCodecFactory) HttpUriBuilder.uriBuilderFrom(io.airlift.http.client.HttpUriBuilder.uriBuilderFrom) Optional(java.util.Optional) JsonResponseHandler.createJsonResponseHandler(io.airlift.http.client.JsonResponseHandler.createJsonResponseHandler) PinotBrokerAuthenticationProvider(io.trino.plugin.pinot.auth.PinotBrokerAuthenticationProvider) CacheBuilder(com.google.common.cache.CacheBuilder) Pattern(java.util.regex.Pattern) JsonCodec(io.airlift.json.JsonCodec) PINOT_INVALID_CONFIGURATION(io.trino.plugin.pinot.PinotErrorCode.PINOT_INVALID_CONFIGURATION) HttpClient(io.airlift.http.client.HttpClient) IntStream(java.util.stream.IntStream) Logger(io.airlift.log.Logger) BrokerResponseNative(org.apache.pinot.common.response.broker.BrokerResponseNative) PinotInsufficientServerResponseException(io.trino.plugin.pinot.PinotInsufficientServerResponseException) PINOT_EXCEPTION(io.trino.plugin.pinot.PinotErrorCode.PINOT_EXCEPTION) Multimap(com.google.common.collect.Multimap) Function(java.util.function.Function) CONTENT_TYPE(com.google.common.net.HttpHeaders.CONTENT_TYPE) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) PinotQueryInfo(io.trino.plugin.pinot.query.PinotQueryInfo) ImmutableList(com.google.common.collect.ImmutableList) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) Objects.requireNonNull(java.util.Objects.requireNonNull) Request(io.airlift.http.client.Request) PinotException(io.trino.plugin.pinot.PinotException) ResultTable(org.apache.pinot.common.response.broker.ResultTable) TableNameBuilder.extractRawTableName(org.apache.pinot.spi.utils.builder.TableNameBuilder.extractRawTableName) ImmutableMultimap(com.google.common.collect.ImmutableMultimap) Iterator(java.util.Iterator) JsonCodec.mapJsonCodec(io.airlift.json.JsonCodec.mapJsonCodec) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) AbstractIterator(com.google.common.collect.AbstractIterator) Iterables.getOnlyElement(com.google.common.collect.Iterables.getOnlyElement) ConnectorSession(io.trino.spi.connector.ConnectorSession) PinotErrorCode(io.trino.plugin.pinot.PinotErrorCode) PinotControllerAuthenticationProvider(io.trino.plugin.pinot.auth.PinotControllerAuthenticationProvider) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) JsonCodec.jsonCodec(io.airlift.json.JsonCodec.jsonCodec) StaticBodyGenerator(io.airlift.http.client.StaticBodyGenerator) JsonCreator(com.fasterxml.jackson.annotation.JsonCreator) VisibleForTesting(com.google.common.annotations.VisibleForTesting) Collections(java.util.Collections) PinotColumnHandle(io.trino.plugin.pinot.PinotColumnHandle) ResultTable(org.apache.pinot.common.response.broker.ResultTable) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Aggregations

PinotColumnHandle (io.trino.plugin.pinot.PinotColumnHandle)8 AggregateExpression (io.trino.plugin.pinot.query.AggregateExpression)4 Variable (io.trino.spi.expression.Variable)4 ImmutableList (com.google.common.collect.ImmutableList)3 ExpressionContext (org.apache.pinot.common.request.context.ExpressionContext)3 OrderByExpressionContext (org.apache.pinot.common.request.context.OrderByExpressionContext)3 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)2 JsonCreator (com.fasterxml.jackson.annotation.JsonCreator)1 JsonProperty (com.fasterxml.jackson.annotation.JsonProperty)1 DeserializationFeature (com.fasterxml.jackson.databind.DeserializationFeature)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Preconditions.checkState (com.google.common.base.Preconditions.checkState)1 CacheBuilder (com.google.common.cache.CacheBuilder)1 CacheLoader (com.google.common.cache.CacheLoader)1 AbstractIterator (com.google.common.collect.AbstractIterator)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 ImmutableMap.toImmutableMap (com.google.common.collect.ImmutableMap.toImmutableMap)1 ImmutableMultimap (com.google.common.collect.ImmutableMultimap)1 Iterables.getOnlyElement (com.google.common.collect.Iterables.getOnlyElement)1