Skip to content

Commit

Permalink
address coverage
Browse files Browse the repository at this point in the history
Signed-off-by: Lantao Jin <ltjin@amazon.com>
  • Loading branch information
LantaoJin committed Jul 4, 2024
1 parent 09ca944 commit 873ecee
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient cli
LOG.info(
"[{}] Request {} is not supported and falling back to old SQL engine",
QueryContext.getRequestId(),
newSqlRequest.toAnonymousString(QueryDataAnonymizer::anonymizeData));
newSqlRequest.toString(QueryDataAnonymizer::anonymizeData));
LOG.info("Request Query: {}", QueryDataAnonymizer.anonymizeData(sqlRequest.getSql()));
QueryAction queryAction = explainRequest(client, sqlRequest, format);
executeSqlRequest(request, queryAction, client, restChannel);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public void test_to_anonymous_string_of_SQLQueryRequest() {
+ "FROM accounts a JOIN employees e";
SQLQueryRequest request =
new SQLQueryRequest(null, query, "/_plugins/_sql", Map.of("pretty", "true"), null);
String actualQuery = request.toAnonymousString(QueryDataAnonymizer::anonymizeData);
String actualQuery = request.toString(QueryDataAnonymizer::anonymizeData);
String expectedQuery =
"SQLQueryRequest(query=( SELECT identifier, identifier, identifier, identifier, identifier"
+ " FROM table a JOIN table e ), path=/_plugins/_sql, format=jdbc,"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,8 @@ private boolean shouldSanitize(Map<String, String> params) {
return true;
}

public String toAnonymousString(Function<String, String> anonymizer) {
/** A new toString() with anonymizer parameter to anonymize its query statement. */
public String toString(Function<String, String> anonymizer) {
return "SQLQueryRequest("
+ "query="
+ anonymizer.apply(getQuery())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,16 @@ public void should_support_raw_format() {
assertTrue(csvRequest.isSupported());
}

@Test
public void test_to_string_with_anonymizer() {
SQLQueryRequest request = SQLQueryRequestBuilder.request("SELECT 1").build();
String actual = request.toString(s -> "***");
String expected =
"SQLQueryRequest(query=***, path=_plugins/_sql, format=jdbc, params={}, sanitize=true,"
+ " cursor=Optional.empty)";
assertEquals(expected, actual);
}

/** SQL query request build helper to improve test data setup readability. */
private static class SQLQueryRequestBuilder {
private String jsonContent;
Expand Down

0 comments on commit 873ecee

Please sign in to comment.