Uploaded image for project: 'Phoenix'
  1. Phoenix
  2. PHOENIX-476

Support declaration of DEFAULT in CREATE statement

    XMLWordPrintableJSON

Details

    • New Feature
    • Status: Resolved
    • Resolution: Fixed
    • 3.0-Release
    • 4.9.0
    • None
    • None
    • 345

    Description

      Support the declaration of a default value in the CREATE TABLE/VIEW statement like this:

      CREATE TABLE Persons (
      Pid int NOT NULL PRIMARY KEY,
      LastName varchar(255) NOT NULL,
      FirstName varchar(255),
      Address varchar(255),
      City varchar(255) DEFAULT 'Sandnes'
      )

      To implement this, we'd need to:

      1. add a new DEFAULT_VALUE key value column in SYSTEM.TABLE and pass through the value when the table is created (in MetaDataClient).
      2. always set NULLABLE to ResultSetMetaData.columnNoNulls if a default value is present, since the column will never be null.
      3. add a getDefaultValue() accessor in PColumn
      4. for a row key column, during UPSERT use the default value if no value was specified for that column. This could be done in the PTableImpl.newKey method.
      5. for a key value column with a default value, we can get away without incurring any storage cost. Although a little bit of extra effort than if we persisted the default value on an UPSERT for key value columns, this approach has the benefit of not incurring any storage cost for a default value.

      • serialize any default value into KeyValueColumnExpression
      • in the evaluate method of KeyValueColumnExpression, conditionally use the default value if the column value is not present. If doing partial evaluation, you should not yet return the default value, as we may not have encountered the the KeyValue for the column yet (since a filter evaluates each time it sees each KeyValue, and there may be more than one KeyValue referenced in the expression). Partial evaluation is determined by calling Tuple.isImmutable(), where false means it is NOT doing partial evaluation, while true means it is.
      • modify EvaluateOnCompletionVisitor by adding a visitor method for RowKeyColumnExpression and KeyValueColumnExpression to set evaluateOnCompletion to true if they have a default value specified. This will cause filter evaluation to execute one final time after all KeyValues for a row have been seen, since it's at this time we know we should use the default value.

      Attachments

        1. PHOENIX-476.12.patch
          97 kB
          James R. Taylor
        2. PHOENIX-476.11.patch
          87 kB
          Kevin Liew
        3. PHOENIX-476.10.patch
          87 kB
          Kevin Liew
        4. PHOENIX-476.9.patch
          93 kB
          Kevin Liew
        5. PHOENIX-476.8.patch
          80 kB
          Kevin Liew
        6. PHOENIX-476.7.patch
          82 kB
          Kevin Liew
        7. PHOENIX-476.6.patch
          68 kB
          Kevin Liew
        8. PHOENIX-476.5.patch
          77 kB
          Kevin Liew
        9. PHOENIX-476.4.patch
          78 kB
          Kevin Liew
        10. PHOENIX-476.3.patch
          63 kB
          Kevin Liew
        11. PHOENIX-476.2.patch
          27 kB
          Kevin Liew
        12. PHOENIX-476.patch
          19 kB
          Kevin Liew

        Activity

          People

            kliew Kevin Liew
            jamestaylor James R. Taylor
            Votes:
            2 Vote for this issue
            Watchers:
            8 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: