NebulaGraph Java Client  release-3.8
ScanEdgeResult.java
1 /* Copyright (c) 2020 vesoft inc. All rights reserved.
2  *
3  * This source code is licensed under Apache 2.0 License.
4  */
5 
6 package com.vesoft.nebula.client.storage.scan;
7 
8 import com.vesoft.nebula.DataSet;
9 import com.vesoft.nebula.client.storage.data.EdgeRow;
10 import com.vesoft.nebula.client.storage.data.EdgeTableRow;
11 import com.vesoft.nebula.client.storage.data.ScanStatus;
12 import com.vesoft.nebula.client.storage.processor.EdgeProcessor;
13 import java.io.Serializable;
14 import java.util.ArrayList;
15 import java.util.List;
16 import org.slf4j.Logger;
17 import org.slf4j.LoggerFactory;
18 
19 public class ScanEdgeResult implements Serializable {
20  private static final Logger LOGGER = LoggerFactory.getLogger(ScanEdgeResult.class);
21  private static final long serialVersionUID = 519190254786197550L;
22 
23  private final List<DataSet> dataSets;
24 
28  private final ScanStatus scanStatus;
32  private List<EdgeTableRow> edgeTableRows = new ArrayList<>();
33 
37  private List<String> propNames = new ArrayList<>();
38 
42  private List<EdgeRow> edgeRows = new ArrayList<>();
43 
44  // todo set decodeType
45  private String decodeType = "utf-8";
46 
47  private boolean isEmpty;
48 
49 
50  public ScanEdgeResult(List<DataSet> dataSets, ScanStatus status) {
51  this.dataSets = dataSets;
52  this.scanStatus = status;
53  this.isEmpty = isDatasetEmpty();
54  }
55 
61  public List<EdgeTableRow> getEdgeTableRows() {
62  if (!isEmpty && edgeTableRows.isEmpty()) {
63  constructEdgeTableRow();
64  }
65  return edgeTableRows;
66  }
67 
73  public List<String> getPropNames() {
74  if (!isEmpty && propNames.isEmpty()) {
75  constructPropNames();
76  }
77  return propNames;
78  }
79 
80 
86  public List<EdgeRow> getEdges() {
87  if (!isEmpty && edgeRows.isEmpty()) {
88  constructEdgeRow();
89  }
90  return edgeRows;
91  }
92 
98  public boolean isAllSuccess() {
99  return scanStatus == ScanStatus.ALL_SUCCESS;
100  }
101 
107  public boolean isEmpty() {
108  return isEmpty;
109  }
110 
111  private boolean isDatasetEmpty() {
112  if (dataSets == null || dataSets.isEmpty()) {
113  return true;
114  }
115  for (DataSet dataSet : dataSets) {
116  if (dataSet.getRows().size() > 0) {
117  return false;
118  }
119  }
120  return true;
121  }
122 
126  private void constructEdgeTableRow() {
127  if (isEmpty) {
128  return;
129  }
130  synchronized (this) {
131  if (edgeTableRows.isEmpty()) {
132  edgeTableRows = EdgeProcessor.constructEdgeTableRow(dataSets, decodeType);
133  }
134  }
135  }
136 
140  private void constructEdgeRow() {
141  if (isEmpty) {
142  return;
143  }
144  synchronized (this) {
145  if (edgeRows.isEmpty()) {
146  edgeRows = EdgeProcessor.constructEdgeRow(dataSets, decodeType);
147  }
148  }
149  }
150 
154  private void constructPropNames() {
155  if (isEmpty) {
156  return;
157  }
158  synchronized (this) {
159  if (propNames.isEmpty()) {
160  List<byte[]> colNames = dataSets.get(0).getColumn_names();
161  for (byte[] colName : colNames) {
162  String propName = new String(colName);
163  if (!propName.contains(".")) {
164  continue;
165  }
166  propNames.add(propName.split("\\.")[1]);
167  }
168  }
169  }
170  }
171 }
List< String > getPropNames()
get the result's property names
List< EdgeTableRow > getEdgeTableRows()
get edge table rows
boolean isEmpty()
whether result data is empty