storj.io/minio@v0.0.0-20230509071714-0cbc90f649b1/pkg/s3select/internal/parquet-go/record.go (about)

     1  /*
     2   * Minio Cloud Storage, (C) 2019 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 (
    20  	"fmt"
    21  	"strings"
    22  )
    23  
    24  // Record - ordered parquet record.
    25  type Record struct {
    26  	nameList     []string
    27  	nameValueMap map[string]Value
    28  }
    29  
    30  // String - returns string representation of this record.
    31  func (r *Record) String() string {
    32  	values := []string{}
    33  	r.Range(func(name string, value Value) bool {
    34  		values = append(values, fmt.Sprintf("%v:%v", name, value))
    35  		return true
    36  	})
    37  
    38  	return "map[" + strings.Join(values, " ") + "]"
    39  }
    40  
    41  func (r *Record) set(name string, value Value) {
    42  	r.nameValueMap[name] = value
    43  }
    44  
    45  // Get - returns Value of name.
    46  func (r *Record) Get(name string) (Value, bool) {
    47  	value, ok := r.nameValueMap[name]
    48  	return value, ok
    49  }
    50  
    51  // Range - calls f sequentially for each name and value present in the record. If f returns false, range stops the iteration.
    52  func (r *Record) Range(f func(name string, value Value) bool) {
    53  	for _, name := range r.nameList {
    54  		value, ok := r.nameValueMap[name]
    55  		if !ok {
    56  			continue
    57  		}
    58  
    59  		if !f(name, value) {
    60  			break
    61  		}
    62  	}
    63  }
    64  
    65  func newRecord(nameList []string) *Record {
    66  	return &Record{
    67  		nameList:     nameList,
    68  		nameValueMap: make(map[string]Value),
    69  	}
    70  }