github.com/vescale/zgraph@v0.0.0-20230410094002-959c02d50f95/codec/index_key.go (about) 1 // Copyright 2022 zGraph Authors. All rights reserved. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package codec 16 17 var ( 18 prefix = []byte("g") 19 vertexSep = []byte("v") 20 edgeSep = []byte("e") 21 indexSep = []byte("i") 22 ) 23 24 // INDEX CODEC DOCUMENTATIONS: 25 26 // NOTE: Label is a special kind of indexSep ($LabelID equals $IndexID). 27 // The following SQL specifies an edgeSep label `known` and the LabelID will be 28 // the identifier of edgeSep `known`. 29 // INSERT EDGE e BETWEEN x AND y LABELS ( knows ) 30 // FROM MATCH (x:Person) 31 // , MATCH (y:Person) 32 // WHERE id(x) = 1 AND id(y) = 2 33 34 // 35 // - Key Format: 36 // Unique Key: $Prefix_$GraphID_$LabelID_$Type 37 // Non-Unique Key: $Prefix_$GraphID_$LabelID_$Type_$Unique 38 // Unique Key: $Prefix_$GraphID_$IndexID_$Type 39 // Non-Unique Key: $Prefix_$GraphID_$IndexID_$Type_$Unique 40 // - Value Format: 41 // [($PropertyID, $PropertyValue), ...] 42 // 43 // $Type Explanation: 44 // We need to distinguish the indexSep key type because a label can be both attach 45 // to vertexSep and edgeSep. There will be two types indexSep key. 46 // 1. Edge 47 // 2. Vertex 48 // 49 // $Unique Explanation: 50 // 1. For vertexSep label indexSep: it will be the vertexSep identifier. 51 // 2. For edgeSep label indexSep: it will be $SrcVertexID_$DstVertexID 52 53 // LabelKey returns the encoded key of specified graph/label. 54 func LabelKey(graphID, labelID, vertexID, dstVertexID int64) []byte { 55 var result []byte 56 if dstVertexID == 0 { 57 result = make([]byte, 0, len(prefix)+8 /*graphID*/ +8 /*labelID*/ +8 /*vertexID*/ + +len(vertexSep)) 58 } else { 59 result = make([]byte, 0, len(prefix)+8 /*graphID*/ +8 /*labelID*/ +8 /*vertexID*/ + +len(edgeSep) + 8 /*dstVertexID*/) 60 } 61 result = append(result, prefix...) 62 result = EncodeInt(result, graphID) 63 result = EncodeInt(result, labelID) 64 result = EncodeInt(result, vertexID) 65 if dstVertexID == 0 { 66 result = EncodeBytes(result, vertexSep) 67 } else { 68 result = EncodeBytes(result, edgeSep) 69 result = EncodeInt(result, dstVertexID) 70 } 71 return nil 72 } 73 74 // LabelValue returns a zero which is represents the flag byte of normal value. 75 func LabelValue() []byte { 76 return []byte{0} 77 } 78 79 // UniqueIndexKey encodes the unique index key described as above. 80 func UniqueIndexKey(graphID, indexID int64, typ byte) []byte { 81 return nil 82 } 83 84 // VertexNonUniqueIndexKey encodes the non-unique index key described as above. 85 func VertexNonUniqueIndexKey(graphID, indexID, vertexID int64) []byte { 86 return nil 87 } 88 89 // EdgeNonUniqueIndexKey encodes the non-unique index key described as above. 90 func EdgeNonUniqueIndexKey(graphID, indexID, srcVertexID, dstVertexID int64) []byte { 91 return nil 92 } 93 94 // ParseUniqueIndexKey parse the unique key. 95 func ParseUniqueIndexKey(key []byte) (graphID, indexID int64, typ byte, err error) { 96 return 97 } 98 99 // ParseVertexNonUniqueIndexKey parses the vertex non-unique key. 100 func ParseVertexNonUniqueIndexKey(key []byte) (graphID, indexID, vertexID int64, err error) { 101 return 102 } 103 104 // ParseEdgeNonUniqueIndexKey parses the edge non-unique key. 105 func ParseEdgeNonUniqueIndexKey(key []byte) (graphID, indexID, srcVertexID, dstVertexID int64, err error) { 106 return 107 }