@@ -377,12 +377,15 @@ constexpr bool is_nested_kind(TypeKind kind) {
377377template <TypeKind KIND >
378378struct TypeFactory ;
379379
380- #define VELOX_FLUENT_CAST (NAME, KIND ) \
380+ #define VELOX_TYPE_AS (NAME, KIND ) \
381381 const typename TypeTraits<TypeKind::KIND >::ImplType& as##NAME () const { \
382382 return this ->as <TypeKind::KIND >(); \
383- } \
384- virtual bool is##NAME () const { \
385- return this ->kind () == TypeKind::KIND ; \
383+ }
384+
385+ #define VELOX_FLUENT_CAST (NAME, KIND ) \
386+ VELOX_TYPE_AS (NAME , KIND ) \
387+ bool is##NAME () const { \
388+ return this ->kind () == TypeKind::KIND ; \
386389 }
387390
388391class Type ;
@@ -627,9 +630,14 @@ class Type : public Tree<const TypePtr>, public velox::ISerializable {
627630 VELOX_FLUENT_CAST (Boolean, BOOLEAN )
628631 VELOX_FLUENT_CAST (Tinyint, TINYINT )
629632 VELOX_FLUENT_CAST (Smallint, SMALLINT )
630- VELOX_FLUENT_CAST (Integer, INTEGER )
631- VELOX_FLUENT_CAST (Bigint, BIGINT )
632- VELOX_FLUENT_CAST (Hugeint, HUGEINT )
633+
634+ VELOX_TYPE_AS (Integer, INTEGER )
635+ VELOX_TYPE_AS (Bigint, BIGINT )
636+ VELOX_TYPE_AS (Hugeint, HUGEINT )
637+ bool isInteger () const ;
638+ bool isBigint () const ;
639+ bool isHugeint () const ;
640+
633641 VELOX_FLUENT_CAST (Real, REAL )
634642 VELOX_FLUENT_CAST (Double, DOUBLE )
635643 VELOX_FLUENT_CAST (Varchar, VARCHAR )
@@ -682,6 +690,7 @@ class Type : public Tree<const TypePtr>, public velox::ISerializable {
682690 const bool providesCustomComparison_;
683691};
684692
693+ #undef VELOX_TYPE_AS
685694#undef VELOX_FLUENT_CAST
686695
687696template <TypeKind KIND , typename = void >
@@ -817,6 +826,18 @@ class ScalarType : public CanProvideCustomComparisonType<KIND> {
817826 }
818827};
819828
829+ FOLLY_ALWAYS_INLINE bool Type::isInteger () const {
830+ return typeid (*this ) == typeid (ScalarType<TypeKind::INTEGER >);
831+ }
832+
833+ FOLLY_ALWAYS_INLINE bool Type::isBigint () const {
834+ return typeid (*this ) == typeid (ScalarType<TypeKind::BIGINT >);
835+ }
836+
837+ FOLLY_ALWAYS_INLINE bool Type::isHugeint () const {
838+ return typeid (*this ) == typeid (ScalarType<TypeKind::HUGEINT >);
839+ }
840+
820841// / This class represents the fixed-point numbers.
821842// / The parameter "precision" represents the number of digits the
822843// / Decimal Type can support and "scale" represents the number of digits to
@@ -828,14 +849,6 @@ class DecimalType : public ScalarType<KIND> {
828849 static constexpr uint8_t kMaxPrecision = KIND == TypeKind::BIGINT ? 18 : 38 ;
829850 static constexpr uint8_t kMinPrecision = KIND == TypeKind::BIGINT ? 1 : 19 ;
830851
831- bool isBigint () const override {
832- return false ;
833- }
834-
835- bool isHugeint () const override {
836- return false ;
837- }
838-
839852 inline bool equivalent (const Type& other) const override {
840853 if (!Type::hasSameTypeId (other)) {
841854 return false ;
@@ -1431,10 +1444,6 @@ class IntervalDayTimeType final : public BigintType {
14311444 return this == &other;
14321445 }
14331446
1434- bool isBigint () const override {
1435- return false ;
1436- }
1437-
14381447 std::string toString () const override {
14391448 return name ();
14401449 }
@@ -1491,10 +1500,6 @@ class IntervalYearMonthType final : public IntegerType {
14911500 return name ();
14921501 }
14931502
1494- bool isInteger () const override {
1495- return false ;
1496- }
1497-
14981503 // / Returns the interval 'value' (months) formatted as YEARS MONTHS.
14991504 // / For example, 14 months (INTERVAL '1-2' YEAR TO MONTH) would be
15001505 // / represented as 1-2; -14 months would be represents as -1-2.
@@ -1540,10 +1545,6 @@ class DateType final : public IntegerType {
15401545 return this == &other;
15411546 }
15421547
1543- bool isInteger () const override {
1544- return false ;
1545- }
1546-
15471548 std::string toString () const override {
15481549 return name ();
15491550 }
0 commit comments