Search in sources :

Example 36 with PropertyKey

use of com.baidu.hugegraph.structure.schema.PropertyKey in project incubator-hugegraph-toolchain by apache.

the class ElementBuilder method convertPropertyValue.

private Object convertPropertyValue(String key, Object rawValue) {
    PropertyKey propertyKey = this.getPropertyKey(key);
    InputSource inputSource = this.struct.input();
    return DataTypeUtil.convert(rawValue, propertyKey, inputSource);
}
Also used : InputSource(com.baidu.hugegraph.loader.source.InputSource) PropertyKey(com.baidu.hugegraph.structure.schema.PropertyKey)

Example 37 with PropertyKey

use of com.baidu.hugegraph.structure.schema.PropertyKey in project incubator-hugegraph-toolchain by apache.

the class PropertyKeyAPI method append.

public PropertyKey.PropertyKeyWithTask append(PropertyKey propertyKey) {
    String id = propertyKey.name();
    Map<String, Object> params = ImmutableMap.of("action", "append");
    Object pkey = this.checkCreateOrUpdate(propertyKey);
    RestResult result = this.client.put(this.path(), id, pkey, params);
    return result.readObject(PropertyKey.PropertyKeyWithTask.class);
}
Also used : RestResult(com.baidu.hugegraph.rest.RestResult) PropertyKey(com.baidu.hugegraph.structure.schema.PropertyKey)

Example 38 with PropertyKey

use of com.baidu.hugegraph.structure.schema.PropertyKey in project incubator-hugegraph-toolchain by apache.

the class PropertyKeyAPI method eliminate.

public PropertyKey.PropertyKeyWithTask eliminate(PropertyKey propertyKey) {
    String id = propertyKey.name();
    Map<String, Object> params = ImmutableMap.of("action", "eliminate");
    Object pkey = this.checkCreateOrUpdate(propertyKey);
    RestResult result = this.client.put(this.path(), id, pkey, params);
    return result.readObject(PropertyKey.PropertyKeyWithTask.class);
}
Also used : RestResult(com.baidu.hugegraph.rest.RestResult) PropertyKey(com.baidu.hugegraph.structure.schema.PropertyKey)

Example 39 with PropertyKey

use of com.baidu.hugegraph.structure.schema.PropertyKey in project incubator-hugegraph-toolchain by apache.

the class PropertyKeyAPI method clear.

public PropertyKey.PropertyKeyWithTask clear(PropertyKey propertyKey) {
    if (this.client.apiVersionLt("0.65")) {
        throw new NotSupportException("action clear on property key");
    }
    String id = propertyKey.name();
    Map<String, Object> params = ImmutableMap.of("action", "clear");
    Object pkey = this.checkCreateOrUpdate(propertyKey);
    RestResult result = this.client.put(this.path(), id, pkey, params);
    return result.readObject(PropertyKey.PropertyKeyWithTask.class);
}
Also used : RestResult(com.baidu.hugegraph.rest.RestResult) NotSupportException(com.baidu.hugegraph.exception.NotSupportException) PropertyKey(com.baidu.hugegraph.structure.schema.PropertyKey)

Example 40 with PropertyKey

use of com.baidu.hugegraph.structure.schema.PropertyKey in project incubator-hugegraph-toolchain by apache.

the class FileLoadTest method testAutoCreateSchema.

/**
 * NOTE: Unsupport auto create schema
 */
// @Test
public void testAutoCreateSchema() {
    String[] args = new String[] { "-f", "example/struct.json", "-g", GRAPH, "-h", SERVER, "--batch-insert-threads", "2" };
    HugeGraphLoader.main(args);
    List<PropertyKey> propertyKeys = CLIENT.schema().getPropertyKeys();
    propertyKeys.forEach(pkey -> {
        Assert.assertEquals(DataType.TEXT, pkey.dataType());
    });
    List<Vertex> vertices = CLIENT.graph().listVertices();
    List<Edge> edges = CLIENT.graph().listEdges();
    Assert.assertEquals(7, vertices.size());
    Assert.assertEquals(6, edges.size());
    boolean interestedVertex = false;
    for (Vertex vertex : vertices) {
        Assert.assertEquals(String.class, vertex.id().getClass());
        if (((String) vertex.id()).contains("li,nary")) {
            interestedVertex = true;
            Assert.assertEquals("26", vertex.property("age"));
            Assert.assertEquals("Wu,han", vertex.property("city"));
        }
    }
    Assert.assertTrue(interestedVertex);
    boolean interestedEdge = false;
    for (Edge edge : edges) {
        Assert.assertEquals(String.class, edge.sourceId().getClass());
        Assert.assertEquals(String.class, edge.targetId().getClass());
        if (((String) edge.sourceId()).contains("marko") && ((String) edge.targetId()).contains("vadas")) {
            interestedEdge = true;
            Assert.assertEquals("20160110", edge.property("date"));
            Assert.assertEquals("0.5", edge.property("weight"));
        }
    }
    Assert.assertTrue(interestedEdge);
}
Also used : Vertex(com.baidu.hugegraph.structure.graph.Vertex) Edge(com.baidu.hugegraph.structure.graph.Edge) PropertyKey(com.baidu.hugegraph.structure.schema.PropertyKey)

Aggregations

PropertyKey (com.baidu.hugegraph.structure.schema.PropertyKey)40 Test (org.junit.Test)27 SchemaManager (com.baidu.hugegraph.driver.SchemaManager)7 HugeClient (com.baidu.hugegraph.driver.HugeClient)6 RestResult (com.baidu.hugegraph.rest.RestResult)6 ExternalException (com.baidu.hugegraph.exception.ExternalException)4 Date (java.util.Date)4 ServerException (com.baidu.hugegraph.exception.ServerException)3 PropertyKeyEntity (com.baidu.hugegraph.entity.schema.PropertyKeyEntity)2 Vertex (com.baidu.hugegraph.structure.graph.Vertex)2 IndexLabel (com.baidu.hugegraph.structure.schema.IndexLabel)2 VertexLabel (com.baidu.hugegraph.structure.schema.VertexLabel)2 GremlinRequest (com.baidu.hugegraph.api.gremlin.GremlinRequest)1 NotSupportException (com.baidu.hugegraph.exception.NotSupportException)1 InputSource (com.baidu.hugegraph.loader.source.InputSource)1 FileSource (com.baidu.hugegraph.loader.source.file.FileSource)1 ListFormat (com.baidu.hugegraph.loader.source.file.ListFormat)1 Edge (com.baidu.hugegraph.structure.graph.Edge)1 ResultSet (com.baidu.hugegraph.structure.gremlin.ResultSet)1 EdgeLabel (com.baidu.hugegraph.structure.schema.EdgeLabel)1