Skip to content

Commit

Permalink
tabular: conform to DB type fields
Browse files Browse the repository at this point in the history
  • Loading branch information
dasfmi authored and lukasmalkmus committed Sep 17, 2024
1 parent 7b63da4 commit efd08b8
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 37 deletions.
4 changes: 2 additions & 2 deletions axiom/datasets_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ var (
},
{
Name: "bytes",
Type: query.TypeReal,
Type: query.TypeFloat,
},
{
Name: "referrer",
Expand All @@ -234,7 +234,7 @@ var (
},
{
Name: "response",
Type: query.TypeReal,
Type: query.TypeFloat,
},
{
Name: "time",
Expand Down
54 changes: 25 additions & 29 deletions axiom/query/field.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,19 @@ import (
// A FieldType describes the type of a [Field].
type FieldType uint16

// All available [Field] types.
// All available [Field] types. Conforms to DB Types
const (
TypeInvalid FieldType = 0 // invalid
TypeBool FieldType = 1 << iota // bool
TypeDateTime // datetime
TypeInt // int
TypeLong // long
TypeReal // real
TypeString // string
TypeTimespan // timespan
TypeArray // array
TypeDictionary // dictionary
TypeUnknown // unknown
TypeInvalid FieldType = 0 // invalid
TypeUnknown FieldType = 1 << iota // unknown
TypeInteger // integer
TypeString // string
TypeBool // boolean
TypeDateTime // datetime
TypeFloat // float
TypeTimespan // timespan
TypeMap // map
TypeArray // array

maxFieldType
)

Expand All @@ -36,20 +36,18 @@ func fieldTypeFromString(s string) (ft FieldType, err error) {
ft |= TypeBool
case TypeDateTime.String(), "date":
ft |= TypeDateTime
case TypeInt.String(), "integer": // "integer" is not documented.
ft |= TypeInt
case TypeLong.String():
ft |= TypeLong
case TypeReal.String(), "double", "float", "float64": // "float" and "float64" are not documented.
ft |= TypeReal
case TypeInteger.String(), "int":
ft |= TypeInteger
case TypeFloat.String(), "double", "float", "float64": // "float" and "float64" are not documented.
ft |= TypeFloat
case TypeString.String():
ft |= TypeString
case TypeTimespan.String(), "time":
ft |= TypeTimespan
case TypeArray.String():
ft |= TypeArray
case TypeDictionary.String():
ft |= TypeDictionary
case TypeMap.String():
ft |= TypeMap
case TypeUnknown.String():
ft |= TypeUnknown
default:
Expand All @@ -72,23 +70,21 @@ func (ft FieldType) String() string {
// handled above.
switch ft {
case TypeBool:
return "bool"
return "boolean"
case TypeDateTime:
return "datetime"
case TypeInt:
return "int"
case TypeLong:
return "long"
case TypeReal:
return "real"
case TypeInteger:
return "integer"
case TypeFloat:
return "float"
case TypeString:
return "string"
case TypeTimespan:
return "timespan"
case TypeArray:
return "array"
case TypeDictionary:
return "dictionary"
case TypeMap:
return "map"
case TypeUnknown:
return "unknown"
}
Expand Down
18 changes: 12 additions & 6 deletions axiom/query/field_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,26 @@ func TestFieldType_Unmarshal(t *testing.T) {
var act struct {
Type FieldType `json:"type"`
}
err := json.Unmarshal([]byte(`{ "type": "int|real" }`), &act)
err := json.Unmarshal([]byte(`{ "type": "int|string" }`), &act)
require.NoError(t, err)

assert.Equal(t, TypeInt|TypeReal, act.Type)
assert.Equal(t, TypeInteger|TypeString, act.Type)
}

func TestFieldType_String(t *testing.T) {
assert.Equal(t, TypeInvalid, FieldType(0))

typ := TypeInt
assert.Equal(t, "int", typ.String())
typ := TypeDateTime
assert.Equal(t, "datetime", typ.String())

typ |= TypeReal
assert.Equal(t, "int|real", typ.String())
typ |= TypeTimespan
assert.Equal(t, "datetime|timespan", typ.String())
}

func TestFieldType_Bool(t *testing.T) {
assert.Equal(t, TypeInvalid, FieldType(0))

assert.Equal(t, "boolean", TypeBool.String())
}

func TestFieldTypeFromString(t *testing.T) {
Expand Down

0 comments on commit efd08b8

Please sign in to comment.