candiduslynx commented on code in PR #35769:
URL: https://github.com/apache/arrow/pull/35769#discussion_r1236488243
##########
format/Schema.fbs:
##########
@@ -171,6 +172,16 @@ table LargeUtf8 {
table LargeBinary {
}
+/// Same as Utf8, but string characters are delimited with a packed
+/// length/pointer instead of offsets.
+table Utf8View {
+}
+
+/// Same as Binary, but string characters are delimited with a packed
+/// length/pointeBinary of offsets.
Review Comment:
This needs rephrasing
##########
go/arrow/datatype.go:
##########
@@ -152,6 +152,13 @@ const (
RUN_END_ENCODED
+ // String (UTF8) view type with 4-byte prefix and inline
+ // small string optimizations
+ STRING_VIEW
+
+ // Bytes view with 4-byte prefix and inline small string optimization
Review Comment:
```suggestion
// Bytes view with 4-byte prefix and inline small byte arrays
optimization
```
##########
dev/archery/archery/integration/datagen.py:
##########
@@ -743,6 +763,72 @@ class LargeStringColumn(_BaseStringColumn,
_LargeOffsetsMixin):
pass
+class BinaryViewColumn(PrimitiveColumn):
+
+ def _encode_value(self, x):
+ return frombytes(binascii.hexlify(x).upper())
+
+ def _get_buffers(self):
+ char_buffers = []
+ DEFAULT_BUFFER_SIZE = 32 # ¯\_(ツ)_/¯
+ INLINE_SIZE = 12
+
+ data = []
+ for i, v in enumerate(self.values):
+ if not self.is_valid[i]:
+ v = b''
+ assert isinstance(v, bytes)
+
+ if len(v) > INLINE_SIZE:
+ offset = 0
+ if len(v) > DEFAULT_BUFFER_SIZE:
+ char_buffers.append(v)
+ else:
+ if len(char_buffers) == 0:
+ char_buffers.append(v)
+ elif len(char_buffers[-1]) + len(v) > DEFAULT_BUFFER_SIZE:
+ char_buffers.append(v)
+ else:
+ offset = len(char_buffers[-1])
+ char_buffers[-1] += v
+ assert len(char_buffers[-1]) <= DEFAULT_BUFFER_SIZE
Review Comment:
isn't it already checked above for the case of `len(char_buffers[-1]) +
len(v) > DEFAULT_BUFFER_SIZE`?
##########
go/arrow/datatype_binary.go:
##########
@@ -83,16 +83,50 @@ func (t *LargeStringType) Layout() DataTypeLayout {
func (t *LargeStringType) OffsetTypeTraits() OffsetTraits { return Int64Traits
}
func (LargeStringType) IsUtf8() bool { return true }
+type BinaryViewType struct{}
+
+func (*BinaryViewType) ID() Type { return BINARY_VIEW }
+func (*BinaryViewType) Name() string { return "binary_view" }
+func (*BinaryViewType) String() string { return "binary_view" }
+func (*BinaryViewType) IsUtf8() bool { return false }
+func (*BinaryViewType) binary() {}
+func (*BinaryViewType) view() {}
+func (t *BinaryViewType) Fingerprint() string { return typeFingerprint(t) }
+func (*BinaryViewType) Layout() DataTypeLayout {
+ variadic := SpecVariableWidth()
+ return DataTypeLayout{Buffers: []BufferSpec{SpecBitmap(),
+ SpecFixedWidth(StringHeaderSizeBytes)}, VariadicSpec: &variadic}
+}
+
+type StringViewType struct{}
Review Comment:
please add compile-time assertions for `BinaryViewType` conformation
##########
go/arrow/datatype_binary.go:
##########
@@ -83,16 +83,50 @@ func (t *LargeStringType) Layout() DataTypeLayout {
func (t *LargeStringType) OffsetTypeTraits() OffsetTraits { return Int64Traits
}
func (LargeStringType) IsUtf8() bool { return true }
+type BinaryViewType struct{}
+
+func (*BinaryViewType) ID() Type { return BINARY_VIEW }
+func (*BinaryViewType) Name() string { return "binary_view" }
+func (*BinaryViewType) String() string { return "binary_view" }
+func (*BinaryViewType) IsUtf8() bool { return false }
+func (*BinaryViewType) binary() {}
+func (*BinaryViewType) view() {}
+func (t *BinaryViewType) Fingerprint() string { return typeFingerprint(t) }
+func (*BinaryViewType) Layout() DataTypeLayout {
+ variadic := SpecVariableWidth()
+ return DataTypeLayout{Buffers: []BufferSpec{SpecBitmap(),
+ SpecFixedWidth(StringHeaderSizeBytes)}, VariadicSpec: &variadic}
Review Comment:
```suggestion
return DataTypeLayout{
Buffers: []BufferSpec{SpecBitmap(),
SpecFixedWidth(StringHeaderSizeBytes)},
VariadicSpec: &variadic,
}
```
##########
go/arrow/internal/flatbuf/BinaryView.go:
##########
@@ -0,0 +1,52 @@
+// Licensed to the Apache Software Foundation (ASF) under one
Review Comment:
why are those in pascal case instead of snake case names?
##########
go/arrow/type_traits_string_view.go:
##########
@@ -0,0 +1,53 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package arrow
+
+import (
+ "reflect"
+ "unsafe"
+
+ "github.com/apache/arrow/go/v13/arrow/endian"
+)
+
+var StringHeaderTraits stringHeaderTraits
Review Comment:
should there be one for binary view as well?
##########
go/arrow/array/binary.go:
##########
@@ -318,6 +319,116 @@ func arrayEqualLargeBinary(left, right *LargeBinary) bool
{
return true
}
+type ViewLike interface {
+ arrow.Array
+ ValueHeader(int) *arrow.StringHeader
+}
+
+type BinaryView struct {
+ array
+ values []arrow.StringHeader
+ dataBuffers []*memory.Buffer
+}
+
+func NewBinaryViewData(data arrow.ArrayData) *BinaryView {
+ a := &BinaryView{}
+ a.refCount = 1
+ a.setData(data.(*Data))
+ return a
+}
+
+func (a *BinaryView) setData(data *Data) {
+ if len(data.buffers) < 2 {
+ panic("len(data.buffers) < 2")
+ }
+ a.array.setData(data)
+
+ if valueData := data.buffers[1]; valueData != nil {
+ a.values =
arrow.StringHeaderTraits.CastFromBytes(valueData.Bytes())
+ }
+
+ a.dataBuffers = data.buffers[2:]
+}
+
+func (a *BinaryView) ValueHeader(i int) *arrow.StringHeader {
+ if i < 0 || i >= a.array.data.length {
+ panic("arrow/array: index out of range")
+ }
+ return &a.values[a.array.data.offset+i]
+}
+
+func (a *BinaryView) Value(i int) []byte {
+ s := a.ValueHeader(i)
+ if s.IsInline() {
+ return s.InlineBytes()
+ }
+ start := s.BufferOffset()
+ buf := a.dataBuffers[s.BufferIndex()]
+ return buf.Bytes()[start : start+uint32(s.Len())]
+}
+
+func (a *BinaryView) ValueString(i int) string {
+ b := a.Value(i)
+ return *(*string)(unsafe.Pointer(&b))
+}
+
+func (a *BinaryView) String() string {
+ var o strings.Builder
+ o.WriteString("[")
+ for i := 0; i < a.Len(); i++ {
+ if i > 0 {
+ o.WriteString(" ")
+ }
+ switch {
+ case a.IsNull(i):
+ o.WriteString(NullValueStr)
+ default:
+ fmt.Fprintf(&o, "%q", a.ValueString(i))
+ }
+ }
+ o.WriteString("]")
+ return o.String()
+}
+
+func (a *BinaryView) ValueStr(i int) string {
Review Comment:
`ValueStr` is paired with `AppendValueFromString` and has a contract of
being able to reconstruct the same data with
`b.AppendValueFromString(a.ValueStr(i))`
##########
go/arrow/array/binary.go:
##########
@@ -318,6 +319,116 @@ func arrayEqualLargeBinary(left, right *LargeBinary) bool
{
return true
}
+type ViewLike interface {
+ arrow.Array
+ ValueHeader(int) *arrow.StringHeader
+}
+
+type BinaryView struct {
+ array
+ values []arrow.StringHeader
+ dataBuffers []*memory.Buffer
+}
+
+func NewBinaryViewData(data arrow.ArrayData) *BinaryView {
+ a := &BinaryView{}
+ a.refCount = 1
Review Comment:
```suggestion
a := &BinaryView{refCount: 1}
```
##########
go/arrow/datatype_binary.go:
##########
@@ -83,16 +83,50 @@ func (t *LargeStringType) Layout() DataTypeLayout {
func (t *LargeStringType) OffsetTypeTraits() OffsetTraits { return Int64Traits
}
func (LargeStringType) IsUtf8() bool { return true }
+type BinaryViewType struct{}
+
+func (*BinaryViewType) ID() Type { return BINARY_VIEW }
+func (*BinaryViewType) Name() string { return "binary_view" }
+func (*BinaryViewType) String() string { return "binary_view" }
+func (*BinaryViewType) IsUtf8() bool { return false }
+func (*BinaryViewType) binary() {}
+func (*BinaryViewType) view() {}
+func (t *BinaryViewType) Fingerprint() string { return typeFingerprint(t) }
+func (*BinaryViewType) Layout() DataTypeLayout {
+ variadic := SpecVariableWidth()
+ return DataTypeLayout{Buffers: []BufferSpec{SpecBitmap(),
+ SpecFixedWidth(StringHeaderSizeBytes)}, VariadicSpec: &variadic}
+}
+
+type StringViewType struct{}
+
+func (*StringViewType) ID() Type { return STRING_VIEW }
+func (*StringViewType) Name() string { return "string_view" }
+func (*StringViewType) String() string { return "string_view" }
+func (*StringViewType) IsUtf8() bool { return true }
+func (*StringViewType) binary() {}
+func (*StringViewType) view() {}
+func (t *StringViewType) Fingerprint() string { return typeFingerprint(t) }
+func (*StringViewType) Layout() DataTypeLayout {
+ variadic := SpecVariableWidth()
+ return DataTypeLayout{Buffers: []BufferSpec{SpecBitmap(),
+ SpecFixedWidth(StringHeaderSizeBytes)}, VariadicSpec: &variadic}
Review Comment:
```suggestion
return DataTypeLayout{
Buffers: []BufferSpec{SpecBitmap(),
SpecFixedWidth(StringHeaderSizeBytes)},
VariadicSpec: &variadic,
}
```
##########
go/arrow/datatype_binary.go:
##########
@@ -83,16 +83,50 @@ func (t *LargeStringType) Layout() DataTypeLayout {
func (t *LargeStringType) OffsetTypeTraits() OffsetTraits { return Int64Traits
}
func (LargeStringType) IsUtf8() bool { return true }
+type BinaryViewType struct{}
Review Comment:
please add compile-time assertions for `BinaryViewType` conformation
##########
go/arrow/datatype_stringheader_inline_tinygo.go:
##########
@@ -0,0 +1,35 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+//go:build !go1.20 && tinygo
+
+package arrow
+
+import (
+ "reflect"
+ "unsafe"
+
+ "github.com/apache/arrow/go/v13/arrow/internal/debug"
+)
+
+func (sh *StringHeader) InlineData() (data string) {
+ debug.Assert(sh.IsInline(), "calling InlineData on non-inline
StringHeader")
+
+ h := (*reflect.StringHeader)(unsafe.Pointer(&data))
Review Comment:
any diff with go1.19 implementation?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]