Documentation
¶
Index ¶
- Constants
- Variables
- func Array(v interface{}) driver.Valuer
- func DBCallerPrettyfier(frame *runtime.Frame) (string, string)
- func Date(t time.Time) driver.Valuer
- func Decimal128(v interface{}, s int32) driver.Valuer
- func Decimal32(v interface{}, s int32) driver.Valuer
- func Decimal64(v interface{}, s int32) driver.Valuer
- func DeregisterTLSConfig(key string)
- func IP(i net.IP) driver.Valuer
- func IsAuthFailed(err error) bool
- func IsNotFound(err error) bool
- func IsProxyErr(err error) bool
- func Map(v interface{}) driver.Valuer
- func NewAPIError(hint string, status int, respBuf []byte) error
- func NewAPIHttpClientFromConfig(cfg *Config) *http.Client
- func RegisterTLSConfig(key string, config *tls.Config) error
- func SetLogger(inLogger *DBLogger)
- func Tuple(v interface{}) driver.Valuer
- func UInt64(u uint64) driver.Valuer
- type APIClient
- func (c *APIClient) CloseQuery(ctx context.Context, response *QueryResponse) error
- func (c *APIClient) GetPresignedURL(ctx context.Context, stage *StageLocation) (*PresignedResponse, error)
- func (c *APIClient) GetQueryID() string
- func (c *APIClient) InsertWithStage(ctx context.Context, sql string, stage *StageLocation, ...) (*QueryResponse, error)
- func (c *APIClient) KillQuery(ctx context.Context, response *QueryResponse) error
- func (c *APIClient) Logout(ctx context.Context) error
- func (c *APIClient) NeedKeepAlive() bool
- func (c *APIClient) NeedSticky() bool
- func (c *APIClient) NewDefaultCSVFormatOptions() map[string]string
- func (c *APIClient) NewDefaultCopyOptions() map[string]string
- func (c *APIClient) NextQuery()
- func (c *APIClient) PollQuery(ctx context.Context, nextURI string) (*QueryResponse, error)
- func (c *APIClient) PollUntilQueryEnd(ctx context.Context, resp *QueryResponse) (*QueryResponse, error)
- func (c *APIClient) QuerySync(ctx context.Context, query string, args []driver.Value) (*QueryResponse, error)
- func (c *APIClient) StartQuery(ctx context.Context, query string, args []driver.Value) (*QueryResponse, error)
- func (c *APIClient) UploadToStage(ctx context.Context, stage *StageLocation, input *bufio.Reader, size int64) error
- func (c *APIClient) UploadToStageByAPI(ctx context.Context, stage *StageLocation, input *bufio.Reader) error
- func (c *APIClient) UploadToStageByPresignURL(ctx context.Context, stage *StageLocation, input *bufio.Reader, size int64) error
- type APIError
- type APIErrorResponseBody
- type AccessTokenLoader
- type AuthMethod
- type Batch
- type ColumnType
- type ColumnTypeOptions
- type Config
- type ContextKey
- type DBLogger
- type DataField
- type DataParser
- type DataParserOptions
- type DatabendConn
- func (dc *DatabendConn) Begin() (driver.Tx, error)
- func (dc *DatabendConn) BeginTx(ctx context.Context, _ driver.TxOptions) (driver.Tx, error)
- func (dc *DatabendConn) Close() error
- func (dc *DatabendConn) ExecContext(ctx context.Context, query string, args []driver.NamedValue) (driver.Result, error)
- func (dc *DatabendConn) ExecuteBatch() (err error)
- func (dc *DatabendConn) Ping(ctx context.Context) error
- func (dc *DatabendConn) Prepare(query string) (driver.Stmt, error)
- func (dc *DatabendConn) PrepareContext(ctx context.Context, query string) (driver.Stmt, error)
- func (dc *DatabendConn) QueryContext(ctx context.Context, query string, args []driver.NamedValue) (driver.Rows, error)
- type DatabendDriver
- type FileAccessTokenData
- type FileAccessTokenLoader
- type IgnoreDomainCookieJar
- type NullableValue
- type PaginationConfig
- type PresignedResponse
- type QueryError
- type QueryIDGenerator
- type QueryProgress
- type QueryRequest
- type QueryResponse
- type QueryStats
- type QueryStatsTracker
- type RequestType
- type ServerInfo
- type SessionState
- type StageAttachmentConfig
- type StageLocation
- type StaticAccessTokenLoader
- type TxnState
- type TypeDesc
Constants ¶
const ( ContextKeyQueryID ContextKey = "X-DATABEND-QUERY-ID" ContextUserAgentID ContextKey = "USER-AGENT" EMPTY_FIELD_AS string = "empty_field_as" PURGE string = "purge" )
const ( DatabendTenantHeader = "X-DATABEND-TENANT" DatabendWarehouseHeader = "X-DATABEND-WAREHOUSE" DatabendQueryIDHeader = "X-DATABEND-QUERY-ID" DatabendRouteHintHeader = "X-DATABEND-ROUTE-HINT" DatabendQueryIDNode = "X-DATABEND-NODE-ID" DatabendQueryStickyNode = "X-DATABEND-STICKY-NODE" Authorization = "Authorization" WarehouseRoute = "X-DATABEND-ROUTE" UserAgent = "User-Agent" )
const DBSessionIDKey contextKey = "LOG_SESSION_ID"
DBSessionIDKey is context key of session id
const SFSessionUserKey contextKey = "LOG_USER"
SFSessionUserKey is context key of user id of a session
const (
SSL_MODE_DISABLE = "disable"
)
Variables ¶
var ( ProvisionWarehouseTimeout = "ProvisionWarehouseTimeout" ErrDoRequest = errors.New("DoReqeustFailed") ErrReadResponse = errors.New("ReadResponseFailed") )
var ( ErrPlaceholderCount = errors.New("databend: wrong placeholder count") ErrNoLastInsertID = errors.New("no LastInsertId available") ErrNoRowsAffected = errors.New("no RowsAffected available") )
var LogKeys = [...]contextKey{DBSessionIDKey, SFSessionUserKey}
LogKeys these keys in context should be included in logging messages when using logger.WithContext
Functions ¶
func Array ¶
Array wraps slice or array into driver.Valuer interface to allow pass through it from database/sql
func DBCallerPrettyfier ¶
DBCallerPrettyfier to provide base file name and function name from calling frame used in SFLogger
func Decimal128 ¶
Decimal128 converts value to Decimal128 of precision S. The value can be a number or a string. The S (scale) parameter specifies the number of decimal places.
func Decimal32 ¶
Decimal32 converts value to Decimal32 of precision S. The value can be a number or a string. The S (scale) parameter specifies the number of decimal places.
func Decimal64 ¶
Decimal64 converts value to Decimal64 of precision S. The value can be a number or a string. The S (scale) parameter specifies the number of decimal places.
func DeregisterTLSConfig ¶
func DeregisterTLSConfig(key string)
DeregisterTLSConfig removes the tls.Config associated with key.
func IsAuthFailed ¶
func IsNotFound ¶
func IsProxyErr ¶
func NewAPIHttpClientFromConfig ¶ added in v0.5.9
func RegisterTLSConfig ¶
RegisterTLSConfig registers a custom tls.Config to be used with sql.Open.
func SetLogger ¶
func SetLogger(inLogger *DBLogger)
SetLogger set a new logger of SFLogger interface for godatabend
Types ¶
type APIClient ¶
type APIClient struct { SessionID string QuerySeq int64 NodeID string WaitTimeSeconds int64 MaxRowsInBuffer int64 MaxRowsPerPage int64 PresignedURLDisabled bool EmptyFieldAs string // contains filtered or unexported fields }
func NewAPIClientFromConfig ¶
func (*APIClient) CloseQuery ¶ added in v0.5.9
func (c *APIClient) CloseQuery(ctx context.Context, response *QueryResponse) error
func (*APIClient) GetPresignedURL ¶
func (c *APIClient) GetPresignedURL(ctx context.Context, stage *StageLocation) (*PresignedResponse, error)
func (*APIClient) GetQueryID ¶ added in v0.5.8
func (*APIClient) InsertWithStage ¶
func (c *APIClient) InsertWithStage(ctx context.Context, sql string, stage *StageLocation, fileFormatOptions, copyOptions map[string]string) (*QueryResponse, error)
func (*APIClient) KillQuery ¶
func (c *APIClient) KillQuery(ctx context.Context, response *QueryResponse) error
func (*APIClient) NeedKeepAlive ¶ added in v0.7.2
func (*APIClient) NeedSticky ¶ added in v0.7.2
func (*APIClient) NewDefaultCSVFormatOptions ¶ added in v0.5.6
func (*APIClient) NewDefaultCopyOptions ¶ added in v0.5.4
func (*APIClient) PollUntilQueryEnd ¶ added in v0.5.9
func (c *APIClient) PollUntilQueryEnd(ctx context.Context, resp *QueryResponse) (*QueryResponse, error)
func (*APIClient) StartQuery ¶ added in v0.5.9
func (*APIClient) UploadToStage ¶
func (*APIClient) UploadToStageByAPI ¶
func (*APIClient) UploadToStageByPresignURL ¶
type APIError ¶
type APIError struct { RespBody APIErrorResponseBody RespText string StatusCode int Hint string }
type APIErrorResponseBody ¶
func RespBody ¶
func RespBody(err error) APIErrorResponseBody
type AccessTokenLoader ¶
type AccessTokenLoader interface { // LoadAccessToken is called whenever a new request is made to the server. LoadAccessToken(ctx context.Context, forceRotate bool) (string, error) }
AccessTokenLoader is used on Bearer authentication. The token may have a limited lifetime, you can rotate your token by this interface.
type AuthMethod ¶
type AuthMethod string
const ( AuthMethodUserPassword AuthMethod = "userPassword" AuthMethodAccessToken AuthMethod = "accessToken" )
type ColumnType ¶ added in v0.7.4
type ColumnType interface { Desc() *TypeDesc DatabaseTypeName() string Nullable() (bool, bool) ScanType() reflect.Type Parse(s string) (driver.Value, error) Length() (int64, bool) PrecisionScale() (int64, int64, bool) }
func NewColumnType ¶ added in v0.7.4
func NewColumnType(dbType string, opts *ColumnTypeOptions) (ColumnType, error)
type ColumnTypeOptions ¶ added in v0.7.4
type ColumnTypeOptions struct {
// contains filtered or unexported fields
}
func (*ColumnTypeOptions) SetFormatNullAsStr ¶ added in v0.7.4
func (opt *ColumnTypeOptions) SetFormatNullAsStr(v bool)
func (*ColumnTypeOptions) SetTimezone ¶ added in v0.7.4
func (opt *ColumnTypeOptions) SetTimezone(v *time.Location)
type Config ¶
type Config struct { Tenant string // Tenant Warehouse string // Warehouse User string // Username Password string // Password (requires User) Database string // Database name Role string // Role is the databend role you want to use for the current connection AccessToken string AccessTokenFile string // path to file containing access token, it can be used to rotate access token AccessTokenLoader AccessTokenLoader Host string Timeout time.Duration /* Pagination params: WaitTimeSecs, MaxRowsInBuffer, MaxRowsPerPage Pagination: critical conditions for each HTTP request to return (before all remaining result is ready to return) Related docs:https://databend.rs/doc/integrations/api/rest#query-request */ WaitTimeSecs int64 MaxRowsInBuffer int64 MaxRowsPerPage int64 Location *time.Location Debug bool GzipCompression bool Params map[string]string TLSConfig string SSLMode string // track the progress of query execution StatsTracker QueryStatsTracker // used on the storage which does not support presigned url like HDFS, local fs PresignedURLDisabled bool // Specifies the value that should be used when encountering empty fields, including both ,, and ,"",, in the CSV data being loaded into the table. // https://docs.databend.com/sql/sql-reference/file-format-options#empty_field_as // default is `string` // databend version should >= v1.2.345-nightly EmptyFieldAs string EnableOpenTelemetry bool }
Config is a set of configuration parameters
type ContextKey ¶ added in v0.5.2
type ContextKey string
type DBLogger ¶
type DBLogger interface { rlog.Ext1FieldLogger SetLogLevel(level string) error WithContext(ctx context.Context) *rlog.Entry SetOutput(output io.Writer) }
DBLogger Databend logger interface to expose FieldLogger defined in logrus
func CreateDefaultLogger ¶
func CreateDefaultLogger() DBLogger
CreateDefaultLogger return a new instance of SFLogger with default config
type DataParser ¶
type DataParser interface { Parse(io.RuneScanner) (driver.Value, error) Nullable() bool Type() reflect.Type }
DataParser implements parsing of a driver value and reporting its type.
func NewDataParser ¶
func NewDataParser(t *TypeDesc, opt *DataParserOptions) (DataParser, error)
NewDataParser creates a new DataParser based on the given TypeDesc.
type DataParserOptions ¶
type DataParserOptions struct { // Location describes default location for DateTime and Date field without Timezone argument. Location *time.Location // UseDBLocation if false: always use Location, ignore DateTime argument. UseDBLocation bool }
DataParserOptions describes DataParser options. Ex.: Fields Location and UseDBLocation specify timezone options.
type DatabendConn ¶
type DatabendConn struct {
// contains filtered or unexported fields
}
func (*DatabendConn) Close ¶
func (dc *DatabendConn) Close() error
Close invalidates and potentially stops any current prepared statements and transactions, marking this connection as no longer in use.
func (*DatabendConn) ExecContext ¶
func (dc *DatabendConn) ExecContext(ctx context.Context, query string, args []driver.NamedValue) (driver.Result, error)
func (*DatabendConn) ExecuteBatch ¶ added in v0.5.7
func (dc *DatabendConn) ExecuteBatch() (err error)
ExecuteBatch applies batch prepared statement if it exists
func (*DatabendConn) PrepareContext ¶
func (*DatabendConn) QueryContext ¶
func (dc *DatabendConn) QueryContext(ctx context.Context, query string, args []driver.NamedValue) (driver.Rows, error)
type DatabendDriver ¶
type DatabendDriver struct{}
DatabendDriver is a context of Go Driver
func (DatabendDriver) Open ¶
func (d DatabendDriver) Open(dsn string) (driver.Conn, error)
Open creates a new connection.
func (DatabendDriver) OpenConnector ¶ added in v0.7.4
func (d DatabendDriver) OpenConnector(dsn string) (driver.Connector, error)
func (DatabendDriver) OpenWithConfig ¶
OpenWithConfig creates a new connection with the given Config.
type FileAccessTokenData ¶
type FileAccessTokenData struct {
AccessToken string `toml:"access_token"`
}
type FileAccessTokenLoader ¶
type FileAccessTokenLoader struct {
// contains filtered or unexported fields
}
func NewFileAccessTokenLoader ¶
func NewFileAccessTokenLoader(path string) *FileAccessTokenLoader
func (*FileAccessTokenLoader) LoadAccessToken ¶
func (l *FileAccessTokenLoader) LoadAccessToken(ctx context.Context, forceRotate bool) (string, error)
try decode as toml, if not toml, return the plain key content
type IgnoreDomainCookieJar ¶ added in v0.7.2
type IgnoreDomainCookieJar struct {
// contains filtered or unexported fields
}
func NewIgnoreDomainCookieJar ¶ added in v0.7.2
func NewIgnoreDomainCookieJar() *IgnoreDomainCookieJar
func (*IgnoreDomainCookieJar) Cookies ¶ added in v0.7.2
func (jar *IgnoreDomainCookieJar) Cookies(u *url.URL) []*http.Cookie
func (*IgnoreDomainCookieJar) SetCookies ¶ added in v0.7.2
func (jar *IgnoreDomainCookieJar) SetCookies(_u *url.URL, cookies []*http.Cookie)
type NullableValue ¶ added in v0.7.0
type NullableValue struct {
// contains filtered or unexported fields
}
func (*NullableValue) Scan ¶ added in v0.7.0
func (nv *NullableValue) Scan(value any) error
Scan implements the [Scanner] interface.
func (NullableValue) Value ¶ added in v0.7.0
func (nv NullableValue) Value() (driver.Value, error)
Value implements the driver.Valuer interface.
type PaginationConfig ¶
type PresignedResponse ¶
type QueryError ¶
type QueryError struct { Code int `json:"code"` Message string `json:"message"` Kind string `json:"kind"` Detail string `json:"detail"` }
func (*QueryError) Error ¶
func (e *QueryError) Error() string
type QueryIDGenerator ¶
type QueryIDGenerator func() string
type QueryProgress ¶
type QueryRequest ¶
type QueryRequest struct { Session *json.RawMessage `json:"session,omitempty"` SQL string `json:"sql"` Pagination *PaginationConfig `json:"pagination,omitempty"` StageAttachment *StageAttachmentConfig `json:"stage_attachment,omitempty"` }
type QueryResponse ¶
type QueryResponse struct { ID string `json:"id"` NodeID string `json:"node_id"` Session *json.RawMessage `json:"session"` Schema *[]DataField `json:"schema"` Data [][]*string `json:"data"` State string `json:"state"` Error *QueryError `json:"error"` Stats *QueryStats `json:"stats"` // TODO: Affect rows StatsURI string `json:"stats_uri"` FinalURI string `json:"final_uri"` NextURI string `json:"next_uri"` KillURI string `json:"kill_uri"` }
func (*QueryResponse) ReadFinished ¶ added in v0.5.9
func (r *QueryResponse) ReadFinished() bool
type QueryStats ¶
type QueryStats struct { RunningTimeMS float64 `json:"running_time_ms"` ScanProgress QueryProgress `json:"scan_progress"` WriteProgress QueryProgress `json:"write_progress"` ResultProgress QueryProgress `json:"result_progress"` }
type QueryStatsTracker ¶
type QueryStatsTracker func(queryID string, stats *QueryStats)
QueryStatsTracker is a function that will be called when query stats are updated, it can be specified in the Config struct.
type RequestType ¶ added in v0.5.9
type RequestType int
const ( Query RequestType = iota Page Final Kill )
request type
type ServerInfo ¶ added in v0.5.7
type SessionState ¶
type SessionState struct { Database string `json:"database,omitempty"` Role string `json:"role,omitempty"` SecondaryRoles *[]string `json:"secondary_roles,omitempty"` Settings map[string]string `json:"settings,omitempty"` // txn TxnState TxnState `json:"txn_state,omitempty"` // "Active", "AutoCommit" NeedSticky bool `json:"need_sticky,omitempty"` NeedKeepAlive bool `json:"need_keep_alive,omitempty"` }
type StageAttachmentConfig ¶
type StageLocation ¶
func (*StageLocation) String ¶
func (sl *StageLocation) String() string
type StaticAccessTokenLoader ¶
type StaticAccessTokenLoader struct {
AccessToken string
}
func NewStaticAccessTokenLoader ¶
func NewStaticAccessTokenLoader(accessToken string) *StaticAccessTokenLoader
func (*StaticAccessTokenLoader) LoadAccessToken ¶
type TypeDesc ¶
TypeDesc describes a (possibly nested) data type returned by Databend.