ts.sum() | Teradata R Package - 17.00 - ts.sum() - Teradata R Package

Teradata® R Package User Guide

prodname
Teradata R Package
vrm_release
17.00
created_date
November 2020
category
User Guide
featnum
B700-4005-090K

The aggregate function ts.sum() returns the sum of values in the column grouped by time.

Nulls are not included in the result computation.
Arguments:
  • value.expression: Specify the column for which sum is to be computed.

Use ts.sum(distinct(column_name)) to exclude duplicate rows while calculating sum.

Example 1: Calculate the sum of the values of the 'temperature' column of sequenced PTI table

  • Calculate the sum.
    > df_seq_sum <- df_seq_grp %>% summarise(sum_temp = ts.sum(temperature))
  • Print the results.
    > df_seq_sum %>% arrange(TIMECODE_RANGE, buoyid, sum_temp)
    # Source:     lazy query [?? x 4]
    # Database:   [Teradata 16.20.50.01] [Teradata Native Driver 17.0.0.2]
    #   [TDAPUSER@<hostname>/TDAPUSERDB]
    # Ordered by: TIMECODE_RANGE, buoyid, sum_temp
      TIMECODE_RANGE                                     `GROUP BY TIME(MINUTES(~ buoyid sum_temp
      <chr>                                              <int64>                   <int>    <int>
    1 2014-01-06 08:00:00.000000+00:00,2014-01-06 08:30~ 35345                         0      219
    2 2014-01-06 09:00:00.000000+00:00,2014-01-06 09:30~ 35347                         1      447
    3 2014-01-06 10:00:00.000000+00:00,2014-01-06 10:30~ 35349                        44      539
    4 2014-01-06 10:30:00.000000+00:00,2014-01-06 11:00~ 35350                        22       23
    5 2014-01-06 10:30:00.000000+00:00,2014-01-06 11:00~ 35350                        44       86
    6 2014-01-06 21:00:00.000000+00:00,2014-01-06 21:30~ 35371                         2      243

Example 2: Calculate the sum of the values of the 'temperature' column of non-PTI table

  • Calculate the sum.
    > df_nonpti_sum <- df_nonpti %>% group_by_time(timebucket.duration = "10m", timecode.column = "TIMECODE") %>% summarise(sum_temp = ts.sum(temperature))
  • Print the results.
    > df_nonpti_sum %>% arrange(TIMECODE_RANGE, sum_temp)
    # Source:     lazy query [?? x 3]
    # Database:   [Teradata 16.20.50.01] [Teradata Native Driver 17.0.0.2]
    #   [TDAPUSER@<hostname>/TDAPUSERDB]
    # Ordered by: TIMECODE_RANGE, sum_temp
      TIMECODE_RANGE                                           `GROUP BY TIME(MINUTES(1~ sum_temp
      <chr>                                                    <int64>                      <int>
    1 2014-01-06 08:00:00.000000+00:00,2014-01-06 08:10:00.00~ 2314993                        109
    2 2014-01-06 08:10:00.000000+00:00,2014-01-06 08:20:00.00~ 2314994                        110
    3 2014-01-06 09:00:00.000000+00:00,2014-01-06 09:10:00.00~ 2314999                        447
    4 2014-01-06 10:00:00.000000+00:00,2014-01-06 10:10:00.00~ 2315005                        496
    5 2014-01-06 10:10:00.000000+00:00,2014-01-06 10:20:00.00~ 2315006                         43
    6 2014-01-06 10:30:00.000000+00:00,2014-01-06 10:40:00.00~ 2315008                         43
    7 2014-01-06 10:50:00.000000+00:00,2014-01-06 11:00:00.00~ 2315010                         43
    8 2014-01-06 21:00:00.000000+00:00,2014-01-06 21:10:00.00~ 2315071                        243