bkietz commented on code in PR #135:
URL: https://github.com/apache/arrow-go/pull/135#discussion_r1771786465


##########
arrow/compute/scalar_compare.go:
##########
@@ -134,4 +136,50 @@ func RegisterScalarComparisons(reg FunctionRegistry) {
        reg.AddFunction(ltFn, false)
        lteFn := makeFlippedCompare("less_equal", gteFn, EmptyFuncDoc)
        reg.AddFunction(lteFn, false)
+
+       isOrNotNullKns := kernels.IsNullKernels()
+       isNullFn := &compareFunction{*NewScalarFunction("is_null", Unary(), 
EmptyFuncDoc)}
+       if err := isNullFn.AddKernel(isOrNotNullKns[0]); err != nil {
+               panic(err)
+       }
+
+       isNotNullFn := &compareFunction{*NewScalarFunction("is_not_null", 
Unary(), EmptyFuncDoc)}
+       if err := isNotNullFn.AddKernel(isOrNotNullKns[1]); err != nil {
+               panic(err)
+       }
+
+       reg.AddFunction(isNullFn, false)
+       reg.AddFunction(isNotNullFn, false)
+
+       reg.AddFunction(NewMetaFunction("is_nan", Unary(), EmptyFuncDoc,
+               func(ctx context.Context, opts FunctionOptions, args ...Datum) 
(Datum, error) {
+                       switch args[0].Kind() {

Review Comment:
   Nit: could you reoder the type switch to be outside the kind switch? Then we 
have one `return CallFunction(ctx, "not_equal", nil, arg, arg)` for all kinds 
of floats and we either return scalar false or broadcast it for other types



##########
arrow/array/struct.go:
##########
@@ -43,6 +43,31 @@ func NewStructArray(cols []arrow.Array, names []string) 
(*Struct, error) {
        return NewStructArrayWithNulls(cols, names, nil, 0, 0)
 }
 
+// NewStructArrayWithFields builds a new Struct Array using the passed columns
+// and provided fields. As opposed to NewStructArray, this allows you to 
provide
+// the full fields to utilize for the struct column instead of just the names.
+func NewStructArrayWithFields(cols []arrow.Array, fields []arrow.Field) 
(*Struct, error) {
+       if len(cols) != len(fields) {
+               return nil, fmt.Errorf("%w: mismatching number of fields and 
child arrays", arrow.ErrInvalid)
+       }
+       if len(cols) == 0 {
+               return nil, fmt.Errorf("%w: can't infer struct array length 
with 0 child arrays", arrow.ErrInvalid)
+       }
+
+       length := cols[0].Len()
+       children := make([]arrow.ArrayData, len(cols))
+       for i, c := range cols {
+               if length != c.Len() {
+                       return nil, fmt.Errorf("%w: mismatching child array 
lengths", arrow.ErrInvalid)
+               }
+               children[i] = c.Data()
+       }
+
+       data := NewData(arrow.StructOf(fields...), length, 
[]*memory.Buffer{nil}, children, 0, 0)
+       defer data.Release()
+       return NewStructData(data), nil

Review Comment:
   Does this check that the types of `cols` match those of `fields`?



##########
arrow/compute/scalar_compare.go:
##########
@@ -134,4 +136,50 @@ func RegisterScalarComparisons(reg FunctionRegistry) {
        reg.AddFunction(ltFn, false)
        lteFn := makeFlippedCompare("less_equal", gteFn, EmptyFuncDoc)
        reg.AddFunction(lteFn, false)
+
+       isOrNotNullKns := kernels.IsNullKernels()
+       isNullFn := &compareFunction{*NewScalarFunction("is_null", Unary(), 
EmptyFuncDoc)}
+       if err := isNullFn.AddKernel(isOrNotNullKns[0]); err != nil {
+               panic(err)
+       }
+
+       isNotNullFn := &compareFunction{*NewScalarFunction("is_not_null", 
Unary(), EmptyFuncDoc)}
+       if err := isNotNullFn.AddKernel(isOrNotNullKns[1]); err != nil {
+               panic(err)
+       }
+
+       reg.AddFunction(isNullFn, false)
+       reg.AddFunction(isNotNullFn, false)
+
+       reg.AddFunction(NewMetaFunction("is_nan", Unary(), EmptyFuncDoc,
+               func(ctx context.Context, opts FunctionOptions, args ...Datum) 
(Datum, error) {
+                       switch args[0].Kind() {
+                       case KindScalar:
+                               arg := args[0].(*ScalarDatum)
+                               switch arg.Type() {
+                               case arrow.PrimitiveTypes.Float32, 
arrow.PrimitiveTypes.Float64:
+                                       // IEEE 754 says that only NAN 
satisfies f != f
+                                       return CallFunction(ctx, "not_equal", 
nil, arg, arg)
+                               default:
+                                       return NewDatum(true), nil

Review Comment:
   Doesn't this mean we always return `is_nan=true` for integers? This doesn't 
seem to match the array case below
   ```suggestion
   return NewDatum(false), nil
   ```



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