-
Notifications
You must be signed in to change notification settings - Fork 123
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add storage address mapping transform (#589)
* fix conflict * Add storage address mapping transform * update --------- Co-authored-by: Anqi <[email protected]> Co-authored-by: jiangyiwang-jk <[email protected]>
- Loading branch information
1 parent
6b25e64
commit cd003d5
Showing
5 changed files
with
219 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.vesoft.nebula.util; | ||
|
||
import com.vesoft.nebula.HostAddr; | ||
import com.vesoft.nebula.client.graph.data.HostAddress; | ||
|
||
/** | ||
* The util of network | ||
* | ||
* @Author jiangyiwang-jk | ||
* @Date 2024/2/1 15:36 | ||
*/ | ||
public class NetUtil { | ||
|
||
private NetUtil() { | ||
; | ||
} | ||
|
||
public static HostAddr parseHostAddr(String hostAddress) { | ||
assert hostAddress != null : "Host address should not be null"; | ||
String[] hostPort = hostAddress.split(":"); | ||
assert hostPort.length == 2 : String.format("Invalid host address %s", hostAddress); | ||
return new HostAddr(hostPort[0].trim(), Integer.parseInt(hostPort[1].trim())); | ||
} | ||
|
||
} |
123 changes: 123 additions & 0 deletions
123
examples/src/main/java/com/vesoft/nebula/examples/SpecialAddressStorageClientExample.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
/* Copyright (c) 2020 vesoft inc. All rights reserved. | ||
* | ||
* This source code is licensed under Apache 2.0 License. | ||
*/ | ||
|
||
package com.vesoft.nebula.examples; | ||
|
||
import com.vesoft.nebula.client.storage.StorageClient; | ||
import com.vesoft.nebula.client.storage.data.EdgeTableRow; | ||
import com.vesoft.nebula.client.storage.data.VertexRow; | ||
import com.vesoft.nebula.client.storage.data.VertexTableRow; | ||
import com.vesoft.nebula.client.storage.scan.ScanEdgeResult; | ||
import com.vesoft.nebula.client.storage.scan.ScanEdgeResultIterator; | ||
import com.vesoft.nebula.client.storage.scan.ScanVertexResult; | ||
import com.vesoft.nebula.client.storage.scan.ScanVertexResultIterator; | ||
import java.util.Arrays; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
public class SpecialAddressStorageClientExample { | ||
private static final Logger LOGGER = | ||
LoggerFactory.getLogger(SpecialAddressStorageClientExample.class); | ||
|
||
public static void main(String[] args) { | ||
Map<String,String> storageAddressMapping = new HashMap<>(); | ||
storageAddressMapping.put("127.0.0.1:9559","10.xx.xx.xx:9559"); | ||
// input params are the metad's ip and port | ||
StorageClient client = new StorageClient("127.0.0.1", 9559); | ||
// set storage address mapping | ||
client.setStorageAddressMapping(storageAddressMapping); | ||
try { | ||
client.connect(); | ||
} catch (Exception e) { | ||
LOGGER.error("storage client connect error, ", e); | ||
client.close(); | ||
System.exit(1); | ||
} | ||
scanVertex(client); | ||
scanEdge(client); | ||
|
||
client.close(); | ||
} | ||
|
||
/** | ||
* Vertex Person's property in Nebula Graph: | ||
* first_name, last_name, gender, birthday | ||
* Tom Li 男 2010 | ||
*/ | ||
public static void scanVertex(StorageClient client) { | ||
ScanVertexResultIterator iterator = client.scanVertex( | ||
"test", | ||
"person", | ||
Arrays.asList("name", "age")); | ||
|
||
while (iterator.hasNext()) { | ||
ScanVertexResult result = null; | ||
try { | ||
result = iterator.next(); | ||
} catch (Exception e) { | ||
LOGGER.error("scan error, ", e); | ||
client.close(); | ||
System.exit(1); | ||
} | ||
if (result.isEmpty()) { | ||
continue; | ||
} | ||
|
||
List<VertexRow> vertexRows = result.getVertices(); | ||
for (VertexRow row : vertexRows) { | ||
if (result.getVertex(row.getVid()) != null) { | ||
System.out.println(result.getVertex(row.getVid())); | ||
} | ||
} | ||
|
||
System.out.println("\nresult vertex table view:"); | ||
System.out.println(result.getPropNames()); | ||
List<VertexTableRow> vertexTableRows = result.getVertexTableRows(); | ||
for (VertexTableRow vertex : vertexTableRows) { | ||
System.out.println(vertex.getValues()); | ||
} | ||
System.out.println("\n"); | ||
} | ||
} | ||
|
||
/** | ||
* Edge Friend's property in Nebula Graph: | ||
* degree | ||
* 1.0 | ||
*/ | ||
public static void scanEdge(StorageClient client) { | ||
ScanEdgeResultIterator iterator = client.scanEdge( | ||
"test", | ||
"like", | ||
Arrays.asList("likeness")); | ||
|
||
while (iterator.hasNext()) { | ||
ScanEdgeResult result = null; | ||
try { | ||
result = iterator.next(); | ||
} catch (Exception e) { | ||
LOGGER.error("scan error, ", e); | ||
client.close(); | ||
System.exit(1); | ||
} | ||
if (result.isEmpty()) { | ||
continue; | ||
} | ||
|
||
System.out.println(result.getEdges()); | ||
|
||
System.out.println("\nresult edge table view:"); | ||
System.out.println(result.getPropNames()); | ||
List<EdgeTableRow> edgeTableRows = result.getEdgeTableRows(); | ||
for (EdgeTableRow edge : edgeTableRows) { | ||
System.out.println(edge.getValues()); | ||
} | ||
System.out.println("\n"); | ||
} | ||
} | ||
} |