felipecrv commented on code in PR #41575:
URL: https://github.com/apache/arrow/pull/41575#discussion_r1604226688


##########
cpp/src/arrow/testing/fixed_width_test_util.cc:
##########
@@ -0,0 +1,176 @@
+// 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.
+
+#include "fixed_width_test_util.h"
+
+namespace arrow::util::internal {
+
+namespace {
+template <typename ArrowType>
+inline Status AppendNumeric(ArrayBuilder* builder, int64_t* next_value) {
+  using NumericBuilder = ::arrow::NumericBuilder<ArrowType>;
+  using value_type = typename NumericBuilder::value_type;
+  auto* numeric_builder = 
::arrow::internal::checked_cast<NumericBuilder*>(builder);
+  auto cast_next_value =
+      static_cast<value_type>(*next_value % 
std::numeric_limits<value_type>::max());
+  RETURN_NOT_OK(numeric_builder->Append(cast_next_value));
+  *next_value += 1;
+  return Status::OK();
+}
+
+template Status AppendNumeric<Int8Type>(ArrayBuilder* builder, int64_t* 
next_value);
+template Status AppendNumeric<Int16Type>(ArrayBuilder* builder, int64_t* 
next_value);
+template Status AppendNumeric<Int32Type>(ArrayBuilder* builder, int64_t* 
next_value);
+template Status AppendNumeric<Int64Type>(ArrayBuilder* builder, int64_t* 
next_value);

Review Comment:
   You don't need these (in this context) because since this template is in an 
anon namespace the compiler will only instantiate the 4 instances that are 
referred to in this compilation unit.



##########
cpp/src/arrow/testing/fixed_width_test_util.h:
##########
@@ -0,0 +1,72 @@
+// 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.
+
+#pragma once
+
+#include <vector>
+
+#include "arrow/builder.h"
+#include "arrow/testing/visibility.h"

Review Comment:
   We should try to "include what you use" [1] as much as possible. Even when 
headers that we need are already included by other headers.
   
   - `<memory>`
   - `<functional>`
   - `<cstdint>`
   - `"arrow/type.h"` for `DataType` (complete type is needed for the pointers 
and vector declarations)
   - `"arrow/type_fwd.h"` forward-declares `ArrayBuilder` (which we don't need 
to be a complete type in the header because we only pointers/references to it 
in this header)
   
   With these included, you should be able to remove `"arrow/builder.h"` which 
is a very expensive header.
   
   [1] 
https://github.com/include-what-you-use/include-what-you-use/blob/master/docs/WhyIWYU.md



##########
cpp/src/arrow/testing/fixed_width_test_util.cc:
##########
@@ -0,0 +1,176 @@
+// 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.
+
+#include "fixed_width_test_util.h"

Review Comment:
   With the removal of include bloat in the header, you should also add all the 
includes for things referred from this file:
   
    - `"arrow/array/builder_primitive.h"` for `NumericBuilder` and 
`ArrowBuilder`
    - `"arrow/array/builder_base.h"` for `MakeBuilder` [1]
    - `<cstdint>`
    - `<limits>`
    - `<vector>`
    - `<functional>`
    - `"arrow/type.h"`
    
   [1] my header had an include to `arrow/builder.h`, but that was unnecessary 
now that I thought more about it



##########
cpp/src/arrow/testing/fixed_width_test_util.cc:
##########
@@ -0,0 +1,176 @@
+// 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.
+
+#include "fixed_width_test_util.h"

Review Comment:
   The linter is complaining about this line because includes should be fully 
qualified based on the `cpp/src/` root, so this should be 
`"arrow/testing/fixed_width_test_util.h"`



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