org.elasticsearch.xpack.esql.action.EsqlQueryResponse Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of x-pack-esql Show documentation
Show all versions of x-pack-esql Show documentation
The plugin that powers ESQL for Elasticsearch
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
package org.elasticsearch.xpack.esql.action;
import org.elasticsearch.TransportVersions;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.collect.Iterators;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.io.stream.Writeable;
import org.elasticsearch.common.xcontent.ChunkedToXContent;
import org.elasticsearch.common.xcontent.ChunkedToXContentHelper;
import org.elasticsearch.common.xcontent.ChunkedToXContentObject;
import org.elasticsearch.compute.data.BlockFactory;
import org.elasticsearch.compute.data.BlockStreamInput;
import org.elasticsearch.compute.data.Page;
import org.elasticsearch.compute.operator.DriverProfile;
import org.elasticsearch.core.AbstractRefCounted;
import org.elasticsearch.core.Nullable;
import org.elasticsearch.core.Releasable;
import org.elasticsearch.core.Releasables;
import org.elasticsearch.xcontent.ToXContent;
import org.elasticsearch.xpack.core.esql.action.EsqlResponse;
import org.elasticsearch.xpack.esql.core.type.DataType;
import java.io.IOException;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
public class EsqlQueryResponse extends org.elasticsearch.xpack.core.esql.action.EsqlQueryResponse
implements
ChunkedToXContentObject,
Releasable {
@SuppressWarnings("this-escape")
private final AbstractRefCounted counted = AbstractRefCounted.of(this::closeInternal);
public static final String DROP_NULL_COLUMNS_OPTION = "drop_null_columns";
private final List columns;
private final List pages;
private final Profile profile;
private final boolean columnar;
private final String asyncExecutionId;
private final boolean isRunning;
// True if this response is as a result of an async query request
private final boolean isAsync;
public EsqlQueryResponse(
List columns,
List pages,
@Nullable Profile profile,
boolean columnar,
@Nullable String asyncExecutionId,
boolean isRunning,
boolean isAsync
) {
this.columns = columns;
this.pages = pages;
this.profile = profile;
this.columnar = columnar;
this.asyncExecutionId = asyncExecutionId;
this.isRunning = isRunning;
this.isAsync = isAsync;
}
public EsqlQueryResponse(List columns, List pages, @Nullable Profile profile, boolean columnar, boolean isAsync) {
this(columns, pages, profile, columnar, null, false, isAsync);
}
/**
* Build a reader for the response.
*/
public static Writeable.Reader reader(BlockFactory blockFactory) {
return in -> {
try (BlockStreamInput bsi = new BlockStreamInput(in, blockFactory)) {
return deserialize(bsi);
}
};
}
static EsqlQueryResponse deserialize(BlockStreamInput in) throws IOException {
String asyncExecutionId = null;
boolean isRunning = false;
boolean isAsync = false;
Profile profile = null;
if (in.getTransportVersion().onOrAfter(TransportVersions.V_8_13_0)) {
asyncExecutionId = in.readOptionalString();
isRunning = in.readBoolean();
isAsync = in.readBoolean();
}
List columns = in.readCollectionAsList(ColumnInfoImpl::new);
List pages = in.readCollectionAsList(Page::new);
if (in.getTransportVersion().onOrAfter(TransportVersions.V_8_12_0)) {
profile = in.readOptionalWriteable(Profile::new);
}
boolean columnar = in.readBoolean();
return new EsqlQueryResponse(columns, pages, profile, columnar, asyncExecutionId, isRunning, isAsync);
}
@Override
public void writeTo(StreamOutput out) throws IOException {
if (out.getTransportVersion().onOrAfter(TransportVersions.V_8_13_0)) {
out.writeOptionalString(asyncExecutionId);
out.writeBoolean(isRunning);
out.writeBoolean(isAsync);
}
out.writeCollection(columns);
out.writeCollection(pages);
if (out.getTransportVersion().onOrAfter(TransportVersions.V_8_12_0)) {
out.writeOptionalWriteable(profile);
}
out.writeBoolean(columnar);
}
public List columns() {
return columns;
}
List pages() {
return pages;
}
public Iterator> values() {
List dataTypes = columns.stream().map(ColumnInfoImpl::type).toList();
return ResponseValueUtils.pagesToValues(dataTypes, pages);
}
public Iterable> rows() {
List dataTypes = columns.stream().map(ColumnInfoImpl::type).toList();
return ResponseValueUtils.valuesForRowsInPages(dataTypes, pages);
}
public Iterator
© 2015 - 2024 Weber Informatics LLC | Privacy Policy