Skip to content

Commit

Permalink
Query response opt (apache#13420)
Browse files Browse the repository at this point in the history
  • Loading branch information
soumitra-st authored Jun 18, 2024
1 parent 10186f4 commit bb42575
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.StreamingOutput;
import org.apache.http.conn.HttpClientConnectionManager;
import org.apache.pinot.broker.api.HttpRequesterIdentity;
import org.apache.pinot.broker.requesthandler.BrokerRequestHandler;
Expand Down Expand Up @@ -374,6 +375,7 @@ static Response getPinotQueryResponse(BrokerResponse brokerResponse)
// returning the Response with OK status and header value.
return Response.ok()
.header(PINOT_QUERY_ERROR_CODE_HEADER, queryErrorCodeHeaderValue)
.entity(brokerResponse.toJsonString()).build();
.entity((StreamingOutput) brokerResponse::toOutputStream).type(MediaType.APPLICATION_JSON)
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import com.fasterxml.jackson.annotation.JsonIgnore;
import java.io.IOException;
import java.io.OutputStream;
import java.util.List;
import java.util.Map;
import javax.annotation.Nullable;
Expand All @@ -41,6 +42,14 @@ default String toJsonString()
return JsonUtils.objectToString(this);
}

/**
* Write the object JSON to the output stream.
*/
default void toOutputStream(OutputStream outputStream)
throws IOException {
JsonUtils.objectToOutputStream(this, outputStream);
}

/**
* Returns the result table.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.charset.StandardCharsets;
import java.util.AbstractMap;
import java.util.ArrayList;
Expand Down Expand Up @@ -239,6 +240,11 @@ public static String objectToString(Object object)
return DEFAULT_WRITER.writeValueAsString(object);
}

public static void objectToOutputStream(Object object, OutputStream outputStream)
throws IOException {
DEFAULT_WRITER.writeValue(outputStream, object);
}

public static String objectToPrettyString(Object object)
throws JsonProcessingException {
return DEFAULT_PRETTY_WRITER.writeValueAsString(object);
Expand Down

0 comments on commit bb42575

Please sign in to comment.