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

docs: add python write demo #60

Merged
merged 6 commits into from
Sep 27, 2022
Merged
Show file tree
Hide file tree
Changes from 4 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
43 changes: 41 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ only showing top 2 rows
### Write in PySpark

Let's try a write example, by default, the `writeMode` is `insert`

#### write vertex
```python
df.write.format("com.vesoft.nebula.connector.NebulaDataSource").option(
"type", "vertex").option(
Expand All @@ -190,7 +190,7 @@ df.write.format("com.vesoft.nebula.connector.NebulaDataSource").option(
"passwd", "nebula").option(
"user", "root").save()
```

#### delete vertex
For delete or update write mode, we could(for instance)specify with `writeMode` as `delete` like:
```python
df.write.format("com.vesoft.nebula.connector.NebulaDataSource").option(
Expand All @@ -206,6 +206,44 @@ df.write.format("com.vesoft.nebula.connector.NebulaDataSource").option(
"writeMode", "delete").option(
"user", "root").save()
```
#### write edge
```python
df.write.format("com.vesoft.nebula.connector.NebulaDataSource")\
.mode("overwrite")\
.option("srcPolicy", "")\
.option("dstPolicy", "")\
.option("metaAddress", "metad0:9559")\
.option("graphAddress", "graphd:9669")\
.option("user", "root")\
.option("passwd", "nebula")\
.option("type", "edge")\
.option("spaceName", "basketballplayer")\
.option("label", "server")\
.option("srcVertexField", "srcid")\
.option("dstVertexField", "dstid")\
.option("rankFiled", "")\
Reid00 marked this conversation as resolved.
Show resolved Hide resolved
.option("batch", 100)\
.option("writeMode", "insert").save() # delete to delete edge, update to update edge
```
#### delete edge
```python
df.write.format("com.vesoft.nebula.connector.NebulaDataSource")\
.mode("overwrite")\
.option("srcPolicy", "")\
.option("dstPolicy", "")\
.option("metaAddress", "metad0:9559")\
.option("graphAddress", "graphd:9669")\
.option("user", "root")\
.option("passwd", "nebula")\
.option("type", "edge")\
.option("spaceName", "basketballplayer")\
.option("label", "server")\
.option("srcVertexField", "srcid")\
.option("dstVertexField", "dstid")\
.option("rankFiled", "")\
Reid00 marked this conversation as resolved.
Show resolved Hide resolved
.option("batch", 100)\
.option("writeMode", "delete").save() # delete to delete edge, update to update edge
```

### Options in PySpark

Expand Down Expand Up @@ -251,6 +289,7 @@ spark = SparkSession.builder.config(
"/path_to/nebula-spark-connector-3.0.0.jar").appName(
"nebula-connector").getOrCreate()

# read vertex
df = spark.read.format(
"com.vesoft.nebula.connector.NebulaDataSource").option(
"type", "vertex").option(
Expand Down
42 changes: 41 additions & 1 deletion README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ only showing top 2 rows
### PySpark 中写 NebulaGraph 中数据

再试一试写入数据的例子,默认不指定的情况下 `writeMode` 是 `insert`:

#### 写入点
```python
df.write.format("com.vesoft.nebula.connector.NebulaDataSource").option(
"type", "vertex").option(
Expand All @@ -190,6 +190,7 @@ df.write.format("com.vesoft.nebula.connector.NebulaDataSource").option(
"passwd", "nebula").option(
"user", "root").save()
```
#### 删除点
如果想指定 `delete` 或者 `update` 的非默认写入模式,增加 `writeMode` 的配置,比如 `delete` 的例子:

```python
Expand All @@ -206,6 +207,44 @@ df.write.format("com.vesoft.nebula.connector.NebulaDataSource").option(
"writeMode", "delete").option(
"user", "root").save()
```
#### 写入边
```python
df.write.format("com.vesoft.nebula.connector.NebulaDataSource")\
.mode("overwrite")\
.option("srcPolicy", "")\
.option("dstPolicy", "")\
.option("metaAddress", "metad0:9559")\
.option("graphAddress", "graphd:9669")\
.option("user", "root")\
.option("passwd", "nebula")\
.option("type", "edge")\
.option("spaceName", "basketballplayer")\
.option("label", "server")\
.option("srcVertexField", "srcid")\
.option("dstVertexField", "dstid")\
.option("rankFiled", "")\
Reid00 marked this conversation as resolved.
Show resolved Hide resolved
.option("batch", 100)\
.option("writeMode", "insert").save() # delete to delete edge, update to update edge
```
#### 删除边
```python
df.write.format("com.vesoft.nebula.connector.NebulaDataSource")\
.mode("overwrite")\
.option("srcPolicy", "")\
.option("dstPolicy", "")\
.option("metaAddress", "metad0:9559")\
.option("graphAddress", "graphd:9669")\
.option("user", "root")\
.option("passwd", "nebula")\
.option("type", "edge")\
.option("spaceName", "basketballplayer")\
.option("label", "server")\
.option("srcVertexField", "srcid")\
.option("dstVertexField", "dstid")\
.option("rankFiled", "")\
Reid00 marked this conversation as resolved.
Show resolved Hide resolved
.option("batch", 100)\
.option("writeMode", "delete").save() # delete to delete edge, update to update edge
```

### 关于 PySpark 读写的 option

Expand Down Expand Up @@ -252,6 +291,7 @@ spark = SparkSession.builder.config(
"/path_to/nebula-spark-connector-3.0.0.jar").appName(
"nebula-connector").getOrCreate()

# read vertex
df = spark.read.format(
"com.vesoft.nebula.connector.NebulaDataSource").option(
"type", "vertex").option(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ object NebulaOptions {
val TIMEOUT: String = "timeout"
val CONNECTION_RETRY: String = "connectionRetry"
val EXECUTION_RETRY: String = "executionRetry"
val RATE_TIME_OUT: String = "reteTimeOut"
val RATE_TIME_OUT: String = "rateTimeOut"
Reid00 marked this conversation as resolved.
Show resolved Hide resolved
val USER_NAME: String = "user"
val PASSWD: String = "passwd"
val ENABLE_GRAPH_SSL: String = "enableGraphSSL"
Expand Down