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

Improve DistributedQueryRunner.Builder #17104

Conversation

ssheikin
Copy link
Contributor

Description

Additional context and related issues

Release notes

(x) This is not user-visible or docs only and no release notes are required.
( ) Release notes are required, please propose a release note for me.
( ) Release notes are required, with the following suggested text:

# Section
* Fix some things. ({issue}`issuenumber`)

@ssheikin ssheikin requested review from wendigo and hashhar April 18, 2023 14:31
@ssheikin ssheikin force-pushed the ssheikin/35/trino/DistributedQueryRunner.builder branch from 72c9341 to 12b1416 Compare April 18, 2023 14:36
@cla-bot cla-bot bot added the cla-signed label Apr 18, 2023
@github-actions github-actions bot added the delta-lake Delta Lake connector label Apr 18, 2023
@hashhar hashhar requested a review from losipiuk April 19, 2023 07:30
@@ -616,7 +616,7 @@ private static void closeUnchecked(AutoCloseable closeable)
{
private Session defaultSession;
private int nodeCount = 3;
private Map<String, String> extraProperties = new HashMap<>();
private Map<String, String> extraProperties = ImmutableMap.of();
Copy link
Member

Choose a reason for hiding this comment

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

I do not get this change. What was wrong with previous appraoch?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

HashMap.put/putAll could potentially silently overwrite existing value. This is not a case with ImmutableMap

Copy link
Member

Choose a reason for hiding this comment

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

Oh I see. Just do putIfAbsent and assert it returns null. Code will be much simpler.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Despite

Code will be much simpler.

This is a step backward from Immutable collections, which relaxes the code style - opens a possibility to override properties without intention. I'd prefer to left it as it is.

Copy link
Member

Choose a reason for hiding this comment

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

I do not see it as such. It is not that ImmutableMap prevents you from overriding properties, but the logic in addProperties/addProperty.
Yet, whatever I will not fight over it.

Copy link
Member

Choose a reason for hiding this comment

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

I agree with @losipiuk. Even if you have ImmutableMap you're still using a builder to construct it in those methods and anyone can override there if needed.

The safety comes from the fact that the only way to set these properties is via addProperties/addProperty and as long as those methods prevent overriding there's no possibility of overriding happening by mistake.

I also don't think it's worth arguing over even though the code looks much simpler and self-documenting with the change applied.

According to javadoc `setSingleCoordinatorProperty`
/**
 * Sets coordinator properties being equal to a map containing given key and
 * value.
 * Note, that calling this method OVERWRITES previously set property values.
 * As a result, it should only be used when only one coordinator property needs
 * to be set.
 */
 So it SILENTLY overwrites previous value of `coordinatorProperties`.
 So far all invocations of `createDockerizedDeltaLakeQueryRunner` were
 receiving at most single value, so in practice it never occurred.

 Also, most probably, `setSingleCoordinatorProperty` was a handy method to set
 only one property to `TpchQueryRunnerBuilder`. In it's turn
 `TpchQueryRunnerBuilder` does not manipulate with coordinator properties, so
 the guarantee of the only one single property is not needed.
 Later, if needed, the similar `addCoordinatorProperty` handy method may be
 added.
@ssheikin ssheikin force-pushed the ssheikin/35/trino/DistributedQueryRunner.builder branch from 12b1416 to fecb124 Compare April 21, 2023 11:37
@ssheikin ssheikin force-pushed the ssheikin/35/trino/DistributedQueryRunner.builder branch from fecb124 to 1859cd4 Compare April 21, 2023 12:05
@losipiuk
Copy link
Member

@hashhar opinion here?

@losipiuk losipiuk merged commit b3b3351 into trinodb:master Apr 27, 2023
@github-actions github-actions bot added this to the 415 milestone Apr 27, 2023
@ssheikin ssheikin deleted the ssheikin/35/trino/DistributedQueryRunner.builder branch May 18, 2023 11:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla-signed delta-lake Delta Lake connector
Development

Successfully merging this pull request may close these issues.

4 participants