Github user arina-ielchiieva commented on a diff in the pull request: https://github.com/apache/drill/pull/1029#discussion_r150086018 --- Diff: exec/java-exec/src/main/java/org/apache/drill/exec/server/rest/profile/ProfileResources.java --- @@ -93,13 +96,35 @@ public ProfileInfo(DrillConfig drillConfig, String queryId, long startTime, long this.time = new Date(startTime); this.foreman = foreman; this.link = generateLink(drillConfig, foreman, queryId); - this.query = query.substring(0, Math.min(query.length(), 150)); + this.query = extractQuerySnippet(query); this.state = state; this.user = user; this.totalCost = totalCost; this.queueName = queueName; } + private String extractQuerySnippet(String queryText) { + //Extract upto max char limit as snippet + String sizeCappedQuerySnippet = queryText.substring(0, Math.min(queryText.length(), QUERY_SNIPPET_MAX_CHAR)); + //Trimming down based on line-count + if ( QUERY_SNIPPET_MAX_LINES < sizeCappedQuerySnippet.split(System.lineSeparator()).length ) { --- End diff -- 1. We can create variable for `sizeCappedQuerySnippet.split(System.lineSeparator())` so we do split only once. 2. Please remove spaces in `if` clause: `if ( QUERY_SNIPPET_MAX_LINES < sizeCappedQuerySnippet.split(System.lineSeparator()).length ) {` -> `if (QUERY_SNIPPET_MAX_LINES < splittedQuery.length) {` and in `if ( ++linesConstructed < QUERY_SNIPPET_MAX_LINES ) {` in the code below.
---