Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support user specified batch in DSN #59

Merged
merged 5 commits into from
Oct 9, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
support user define batch size
  • Loading branch information
weiguoz committed Sep 29, 2019
commit 4dbf9c691cf1629583465a4b87c0afc4b18fabd7
4 changes: 1 addition & 3 deletions driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import (
hiveserver2 "sqlflow.org/gohive/hiveserver2/gen-go/tcliservice"
)

const DEFAULT_BATCH_SIZE = 10000

type drv struct{}

func (d drv) Open(dsn string) (driver.Conn, error) {
Expand Down Expand Up @@ -66,7 +64,7 @@ func (d drv) Open(dsn string) (driver.Conn, error) {
return nil, err
}

options := hiveOptions{PollIntervalSeconds: 5, BatchSize: DEFAULT_BATCH_SIZE}
options := hiveOptions{PollIntervalSeconds: 5, BatchSize: int64(cfg.Batch)}
conn := &hiveConnection{
thrift: client,
session: session.SessionHandle,
Expand Down
23 changes: 20 additions & 3 deletions dsn.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"net/url"
"regexp"
"strconv"
"strings"
)

Expand All @@ -13,6 +14,7 @@ type Config struct {
Addr string
DBName string
Auth string
Batch int
SessionCfg map[string]string
}

Expand All @@ -22,7 +24,13 @@ var (
reUserPasswd = regexp.MustCompile(`([^:@]+)(:[^:@]+)?@`)
)

const sessionConfPrefix = "session."
const (
sessionConfPrefix = "session."
authConfName = "auth"
defaultAuth = "NOSASL"
batchSizeName = "batch"
defaultBatchSize = 10000
)

// ParseDSN requires DSN names in the format [user[:password]@]addr/dbname.
func ParseDSN(dsn string) (*Config, error) {
Expand Down Expand Up @@ -50,13 +58,21 @@ func ParseDSN(dsn string) (*Config, error) {
}
}

auth := "NOSASL"
auth := defaultAuth
batch := defaultBatchSize
sc := make(map[string]string)
if len(sub[3]) > 0 && sub[3][0] == '?' {
qry, _ := url.ParseQuery(sub[3][1:])
if v, found := qry["auth"]; found {
if v, found := qry[authConfName]; found {
auth = v[0]
} else if v, found := qry[batchSizeName]; found {
bch, err := strconv.Atoi(v[0])
if err != nil {
return nil, err
}
batch = bch
}

for k, v := range qry {
if strings.HasPrefix(k, sessionConfPrefix) {
sc[k[len(sessionConfPrefix):]] = v[0]
Expand All @@ -70,6 +86,7 @@ func ParseDSN(dsn string) (*Config, error) {
Addr: addr,
DBName: dbname,
Auth: auth,
Batch: batch,
SessionCfg: sc,
}, nil
}
Expand Down