pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: http://github.com/Dwrite/ClickHouse/commit/1406c6533d0033bd9a97f7d5aa09897fce006a9e

c69660fa.css" /> Add setting apply_settings_from_server · Dwrite/ClickHouse@1406c65 · GitHub
Skip to content

Commit 1406c65

Browse files
committed
Add setting apply_settings_from_server
1 parent fd3118a commit 1406c65

7 files changed

Lines changed: 96 additions & 24 deletions

File tree

programs/client/Client.cpp

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -484,15 +484,7 @@ void Client::connect()
484484
config().setString("host", connection_parameters.host);
485485
config().setInt("port", connection_parameters.port);
486486

487-
/// Apply setting changes received from server, but with lower priority than settings
488-
/// changed from command line.
489-
SettingsChanges settings_from_server = assert_cast<Connection &>(*connection).settingsFromServer();
490-
const Settings & settings = global_context->getSettingsRef();
491-
std::erase_if(settings_from_server, [&](const SettingChange & change)
492-
{
493-
return settings.isChanged(change.name);
494-
});
495-
global_context->applySettingsChanges(settings_from_server);
487+
settings_from_server = assert_cast<Connection &>(*connection).settingsFromServer();
496488

497489
break;
498490
}

src/Client/ClientBase.cpp

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ namespace Setting
109109
extern const SettingsBool partial_result_on_first_cancel;
110110
extern const SettingsBool throw_if_no_data_to_insert;
111111
extern const SettingsBool implicit_select;
112+
extern const SettingsBool apply_settings_from_server;
112113
}
113114

114115
namespace ErrorCodes
@@ -850,18 +851,8 @@ void ClientBase::setDefaultFormatsAndCompressionFromConfiguration()
850851
default_input_compression_method = chooseCompressionMethod(*file_name, "");
851852
}
852853

853-
format_max_block_size = getClientConfiguration().getUInt64("format_max_block_size", global_context->getSettingsRef()[Setting::max_block_size]);
854-
855-
/// Setting value from cmd arg overrides one from config
856-
if (global_context->getSettingsRef()[Setting::max_insert_block_size].changed)
857-
{
858-
insert_format_max_block_size = global_context->getSettingsRef()[Setting::max_insert_block_size];
859-
}
860-
else
861-
{
862-
insert_format_max_block_size
863-
= getClientConfiguration().getUInt64("insert_format_max_block_size", global_context->getSettingsRef()[Setting::max_insert_block_size]);
864-
}
854+
if (getClientConfiguration().has("insert_format_max_block_size"))
855+
insert_format_max_block_size_from_config = getClientConfiguration().getUInt64("insert_format_max_block_size");
865856
}
866857

867858
void ClientBase::initTTYBuffer(ProgressOption progress_option, ProgressOption progress_table_option)
@@ -1877,6 +1868,12 @@ void ClientBase::sendDataFrom(ReadBuffer & buf, Block & sample, const ColumnsDes
18771868
current_format = insert->format;
18781869
}
18791870

1871+
/// Setting value from cmd arg overrides one from config.
1872+
size_t insert_format_max_block_size = client_context->getSettingsRef()[Setting::max_insert_block_size];
1873+
if (!client_context->getSettingsRef()[Setting::max_insert_block_size].changed &&
1874+
insert_format_max_block_size_from_config.has_value())
1875+
insert_format_max_block_size = insert_format_max_block_size_from_config.value();
1876+
18801877
auto source = client_context->getInputFormat(current_format, buf, sample, insert_format_max_block_size);
18811878
Pipe pipe(source);
18821879

@@ -2131,6 +2128,8 @@ void ClientBase::processParsedSingleQuery(const String & full_query, const Strin
21312128
if (!connection->checkConnected(connection_parameters.timeouts))
21322129
connect();
21332130

2131+
applySettingsFromServerIfNeeded(); // after connect() and applySettingsFromQuery()
2132+
21342133
ASTPtr input_function;
21352134
const auto * insert = parsed_query->as<ASTInsertQuery>();
21362135
if (insert && insert->select)
@@ -2766,6 +2765,29 @@ bool ClientBase::addMergeTreeSettings(ASTCreateQuery & ast_create)
27662765
return added_new_setting;
27672766
}
27682767

2768+
void ClientBase::applySettingsFromServerIfNeeded()
2769+
{
2770+
const Settings & settings = client_context->getSettingsRef();
2771+
SettingsChanges changes_to_apply;
2772+
for (const SettingChange & change : settings_from_server)
2773+
{
2774+
/// Apply settings received from server with lower priority than settings changed from
2775+
/// command line or query.
2776+
if (settings.isChanged(change.name))
2777+
continue;
2778+
2779+
/// The setting apply_settings_from_server may itself be received from server.
2780+
/// Apply it first.
2781+
if (change.name == "apply_settings_from_server")
2782+
client_context->setSetting("apply_settings_from_server", change.value);
2783+
else
2784+
changes_to_apply.push_back(change);
2785+
}
2786+
2787+
if (settings[Setting::apply_settings_from_server])
2788+
global_context->applySettingsChanges(changes_to_apply);
2789+
}
2790+
27692791
void ClientBase::startKeystrokeInterceptorIfExists()
27702792
{
27712793
if (keystroke_interceptor)

src/Client/ClientBase.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,8 @@ class ClientBase
229229
void initQueryIdFormats();
230230
bool addMergeTreeSettings(ASTCreateQuery & ast_create);
231231

232+
void applySettingsFromServerIfNeeded();
233+
232234
void startKeystrokeInterceptorIfExists();
233235
void stopKeystrokeInterceptorIfExists();
234236

@@ -325,8 +327,7 @@ class ClientBase
325327
bool select_into_file = false; /// If writing result INTO OUTFILE. It affects progress rendering.
326328
bool select_into_file_and_stdout = false; /// If writing result INTO OUTFILE AND STDOUT. It affects progress rendering.
327329
bool is_default_format = true; /// false, if format is set in the config or command line.
328-
size_t format_max_block_size = 0; /// Max block size for console output.
329-
size_t insert_format_max_block_size = 0; /// Max block size when reading INSERT data.
330+
std::optional<size_t> insert_format_max_block_size_from_config = 0; /// Max block size when reading INSERT data.
330331
size_t max_client_network_bandwidth = 0; /// The maximum speed of data exchange over the network for the client in bytes per second.
331332

332333
bool has_vertical_output_suffix = false; /// Is \G present at the end of the query string?
@@ -377,6 +378,9 @@ class ClientBase
377378
String prompt;
378379
String server_display_name;
379380

381+
/// Settings received from the server, if any. Populated by connect().
382+
SettingsChanges settings_from_server;
383+
380384
ProgressIndication progress_indication;
381385
ProgressTable progress_table;
382386
bool need_render_progress = true;

src/Core/Settings.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5896,6 +5896,9 @@ As each series represents a node in Keeper, it is recommended to have no more th
58965896
)", 0) \
58975897
DECLARE(Bool, use_hive_partitioning, true, R"(
58985898
When enabled, ClickHouse will detect Hive-style partitioning in path (`/name=value/`) in file-like table engines [File](../../engines/table-engines/special/file.md#hive-style-partitioning)/[S3](../../engines/table-engines/integrations/s3.md#hive-style-partitioning)/[URL](../../engines/table-engines/special/url.md#hive-style-partitioning)/[HDFS](../../engines/table-engines/integrations/hdfs.md#hive-style-partitioning)/[AzureBlobStorage](../../engines/table-engines/integrations/azureBlobStorage.md#hive-style-partitioning) and will allow to use partition columns as virtual columns in the query. These virtual columns will have the same names as in the partitioned path, but starting with `_`.
5899+
)", 0) \
5900+
DECLARE(Bool, apply_settings_from_server, true, R"(
5901+
Whether the client should use the user settings from the the server configuration. This only affects operations performed on the client side, in particular parsing the INSERT input data and formatting the query result. Most of query execution happens on the server and is not affected by this setting. The settings are sent over network even if this setting is set to false; server setting send_settings_to_client can be used to disable it fully.
58995902
)", 0) \
59005903
\
59015904
/* ####################################################### */ \

src/Core/SettingsChangesHistory.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ const VersionToSettingsChangesMap & getSettingsChangesHistory()
6767
addSettingsChanges(settings_changes_history, "25.2",
6868
{
6969
{"query_plan_use_new_logical_join_step", false, true, "Enable new step"},
70+
/// 24.12 and 25.1 don't have this setting but behave as if it's set to true.
71+
/// Older versions behave as if it's set to false.
72+
{"apply_settings_from_server", false, true, "Client-side code (e.g. INSERT input parsing and query output formatting) will use the same settings as the server, including settings from server config."},
7073
});
7174
addSettingsChanges(settings_changes_history, "25.1",
7275
{

tests/integration/test_settings_from_server/configs/users.d/users.xml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,14 @@
77
<output_format_json_quote_64bit_integers>1</output_format_json_quote_64bit_integers>
88
<output_format_json_array_of_rows>1</output_format_json_array_of_rows>
99
</second_profile>
10+
<no_apply_profile>
11+
<output_format_json_quote_64bit_integers>0</output_format_json_quote_64bit_integers>
12+
<apply_settings_from_server>0</apply_settings_from_server>
13+
</no_apply_profile>
14+
<compat_profile>
15+
<output_format_json_quote_64bit_integers>0</output_format_json_quote_64bit_integers>
16+
<compatibility>24.11</compatibility>
17+
</compat_profile>
1018
</profiles>
1119
<users>
1220
<default>
@@ -17,5 +25,13 @@
1725
<password></password>
1826
<profile>second_profile</profile>
1927
</second_user>
28+
<no_apply_user>
29+
<password></password>
30+
<profile>no_apply_profile</profile>
31+
</no_apply_user>
32+
<compat_user>
33+
<password></password>
34+
<profile>compat_profile</profile>
35+
</compat_user>
2036
</users>
2137
</clickhouse>

tests/integration/test_settings_from_server/test.py

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def test_settings_from_server(started_cluster):
5050
)
5151
assert "[" not in res, "should not be formatted as a JSON array"
5252

53-
# Setting changed by server but changed back client command line.
53+
# Setting changed by server but changed back by client command line.
5454
res = node.query(
5555
"select 42::UInt64 as x format JSONEachRow",
5656
user="second_user",
@@ -66,6 +66,38 @@ def test_settings_from_server(started_cluster):
6666
assert res == "86400\n"
6767
node.query("drop user u")
6868

69+
# apply_settings_from_server = false
70+
res = node.query("select 42::UInt64 as x settings apply_settings_from_server=0 format JSON")
71+
assert '"x": "42"' in res, "should be quoted"
72+
73+
# apply_settings_from_server = false using SET query.
74+
res = node.query("set apply_settings_from_server=0; select 42::UInt64 as x format JSON;")
75+
assert '"x": "42"' in res, "should be quoted"
76+
77+
# apply_settings_from_server = false received from server.
78+
res = node.query("select 42::UInt64 as x format JSON", user="no_apply_user")
79+
assert '"x": "42"' in res, "should be quoted"
80+
81+
# apply_settings_from_server = false received from server but overridden by the query.
82+
res = node.query("select 42::UInt64 as x settings apply_settings_from_server=1 format JSON", user="no_apply_user")
83+
assert '"x": 42' in res, "should be unquoted"
84+
85+
# apply_settings_from_server = false implicitly set using compatibility setting.
86+
res = node.query("select 42::UInt64 as x format JSON", user="compat_user")
87+
assert '"x": "42"' in res, "should be quoted"
88+
89+
# apply_settings_from_server = false implicitly set using compatibility setting, but overridden by the query.
90+
res = node.query("select 42::UInt64 as x settings apply_settings_from_server=1 format JSON", user="compat_user")
91+
assert '"x": 42' in res, "should be unquoted"
92+
93+
# Multiple queries in one session with different value of apply_settings_from_server.
94+
res = node.query("select 42::UInt64 as x settings apply_settings_from_server=0 format JSON; select 42::UInt64 as x format JSON;")
95+
quoted_pos = res.find('"x": "42"')
96+
unquoted_pos = res.find('"x": 42')
97+
assert quoted_pos != -1, "first query should return quoted number"
98+
assert unquoted_pos != -1, "second query should return unquoted number"
99+
assert quoted_pos < unquoted_pos, "should be quoted for first query, unquoted for second"
100+
69101
# send_settings_to_client = false
70102
res = node_no_send.query("select 42::UInt64 as x format JSON")
71103
assert '"x": "42"' in res, "should be quoted"

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy