Visitor pattern for Iceberg types Adapted from Apache Arrow https://github.com/apache/arrow/blob/main/cpp/src/arrow/visit_type_inline.h.
More...
#include <utility>
#include "iceberg/result.h"
#include "iceberg/type.h"
#include "iceberg/util/checked_cast.h"
#include "iceberg/util/visitor_generate.h"
Go to the source code of this file.
|
| template<typename VISITOR , typename... ARGS> |
| Status | iceberg::VisitTypeInline (const Type &type, VISITOR *visitor, ARGS &&... args) |
| | Calls visitor with the corresponding concrete type class.
|
| |
| template<typename VISITOR , typename... ARGS> |
| auto | iceberg::VisitType (const Type &type, VISITOR &&visitor, ARGS &&... args) -> decltype(std::forward< VISITOR >(visitor)(type, args...)) |
| | Call visitor with the corresponding concrete type class.
|
| |
| template<typename VISITOR , typename... ARGS> |
| Status | iceberg::VisitTypeIdInline (TypeId id, VISITOR *visitor, ARGS &&... args) |
| | Calls visitor with a nullptr of the corresponding concrete type class.
|
| |
| template<typename VISITOR , typename... ARGS> |
| auto | iceberg::VisitTypeCategory (const Type &type, VISITOR *visitor, ARGS &&... args) |
| | Visit a type using a categorical visitor pattern.
|
| |
◆ SCHEMA_VISIT_ACTION
| #define SCHEMA_VISIT_ACTION |
( |
|
TYPE_CLASS | ) |
|
Value: return visitor->Visit##TYPE_CLASS( \
internal::checked_cast<const TYPE_CLASS##Type&>(type), \
std::forward<ARGS>(args)...);
◆ TYPE_ID_VISIT_INLINE
| #define TYPE_ID_VISIT_INLINE |
( |
|
TYPE_CLASS | ) |
|
Value: case TYPE_CLASS##Type::kTypeId: { \
const TYPE_CLASS##Type* concrete_ptr = nullptr; \
return visitor->Visit(concrete_ptr, std::forward<ARGS>(args)...); \
}
◆ TYPE_VISIT_INLINE [1/2]
| #define TYPE_VISIT_INLINE |
( |
|
TYPE_CLASS | ) |
|
Value: case TYPE_CLASS##Type::kTypeId: \
return visitor->Visit( \
iceberg::internal::checked_cast<const TYPE_CLASS##Type&>(type), \
std::forward<ARGS>(args)...);
◆ TYPE_VISIT_INLINE [2/2]
| #define TYPE_VISIT_INLINE |
( |
|
TYPE_CLASS | ) |
|
Value: case TYPE_CLASS##Type::kTypeId: \
return std::forward<VISITOR>(visitor)( \
internal::checked_cast<const TYPE_CLASS##Type&>(type), \
std::forward<ARGS>(args)...);
◆ VisitType()
template<typename VISITOR , typename... ARGS>
| auto iceberg::VisitType |
( |
const Type & |
type, |
|
|
VISITOR && |
visitor, |
|
|
ARGS &&... |
args |
|
) |
| -> decltype(std::forward<VISITOR>(visitor)(type, args...)) |
|
inline |
Call visitor with the corresponding concrete type class.
- Template Parameters
-
| ARGS | Additional arguments, if any, will be passed to the Visit function after the type argument |
Unlike VisitTypeInline which calls visitor.Visit, here visitor itself is called. visitor must support a const Type& argument as a fallback, in addition to concrete type classes.
The intent is for this to be called on a generic lambda that may internally use if constexpr or similar constructs.
◆ VisitTypeCategory()
template<typename VISITOR , typename... ARGS>
| auto iceberg::VisitTypeCategory |
( |
const Type & |
type, |
|
|
VISITOR * |
visitor, |
|
|
ARGS &&... |
args |
|
) |
| |
|
inline |
Visit a type using a categorical visitor pattern.
This function provides a simplified visitor interface that groups Iceberg types into four categories based on their structural properties:
- Struct types: Complex types with named fields (StructType)
- List types: Sequential container types (ListType)
- Map types: Key-value container types (MapType)
- Primitive types: All leaf types without nested structure (14 primitive types)
This grouping is useful for algorithms that need to distinguish between container types and leaf types, but don't require separate handling for each primitive type variant (e.g., Int vs Long vs String).
- Template Parameters
-
| VISITOR | Visitor class that must implement four Visit methods:
VisitStruct(const StructType&, ARGS...) for struct types
VisitList(const ListType&, ARGS...) for list types
VisitMap(const MapType&, ARGS...) for map types
VisitPrimitive(const PrimitiveType&, ARGS...) for all primitive types
|
| ARGS | Additional argument types forwarded to Visit methods |
- Parameters
-
| type | The type to visit |
| visitor | Pointer to the visitor instance |
| args | Additional arguments forwarded to the Visit methods |
- Returns
- The return value from the invoked Visit method
◆ VisitTypeIdInline()
template<typename VISITOR , typename... ARGS>
| Status iceberg::VisitTypeIdInline |
( |
TypeId |
id, |
|
|
VISITOR * |
visitor, |
|
|
ARGS &&... |
args |
|
) |
| |
|
inline |
Calls visitor with a nullptr of the corresponding concrete type class.
- Template Parameters
-
| VISITOR | Visitor type that implements Visit() for all Iceberg types. |
| ARGS | Additional arguments, if any, will be passed to the Visit function after the type argument |
- Returns
- Status
◆ VisitTypeInline()
template<typename VISITOR , typename... ARGS>
| Status iceberg::VisitTypeInline |
( |
const Type & |
type, |
|
|
VISITOR * |
visitor, |
|
|
ARGS &&... |
args |
|
) |
| |
|
inline |
Calls visitor with the corresponding concrete type class.
- Template Parameters
-
| VISITOR | Visitor type that implements Visit() for all Iceberg types. |
| ARGS | Additional arguments, if any, will be passed to the Visit function after the type argument |
- Returns
- Status
A visitor is a type that implements specialized logic for each Iceberg type. Example usage:
class ExampleVisitor {
Status Visit(const IntType& type) { ... }
Status Visit(const LongType& type) { ... }
...
}
ExampleVisitor visitor;
Status VisitTypeInline(const Type &type, VISITOR *visitor, ARGS &&... args)
Calls visitor with the corresponding concrete type class.
Definition visit_type.h:63