Merge pull request #8837 from influxdata/js-unsigned-type-data-type
Unsigned data type parsing and prioritizationpull/8843/head
commit
6e636264f2
|
@ -72,6 +72,8 @@ func InspectDataType(v interface{}) DataType {
|
|||
return String
|
||||
case bool:
|
||||
return Boolean
|
||||
case uint64:
|
||||
return Unsigned
|
||||
case time.Time:
|
||||
return Time
|
||||
case time.Duration:
|
||||
|
@ -88,7 +90,14 @@ func InspectDataType(v interface{}) DataType {
|
|||
// integers used decrease with higher precedence, but Unknown is the lowest
|
||||
// precedence at the zero value.
|
||||
func (d DataType) LessThan(other DataType) bool {
|
||||
return d == Unknown || (other != Unknown && other < d)
|
||||
if d == Unknown {
|
||||
return true
|
||||
} else if d == Unsigned {
|
||||
return other != Unknown && other <= Integer
|
||||
} else if other == Unsigned {
|
||||
return d >= String
|
||||
}
|
||||
return other != Unknown && other < d
|
||||
}
|
||||
|
||||
// String returns the human-readable string representation of the DataType.
|
||||
|
@ -98,6 +107,8 @@ func (d DataType) String() string {
|
|||
return "float"
|
||||
case Integer:
|
||||
return "integer"
|
||||
case Unsigned:
|
||||
return "unsigned"
|
||||
case String:
|
||||
return "string"
|
||||
case Boolean:
|
||||
|
@ -4124,7 +4135,7 @@ func FieldDimensions(sources Sources, m FieldMapper) (fields map[string]DataType
|
|||
}
|
||||
|
||||
for k, typ := range f {
|
||||
if _, ok := fields[k]; typ != Unknown && (!ok || typ < fields[k]) {
|
||||
if fields[k].LessThan(typ) {
|
||||
fields[k] = typ
|
||||
}
|
||||
}
|
||||
|
@ -4136,7 +4147,7 @@ func FieldDimensions(sources Sources, m FieldMapper) (fields map[string]DataType
|
|||
k := f.Name()
|
||||
typ := EvalType(f.Expr, src.Statement.Sources, m)
|
||||
|
||||
if _, ok := fields[k]; typ != Unknown && (!ok || typ < fields[k]) {
|
||||
if fields[k].LessThan(typ) {
|
||||
fields[k] = typ
|
||||
}
|
||||
}
|
||||
|
|
|
@ -71,36 +71,49 @@ func TestDataType_LessThan(t *testing.T) {
|
|||
{typ: influxql.Unknown, other: influxql.Unknown, exp: true},
|
||||
{typ: influxql.Unknown, other: influxql.Float, exp: true},
|
||||
{typ: influxql.Unknown, other: influxql.Integer, exp: true},
|
||||
{typ: influxql.Unknown, other: influxql.Unsigned, exp: true},
|
||||
{typ: influxql.Unknown, other: influxql.String, exp: true},
|
||||
{typ: influxql.Unknown, other: influxql.Boolean, exp: true},
|
||||
{typ: influxql.Unknown, other: influxql.Tag, exp: true},
|
||||
{typ: influxql.Float, other: influxql.Unknown, exp: false},
|
||||
{typ: influxql.Integer, other: influxql.Unknown, exp: false},
|
||||
{typ: influxql.Unsigned, other: influxql.Unknown, exp: false},
|
||||
{typ: influxql.String, other: influxql.Unknown, exp: false},
|
||||
{typ: influxql.Boolean, other: influxql.Unknown, exp: false},
|
||||
{typ: influxql.Tag, other: influxql.Unknown, exp: false},
|
||||
{typ: influxql.Float, other: influxql.Float, exp: false},
|
||||
{typ: influxql.Float, other: influxql.Integer, exp: false},
|
||||
{typ: influxql.Float, other: influxql.Unsigned, exp: false},
|
||||
{typ: influxql.Float, other: influxql.String, exp: false},
|
||||
{typ: influxql.Float, other: influxql.Boolean, exp: false},
|
||||
{typ: influxql.Float, other: influxql.Tag, exp: false},
|
||||
{typ: influxql.Integer, other: influxql.Float, exp: true},
|
||||
{typ: influxql.Integer, other: influxql.Integer, exp: false},
|
||||
{typ: influxql.Integer, other: influxql.Unsigned, exp: false},
|
||||
{typ: influxql.Integer, other: influxql.String, exp: false},
|
||||
{typ: influxql.Integer, other: influxql.Boolean, exp: false},
|
||||
{typ: influxql.Integer, other: influxql.Tag, exp: false},
|
||||
{typ: influxql.Unsigned, other: influxql.Float, exp: true},
|
||||
{typ: influxql.Unsigned, other: influxql.Integer, exp: true},
|
||||
{typ: influxql.Unsigned, other: influxql.Unsigned, exp: false},
|
||||
{typ: influxql.Unsigned, other: influxql.String, exp: false},
|
||||
{typ: influxql.Unsigned, other: influxql.Boolean, exp: false},
|
||||
{typ: influxql.Unsigned, other: influxql.Tag, exp: false},
|
||||
{typ: influxql.String, other: influxql.Float, exp: true},
|
||||
{typ: influxql.String, other: influxql.Integer, exp: true},
|
||||
{typ: influxql.String, other: influxql.Unsigned, exp: true},
|
||||
{typ: influxql.String, other: influxql.String, exp: false},
|
||||
{typ: influxql.String, other: influxql.Boolean, exp: false},
|
||||
{typ: influxql.String, other: influxql.Tag, exp: false},
|
||||
{typ: influxql.Boolean, other: influxql.Float, exp: true},
|
||||
{typ: influxql.Boolean, other: influxql.Integer, exp: true},
|
||||
{typ: influxql.Boolean, other: influxql.Unsigned, exp: true},
|
||||
{typ: influxql.Boolean, other: influxql.String, exp: true},
|
||||
{typ: influxql.Boolean, other: influxql.Boolean, exp: false},
|
||||
{typ: influxql.Boolean, other: influxql.Tag, exp: false},
|
||||
{typ: influxql.Tag, other: influxql.Float, exp: true},
|
||||
{typ: influxql.Tag, other: influxql.Integer, exp: true},
|
||||
{typ: influxql.Tag, other: influxql.Unsigned, exp: true},
|
||||
{typ: influxql.Tag, other: influxql.String, exp: true},
|
||||
{typ: influxql.Tag, other: influxql.Boolean, exp: true},
|
||||
{typ: influxql.Tag, other: influxql.Tag, exp: false},
|
||||
|
|
|
@ -2462,12 +2462,14 @@ func (p *Parser) ParseVarRef() (*VarRef, error) {
|
|||
dtype = Float
|
||||
case "integer":
|
||||
dtype = Integer
|
||||
case "unsigned":
|
||||
dtype = Unsigned
|
||||
case "string":
|
||||
dtype = String
|
||||
case "boolean":
|
||||
dtype = Boolean
|
||||
default:
|
||||
return nil, newParseError(tokstr(tok, lit), []string{"float", "integer", "string", "boolean", "field", "tag"}, pos)
|
||||
return nil, newParseError(tokstr(tok, lit), []string{"float", "integer", "unsigned", "string", "boolean", "field", "tag"}, pos)
|
||||
}
|
||||
case FIELD:
|
||||
dtype = AnyField
|
||||
|
|
|
@ -1112,7 +1112,7 @@ func TestParser_ParseStatement(t *testing.T) {
|
|||
|
||||
// SELECT casts
|
||||
{
|
||||
s: `SELECT field1::float, field2::integer, field3::string, field4::boolean, field5::field, tag1::tag FROM cpu`,
|
||||
s: `SELECT field1::float, field2::integer, field6::unsigned, field3::string, field4::boolean, field5::field, tag1::tag FROM cpu`,
|
||||
stmt: &influxql.SelectStatement{
|
||||
IsRawQuery: true,
|
||||
Fields: []*influxql.Field{
|
||||
|
@ -1128,6 +1128,12 @@ func TestParser_ParseStatement(t *testing.T) {
|
|||
Type: influxql.Integer,
|
||||
},
|
||||
},
|
||||
{
|
||||
Expr: &influxql.VarRef{
|
||||
Val: "field6",
|
||||
Type: influxql.Unsigned,
|
||||
},
|
||||
},
|
||||
{
|
||||
Expr: &influxql.VarRef{
|
||||
Val: "field3",
|
||||
|
|
|
@ -822,7 +822,7 @@ func (s *Shard) FieldDimensions(measurements []string) (fields map[string]influx
|
|||
|
||||
if len(keys) > 0 {
|
||||
for _, k := range keys {
|
||||
if _, ok := fields[k]; !ok || influxql.String < fields[k] {
|
||||
if fields[k].LessThan(influxql.String) {
|
||||
fields[k] = influxql.String
|
||||
}
|
||||
}
|
||||
|
@ -842,7 +842,7 @@ func (s *Shard) FieldDimensions(measurements []string) (fields map[string]influx
|
|||
mf := s.engine.MeasurementFields([]byte(name))
|
||||
if mf != nil {
|
||||
for k, typ := range mf.FieldSet() {
|
||||
if _, ok := fields[k]; !ok || typ < fields[k] {
|
||||
if fields[k].LessThan(typ) {
|
||||
fields[k] = typ
|
||||
}
|
||||
}
|
||||
|
@ -1080,7 +1080,7 @@ func (a Shards) FieldDimensions(measurements []string) (fields map[string]influx
|
|||
return nil, nil, err
|
||||
}
|
||||
for k, typ := range f {
|
||||
if _, ok := fields[k]; typ != influxql.Unknown && (!ok || typ < fields[k]) {
|
||||
if fields[k].LessThan(typ) {
|
||||
fields[k] = typ
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue