Skip to content

Commit

Permalink
support geo value
Browse files Browse the repository at this point in the history
  • Loading branch information
jievince committed Oct 20, 2021
1 parent b86a241 commit 96b3494
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 1 deletion.
30 changes: 30 additions & 0 deletions examples/v2/example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -440,3 +440,33 @@ files:
- name: c4
type: timestamp
index: 4

- path: ./geography_test.csv
failDataPath: ./err/geography_test.csv
batchSize: 2
inOrder: true
type: csv
csv:
withHeader: false
withLabel: false
delimiter: ","
schema:
type: vertex
vertex:
vid:
index: 0
tags:
- name: geography_test
props:
- name: any_shape
type: geography
index: 1
- name: only_point
type: geography(point)
index: 2
- name: only_linestring
type: geography(linestring)
index: 3
- name: only_polygon
type: geography(polygon)
index: 4
3 changes: 3 additions & 0 deletions examples/v2/geography_test.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
g1,POINT (-82.3764154 42.6452196),"Point(3, 8)","POLYGON ((-108.7 35.0,-100.0 46.5,-90.7 34.9,-108.7 35.0)","POlygon ( (-100.1 41.4,-102.9 37.6,-96.8 37.5,-100.1 41.4))"
g2,"LineString(0 1, 1 2, 2 3)","point(4.6 5.7 )", "LINESTRING(43.8 52.6, -78.99 84.323)","polygon((-100.1 41.4,-102.9 37.6,-96.8 37.5,-100.1 41.4))"
g3,"Polygon((-85.1 34.8,-80.7 28.4,-76.9 34.9,-85.1 34.8))", Point(0.0 0.0), "linestring(0 1, 179.99 89.99)","polygon((0 1, 2 4, 3 5, 4 9, 0 1))"
2 changes: 1 addition & 1 deletion pkg/base/tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func FileExists(filename string) bool {

func IsValidType(t string) bool {
switch strings.ToLower(t) {
case "string", "int", "float", "double", "bool", "date", "time", "datetime", "timestamp":
case "string", "int", "float", "double", "bool", "date", "time", "datetime", "timestamp", "geography", "geography(point)", "geography(linestring)", "geography(polygon)":
return true
default:
return false
Expand Down
4 changes: 4 additions & 0 deletions pkg/base/tools_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,8 @@ func TestIsValidType(t *testing.T) {
assert.True(t, IsValidType("bool"))
assert.True(t, IsValidType("timestamp"))
assert.True(t, IsValidType("double"))
assert.True(t, IsValidType("geography"))
assert.True(t, IsValidType("geography(point)"))
assert.True(t, IsValidType("geography(linestring)"))
assert.True(t, IsValidType("geography(polygon)"))
}
9 changes: 9 additions & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -791,6 +791,11 @@ func (p *Prop) IsDateOrTimeType() bool {
return t == "date" || t == "time" || t == "datetime" || t == "timestamp"
}

func (p *Prop) IsGeographyType() bool {
t := strings.ToLower(*p.Type)
return t == "geography" || t == "geography(point)" || t == "geography(linestring)" || t == "geography(polygon)"
}

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 @@ -802,6 +807,10 @@ func (p *Prop) FormatValue(record base.Record) (string, error) {
if p.IsDateOrTimeType() {
return fmt.Sprintf("%s(%q)", strings.ToLower(*p.Type), r), nil
}
// Only support wkt for geography currently
if p.IsGeographyType() {
return fmt.Sprintf("ST_GeogFromText(%q)", r), nil
}

return r, nil
}
Expand Down

0 comments on commit 96b3494

Please sign in to comment.