Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-08-28 08:27:00

0001 // Licensed to the Apache Software Foundation (ASF) under one
0002 // or more contributor license agreements.  See the NOTICE file
0003 // distributed with this work for additional information
0004 // regarding copyright ownership.  The ASF licenses this file
0005 // to you under the Apache License, Version 2.0 (the
0006 // "License"); you may not use this file except in compliance
0007 // with the License.  You may obtain a copy of the License at
0008 //
0009 //   http://www.apache.org/licenses/LICENSE-2.0
0010 //
0011 // Unless required by applicable law or agreed to in writing,
0012 // software distributed under the License is distributed on an
0013 // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
0014 // KIND, either express or implied.  See the License for the
0015 // specific language governing permissions and limitations
0016 // under the License.
0017 
0018 #pragma once
0019 
0020 #include <cstdint>
0021 #include <functional>
0022 #include <memory>
0023 #include <vector>
0024 
0025 #include "arrow/testing/visibility.h"
0026 #include "arrow/type.h"
0027 #include "arrow/type_fwd.h"
0028 
0029 namespace arrow::util::internal {
0030 
0031 class ARROW_TESTING_EXPORT NestedListGenerator {
0032  public:
0033   /// \brief Create a nested FixedSizeListType.
0034   ///
0035   /// \return `fixed_size_list(fixed_size_list(..., sizes[1]), sizes[0])`
0036   static std::shared_ptr<DataType> NestedFSLType(
0037       const std::shared_ptr<DataType>& inner_type, const std::vector<int>& sizes);
0038 
0039   /// \brief Create a nested FixedListType.
0040   ///
0041   /// \return `list(list(...))`
0042   static std::shared_ptr<DataType> NestedListType(
0043       const std::shared_ptr<DataType>& inner_type, size_t depth);
0044 
0045   static Result<std::shared_ptr<Array>> NestedFSLArray(
0046       const std::shared_ptr<DataType>& inner_type, const std::vector<int>& list_sizes,
0047       int64_t length);
0048 
0049   static Result<std::shared_ptr<Array>> NestedListArray(
0050       const std::shared_ptr<DataType>& inner_type, const std::vector<int>& list_sizes,
0051       int64_t length);
0052 
0053   /// \brief Generate all possible nested list configurations of depth 1 to max_depth.
0054   ///
0055   /// Each configuration consists of a single inner value type and a list of sizes.
0056   /// Both can be used with NestedFSLArray and NestedListArray to generate test data.
0057   ///
0058   /// The product of the list sizes and the size of the inner value type is always a power
0059   /// of 2 no greater than max_power_of_2_size. For max_depth=3 and
0060   /// max_power_of_2_size=32, this generates 108 configurations.
0061   static void VisitAllNestedListConfigurations(
0062       const std::vector<std::shared_ptr<DataType>>& inner_value_types,
0063       const std::function<void(const std::shared_ptr<DataType>&,
0064                                const std::vector<int>&)>& visit,
0065       int max_depth = 3, int max_power_of_2_size = 32);
0066 
0067  private:
0068   // Append([...[[*next_inner_value++, *next_inner_value++, ...]]...])
0069   static Status AppendNestedList(ArrayBuilder* nested_builder, const int* list_sizes,
0070                                  int64_t* next_inner_value);
0071 
0072   static Result<std::shared_ptr<Array>> NestedListArray(
0073       ArrayBuilder* nested_builder, const std::vector<int>& list_sizes, int64_t length);
0074 };
0075 
0076 }  // namespace arrow::util::internal