|
@@ -25,12 +25,7 @@ import org.elasticsearch.core.AbstractRefCounted;
|
|
|
import org.elasticsearch.core.Nullable;
|
|
|
import org.elasticsearch.core.Releasable;
|
|
|
import org.elasticsearch.core.Releasables;
|
|
|
-import org.elasticsearch.xcontent.InstantiatingObjectParser;
|
|
|
-import org.elasticsearch.xcontent.ObjectParser;
|
|
|
-import org.elasticsearch.xcontent.ParseField;
|
|
|
-import org.elasticsearch.xcontent.ParserConstructor;
|
|
|
import org.elasticsearch.xcontent.ToXContent;
|
|
|
-import org.elasticsearch.xcontent.XContentParser;
|
|
|
|
|
|
import java.io.IOException;
|
|
|
import java.util.Collections;
|
|
@@ -39,35 +34,10 @@ import java.util.List;
|
|
|
import java.util.Objects;
|
|
|
import java.util.Optional;
|
|
|
|
|
|
-import static org.elasticsearch.xcontent.ConstructingObjectParser.constructorArg;
|
|
|
-import static org.elasticsearch.xcontent.ConstructingObjectParser.optionalConstructorArg;
|
|
|
-import static org.elasticsearch.xpack.esql.action.ResponseValueUtils.valuesToPage;
|
|
|
-
|
|
|
public class EsqlQueryResponse extends ActionResponse implements ChunkedToXContentObject, Releasable {
|
|
|
|
|
|
private final AbstractRefCounted counted = AbstractRefCounted.of(this::closeInternal);
|
|
|
|
|
|
- private static final ParseField ID = new ParseField("id");
|
|
|
- private static final ParseField IS_RUNNING = new ParseField("is_running");
|
|
|
- private static final InstantiatingObjectParser<EsqlQueryResponse, Void> PARSER;
|
|
|
- static {
|
|
|
- InstantiatingObjectParser.Builder<EsqlQueryResponse, Void> parser = InstantiatingObjectParser.builder(
|
|
|
- "esql/query_response",
|
|
|
- true,
|
|
|
- EsqlQueryResponse.class
|
|
|
- );
|
|
|
- parser.declareString(optionalConstructorArg(), ID);
|
|
|
- parser.declareField(
|
|
|
- optionalConstructorArg(),
|
|
|
- p -> p.currentToken() == XContentParser.Token.VALUE_NULL ? false : p.booleanValue(),
|
|
|
- IS_RUNNING,
|
|
|
- ObjectParser.ValueType.BOOLEAN_OR_NULL
|
|
|
- );
|
|
|
- parser.declareObjectArray(constructorArg(), (p, c) -> ColumnInfo.fromXContent(p), new ParseField("columns"));
|
|
|
- parser.declareField(constructorArg(), (p, c) -> p.list(), new ParseField("values"), ObjectParser.ValueType.OBJECT_ARRAY);
|
|
|
- PARSER = parser.build();
|
|
|
- }
|
|
|
-
|
|
|
private final List<ColumnInfo> columns;
|
|
|
private final List<Page> pages;
|
|
|
private final Profile profile;
|
|
@@ -99,27 +69,6 @@ public class EsqlQueryResponse extends ActionResponse implements ChunkedToXConte
|
|
|
this(columns, pages, profile, columnar, null, false, isAsync);
|
|
|
}
|
|
|
|
|
|
- // Used for XContent reconstruction
|
|
|
- @ParserConstructor
|
|
|
- public EsqlQueryResponse(@Nullable String asyncExecutionId, Boolean isRunning, List<ColumnInfo> columns, List<List<Object>> values) {
|
|
|
- this(
|
|
|
- columns,
|
|
|
- List.of(valuesToPage(columns, values)),
|
|
|
- null,
|
|
|
- false,
|
|
|
- asyncExecutionId,
|
|
|
- isRunning != null,
|
|
|
- isAsync(asyncExecutionId, isRunning)
|
|
|
- );
|
|
|
- }
|
|
|
-
|
|
|
- static boolean isAsync(@Nullable String asyncExecutionId, Boolean isRunning) {
|
|
|
- if (asyncExecutionId != null || isRunning != null) {
|
|
|
- return true;
|
|
|
- }
|
|
|
- return false;
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* Build a reader for the response.
|
|
|
*/
|
|
@@ -229,10 +178,6 @@ public class EsqlQueryResponse extends ActionResponse implements ChunkedToXConte
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
- public static EsqlQueryResponse fromXContent(XContentParser parser) {
|
|
|
- return PARSER.apply(parser, null);
|
|
|
- }
|
|
|
-
|
|
|
@Override
|
|
|
public boolean equals(Object o) {
|
|
|
if (this == o) return true;
|