@@ -156,6 +156,9 @@ public class Client implements AutoCloseable {
156156
157157 private final ColumnToMethodMatchingStrategy columnToMethodMatchingStrategy ;
158158
159+ // Server context
160+ private String serverVersion ;
161+
159162 private Client (Set <String > endpoints , Map <String ,String > configuration , boolean useNewImplementation ,
160163 ExecutorService sharedOperationExecutor , ColumnToMethodMatchingStrategy columnToMethodMatchingStrategy ) {
161164 this .endpoints = endpoints ;
@@ -182,8 +185,27 @@ private Client(Set<String> endpoints, Map<String,String> configuration, boolean
182185 LOG .info ("Using old http client implementation" );
183186 }
184187 this .columnToMethodMatchingStrategy = columnToMethodMatchingStrategy ;
188+
189+ updateServerContext ();
190+ }
191+
192+ private void updateServerContext () {
193+ try (QueryResponse response = this .query ("SELECT currentUser() AS user, timezone() AS timezone, version() AS version LIMIT 1" ).get ()) {
194+ try (ClickHouseBinaryFormatReader reader = this .newBinaryFormatReader (response )) {
195+ if (reader .next () != null ) {
196+ this .configuration .put (ClientConfigProperties .USER .getKey (), reader .getString ("user" ));
197+ this .configuration .put (ClientConfigProperties .SERVER_TIMEZONE .getKey (), reader .getString ("timezone" ));
198+ serverVersion = reader .getString ("version" );
199+ }
200+ }
201+ } catch (Exception e ) {
202+ LOG .error ("Failed to get server info" , e );
203+ }
185204 }
186205
206+
207+
208+
187209 /**
188210 * Returns default database name that will be used by operations if not specified.
189211 *
@@ -219,6 +241,7 @@ public void close() {
219241 }
220242 }
221243
244+
222245 public static class Builder {
223246 private Set <String > endpoints ;
224247
@@ -1033,6 +1056,7 @@ public Client build() {
10331056 this .columnToMethodMatchingStrategy );
10341057 }
10351058
1059+
10361060 private static final int DEFAULT_NETWORK_BUFFER_SIZE = 300_000 ;
10371061
10381062 private void setDefaults () {
@@ -2142,6 +2166,10 @@ public String getUser() {
21422166 return this .configuration .get (ClientConfigProperties .USER .getKey ());
21432167 }
21442168
2169+ public String getServerVersion () {
2170+ return this .serverVersion ;
2171+ }
2172+
21452173 /**
21462174 * Sets list of DB roles that should be applied to each query.
21472175 *
0 commit comments