Skip to content

Commit 0e1d89b

Browse files
shivam2680dgiagio
authored andcommitted
Add metric view metadata support (databricks#286)
1 parent 5f3e28b commit 0e1d89b

File tree

3 files changed

+100
-38
lines changed

3 files changed

+100
-38
lines changed

connector.go

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,21 @@ func (c *connector) Connect(ctx context.Context) (driver.Conn, error) {
4141
if err != nil {
4242
return nil, dbsqlerrint.NewDriverError(ctx, dbsqlerr.ErrThriftClient, err)
4343
}
44+
45+
// Prepare session configuration
46+
sessionParams := make(map[string]string)
47+
for k, v := range c.cfg.SessionParams {
48+
sessionParams[k] = v
49+
}
50+
51+
if c.cfg.EnableMetricViewMetadata {
52+
sessionParams["spark.sql.thriftserver.metadata.metricview.enabled"] = "true"
53+
}
54+
4455
protocolVersion := int64(c.cfg.ThriftProtocolVersion)
4556
session, err := tclient.OpenSession(ctx, &cli_service.TOpenSessionReq{
4657
ClientProtocolI64: &protocolVersion,
47-
Configuration: c.cfg.SessionParams,
58+
Configuration: sessionParams,
4859
InitialNamespace: &cli_service.TNamespace{
4960
CatalogName: catalogName,
5061
SchemaName: schemaName,
@@ -265,6 +276,14 @@ func WithMaxDownloadThreads(numThreads int) ConnOption {
265276
}
266277
}
267278

279+
// WithEnableMetricViewMetadata enables metric view metadata support. Default is false.
280+
// When enabled, adds spark.sql.thriftserver.metadata.metricview.enabled=true to session configuration.
281+
func WithEnableMetricViewMetadata(enable bool) ConnOption {
282+
return func(c *config.Config) {
283+
c.EnableMetricViewMetadata = enable
284+
}
285+
}
286+
268287
// Setup of Oauth M2m authentication
269288
func WithClientCredentials(clientID, clientSecret string) ConnOption {
270289
return func(c *config.Config) {

connector_test.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,39 @@ func TestNewConnector(t *testing.T) {
213213
require.True(t, ok)
214214
require.True(t, internalClient.TLSClientConfig.InsecureSkipVerify)
215215
})
216+
217+
t.Run("Connector test WithEnableMetricViewMetadata enabled", func(t *testing.T) {
218+
host := "databricks-host"
219+
accessToken := "token"
220+
httpPath := "http-path"
221+
con, err := NewConnector(
222+
WithServerHostname(host),
223+
WithAccessToken(accessToken),
224+
WithHTTPPath(httpPath),
225+
WithEnableMetricViewMetadata(true),
226+
)
227+
assert.Nil(t, err)
228+
229+
coni, ok := con.(*connector)
230+
require.True(t, ok)
231+
assert.True(t, coni.cfg.EnableMetricViewMetadata)
232+
})
233+
234+
t.Run("Connector test WithEnableMetricViewMetadata disabled by default", func(t *testing.T) {
235+
host := "databricks-host"
236+
accessToken := "token"
237+
httpPath := "http-path"
238+
con, err := NewConnector(
239+
WithServerHostname(host),
240+
WithAccessToken(accessToken),
241+
WithHTTPPath(httpPath),
242+
)
243+
assert.Nil(t, err)
244+
245+
coni, ok := con.(*connector)
246+
require.True(t, ok)
247+
assert.False(t, coni.cfg.EnableMetricViewMetadata)
248+
})
216249
}
217250

218251
type mockRoundTripper struct{}

internal/config/config.go

Lines changed: 47 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -82,24 +82,25 @@ func (c *Config) DeepCopy() *Config {
8282

8383
// UserConfig is the set of configurations exposed to users
8484
type UserConfig struct {
85-
Protocol string
86-
Host string // from databricks UI
87-
Port int // from databricks UI
88-
HTTPPath string // from databricks UI
89-
Catalog string
90-
Schema string
91-
Authenticator auth.Authenticator
92-
AccessToken string // from databricks UI
93-
MaxRows int // max rows per page
94-
QueryTimeout time.Duration // Timeout passed to server for query processing
95-
UserAgentEntry string
96-
Location *time.Location
97-
SessionParams map[string]string
98-
RetryWaitMin time.Duration
99-
RetryWaitMax time.Duration
100-
RetryMax int
101-
Transport http.RoundTripper
102-
UseLz4Compression bool
85+
Protocol string
86+
Host string // from databricks UI
87+
Port int // from databricks UI
88+
HTTPPath string // from databricks UI
89+
Catalog string
90+
Schema string
91+
Authenticator auth.Authenticator
92+
AccessToken string // from databricks UI
93+
MaxRows int // max rows per page
94+
QueryTimeout time.Duration // Timeout passed to server for query processing
95+
UserAgentEntry string
96+
Location *time.Location
97+
SessionParams map[string]string
98+
RetryWaitMin time.Duration
99+
RetryWaitMax time.Duration
100+
RetryMax int
101+
Transport http.RoundTripper
102+
UseLz4Compression bool
103+
EnableMetricViewMetadata bool
103104
CloudFetchConfig
104105
}
105106

@@ -123,25 +124,26 @@ func (ucfg UserConfig) DeepCopy() UserConfig {
123124
}
124125

125126
return UserConfig{
126-
Protocol: ucfg.Protocol,
127-
Host: ucfg.Host,
128-
Port: ucfg.Port,
129-
HTTPPath: ucfg.HTTPPath,
130-
Catalog: ucfg.Catalog,
131-
Schema: ucfg.Schema,
132-
Authenticator: ucfg.Authenticator,
133-
AccessToken: ucfg.AccessToken,
134-
MaxRows: ucfg.MaxRows,
135-
QueryTimeout: ucfg.QueryTimeout,
136-
UserAgentEntry: ucfg.UserAgentEntry,
137-
Location: loccp,
138-
SessionParams: sessionParams,
139-
RetryWaitMin: ucfg.RetryWaitMin,
140-
RetryWaitMax: ucfg.RetryWaitMax,
141-
RetryMax: ucfg.RetryMax,
142-
Transport: ucfg.Transport,
143-
UseLz4Compression: ucfg.UseLz4Compression,
144-
CloudFetchConfig: ucfg.CloudFetchConfig,
127+
Protocol: ucfg.Protocol,
128+
Host: ucfg.Host,
129+
Port: ucfg.Port,
130+
HTTPPath: ucfg.HTTPPath,
131+
Catalog: ucfg.Catalog,
132+
Schema: ucfg.Schema,
133+
Authenticator: ucfg.Authenticator,
134+
AccessToken: ucfg.AccessToken,
135+
MaxRows: ucfg.MaxRows,
136+
QueryTimeout: ucfg.QueryTimeout,
137+
UserAgentEntry: ucfg.UserAgentEntry,
138+
Location: loccp,
139+
SessionParams: sessionParams,
140+
RetryWaitMin: ucfg.RetryWaitMin,
141+
RetryWaitMax: ucfg.RetryWaitMax,
142+
RetryMax: ucfg.RetryMax,
143+
Transport: ucfg.Transport,
144+
UseLz4Compression: ucfg.UseLz4Compression,
145+
EnableMetricViewMetadata: ucfg.EnableMetricViewMetadata,
146+
CloudFetchConfig: ucfg.CloudFetchConfig,
145147
}
146148
}
147149

@@ -272,6 +274,14 @@ func ParseDSN(dsn string) (UserConfig, error) {
272274
ucfg.MaxDownloadThreads = numThreads
273275
}
274276

277+
// Metric View Metadata parameter
278+
if enableMetricViewMetadata, ok, err := params.extractAsBool("enableMetricViewMetadata"); ok {
279+
if err != nil {
280+
return UserConfig{}, err
281+
}
282+
ucfg.EnableMetricViewMetadata = enableMetricViewMetadata
283+
}
284+
275285
// for timezone we do a case insensitive key match.
276286
// We use getNoCase because we want to leave timezone in the params so that it will also
277287
// be used as a session param.

0 commit comments

Comments
 (0)