Skip to content

GH-46531: [C++] Add type_singleton utility function and tests.#47922

Merged
pitrou merged 1 commit into
apache:mainfrom
harshkumar-2005:ARROW-46531-type-singleton-util
Feb 18, 2026
Merged

GH-46531: [C++] Add type_singleton utility function and tests.#47922
pitrou merged 1 commit into
apache:mainfrom
harshkumar-2005:ARROW-46531-type-singleton-util

Conversation

@harshkumar-2005

@harshkumar-2005 harshkumar-2005 commented Oct 23, 2025

Copy link
Copy Markdown
Contributor

Rationale for this change

Introduce a type_singleton(Type::type id) utility to create parameter-free DataType instances (such as int32, boolean, utf8, etc.). Returns an error for parameterized types.

Are these changes tested?

Yes, by additional unit tests in type_test.cc.

Are there any user-facing changes?

No.

@github-actions

Copy link
Copy Markdown

Thanks for opening a pull request!

If this is not a minor PR. Could you open an issue for this pull request on GitHub? https://github.com/apache/arrow/issues/new/choose

Opening GitHub issues ahead of time contributes to the Openness of the Apache Arrow project.

Then could you also rename the pull request title in the following format?

GH-${GITHUB_ISSUE_ID}: [${COMPONENT}] ${SUMMARY}

or

MINOR: [${COMPONENT}] ${SUMMARY}

See also:

@harshkumar-2005

Copy link
Copy Markdown
Contributor Author

@pitrou Cl jobs are awaiting maintainer approval. Please approve to trigger the remaining checks.

@harshkumar-2005

Copy link
Copy Markdown
Contributor Author

@pitrou
This PR has 9 workflows pending approval. Kindly review and approve to initiate the workflow runs. Thank you!

@harshkumar-2005 harshkumar-2005 changed the title ARROW-46531: [C++] Add type_singleton utility function and tests GH-46531: [C++] Add type_singleton utility function and tests GH-${GITHUB_ISSUE_ID}: [${COMPONENT}] ${SUMMARY} Oct 26, 2025
@harshkumar-2005 harshkumar-2005 changed the title GH-46531: [C++] Add type_singleton utility function and tests GH-${GITHUB_ISSUE_ID}: [${COMPONENT}] ${SUMMARY} GH-46531: [C++] Add type_singleton utility function and tests. Oct 26, 2025
@github-actions

Copy link
Copy Markdown

⚠️ GitHub issue #46531 has been automatically assigned in GitHub to PR creator.

@pitrou pitrou left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for doing this @harshkumar-2005 . Please find a couple comments below.

Comment thread cpp/src/arrow/type_traits.cc Outdated
Comment thread cpp/src/arrow/type_traits.cc Outdated
Comment thread cpp/src/arrow/type_test.cc
Comment thread cpp/src/arrow/type_traits.h Outdated
@github-actions github-actions Bot added awaiting review Awaiting review awaiting committer review Awaiting committer review and removed awaiting review Awaiting review labels Feb 3, 2026
@harshkumar-2005 harshkumar-2005 force-pushed the ARROW-46531-type-singleton-util branch from a171977 to 98795b2 Compare February 3, 2026 13:23
@github-actions github-actions Bot added awaiting review Awaiting review and removed awaiting review Awaiting review awaiting committer review Awaiting committer review labels Feb 3, 2026
@pitrou

pitrou commented Feb 3, 2026

Copy link
Copy Markdown
Member

@harshkumar-2005 Are you using AI for this PR?

Comment thread cpp/src/arrow/type_test.cc Outdated

TEST(TestTypeSingleton, ParameterizedTypes) {
// Test error cases - parameterized types
std::vector<Type::type> parameterized_types = {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment here: no need to test these exhaustively, only one of them will be enough.

Comment thread cpp/src/arrow/type_traits.h Outdated
#include "arrow/type.h"
#include "arrow/util/logging_internal.h"

namespace arrow {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this change?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You still forgot to undo this.

Comment thread cpp/src/arrow/type_traits.cc Outdated
Comment thread cpp/src/arrow/type.cc Outdated
Comment thread cpp/src/arrow/type.cc Outdated

Visitor visitor;
auto status = VisitTypeIdInline(id, &visitor);
if (!status.ok()) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for this as the visitor is already returning a Status.

@github-actions github-actions Bot added awaiting committer review Awaiting committer review and removed awaiting review Awaiting review labels Feb 3, 2026
@harshkumar-2005

Copy link
Copy Markdown
Contributor Author

@harshkumar-2005 Are you using AI for this PR?

Yes, partially—for understanding a few concepts. The implementation and final code are mine.

@pitrou

pitrou commented Feb 3, 2026

Copy link
Copy Markdown
Member

@harshkumar-2005 Are you using AI for this PR?

Yes, partially—for understanding a few concepts. The implementation and final code are mine.

Ok, thanks. I was asking because your latest changes seemed unfinished and don't compile at all on CI.

@pitrou pitrou left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@harshkumar-2005 Here are a couple more suggestions. Also, please review and build your own code before submitting, as some changes probably break compilation.

Comment thread cpp/src/arrow/type.h Outdated
Comment thread cpp/src/arrow/type_test.cc Outdated
Comment on lines +69 to +71
ASSERT_TRUE(type->Equals(*test_case.second))
<< "Failed on type " << test_case.first << ". Expected "
<< test_case.second->ToString() << " but got " << type->ToString();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested improvement: you can use AssertTypeEqual to automate the generation of a nice error message if the types don't match.

Comment thread cpp/src/arrow/type_test.cc Outdated
Comment thread cpp/src/arrow/type_test.cc Outdated
testing::HasSubstr("is not a parameter-free singleton type"));
}

TEST(TestTypeSingleton, InvalidType) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this test is useful, passing an invalid type id is a programming error.

Comment thread cpp/src/arrow/type.cc Outdated
Comment thread cpp/src/arrow/type_test.cc Outdated
#include "arrow/type_traits.h"
#include "arrow/util/checked_cast.h"
#include "arrow/util/key_value_metadata.h"
#include "arrow/util/logging.h"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This include doesn't seem actually used?

#include "arrow/type.h"
#include "arrow/util/logging_internal.h"

namespace arrow {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You still forgot to undo this.

Comment thread cpp/src/arrow/type_traits.cc Outdated

#include "arrow/type_traits.h"

#include "arrow/type.h"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure why this addition is required?

Comment thread cpp/src/arrow/type_traits.h Outdated
#include <type_traits>
#include <vector>

#include "arrow/result.h"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why these additions? Let's remove them.

@github-actions

Copy link
Copy Markdown

⚠️ GitHub issue #46531 has been automatically assigned in GitHub to PR creator.

1 similar comment
@github-actions

Copy link
Copy Markdown

⚠️ GitHub issue #46531 has been automatically assigned in GitHub to PR creator.

@pitrou pitrou force-pushed the ARROW-46531-type-singleton-util branch from a10dfb1 to 4bb9a23 Compare February 18, 2026 14:55
@pitrou pitrou force-pushed the ARROW-46531-type-singleton-util branch from 4bb9a23 to 0a87cce Compare February 18, 2026 14:56
@pitrou

pitrou commented Feb 18, 2026

Copy link
Copy Markdown
Member

I've pushed some updates to fix compilation and simplify the implementation. Will merge if green.

@pitrou pitrou merged commit 99984fd into apache:main Feb 18, 2026
55 checks passed
@pitrou pitrou removed the awaiting committer review Awaiting committer review label Feb 18, 2026
@harshkumar-2005 harshkumar-2005 deleted the ARROW-46531-type-singleton-util branch February 18, 2026 18:55
@conbench-apache-arrow

Copy link
Copy Markdown

After merging your PR, Conbench analyzed the 1 benchmarking run that has been run so far on merge-commit 99984fd.

There was 1 benchmark result indicating a performance regression:

The full Conbench report has more details. It also includes information about 37 possible false positives for unstable benchmarks that are known to sometimes produce them.

@conbench-apache-arrow

Copy link
Copy Markdown

After merging your PR, Conbench analyzed the 3 benchmarking runs that have been run so far on merge-commit 99984fd.

There were 3 benchmark results indicating a performance regression:

The full Conbench report has more details. It also includes information about 14 possible false positives for unstable benchmarks that are known to sometimes produce them.

@harshkumar-2005

Copy link
Copy Markdown
Contributor Author

Thanks for the merge! I noticed the performance alerts on both the ARM and Intel runners for file-read. I'm setting up some local benchmarks to verify this. Before I go too deep into the profiling, I’m curious if these Python benchmarks are known to be sensitive to the recent changes in [mention a related area, e.g., memory management/IPC]. Any thoughts on whether this looks like genuine regression vs. environment noise would be highly valued.

@pitrou

pitrou commented Feb 23, 2026

Copy link
Copy Markdown
Member

Hi @harshkumar-2005 , those performance alerts are certainly false positives since we haven't touched any performance-sensitive codepaths. You probably needn't bother.

Mottl pushed a commit to Mottl/arrow that referenced this pull request May 26, 2026
…pache#47922)

### Rationale for this change

Introduce a `type_singleton(Type::type id)` utility to create parameter-free DataType instances (such as int32, boolean, utf8, etc.). Returns an error for parameterized types.

### Are these changes tested?

Yes, by additional unit tests in `type_test.cc`.

### Are there any user-facing changes?

No.

* GitHub Issue: apache#46531

Authored-by: Harsh <kumarharsh93982@gmail.com>
Signed-off-by: Antoine Pitrou <antoine@python.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants