Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
- Fix OAuth M2M token requests hanging indefinitely when the token endpoint stops responding. Each request now uses a copy of `http.DefaultClient` with a timeout of at most 60s; `WithRetries` repeats failed fetches (databricks/databricks-sql-go#475).
- Render non-finite FLOAT / DOUBLE values inside ARRAY / MAP / STRUCT results as the JSON strings `"NaN"`, `"Infinity"`, and `"-Infinity"` on both backends instead of failing row iteration. SQL NULL remains `null`; top-level floats remain numeric (databricks/databricks-sql-go#573).
- **Behavior change:** Non-finite floating-point MAP keys use the same spellings as values on both backends. On the kernel backend, keys previously rendered as `"+Inf"` and `"-Inf"` now render as `"Infinity"` and `"-Infinity"`; `"NaN"` is unchanged. On Thrift, these keys previously failed row iteration (databricks/databricks-sql-go#573).
- Kernel HTTPS traffic negotiates HTTP/2 with HTTP/1.1 fallback. Set `WithEnableHTTP2(false)` or DSN `enableHttp2=false` to force HTTP/1.1. Configured proxies also force HTTP/1.1.
- Fix the module-root package conflict when building, linting, or running Gazelle with the `tools` build tag (databricks/databricks-sql-go#162).
- **Behavior change:** Report declared DECIMAL precision and scale through `sql.ColumnType.DecimalSize()` on Thrift and SEA, including zero-row results. Tools such as ORM migrators can now act on these qualifiers (databricks/databricks-sql-go#500).
- **Behavior change:** Support Arrow TIME results on Thrift and SEA as UTC `time.Time` values on `0001-01-01`, preserving precision and using clock-only nested JSON. TIME metadata now reports `TIME`/`time.Time` with no length, including empty and NULL-only results; previously Thrift reported `STRING`/`string` with unbounded length, and SEA reported an empty name with `*interface{}` (databricks/databricks-sql-go#505).
Expand Down
1 change: 1 addition & 0 deletions CONNECTION_PARAMETERS.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ wire. They are listed under [Kernel client-result confs](#kernel-client-result-c
| `catalog` | `WithInitialNamespace` | ✅ | ✅ | | Initial catalog. Kernel applies it post-connect via `USE CATALOG`. |
| `schema` | `WithInitialNamespace` | ✅ | ✅ | | Initial schema. Kernel applies it post-connect via `USE SCHEMA`. |
| `useKernel` | `WithUseKernel` | ✅ | ✅ | `false` | Select the SEA/kernel backend. Requires a `databricks_kernel` build. |
| `enableHttp2` | `WithEnableHTTP2(b)` | ❌ | ✅ | `true` | Negotiate HTTP/2 for session HTTPS traffic, with HTTP/1.1 fallback. `false` or an explicit/environment proxy forces HTTP/1.1, including bypassed hosts. |

## Authentication

Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ session parameter on both backends.
| `catalog` | `WithInitialNamespace` | Both | | Initial catalog. Kernel applies it post-connect via `USE CATALOG`. |
| `schema` | `WithInitialNamespace` | Both | | Initial schema. Kernel applies it post-connect via `USE SCHEMA`. |
| `useKernel` | `WithUseKernel` | Both | `false` | Select the SEA/kernel backend. Requires a `databricks_kernel` build. |
| `enableHttp2` | `WithEnableHTTP2(b)` | SEA only | `true` | Negotiate HTTP/2 for session HTTPS traffic, with HTTP/1.1 fallback. `false` or a configured proxy forces HTTP/1.1, including bypassed hosts. |

### Query execution

Expand Down
15 changes: 15 additions & 0 deletions connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,10 @@ func withUserConfig(ucfg config.UserConfig) ConnOption {
enabled := *ucfg.EnableGeoSpatialSupportDSN
kernelExperimental(c).EnableGeoSpatialSupport = &enabled
}
if ucfg.EnableHTTP2DSN != nil {
enabled := *ucfg.EnableHTTP2DSN
kernelExperimental(c).EnableHTTP2 = &enabled
}
}
}

Expand Down Expand Up @@ -711,6 +715,17 @@ func WithEnableGeoSpatialSupport(enabled bool) ConnOption {
}
}

// WithEnableHTTP2 controls HTTPS protocol negotiation on the kernel backend.
// Defaults to HTTP/2 with HTTP/1.1 fallback. False or a configured proxy forces
// HTTP/1.1 for session traffic, including destinations that bypass the proxy.
// The Thrift backend rejects this option. DSN: enableHttp2=false.
func WithEnableHTTP2(enabled bool) ConnOption {
return func(c *config.Config) {
value := enabled
kernelExperimental(c).EnableHTTP2 = &value
}
}

// WithKernelTrustedCerts adds a PEM CA-certificate bundle to the kernel's TLS
// trust store on top of the system roots — for a corporate re-signing proxy or an
// on-prem CA. Required (rather than relying on SSL_CERT_FILE) because the kernel's
Expand Down
13 changes: 13 additions & 0 deletions connector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,19 @@ func TestNewConnector(t *testing.T) {
assert.False(t, *coni.cfg.KernelExperimental.EnableGeoSpatialSupport)
})

t.Run("Connector test enableHttp2=false DSN param preserves explicit false", func(t *testing.T) {
ucfg, err := config.ParseDSN("token:supersecret@databricks-host:443/sql/1.0/endpoints/abc?enableHttp2=false")
require.NoError(t, err)
con, err := NewConnector(withUserConfig(ucfg))
require.NoError(t, err)

coni, ok := con.(*connector)
require.True(t, ok)
got := buildKernelConfig(coni.cfg, kernel.Auth{}).EnableHTTP2
require.NotNil(t, got)
assert.False(t, *got)
})

t.Run("Connector test WithTransport sets HTTPClient in CloudFetchConfig", func(t *testing.T) {
host := "databricks-host"
accessToken := "token"
Expand Down
15 changes: 15 additions & 0 deletions internal/backend/kernel/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,9 @@
if err := k.applyEnableGeoSpatialSupport(cfg); err != nil {
return err
}
if err := k.applyEnableHTTP2(cfg); err != nil {
return err
}

// Retry / backoff policy (WithRetries). See applyRetry.
if err := k.applyRetry(cfg); err != nil {
Expand Down Expand Up @@ -468,6 +471,18 @@
return nil
}

func (k *KernelBackend) applyEnableHTTP2(cfg *C.KernelSessionConfig) error {
if k.cfg.EnableHTTP2 == nil {
return nil
}
if err := call(func() C.KernelStatusCode {
return C.kernel_session_config_set_http2_enabled(cfg, C.bool(*k.cfg.EnableHTTP2))

Check failure on line 479 in internal/backend/kernel/backend.go

View workflow job for this annotation

GitHub Actions / Test (kernel backend)

could not determine what C.kernel_session_config_set_http2_enabled refers to

Check failure on line 479 in internal/backend/kernel/backend.go

View workflow job for this annotation

GitHub Actions / Test (kernel backend)

could not determine what C.kernel_session_config_set_http2_enabled refers to

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟠 High — The new cgo call uses kernel_session_config_set_http2_enabled, which this PR adds to the header by hand. go.mod still pins the bindings modules at v1.4.0 and the PR doesn't bump them or KERNEL_REV, so default kernel-tagged builds likely fail to link. Bump all seven bindings pins, update go.sum, sync KERNEL_REV, and use the published header.

🔀 Found by both reviewers · confirmed by the judge

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duplicate of the release prerequisite at #580 (comment). This PR is blocked on the kernel #483 release; the seven bindings pins, go.sum and KERNEL_REV must be updated, and the complete header copied from that revision, before merge.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still open at 1f2066d: the bindings are still pinned at v1.4.0 with no go.sum, KERNEL_REV or header sync. Keeping this open until the kernel #483 release lands.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟠 High — The new cgo call references kernel_session_config_set_http2_enabled, but go.mod and go.sum still pin all seven bindings modules at v1.4.0, and the PR doesn't bump KERNEL_REV. If v1.4.0 lacks the symbol, kernel-tagged builds fail to link. Bump the pins and checksums to the release that has the setter, and sync KERNEL_REV and the header.

🔀 Found by both reviewers · confirmed by the judge

}); err != nil {
return fmt.Errorf("kernel: set_http2_enabled: %w", toConnError(err))
}
return nil
}

// applyRetry forwards the driver's HTTP retry / backoff policy to the session
// config. A no-op when Config.Retry is nil, so the kernel's own default policy
// (exponential backoff with jitter, 5 retries, 1s..60s, 900s budget) is preserved
Expand Down
3 changes: 3 additions & 0 deletions internal/backend/kernel/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ type Config struct {
// sets this field and defaults it to false.
EnableGeoSpatialSupport bool

// EnableHTTP2 leaves the kernel default in effect when nil; false forces HTTP/1.1.
EnableHTTP2 *bool

// TokenCacheEnabled controls the kernel's on-disk OAuth U2M token-cache persistence
// (WithTokenCache / tokenCache DSN param). When false (the default), tokens are held
// in memory only; when true, the refresh token is persisted encrypted to
Expand Down
5 changes: 5 additions & 0 deletions internal/backend/kernel/include/databricks_kernel.h
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,11 @@ KernelStatusCode kernel_session_config_set_custom_header(KernelSessionConfig* co
KernelStatusCode kernel_session_config_set_sea_response_compression_enabled(
KernelSessionConfig* config, bool enabled);

/* Negotiate HTTP/2 for session HTTPS requests, with HTTP/1.1 fallback.
* Enabled by default. False or a configured proxy forces HTTP/1.1. */
KernelStatusCode kernel_session_config_set_http2_enabled(
KernelSessionConfig* config, bool enabled);

/* Configure the total timeout for one HTTP request, from connection start
* through response-body completion. A separate 30s connection timeout also
* applies, so connection establishment is bounded by the shorter limit.
Expand Down
19 changes: 19 additions & 0 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,8 @@ type KernelExperimentalConfig struct {
// struct<srid,wkb> Arrow value; false requests WKT / EWKT strings. A pointer
// distinguishes the omitted value (default false) from an explicit setting.
EnableGeoSpatialSupport *bool
// EnableHTTP2 is nil when the kernel owns the HTTPS protocol default.
EnableHTTP2 *bool
}

// DeepCopy returns a deep copy of the experimental config, or nil for a nil
Expand All @@ -169,6 +171,10 @@ func (k *KernelExperimentalConfig) DeepCopy() *KernelExperimentalConfig {
enabled := *k.EnableGeoSpatialSupport
cp.EnableGeoSpatialSupport = &enabled
}
if k.EnableHTTP2 != nil {
enabled := *k.EnableHTTP2
cp.EnableHTTP2 = &enabled
}
if k.MaxConnections != nil {
max := *k.MaxConnections
cp.MaxConnections = &max
Expand Down Expand Up @@ -317,6 +323,8 @@ type UserConfig struct {
// enableGeoSpatialSupport=true|false. Nil means omitted (the default is
// false); the connector copies a present value into KernelExperimental.
EnableGeoSpatialSupportDSN *bool
// EnableHTTP2DSN carries an explicit enableHttp2 DSN setting to the connector.
EnableHTTP2DSN *bool
}

// DeepCopy returns a true deep copy of UserConfig
Expand Down Expand Up @@ -371,6 +379,10 @@ func (ucfg UserConfig) DeepCopy() UserConfig {
enabled := *ucfg.EnableGeoSpatialSupportDSN
result.EnableGeoSpatialSupportDSN = &enabled
}
if ucfg.EnableHTTP2DSN != nil {
enabled := *ucfg.EnableHTTP2DSN
result.EnableHTTP2DSN = &enabled
}
return result
}

Expand Down Expand Up @@ -556,6 +568,13 @@ func ParseDSN(dsn string) (UserConfig, error) {
ucfg.EnableGeoSpatialSupportDSN = &enableGeoSpatialSupport
}

if enabled, ok, err := params.extractAsBool("enableHttp2"); ok {
if err != nil {
return UserConfig{}, err
}
ucfg.EnableHTTP2DSN = &enabled
}

// Telemetry parameters
if enableTelemetry, ok, err := params.extractAsBool("enableTelemetry"); ok {
if err != nil {
Expand Down
33 changes: 33 additions & 0 deletions internal/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -730,6 +730,39 @@ func TestParseDSNEnableGeoSpatialSupport(t *testing.T) {
}
}

func TestParseDSNEnableHTTP2(t *testing.T) {
base := "token:supersecret@example.cloud.databricks.com:443/sql/1.0/endpoints/abc"
for _, tc := range []struct {
name string
query string
want *bool
}{
{name: "omitted", query: "", want: nil},
{name: "enabled", query: "?enableHttp2=true", want: func() *bool { v := true; return &v }()},
{name: "disabled", query: "?enableHttp2=false", want: func() *bool { v := false; return &v }()},
} {
t.Run(tc.name, func(t *testing.T) {
got, err := ParseDSN(base + tc.query)
if err != nil {
t.Fatal(err)
}
if tc.want == nil {
if got.EnableHTTP2DSN != nil {
t.Errorf("EnableHTTP2DSN = %v, want nil", *got.EnableHTTP2DSN)
}
return
}
if got.EnableHTTP2DSN == nil || *got.EnableHTTP2DSN != *tc.want {
t.Errorf("EnableHTTP2DSN = %v, want %v", got.EnableHTTP2DSN, *tc.want)
}
})
}

if _, err := ParseDSN(base + "?enableHttp2=invalid"); err == nil {
t.Error("malformed enableHttp2 should fail DSN parsing")
}
}

func TestParseDSNQueryTimeoutRange(t *testing.T) {
if strconv.IntSize < 64 {
t.Skip("strconv.Atoi rejects these values before the range check on 32-bit platforms")
Expand Down
1 change: 1 addition & 0 deletions kernel_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ func buildKernelConfig(cfg *config.Config, kauth kernel.Auth) kernel.Config {
if ke.EnableGeoSpatialSupport != nil {
kc.EnableGeoSpatialSupport = *ke.EnableGeoSpatialSupport
}
kc.EnableHTTP2 = ke.EnableHTTP2
// U2M token-cache control (WithTokenCache / tokenCache DSN param): forward to kernel.
kc.TokenCacheEnabled = ke.TokenCacheEnabled
}
Expand Down
1 change: 1 addition & 0 deletions kernel_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,7 @@ var kernelConfigFieldDisposition = map[string]string{
"UseArrowNativeDecimalDSN": "inert", // DSN carrier; kernel renders decimals exactly regardless
"TokenCacheEnabledDSN": "inert", // DSN carrier; forwarded to KernelExperimental.TokenCacheEnabled
"EnableGeoSpatialSupportDSN": "inert", // DSN carrier; forwarded to KernelExperimental.EnableGeoSpatialSupport
"EnableHTTP2DSN": "inert", // DSN carrier; forwarded to KernelExperimental.EnableHTTP2

// Fields promoted from the embedded CloudFetchConfig. The kernel does
// CloudFetch internally (below the C ABI); each option is
Expand Down
16 changes: 16 additions & 0 deletions kernel_experimental_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
// deliberate decision and a setter in KernelBackend.OpenSession so it can't be
// silently dropped.
var kernelExperimentalFieldDisposition = map[string]string{
"EnableHTTP2": "forwarded", // set_http2_enabled
"TLSTrustedCertsPEM": "forwarded", // set_tls_trusted_certs
"TLSClientCertPEM": "forwarded", // set_tls_client_certificate (cert)
"TLSClientKeyPEM": "forwarded", // set_tls_client_certificate (key)
Expand Down Expand Up @@ -104,6 +105,9 @@ func TestWithKernelTLSOptionsSetExperimental(t *testing.T) {
{"disable geospatial support", WithEnableGeoSpatialSupport(false), func(k *config.KernelExperimentalConfig) bool {
return k.EnableGeoSpatialSupport != nil && !*k.EnableGeoSpatialSupport
}},
{"force HTTP/1.1", WithEnableHTTP2(false), func(k *config.KernelExperimentalConfig) bool {
return k.EnableHTTP2 != nil && !*k.EnableHTTP2
}},
{"token cache", WithTokenCache(true), func(k *config.KernelExperimentalConfig) bool {
return k.TokenCacheEnabled
}},
Expand Down Expand Up @@ -143,6 +147,7 @@ func TestWithKernelOptionsRejectedOnThriftPath(t *testing.T) {
{"max chunks in memory", WithKernelMaxChunksInMemory(4)},
{"decimal as float", WithKernelDecimalAsFloat(true)},
{"disable geospatial support", WithEnableGeoSpatialSupport(false)},
{"force HTTP/1.1", WithEnableHTTP2(false)},
{"token cache", WithTokenCache(true)},
}
for _, tc := range cases {
Expand Down Expand Up @@ -180,6 +185,8 @@ func TestWithKernelOptionsRejectedOnThriftPath(t *testing.T) {
for _, dsn := range []string{
"token:supersecret@example.cloud.databricks.com:443/sql/1.0/endpoints/12346a5b5b0e123a?enableGeoSpatialSupport=true",
"token:supersecret@example.cloud.databricks.com:443/sql/1.0/endpoints/12346a5b5b0e123a?enableGeoSpatialSupport=false",
"token:supersecret@example.cloud.databricks.com:443/sql/1.0/endpoints/12346a5b5b0e123a?enableHttp2=true",
"token:supersecret@example.cloud.databricks.com:443/sql/1.0/endpoints/12346a5b5b0e123a?enableHttp2=false",
} {
ucfg, err := config.ParseDSN(dsn)
if err != nil {
Expand Down Expand Up @@ -242,6 +249,7 @@ func TestWithKernelClientCertificateCopiesPEM(t *testing.T) {
func TestKernelExperimentalDeepCopy(t *testing.T) {
maxConnections := 37
enableGeoSpatialSupport := false
enableHTTP2 := false
orig := &config.KernelExperimentalConfig{
TLSTrustedCertsPEM: []byte("ca-bundle"),
TLSClientCertPEM: []byte("client-cert"),
Expand All @@ -256,6 +264,7 @@ func TestKernelExperimentalDeepCopy(t *testing.T) {
MaxConnections: &maxConnections,
MaxChunksInMemory: 4,
EnableGeoSpatialSupport: &enableGeoSpatialSupport,
EnableHTTP2: &enableHTTP2,
TokenCacheEnabled: true,
}
cp := orig.DeepCopy()
Expand All @@ -282,6 +291,13 @@ func TestKernelExperimentalDeepCopy(t *testing.T) {
} else if cp.EnableGeoSpatialSupport == orig.EnableGeoSpatialSupport {
t.Error("DeepCopy aliased EnableGeoSpatialSupport pointer")
}
if cp.EnableHTTP2 == nil || *cp.EnableHTTP2 {
t.Fatalf("DeepCopy lost EnableHTTP2: %v", cp.EnableHTTP2)
}
*cp.EnableHTTP2 = true
if *orig.EnableHTTP2 {
t.Error("DeepCopy aliased EnableHTTP2 pointer")
}
if !cp.TokenCacheEnabled {
t.Errorf("DeepCopy lost TokenCacheEnabled: %v", cp.TokenCacheEnabled)
}
Expand Down
74 changes: 74 additions & 0 deletions kernel_http2_transport_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
//go:build cgo && databricks_kernel

package dbsql

import (
"context"
"encoding/pem"
"net/http"
"net/http/httptest"
"os"
"testing"
"time"
)

func TestKernelHTTP2Transport(t *testing.T) {
for _, name := range []string{"HTTP_PROXY", "http_proxy", "HTTPS_PROXY", "https_proxy", "ALL_PROXY", "all_proxy"} {
if os.Getenv(name) != "" {
t.Skipf("unset %s to test direct HTTP/2 negotiation", name)
}
}
cases := []struct {
name string
options []ConnOption
wantVersion int
}{
{name: "default", wantVersion: 2},
{name: "opt_out", options: []ConnOption{WithEnableHTTP2(false)}, wantVersion: 1},
}
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
versions := make(chan int, 4)
server := httptest.NewUnstartedServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
versions <- r.ProtoMajor
w.Header().Set("Content-Type", "application/json")
_, _ = w.Write([]byte(`{"session_id":"http2-test"}`))
}))
server.EnableHTTP2 = true
server.StartTLS()
defer server.Close()
ca := pem.EncodeToMemory(&pem.Block{Type: "CERTIFICATE", Bytes: server.Certificate().Raw})
options := []ConnOption{
WithServerHostname(server.URL),
WithHTTPPath("/sql/1.0/warehouses/test"),
WithAccessToken("test-token"),
WithUseKernel(true),
WithKernelTrustedCerts(ca),
WithRetries(-1, 0, 0),
}
connector, err := NewConnector(append(options, tc.options...)...)
if err != nil {
t.Fatal(err)
}
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
connection, err := connector.Connect(ctx)
if err != nil {
t.Fatal(err)
}
if err := connection.Close(); err != nil {
t.Fatal(err)
}
for range 2 {
select {
case got := <-versions:
if got != tc.wantVersion {
t.Fatalf("HTTP/%d received, want HTTP/%d", got, tc.wantVersion)
}
case <-ctx.Done():
t.Fatal(ctx.Err())
}
}
})
}
}
Loading