/* -------------------------------------------------------------------
**
** riak_ts.proto: Protocol buffers for riak KV (timeseries-specific messages)
**
** Copyright (c) 2015 Basho Technologies, Inc.  All Rights Reserved.
**
** This file is provided 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.
**
** -------------------------------------------------------------------
*/

/*
** Revision: 1.0rc7
*/

// Java package specifiers
option java_package = "com.basho.riak.protobuf";
option java_outer_classname = "RiakTsPB";

import "riak.proto"; // for RpbPair


// Dispatch a query to Riak
message TsQueryReq {
  // left optional to support parameterized queries in the future
  optional TsInterpolation query = 1;
  optional bool stream = 2 [default = false];
  optional bytes cover_context = 3; // chopped up coverage plan per-req
}

message TsQueryResp {
  repeated TsColumnDescription columns = 1;
  repeated TsRow rows = 2;  // 0 to n rows
  optional bool done = 3 [default = true];
}

message TsGetReq {
  required bytes table = 1;
  repeated TsCell key = 2;
  optional uint32 timeout = 3;
}

message TsGetResp {
  repeated TsColumnDescription columns = 1;
  repeated TsRow rows = 2;  // 0 or 1 rows
}


message TsPutReq {
  required bytes table = 1;

  // optional: omitting it should use table order
  repeated TsColumnDescription columns = 2;

  repeated TsRow rows = 3;
}

message TsPutResp {

}

message TsDelReq {
  required bytes table = 1;
  repeated TsCell key = 2;
  optional bytes vclock = 3;
  optional uint32 timeout = 4;
}

message TsDelResp {

}

message TsInterpolation {
  required bytes base = 1;
  repeated RpbPair interpolations = 2;
}

enum TsColumnType {
  VARCHAR = 0;
  SINT64 = 1;
  DOUBLE = 2;
  TIMESTAMP = 3;
  BOOLEAN = 4;
  BLOB = 5;
}

message TsColumnDescription {
  required bytes name = 1;
  required TsColumnType type = 2;
}

message TsRow {
  repeated TsCell cells = 1;
}

message TsCell {
  optional bytes varchar_value = 1;
  optional sint64 sint64_value = 2;
  optional sint64 timestamp_value = 3;
  optional bool boolean_value = 4;
  optional double double_value = 5;
}

message TsListKeysReq {
  required bytes table = 1;
  optional uint32 timeout = 2;
}

message TsListKeysResp {
  repeated TsRow keys = 1;
  optional bool done = 2;
}

// Request a segmented coverage plan for this query
message TsCoverageReq {
  // left optional to support parameterized queries in the future
  optional TsInterpolation query = 1;
  required bytes table = 2;
  optional bytes replace_cover = 3;     // For failure recovery
  repeated bytes unavailable_cover = 4; // Other coverage contexts that have failed to assist Riak in deciding what nodes to avoid
}

// Segmented TS coverage plan response
message TsCoverageResp {
   repeated TsCoverageEntry entries = 1;
}

// Segment of a TS coverage plan
message TsCoverageEntry {
    required bytes ip = 1;
    required uint32 port = 2;
    required bytes cover_context = 3; // Opaque context to pass into follow-up request
    optional TsRange range = 4; // Might be other types of coverage queries/responses
}

// Each prospective subquery has a range of valid time values
message TsRange {
    required bytes field_name = 1;
    required sint64 lower_bound = 2;
    required bool lower_bound_inclusive = 3;
    required sint64 upper_bound = 4;
    required bool upper_bound_inclusive = 5;
    required bytes desc = 6; // Some human readable description of the time range
}
