//
// 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.
//

package exec.bit.data;

option java_package = "org.apache.drill.exec.proto";
option java_outer_classname = "BitData";
option optimize_for = SPEED;

import "ExecutionProtos.proto";
import "Coordination.proto";
import "UserBitShared.proto";

enum RpcType {
  HANDSHAKE = 0;
  ACK = 1;
  GOODBYE = 2;
  REQ_RECORD_BATCH = 3; // send record batch, returns Ack

  // both bit request and response
  SASL_MESSAGE = 4;

  REQ_RUNTIME_FILTER = 5; // send runtime filter data from HashJoin to Foreman, from Foreman to Scan nodes.

  DATA_ACK_WITH_CREDIT = 6; // a ack for data tunnel,with a runtime suggested credit as a response.
}

message BitClientHandshake{
  optional int32 rpc_version = 1;
  optional exec.shared.RpcChannel channel = 2 [default = BIT_DATA];
}

message BitServerHandshake{
  optional int32 rpc_version = 1;
  repeated string authenticationMechanisms = 2;
}

message FragmentRecordBatch{
  optional exec.shared.QueryId query_id = 1;
  optional int32 receiving_major_fragment_id = 2;
  repeated int32 receiving_minor_fragment_id = 3; 
  optional int32 sending_major_fragment_id = 4;
  optional int32 sending_minor_fragment_id = 5;
  optional exec.shared.RecordBatchDef def = 6;
  optional bool isLastBatch = 7;
}

message RuntimeFilterBDef{
  optional exec.shared.QueryId query_id = 1;
  optional int32 major_fragment_id = 2;
  optional int32 minor_fragment_id = 3;
  optional bool to_foreman = 4; // true means sending to foreman,false means sending to scan nodes
  repeated int32 bloom_filter_size_in_bytes = 5;
  repeated string probe_fields = 6; // probe fields with corresponding BloomFilters
  optional int32 hj_op_id = 7; // the operator id of the HashJoin which generates this RuntimeFilter
  optional int64 rf_identifier = 8; // the runtime filter identifier
}

message AckWithCredit{
  optional int32 allowed_credit = 1; // the credit allowed the sender to send in batch granularity
}
