nssalian commented on code in PR #1206:
URL: https://github.com/apache/arrow-go/pull/1206#discussion_r3898733390


##########
arrow/compute/variant_get.go:
##########
@@ -0,0 +1,735 @@
+// 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 (
+       "context"
+       "fmt"
+
+       "github.com/apache/arrow-go/v18/arrow"
+       "github.com/apache/arrow-go/v18/arrow/array"
+       "github.com/apache/arrow-go/v18/arrow/bitutil"
+       "github.com/apache/arrow-go/v18/arrow/decimal"
+       "github.com/apache/arrow-go/v18/arrow/decimal128"
+       "github.com/apache/arrow-go/v18/arrow/extensions"
+       "github.com/apache/arrow-go/v18/arrow/memory"
+       "github.com/apache/arrow-go/v18/parquet/variant"
+       "github.com/google/uuid"
+)
+
+// VariantGetOptions controls VariantGet.
+type VariantGetOptions struct {
+       // Path is the path to extract from every variant value.
+       Path variant.VariantPath
+       // AsType, when nil, makes VariantGet return a VariantArray pointing at 
the path;
+       // when set, the extracted values are cast to it via the cast kernels.
+       AsType arrow.DataType
+       // Strict makes a lossy cast fail; the default allows overflow and 
truncation via
+       // the cast kernels. Unlike arrow-rs safe mode there is no 
null-on-failure: an
+       // impossible cast always errors, since arrow-go's cast kernels have no 
safe flag.
+       // Non-strict nulls a whole natural-type group if any value in it is 
inconvertible.
+       Strict bool
+}
+
+// VariantGet extracts opts.Path from every value of input. It follows the 
shredded
+// typed_value columns as far as the path allows - stepping into struct fields
+// directly and gathering list elements with the take kernel - then 
reassembles only
+// the residual for any remaining path. With AsType nil it returns a 
VariantArray of
+// the extracted values; otherwise it casts them to AsType with the cast 
kernels.
+func VariantGet(ctx context.Context, input *extensions.VariantArray, opts 
VariantGetOptions) (arrow.Array, error) {
+       if input == nil {
+               return nil, fmt.Errorf("%w: VariantGet requires a non-nil 
VariantArray", arrow.ErrInvalid)
+       }
+
+       // Nested target types are not yet supported; reject up front rather 
than
+       // silently producing an all-null array from the leaf cast.
+       if _, ok := opts.AsType.(arrow.NestedType); ok {

Review Comment:
   Figured this out. The nested-target rejection was tripping on UUID because 
`*extensions.UUIDType` embeds `ExtensionBase`, which satisfies 
`arrow.NestedType` (it carries `Fields()`/`NumFields()`), so it was rejected 
before reaching the UUID support in `naturalArrowType`/`appendNatural`. 
`VariantGet` now unwraps an extension target to its storage type before the 
`NestedType` check - a fixed-size-binary-backed target (UUID) passes, actual 
struct/list storage still rejects. `VariantGet(..., AsType: 
extensions.NewUUIDType())` now round-trips. Add tests: 
`TestVariantGetUUIDTarget`; `TestVariantGetNestedTypeNotImplemented` still pins 
struct/list rejection.



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