zeroshade commented on code in PR #13136:
URL: https://github.com/apache/arrow/pull/13136#discussion_r886913269
##########
go/arrow/datatype.go:
##########
@@ -209,3 +210,77 @@ func timeUnitFingerprint(unit TimeUnit) rune {
return rune(0)
}
}
+
+// BufferKind describes the type of buffer expected when defining a layout
specification
+type BufferKind int8
+
+// The expected types of buffers
+const (
+ KindFixedWidth BufferKind = iota
+ KindVarWidth
+ KindBitmap
+ KindAlwaysNull
+)
+
+// BufferSpec provides a specification for the buffers of a particular datatype
+type BufferSpec struct {
+ Kind BufferKind
+ ByteWidth int // for KindFixedWidth
+}
+
+func (b BufferSpec) Equals(other BufferSpec) bool {
+ return b.Kind == other.Kind && (b.Kind != KindFixedWidth || b.ByteWidth
== other.ByteWidth)
+}
+
+// DataTypeLayout represents the physical layout of a datatype's buffers
including
+// the number of and types of those binary buffers. This will correspond
+// with the buffers in the ArrayData for an array of that type.
+type DataTypeLayout struct {
+ Buffers []BufferSpec
+ HasDict bool
+}
+
+func SpecFixedWidth(w int) BufferSpec { return BufferSpec{KindFixedWidth, w} }
+func SpecVariableWidth() BufferSpec { return BufferSpec{KindVarWidth, -1} }
+func SpecBitmap() BufferSpec { return BufferSpec{KindBitmap, -1} }
+func SpecAlwaysNull() BufferSpec { return BufferSpec{KindAlwaysNull, -1} }
+
+// IsInteger is a helper to return true if the type ID provided is one of the
+// integral types of uint or int with the varying sizes.
+func IsInteger(t Type) bool {
+ switch t {
+ case UINT8, INT8, UINT16, INT16, UINT32, INT32, UINT64, INT64:
+ return true
+ }
+ return false
+}
+
+// IsPrimitive returns true if the provided type ID represents a fixed width
Review Comment:
I mentioned this in my response
[here](https://github.com/apache/arrow/pull/13136/#discussion_r885716884) but
essentially the reason why this is `IsPrimitive` is because it returns true if
the type is a value with a bit-width that is interpretable as a single
"primitive" value in most languages (ie: an integer with a specific bit-width
or a float/double) as opposed to values like DECIMAL128 and the interval values
which are compound structures consisting of multiple primitive values despite
being a known fixed width (for example two 64-bit integers for DECIMAL). That's
why i don't think `IsKnownFixedWidth` works for this
--
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]