syntax = "proto3";

package cz.proto;

option java_multiple_files = true;

enum JobStatus {
  SETUP = 0;
  QUEUEING = 1;
  RUNNING = 2;
  SUCCEED = 3;
  CANCELLING = 4;
  CANCELLED = 5;
  FAILED = 6;
}

message JobCost {
  uint32 cpu = 1;
  uint32 memory = 2;
}

message JobHistory {
  string coordinator_host = 1;
  uint64 coordinator_version = 2;
  uint64 start_time_ms = 3;
  string release_version = 4;
}

message SQLJobConfig {
  int32 timeout = 1;
  int64 adhoc_size_limit = 2;
  int64 adhoc_row_limit = 3;
  map<string, string> hint = 4;
}

message SQLJob {
  repeated string query = 1;
  repeated string default_namespace = 2; // namespace = [workspace, schema]
  SQLJobConfig sql_config = 3;
  int64 default_instance_id = 4;
}

enum JobType {
  SQL_JOB = 0;
  COMPACTION_JOB = 1; // currently, compaction job is a sql job, so jobDesc will contains a sql_job field
}

message JobSummaryLocation {
  string summary_location = 1;
  string plan_location = 2;
  string stats_location = 3;
  string progress_location = 4;
}

message JobMeta {
  string job_name = 2;
  int64 virtual_cluster = 3;
  JobStatus status = 4;
  JobType type = 5;
  uint64 start_time = 6;
  uint64 end_time = 7;
  uint32 priority = 9;
  string signature = 10;
  JobCost cost = 11;

  message HistoryList {
    repeated JobHistory history = 1;
  }
  HistoryList histories = 12;
  string result = 13;
  JobSummaryLocation job_summary = 14;

  message Partition {
    repeated uint32 field_id = 1;
    repeated string value = 2;
  }

  message Table {
    repeated string namespace = 1;
    string tableName = 2;
    uint64 size = 3;
    uint64 record = 4;
    uint64 cache_size = 5;
    repeated Partition partitions = 6;
    int64 instance_id = 7;
  }
  message TableList {
    repeated Table table = 1;
  }
  TableList input_tables = 15;
  TableList output_tables = 16;

  message Content {
    map<string, string> job_config = 1;
    oneof job {
      SQLJob sql_job = 2;
    }
    string release_version = 3;
    string job_desc_location = 20; // when job desc size > 128KB, will spill job desc to oss and save location here
  }
  Content content = 17;
}