Search in sources :

Example 11 with PropertyValue

use of com.alibaba.maxgraph.sdkcommon.schema.PropertyValue in project GraphScope by alibaba.

the class ClientDdlService method parseTypeDefPb.

private TypeDef parseTypeDefPb(TypeDefPb typeDefPb) {
    TypeDef.Builder builder = TypeDef.newBuilder();
    builder.setLabel(typeDefPb.getLabel());
    TypeEnumPb typeEnumPb = typeDefPb.getTypeEnum();
    switch(typeEnumPb) {
        case VERTEX:
            builder.setTypeEnum(TypeEnum.VERTEX);
            break;
        case EDGE:
            builder.setTypeEnum(TypeEnum.EDGE);
            break;
        default:
            throw new IllegalStateException("Unexpected value: " + typeEnumPb);
    }
    for (PropertyDefPb propertyDefPb : typeDefPb.getPropsList()) {
        PropertyDef.Builder propBuilder = PropertyDef.newBuilder();
        propBuilder.setName(propertyDefPb.getName());
        propBuilder.setPk(propertyDefPb.getPk());
        propBuilder.setComment(propertyDefPb.getComment());
        propBuilder.setDataType(parseDataType(propertyDefPb.getDataType()));
        PropertyValuePb defaultValuePb = propertyDefPb.getDefaultValue();
        propBuilder.setDefaultValue(new PropertyValue(parseDataType(defaultValuePb.getDataType()), defaultValuePb.getVal().toByteArray()));
        builder.addPropertyDef(propBuilder.build());
    }
    return builder.build();
}
Also used : TypeDef(com.alibaba.maxgraph.sdkcommon.schema.TypeDef) PropertyDef(com.alibaba.maxgraph.sdkcommon.schema.PropertyDef) PropertyValue(com.alibaba.maxgraph.sdkcommon.schema.PropertyValue)

Example 12 with PropertyValue

use of com.alibaba.maxgraph.sdkcommon.schema.PropertyValue in project GraphScope by alibaba.

the class PkHashUtilsTest method testHash.

@Test
public void testHash() {
    byte[] bytes = new PropertyValue(DataType.BOOL, true).getValBytes();
    assertEquals(-5831416668854475863L, PkHashUtils.hash(1, Arrays.asList(bytes)));
    bytes = new PropertyValue(DataType.BOOL, false).getValBytes();
    assertEquals(4016402799948355554L, PkHashUtils.hash(1, Arrays.asList(bytes)));
    bytes = new PropertyValue(DataType.SHORT, 5).getValBytes();
    assertEquals(-6461270943182640449L, PkHashUtils.hash(1, Arrays.asList(bytes)));
    bytes = new PropertyValue(DataType.INT, 6).getValBytes();
    assertEquals(-5566731246168985051L, PkHashUtils.hash(1, Arrays.asList(bytes)));
    bytes = new PropertyValue(DataType.LONG, 7).getValBytes();
    assertEquals(-2037727154783756963L, PkHashUtils.hash(1, Arrays.asList(bytes)));
    bytes = new PropertyValue(DataType.FLOAT, 5.5).getValBytes();
    assertEquals(3718470844984468536L, PkHashUtils.hash(1, Arrays.asList(bytes)));
    bytes = new PropertyValue(DataType.DOUBLE, 11.5).getValBytes();
    assertEquals(-6473588278280513549L, PkHashUtils.hash(1, Arrays.asList(bytes)));
    bytes = new PropertyValue(DataType.BYTES, new byte[] { 1, 2, 3 }).getValBytes();
    assertEquals(-5358885630460755339L, PkHashUtils.hash(1, Arrays.asList(bytes)));
    bytes = new PropertyValue(DataType.STRING, "abc").getValBytes();
    assertEquals(-1681001599945530356L, PkHashUtils.hash(1, Arrays.asList(bytes)));
    bytes = new PropertyValue(DataType.INT_LIST, Arrays.asList(400, 500, 600, 700)).getValBytes();
    assertEquals(-6843607735995935492L, PkHashUtils.hash(1, Arrays.asList(bytes)));
    bytes = new PropertyValue(DataType.LONG_LIST, Arrays.asList(111111111111L, 222222222222L, 333333333333L, 444444444444L)).getValBytes();
    assertEquals(7595853299324856776L, PkHashUtils.hash(1, Arrays.asList(bytes)));
    bytes = new PropertyValue(DataType.FLOAT_LIST, Arrays.asList(1.234567F, 12.34567F, 123.4567F, 1234.567F)).getValBytes();
    assertEquals(-866958979581072036L, PkHashUtils.hash(1, Arrays.asList(bytes)));
    bytes = new PropertyValue(DataType.DOUBLE_LIST, Arrays.asList(987654.3, 98765.43, 9876.543, 987.6543)).getValBytes();
    assertEquals(-1870641235154602931L, PkHashUtils.hash(1, Arrays.asList(bytes)));
    bytes = new PropertyValue(DataType.STRING_LIST, Arrays.asList("English", "中文")).getValBytes();
    assertEquals(-5965060437586883158L, PkHashUtils.hash(1, Arrays.asList(bytes)));
    assertEquals(7757033342887554736L, PkHashUtils.hash(1, Arrays.asList(new PropertyValue(DataType.STRING, "aaa").getValBytes(), new PropertyValue(DataType.LONG, 999999999999L).getValBytes())));
}
Also used : PropertyValue(com.alibaba.maxgraph.sdkcommon.schema.PropertyValue) Test(org.junit.Test)

Example 13 with PropertyValue

use of com.alibaba.maxgraph.sdkcommon.schema.PropertyValue in project GraphScope by alibaba.

the class PkHashUtilsTest method benchHash.

@Test
public void benchHash() {
    long i = 0;
    int interval = 10000000;
    long last_time = System.nanoTime();
    while (true) {
        i++;
        String testKey = "test_key_" + i;
        byte[] valBytes = new PropertyValue(DataType.STRING, testKey).getValBytes();
        PkHashUtils.hash(1, Arrays.asList(valBytes));
        if (i % interval == 0) {
            long now_time = System.nanoTime();
            long cost = now_time - last_time;
            last_time = now_time;
            System.out.println("total [" + i + "], cost [" + cost / 1000000 + "], interval_speed [" + (int) (1000000000.0 * interval / cost) + "]");
        }
    }
}
Also used : PropertyValue(com.alibaba.maxgraph.sdkcommon.schema.PropertyValue) Test(org.junit.Test)

Example 14 with PropertyValue

use of com.alibaba.maxgraph.sdkcommon.schema.PropertyValue in project GraphScope by alibaba.

the class Codec method encode.

public void encode(Map<Integer, PropertyValue> propertiesMap, ByteBuffer scratch) {
    scratch.putInt(this.version);
    scratch.put(this.nullBytesHolder);
    for (int i = 0; i < this.fixedPropertiesCount; i++) {
        GraphProperty propertyDef = this.propertyDefs.get(i);
        PropertyValue propertyValue = propertiesMap.get(propertyDef.getId());
        if (propertyValue != null) {
            writeBytes(scratch, this.offsets.get(i), propertyValue.getValBytes());
        } else if (propertyDef.getDefaultValue() != null) {
            PropertyValue defaultValue = new PropertyValue(propertyDef.getDataType(), propertyDef.getDefaultValue());
            writeBytes(scratch, this.offsets.get(i), defaultValue.getValBytes());
        } else {
            setNull(i, scratch);
        }
    }
    int varOffsetsPos = this.offsets.get(this.offsets.size() - 1);
    int dataOffset = varOffsetsPos + 3 * (this.propertyDefs.size() - this.fixedPropertiesCount);
    scratch.position(dataOffset);
    int varEndOffset = 0;
    for (int i = this.fixedPropertiesCount; i < this.propertyDefs.size(); i++) {
        GraphProperty propertyDef = this.propertyDefs.get(i);
        PropertyValue propertyValue = propertiesMap.get(propertyDef.getId());
        if (propertyValue != null) {
            byte[] valBytes = propertyValue.getValBytes();
            scratch.put(valBytes);
            varEndOffset += valBytes.length;
        } else if (propertyDef.getDefaultValue() != null) {
            PropertyValue defaultValue = new PropertyValue(propertyDef.getDataType(), propertyDef.getDefaultValue());
            byte[] valBytes = defaultValue.getValBytes();
            scratch.put(valBytes);
            varEndOffset += valBytes.length;
        } else {
            setNull(i, scratch);
        }
        byte[] endOffsetBytes = lengthBytes(varEndOffset);
        writeBytes(scratch, varOffsetsPos, endOffsetBytes);
        varOffsetsPos += 3;
    }
}
Also used : GraphProperty(com.alibaba.maxgraph.compiler.api.schema.GraphProperty) PropertyValue(com.alibaba.maxgraph.sdkcommon.schema.PropertyValue)

Example 15 with PropertyValue

use of com.alibaba.maxgraph.sdkcommon.schema.PropertyValue in project GraphScope by alibaba.

the class GraphWriter method addDeleteEdgeOperation.

private void addDeleteEdgeOperation(OperationBatch.Builder batchBuilder, GraphSchema schema, DataRecord dataRecord) {
    EdgeId edgeId;
    EdgeKind edgeKind;
    EdgeTarget edgeTarget = dataRecord.getEdgeTarget();
    if (edgeTarget != null) {
        edgeId = edgeTarget.getEdgeId();
        edgeKind = edgeTarget.getEdgeKind();
    } else {
        EdgeRecordKey edgeRecordKey = dataRecord.getEdgeRecordKey();
        VertexRecordKey srcVertexRecordKey = edgeRecordKey.getSrcVertexRecordKey();
        VertexRecordKey dstVertexRecordKey = edgeRecordKey.getDstVertexRecordKey();
        String label = edgeRecordKey.getLabel();
        GraphElement edgeDef = schema.getElement(label);
        GraphElement srcVertexDef = schema.getElement(srcVertexRecordKey.getLabel());
        GraphElement dstVertexDef = schema.getElement(dstVertexRecordKey.getLabel());
        int labelId = edgeDef.getLabelId();
        Map<Integer, PropertyValue> srcVertexPkVals = parseRawProperties(srcVertexDef, srcVertexRecordKey.getProperties());
        long srcVertexHashId = getHashId(srcVertexDef.getLabelId(), srcVertexPkVals, srcVertexDef);
        Map<Integer, PropertyValue> dstVertexPkVals = parseRawProperties(dstVertexDef, dstVertexRecordKey.getProperties());
        long dstVertexHashId = getHashId(dstVertexDef.getLabelId(), dstVertexPkVals, dstVertexDef);
        long edgeInnerId = edgeRecordKey.getEdgeInnerId();
        edgeId = new EdgeId(new VertexId(srcVertexHashId), new VertexId(dstVertexHashId), edgeInnerId);
        edgeKind = EdgeKind.newBuilder().setEdgeLabelId(new LabelId(labelId)).setSrcVertexLabelId(new LabelId(srcVertexDef.getLabelId())).setDstVertexLabelId(new LabelId(dstVertexDef.getLabelId())).build();
    }
    batchBuilder.addOperation(new DeleteEdgeOperation(edgeId, edgeKind, true));
    batchBuilder.addOperation(new DeleteEdgeOperation(edgeId, edgeKind, false));
}
Also used : EdgeKind(com.alibaba.maxgraph.sdkcommon.schema.EdgeKind) PropertyValue(com.alibaba.maxgraph.sdkcommon.schema.PropertyValue) VertexId(com.alibaba.graphscope.groot.operation.VertexId) EdgeRecordKey(com.alibaba.maxgraph.sdkcommon.common.EdgeRecordKey) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) VertexRecordKey(com.alibaba.maxgraph.sdkcommon.common.VertexRecordKey) EdgeId(com.alibaba.graphscope.groot.operation.EdgeId) GraphElement(com.alibaba.maxgraph.compiler.api.schema.GraphElement) LabelId(com.alibaba.maxgraph.sdkcommon.schema.LabelId)

Aggregations

PropertyValue (com.alibaba.maxgraph.sdkcommon.schema.PropertyValue)17 LabelId (com.alibaba.maxgraph.sdkcommon.schema.LabelId)7 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)7 VertexId (com.alibaba.graphscope.groot.operation.VertexId)6 GraphElement (com.alibaba.maxgraph.compiler.api.schema.GraphElement)6 VertexRecordKey (com.alibaba.maxgraph.sdkcommon.common.VertexRecordKey)6 EdgeKind (com.alibaba.maxgraph.sdkcommon.schema.EdgeKind)4 PropertyDef (com.alibaba.maxgraph.sdkcommon.schema.PropertyDef)4 TypeDef (com.alibaba.maxgraph.sdkcommon.schema.TypeDef)4 EdgeId (com.alibaba.graphscope.groot.operation.EdgeId)3 EdgeRecordKey (com.alibaba.maxgraph.sdkcommon.common.EdgeRecordKey)3 DdlExecutors (com.alibaba.graphscope.groot.schema.ddl.DdlExecutors)2 CreateVertexTypeRequest (com.alibaba.graphscope.groot.schema.request.CreateVertexTypeRequest)2 DdlRequestBatch (com.alibaba.graphscope.groot.schema.request.DdlRequestBatch)2 PropertyDefNotFoundException (com.alibaba.maxgraph.compiler.api.exception.PropertyDefNotFoundException)2 GraphProperty (com.alibaba.maxgraph.compiler.api.schema.GraphProperty)2 GraphDef (com.alibaba.maxgraph.sdkcommon.schema.GraphDef)2 Test (org.junit.Test)2 Test (org.junit.jupiter.api.Test)2 SnapshotListener (com.alibaba.graphscope.groot.SnapshotListener)1