github.com/segmentio/parquet-go@v0.0.0-20230712180008-5d42db8f0d47/dictionary_amd64.go (about)

     1  //go:build !purego
     2  
     3  package parquet
     4  
     5  import (
     6  	"unsafe"
     7  
     8  	"github.com/segmentio/parquet-go/internal/unsafecast"
     9  	"github.com/segmentio/parquet-go/sparse"
    10  )
    11  
    12  //go:noescape
    13  func dictionaryBoundsInt32(dict []int32, indexes []int32) (min, max int32, err errno)
    14  
    15  //go:noescape
    16  func dictionaryBoundsInt64(dict []int64, indexes []int32) (min, max int64, err errno)
    17  
    18  //go:noescape
    19  func dictionaryBoundsFloat32(dict []float32, indexes []int32) (min, max float32, err errno)
    20  
    21  //go:noescape
    22  func dictionaryBoundsFloat64(dict []float64, indexes []int32) (min, max float64, err errno)
    23  
    24  //go:noescape
    25  func dictionaryBoundsUint32(dict []uint32, indexes []int32) (min, max uint32, err errno)
    26  
    27  //go:noescape
    28  func dictionaryBoundsUint64(dict []uint64, indexes []int32) (min, max uint64, err errno)
    29  
    30  //go:noescape
    31  func dictionaryBoundsBE128(dict [][16]byte, indexes []int32) (min, max *[16]byte, err errno)
    32  
    33  //go:noescape
    34  func dictionaryLookup32(dict []uint32, indexes []int32, rows sparse.Array) errno
    35  
    36  //go:noescape
    37  func dictionaryLookup64(dict []uint64, indexes []int32, rows sparse.Array) errno
    38  
    39  //go:noescape
    40  func dictionaryLookupByteArrayString(dict []uint32, page []byte, indexes []int32, rows sparse.Array) errno
    41  
    42  //go:noescape
    43  func dictionaryLookupFixedLenByteArrayString(dict []byte, len int, indexes []int32, rows sparse.Array) errno
    44  
    45  //go:noescape
    46  func dictionaryLookupFixedLenByteArrayPointer(dict []byte, len int, indexes []int32, rows sparse.Array) errno
    47  
    48  func (d *int32Dictionary) lookup(indexes []int32, rows sparse.Array) {
    49  	checkLookupIndexBounds(indexes, rows)
    50  	dict := unsafecast.Int32ToUint32(d.values)
    51  	dictionaryLookup32(dict, indexes, rows).check()
    52  }
    53  
    54  func (d *int64Dictionary) lookup(indexes []int32, rows sparse.Array) {
    55  	checkLookupIndexBounds(indexes, rows)
    56  	dict := unsafecast.Int64ToUint64(d.values)
    57  	dictionaryLookup64(dict, indexes, rows).check()
    58  }
    59  
    60  func (d *floatDictionary) lookup(indexes []int32, rows sparse.Array) {
    61  	checkLookupIndexBounds(indexes, rows)
    62  	dict := unsafecast.Float32ToUint32(d.values)
    63  	dictionaryLookup32(dict, indexes, rows).check()
    64  }
    65  
    66  func (d *doubleDictionary) lookup(indexes []int32, rows sparse.Array) {
    67  	checkLookupIndexBounds(indexes, rows)
    68  	dict := unsafecast.Float64ToUint64(d.values)
    69  	dictionaryLookup64(dict, indexes, rows).check()
    70  }
    71  
    72  func (d *byteArrayDictionary) lookupString(indexes []int32, rows sparse.Array) {
    73  	checkLookupIndexBounds(indexes, rows)
    74  	// TODO: this optimization is disabled for now because it appears to race
    75  	// with the garbage collector and result in writing pointers to free objects
    76  	// to the output.
    77  	//
    78  	// This command was used to trigger the problem:
    79  	//
    80  	//	GOMAXPROCS=8 go test -run TestIssue368 -count 10
    81  	//
    82  	// https://github.com/segmentio/parquet-go/issues/368
    83  	//
    84  	//dictionaryLookupByteArrayString(d.offsets, d.values, indexes, rows).check()
    85  	for i, j := range indexes {
    86  		v := d.index(int(j))
    87  		*(*string)(rows.Index(i)) = *(*string)(unsafe.Pointer(&v))
    88  	}
    89  }
    90  
    91  func (d *fixedLenByteArrayDictionary) lookupString(indexes []int32, rows sparse.Array) {
    92  	checkLookupIndexBounds(indexes, rows)
    93  	//dictionaryLookupFixedLenByteArrayString(d.data, d.size, indexes, rows).check()
    94  	for i, j := range indexes {
    95  		v := d.index(j)
    96  		*(*string)(rows.Index(i)) = *(*string)(unsafe.Pointer(&v))
    97  	}
    98  }
    99  
   100  func (d *uint32Dictionary) lookup(indexes []int32, rows sparse.Array) {
   101  	checkLookupIndexBounds(indexes, rows)
   102  	dictionaryLookup32(d.values, indexes, rows).check()
   103  }
   104  
   105  func (d *uint64Dictionary) lookup(indexes []int32, rows sparse.Array) {
   106  	checkLookupIndexBounds(indexes, rows)
   107  	dictionaryLookup64(d.values, indexes, rows).check()
   108  }
   109  
   110  func (d *be128Dictionary) lookupString(indexes []int32, rows sparse.Array) {
   111  	checkLookupIndexBounds(indexes, rows)
   112  	//dict := unsafecast.Uint128ToBytes(d.values)
   113  	//dictionaryLookupFixedLenByteArrayString(dict, 16, indexes, rows).check()
   114  	s := "0123456789ABCDEF"
   115  	for i, j := range indexes {
   116  		*(**[16]byte)(unsafe.Pointer(&s)) = d.index(j)
   117  		*(*string)(rows.Index(i)) = s
   118  	}
   119  }
   120  
   121  func (d *be128Dictionary) lookupPointer(indexes []int32, rows sparse.Array) {
   122  	checkLookupIndexBounds(indexes, rows)
   123  	//dict := unsafecast.Uint128ToBytes(d.values)
   124  	//dictionaryLookupFixedLenByteArrayPointer(dict, 16, indexes, rows).check()
   125  	for i, j := range indexes {
   126  		*(**[16]byte)(rows.Index(i)) = d.index(j)
   127  	}
   128  }
   129  
   130  func (d *int32Dictionary) bounds(indexes []int32) (min, max int32) {
   131  	min, max, err := dictionaryBoundsInt32(d.values, indexes)
   132  	err.check()
   133  	return min, max
   134  }
   135  
   136  func (d *int64Dictionary) bounds(indexes []int32) (min, max int64) {
   137  	min, max, err := dictionaryBoundsInt64(d.values, indexes)
   138  	err.check()
   139  	return min, max
   140  }
   141  
   142  func (d *floatDictionary) bounds(indexes []int32) (min, max float32) {
   143  	min, max, err := dictionaryBoundsFloat32(d.values, indexes)
   144  	err.check()
   145  	return min, max
   146  }
   147  
   148  func (d *doubleDictionary) bounds(indexes []int32) (min, max float64) {
   149  	min, max, err := dictionaryBoundsFloat64(d.values, indexes)
   150  	err.check()
   151  	return min, max
   152  }
   153  
   154  func (d *uint32Dictionary) bounds(indexes []int32) (min, max uint32) {
   155  	min, max, err := dictionaryBoundsUint32(d.values, indexes)
   156  	err.check()
   157  	return min, max
   158  }
   159  
   160  func (d *uint64Dictionary) bounds(indexes []int32) (min, max uint64) {
   161  	min, max, err := dictionaryBoundsUint64(d.values, indexes)
   162  	err.check()
   163  	return min, max
   164  }
   165  
   166  func (d *be128Dictionary) bounds(indexes []int32) (min, max *[16]byte) {
   167  	min, max, err := dictionaryBoundsBE128(d.values, indexes)
   168  	err.check()
   169  	return min, max
   170  }