Skip to content

Commit

Permalink
ARROW-17482: [Go] Remove ValueDescr types (#13930)
Browse files Browse the repository at this point in the history
Authored-by: Matt Topol <zotthewizard@gmail.com>
Signed-off-by: Matt Topol <zotthewizard@gmail.com>
  • Loading branch information
zeroshade committed Aug 22, 2022
1 parent 258173d commit 5f66708
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 120 deletions.
1 change: 0 additions & 1 deletion dev/release/rat_exclude_files.txt
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,6 @@ go/arrow/cdata/test/go.sum
go/arrow/unionmode_string.go
go/arrow/compute/go.sum
go/arrow/compute/datumkind_string.go
go/arrow/compute/valueshape_string.go
go/*.tmpldata
go/*.s
go/parquet/internal/gen-go/parquet/GoUnusedProtection__.go
Expand Down
74 changes: 0 additions & 74 deletions go/arrow/compute/datum.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,37 +18,14 @@ package compute

import (
"fmt"
"strings"

"github.com/apache/arrow/go/v10/arrow"
"github.com/apache/arrow/go/v10/arrow/array"
"github.com/apache/arrow/go/v10/arrow/scalar"
)

//go:generate go run golang.org/x/tools/cmd/stringer -type=ValueShape -linecomment
//go:generate go run golang.org/x/tools/cmd/stringer -type=DatumKind -linecomment

// ValueShape is a brief description of the shape of a value (array, scalar or otherwise)
type ValueShape int8

const (
// either Array or Scalar
ShapeAny ValueShape = iota // any
ShapeArray // array
ShapeScalar // scalar
)

// ValueDescr is a descriptor type giving both the shape and the datatype of a value
// but without the data.
type ValueDescr struct {
Shape ValueShape
Type arrow.DataType
}

func (v *ValueDescr) String() string {
return fmt.Sprintf("%s [%s]", v.Shape, v.Type)
}

// DatumKind is an enum used for denoting which kind of type a datum is encapsulating
type DatumKind int

Expand Down Expand Up @@ -82,8 +59,6 @@ type Datum interface {
// a slice with 1 element for Array, and the slice of chunks for a chunked array.
type ArrayLikeDatum interface {
Datum
Shape() ValueShape
Descr() ValueDescr
NullN() int64
Type() arrow.DataType
Chunks() []arrow.Array
Expand Down Expand Up @@ -114,12 +89,10 @@ type ScalarDatum struct {
}

func (ScalarDatum) Kind() DatumKind { return KindScalar }
func (ScalarDatum) Shape() ValueShape { return ShapeScalar }
func (ScalarDatum) Len() int64 { return 1 }
func (ScalarDatum) Chunks() []arrow.Array { return nil }
func (d *ScalarDatum) Type() arrow.DataType { return d.Value.DataType() }
func (d *ScalarDatum) String() string { return d.Value.String() }
func (d *ScalarDatum) Descr() ValueDescr { return ValueDescr{ShapeScalar, d.Value.DataType()} }
func (d *ScalarDatum) ToScalar() (scalar.Scalar, error) {
return d.Value, nil
}
Expand Down Expand Up @@ -155,11 +128,9 @@ type ArrayDatum struct {
}

func (ArrayDatum) Kind() DatumKind { return KindArray }
func (ArrayDatum) Shape() ValueShape { return ShapeArray }
func (d *ArrayDatum) Type() arrow.DataType { return d.Value.DataType() }
func (d *ArrayDatum) Len() int64 { return int64(d.Value.Len()) }
func (d *ArrayDatum) NullN() int64 { return int64(d.Value.NullN()) }
func (d *ArrayDatum) Descr() ValueDescr { return ValueDescr{ShapeArray, d.Value.DataType()} }
func (d *ArrayDatum) String() string { return fmt.Sprintf("Array:{%s}", d.Value.DataType()) }
func (d *ArrayDatum) MakeArray() arrow.Array { return array.MakeFromData(d.Value) }
func (d *ArrayDatum) Chunks() []arrow.Array { return []arrow.Array{d.MakeArray()} }
Expand Down Expand Up @@ -191,11 +162,9 @@ type ChunkedDatum struct {
}

func (ChunkedDatum) Kind() DatumKind { return KindChunked }
func (ChunkedDatum) Shape() ValueShape { return ShapeArray }
func (d *ChunkedDatum) Type() arrow.DataType { return d.Value.DataType() }
func (d *ChunkedDatum) Len() int64 { return int64(d.Value.Len()) }
func (d *ChunkedDatum) NullN() int64 { return int64(d.Value.NullN()) }
func (d *ChunkedDatum) Descr() ValueDescr { return ValueDescr{ShapeArray, d.Value.DataType()} }
func (d *ChunkedDatum) String() string { return fmt.Sprintf("Array:{%s}", d.Value.DataType()) }
func (d *ChunkedDatum) Chunks() []arrow.Array { return d.Value.Chunks() }

Expand Down Expand Up @@ -258,46 +227,6 @@ func (d *TableDatum) Equals(other Datum) bool {
}

// CollectionDatum is a slice of Datums
type CollectionDatum []Datum

func (CollectionDatum) Kind() DatumKind { return KindCollection }
func (c CollectionDatum) Len() int64 { return int64(len(c)) }
func (c CollectionDatum) String() string {
var b strings.Builder
b.WriteString("Collection(")
for i, d := range c {
if i > 0 {
b.WriteString(", ")
}
b.WriteString(d.String())
}
b.WriteByte(')')
return b.String()
}

func (c CollectionDatum) Release() {
for _, v := range c {
v.Release()
}
}

func (c CollectionDatum) Equals(other Datum) bool {
rhs, ok := other.(CollectionDatum)
if !ok {
return false
}

if len(c) != len(rhs) {
return false
}

for i := range c {
if !c[i].Equals(rhs[i]) {
return false
}
}
return true
}

// NewDatum will construct the appropriate Datum type based on what is passed in
// as the argument.
Expand Down Expand Up @@ -327,8 +256,6 @@ func NewDatum(value interface{}) Datum {
case arrow.Table:
v.Retain()
return &TableDatum{v}
case []Datum:
return CollectionDatum(v)
case scalar.Scalar:
return &ScalarDatum{v}
default:
Expand All @@ -342,5 +269,4 @@ var (
_ ArrayLikeDatum = (*ChunkedDatum)(nil)
_ TableLikeDatum = (*RecordDatum)(nil)
_ TableLikeDatum = (*TableDatum)(nil)
_ Datum = (CollectionDatum)(nil)
)
25 changes: 6 additions & 19 deletions go/arrow/compute/expression.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,6 @@ type Expression interface {
// FieldRef returns a pointer to the underlying field reference, or nil if
// this expression is not a field reference.
FieldRef() *FieldRef
// Descr returns the shape of this expression will evaluate to including the type
// and whether it will be an Array, Scalar, or either.
Descr() ValueDescr
// Type returns the datatype this expression will evaluate to.
Type() arrow.DataType

Expand Down Expand Up @@ -146,14 +143,6 @@ func (l *Literal) IsSatisfiable() bool {
return true
}

func (l *Literal) Descr() ValueDescr {
if ad, ok := l.Literal.(ArrayLikeDatum); ok {
return ad.Descr()
}

return ValueDescr{ShapeAny, nil}
}

func (l *Literal) Hash() uint64 {
if l.IsScalarExpr() {
return scalar.Hash(hashSeed, l.Literal.(*ScalarDatum).Value)
Expand Down Expand Up @@ -183,20 +172,19 @@ type Parameter struct {
ref *FieldRef

// post bind props
descr ValueDescr
dt arrow.DataType
index int

bound boundRef
}

func (Parameter) IsNullLiteral() bool { return false }
func (p *Parameter) boundExpr() boundRef { return p.bound }
func (p *Parameter) Type() arrow.DataType { return p.descr.Type }
func (p *Parameter) Type() arrow.DataType { return p.dt }
func (p *Parameter) IsBound() bool { return p.Type() != nil }
func (p *Parameter) IsScalarExpr() bool { return p.ref != nil }
func (p *Parameter) IsSatisfiable() bool { return p.Type() == nil || p.Type().ID() != arrow.NULL }
func (p *Parameter) FieldRef() *FieldRef { return p.ref }
func (p *Parameter) Descr() ValueDescr { return p.descr }
func (p *Parameter) Hash() uint64 { return p.ref.Hash(hashSeed) }

func (p *Parameter) String() string {
Expand All @@ -219,15 +207,15 @@ func (p *Parameter) Equals(other Expression) bool {
}

func (p *Parameter) Bind(ctx context.Context, mem memory.Allocator, schema *arrow.Schema) (Expression, error) {
bound, descr, index, _, err := bindExprSchema(ctx, mem, p, schema)
bound, dt, index, _, err := bindExprSchema(ctx, mem, p, schema)
if err != nil {
return nil, err
}

return &Parameter{
ref: p.ref,
index: index,
descr: descr,
dt: dt,
bound: bound,
}, nil
}
Expand Down Expand Up @@ -325,7 +313,7 @@ func optionsToString(fn FunctionOptions) string {
type Call struct {
funcName string
args []Expression
descr ValueDescr
dt arrow.DataType
options FunctionOptions

cachedHash uint64
Expand All @@ -335,8 +323,7 @@ type Call struct {
func (c *Call) boundExpr() boundRef { return c.bound }
func (c *Call) IsNullLiteral() bool { return false }
func (c *Call) FieldRef() *FieldRef { return nil }
func (c *Call) Descr() ValueDescr { return c.descr }
func (c *Call) Type() arrow.DataType { return c.descr.Type }
func (c *Call) Type() arrow.DataType { return c.dt }
func (c *Call) IsSatisfiable() bool { return c.Type() == nil || c.Type().ID() != arrow.NULL }

func (c *Call) String() string {
Expand Down
2 changes: 1 addition & 1 deletion go/arrow/compute/no_exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,6 @@ func (boundRef) release() {}

// when compiled without the c++ library (the build tags control whether it looks for it)
// then we do not have pure go implementation of the expression binding currently.
func bindExprSchema(context.Context, memory.Allocator, Expression, *arrow.Schema) (boundRef, ValueDescr, int, Expression, error) {
func bindExprSchema(context.Context, memory.Allocator, Expression, *arrow.Schema) (boundRef, arrow.DataType, int, Expression, error) {
panic("arrow/compute: bind expression not implemented")
}
25 changes: 0 additions & 25 deletions go/arrow/compute/valueshape_string.go

This file was deleted.

0 comments on commit 5f66708

Please sign in to comment.