Skip to content

Commit

Permalink
add debug to clickhouse dsn
Browse files Browse the repository at this point in the history
  • Loading branch information
childe committed Feb 22, 2021
1 parent 036899c commit daf6e62
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions output/clickhouse_output.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,11 @@ func newClickhouseOutput(config map[interface{}]interface{}) topology.Output {
p.password = v.(string)
}

debug := false
if v, ok := config["debug"]; ok {
debug = v.(bool)
}

if v, ok := config["fields"]; ok {
for _, f := range v.([]interface{}) {
p.fields = append(p.fields, f.(string))
Expand All @@ -276,7 +281,7 @@ func newClickhouseOutput(config map[interface{}]interface{}) topology.Output {
p.fieldsLength = len(p.fields)

fields := make([]string, p.fieldsLength)
for i, _ := range fields {
for i := range fields {
fields[i] = fmt.Sprintf(`"%s"`, p.fields[i])
}
questionMarks := make([]string, p.fieldsLength)
Expand All @@ -294,7 +299,7 @@ func newClickhouseOutput(config map[interface{}]interface{}) topology.Output {
dbs := make([]*sql.DB, 0)

for _, host := range p.hosts {
dataSourceName := fmt.Sprintf("%s?database=%s&username=%s&password=%s", host, p.getDatabase(), p.username, p.password)
dataSourceName := fmt.Sprintf("%s?database=%s&username=%s&password=%s&debug=%v", host, p.getDatabase(), p.username, p.password, debug)
if db, err := sql.Open("clickhouse", dataSourceName); err == nil {
if err := db.Ping(); err != nil {
if exception, ok := err.(*clickhouse.Exception); ok {
Expand Down

0 comments on commit daf6e62

Please sign in to comment.