Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chore: use Locale.ROOT in String.format. #3117

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

hatyo
Copy link
Contributor

@hatyo hatyo commented Feb 7, 2025

Use String.format in locale-neutral to avoid rendering message in an unexpected way when the JVM process is configured with a specific locale such as lrc_IR.

This fixes #3121.

@hatyo hatyo marked this pull request as ready for review February 7, 2025 14:45
@@ -184,7 +185,7 @@ public static LogicalOperator generateAccess(@Nonnull Identifier identifier,
return logicalOperatorCatalog.lookupTableAccess(identifier, alias, requestedIndexes, semanticAnalyzer);
} else {
final var correlatedField = semanticAnalyzer.resolveCorrelatedIdentifier(identifier, currentPlanFragment.getLogicalOperatorsIncludingOuter());
Assert.thatUnchecked(requestedIndexes.isEmpty(), ErrorCode.UNSUPPORTED_QUERY, () -> String.format("Can not hint indexes with correlated field access %s", identifier));
Assert.thatUnchecked(requestedIndexes.isEmpty(), ErrorCode.UNSUPPORTED_QUERY, () -> String.format(Locale.ROOT, "Can not hint indexes with correlated field access %s", identifier));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably quite a few of these would be better off using string concatenation, but using the simple mechanical change of adding Locale.ROOT seems good for this broad change.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I will propose a different PR to remove usage of String.format where applicable.

Admittedly, most (if not all) of the current usages of String.format in relational are in an exceptional code path; either in an assertion failure, or to formulate an exception message. I do not think optimizing exceptional code paths for performance is crucial (they should not be in a tight loop, stack unrolling is already very expensive, ... etc).

Nevertheless, it is probably a good practice to avoid using String.format all together, and have a code analysis check that errors out when one uses it by mistake, considering how terrible its performance is.

@@ -162,7 +162,8 @@ public Stream<? extends Arguments> provideArguments(final ExtensionContext conte
Arguments.of(75, "with recursive c as (select * from t, c) select * from c", "recursive CTE does not contain non-recursive term"),
Arguments.of(76, "with recursive c1 as (select * from restaurant union all select * from c1) select * From c1", null),
Arguments.of(77, "with recursive c as (with recursive c1 as (select * from restaurant union all select * from c1) select * From c1 union all select * from restaurant, c) select * from c", null),
Arguments.of(78, "with recursive c as (with c as (select * from restaurant) select * from c union all select * from restaurant) select * from c union all select * from restaurant", "ambiguous nested recursive CTE name")
Arguments.of(78, "with recursive c as (with c as (select * from restaurant) select * from c union all select * from restaurant) select * from c union all select * from restaurant", "ambiguous nested recursive CTE name"),
Arguments.of(79, "with recursive c1(name) as (select * from restaurant union all select * from c1) select * From c", "cte query has 7 column(s), however 1 aliases defined")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I always approve of additional testing, but to make sure I didn't miss a code change, why an additional test here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, the additional test was to confirm the fix done here [0] in SemanticAnalyzer's validation of the CTE columns, where the incorrect %s in the error message is replaced with %d as it is a placeholder for column count which is a number.

[0] https://github.com/FoundationDB/fdb-record-layer/pull/3117/files#diff-02328f5aa27f48c66a951cf05b4a1f0e866d2f3488f7471bfba6bf49c108cb4aR695

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

use Locale.ROOT in String.format
2 participants