Skip to content

Commit

Permalink
Introduced protocol checking
Browse files Browse the repository at this point in the history
  • Loading branch information
nithinkdb committed Sep 20, 2023
1 parent 388ec47 commit beea4c4
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 6 deletions.
10 changes: 9 additions & 1 deletion connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ func (c *conn) ExecContext(ctx context.Context, query string, args []driver.Name

ctx = driverctx.NewContextWithConnId(ctx, c.id)

if len(args) > 0 && c.session.ServerProtocolVersion < cli_service.TProtocolVersion_SPARK_CLI_SERVICE_PROTOCOL_V8 {
return nil, dbsqlerrint.NewDriverError(ctx, dbsqlerr.ErrParametersNotSupported, nil)
}

exStmtResp, opStatusResp, err := c.runQuery(ctx, query, args)

if exStmtResp != nil && exStmtResp.OperationHandle != nil {
Expand Down Expand Up @@ -141,6 +145,10 @@ func (c *conn) QueryContext(ctx context.Context, query string, args []driver.Nam

ctx = driverctx.NewContextWithConnId(ctx, c.id)

if len(args) > 0 && c.session.ServerProtocolVersion < cli_service.TProtocolVersion_SPARK_CLI_SERVICE_PROTOCOL_V8 {
return nil, dbsqlerrint.NewDriverError(ctx, dbsqlerr.ErrParametersNotSupported, nil)
}

// first we try to get the results synchronously.
// at any point in time that the context is done we must cancel and return
exStmtResp, opStatusResp, err := c.runQuery(ctx, query, args)
Expand Down Expand Up @@ -274,7 +282,7 @@ func (c *conn) executeStatement(ctx context.Context, query string, args []driver
req := cli_service.TExecuteStatementReq{
SessionHandle: c.session.SessionHandle,
Statement: query,
RunAsync: c.cfg.RunAsync,
RunAsync: true,
QueryTimeout: int64(c.cfg.QueryTimeout / time.Second),
GetDirectResults: &cli_service.TSparkGetDirectResults{
MaxRows: int64(c.cfg.MaxRows),
Expand Down
1 change: 1 addition & 0 deletions errors/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const (
ErrTransactionsNotSupported = "transactions are not supported"
ErrReadQueryStatus = "could not read query status"
ErrSentinelTimeout = "sentinel timed out waiting for operation to complete"
ErrParametersNotSupported = "query parameters are not supported by this server"

// Request error messages (connection, authentication, network error)
ErrCloseConnection = "failed to close connection"
Expand Down
5 changes: 1 addition & 4 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ type Config struct {
UserConfig
TLSConfig *tls.Config // nil disables TLS
ArrowConfig
RunAsync bool // TODO
PollInterval time.Duration
ClientTimeout time.Duration // max time the http request can last
PingTimeout time.Duration // max time allowed for ping
Expand Down Expand Up @@ -68,7 +67,6 @@ func (c *Config) DeepCopy() *Config {
UserConfig: c.UserConfig.DeepCopy(),
TLSConfig: c.TLSConfig.Clone(),
ArrowConfig: c.ArrowConfig.DeepCopy(),
RunAsync: c.RunAsync,
PollInterval: c.PollInterval,
ClientTimeout: c.ClientTimeout,
PingTimeout: c.PingTimeout,
Expand Down Expand Up @@ -188,15 +186,14 @@ func WithDefaults() *Config {
UserConfig: UserConfig{}.WithDefaults(),
TLSConfig: &tls.Config{MinVersion: tls.VersionTLS12},
ArrowConfig: ArrowConfig{}.WithDefaults(),
RunAsync: true,
PollInterval: 1 * time.Second,
ClientTimeout: 900 * time.Second,
PingTimeout: 60 * time.Second,
CanUseMultipleCatalogs: true,
DriverName: "godatabrickssqlconnector", // important. Do not change
ThriftProtocol: "binary",
ThriftTransport: "http",
ThriftProtocolVersion: cli_service.TProtocolVersion_SPARK_CLI_SERVICE_PROTOCOL_V7,
ThriftProtocolVersion: cli_service.TProtocolVersion_SPARK_CLI_SERVICE_PROTOCOL_V8,
ThriftDebugClientProtocol: false,
}

Expand Down
1 change: 0 additions & 1 deletion internal/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -640,7 +640,6 @@ func TestConfig_DeepCopy(t *testing.T) {
cfg := &Config{
UserConfig: UserConfig{}.WithDefaults(),
TLSConfig: &tls.Config{MinVersion: tls.VersionTLS12},
RunAsync: true,
PollInterval: 1 * time.Second,
ClientTimeout: 900 * time.Second,
PingTimeout: 15 * time.Second,
Expand Down

0 comments on commit beea4c4

Please sign in to comment.