Skip to content

Commit b4f7158

Browse files
prakhar10mosabua
authored andcommitted
Open query text in a separate window
1 parent d18a585 commit b4f7158

File tree

10 files changed

+1379
-94
lines changed

10 files changed

+1379
-94
lines changed

gateway-ha/src/main/java/io/trino/gateway/ha/handler/ProxyUtils.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ public final class ProxyUtils
3939
public static final String AUTHORIZATION = "Authorization";
4040

4141
private static final Logger log = Logger.get(ProxyUtils.class);
42-
public static final int QUERY_TEXT_LENGTH_FOR_HISTORY = 200;
4342
/**
4443
* This regular expression matches query ids as they appear in the path of a URL. The query id must be preceded
4544
* by a "/". A query id is defined as three groups of digits separated by underscores, with a final group

gateway-ha/src/main/java/io/trino/gateway/proxyserver/ProxyRequestHandler.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@
6363
import static io.airlift.http.client.Request.Builder.preparePut;
6464
import static io.airlift.http.client.StaticBodyGenerator.createStaticBodyGenerator;
6565
import static io.airlift.jaxrs.AsyncResponseHandler.bindAsyncResponse;
66-
import static io.trino.gateway.ha.handler.ProxyUtils.QUERY_TEXT_LENGTH_FOR_HISTORY;
6766
import static io.trino.gateway.ha.handler.ProxyUtils.SOURCE_HEADER;
6867
import static jakarta.ws.rs.core.MediaType.TEXT_PLAIN_TYPE;
6968
import static jakarta.ws.rs.core.Response.Status.BAD_GATEWAY;
@@ -307,10 +306,7 @@ public static QueryHistoryManager.QueryDetail getQueryDetailsFromRequest(Request
307306
queryDetail.setSource(request.getHeader(SOURCE_HEADER));
308307

309308
String queryText = new String(((StaticBodyGenerator) request.getBodyGenerator()).getBody(), UTF_8);
310-
queryDetail.setQueryText(
311-
queryText.length() > QUERY_TEXT_LENGTH_FOR_HISTORY
312-
? queryText.substring(0, QUERY_TEXT_LENGTH_FOR_HISTORY) + "..."
313-
: queryText);
309+
queryDetail.setQueryText(queryText);
314310
return queryDetail;
315311
}
316312

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
ALTER TABLE query_history
2+
MODIFY query_text LONGTEXT;
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
ALTER TABLE query_history ADD (query_text_clob CLOB);
2+
UPDATE query_history SET query_text_clob = query_text;
3+
ALTER TABLE query_history DROP COLUMN query_text;
4+
ALTER TABLE query_history RENAME COLUMN query_text_clob TO query_text;
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
ALTER TABLE query_history
2+
ALTER COLUMN query_text TYPE text;

gateway-ha/src/test/java/io/trino/gateway/proxyserver/TestProxyRequestHandler.java

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
package io.trino.gateway.proxyserver;
1515

1616
import io.trino.gateway.ha.HaGatewayLauncher;
17+
import io.trino.gateway.ha.router.QueryHistoryManager;
1718
import okhttp3.MediaType;
1819
import okhttp3.OkHttpClient;
1920
import okhttp3.Request;
@@ -30,12 +31,19 @@
3031
import org.testcontainers.containers.PostgreSQLContainer;
3132

3233
import java.io.File;
34+
import java.net.URI;
35+
import java.util.Optional;
3336

3437
import static com.google.common.net.HttpHeaders.CONTENT_TYPE;
3538
import static com.google.common.net.MediaType.JSON_UTF_8;
39+
import static io.airlift.http.client.Request.Builder.preparePost;
40+
import static io.airlift.http.client.StaticBodyGenerator.createStaticBodyGenerator;
3641
import static io.trino.gateway.ha.HaGatewayTestUtils.buildGatewayConfig;
3742
import static io.trino.gateway.ha.HaGatewayTestUtils.prepareMockBackend;
3843
import static io.trino.gateway.ha.HaGatewayTestUtils.setUpBackend;
44+
import static io.trino.gateway.ha.handler.HttpUtils.V1_STATEMENT_PATH;
45+
import static io.trino.gateway.ha.handler.ProxyUtils.SOURCE_HEADER;
46+
import static java.nio.charset.StandardCharsets.UTF_8;
3947
import static org.assertj.core.api.Assertions.assertThat;
4048
import static org.junit.jupiter.api.TestInstance.Lifecycle.PER_CLASS;
4149

@@ -116,4 +124,38 @@ void testPutRequestHandler()
116124
assertThat(response.code()).isEqualTo(NOT_FOUND);
117125
}
118126
}
127+
128+
@Test
129+
void testGetQueryDetailsFromRequest()
130+
{
131+
// A sample query longer than 200 characters to test against truncation.
132+
String longQuery = """
133+
SELECT
134+
c.customer_name,
135+
c.customer_region,
136+
COUNT(o.order_id) AS total_orders,
137+
SUM(o.order_value) AS total_revenue
138+
FROM
139+
hive.sales_data.customers AS c
140+
JOIN
141+
hive.sales_data.orders AS o
142+
ON c.customer_id = o.customer_id
143+
WHERE
144+
o.order_date >= date '2023-01-01'""";
145+
146+
io.airlift.http.client.Request request = preparePost()
147+
.setUri(URI.create("http://localhost:" + routerPort + V1_STATEMENT_PATH))
148+
.addHeader(SOURCE_HEADER, "trino-cli")
149+
.setBodyGenerator(createStaticBodyGenerator(longQuery, UTF_8))
150+
.build();
151+
152+
Optional<String> username = Optional.of("test_user");
153+
154+
QueryHistoryManager.QueryDetail queryDetail = ProxyRequestHandler.getQueryDetailsFromRequest(request, username);
155+
156+
assertThat(queryDetail.getQueryText()).isEqualTo(longQuery).hasSizeGreaterThan(200);
157+
assertThat(queryDetail.getUser()).isEqualTo(username.get());
158+
assertThat(queryDetail.getSource()).isEqualTo("trino-cli");
159+
assertThat(queryDetail.getBackendUrl()).isEqualTo("http://localhost:" + routerPort);
160+
}
119161
}

webapp/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@
1010
"preview": "vite preview"
1111
},
1212
"dependencies": {
13-
"@douyinfe/semi-icons": "^2.47.1",
14-
"@douyinfe/semi-icons-lab": "^2.47.1",
15-
"@douyinfe/semi-illustrations": "^2.47.1",
16-
"@douyinfe/semi-ui": "^2.47.1",
13+
"@douyinfe/semi-icons": "^2.62.0",
14+
"@douyinfe/semi-icons-lab": "^2.62.0",
15+
"@douyinfe/semi-illustrations": "^2.62.0",
16+
"@douyinfe/semi-ui": "^2.62.0",
1717
"echarts": "^5.4.3",
1818
"js-cookie": "^3.0.5",
1919
"moment": "^2.29.4",

0 commit comments

Comments
 (0)