From efd08b8c714973ef9142e56f1776d2b93284bb2c Mon Sep 17 00:00:00 2001 From: Islam Shehata Date: Thu, 15 Aug 2024 13:20:20 +0300 Subject: [PATCH] tabular: conform to DB type fields --- axiom/datasets_test.go | 4 +-- axiom/query/field.go | 54 ++++++++++++++++++--------------------- axiom/query/field_test.go | 18 ++++++++----- 3 files changed, 39 insertions(+), 37 deletions(-) diff --git a/axiom/datasets_test.go b/axiom/datasets_test.go index 287a2df..cd7a775 100644 --- a/axiom/datasets_test.go +++ b/axiom/datasets_test.go @@ -214,7 +214,7 @@ var ( }, { Name: "bytes", - Type: query.TypeReal, + Type: query.TypeFloat, }, { Name: "referrer", @@ -234,7 +234,7 @@ var ( }, { Name: "response", - Type: query.TypeReal, + Type: query.TypeFloat, }, { Name: "time", diff --git a/axiom/query/field.go b/axiom/query/field.go index 997b698..447a984 100644 --- a/axiom/query/field.go +++ b/axiom/query/field.go @@ -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 ) @@ -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: @@ -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" } diff --git a/axiom/query/field_test.go b/axiom/query/field_test.go index c05f8ab..fd349cc 100644 --- a/axiom/query/field_test.go +++ b/axiom/query/field_test.go @@ -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) {