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

Support command level URL query string parameters #510

Conversation

MikeAmputer
Copy link
Contributor

Discussed in #509 , closes #86

This PR introduces CustomSettings attribute for ClickHouseCommand class.

  • The values assigned to CustomSettings are appended as URL query string parameters.
  • This implementation is similar to the existing public contract of ClickHouseConnection for consistency.
  • Command-level settings specified through CustomSettings will take precedence over analogous connection-level settings.

ClickHouseUriBuilder tests were added. Some of them demonstrate that both command-level and connection-level custom settings can override common parameters, such as query, session_id, etc. This behavior might be unintended.

@MikeAmputer
Copy link
Contributor Author

Hi @DarkWanderer , just checking in to see if you're still interested in these changes. The pull request is ready for review whenever you have the time.

public static string DefaultFormat => "RowBinaryWithNamesAndTypes";

public IDictionary<string, object> CustomParameters { get; set; }
public IDictionary<string, object> ConnectionQueryStringParameters { get; set; }
Copy link
Owner

Choose a reason for hiding this comment

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

This class doesn't need to know about existence of Command or ConnectionString. The custom parameters should be fed from outside - overriding the values as needed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point. However, considering that this class is internal, I believe this implementation is easier to maintain.

Copy link
Owner

@DarkWanderer DarkWanderer Aug 25, 2024

Choose a reason for hiding this comment

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

Having N properties instead of 1 is definitely not easier to maintain. Merging the dictionary can well be done at builder population stage rather than at URI build time.

Copy link
Contributor Author

@MikeAmputer MikeAmputer Aug 25, 2024

Choose a reason for hiding this comment

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

Merging this into a single dictionary would complicate unit tests. To properly test the override of command-level settings over connection-level ones, I'd need to create a connection with a command and mock an HttpClient. Since there is no Moq reference yet, what do you think is the most suitable approach here?
(sorry, didn’t realize the PR had already been merged)

/// Gets collection of custom settings which will be passed as URL query string parameters.
/// </summary>
/// <remarks>Not thread-safe.</remarks>
public IDictionary<string, object> CustomSettings => customSettings ??= new Dictionary<string, object>();
Copy link
Owner

Choose a reason for hiding this comment

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

An autoproperty would be more efficient and idiomatic here:

    public IDictionary<string, object> CustomSettings { get; } = new Dictionary<string, object>();

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're right, the auto-property is more idiomatic. But is it truly more efficient here? Since commands are created frequently and settings are used only occasionally, I chose not to allocate the dictionary every time to reduce command initialization time.

Copy link
Owner

Choose a reason for hiding this comment

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

The cost of having an NRE at the wrong time will definitely be more than the cost of creating an extra Dictionary object

@DarkWanderer
Copy link
Owner

Greetings. Sorry for slow response - real life gets in the way. Left a few minor comments

@DarkWanderer
Copy link
Owner

I feel some things can be polished further, but these should not prevent the feature to be available. Thank you for your contribution!

@DarkWanderer DarkWanderer merged commit 4e199c6 into DarkWanderer:main Aug 25, 2024
18 of 19 checks passed
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.

2 participants