diff --git a/velox/vector/BaseVector.h b/velox/vector/BaseVector.h index 18f5725d4e76..ec9ce0a0d883 100644 --- a/velox/vector/BaseVector.h +++ b/velox/vector/BaseVector.h @@ -145,6 +145,28 @@ class BaseVector { return static_cast(this); } + template + T* asChecked() { + auto* casted = as(); + VELOX_CHECK_NOT_NULL( + casted, + "Wrong type cast expected {}, but got {}", + typeid(T).name(), + typeid(*this).name()); + return casted; + } + + template + const T* asChecked() const { + auto* casted = as(); + VELOX_CHECK_NOT_NULL( + casted, + "Wrong type cast expected {}, but got {}", + typeid(T).name(), + typeid(*this).name()); + return casted; + } + template const FlatVector* asFlatVector() const { return dynamic_cast*>(this);