Skip to content

Add Tuple Element Names to TupleType#491

Open
IyeOnline wants to merge 3 commits intoClickHouse:masterfrom
IyeOnline:topic/tuple-names
Open

Add Tuple Element Names to TupleType#491
IyeOnline wants to merge 3 commits intoClickHouse:masterfrom
IyeOnline:topic/tuple-names

Conversation

@IyeOnline
Copy link
Copy Markdown
Contributor

@IyeOnline IyeOnline commented Apr 29, 2026

This extends the type parser to support an element name alongside the
element type and wires this through to make the field names in TupleType
available in the C++ API.

This extends the type parser to support an element name alongside the
element type and wires this through to make the field names in a tuple
available in the C++ API.
slabko
slabko previously approved these changes Apr 30, 2026
Copy link
Copy Markdown
Contributor

@slabko slabko left a comment

Choose a reason for hiding this comment

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

@IyeOnline

Thank you very much for your PR. This absolutely makes sense and is well implemented. I’ve added a couple of points; they’re not critical, so feel free to ignore them if you don’t have time to address them. You can go ahead and merge, and I’ll take care of the remaining required changes.

Comment thread clickhouse/types/types.h
Comment on lines +34 to +36
/// Name of this element inside its parent (e.g. field name inside a named
/// Tuple). Empty for unnamed elements.
std::string element_name;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think it would make more sense to add a vector here, called all_names, store both the name and the type in it, and keep the name field set to the last value as it currently works.

/// Type's name.
/// Need to cache TypeAst, so can't use StringView for name.
std::string name;
/// List of all names assigned to the element, for example 
/// named tuples, have name and type, `Tuple(i Int64, s String)`.
std::vector<std::string> all_names

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Personally I dont really like that, because it

  • Creates two spots containing the same information
  • Does not make it clear through the type-system/name that the entries in all_names are rather different entities (field name, vs type name)

Comment thread clickhouse/types/types.cpp Outdated
Comment thread clickhouse/types/types.cpp
Comment thread clickhouse/columns/tuple.cpp Outdated
Comment thread clickhouse/columns/tuple.cpp Outdated

/// Tuple types can be appended if they have the same shape and
/// the to-be-appended type has the same names or is entirely unnamed.
static bool CanAppendType(const TypeRef& destination_type, const TypeRef& source_type) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Not a big deal at all, but it might be worth considering making this a member function. It could help avoid any confusion between the source and destination, and would keep the interface to a single parameter - the type to append. Also it looks like the project tends to use anonymous namespaces rather than static for internal linkage.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The problem is that we need to support recursion, so unless we extend the generic Type or TupleType interface, this cant work.

I don't want to introduce a concept of "type similarity" in this PR, so I think its best to just stay with the free function.

Comment thread clickhouse/types/types.cpp Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Provide nested field names for Tuple

2 participants