Skip to content

Commit 6e98bb4

Browse files
committed
Output succinct data sizes only when getting pretty query JSON
1 parent 2fb001e commit 6e98bb4

File tree

1 file changed

+20
-7
lines changed

1 file changed

+20
-7
lines changed

core/trino-main/src/main/java/io/trino/server/ui/UiQueryResource.java

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,16 @@
7070
public class UiQueryResource
7171
{
7272
private final JsonCodec<QueryInfo> queryInfoCodec;
73+
private final JsonCodec<QueryInfo> prettyQueryInfoCodec;
7374
private final DispatchManager dispatchManager;
7475
private final AccessControl accessControl;
7576
private final HttpRequestSessionContextFactory sessionContextFactory;
7677

7778
@Inject
7879
public UiQueryResource(ObjectMapper objectMapper, DispatchManager dispatchManager, AccessControl accessControl, HttpRequestSessionContextFactory sessionContextFactory)
7980
{
80-
this.queryInfoCodec = buildQueryInfoCodec(objectMapper);
81+
this.queryInfoCodec = buildQueryInfoCodec(objectMapper, false);
82+
this.prettyQueryInfoCodec = buildQueryInfoCodec(objectMapper, true);
8183
this.dispatchManager = requireNonNull(dispatchManager, "dispatchManager is null");
8284
this.accessControl = requireNonNull(accessControl, "accessControl is null");
8385
this.sessionContextFactory = requireNonNull(sessionContextFactory, "sessionContextFactory is null");
@@ -110,6 +112,11 @@ public Response getQueryInfo(@PathParam("queryId") QueryId queryId, @Context Htt
110112
if (queryInfo.isPresent()) {
111113
try {
112114
checkCanViewQueryOwnedBy(sessionContextFactory.extractAuthorizedIdentity(servletRequest, httpHeaders), queryInfo.get().getSession().toIdentity(), accessControl);
115+
116+
if (servletRequest.getQueryString().contains("pretty")) {
117+
// Use pretty JSON codec that reduces noise
118+
return Response.ok(prettyQueryInfoCodec.toJson(queryInfo.get()), APPLICATION_JSON_TYPE).build();
119+
}
113120
return Response.ok(queryInfoCodec.toJson(queryInfo.get()), APPLICATION_JSON_TYPE).build();
114121
}
115122
catch (AccessDeniedException e) {
@@ -159,13 +166,15 @@ private Response failQuery(QueryId queryId, TrinoException queryException, HttpS
159166
}
160167
}
161168

162-
private JsonCodec<QueryInfo> buildQueryInfoCodec(ObjectMapper objectMapper)
169+
private JsonCodec<QueryInfo> buildQueryInfoCodec(ObjectMapper objectMapper, boolean pretty)
163170
{
164-
// Enable succinct DataSize serialization for QueryInfo to make it more human friendly
165-
ContextAttributes attrs = ContextAttributes.getEmpty()
166-
.withSharedAttribute(SUCCINCT_DATA_SIZE_ENABLED, Boolean.TRUE);
167-
168171
JsonCodecFactory jsonCodecFactory = new JsonCodecFactory(() -> {
172+
// Enable succinct DataSize serialization for QueryInfo to make it more human friendly
173+
ContextAttributes attrs = ContextAttributes.getEmpty();
174+
if (pretty) {
175+
attrs = attrs.withSharedAttribute(SUCCINCT_DATA_SIZE_ENABLED, Boolean.TRUE);
176+
}
177+
169178
ObjectMapper mapper = objectMapper
170179
.copy()
171180
.setDefaultAttributes(attrs);
@@ -177,7 +186,11 @@ private JsonCodec<QueryInfo> buildQueryInfoCodec(ObjectMapper objectMapper)
177186
// Do not output @type property for OperatorInfo
178187
mapper.addMixIn(OperatorInfo.class, DropTypeInfo.class);
179188
return mapper;
180-
}).prettyPrint();
189+
});
190+
191+
if (pretty) {
192+
jsonCodecFactory = jsonCodecFactory.prettyPrint();
193+
}
181194

182195
return jsonCodecFactory.jsonCodec(QueryInfo.class);
183196
}

0 commit comments

Comments
 (0)