emkornfield commented on a change in pull request #11514:
URL: https://github.com/apache/arrow/pull/11514#discussion_r744023225



##########
File path: go/arrow/compute/expression.go
##########
@@ -0,0 +1,954 @@
+// 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 compute
+
+import (
+       "bytes"
+       "context"
+       "encoding/hex"
+       "errors"
+       "fmt"
+       "hash/maphash"
+       "reflect"
+       "strconv"
+       "strings"
+
+       "github.com/apache/arrow/go/arrow"
+       "github.com/apache/arrow/go/arrow/array"
+       "github.com/apache/arrow/go/arrow/internal/debug"
+       "github.com/apache/arrow/go/arrow/ipc"
+       "github.com/apache/arrow/go/arrow/memory"
+       "github.com/apache/arrow/go/arrow/scalar"
+)
+
+var hashSeed = maphash.MakeSeed()
+
+// Expression is an interface for mapping one datum to another. An expression
+// is one of:
+//     A literal Datum
+//     A reference to a single (potentially nested) field of an input Datum
+//     A call to a compute function, with arguments specified by other 
Expressions
+type Expression interface {
+       fmt.Stringer
+       // IsBound returns true if this expression has been bound to a 
particular
+       // Datum and/or Schema.
+       IsBound() bool
+       // IsScalarExpr returns true if this expression is composed only of 
scalar
+       // literals, field references and calls to scalar functions.
+       IsScalarExpr() bool
+       // IsNullLiteral returns true if this expression is a literal and 
entirely
+       // null.
+       IsNullLiteral() bool
+       // IsSatisfiable returns true if this expression could evaluate to true
+       IsSatisfiable() bool
+       // 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
+
+       Hash() uint64
+       Equals(Expression) bool
+
+       // Bind binds this expression to the given input schema, looking up 
appropriate
+       // underlying implementations and some expression simplification may be 
performed
+       // along with implicit casts being inserted.
+       // Any state necessary for execution will be initialized.
+       //
+       // This only works in conjunction with cgo and being able to link 
against the
+       // C++ libarrow.so compute library. If this was not built with the 
libarrow compute
+       // support, this will panic.
+       Bind(context.Context, memory.Allocator, *arrow.Schema) (Expression, 
error)
+
+       // Release releases the underlying bound C++ memory that is allocated 
when
+       // a Bind is performed. Any bound expression should get released to 
ensure
+       // no memory leaks.
+       Release()
+
+       boundExpr() boundRef
+}
+
+func printDatum(datum Datum) string {
+       switch datum := datum.(type) {
+       case *ScalarDatum:
+               if !datum.Value.IsValid() {
+                       return "null"
+               }
+
+               switch datum.Type().ID() {
+               case arrow.STRING, arrow.LARGE_STRING:
+                       return 
strconv.Quote(datum.Value.(scalar.BinaryScalar).String())
+               case arrow.BINARY, arrow.FIXED_SIZE_BINARY, arrow.LARGE_BINARY:
+                       return `"` + 
strings.ToUpper(hex.EncodeToString(datum.Value.(scalar.BinaryScalar).Data())) + 
`"`
+               }
+
+               return datum.Value.String()
+       default:
+               return datum.String()
+       }
+}
+
+// Literal is an expression denoting a literal Datum which could be any value
+// as a scalar, an array, or so on.
+type Literal struct {
+       Literal Datum
+
+       bound boundRef
+}
+
+func (Literal) FieldRef() *FieldRef     { return nil }
+func (l *Literal) String() string       { return printDatum(l.Literal) }
+func (l *Literal) boundExpr() boundRef  { return l.bound }
+func (l *Literal) Type() arrow.DataType { return 
l.Literal.(ArrayLikeDatum).Type() }
+func (l *Literal) IsBound() bool        { return l.Type() != nil }
+func (l *Literal) IsScalarExpr() bool   { return l.Literal.Kind() == 
KindScalar }
+
+func (l *Literal) Equals(other Expression) bool {
+       if rhs, ok := other.(*Literal); ok {
+               return l.Literal.Equals(rhs.Literal)
+       }
+       return false
+}
+
+func (l *Literal) IsNullLiteral() bool {
+       if ad, ok := l.Literal.(ArrayLikeDatum); ok {
+               return ad.NullN() == ad.Len()
+       }
+       return true
+}
+
+func (l *Literal) IsSatisfiable() bool {
+       if l.IsNullLiteral() {
+               return false
+       }
+
+       if sc, ok := l.Literal.(*ScalarDatum); ok && sc.Type().ID() == 
arrow.BOOL {

Review comment:
       so an error returns false?  What case does happen in?




-- 
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]


Reply via email to