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

Add to_human_size and to_human_duration function

    XMLWordPrintableJSON

Details

    • New Feature
    • Status: Open
    • Normal
    • Resolution: Unresolved
    • 5.x
    • Legacy/CQL
    • None
    • Operability
    • Normal
    • All
    • None
    • Hide

      ci

      Show
      ci

    Description

      There are cases (e.g in our system_views tables but might be applicable for user tables as well) when a column is of a type which represents number of bytes. However, it is quite hard to parse a value for a human to have some estimation what that value is.

      I propose this:

      cqlsh> select * from myks.mytb ;
      
       id | col1 | col2 | col3 | col4     
      ----+------+------+------+----------
        1 |  100 |  200 |  300 | 32432423 
      
      (1 rows)
      cqlsh> select to_human_size(col4) from myks.mytb where id = 1;
      
       system.to_human_size(col4)
      ----------------------
                  30.93 MiB
      
      (1 rows)
      cqlsh> select to_human_size(col4,0) from myks.mytb where id = 1;
      
       system.to_human_size(col4, 0)
      -------------------------
                        31 MiB
      
      (1 rows)
      cqlsh> select to_human_size(col4,1) from myks.mytb where id = 1;
      
       system.to_human_size(col4, 1)
      -------------------------
                      30.9 MiB
      
      (1 rows)
      
      

      The second argument is optional and represents the number of decimal places (at most) to use. Without the second argument, it will default to FileUtils.df which is "#.##" format.

      cqlsh> DESCRIBE myks.mytb ;
      
      CREATE TABLE myks.mytb (
      id int PRIMARY KEY,
      col1 int,
      col2 smallint,
      col3 bigint,
      col4 varint,
      )
      

      I also propose that this to_human_size function (name of it might be indeed discussed and it is just a suggestion) should be only applicable for int, smallint, bigint and varint types. I am not sure how to apply this to e.g. "float" or similar. As I mentioned, it is meant to convert just number of bytes, which is just some number, to a string representation of that and I do not think that applying that function to anything else but these types makes sense.

      Attachments

        Activity

          People

            Unassigned Unassigned
            smiklosovic Stefan Miklosovic
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:

              Time Tracking

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