/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you 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.
 */

option java_package = "org.apache.phoenix.coprocessor.generated";
option java_outer_classname = "PTableProtos";
option java_generic_services = true;
option java_generate_equals_and_hash = true;
option optimize_for = SPEED;

import "PGuidePosts.proto";
import "ServerCachingService.proto";

enum PTableType {
  SYSTEM = 0;
  USER = 1;
  VIEW = 2;
  INDEX = 3;
  JOIN = 4;
  CDC = 5;
}

message PColumn {
  required bytes columnNameBytes = 1;
  optional bytes familyNameBytes = 2;
  optional string dataType = 3;
  optional int32 maxLength = 4;
  optional int32 scale = 5;
  required bool nullable = 6;
  required int32 position = 7;
  optional int32 sortOrder = 8;
  optional int32 arraySize = 9;
  optional bytes viewConstant = 10;
  optional bool viewReferenced = 11;
  optional string expression = 12;
  optional bool isRowTimestamp = 13;
  optional bool isDynamic = 14;
  optional bytes columnQualifierBytes = 15;
  optional int64 timestamp = 16;
  optional bool derived = 17 [default = false];
}

message PTableStats {
  required bytes key = 1;
  repeated bytes values = 2;
  optional int64 guidePostsByteCount = 3;
  optional int64 keyBytesCount = 4;
  optional int32 guidePostsCount = 5;
  optional PGuidePosts pGuidePosts = 6;
}

message PTable {
  required bytes schemaNameBytes = 1;
  required bytes tableNameBytes = 2;
  required PTableType tableType = 3;
  optional string indexState = 4;
  required int64 sequenceNumber = 5;
  required int64 timeStamp = 6;
  optional bytes pkNameBytes = 7;
  required int32 bucketNum = 8;
  repeated PColumn columns = 9;
  repeated PTable indexes = 10;
  required bool isImmutableRows = 11;
  // Do NOT reuse the tag '12'. Stats are no longer passed
  // along with the PTable.
  //repeated PTableStats guidePosts = 12;
  // TODO remove this field in 5.0 release
  optional bytes dataTableNameBytes = 13;
  optional bytes defaultFamilyName = 14;
  required bool disableWAL = 15;
  required bool multiTenant = 16;
  optional bytes viewType = 17;
  optional bytes viewStatement = 18;
  repeated bytes physicalNames = 19;
  optional bytes tenantId = 20;
  optional int64 viewIndexId = 21;
  optional bytes indexType = 22;
  optional int64 statsTimeStamp = 23;
  optional bool storeNulls = 24;
  optional int32 baseColumnCount = 25;
  optional bool rowKeyOrderOptimizable = 26;
  optional bool transactional = 27;
  optional int64 updateCacheFrequency = 28;
  optional int64 indexDisableTimestamp = 29;
  optional bool isNamespaceMapped = 30;
  optional string autoParititonSeqName = 31;
  optional bool isAppendOnlySchema = 32;
  optional bytes parentNameBytes = 33;
  optional bytes storageScheme = 34;
  optional bytes encodingScheme = 35;
  repeated EncodedCQCounter encodedCQCounters = 36;
  optional bool useStatsForParallelization = 37;
  optional int32 transactionProvider = 38;
  optional int32 viewIndexIdType = 39 [default = 5];
  optional bool viewModifiedUpdateCacheFrequency = 40;
  optional bool viewModifiedUseStatsForParallelization = 41;
  optional int64 phoenixTTL = 42;
  optional int64 phoenixTTLHighWaterMark = 43;
  optional bool viewModifiedPhoenixTTL = 44;
  optional int64 lastDDLTimestamp = 45;
  optional bool changeDetectionEnabled = 46;
  optional bytes physicalTableNameBytes = 47;
  optional bytes baseTableLogicalNameBytes = 48;
  optional bytes schemaVersion = 49;
  optional bytes externalSchemaId=50;
  optional PTable transformingNewTable=51;
  optional bytes streamingTopicName=52;
  optional bytes indexWhere=53;
  optional string CDCIncludeScopes=54;
  optional bytes ttl = 55;
  optional bytes rowKeyMatcher = 56;
  optional bool isStrictTTL = 57;
  optional string indexConsistency = 58;
}

message EncodedCQCounter {
  required string colFamily = 1;
  required int32 counter = 2;
}

message LiteralTTL {
  required int32 ttlValue = 1;
}

message ConditionTTL {
  required string ttlExpression = 1;
  required bytes compiledExpression = 2;
  repeated ColumnReference ttlExpressionColumns = 3;
}

message TTLExpression {
  optional LiteralTTL literal = 1;
  optional ConditionTTL condition = 2;
}
