diff --git a/examples/v2/date_test.csv b/examples/v2/date_test.csv index 781cf895..3195a535 100644 --- a/examples/v2/date_test.csv +++ b/examples/v2/date_test.csv @@ -1,2 +1,2 @@ d1,2020-01-01,18:28:23.284,2020-01-01T18:28:23.284,2020-01-01T18:28:23 -d2,2020-01-02,18:38:23.284,2020-01-11T19:28:23.284,2020-01-11T19:28:23 +d2,2020-01-02,18:38:23.284,2020-01-11T19:28:23.284,1578770903 diff --git a/pkg/config/config.go b/pkg/config/config.go index 067ed368..90c7eb1d 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -17,6 +17,10 @@ import ( "gopkg.in/yaml.v2" ) +var ( + reTimestampInteger = regexp.MustCompile(`^(0[xX][0-9a-fA-F]+|0[0-7]+|\d+)$`) +) + type NebulaClientConnection struct { User *string `json:"user" yaml:"user"` Password *string `json:"password" yaml:"password"` @@ -811,6 +815,11 @@ func (p *Prop) IsDateOrTimeType() bool { return t == "date" || t == "time" || t == "datetime" || t == "timestamp" } +func (p *Prop) IsTimestampType() bool { + t := strings.ToLower(*p.Type) + return t == "timestamp" +} + func (p *Prop) IsGeographyType() bool { t := strings.ToLower(*p.Type) return t == "geography" || t == "geography(point)" || t == "geography(linestring)" || t == "geography(polygon)" @@ -825,6 +834,9 @@ func (p *Prop) FormatValue(record base.Record) (string, error) { return fmt.Sprintf("%q", r), nil } if p.IsDateOrTimeType() { + if p.IsTimestampType() && reTimestampInteger.MatchString(r) { + return fmt.Sprintf("%s(%s)", strings.ToLower(*p.Type), r), nil + } return fmt.Sprintf("%s(%q)", strings.ToLower(*p.Type), r), nil } // Only support wkt for geography currently diff --git a/pkg/config/config_test.go b/pkg/config/config_test.go index 6716a9a5..4a8fcd59 100644 --- a/pkg/config/config_test.go +++ b/pkg/config/config_test.go @@ -676,6 +676,33 @@ func TestPropFormatValue(t *testing.T) { record: base.Record{"2020-01-11T19:28:23"}, want: "timestamp(\"2020-01-11T19:28:23\")", }, + { + name: "type timestamp integer", + prop: Prop{ + Index: &idx0, + Type: &tTimestamp, + }, + record: base.Record{"1578770903"}, + want: "timestamp(1578770903)", + }, + { + name: "type timestamp integer", + prop: Prop{ + Index: &idx0, + Type: &tTimestamp, + }, + record: base.Record{"0123"}, + want: "timestamp(0123)", + }, + { + name: "type timestamp integer", + prop: Prop{ + Index: &idx0, + Type: &tTimestamp, + }, + record: base.Record{"0XF0"}, + want: "timestamp(0XF0)", + }, { name: "type date", prop: Prop{