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

Support date/time/datetime/timestamp #152

Merged
merged 2 commits into from
Jul 16, 2021
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: 2 additions & 0 deletions examples/v2/date_test.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
1,2020-01-01,18:28:23.284,2020-01-01T18:28:23.284,2020-01-01T18:28:23.284
2,2020-01-02,18:38:23.284,2020-01-11T19:28:23.284,2020-01-11T19:28:23.284
31 changes: 31 additions & 0 deletions examples/v2/example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ clientSettings:
CREATE TAG course_no_props();
CREATE TAG building_no_props();
CREATE EDGE follow_no_props();
CREATE TAG date_test(c1 date, c2 time, c3 datetime, c4 timestamp)
afterPeriod: 8s
preStop:
commands: |
Expand Down Expand Up @@ -392,3 +393,33 @@ files:
index: 1
srcVID:
index: 0

- path: ./date_test.csv
failDataPath: ./err/date_test.csv
batchSize: 2
inOrder: true
type: csv
csv:
withHeader: false
withLabel: false
delimiter: ","
schema:
type: vertex
vertex:
vid:
index: 0
tags:
- name: date_test
props:
- name: c1
type: date
index: 1
- name: c2
type: time
index: 2
- name: c3
type: datetime
index: 3
- name: c4
type: timestamp
index: 4
5 changes: 2 additions & 3 deletions pkg/base/tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,11 @@ func FileExists(filename string) bool {

func IsValidType(t string) bool {
switch strings.ToLower(t) {
case "string", "int", "float", "double", "bool", "timestamp":
break
case "string", "int", "float", "double", "bool", "date", "time", "datetime", "timestamp":
return true
default:
return false
}
return true
}

func HasHttpPrefix(path string) bool {
Expand Down
9 changes: 9 additions & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -723,6 +723,11 @@ func (p *Prop) IsStringType() bool {
return strings.ToLower(*p.Type) == "string"
}

func (p *Prop) IsDateOrTimeType() bool {
t := strings.ToLower(*p.Type)
return t == "date" || t == "time" || t == "datetime" || t == "timestamp"
}

func (p *Prop) FormatValue(record base.Record) (string, error) {
if p.Index != nil && *p.Index >= len(record) {
return "", fmt.Errorf("Prop index %d out range %d of record(%v)", *p.Index, len(record), record)
Expand All @@ -731,6 +736,10 @@ func (p *Prop) FormatValue(record base.Record) (string, error) {
if p.IsStringType() {
return fmt.Sprintf("%q", r), nil
}
if p.IsDateOrTimeType() {
return fmt.Sprintf("%s(%q)", strings.ToLower(*p.Type), r), nil
}

return r, nil
}

Expand Down