Add uint/bool support to cratedb output (#4117)
This commit is contained in:
parent
339c5d0312
commit
b11468757c
|
@ -79,15 +79,15 @@ services:
|
||||||
- "389:389"
|
- "389:389"
|
||||||
- "636:636"
|
- "636:636"
|
||||||
crate:
|
crate:
|
||||||
image: crate/crate
|
image: crate/crate
|
||||||
ports:
|
ports:
|
||||||
- "4200:4200"
|
- "4200:4200"
|
||||||
- "4230:4230"
|
- "4230:4230"
|
||||||
command:
|
- "5432:5432"
|
||||||
- crate
|
command:
|
||||||
- -Cnetwork.host=0.0.0.0
|
- crate
|
||||||
- -Ctransport.host=localhost
|
- -Cnetwork.host=0.0.0.0
|
||||||
- -Clicense.enterprise=false
|
- -Ctransport.host=localhost
|
||||||
environment:
|
- -Clicense.enterprise=false
|
||||||
- CRATE_HEAP_SIZE=128m
|
environment:
|
||||||
- JAVA_OPTS='-Xms256m -Xmx256m'
|
- CRATE_HEAP_SIZE=128m
|
||||||
|
|
|
@ -7,6 +7,7 @@ import (
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
"fmt"
|
"fmt"
|
||||||
"sort"
|
"sort"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -16,6 +17,8 @@ import (
|
||||||
_ "github.com/jackc/pgx/stdlib"
|
_ "github.com/jackc/pgx/stdlib"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const MaxInt64 = int64(^uint64(0) >> 1)
|
||||||
|
|
||||||
type CrateDB struct {
|
type CrateDB struct {
|
||||||
URL string
|
URL string
|
||||||
Timeout internal.Duration
|
Timeout internal.Duration
|
||||||
|
@ -115,11 +118,19 @@ func escapeValue(val interface{}) (string, error) {
|
||||||
switch t := val.(type) {
|
switch t := val.(type) {
|
||||||
case string:
|
case string:
|
||||||
return escapeString(t, `'`), nil
|
return escapeString(t, `'`), nil
|
||||||
// We don't handle uint, uint32 and uint64 here because CrateDB doesn't
|
case int64, float64:
|
||||||
// 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:
|
|
||||||
return fmt.Sprint(t), nil
|
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:
|
case time.Time:
|
||||||
// see https://crate.io/docs/crate/reference/sql/data_types.html#timestamp
|
// see https://crate.io/docs/crate/reference/sql/data_types.html#timestamp
|
||||||
return escapeValue(t.Format("2006-01-02T15:04:05.999-0700"))
|
return escapeValue(t.Format("2006-01-02T15:04:05.999-0700"))
|
||||||
|
|
|
@ -111,12 +111,12 @@ func Test_escapeValue(t *testing.T) {
|
||||||
{`foo`, `'foo'`},
|
{`foo`, `'foo'`},
|
||||||
{`foo'bar 'yeah`, `'foo''bar ''yeah'`},
|
{`foo'bar 'yeah`, `'foo''bar ''yeah'`},
|
||||||
// int types
|
// int types
|
||||||
{123, `123`}, // int
|
|
||||||
{int64(123), `123`},
|
{int64(123), `123`},
|
||||||
{int32(123), `123`},
|
{uint64(123), `123`},
|
||||||
|
{uint64(MaxInt64) + 1, `9223372036854775807`},
|
||||||
|
{true, `true`},
|
||||||
|
{false, `false`},
|
||||||
// float types
|
// float types
|
||||||
{123.456, `123.456`},
|
|
||||||
{float32(123.456), `123.456`}, // floating point SNAFU
|
|
||||||
{float64(123.456), `123.456`},
|
{float64(123.456), `123.456`},
|
||||||
// time.Time
|
// time.Time
|
||||||
{time.Date(2017, 8, 7, 16, 44, 52, 123*1000*1000, time.FixedZone("Dreamland", 5400)), `'2017-08-07T16:44:52.123+0130'`},
|
{time.Date(2017, 8, 7, 16, 44, 52, 123*1000*1000, time.FixedZone("Dreamland", 5400)), `'2017-08-07T16:44:52.123+0130'`},
|
||||||
|
|
Loading…
Reference in New Issue