Add uint/bool support to cratedb output (#4117)

This commit is contained in:
Daniel Nelson
2018-05-08 12:10:25 -07:00
committed by GitHub
parent 339c5d0312
commit b11468757c
3 changed files with 31 additions and 20 deletions

View File

@@ -7,6 +7,7 @@ import (
"encoding/binary"
"fmt"
"sort"
"strconv"
"strings"
"time"
@@ -16,6 +17,8 @@ import (
_ "github.com/jackc/pgx/stdlib"
)
const MaxInt64 = int64(^uint64(0) >> 1)
type CrateDB struct {
URL string
Timeout internal.Duration
@@ -115,11 +118,19 @@ func escapeValue(val interface{}) (string, error) {
switch t := val.(type) {
case string:
return escapeString(t, `'`), nil
// We don't handle uint, uint32 and uint64 here because CrateDB doesn't
// seem to support unsigned types. But it seems like input plugins don't
// produce those types, so it's hopefully ok.
case int, int32, int64, float32, float64:
case int64, float64:
return fmt.Sprint(t), nil
case uint64:
// The long type is the largest integer type in CrateDB and is the
// size of a signed int64. If our value is too large send the largest
// possible value.
if t <= uint64(MaxInt64) {
return strconv.FormatInt(int64(t), 10), nil
} else {
return strconv.FormatInt(MaxInt64, 10), nil
}
case bool:
return strconv.FormatBool(t), nil
case time.Time:
// see https://crate.io/docs/crate/reference/sql/data_types.html#timestamp
return escapeValue(t.Format("2006-01-02T15:04:05.999-0700"))