Skip to content

Commit

Permalink
Use StringBuilder to create ids
Browse files Browse the repository at this point in the history
  • Loading branch information
shangm2 authored and NikhilCollooru committed Jan 24, 2025
1 parent 1160e01 commit ff8b97d
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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()));
}
}
5 changes: 5 additions & 0 deletions presto-spi/src/main/java/com/facebook/presto/spi/QueryId.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ public String toString()
return id;
}

public void appendString(StringBuilder builder)
{
builder.append(id);
}

@Override
public int hashCode()
{
Expand Down

0 comments on commit ff8b97d

Please sign in to comment.