com.facebook.presto.client.QueryResults Maven / Gradle / Ivy
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.facebook.presto.client;
import com.facebook.presto.spi.type.NamedTypeSignature;
import com.facebook.presto.spi.type.ParameterKind;
import com.facebook.presto.spi.type.TypeSignature;
import com.facebook.presto.spi.type.TypeSignatureParameter;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.common.collect.ImmutableList;
import javax.annotation.Nullable;
import javax.annotation.concurrent.Immutable;
import javax.validation.constraints.NotNull;
import java.net.URI;
import java.util.ArrayList;
import java.util.Base64;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import static com.facebook.presto.spi.type.StandardTypes.ARRAY;
import static com.facebook.presto.spi.type.StandardTypes.BIGINT;
import static com.facebook.presto.spi.type.StandardTypes.BOOLEAN;
import static com.facebook.presto.spi.type.StandardTypes.CHAR;
import static com.facebook.presto.spi.type.StandardTypes.DATE;
import static com.facebook.presto.spi.type.StandardTypes.DECIMAL;
import static com.facebook.presto.spi.type.StandardTypes.DOUBLE;
import static com.facebook.presto.spi.type.StandardTypes.INTEGER;
import static com.facebook.presto.spi.type.StandardTypes.INTERVAL_DAY_TO_SECOND;
import static com.facebook.presto.spi.type.StandardTypes.INTERVAL_YEAR_TO_MONTH;
import static com.facebook.presto.spi.type.StandardTypes.JSON;
import static com.facebook.presto.spi.type.StandardTypes.MAP;
import static com.facebook.presto.spi.type.StandardTypes.REAL;
import static com.facebook.presto.spi.type.StandardTypes.ROW;
import static com.facebook.presto.spi.type.StandardTypes.SMALLINT;
import static com.facebook.presto.spi.type.StandardTypes.TIME;
import static com.facebook.presto.spi.type.StandardTypes.TIMESTAMP;
import static com.facebook.presto.spi.type.StandardTypes.TIMESTAMP_WITH_TIME_ZONE;
import static com.facebook.presto.spi.type.StandardTypes.TIME_WITH_TIME_ZONE;
import static com.facebook.presto.spi.type.StandardTypes.TINYINT;
import static com.facebook.presto.spi.type.StandardTypes.VARCHAR;
import static com.facebook.presto.spi.type.TypeSignature.parseTypeSignature;
import static com.google.common.base.MoreObjects.toStringHelper;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.collect.Iterables.unmodifiableIterable;
import static java.util.Collections.unmodifiableList;
import static java.util.Objects.requireNonNull;
import static java.util.stream.Collectors.toList;
@Immutable
public class QueryResults
{
private final String id;
private final URI infoUri;
private final URI partialCancelUri;
private final URI nextUri;
private final List columns;
private final Iterable> data;
private final StatementStats stats;
private final QueryError error;
private final String updateType;
private final Long updateCount;
@JsonCreator
public QueryResults(
@JsonProperty("id") String id,
@JsonProperty("infoUri") URI infoUri,
@JsonProperty("partialCancelUri") URI partialCancelUri,
@JsonProperty("nextUri") URI nextUri,
@JsonProperty("columns") List columns,
@JsonProperty("data") List> data,
@JsonProperty("stats") StatementStats stats,
@JsonProperty("error") QueryError error,
@JsonProperty("updateType") String updateType,
@JsonProperty("updateCount") Long updateCount)
{
this(id, infoUri, partialCancelUri, nextUri, columns, fixData(columns, data), stats, error, updateType, updateCount);
}
public QueryResults(
String id,
URI infoUri,
URI partialCancelUri,
URI nextUri,
List columns,
Iterable> data,
StatementStats stats,
QueryError error,
String updateType,
Long updateCount)
{
this.id = requireNonNull(id, "id is null");
this.infoUri = requireNonNull(infoUri, "infoUri is null");
this.partialCancelUri = partialCancelUri;
this.nextUri = nextUri;
this.columns = (columns != null) ? ImmutableList.copyOf(columns) : null;
this.data = (data != null) ? unmodifiableIterable(data) : null;
this.stats = requireNonNull(stats, "stats is null");
this.error = error;
this.updateType = updateType;
this.updateCount = updateCount;
}
@NotNull
@JsonProperty
public String getId()
{
return id;
}
@NotNull
@JsonProperty
public URI getInfoUri()
{
return infoUri;
}
@Nullable
@JsonProperty
public URI getPartialCancelUri()
{
return partialCancelUri;
}
@Nullable
@JsonProperty
public URI getNextUri()
{
return nextUri;
}
@Nullable
@JsonProperty
public List getColumns()
{
return columns;
}
@Nullable
@JsonProperty
public Iterable> getData()
{
return data;
}
@NotNull
@JsonProperty
public StatementStats getStats()
{
return stats;
}
@Nullable
@JsonProperty
public QueryError getError()
{
return error;
}
@Nullable
@JsonProperty
public String getUpdateType()
{
return updateType;
}
@Nullable
@JsonProperty
public Long getUpdateCount()
{
return updateCount;
}
@Override
public String toString()
{
return toStringHelper(this)
.add("id", id)
.add("infoUri", infoUri)
.add("partialCancelUri", partialCancelUri)
.add("nextUri", nextUri)
.add("columns", columns)
.add("hasData", data != null)
.add("stats", stats)
.add("error", error)
.add("updateType", updateType)
.add("updateCount", updateCount)
.toString();
}
private static Iterable> fixData(List columns, List> data)
{
if (data == null) {
return null;
}
requireNonNull(columns, "columns is null");
List signatures = columns.stream()
.map(column -> parseTypeSignature(column.getType()))
.collect(toList());
ImmutableList.Builder> rows = ImmutableList.builder();
for (List
© 2015 - 2025 Weber Informatics LLC | Privacy Policy