Skip to content

Commit

Permalink
fix: TIMESTAMP support integer (#230)
Browse files Browse the repository at this point in the history
close #229
  • Loading branch information
veezhang authored Dec 1, 2022
1 parent b4946cb commit 9ece886
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 1 deletion.
2 changes: 1 addition & 1 deletion examples/v2/date_test.csv
Original file line number Diff line number Diff line change
@@ -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
12 changes: 12 additions & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down Expand Up @@ -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)"
Expand All @@ -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
Expand Down
27 changes: 27 additions & 0 deletions pkg/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down

0 comments on commit 9ece886

Please sign in to comment.