Skip to content

Commit

Permalink
support time.Time as well as int32 timestamp for timestamp,time & dat…
Browse files Browse the repository at this point in the history
…e logical types
  • Loading branch information
khezen committed Jul 16, 2020
1 parent 8fb48a1 commit 9599c3d
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions sqlavro/criterion.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,8 @@ func rawLimit2Native(schema avro.Schema, limit interface{}) (json.RawMessage, er
case avro.TypeString:
rawLimit = json.RawMessage(fmt.Sprintf(`"%s"`, limit.(string)))
return rawLimit, nil
case avro.Type(avro.LogicalTypeTimestamp):
case avro.Type(avro.LogicalTypeTimestamp),
avro.Type(avro.LogicalTypeTime):
var t time.Time
var ok bool
if t, ok = limit.(time.Time); !ok {
Expand All @@ -191,16 +192,12 @@ func rawLimit2Native(schema avro.Schema, limit interface{}) (json.RawMessage, er
rawLimit = json.RawMessage(fmt.Sprintf(`"%s"`, t.Format(time.RFC3339Nano)))
return rawLimit, nil
case avro.Type(avro.LogicalTypeDate):
t := limit.(time.Time)
rawLimit = json.RawMessage(fmt.Sprintf(`"%s"`, t.Format(SQLDateFormat)))
return rawLimit, nil
case avro.Type(avro.LogicalTypeTime):
var t time.Time
var ok bool
if t, ok = limit.(time.Time); !ok {
t = time.Date(1970, 1, 1, 0, 0, int(limit.(int32)), 0, time.UTC)
}
rawLimit = json.RawMessage(fmt.Sprintf(`"%s"`, t.Format(time.RFC3339Nano)))
rawLimit = json.RawMessage(fmt.Sprintf(`"%s"`, t.Format(SQLDateFormat)))
return rawLimit, nil
default:
return nil, ErrUnsupportedTypeForCriterion
Expand Down

0 comments on commit 9599c3d

Please sign in to comment.