Uploaded image for project: 'Cassandra'
  1. Cassandra
  2. CASSANDRA-18060

Add aggregation scalar functions on collections

    XMLWordPrintableJSON

Details

    • New Feature
    • Status: Resolved
    • Normal
    • Resolution: Fixed
    • 5.0-alpha1, 5.0
    • CQL/Semantics
    • None

    Description

      The new mechanism for dynamically building native functions introduced by CASSANDRA-17811 can be used to provide within-collection aggregation functions. We can use that mechanism to add new CQL functions to get:

      • The number of items in a collection.
      • The max/min items of a collection.
      • The sum/avg of the items of a numeric collection.
      • The keys or the values of a map.

      For example:

      CREATE TABLE k.t (k int PRIMARY KEY, l list<int>, m map<int, int>);
      INSERT INTO t(k, l, m) VALUES (0, [1, 2, 3], {1:10, 2:20, 3:30});
      
      > SELECT map_keys(m), map_values(m) FROM t;
      
       system.map_keys(m) | system.map_values(m)
      --------------------+----------------------
                {1, 2, 3} |         [10, 20, 30]
      
      > SELECT collection_count(m), collection_count(l) FROM t;
      
       system.collection_count(m) | system.collection_count(l)
      ----------------------------+----------------------------
                                3 |                          3
      
      > SELECT collection_min(l), collection_max(l) FROM t;
      
       system.collection_min(l) | system.collection_max(l)
      --------------------------+--------------------------
                              1 |                        3
      
      > SELECT collection_sum(l), collection_avg(l) FROM t;
      
       system.collection_sum(l) | system.collection_avg(l)
      --------------------------+--------------------------
                              6 |                        2
      

      Note that this type of aggregation is different from the kind of aggregation provided by min, max, sum and avg, which aggregate entire collections across rows. Here we only aggregate the items of a collection row per row.

      Attachments

        Issue Links

          Activity

            People

              adelapena Andres de la Peña
              adelapena Andres de la Peña
              Andres de la Peña
              Berenguer Blasi
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 1h 40m
                  1h 40m