syntax = "proto3";

package iterators;

message TriplePattern {
  string subject = 1;
  string predicate = 2;
  string object = 3;
  string graph = 4;
}

message SavedScanIterator {
  TriplePattern triple = 1;
  string last_read = 2;
  int64 cardinality = 3;
}

message SavedProjectionIterator {
  repeated string values = 1;
  oneof source {
    SavedScanIterator scan_source = 2;
    SavedIndexJoinIterator join_source = 3;
    SavedBagUnionIterator union_source = 4;
    SavedFilterIterator filter_source = 5;
  }
}

message SavedIndexJoinIterator {
  oneof source {
    SavedScanIterator scan_source = 1;
    SavedIndexJoinIterator join_source = 2;
    SavedFilterIterator filter_source = 3;
  }
  TriplePattern inner = 4;
  map<string, string> muc = 5;
  string last_read = 6;
  string timestamp = 7;
}

message SavedBagUnionIterator {
  oneof left {
    SavedScanIterator scan_left = 1;
    SavedProjectionIterator proj_left = 2;
    SavedBagUnionIterator union_left = 3;
    SavedIndexJoinIterator join_left = 4;
    SavedFilterIterator filter_left = 5;
  }
  oneof right {
    SavedScanIterator scan_right = 6;
    SavedProjectionIterator proj_right = 7;
    SavedBagUnionIterator union_right = 8;
    SavedIndexJoinIterator join_right = 9;
    SavedFilterIterator filter_right = 10;
  }
}

message SavedFilterIterator {
  oneof source {
    SavedScanIterator scan_source = 1;
    SavedProjectionIterator proj_source = 2;
    SavedFilterIterator filter_source = 3;
    SavedIndexJoinIterator join_source = 4;
  }
  string expression = 5;
  map<string, string> mu = 6;
}

message SavedInsertData {
  map<string, uint64> nb_inserted = 1;
}

message SavedDeleteData {
  map<string, uint64> nb_inserted = 1;
}

message RootTree {
  oneof source {
    SavedScanIterator scan_source = 1;
    SavedProjectionIterator proj_source = 2;
    SavedIndexJoinIterator join_source = 3;
    SavedBagUnionIterator union_source = 4;
    SavedFilterIterator filter_source = 5;
    SavedInsertData insert_source = 6;
    SavedDeleteData delete_source = 7;
  }
}
