diff --git a/presto-main/src/main/java/com/facebook/presto/execution/StageExecutionId.java b/presto-main/src/main/java/com/facebook/presto/execution/StageExecutionId.java index 4de486abe194e..037b0f18b86c6 100644 --- a/presto-main/src/main/java/com/facebook/presto/execution/StageExecutionId.java +++ b/presto-main/src/main/java/com/facebook/presto/execution/StageExecutionId.java @@ -90,6 +90,14 @@ public int hashCode() @JsonValue public String toString() { - return stageId + "." + id; + StringBuilder builder = new StringBuilder(); + appendString(builder); + return builder.toString(); + } + + public void appendString(StringBuilder builder) + { + stageId.appendString(builder); + builder.append(".").append(id); } } diff --git a/presto-main/src/main/java/com/facebook/presto/execution/StageId.java b/presto-main/src/main/java/com/facebook/presto/execution/StageId.java index f0e60fafce939..ef5a03927e306 100644 --- a/presto-main/src/main/java/com/facebook/presto/execution/StageId.java +++ b/presto-main/src/main/java/com/facebook/presto/execution/StageId.java @@ -79,7 +79,15 @@ public int getId() @JsonValue public String toString() { - return queryId + "." + id; + StringBuilder builder = new StringBuilder(); + appendString(builder); + return builder.toString(); + } + + public void appendString(StringBuilder builder) + { + queryId.appendString(builder); + builder.append(".").append(id); } @Override diff --git a/presto-main/src/main/java/com/facebook/presto/execution/TaskId.java b/presto-main/src/main/java/com/facebook/presto/execution/TaskId.java index 40036ef94a042..3c0a4268ec0c0 100644 --- a/presto-main/src/main/java/com/facebook/presto/execution/TaskId.java +++ b/presto-main/src/main/java/com/facebook/presto/execution/TaskId.java @@ -83,7 +83,15 @@ public QueryId getQueryId() @JsonValue public String toString() { - return stageExecutionId + "." + id + "." + attemptNumber; + StringBuilder builder = new StringBuilder(); + appendString(builder); + return builder.toString(); + } + + public void appendString(StringBuilder builder) + { + stageExecutionId.appendString(builder); + builder.append(".").append(id).append(".").append(attemptNumber); } @Override diff --git a/presto-main/src/test/java/com/facebook/presto/execution/TestId.java b/presto-main/src/test/java/com/facebook/presto/execution/TestId.java new file mode 100644 index 0000000000000..45cc7dd894ee5 --- /dev/null +++ b/presto-main/src/test/java/com/facebook/presto/execution/TestId.java @@ -0,0 +1,36 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.facebook.presto.execution; + +import com.facebook.presto.spi.QueryId; +import org.testng.annotations.Test; + +import static org.testng.Assert.assertEquals; + +public class TestId +{ + @Test + public void testAppendString() + { + QueryId queryId = new QueryId("foo"); + StageId stageId = new StageId(queryId, 1); + StageExecutionId stageExecutionId = new StageExecutionId(stageId, 2); + TaskId taskId = new TaskId(stageExecutionId, 3, 1); + + assertEquals(queryId.toString(), "foo"); + assertEquals(stageId.toString(), String.format("%s.%s", queryId.getId(), stageId.getId())); + assertEquals(stageExecutionId.toString(), String.format("%s.%s.%s", queryId.getId(), stageId.getId(), stageExecutionId.getId())); + assertEquals(taskId.toString(), String.format("%s.%s.%s.%s.%s", queryId.getId(), stageId.getId(), stageExecutionId.getId(), taskId.getId(), taskId.getAttemptNumber())); + } +} diff --git a/presto-spi/src/main/java/com/facebook/presto/spi/QueryId.java b/presto-spi/src/main/java/com/facebook/presto/spi/QueryId.java index 915a07c09e9b0..e0c5bf752cee0 100644 --- a/presto-spi/src/main/java/com/facebook/presto/spi/QueryId.java +++ b/presto-spi/src/main/java/com/facebook/presto/spi/QueryId.java @@ -58,6 +58,11 @@ public String toString() return id; } + public void appendString(StringBuilder builder) + { + builder.append(id); + } + @Override public int hashCode() {