[MDEV-21392] Cleanup redundant overriding in Item_sum_num Created: 2019-12-25  Updated: 2020-06-01  Resolved: 2019-12-25

Status: Closed
Project: MariaDB Server
Component/s: Data types
Fix Version/s: 10.3.22, 10.4.12, 10.5.1

Type: Task Priority: Major
Reporter: Alexander Barkov Assignee: Alexander Barkov
Resolution: Fixed Votes: 0
Labels: None

Issue Links:
Blocks
blocks MDEV-21071 Data type cleanups Open
Relates
relates to MDEV-4912 Data type plugin API version 1 Closed
relates to MDEV-20280 PERCENTILE_DISC() rejects temporal an... Closed

 Description   

Item_sum_num has features of DOUBLE data type by default and implements DOUBLE-applicable methods:

  • val_int()
  • val_str()
  • val_decimal()

These methods then are overriden to INT-applicable and hybrid-applicable as follows:

  • Item_sum_int overrides these methods to INT-applicable.
  • Item_sum_window_with_row_count derives DOUBLE-applicable implementations from Item_sum_num.
  • Item_sum_ntile derives DOUBLE-applicable implementations from Item_sum_window_with_row_count and overrides val_real() to INT-based implementation. Note, Item_sum_ntile does not override val_decimal() and val_str(), which looks wrong because they work through val_real() by default and therefore may return truncated results on a huge data sets.
  • Item_sum_cume_dist derives from Item_sum_window_with_row_count.
  • Item_sum_percentile_disc derives from Item_sum_cume_dist and Type_handler_hybrid_field_type and overrides value methods to hybrid-applicable, except get_date().
  • Item_sum_percentile_cont derives from Item_sum_cume_dist and Type_handler_hybrid_field_type, but in fact it can olny have the DOUBLE data type.

This multiple overriding is hard to follow. Let's introduce a new abstract class Item_sum_double and change the Item_sum_num hierarchy as follows:

Item_sum_num
  Item_sum_percentile_disc  -- hybrid type
  Item_sum_sum              -- hybrid type
    Item_sum_avg
  Item_sum_double           -- DOUBLE
    Item_sum_percent_rank
    Item_sum_cume_dist
    Item_sum_percentile_cont
    Item_sum_variance
      Item_sum_std
    Item_sum_udf_float
    Item_sum_udf_int
    Item_sum_udf_decimal
    Item_sum_udf_str
  Item_sum_int              -- INT
    Item_sum_row_number
    Item_sum_rank
    Item_sum_dense_rank
    Item_sum_ntile
    Item_sum_count
    Item_sum_bit
      Item_sum_or
      Item_sum_and
      Item_sum_xor

so that the method type_handler() and value methods like val_int(), val_real(), val_decimal(), get_date() are implemented inside the same class, without multiple nested overriding.


Generated at Thu Feb 08 09:06:47 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.