Skip to content

Commit

Permalink
Pull out DriverVersion to driver.go
Browse files Browse the repository at this point in the history
Signed-off-by: Matthew Kim <11141331+mattdeekay@users.noreply.github.com>
  • Loading branch information
mattdeekay committed Jan 17, 2023
1 parent 9dd574d commit 5e4085a
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 7 deletions.
1 change: 1 addition & 0 deletions connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ type connOption func(*config.Config)
func NewConnector(options ...connOption) (driver.Connector, error) {
// config with default options
cfg := config.WithDefaults()
cfg.DriverVersion = DriverVersion

for _, opt := range options {
opt(cfg)
Expand Down
4 changes: 4 additions & 0 deletions connector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
"github.com/stretchr/testify/require"
)

var ExpectedDriverVersion = "1.0.1"

func TestNewConnector(t *testing.T) {
t.Run("Connector initialized with functional options should have all options set", func(t *testing.T) {
host := "databricks-host"
Expand Down Expand Up @@ -46,6 +48,7 @@ func TestNewConnector(t *testing.T) {
SessionParams: sessionParams,
}
expectedCfg := config.WithDefaults()
expectedCfg.DriverVersion = ExpectedDriverVersion
expectedCfg.UserConfig = expectedUserConfig
coni, ok := con.(*connector)
require.True(t, ok)
Expand Down Expand Up @@ -74,6 +77,7 @@ func TestNewConnector(t *testing.T) {
SessionParams: sessionParams,
}
expectedCfg := config.WithDefaults()
expectedCfg.DriverVersion = ExpectedDriverVersion
expectedCfg.UserConfig = expectedUserConfig
coni, ok := con.(*connector)
require.True(t, ok)
Expand Down
10 changes: 4 additions & 6 deletions driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,23 @@ func init() {

type databricksDriver struct{}

var DriverVersion = "1.0.1" // update with each version cut

// Open returns a new connection to Databricks database with a DSN string.
// Use sql.Open("databricks", <dsn string>) after importing this driver package.
func (d *databricksDriver) Open(dsn string) (driver.Conn, error) {
cfg := config.WithDefaults()
userCfg, err := config.ParseDSN(dsn)
c, err := d.OpenConnector(dsn)
if err != nil {
return nil, err
}
cfg.UserConfig = userCfg
c := &connector{
cfg: cfg,
}
return c.Connect(context.Background())
}

// OpenConnector returns a new Connector.
// Used by sql.DB to obtain a Connector and invoke its Connect method to obtain each needed connection.
func (d *databricksDriver) OpenConnector(dsn string) (driver.Connector, error) {
cfg := config.WithDefaults()
cfg.DriverVersion = DriverVersion
ucfg, err := config.ParseDSN(dsn)
if err != nil {
return nil, err
Expand Down
1 change: 0 additions & 1 deletion internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,6 @@ func WithDefaults() *Config {
PingTimeout: 15 * time.Second,
CanUseMultipleCatalogs: true,
DriverName: "godatabrickssqlconnector", // important. Do not change
DriverVersion: "1.0.1",
ThriftProtocol: "binary",
ThriftTransport: "http",
ThriftProtocolVersion: cli_service.TProtocolVersion_SPARK_CLI_SERVICE_PROTOCOL_V6,
Expand Down

0 comments on commit 5e4085a

Please sign in to comment.