move validate query to read bytes ref
This commit is contained in:
parent
0f1b3f0457
commit
bb1b46431c
|
@ -20,6 +20,7 @@
|
|||
package org.elasticsearch.action.admin.indices.validate.query;
|
||||
|
||||
import org.elasticsearch.action.support.broadcast.BroadcastShardOperationRequest;
|
||||
import org.elasticsearch.common.BytesHolder;
|
||||
import org.elasticsearch.common.Nullable;
|
||||
import org.elasticsearch.common.Strings;
|
||||
import org.elasticsearch.common.io.stream.StreamInput;
|
||||
|
@ -29,14 +30,10 @@ import java.io.IOException;
|
|||
|
||||
/**
|
||||
* Internal validate request executed directly against a specific index shard.
|
||||
*
|
||||
*
|
||||
*/
|
||||
class ShardValidateQueryRequest extends BroadcastShardOperationRequest {
|
||||
|
||||
private byte[] querySource;
|
||||
private int querySourceOffset;
|
||||
private int querySourceLength;
|
||||
private BytesHolder querySource;
|
||||
|
||||
private String[] types = Strings.EMPTY_ARRAY;
|
||||
|
||||
|
@ -50,24 +47,14 @@ class ShardValidateQueryRequest extends BroadcastShardOperationRequest {
|
|||
public ShardValidateQueryRequest(String index, int shardId, @Nullable String[] filteringAliases, ValidateQueryRequest request) {
|
||||
super(index, shardId);
|
||||
this.querySource = request.querySource();
|
||||
this.querySourceOffset = request.querySourceOffset();
|
||||
this.querySourceLength = request.querySourceLength();
|
||||
this.types = request.types();
|
||||
this.filteringAliases = filteringAliases;
|
||||
}
|
||||
|
||||
public byte[] querySource() {
|
||||
public BytesHolder querySource() {
|
||||
return querySource;
|
||||
}
|
||||
|
||||
public int querySourceOffset() {
|
||||
return querySourceOffset;
|
||||
}
|
||||
|
||||
public int querySourceLength() {
|
||||
return querySourceLength;
|
||||
}
|
||||
|
||||
public String[] types() {
|
||||
return this.types;
|
||||
}
|
||||
|
@ -79,10 +66,8 @@ class ShardValidateQueryRequest extends BroadcastShardOperationRequest {
|
|||
@Override
|
||||
public void readFrom(StreamInput in) throws IOException {
|
||||
super.readFrom(in);
|
||||
querySourceLength = in.readVInt();
|
||||
querySourceOffset = 0;
|
||||
querySource = new byte[querySourceLength];
|
||||
in.readFully(querySource);
|
||||
querySource = in.readBytesReference();
|
||||
|
||||
int typesSize = in.readVInt();
|
||||
if (typesSize > 0) {
|
||||
types = new String[typesSize];
|
||||
|
@ -102,8 +87,8 @@ class ShardValidateQueryRequest extends BroadcastShardOperationRequest {
|
|||
@Override
|
||||
public void writeTo(StreamOutput out) throws IOException {
|
||||
super.writeTo(out);
|
||||
out.writeVInt(querySourceLength);
|
||||
out.writeBytes(querySource, querySourceOffset, querySourceLength);
|
||||
out.writeBytesHolder(querySource);
|
||||
|
||||
out.writeVInt(types.length);
|
||||
for (String type : types) {
|
||||
out.writeUTF(type);
|
||||
|
|
|
@ -136,11 +136,11 @@ public class TransportValidateQueryAction extends TransportBroadcastOperationAct
|
|||
protected ShardValidateQueryResponse shardOperation(ShardValidateQueryRequest request) throws ElasticSearchException {
|
||||
IndexQueryParserService queryParserService = indicesService.indexServiceSafe(request.index()).queryParserService();
|
||||
boolean valid;
|
||||
if (request.querySourceLength() == 0) {
|
||||
if (request.querySource().length() == 0) {
|
||||
valid = true;
|
||||
} else {
|
||||
try {
|
||||
queryParserService.parse(request.querySource(), request.querySourceOffset(), request.querySourceLength());
|
||||
queryParserService.parse(request.querySource().bytes(), request.querySource().offset(), request.querySource().length());
|
||||
valid = true;
|
||||
} catch (QueryParsingException e) {
|
||||
valid = false;
|
||||
|
|
|
@ -25,6 +25,7 @@ import org.elasticsearch.action.ActionRequestValidationException;
|
|||
import org.elasticsearch.action.support.broadcast.BroadcastOperationRequest;
|
||||
import org.elasticsearch.action.support.broadcast.BroadcastOperationThreading;
|
||||
import org.elasticsearch.client.Requests;
|
||||
import org.elasticsearch.common.BytesHolder;
|
||||
import org.elasticsearch.common.Required;
|
||||
import org.elasticsearch.common.Strings;
|
||||
import org.elasticsearch.common.Unicode;
|
||||
|
@ -45,8 +46,6 @@ import java.util.Map;
|
|||
* <p/>
|
||||
* <p>The request requires the query source to be set either using {@link #query(org.elasticsearch.index.query.QueryBuilder)},
|
||||
* or {@link #query(byte[])}.
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class ValidateQueryRequest extends BroadcastOperationRequest {
|
||||
|
||||
|
@ -111,16 +110,8 @@ public class ValidateQueryRequest extends BroadcastOperationRequest {
|
|||
/**
|
||||
* The query source to execute.
|
||||
*/
|
||||
byte[] querySource() {
|
||||
return querySource;
|
||||
}
|
||||
|
||||
int querySourceOffset() {
|
||||
return querySourceOffset;
|
||||
}
|
||||
|
||||
int querySourceLength() {
|
||||
return querySourceLength;
|
||||
BytesHolder querySource() {
|
||||
return new BytesHolder(querySource, querySourceOffset, querySourceLength);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -218,11 +209,11 @@ public class ValidateQueryRequest extends BroadcastOperationRequest {
|
|||
public void readFrom(StreamInput in) throws IOException {
|
||||
super.readFrom(in);
|
||||
|
||||
BytesHolder bytes = in.readBytesReference();
|
||||
querySourceUnsafe = false;
|
||||
querySourceOffset = 0;
|
||||
querySourceLength = in.readVInt();
|
||||
querySource = new byte[querySourceLength];
|
||||
in.readFully(querySource);
|
||||
querySource = bytes.bytes();
|
||||
querySourceOffset = bytes.offset();
|
||||
querySourceLength = bytes.length();
|
||||
|
||||
int typesSize = in.readVInt();
|
||||
if (typesSize > 0) {
|
||||
|
@ -237,8 +228,7 @@ public class ValidateQueryRequest extends BroadcastOperationRequest {
|
|||
public void writeTo(StreamOutput out) throws IOException {
|
||||
super.writeTo(out);
|
||||
|
||||
out.writeVInt(querySourceLength);
|
||||
out.writeBytes(querySource, querySourceOffset, querySourceLength);
|
||||
out.writeBytesHolder(querySource, querySourceOffset, querySourceLength);
|
||||
|
||||
out.writeVInt(types.length);
|
||||
for (String type : types) {
|
||||
|
@ -248,6 +238,6 @@ public class ValidateQueryRequest extends BroadcastOperationRequest {
|
|||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "[" + Arrays.toString(indices) + "]" + Arrays.toString(types) + ", querySource[" + Unicode.fromBytes(querySource) + "]";
|
||||
return "[" + Arrays.toString(indices) + "]" + Arrays.toString(types) + ", querySource[" + Unicode.fromBytes(querySource, querySourceOffset, querySourceLength) + "]";
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue