Skip to content

Commit

Permalink
- fix conversion in query
Browse files Browse the repository at this point in the history
  • Loading branch information
Dimitri Capitaine committed Jun 26, 2020
1 parent f1406a2 commit 3469877
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 6 deletions.
2 changes: 2 additions & 0 deletions package/deb/input-amd64
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
build/lookatch-agent=/usr/bin/
package/deb/config.json=/etc/lookatch/config.json
3 changes: 3 additions & 0 deletions package/rpm/input-amd64
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
build/lookatch-agent=/usr/bin/
package/rpm/config.json=/etc/lookatch/config.json
package/rpm/lookatch-agent.service=/etc/systemd/system/lookatch-agent.service
6 changes: 5 additions & 1 deletion sources/dbsql_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,11 @@ func (d *DBSQLQuery) ProcessLines(columns []string, lines [][]interface{}, info
for i, col := range columns {
switch vr := (*values[i].(*interface{})).(type) {
case []uint8:
colmap[col], err = strconv.ParseFloat(string(vr), 64)
if utils.IsNumDot(string(vr)) {
colmap[col], err = strconv.ParseFloat(string(vr), 64)
} else {
colmap[col], err = strconv.ParseInt(string(vr), 10, 64)
}
if err != nil {
colmap[col] = string(vr)
}
Expand Down
10 changes: 5 additions & 5 deletions sources/pg_cdc.go
Original file line number Diff line number Diff line change
Expand Up @@ -531,17 +531,17 @@ func (p *PostgreSQLCDC) GetOffsetTimeline(tli int32, lsn pglogrepl.LSN) (int32,
return 0, err
}
if len(results) != 1 {
return 0, errors.New(fmt.Sprintf("expected 1 result set, got %d", len(results)))
return 0, fmt.Errorf("expected 1 result set, got %d", len(results))
}

result := results[0]
if len(result.Rows) != 1 {
return 0, errors.New(fmt.Sprintf("expected 1 result set, got %d", len(result.Rows)))
return 0, fmt.Errorf("expected 1 result set, got %d", len(result.Rows))
}

row := result.Rows[0]
if len(row) != 2 {
return 0, errors.New(fmt.Sprintf("expected 1 result set, got %d", len(row)))
return 0, fmt.Errorf("expected 1 result set, got %d", len(row))
}

//split line
Expand All @@ -550,12 +550,12 @@ func (p *PostgreSQLCDC) GetOffsetTimeline(tli int32, lsn pglogrepl.LSN) (int32,
current := strings.Split(timeline, "\t")
tLsn, err := pglogrepl.ParseLSN(current[1])
if err != nil {
return 0, errors.New(fmt.Sprintf("expected LSN string, got %s", current[1]))
return 0, fmt.Errorf("expected LSN string, got %s", current[1])
}
if lsn <= tLsn {
currentTli, err := strconv.Atoi(current[0])
if err != nil {
return 0, errors.New(fmt.Sprintf("expected timeline, got %s", current[1]))
return 0, fmt.Errorf("expected timeline, got %s", current[1])
}
return int32(currentTli), nil
}
Expand Down
11 changes: 11 additions & 0 deletions utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,14 @@ func InSlice(slice []string, val string) bool {
}
return false
}

func IsNumDot(s string) bool {
for _, v := range s {
if v == '.' {
return true
} else if v < '0' || v > '9' {
return false
}
}
return false
}
14 changes: 14 additions & 0 deletions utils/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,17 @@ func TestInSlice2(t *testing.T) {
}

}

func TestNumDot(t *testing.T) {
StringMap := map[string]bool{
"254": false,
"32.2": true,
"for": false,
}
for k, v := range StringMap {
if v != IsNumDot(k) {
t.Fail()
}
}

}

0 comments on commit 3469877

Please sign in to comment.