Skip to content

Commit 30c57ab

Browse files
maswinebyhr
authored andcommitted
Fix partialCancel statement path redirection
1 parent 535802e commit 30c57ab

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
*/
1414
package io.trino.gateway.ha.handler;
1515

16+
import com.google.common.collect.ImmutableSet;
1617
import com.google.common.io.CharStreams;
1718
import io.airlift.log.Logger;
1819
import io.trino.gateway.ha.router.TrinoQueryProperties;
@@ -24,6 +25,7 @@
2425
import java.net.URI;
2526
import java.util.List;
2627
import java.util.Optional;
28+
import java.util.Set;
2729
import java.util.regex.Matcher;
2830
import java.util.regex.Pattern;
2931

@@ -52,6 +54,8 @@ public final class ProxyUtils
5254
* capitalization.
5355
*/
5456
private static final Pattern QUERY_ID_PARAM_PATTERN = Pattern.compile(".*(?:%2F|(?i)query_?id(?-i)=|^)(\\d+_\\d+_\\d+_\\w+).*");
57+
private static final Set<String> QUERY_STATE_PATH = ImmutableSet.of("queued", "scheduled", "executing");
58+
private static final String PARTIAL_CANCEL_PATH = "partialCancel";
5559

5660
private ProxyUtils() {}
5761

@@ -100,10 +104,10 @@ public static Optional<String> extractQueryIdIfPresent(String path, String query
100104
path = path.replace(matchingStatementPath.orElse(V1_QUERY_PATH), "");
101105
String[] tokens = path.split("/");
102106
if (tokens.length >= 2) {
103-
if (tokens[1].equals("queued")
104-
|| tokens[1].equals("scheduled")
105-
|| tokens[1].equals("executing")
106-
|| tokens[1].equals("partialCancel")) {
107+
if (tokens.length >= 3 && QUERY_STATE_PATH.contains(tokens[1])) {
108+
if (tokens.length >= 4 && tokens[2].equals(PARTIAL_CANCEL_PATH)) {
109+
return Optional.of(tokens[3]);
110+
}
107111
return Optional.of(tokens[2]);
108112
}
109113
return Optional.of(tokens[1]);

gateway-ha/src/test/java/io/trino/gateway/ha/handler/TestQueryIdCachingProxyHandler.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,14 @@ void testExtractQueryIdFromUrl()
4444
throws IOException
4545
{
4646
List<String> statementPaths = ImmutableList.of("/v1/statement", "/custom/api/statement");
47+
assertThat(extractQueryIdIfPresent("/v1/statement/queued/20200416_160256_03078_6b4yt/ye6c54db413e65c5de0e99612ab1eaabb8611a8aa/1", null, statementPaths))
48+
.hasValue("20200416_160256_03078_6b4yt");
49+
assertThat(extractQueryIdIfPresent("/v1/statement/scheduled/20200416_160256_03078_6b4yt/ye6c54db413e65c5de0e99612ab1eaabb8611a8aa/1", null, statementPaths))
50+
.hasValue("20200416_160256_03078_6b4yt");
4751
assertThat(extractQueryIdIfPresent("/v1/statement/executing/20200416_160256_03078_6b4yt/ya7e884929c67cdf86207a80e7a77ab2166fa2e7b/1368", null, statementPaths))
4852
.hasValue("20200416_160256_03078_6b4yt");
53+
assertThat(extractQueryIdIfPresent("/v1/statement/executing/partialCancel/20200416_160256_03078_6b4yt/0/yce0e0e038758e454d22d7270de30395e19a28eb6/1", null, statementPaths))
54+
.hasValue("20200416_160256_03078_6b4yt");
4955
assertThat(extractQueryIdIfPresent("/custom/api/statement/executing/20200416_160256_03078_6b4yt/ya7e884929c67cdf86207a80e7a77ab2166fa2e7b/1368", null, statementPaths))
5056
.hasValue("20200416_160256_03078_6b4yt");
5157
assertThat(extractQueryIdIfPresent("/v1/statement/queued/20200416_160256_03078_6b4yt/y0d7620a6941e78d3950798a1085383234258a566/1", null, statementPaths))

0 commit comments

Comments
 (0)