Skip to content

Commit

Permalink
Support date/time/datetime/timestamp (#152)
Browse files Browse the repository at this point in the history
* Support date/time/datetime

* timestamp
  • Loading branch information
yixinglu authored Jul 16, 2021
1 parent 4da4f88 commit 8882282
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 3 deletions.
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

0 comments on commit 8882282

Please sign in to comment.