Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TIMESTAMP support integer #230

Merged
merged 2 commits into from
Dec 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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+)$`)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0o prefix represent the octal number

Copy link
Contributor Author

@veezhang veezhang Dec 1, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've tried.

(root@nebula) [importer_test_v2]> RETURN TIMESTAMP(01234)
+----------------+
| timestamp(668) |
+----------------+
| 668            |
+----------------+
(root@nebula) [importer_test_v2]> RETURN TIMESTAMP(0o1234)
[ERROR (-1004)]: SyntaxError: syntax error near `o1234'

Thu, 01 Dec 2022 13:47:00 CST

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK.

)

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