Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GH-39864: [C++] DataType::ToString support optionally show metadata #39888

Merged
merged 9 commits into from
Feb 27, 2024

Conversation

Cerdore
Copy link
Contributor

@Cerdore Cerdore commented Feb 1, 2024

Rationale for this change

Support showing metadata of nested DataType which have child fields.

What changes are included in this PR?

Add an optional argument "show_metadata" to the ToString() of DataType and other DataType derived class. And we also add it to TypeHolder::ToString().

Are these changes tested?

Yes, I add tests for changes.

Are there any user-facing changes?

No.

Closes: #39864

@github-actions github-actions bot added the awaiting review Awaiting review label Feb 1, 2024
Copy link

github-actions bot commented Feb 1, 2024

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

@Cerdore
Copy link
Contributor Author

Cerdore commented Feb 1, 2024

MapType::ToString() don't show the metadata currently. It use type().ToString() and field.name().

I didn't change here.

  const auto print_field_name = [](std::ostream& os, const Field& field,
                                   const char* std_name) {
    if (field.name() != std_name) {
      os << " ('" << field.name() << "')";
    }
  };
  const auto print_field = [&](std::ostream& os, const Field& field,
                               const char* std_name) {
    os << field.type()->ToString(show_metadata);
    print_field_name(os, field, std_name);
  };

cpp/src/arrow/type_test.cc Outdated Show resolved Hide resolved
@github-actions github-actions bot added awaiting committer review Awaiting committer review and removed awaiting review Awaiting review labels Feb 4, 2024
Copy link
Member

@westonpace westonpace left a comment

Choose a reason for hiding this comment

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

This looks like a reasonable addition to me. I think those python test failures might be relevant though (looks like the gdb extension might be calling ToString somewhere and need to explicitly pass a show_metadata arg)

@github-actions github-actions bot added awaiting changes Awaiting changes and removed awaiting committer review Awaiting committer review labels Feb 5, 2024
Copy link
Member

@pitrou pitrou left a comment

Choose a reason for hiding this comment

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

Can you also change AssertTypeEqual so that it shows the metadata on error?

@github-actions github-actions bot added awaiting change review Awaiting change review and removed awaiting changes Awaiting changes labels Feb 7, 2024
@Cerdore
Copy link
Contributor Author

Cerdore commented Feb 7, 2024

Can you also change AssertTypeEqual so that it shows the metadata on error?

AssertTypeEqual(ty1, ty2, /*check_metadata*/true);
Should I do it above way or modify the implementation of AssertTypeEqual?

@pitrou
Copy link
Member

pitrou commented Feb 7, 2024

I mean change these now that DataType::ToString accepts a show_metadata argument:

template <typename T>
std::string ToStringWithMetadata(const T& t, bool show_metadata) {
return t.ToString(show_metadata);
}
std::string ToStringWithMetadata(const DataType& t, bool show_metadata) {
return t.ToString();
}

@Cerdore
Copy link
Contributor Author

Cerdore commented Feb 7, 2024

I mean change these now that DataType::ToString accepts a show_metadata argument:

Thank you! I see.

Comment on lines 240 to 242
std::string ToStringWithMetadata(const DataType& t, bool show_metadata) {
return t.ToString();
return t.ToString(show_metadata);
}
Copy link
Member

Choose a reason for hiding this comment

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

Thanks, but this can actually be simplified now. ToStringWithMetadata was created because DataType::ToString didn't support the show_metadata argument. Now that it does, ToStringWithMetadata can probably be suppressed and all calls to ToStringWithMetadata(t, show_metadata) replaced with t.ToString(show_metadata).

xiansen.chen and others added 8 commits February 27, 2024 17:12
Signed-off-by: xiansen.chen <xiansen.chen@openpie.com>
Signed-off-by: xiansen.chen <xiansen.chen@openpie.com>
Signed-off-by: xiansen.chen <xiansen.chen@openpie.com>
Signed-off-by: xiansen.chen <xiansen.chen@openpie.com>
Signed-off-by: xiansen.chen <xiansen.chen@openpie.com>
Signed-off-by: xiansen.chen <xiansen.chen@openpie.com>
Signed-off-by: xiansen.chen <xiansen.chen@openpie.com>
Copy link
Member

@pitrou pitrou left a comment

Choose a reason for hiding this comment

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

I've made a few minor changes. Thanks @Cerdore for tackling this, I'll be merging this PR if CI passes.

@pitrou pitrou merged commit c5f60a0 into apache:main Feb 27, 2024
33 of 34 checks passed
@pitrou pitrou removed the awaiting change review Awaiting change review label Feb 27, 2024
Copy link

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

There were no benchmark performance regressions. 🎉

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

zanmato1984 pushed a commit to zanmato1984/arrow that referenced this pull request Feb 28, 2024
…data (apache#39888)

### Rationale for this change

Support showing metadata of  nested DataType which have child fields.

### What changes are included in this PR?

Add an optional argument "show_metadata" to the ToString() of DataType and other DataType derived class. And we also  add it to TypeHolder::ToString().

### Are these changes tested?

Yes, I add tests for changes.

### Are there any user-facing changes?
No.

Closes: apache#39864
* Closes: apache#39864

Lead-authored-by: xiansen.chen <xiansen.chen@openpie.com>
Co-authored-by: Antoine Pitrou <antoine@python.org>
Signed-off-by: Antoine Pitrou <antoine@python.org>
@Cerdore
Copy link
Contributor Author

Cerdore commented Mar 1, 2024

I've made a few minor changes. Thanks @Cerdore for tackling this, I'll be merging this PR if CI passes.

Sorry, I've been busy with some other things lately... And thank you very much for your suggestions and subsequent changes!

thisisnic pushed a commit to thisisnic/arrow that referenced this pull request Mar 8, 2024
…data (apache#39888)

### Rationale for this change

Support showing metadata of  nested DataType which have child fields.

### What changes are included in this PR?

Add an optional argument "show_metadata" to the ToString() of DataType and other DataType derived class. And we also  add it to TypeHolder::ToString().

### Are these changes tested?

Yes, I add tests for changes.

### Are there any user-facing changes?
No.

Closes: apache#39864
* Closes: apache#39864

Lead-authored-by: xiansen.chen <xiansen.chen@openpie.com>
Co-authored-by: Antoine Pitrou <antoine@python.org>
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.

[C++] DataType::ToString should optionally show metadata
4 participants