Skip to content

Commit

Permalink
Refactor String.format to Concatenation (#14418)
Browse files Browse the repository at this point in the history
  • Loading branch information
ashishjayamohan authored Nov 16, 2024
1 parent 8091415 commit a51b1d1
Show file tree
Hide file tree
Showing 11 changed files with 83 additions and 85 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,11 @@ public static List<BasicAuthPrincipal> extractBasicAuthPrincipals(PinotConfigura
String name = rawName.trim();
Preconditions.checkArgument(StringUtils.isNotBlank(name), "%s is not a valid name", name);

String password = configuration.getProperty(String.format("%s.%s.%s", prefix, name, PASSWORD));
String password = configuration.getProperty(prefix + "." + name + "." + PASSWORD);
Preconditions.checkArgument(StringUtils.isNotBlank(password), "must provide a password for %s", name);

Set<String> tables = extractSet(configuration, String.format("%s.%s.%s", prefix, name, TABLES));
Set<String> permissions = extractSet(configuration, String.format("%s.%s.%s", prefix, name, PERMISSIONS));
Set<String> tables = extractSet(configuration, prefix + "." + name + "." + TABLES);
Set<String> permissions = extractSet(configuration, prefix + "." + name + "." + PERMISSIONS);

return new BasicAuthPrincipal(name, org.apache.pinot.common.auth.BasicAuthUtils.toBasicAuthToken(name, password),
tables, permissions);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@
*/
public class DateTruncTransformFunction extends BaseTransformFunction {
public static final String FUNCTION_NAME = "dateTrunc";
public static final String EXAMPLE_INVOCATION =
String.format("%s('week', time_expression, 'seconds', <TZ>, <Output-Granularity>)", FUNCTION_NAME);
public static final String EXAMPLE_INVOCATION = FUNCTION_NAME + "('week', time_expression, 'seconds', <TZ>, "
+ "<Output-Granularity>)";
private static final String UTC_TZ = TimeZoneKey.UTC_KEY.getId();
private TransformFunction _mainTransformFunction;
private TransformResultMetadata _resultMetadata;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,9 +193,9 @@ private SchedulerQueryContext takeNextInternal() {
if (currentWinnerGroup != null) {
ServerQueryRequest queryRequest = currentWinnerGroup.peekFirst().getQueryRequest();
if (LOGGER.isDebugEnabled()) {
sb.append(String.format(" Winner: %s: [%d,%d,%d,%d]", currentWinnerGroup.name(),
queryRequest.getTimerContext().getQueryArrivalTimeMs(), queryRequest.getRequestId(),
queryRequest.getSegmentsToQuery().size(), startTime));
sb.append(" Winner: " + currentWinnerGroup.name() + ": ["
+ queryRequest.getTimerContext().getQueryArrivalTimeMs() + "," + queryRequest.getRequestId() + ","
+ queryRequest.getSegmentsToQuery().size() + "," + startTime + "]");
}
query = currentWinnerGroup.removeFirst();
}
Expand All @@ -209,10 +209,10 @@ private void checkGroupHasCapacity(SchedulerGroup groupContext)
throws OutOfCapacityException {
if (groupContext.numPending() >= _maxPendingPerGroup
&& groupContext.totalReservedThreads() >= _resourceManager.getTableThreadsHardLimit()) {
throw new OutOfCapacityException(String.format(
"SchedulerGroup %s is out of capacity. numPending: %d, maxPending: %d, reservedThreads: %d "
+ "threadsHardLimit: %d", groupContext.name(), groupContext.numPending(), _maxPendingPerGroup,
groupContext.totalReservedThreads(), _resourceManager.getTableThreadsHardLimit()));
throw new OutOfCapacityException(
"SchedulerGroup " + groupContext.name() + " is out of capacity. numPending: " + groupContext.numPending()
+ ", maxPending: " + _maxPendingPerGroup + ", reservedThreads: " + groupContext.totalReservedThreads()
+ " threadsHardLimit: " + _resourceManager.getTableThreadsHardLimit());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,24 +144,24 @@ private SchedulerQueryContext takeNextInternal() {
StringBuilder sb = new StringBuilder("SchedulerInfo:");
sb.append(_schedulerGroup.toString());
ServerQueryRequest queryRequest = _schedulerGroup.peekFirst().getQueryRequest();
sb.append(String.format(" Group: %s: [%d,%d,%d,%d]", _schedulerGroup.name(),
queryRequest.getTimerContext().getQueryArrivalTimeMs(), queryRequest.getRequestId(),
queryRequest.getSegmentsToQuery().size(), startTimeMs));
sb.append(" Group: " + _schedulerGroup.name() + ": [" + queryRequest.getTimerContext().getQueryArrivalTimeMs()
+ "," + queryRequest.getRequestId() + "," + queryRequest.getSegmentsToQuery().size() + "," + startTimeMs
+ "]");
LOGGER.debug(sb.toString());
}

SchedulerQueryContext query = _schedulerGroup.removeFirst();
return query;
return _schedulerGroup.removeFirst();
}

private void checkSchedulerGroupCapacity(SchedulerQueryContext query)
throws OutOfCapacityException {
if (_schedulerGroup.numPending() >= _maxPendingPerGroup
&& _schedulerGroup.totalReservedThreads() >= _resourceManager.getTableThreadsHardLimit()) {
throw new OutOfCapacityException(String.format(
"SchedulerGroup %s is out of capacity. numPending: %d, maxPending: %d, reservedThreads: %d "
+ "threadsHardLimit: %d", _schedulerGroup.name(), _schedulerGroup.numPending(), _maxPendingPerGroup,
_schedulerGroup.totalReservedThreads(), _resourceManager.getTableThreadsHardLimit()));
throw new OutOfCapacityException(
"SchedulerGroup " + _schedulerGroup.name() + " is out of capacity. numPending: "
+ _schedulerGroup.numPending() + ", maxPending: " + _maxPendingPerGroup + ", reservedThreads: "
+ _schedulerGroup.totalReservedThreads() + " threadsHardLimit: "
+ _resourceManager.getTableThreadsHardLimit());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ private static HttpServerThreadPoolConfig buildServerThreadPoolConfig(PinotConfi

public static String toString(Collection<? extends ListenerConfig> listenerConfigs) {
return StringUtils.join(listenerConfigs.stream()
.map(listener -> String.format("%s://%s:%d", listener.getProtocol(), listener.getHost(), listener.getPort()))
.map(listener -> listener.getProtocol() + "://" + listener.getHost() + ":" + listener.getPort())
.toArray(), ", ");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,14 @@ public DateTimeFormatSpec(String format) {

String[] tokens = StringUtil.split(format, COLON_SEPARATOR, COLON_FORMAT_MAX_TOKENS);
Preconditions.checkArgument(tokens.length >= COLON_FORMAT_MIN_TOKENS && tokens.length <= COLON_FORMAT_MAX_TOKENS,
"Invalid format: %s, must be of format 'size:timeUnit:timeFormat(:patternWithTz)'", format);
"Invalid format:" + format + ", must be of format 'size:timeUnit:timeFormat(:patternWithTz)'");

TimeFormat timeFormat;
try {
timeFormat = TimeFormat.valueOf(tokens[COLON_FORMAT_TIME_FORMAT_POSITION]);
} catch (Exception e) {
throw new IllegalArgumentException(
String.format("Invalid time format: %s in format: %s", tokens[COLON_FORMAT_TIME_FORMAT_POSITION], format));
throw new IllegalArgumentException("Invalid time format: " + tokens[COLON_FORMAT_TIME_FORMAT_POSITION]
+ " in format: " + format);
}

switch (timeFormat) {
Expand All @@ -95,15 +95,15 @@ public DateTimeFormatSpec(String format) {
try {
_size = Integer.parseInt(sizeStr);
} catch (Exception e) {
throw new IllegalArgumentException(String.format("Invalid size: %s in format: %s", sizeStr, format));
throw new IllegalArgumentException("Invalid size: " + sizeStr + " in format: " + format);
}
Preconditions.checkArgument(_size > 0, "Invalid size: %s in format: %s, must be positive", _size, format);
Preconditions.checkArgument(_size > 0, "Invalid size: " + _size + " in format: " + format
+ ", must be positive");
String timeUnitStr = tokens[COLON_FORMAT_TIME_UNIT_POSITION];
try {
_unitSpec = new DateTimeFormatUnitSpec(timeUnitStr);
} catch (Exception e) {
throw new IllegalArgumentException(
String.format("Invalid time unit: %s in format: %s", timeUnitStr, format));
throw new IllegalArgumentException("Invalid time unit: " + timeUnitStr + " in format: " + format);
}
_patternSpec = DateTimeFormatPatternSpec.EPOCH;
break;
Expand All @@ -120,8 +120,8 @@ public DateTimeFormatSpec(String format) {
try {
_patternSpec = new DateTimeFormatPatternSpec(TimeFormat.SIMPLE_DATE_FORMAT, patternStr);
} catch (Exception e) {
throw new IllegalArgumentException(
String.format("Invalid SIMPLE_DATE_FORMAT pattern: %s in format: %s", patternStr, format));
throw new IllegalArgumentException("Invalid SIMPLE_DATE_FORMAT pattern: " + patternStr + " in format: "
+ format);
}
break;
default:
Expand All @@ -132,15 +132,15 @@ public DateTimeFormatSpec(String format) {

String[] tokens = StringUtil.split(format, PIPE_SEPARATOR, PIPE_FORMAT_MAX_TOKENS);
Preconditions.checkArgument(tokens.length >= PIPE_FORMAT_MIN_TOKENS && tokens.length <= PIPE_FORMAT_MAX_TOKENS,
"Invalid format: %s, must be of format 'EPOCH|<timeUnit>(|<size>)' or "
+ "'SIMPLE_DATE_FORMAT|<pattern>(|<timeZone>)' or 'TIMESTAMP'", format);
"Invalid format: " + format + ", must be of format 'EPOCH|<timeUnit>(|<size>)' or "
+ "'SIMPLE_DATE_FORMAT|<pattern>(|<timeZone>)' or 'TIMESTAMP'");

TimeFormat timeFormat;
try {
timeFormat = TimeFormat.valueOf(tokens[PIPE_FORMAT_TIME_FORMAT_POSITION]);
} catch (Exception e) {
throw new IllegalArgumentException(
String.format("Invalid time format: %s in format: %s", tokens[PIPE_FORMAT_TIME_FORMAT_POSITION], format));
throw new IllegalArgumentException("Invalid time format: " + tokens[PIPE_FORMAT_TIME_FORMAT_POSITION]
+ " in format: " + format);
}

switch (timeFormat) {
Expand All @@ -149,19 +149,20 @@ public DateTimeFormatSpec(String format) {
try {
_size = Integer.parseInt(tokens[PIPE_FORMAT_SIZE_POSITION]);
} catch (Exception e) {
throw new IllegalArgumentException(
String.format("Invalid size: %s in format: %s", tokens[COLON_FORMAT_SIZE_POSITION], format));
throw new IllegalArgumentException("Invalid size: " + tokens[COLON_FORMAT_SIZE_POSITION] + " in format: "
+ format);
}
Preconditions.checkArgument(_size > 0, "Invalid size: %s in format: %s, must be positive", _size, format);
Preconditions.checkArgument(_size > 0, "Invalid size: " + _size + " in format: " + format
+ ", must be positive");
} else {
_size = 1;
}
try {
_unitSpec = tokens.length > PIPE_FORMAT_TIME_UNIT_POSITION ? new DateTimeFormatUnitSpec(
tokens[PIPE_FORMAT_TIME_UNIT_POSITION]) : DateTimeFormatUnitSpec.MILLISECONDS;
} catch (Exception e) {
throw new IllegalArgumentException(
String.format("Invalid time unit: %s in format: %s", tokens[PIPE_FORMAT_TIME_UNIT_POSITION], format));
throw new IllegalArgumentException("Invalid time unit: " + tokens[PIPE_FORMAT_TIME_UNIT_POSITION]
+ " in format: " + format);
}
_patternSpec = DateTimeFormatPatternSpec.EPOCH;
break;
Expand All @@ -179,9 +180,9 @@ public DateTimeFormatSpec(String format) {
new DateTimeFormatPatternSpec(TimeFormat.SIMPLE_DATE_FORMAT, tokens[PIPE_FORMAT_PATTERN_POSITION],
tokens[PIPE_FORMAT_TIME_ZONE_POSITION]);
} catch (Exception e) {
throw new IllegalArgumentException(
String.format("Invalid SIMPLE_DATE_FORMAT pattern: %s, time zone: %s in format: %s",
tokens[PIPE_FORMAT_PATTERN_POSITION], tokens[PIPE_FORMAT_TIME_ZONE_POSITION], format));
throw new IllegalArgumentException("Invalid SIMPLE_DATE_FORMAT pattern: "
+ tokens[PIPE_FORMAT_PATTERN_POSITION] + ", time zone: " + tokens[PIPE_FORMAT_TIME_ZONE_POSITION]
+ " in format: " + format);
}
} else {
try {
Expand Down Expand Up @@ -215,7 +216,7 @@ public static DateTimeFormatSpec forEpoch(String timeUnit) {
}

public static DateTimeFormatSpec forEpoch(int size, String timeUnit) {
Preconditions.checkArgument(size > 0, "Invalid size: %s, must be positive", size);
Preconditions.checkArgument(size > 0, "Invalid size: " + size + ", must be positive");
Preconditions.checkArgument(timeUnit != null, "Must provide time unit");
return new DateTimeFormatSpec(size, new DateTimeFormatUnitSpec(timeUnit), DateTimeFormatPatternSpec.EPOCH);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,8 @@ public DateTimeGranularitySpec(String granularity) {
try {
_timeUnit = TimeUnit.valueOf(granularityTokens[timeUnitPosition]);
} catch (Exception e) {
throw new IllegalArgumentException(
String.format("Invalid time unit: %s in granularity: %s", granularityTokens[timeUnitPosition],
granularity));
throw new IllegalArgumentException("Invalid time unit: " + granularityTokens[timeUnitPosition]
+ " in granularity: " + granularity);
}

// New format without explicitly setting size - use default size = 1
Expand All @@ -96,8 +95,8 @@ public DateTimeGranularitySpec(String granularity) {
try {
_size = Integer.parseInt(granularityTokens[sizePosition]);
} catch (Exception e) {
throw new IllegalArgumentException(
String.format("Invalid size: %s in granularity: %s", granularityTokens[sizePosition], granularity));
throw new IllegalArgumentException("Invalid size: " + granularityTokens[sizePosition] + " in granularity: "
+ granularity);
}
Preconditions.checkArgument(_size > 0, "Invalid size: %s in granularity: %s, must be positive", _size, granularity);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,7 @@ public Object convert(String value) {
throw new IllegalStateException();
}
} catch (Exception e) {
throw new IllegalArgumentException(String.format("Cannot convert value: '%s' to type: %s", value, this));
throw new IllegalArgumentException("Cannot convert value: '" + value + "' to type: " + this);
}
}

Expand Down Expand Up @@ -721,7 +721,7 @@ public Comparable convertInternal(String value) {
throw new IllegalStateException();
}
} catch (Exception e) {
throw new IllegalArgumentException(String.format("Cannot convert value: '%s' to type: %s", value, this));
throw new IllegalArgumentException("Cannot convert value: '" + value + "' to type: " + this);
}
}

Expand Down
32 changes: 16 additions & 16 deletions pinot-spi/src/main/java/org/apache/pinot/spi/data/Schema.java
Original file line number Diff line number Diff line change
Expand Up @@ -962,30 +962,30 @@ private static String constructTransformFunctionString(String incomingName, int
break;
case SECONDS:
if (incomingTimeSize > 1) {
innerFunction = String.format("fromEpochSecondsBucket(%s, %d)", incomingName, incomingTimeSize);
innerFunction = "fromEpochSecondsBucket(" + incomingName + ", " + incomingTimeSize + ")";
} else {
innerFunction = String.format("fromEpochSeconds(%s)", incomingName);
innerFunction = "fromEpochSeconds(" + incomingName + ")";
}
break;
case MINUTES:
if (incomingTimeSize > 1) {
innerFunction = String.format("fromEpochMinutesBucket(%s, %d)", incomingName, incomingTimeSize);
innerFunction = "fromEpochMinutesBucket(" + incomingName + ", " + incomingTimeSize + ")";
} else {
innerFunction = String.format("fromEpochMinutes(%s)", incomingName);
innerFunction = "fromEpochMinutes(" + incomingName + ")";
}
break;
case HOURS:
if (incomingTimeSize > 1) {
innerFunction = String.format("fromEpochHoursBucket(%s, %d)", incomingName, incomingTimeSize);
innerFunction = "fromEpochHoursBucket(" + incomingName + ", " + incomingTimeSize + ")";
} else {
innerFunction = String.format("fromEpochHours(%s)", incomingName);
innerFunction = "fromEpochHours(" + incomingName + ")";
}
break;
case DAYS:
if (incomingTimeSize > 1) {
innerFunction = String.format("fromEpochDaysBucket(%s, %d)", incomingName, incomingTimeSize);
innerFunction = "fromEpochDaysBucket(" + incomingName + ", " + incomingTimeSize + ")";
} else {
innerFunction = String.format("fromEpochDays(%s)", incomingName);
innerFunction = "fromEpochDays(" + incomingName + ")";
}
break;
default:
Expand All @@ -998,30 +998,30 @@ private static String constructTransformFunctionString(String incomingName, int
break;
case SECONDS:
if (outgoingTimeSize > 1) {
outerFunction = String.format("toEpochSecondsBucket(%s, %d)", innerFunction, outgoingTimeSize);
outerFunction = "toEpochSecondsBucket(" + innerFunction + ", " + outgoingTimeSize + ")";
} else {
outerFunction = String.format("toEpochSeconds(%s)", innerFunction);
outerFunction = "toEpochSeconds(" + innerFunction + ")";
}
break;
case MINUTES:
if (outgoingTimeSize > 1) {
outerFunction = String.format("toEpochMinutesBucket(%s, %d)", innerFunction, outgoingTimeSize);
outerFunction = "toEpochMinutesBucket(" + innerFunction + ", " + outgoingTimeSize + ")";
} else {
outerFunction = String.format("toEpochMinutes(%s)", innerFunction);
outerFunction = "toEpochMinutes(" + innerFunction + ")";
}
break;
case HOURS:
if (outgoingTimeSize > 1) {
outerFunction = String.format("toEpochHoursBucket(%s, %d)", innerFunction, outgoingTimeSize);
outerFunction = "toEpochHoursBucket(" + innerFunction + ", " + outgoingTimeSize + ")";
} else {
outerFunction = String.format("toEpochHours(%s)", innerFunction);
outerFunction = "toEpochHours(" + innerFunction + ")";
}
break;
case DAYS:
if (outgoingTimeSize > 1) {
outerFunction = String.format("toEpochDaysBucket(%s, %d)", innerFunction, outgoingTimeSize);
outerFunction = "toEpochDaysBucket(" + innerFunction + ", " + outgoingTimeSize + ")";
} else {
outerFunction = String.format("toEpochDays(%s)", innerFunction);
outerFunction = "toEpochDays(" + innerFunction + ")";
}
break;
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ protected void parseProperty(final String line) {
// getPropertySeparator(), in general returns the PropertiesConfiguration `DEFAULT_SEPARATOR` value i.e. ' = '.
String separator = getPropertySeparator();
Preconditions.checkArgument(CommonsConfigurationUtils.VERSIONED_CONFIG_SEPARATOR.equals(separator),
String.format("Versioned property configuration separator '%s' should be equal to '%s'",
separator, CommonsConfigurationUtils.VERSIONED_CONFIG_SEPARATOR));
"Versioned property configuration separator '" + separator + "' should be equal to '"
+ CommonsConfigurationUtils.VERSIONED_CONFIG_SEPARATOR + "'");

String[] keyValue = StringUtils.splitByWholeSeparator(line, separator, 2);
Preconditions.checkArgument(keyValue.length == 2, "property content split should result in key and value");
Expand Down
Loading

0 comments on commit a51b1d1

Please sign in to comment.