github.com/matrixorigin/matrixone@v1.2.0/pkg/objectio/column.go (about) 1 // Copyright 2021 Matrix Origin 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 objectio 16 17 import ( 18 "github.com/matrixorigin/matrixone/pkg/container/types" 19 ) 20 21 const ( 22 dataTypeLen = 1 23 idxOff = dataTypeLen 24 idxLen = 2 25 ndvOff = idxOff + idxLen 26 ndvLen = 4 27 nullCntOff = ndvOff + ndvLen 28 nullCntLen = 4 29 locationOff = nullCntOff + nullCntLen 30 locationLen = ExtentSize 31 checkSumOff = locationOff + locationLen 32 checkSumLen = 4 33 zoneMapOff = checkSumOff + checkSumLen 34 zoneMapLen = 64 35 colMetaDummyOff = zoneMapOff + zoneMapLen 36 colMetaDummyLen = 32 37 colMetaLen = colMetaDummyOff + colMetaDummyLen 38 ) 39 40 func GetColumnMeta(idx uint16, data []byte) ColumnMeta { 41 offset := headerLen + uint32(idx)*colMetaLen 42 return data[offset : offset+colMetaLen] 43 } 44 45 type ColumnMeta []byte 46 47 func BuildColumnMeta() ColumnMeta { 48 var buf [colMetaLen]byte 49 meta := ColumnMeta(buf[:]) 50 return meta 51 } 52 53 func (cm ColumnMeta) DataType() uint8 { 54 return types.DecodeUint8(cm[:dataTypeLen]) 55 } 56 57 func (cm ColumnMeta) setDataType(t uint8) { 58 copy(cm[:dataTypeLen], types.EncodeUint8(&t)) 59 } 60 61 func (cm ColumnMeta) Idx() uint16 { 62 return types.DecodeUint16(cm[idxOff : idxOff+idxLen]) 63 } 64 65 func (cm ColumnMeta) setIdx(idx uint16) { 66 copy(cm[idxOff:idxOff+idxLen], types.EncodeUint16(&idx)) 67 } 68 69 func (cm ColumnMeta) Ndv() uint32 { 70 return types.DecodeUint32(cm[ndvOff : ndvOff+ndvLen]) 71 } 72 73 func (cm ColumnMeta) SetNdv(cnt uint32) { 74 copy(cm[ndvOff:ndvOff+ndvLen], types.EncodeUint32(&cnt)) 75 } 76 77 func (cm ColumnMeta) NullCnt() uint32 { 78 return types.DecodeUint32(cm[nullCntOff : nullCntOff+nullCntLen]) 79 } 80 81 func (cm ColumnMeta) SetNullCnt(cnt uint32) { 82 copy(cm[nullCntOff:nullCntOff+nullCntLen], types.EncodeUint32(&cnt)) 83 } 84 85 func (cm ColumnMeta) Location() Extent { 86 return Extent(cm[locationOff : locationOff+locationLen]) 87 } 88 89 func (cm ColumnMeta) setLocation(location Extent) { 90 copy(cm[locationOff:locationOff+locationLen], location) 91 } 92 93 func (cm ColumnMeta) ZoneMap() ZoneMap { 94 return ZoneMap(cm[zoneMapOff : zoneMapOff+zoneMapLen]) 95 } 96 97 func (cm ColumnMeta) SetZoneMap(zm ZoneMap) { 98 copy(cm[zoneMapOff:zoneMapOff+zoneMapLen], zm) 99 } 100 101 func (cm ColumnMeta) Checksum() uint32 { 102 return types.DecodeUint32(cm[checkSumOff : checkSumOff+checkSumLen]) 103 } 104 105 func (cm ColumnMeta) IsEmpty() bool { 106 return len(cm) == 0 107 }