javeme commented on code in PR #480:
URL:
https://github.com/apache/incubator-hugegraph-toolchain/pull/480#discussion_r1258614628
##########
hugegraph-loader/src/main/java/org/apache/hugegraph/loader/executor/LoadOptions.java:
##########
@@ -233,6 +233,10 @@ public class LoadOptions implements Serializable {
description = "hbaseZKParent")
public String hbaseZKParent;
+ @Parameter(names = {"--action-type"}, arity = 1,
+ description = "add/update or delete")
Review Comment:
align with "names"
##########
hugegraph-loader/src/main/java/org/apache/hugegraph/loader/direct/loader/HBaseDirectLoader.java:
##########
@@ -200,23 +201,29 @@ List<Tuple2<ImmutableBytesWritable, KeyValue>>
buildAndSer(HBaseSerializer seria
struct.input().type()));
}
- boolean isVertex = builder.mapping().type().isVertex();
- if (isVertex) {
- for (Vertex vertex : (List<Vertex>) (Object) elementsElement) {
- LOG.debug("vertex already build done {} ",
vertex.toString());
- Tuple2<ImmutableBytesWritable, KeyValue> tuple2 =
- vertexSerialize(serializer, vertex);
-
loadDistributeMetrics.increaseDisVertexInsertSuccess(builder.mapping());
- result.add(tuple2);
- }
- } else {
- for (Edge edge : (List<Edge>) (Object) elementsElement) {
- LOG.debug("edge already build done {}", edge.toString());
- Tuple2<ImmutableBytesWritable, KeyValue> tuple2 =
- edgeSerialize(serializer, edge);
-
loadDistributeMetrics.increaseDisEdgeInsertSuccess(builder.mapping());
- result.add(tuple2);
-
+ if (elementsElement != null) {
+ for (GraphElement graphElement : elementsElement) {
+ final byte[] rowkey = serializer.getKeyBytes(graphElement);
+ final byte[] values =
serializer.getValueBytes(graphElement);
+ ImmutableBytesWritable rowKey = new
ImmutableBytesWritable();
+ rowKey.set(rowkey);
+ if
(loadOptions.actionType.equals(Constants.DELETE_ACTION)) {
+ KeyValue keyValue = new KeyValue(
Review Comment:
2 spaces in `KeyValue keyValue`
##########
hugegraph-loader/src/main/java/org/apache/hugegraph/loader/direct/loader/HBaseDirectLoader.java:
##########
@@ -200,23 +201,29 @@ List<Tuple2<ImmutableBytesWritable, KeyValue>>
buildAndSer(HBaseSerializer seria
struct.input().type()));
}
- boolean isVertex = builder.mapping().type().isVertex();
- if (isVertex) {
- for (Vertex vertex : (List<Vertex>) (Object) elementsElement) {
- LOG.debug("vertex already build done {} ",
vertex.toString());
- Tuple2<ImmutableBytesWritable, KeyValue> tuple2 =
- vertexSerialize(serializer, vertex);
-
loadDistributeMetrics.increaseDisVertexInsertSuccess(builder.mapping());
- result.add(tuple2);
- }
- } else {
- for (Edge edge : (List<Edge>) (Object) elementsElement) {
- LOG.debug("edge already build done {}", edge.toString());
- Tuple2<ImmutableBytesWritable, KeyValue> tuple2 =
- edgeSerialize(serializer, edge);
-
loadDistributeMetrics.increaseDisEdgeInsertSuccess(builder.mapping());
- result.add(tuple2);
-
+ if (elementsElement != null) {
Review Comment:
prefer `continue if (elementsElement == null)`
##########
hugegraph-loader/src/main/java/org/apache/hugegraph/loader/executor/LoadOptions.java:
##########
@@ -233,6 +233,10 @@ public class LoadOptions implements Serializable {
description = "hbaseZKParent")
public String hbaseZKParent;
+ @Parameter(names = {"--action-type"}, arity = 1,
Review Comment:
is it just for hbase? seems it's not implemented for other backends
currently?
##########
hugegraph-loader/src/main/java/org/apache/hugegraph/loader/constant/Constants.java:
##########
@@ -81,4 +81,5 @@ public final class Constants {
public static final String LOAD_DATA_PARSE_SUFFIX = "parse";
public static final String LOAD_DATA_SER_SUFFIX = "ser";
public static final String LOAD_DATA_INSERT_SUFFIX = "insert";
+ public static final String DELETE_ACTION = "delete";
Review Comment:
prefer ACTION_DELETE, and please also define ACTION_UPDATE
##########
hugegraph-loader/src/main/java/org/apache/hugegraph/loader/direct/loader/HBaseDirectLoader.java:
##########
@@ -200,23 +201,29 @@ List<Tuple2<ImmutableBytesWritable, KeyValue>>
buildAndSer(HBaseSerializer seria
struct.input().type()));
}
- boolean isVertex = builder.mapping().type().isVertex();
- if (isVertex) {
- for (Vertex vertex : (List<Vertex>) (Object) elementsElement) {
- LOG.debug("vertex already build done {} ",
vertex.toString());
- Tuple2<ImmutableBytesWritable, KeyValue> tuple2 =
- vertexSerialize(serializer, vertex);
-
loadDistributeMetrics.increaseDisVertexInsertSuccess(builder.mapping());
- result.add(tuple2);
- }
- } else {
- for (Edge edge : (List<Edge>) (Object) elementsElement) {
- LOG.debug("edge already build done {}", edge.toString());
- Tuple2<ImmutableBytesWritable, KeyValue> tuple2 =
- edgeSerialize(serializer, edge);
-
loadDistributeMetrics.increaseDisEdgeInsertSuccess(builder.mapping());
- result.add(tuple2);
-
+ if (elementsElement != null) {
+ for (GraphElement graphElement : elementsElement) {
+ final byte[] rowkey = serializer.getKeyBytes(graphElement);
+ final byte[] values =
serializer.getValueBytes(graphElement);
+ ImmutableBytesWritable rowKey = new
ImmutableBytesWritable();
+ rowKey.set(rowkey);
+ if
(loadOptions.actionType.equals(Constants.DELETE_ACTION)) {
+ KeyValue keyValue = new KeyValue(
+
rowkey,Bytes.toBytes(Constants.HBASE_COL_FAMILY),
+
Bytes.toBytes(Constants.EMPTY_STR),HConstants.LATEST_TIMESTAMP,
+ KeyValue.Type.DeleteFamily);
+ Tuple2<ImmutableBytesWritable, KeyValue> tuple2 =
+ new Tuple2<>(rowKey,keyValue);
+ result.add(tuple2);
+ } else {
+ KeyValue keyValue = new KeyValue(rowkey,
+ Bytes.toBytes(Constants.HBASE_COL_FAMILY),
+ Bytes.toBytes(Constants.EMPTY_STR),
+ values);
+ Tuple2<ImmutableBytesWritable, KeyValue> tuple2 =
+ new Tuple2<>(rowKey,keyValue);
Review Comment:
ditto
##########
hugegraph-loader/src/main/java/org/apache/hugegraph/loader/executor/LoadOptions.java:
##########
@@ -233,6 +233,10 @@ public class LoadOptions implements Serializable {
description = "hbaseZKParent")
public String hbaseZKParent;
Review Comment:
could you please also improve these names and descriptions
##########
hugegraph-loader/src/main/java/org/apache/hugegraph/loader/executor/LoadOptions.java:
##########
@@ -233,6 +233,10 @@ public class LoadOptions implements Serializable {
description = "hbaseZKParent")
public String hbaseZKParent;
+ @Parameter(names = {"--action-type"}, arity = 1,
+ description = "add/update or delete")
Review Comment:
prefer "One of action types: 'update' or 'delete'"
##########
hugegraph-loader/src/main/java/org/apache/hugegraph/loader/direct/loader/HBaseDirectLoader.java:
##########
@@ -200,23 +201,29 @@ List<Tuple2<ImmutableBytesWritable, KeyValue>>
buildAndSer(HBaseSerializer seria
struct.input().type()));
}
- boolean isVertex = builder.mapping().type().isVertex();
- if (isVertex) {
- for (Vertex vertex : (List<Vertex>) (Object) elementsElement) {
- LOG.debug("vertex already build done {} ",
vertex.toString());
- Tuple2<ImmutableBytesWritable, KeyValue> tuple2 =
- vertexSerialize(serializer, vertex);
-
loadDistributeMetrics.increaseDisVertexInsertSuccess(builder.mapping());
- result.add(tuple2);
- }
- } else {
- for (Edge edge : (List<Edge>) (Object) elementsElement) {
- LOG.debug("edge already build done {}", edge.toString());
- Tuple2<ImmutableBytesWritable, KeyValue> tuple2 =
- edgeSerialize(serializer, edge);
-
loadDistributeMetrics.increaseDisEdgeInsertSuccess(builder.mapping());
- result.add(tuple2);
-
+ if (elementsElement != null) {
+ for (GraphElement graphElement : elementsElement) {
+ final byte[] rowkey = serializer.getKeyBytes(graphElement);
+ final byte[] values =
serializer.getValueBytes(graphElement);
+ ImmutableBytesWritable rowKey = new
ImmutableBytesWritable();
+ rowKey.set(rowkey);
+ if
(loadOptions.actionType.equals(Constants.DELETE_ACTION)) {
+ KeyValue keyValue = new KeyValue(
+
rowkey,Bytes.toBytes(Constants.HBASE_COL_FAMILY),
+
Bytes.toBytes(Constants.EMPTY_STR),HConstants.LATEST_TIMESTAMP,
+ KeyValue.Type.DeleteFamily);
+ Tuple2<ImmutableBytesWritable, KeyValue> tuple2 =
+ new Tuple2<>(rowKey,keyValue);
Review Comment:
expect a space after the "rowKey,"
##########
hugegraph-loader/src/main/java/org/apache/hugegraph/loader/direct/loader/HBaseDirectLoader.java:
##########
@@ -200,23 +201,29 @@ List<Tuple2<ImmutableBytesWritable, KeyValue>>
buildAndSer(HBaseSerializer seria
struct.input().type()));
}
- boolean isVertex = builder.mapping().type().isVertex();
- if (isVertex) {
- for (Vertex vertex : (List<Vertex>) (Object) elementsElement) {
- LOG.debug("vertex already build done {} ",
vertex.toString());
- Tuple2<ImmutableBytesWritable, KeyValue> tuple2 =
- vertexSerialize(serializer, vertex);
-
loadDistributeMetrics.increaseDisVertexInsertSuccess(builder.mapping());
- result.add(tuple2);
- }
- } else {
- for (Edge edge : (List<Edge>) (Object) elementsElement) {
- LOG.debug("edge already build done {}", edge.toString());
- Tuple2<ImmutableBytesWritable, KeyValue> tuple2 =
- edgeSerialize(serializer, edge);
-
loadDistributeMetrics.increaseDisEdgeInsertSuccess(builder.mapping());
- result.add(tuple2);
-
+ if (elementsElement != null) {
+ for (GraphElement graphElement : elementsElement) {
+ final byte[] rowkey = serializer.getKeyBytes(graphElement);
+ final byte[] values =
serializer.getValueBytes(graphElement);
+ ImmutableBytesWritable rowKey = new
ImmutableBytesWritable();
+ rowKey.set(rowkey);
+ if
(loadOptions.actionType.equals(Constants.DELETE_ACTION)) {
+ KeyValue keyValue = new KeyValue(
+
rowkey,Bytes.toBytes(Constants.HBASE_COL_FAMILY),
+
Bytes.toBytes(Constants.EMPTY_STR),HConstants.LATEST_TIMESTAMP,
+ KeyValue.Type.DeleteFamily);
+ Tuple2<ImmutableBytesWritable, KeyValue> tuple2 =
+ new Tuple2<>(rowKey,keyValue);
+ result.add(tuple2);
+ } else {
+ KeyValue keyValue = new KeyValue(rowkey,
Review Comment:
ditto
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]