// Copyright 2017 Google Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

syntax = "proto3";

package google.bigtable.admin.v2;

import "google/api/annotations.proto";
import "google/protobuf/duration.proto";
import "google/protobuf/timestamp.proto";

option go_package = "google.golang.org/genproto/googleapis/bigtable/admin/v2;admin";
option java_multiple_files = true;
option java_outer_classname = "TableProto";
option java_package = "com.google.bigtable.admin.v2";


// A collection of user data indexed by row, column, and timestamp.
// Each table is served using the resources of its parent cluster.
message Table {
  // Possible timestamp granularities to use when keeping multiple versions
  // of data in a table.
  enum TimestampGranularity {
    // The user did not specify a granularity. Should not be returned.
    // When specified during table creation, MILLIS will be used.
    TIMESTAMP_GRANULARITY_UNSPECIFIED = 0;

    // The table keeps data versioned at a granularity of 1ms.
    MILLIS = 1;
  }

  // Defines a view over a table's fields.
  enum View {
    // Uses the default view for each method as documented in its request.
    VIEW_UNSPECIFIED = 0;

    // Only populates `name`.
    NAME_ONLY = 1;

    // Only populates `name` and fields related to the table's schema.
    SCHEMA_VIEW = 2;

    // Populates all fields.
    FULL = 4;
  }

  // (`OutputOnly`)
  // The unique name of the table. Values are of the form
  // `projects/<project>/instances/<instance>/tables/[_a-zA-Z0-9][-_.a-zA-Z0-9]*`.
  // Views: `NAME_ONLY`, `SCHEMA_VIEW`, `FULL`
  string name = 1;

  // (`CreationOnly`)
  // The column families configured for this table, mapped by column family ID.
  // Views: `SCHEMA_VIEW`, `FULL`
  map<string, ColumnFamily> column_families = 3;

  // (`CreationOnly`)
  // The granularity (e.g. `MILLIS`, `MICROS`) at which timestamps are stored in
  // this table. Timestamps not matching the granularity will be rejected.
  // If unspecified at creation time, the value will be set to `MILLIS`.
  // Views: `SCHEMA_VIEW`, `FULL`
  TimestampGranularity granularity = 4;
}

// A set of columns within a table which share a common configuration.
message ColumnFamily {
  // Garbage collection rule specified as a protobuf.
  // Must serialize to at most 500 bytes.
  //
  // NOTE: Garbage collection executes opportunistically in the background, and
  // so it's possible for reads to return a cell even if it matches the active
  // GC expression for its family.
  GcRule gc_rule = 1;
}

// Rule for determining which cells to delete during garbage collection.
message GcRule {
  // A GcRule which deletes cells matching all of the given rules.
  message Intersection {
    // Only delete cells which would be deleted by every element of `rules`.
    repeated GcRule rules = 1;
  }

  // A GcRule which deletes cells matching any of the given rules.
  message Union {
    // Delete cells which would be deleted by any element of `rules`.
    repeated GcRule rules = 1;
  }

  // Garbage collection rules.
  oneof rule {
    // Delete all cells in a column except the most recent N.
    int32 max_num_versions = 1;

    // Delete cells in a column older than the given age.
    // Values must be at least one millisecond, and will be truncated to
    // microsecond granularity.
    google.protobuf.Duration max_age = 2;

    // Delete cells that would be deleted by every nested rule.
    Intersection intersection = 3;

    // Delete cells that would be deleted by any nested rule.
    Union union = 4;
  }
}
