dosubot[bot] commented on issue #2656:
URL:
https://github.com/apache/incubator-hugegraph/issues/2656#issuecomment-2328337943
<!-- Greeting -->
Hello, @kouhangting! I'm here to help you with any issues, bugs, or
questions you have. Let me know how I can assist you with your repository.
<!-- Answer -->
To resolve the issue where creating a node with Chinese attributes in
HugeGraph results in unexpected characters or behavior, you need to ensure that
the property keys are correctly defined to handle text values, and that the
input values are properly encoded.
Here is an example of how you can add a vertex with Chinese attributes:
```java
HugeGraph graph = graph();
// Define the schema if not already defined
SchemaManager schema = graph.schema();
schema.propertyKey("name").asText().create();
schema.propertyKey("city").asText().create();
schema.vertexLabel("person").properties("name", "city").create();
// Add a vertex with Chinese attributes
graph.addVertex(T.label, "person", "name", "张三", "city", "北京");
this.commitTx();
```
Ensure that the text encoding is properly handled in your environment to
avoid any issues with character representation. If you encounter any specific
errors related to character encoding, you may need to check your database and
application settings to ensure they support UTF-8 encoding
<sup>[[1]](https://github.com/apache/incubator-hugegraph/blob/master/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/core/VertexCoreTest.java)</sup>.
Additionally, HugeGraph handles character encoding for property values,
including non-ASCII characters like Chinese, by specifying the character set
when writing and reading files. For example, in the provided test cases, the
`GBK` charset is used to handle Chinese characters:
```java
private static final Charset GBK = Charset.forName("GBK");
@Test
public void testMatchedEncodingCharset() {
ioUtil.write("vertex_software.csv", GBK,
"name,lang,price",
"lop,中文,328");
String[] args = new String[]{
"-f", structPath("matched_encoding_charset/struct.json"),
"-s", configPath("matched_encoding_charset/schema.groovy"),
"-g", GRAPH,
"-h", SERVER,
"--batch-insert-threads", "2",
"--test-mode", "true"
};
HugeGraphLoader.main(args);
List<Vertex> vertices = CLIENT.graph().listVertices();
Assert.assertEquals(1, vertices.size());
Vertex vertex = vertices.get(0);
Assert.assertEquals("lop", vertex.property("name"));
Assert.assertEquals("中文", vertex.property("lang"));
Assert.assertEquals(328.0, vertex.property("price"));
}
```
In this test, the `GBK` charset is used to correctly handle the Chinese
characters in the `vertex_software.csv` file. The test verifies that the
property values are correctly encoded and decoded, ensuring that non-ASCII
characters are properly managed
<sup>[[2]](https://github.com/apache/incubator-hugegraph-toolchain/blob/master/hugegraph-loader/src/test/java/org/apache/hugegraph/loader/test/functional/FileLoadTest.java)</sup>.
<!-- Dosu Comment Footer -->
*To continue talking to [Dosu](https://dosu.dev), mention @dosu.*
--
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]