Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename encodingId to just encoding #23388

Merged
merged 2 commits into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions client/trino-cli/src/main/java/io/trino/cli/ClientOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
import static io.trino.client.uri.PropertyName.CLIENT_INFO;
import static io.trino.client.uri.PropertyName.CLIENT_TAGS;
import static io.trino.client.uri.PropertyName.DISABLE_COMPRESSION;
import static io.trino.client.uri.PropertyName.ENCODING_ID;
import static io.trino.client.uri.PropertyName.ENCODING;
import static io.trino.client.uri.PropertyName.EXTERNAL_AUTHENTICATION;
import static io.trino.client.uri.PropertyName.EXTERNAL_AUTHENTICATION_REDIRECT_HANDLERS;
import static io.trino.client.uri.PropertyName.EXTRA_CREDENTIALS;
Expand Down Expand Up @@ -287,9 +287,9 @@ public class ClientOptions
@Option(names = "--disable-compression", description = "Disable compression of query results")
public boolean disableCompression;

@PropertyMapping(ENCODING_ID)
@Option(names = "--encoding-id", paramLabel = "<encoding-id>", description = "Experimental spooled protocol encoding [available: ${ENCODINGS}]")
public Optional<String> encodingId = Optional.empty();
@PropertyMapping(ENCODING)
@Option(names = "--encoding", paramLabel = "<encoding>", description = "Experimental spooled protocol encoding [available: ${ENCODINGS}]")
public Optional<String> encoding = Optional.empty();

@Option(names = "--editing-mode", paramLabel = "<editing-mode>", defaultValue = "EMACS", description = "Editing mode [${COMPLETION-CANDIDATES}] " + DEFAULT_VALUE)
public EditingMode editingMode;
Expand Down Expand Up @@ -342,7 +342,7 @@ public ClientSession toClientSession(TrinoUri uri)
return uri
.toClientSessionBuilder()
.source(uri.getSource().orElse(SOURCE_DEFAULT))
.encodingId(encodingId)
.encoding(encoding)
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public class ClientSession
private final String transactionId;
private final Duration clientRequestTimeout;
private final boolean compressionDisabled;
private Optional<String> encodingId;
private Optional<String> encoding;

public static Builder builder()
{
Expand Down Expand Up @@ -97,7 +97,7 @@ private ClientSession(
String transactionId,
Duration clientRequestTimeout,
boolean compressionDisabled,
Optional<String> encodingId)
Optional<String> encoding)
{
this.server = requireNonNull(server, "server is null");
this.principal = requireNonNull(principal, "principal is null");
Expand All @@ -120,7 +120,7 @@ private ClientSession(
this.extraCredentials = ImmutableMap.copyOf(requireNonNull(extraCredentials, "extraCredentials is null"));
this.clientRequestTimeout = clientRequestTimeout;
this.compressionDisabled = compressionDisabled;
this.encodingId = requireNonNull(encodingId, "encodingId is null");
this.encoding = requireNonNull(encoding, "encoding is null");

for (String clientTag : clientTags) {
checkArgument(!clientTag.contains(","), "client tag cannot contain ','");
Expand Down Expand Up @@ -264,9 +264,9 @@ public boolean isCompressionDisabled()
return compressionDisabled;
}

public Optional<String> getEncodingId()
public Optional<String> getEncoding()
{
return encodingId;
return encoding;
}

@Override
Expand All @@ -291,7 +291,7 @@ public String toString()
.add("resourceEstimates", resourceEstimates)
.add("clientRequestTimeout", clientRequestTimeout)
.add("compressionDisabled", compressionDisabled)
.add("encodingId", encodingId)
.add("encoding", encoding)
.omitNullValues()
.toString();
}
Expand Down Expand Up @@ -319,7 +319,7 @@ public static final class Builder
private String transactionId;
private Duration clientRequestTimeout;
private boolean compressionDisabled;
private Optional<String> encodingId = Optional.empty();
private Optional<String> encoding = Optional.empty();

private Builder() {}

Expand Down Expand Up @@ -347,7 +347,7 @@ private Builder(ClientSession clientSession)
transactionId = clientSession.getTransactionId();
clientRequestTimeout = clientSession.getClientRequestTimeout();
compressionDisabled = clientSession.isCompressionDisabled();
encodingId = clientSession.getEncodingId();
encoding = clientSession.getEncoding();
}

public Builder server(URI server)
Expand Down Expand Up @@ -476,9 +476,9 @@ public Builder compressionDisabled(boolean compressionDisabled)
return this;
}

public Builder encodingId(Optional<String> encodingId)
public Builder encoding(Optional<String> encoding)
{
this.encodingId = encodingId;
this.encoding = encoding;
return this;
}

Expand Down Expand Up @@ -506,7 +506,7 @@ public ClientSession build()
transactionId,
clientRequestTimeout,
compressionDisabled,
encodingId);
encoding);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ interface Factory
{
QueryDataDecoder create(List<Column> columns, DataAttributes queryAttributes);

String encodingId();
String encoding();
}

Iterable<List<Object>> decode(InputStream input, DataAttributes segmentAttributes)
throws IOException;

String encodingId();
String encoding();
}
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public StatementClientV1(Call.Factory httpCallFactory, Call.Factory segmentHttpC
this.compressionDisabled = session.isCompressionDisabled();
this.segmentLoader = new SegmentLoader(requireNonNull(segmentHttpCallFactory, "segmentHttpCallFactory is null"));

Request request = buildQueryRequest(session, query, session.getEncodingId());
Request request = buildQueryRequest(session, query, session.getEncoding());
// Pass empty as materializedJsonSizeLimit to always materialize the first response
// to avoid losing the response body if the initial response parsing fails
executeRequest(request, "starting query", OptionalLong.empty(), this::isTransient);
Expand Down Expand Up @@ -514,14 +514,14 @@ private void processResponse(Headers headers, QueryResults results)
EncodedQueryData encodedData = (EncodedQueryData) results.getData();
DataAttributes queryAttributed = encodedData.getMetadata();
if (decoder.get() == null) {
verify(QueryDataDecoders.exists(encodedData.getEncodingId()), "Received encoded data format but there is no decoder matching %s", encodedData.getEncodingId());
verify(QueryDataDecoders.exists(encodedData.getEncoding()), "Received encoded data format but there is no decoder matching %s", encodedData.getEncoding());
QueryDataDecoder queryDataDecoder = QueryDataDecoders
.get(encodedData.getEncodingId())
.get(encodedData.getEncoding())
.create(results.getColumns(), queryAttributed);
decoder.set(queryDataDecoder);
}

verify(decoder.get().encodingId().equals(encodedData.getEncodingId()), "Decoder has wrong encoding id, expected %s, got %s", encodedData.getEncodingId(), decoder.get().encodingId());
verify(decoder.get().encoding().equals(encodedData.getEncoding()), "Decoder has wrong encoding id, expected %s, got %s", encodedData.getEncoding(), decoder.get().encoding());
}

currentResults.set(results);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,22 +39,22 @@
public class EncodedQueryData
implements QueryData
{
private final String encodingId;
private final String encoding;
private final DataAttributes metadata;
private final List<Segment> segments;

@JsonCreator
public EncodedQueryData(
@JsonProperty("encodingId") String encodingId,
@JsonProperty("encoding") String encoding,
@JsonProperty("metadata") Map<String, Object> metadata,
@JsonProperty("segments") List<Segment> segments)
{
this(encodingId, new DataAttributes(metadata), segments);
this(encoding, new DataAttributes(metadata), segments);
}

public EncodedQueryData(String encodingId, DataAttributes metadata, List<Segment> segments)
public EncodedQueryData(String encoding, DataAttributes metadata, List<Segment> segments)
{
this.encodingId = requireNonNull(encodingId, "encodingId is null");
this.encoding = requireNonNull(encoding, "encoding is null");
this.metadata = requireNonNull(metadata, "metadata is null");
this.segments = ImmutableList.copyOf(requireNonNull(segments, "segments is null"));
}
Expand All @@ -65,10 +65,10 @@ public List<Segment> getSegments()
return segments;
}

@JsonProperty("encodingId")
public String getEncodingId()
@JsonProperty("encoding")
public String getEncoding()
{
return encodingId;
return encoding;
}

@JsonInclude(JsonInclude.Include.NON_EMPTY)
Expand All @@ -92,8 +92,8 @@ public Iterable<List<Object>> getData()

public QueryData toRawData(QueryDataDecoder decoder, SegmentLoader segmentLoader)
{
if (!decoder.encodingId().equals(encodingId)) {
throw new IllegalArgumentException(format("Invalid decoder supplied, expected %s, got %s", encodingId, decoder.encodingId()));
if (!decoder.encoding().equals(encoding)) {
throw new IllegalArgumentException(format("Invalid decoder supplied, expected %s, got %s", encoding, decoder.encoding()));
}

return RawQueryData.of(unmodifiableIterable(concat(transform(segments, segment -> {
Expand Down Expand Up @@ -125,7 +125,7 @@ public QueryData toRawData(QueryDataDecoder decoder, SegmentLoader segmentLoader
public String toString()
{
return toStringHelper(this)
.add("encodingId", encodingId)
.add("encoding", encoding)
.add("segments", segments)
.add("metadata", metadata.attributes.keySet())
.toString();
Expand All @@ -138,13 +138,13 @@ public static Builder builder(String format)

public static class Builder
{
private final String encodingId;
private final String encoding;
private final ImmutableList.Builder<Segment> segments = ImmutableList.builder();
private DataAttributes metadata = DataAttributes.empty();

private Builder(String encodingId)
private Builder(String encoding)
{
this.encodingId = requireNonNull(encodingId, "encodingId is null");
this.encoding = requireNonNull(encoding, "encoding is null");
}

public Builder withSegment(Segment segment)
Expand All @@ -161,7 +161,7 @@ public Builder withAttributes(DataAttributes attributes)

public EncodedQueryData build()
{
return new EncodedQueryData(encodingId, metadata, segments.build());
return new EncodedQueryData(encoding, metadata, segments.build());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public Iterable<List<Object>> decode(InputStream stream, DataAttributes attribut
}

@Override
public String encodingId()
public String encoding()
{
return "json";
}
Expand All @@ -68,7 +68,7 @@ public QueryDataDecoder create(List<Column> columns, DataAttributes queryAttribu
}

@Override
public String encodingId()
public String encoding()
{
return "json";
}
Expand All @@ -84,9 +84,9 @@ public QueryDataDecoder create(List<Column> columns, DataAttributes queryAttribu
}

@Override
public String encodingId()
public String encoding()
{
return super.encodingId() + "+zstd";
return super.encoding() + "+zstd";
}
}

Expand All @@ -100,9 +100,9 @@ public QueryDataDecoder create(List<Column> columns, DataAttributes queryAttribu
}

@Override
public String encodingId()
public String encoding()
{
return super.encodingId() + "+lz4";
return super.encoding() + "+lz4";
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ InputStream decompress(InputStream stream, int uncompressedSize)
}

@Override
public String encodingId()
public String encoding()
{
return delegate.encodingId() + "+lz4";
return delegate.encoding() + "+lz4";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,20 @@ public class QueryDataDecoders

private QueryDataDecoders() {}

public static Factory get(String encodingId)
public static Factory get(String encoding)
{
if (!encodingMap.containsKey(encodingId)) {
throw new IllegalArgumentException("Unknown encoding id: " + encodingId);
if (!encodingMap.containsKey(encoding)) {
throw new IllegalArgumentException("Unknown encoding: " + encoding);
}

Factory factory = encodingMap.get(encodingId);
verify(factory.encodingId().equals(encodingId), "Factory has wrong encoding id, expected %s, got %s", encodingId, factory.encodingId());
Factory factory = encodingMap.get(encoding);
verify(factory.encoding().equals(encoding), "Factory has wrong encoding, expected %s, got %s", encoding, factory.encoding());
return factory;
}

public static boolean exists(String encodingId)
public static boolean exists(String encoding)
{
return encodingMap.containsKey(encodingId);
return encodingMap.containsKey(encoding);
}

public static Set<String> getSupportedEncodings()
Expand All @@ -59,6 +59,6 @@ public static Set<String> getSupportedEncodings()
private static Map<String, Factory> factoriesMap()
{
return decoders.stream()
.collect(toImmutableMap(Factory::encodingId, identity()));
.collect(toImmutableMap(Factory::encoding, identity()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ InputStream decompress(InputStream inputStream, int uncompressedSize)
}

@Override
public String encodingId()
public String encoding()
{
return delegate.encodingId() + "+zstd";
return delegate.encoding() + "+zstd";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ enum SslVerificationMode
public static final ConnectionProperty<String, HostAndPort> HTTP_PROXY = new HttpProxy();
public static final ConnectionProperty<String, String> APPLICATION_NAME_PREFIX = new ApplicationNamePrefix();
public static final ConnectionProperty<String, Boolean> DISABLE_COMPRESSION = new DisableCompression();
public static final ConnectionProperty<String, String> ENCODING_ID = new EncodingId();
public static final ConnectionProperty<String, String> ENCODING = new Encoding();
public static final ConnectionProperty<String, Boolean> ASSUME_LITERAL_NAMES_IN_METADATA_CALLS_FOR_NON_CONFORMING_CLIENTS = new AssumeLiteralNamesInMetadataCallsForNonConformingClients();
public static final ConnectionProperty<String, Boolean> ASSUME_LITERAL_UNDERSCORE_IN_METADATA_CALLS_FOR_NON_CONFORMING_CLIENTS = new AssumeLiteralUnderscoreInMetadataCallsForNonConformingClients();
public static final ConnectionProperty<String, Boolean> SSL = new Ssl();
Expand Down Expand Up @@ -129,7 +129,7 @@ enum SslVerificationMode
.add(DISABLE_COMPRESSION)
.add(DNS_RESOLVER)
.add(DNS_RESOLVER_CONTEXT)
.add(ENCODING_ID)
.add(ENCODING)
.add(EXPLICIT_PREPARE)
.add(EXTERNAL_AUTHENTICATION)
.add(EXTERNAL_AUTHENTICATION_REDIRECT_HANDLERS)
Expand Down Expand Up @@ -380,22 +380,22 @@ public DisableCompression()
}
}

private static class EncodingId
private static class Encoding
extends AbstractConnectionProperty<String, String>
{
public EncodingId()
public Encoding()
{
super(PropertyName.ENCODING_ID, NOT_REQUIRED, EncodingId::areEncodingsValid, STRING_CONVERTER);
super(PropertyName.ENCODING, NOT_REQUIRED, Encoding::areEncodingsValid, STRING_CONVERTER);
}

public static Optional<String> areEncodingsValid(Properties properties)
{
List<String> supportedEncodings = Splitter.on(",").trimResults().omitEmptyStrings()
.splitToList(ENCODING_ID.getRequiredValue(properties));
.splitToList(ENCODING.getRequiredValue(properties));

for (String encodingId : supportedEncodings) {
if (!QueryDataDecoders.exists(encodingId)) {
return Optional.of("Unknown encoding id: " + encodingId);
for (String encoding : supportedEncodings) {
if (!QueryDataDecoders.exists(encoding)) {
return Optional.of("Unknown encoding: " + encoding);
}
}
return Optional.empty();
Expand Down
Loading
Loading