jasonlin45 commented on code in PR #3325: URL: https://github.com/apache/arrow-adbc/pull/3325#discussion_r2449219645
########## go/adbc/driver/databricks/database.go: ########## @@ -0,0 +1,407 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package databricks + +import ( + "context" + "database/sql" + "errors" + "fmt" + "strconv" + "strings" + "time" + + "crypto/tls" + "crypto/x509" + "net/http" + "os" + + "github.com/apache/arrow-adbc/go/adbc" + "github.com/apache/arrow-adbc/go/adbc/driver/internal/driverbase" + dbsql "github.com/databricks/databricks-sql-go" +) + +const DEFAULT_PORT = 443 +const DEFAULT_RETRY_WAIT_MIN = 1 * time.Second +const DEFAULT_RETRY_WAIT_MAX = 30 * time.Second + +type databaseImpl struct { + driverbase.DatabaseImplBase + + // Connection Pool + db *sql.DB + needsRefresh bool // Whether we need to re-initialize + + // Connection parameters + serverHostname string + httpPath string + accessToken string + port string + catalog string + schema string + + // Query options + queryTimeout time.Duration + maxRows int + queryRetryCount int + downloadThreadCount int + + // TLS/SSL options + sslMode string + sslRootCert string + + // OAuth options (for future expansion) + oauthClientID string + oauthClientSecret string + oauthRefreshToken string +} + +func (d *databaseImpl) resolveConnectionOptions() ([]dbsql.ConnOption, error) { + if d.serverHostname == "" { + return nil, adbc.Error{ + Code: adbc.StatusInvalidArgument, + Msg: "server hostname is required", + } + } + + if d.httpPath == "" { + return nil, adbc.Error{ + Code: adbc.StatusInvalidArgument, + Msg: "HTTP path is required", + } + } + + // FIXME: Support other auth methods + if d.accessToken == "" { + return nil, adbc.Error{ + Code: adbc.StatusInvalidArgument, + Msg: "access token is required", + } + } + + opts := []dbsql.ConnOption{ + dbsql.WithAccessToken(d.accessToken), + dbsql.WithServerHostname(d.serverHostname), + dbsql.WithHTTPPath(d.httpPath), + } + + // Validate and set custom port + // Defaults to 443 + if d.port != "" { + port, err := strconv.Atoi(d.port) + if err != nil || port < 1 || port > 65535 { + return nil, adbc.Error{ + Code: adbc.StatusInvalidArgument, + Msg: "invalid port number", + } + } + opts = append(opts, dbsql.WithPort(port)) + } else { + opts = append(opts, dbsql.WithPort(DEFAULT_PORT)) + } Review Comment: Stored as int, and moved conversion in [3f29df5](https://github.com/apache/arrow-adbc/pull/3325/commits/3f29df541207ff3497f85ba4bf354836281d623f) -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
