github.com/dolthub/go-mysql-server@v0.18.0/sql/partition.go (about) 1 // Copyright 2022 Dolthub, Inc. 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 sql 16 17 import "io" 18 19 // Partition represents a partition from a SQL table. 20 type Partition interface { 21 Key() []byte 22 } 23 24 // PartitionIter is an iterator that retrieves partitions. 25 type PartitionIter interface { 26 Closer 27 Next(*Context) (Partition, error) 28 } 29 30 // PartitionsToPartitionIter creates a PartitionIter that iterates over the given partitions. 31 func PartitionsToPartitionIter(partitions ...Partition) PartitionIter { 32 return &slicePartitionIter{partitions: partitions} 33 } 34 35 type slicePartitionIter struct { 36 partitions []Partition 37 idx int 38 } 39 40 func (i *slicePartitionIter) Next(*Context) (Partition, error) { 41 if i.idx >= len(i.partitions) { 42 return nil, io.EOF 43 } 44 i.idx++ 45 return i.partitions[i.idx-1], nil 46 } 47 func (i *slicePartitionIter) Close(*Context) error { 48 i.partitions = nil 49 return nil 50 }