storj.io/minio@v0.0.0-20230509071714-0cbc90f649b1/pkg/s3select/internal/parquet-go/table.go (about) 1 /* 2 * Minio Cloud Storage, (C) 2018 Minio, Inc. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package parquet 18 19 import "storj.io/minio/pkg/s3select/internal/parquet-go/gen-go/parquet" 20 21 func getTableValues(values interface{}, valueType parquet.Type) (tableValues []interface{}) { 22 return valuesToInterfaces(values, valueType) 23 } 24 25 type table struct { 26 RepetitionType parquet.FieldRepetitionType 27 Type parquet.Type 28 MaxDefinitionLevel int32 29 MaxRepetitionLevel int32 30 Path []string // Path of this column 31 Values []interface{} // Parquet values 32 DefinitionLevels []int32 // Definition Levels slice 33 RepetitionLevels []int32 // Repetition Levels slice 34 ConvertedType parquet.ConvertedType 35 Encoding parquet.Encoding 36 BitWidth int32 37 } 38 39 func newTableFromTable(srcTable *table) *table { 40 if srcTable == nil { 41 return nil 42 } 43 44 return &table{ 45 Type: srcTable.Type, 46 Path: append([]string{}, srcTable.Path...), 47 } 48 } 49 50 func (table *table) Merge(tables ...*table) { 51 for i := 0; i < len(tables); i++ { 52 if tables[i] == nil { 53 continue 54 } 55 56 table.Values = append(table.Values, tables[i].Values...) 57 table.RepetitionLevels = append(table.RepetitionLevels, tables[i].RepetitionLevels...) 58 table.DefinitionLevels = append(table.DefinitionLevels, tables[i].DefinitionLevels...) 59 60 if table.MaxDefinitionLevel < tables[i].MaxDefinitionLevel { 61 table.MaxDefinitionLevel = tables[i].MaxDefinitionLevel 62 } 63 64 if table.MaxRepetitionLevel < tables[i].MaxRepetitionLevel { 65 table.MaxRepetitionLevel = tables[i].MaxRepetitionLevel 66 } 67 } 68 } 69 70 func (table *table) Pop(numRows int64) *table { 71 result := newTableFromTable(table) 72 var i, num int64 73 for i = int64(0); i < int64(len(table.Values)); i++ { 74 if table.RepetitionLevels[i] == 0 { 75 if num >= numRows { 76 break 77 } 78 79 num++ 80 } 81 82 if result.MaxRepetitionLevel < table.RepetitionLevels[i] { 83 result.MaxRepetitionLevel = table.RepetitionLevels[i] 84 } 85 86 if result.MaxDefinitionLevel < table.DefinitionLevels[i] { 87 result.MaxDefinitionLevel = table.DefinitionLevels[i] 88 } 89 } 90 91 result.RepetitionLevels = table.RepetitionLevels[:i] 92 result.DefinitionLevels = table.DefinitionLevels[:i] 93 result.Values = table.Values[:i] 94 95 table.RepetitionLevels = table.RepetitionLevels[i:] 96 table.DefinitionLevels = table.DefinitionLevels[i:] 97 table.Values = table.Values[i:] 98 99 return result 100 }