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 10709fc
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 6 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ Each tag contains the following two properties:
* `name`: The tag name.
* `prop`: A property of the tag. Each property contains the following two fields:
* `name`: **Required**. The property name, must be the same with the tag property in Nebula Graph.
* `type`: **Optional**. The property type, currently `bool`, `int`, `float`, `double`, `string`, `time`, `timestamp`, `date` and `datetime` are supported.
* `type`: **Optional**. The property type, currently `bool`, `int`, `float`, `double`, `string`, `time`, `timestamp`, `date`, `datetime`, `geography`, `geography(point)`, `geography(linestring)` and `geography(polygon)` are supported.
* `index`: **Optional**. The column number in the CSV file.

> **NOTE**: The properties in the preceding `prop` parameter must be sorted in the **same** way as in the CSV data file.
Expand Down Expand Up @@ -315,7 +315,7 @@ The format for each column is `<tag_name/edge_name>.<prop_name>:<prop_type>`:

* `<tag_name/edge_name>` is the name for the vertex or edge.
* `<prop_name>` is the property name.
* `<prop_type>` is the property type. It can be `bool`, `int`, `float`, `double`, `string`, `time`, `timestamp`, `date` and `datetime`. The default type is `string`.
* `<prop_type>` is the property type. It can be `bool`, `int`, `float`, `double`, `string`, `time`, `timestamp`, `date`, `datetime`, `geography`, `geography(point)`, `geography(linestring)` and `geography(polygon)`. The default type is `string`.

In the above `<prop_type>` field, the following keywords contain special semantics:

Expand Down
4 changes: 2 additions & 2 deletions README_zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ schema:
- `name`:TAG 的名称。
- `props`:TAG 的属性字段数组,每个属性字段又由如下两个字段构成:
- `name`:**必填**。属性名称,同 Nebula Graph 中创建的 TAG 的属性名称一致。
- `type`:**必填**。属性类型,目前支持 `bool`、`int`、`float`、`double`、`timestamp``string` 几种类型。
- `type`:**必填**。属性类型,目前支持 `bool`、`int`、`float`、`double`、`timestamp``string`、`geography`、`geography(point)`、`geography(linestring)`和`geography(polygon)` 几种类型。
- `index`:**可选**。在 CSV 文件中的列标。
> **注意**:上述 `props` 中的属性描述**顺序**必须同数据文件中的对应数据排列顺序一致。
Expand Down Expand Up @@ -268,7 +268,7 @@ example 中 choose 类型的边的样例数据:
- `<tag_name/edge_name>` 表示 TAG 或者 EDGE 的名称。
- `<prop_name>` 表示属性名称。
- `<prop_type>` 表示属性类型。可以是 `bool`、`int`、`float`、`double`、`string``timestamp`,不设置默认为 `string`。
- `<prop_type>` 表示属性类型。可以是 `bool`、`int`、`float`、`double`、`string``timestamp`、`geography`、`geography(point)`、`geography(linestring)`和`geography(polygon)`,不设置默认为 `string`。
在上述的 `<prop_type>` 字段中有如下几个关键词含有特殊语义:
Expand Down
33 changes: 32 additions & 1 deletion examples/v2/example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ 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)
CREATE TAG date_test(c1 date, c2 time, c3 datetime, c4 timestamp);
CREATE TAG geography_test(any_shape geography, only_point geography(point), only_linestring geography(linestring), only_polygon geography(polygon))
afterPeriod: 8s
preStop:
commands: |
Expand Down Expand Up @@ -440,3 +441,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)","LINEstring (-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 ((-108.7 35.0,-100.0 46.5,-90.7 34.9,-108.7 35.0))"
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 10709fc

Please sign in to comment.