@@ -154,6 +154,10 @@ public class Client implements AutoCloseable {
154154
155155 private final ColumnToMethodMatchingStrategy columnToMethodMatchingStrategy ;
156156
157+ // Server context
158+ private String serverUser ;
159+ private String serverVersion ;
160+
157161 private Client (Set <String > endpoints , Map <String ,String > configuration , boolean useNewImplementation ,
158162 ExecutorService sharedOperationExecutor , ColumnToMethodMatchingStrategy columnToMethodMatchingStrategy ) {
159163 this .endpoints = endpoints ;
@@ -179,8 +183,25 @@ private Client(Set<String> endpoints, Map<String,String> configuration, boolean
179183 LOG .info ("Using old http client implementation" );
180184 }
181185 this .columnToMethodMatchingStrategy = columnToMethodMatchingStrategy ;
186+
187+ updateServerContext ();
182188 }
183189
190+ private void updateServerContext () {
191+ try (QueryResponse response = this .query ("SELECT currentUser() AS user, timezone() AS timezone, version() AS version LIMIT 1" ).get ()) {
192+ try (ClickHouseBinaryFormatReader reader = this .newBinaryFormatReader (response )) {
193+ if (reader .next () != null ) {
194+ serverUser = reader .getString ("user" );
195+ this .configuration .put (ClientConfigProperties .SERVER_TIMEZONE .getKey (), reader .getString ("timezone" ));
196+ serverVersion = reader .getString ("version" );
197+ }
198+ }
199+ } catch (Exception e ) {
200+ LOG .error ("Failed to get server info" , e );
201+ }
202+ }
203+
204+
184205 /**
185206 * Returns default database name that will be used by operations if not specified.
186207 *
@@ -216,6 +237,7 @@ public void close() {
216237 }
217238 }
218239
240+
219241 public static class Builder {
220242 private Set <String > endpoints ;
221243
@@ -1015,6 +1037,7 @@ public Client build() {
10151037 return new Client (this .endpoints , this .configuration , this .useNewImplementation , this .sharedOperationExecutor , this .columnToMethodMatchingStrategy );
10161038 }
10171039
1040+
10181041 private static final int DEFAULT_NETWORK_BUFFER_SIZE = 300_000 ;
10191042
10201043 private void setDefaults () {
0 commit comments