Example #1
0
int main(){
  TTableContext Context;
  // create scheme
  Schema AnimalS;
  AnimalS.Add(TPair<TStr,TAttrType>("Animal", atStr));
  AnimalS.Add(TPair<TStr,TAttrType>("Size", atStr));
  AnimalS.Add(TPair<TStr,TAttrType>("Location", atStr));
  AnimalS.Add(TPair<TStr,TAttrType>("Number", atInt));
  TIntV RelevantCols;
  RelevantCols.Add(0);
  RelevantCols.Add(1);
  RelevantCols.Add(2);
  // create table
  PTable T = TTable::LoadSS("Animals", AnimalS, "tests/animals.txt", Context, RelevantCols);
  //PTable T = TTable::LoadSS("Animals", AnimalS, "animals.txt");
  T->Unique("Animal");
  TTable Ts = *T;  // did we fix problem with copy-c'tor ?
  //PTable Ts = TTable::LoadSS("Animals_s", AnimalS, "../../testfiles/animals.txt", RelevantCols);
  //Ts->Unique(AnimalUnique);

  // test Select
  // create predicate tree: find all animals that are big and african or medium and Australian
  TPredicate::TAtomicPredicate A1(atStr, true, EQ, "Location", "", 0, 0, "Africa");  
  TPredicate::TPredicateNode N1(A1);  // Location == "Africa"
  TPredicate::TAtomicPredicate A2(atStr, true, EQ, "Size", "", 0, 0, "big");  
  TPredicate::TPredicateNode N2(A2);  // Size == "big"
  TPredicate::TPredicateNode N3(AND);
  N3.AddLeftChild(&N1);
  N3.AddRightChild(&N2);
  TPredicate::TAtomicPredicate A4(atStr, true, EQ, "Location", "", 0, 0, "Australia");  
  TPredicate::TPredicateNode N4(A4);  
  TPredicate::TAtomicPredicate A5(atStr, true, EQ, "Size", "", 0, 0, "medium");  
  TPredicate::TPredicateNode N5(A5); 
  TPredicate::TPredicateNode N6(AND);
  N6.AddLeftChild(&N4);
  N6.AddRightChild(&N5);
  TPredicate::TPredicateNode N7(OR);
  N7.AddLeftChild(&N3);
  N7.AddRightChild(&N6);
  TPredicate Pred(&N7);
  TIntV SelectedRows;
  Ts.Select(Pred, SelectedRows);

  TStrV GroupBy;
  GroupBy.Add("Location");
  T->Group(GroupBy, "LocationGroup");
  GroupBy.Add("Size");
  T->Group(GroupBy, "LocationSizeGroup");
  T->Count("LocationCount", "Location");
  PTable Tj = T->Join("Location", Ts, "Location");
  TStrV UniqueAnimals;
  UniqueAnimals.Add("Animals_1.Animal");
  UniqueAnimals.Add("Animals_2.Animal");
  Tj->Unique(UniqueAnimals, false);
  //print table
   T->SaveSS("tests/animals_out_T.txt");
   Ts.SaveSS("tests/animals_out_Ts.txt");
   Tj->SaveSS("tests/animals_out_Tj.txt");
  return 0;
}
Example #2
0
int main() {
    // create scheme
    TTable::Schema AnimalS;
    AnimalS.Add(TPair<TStr,TTable::TYPE>("Animal", TTable::STR));
    AnimalS.Add(TPair<TStr,TTable::TYPE>("Size", TTable::STR));
    AnimalS.Add(TPair<TStr,TTable::TYPE>("Location", TTable::STR));
    AnimalS.Add(TPair<TStr,TTable::TYPE>("Number", TTable::INT));
    // create table
    PTable T = TTable::LoadSS("Animals", AnimalS, "animals.txt");
    //PTable T = TTable::LoadSS("Animals", AnimalS, "animals.txt");
    T->Unique("Animal");
    //TTable Ts = *T;  not working because of problem with copy-c'tor
    PTable Ts = TTable::LoadSS("Animals_s", AnimalS, "animals.txt");
    Ts->Unique("Animal");

    // test Select
    // create predicate tree: find all animals that are big and african or medium and Australian
    TPredicate::TAtomicPredicate A1(TPredicate::STR, true, TPredicate::EQ, "Location", "", 0, 0, "Africa");
    TPredicate::TPredicateNode N1(A1);  // Location == "Africa"
    TPredicate::TAtomicPredicate A2(TPredicate::STR, true, TPredicate::EQ, "Size", "", 0, 0, "big");
    TPredicate::TPredicateNode N2(A2);  // Size == "big"
    TPredicate::TPredicateNode N3(TPredicate::AND);
    N3.AddLeftChild(&N1);
    N3.AddRightChild(&N2);
    TPredicate::TAtomicPredicate A4(TPredicate::STR, true, TPredicate::EQ, "Location", "", 0, 0, "Australia");
    TPredicate::TPredicateNode N4(A4);
    TPredicate::TAtomicPredicate A5(TPredicate::STR, true, TPredicate::EQ, "Size", "", 0, 0, "medium");
    TPredicate::TPredicateNode N5(A5);
    TPredicate::TPredicateNode N6(TPredicate::AND);
    N6.AddLeftChild(&N4);
    N6.AddRightChild(&N5);
    TPredicate::TPredicateNode N7(TPredicate::OR);
    N7.AddLeftChild(&N3);
    N7.AddRightChild(&N6);
    TPredicate Pred(&N7);
    Ts->Select(Pred);

    TStrV GroupBy;
    GroupBy.Add("Location");
    T->Group("LocationGroup", GroupBy);
    GroupBy.Add("Size");
    T->Group("LocationSizeGroup", GroupBy);
    T->Count("LocationCount", "Location");
    PTable Tj = T->Join("Location", *Ts, "Location");
    //print table
    T->SaveSS("animals_out_T.txt");
    Ts->SaveSS("animals_out_Ts.txt");
    Tj->SaveSS("animals_out_Tj.txt");
    return 0;
}
Example #3
0
int main(){
  TTableContext Context;
  // Case 1: Euclidean Distance
  Schema BuildingS;
  BuildingS.Add(TPair<TStr,TAttrType>("Building", atStr));
  BuildingS.Add(TPair<TStr,TAttrType>("X", atInt));
  BuildingS.Add(TPair<TStr,TAttrType>("Y", atInt));

  // create table
  PTable TBuildings = TTable::LoadSS("Buildings", BuildingS, "tests/buildings.txt", Context, '\t', false);

	TStrV Cols;
	Cols.Add("X");
	Cols.Add("Y");

	// Find all buildings within 5 Euc Distance of each other.
	PTable BuildingJointTable = TBuildings->SelfSimJoin(Cols, "Euclidean_Distance", L2Norm, 5.0);
	BuildingJointTable->SaveSS("tests/buildings.out.txt");

  // Case2 : Haversine distance 
  Schema PlaceS;
  PlaceS.Add(TPair<TStr,TAttrType>("Name", atStr));
  PlaceS.Add(TPair<TStr,TAttrType>("Location", atStr));
  PlaceS.Add(TPair<TStr,TAttrType>("Latitude", atFlt));
  PlaceS.Add(TPair<TStr,TAttrType>("Longitude", atFlt));

  // create table
  PTable TPlaces = TTable::LoadSS("Places", PlaceS, "tests/places.txt", Context, '\t', false);

	Cols.Clr();
	Cols.Add("Latitude");
	Cols.Add("Longitude");

	PTable PlacesJointTable = TPlaces->SelfSimJoin(Cols, "Distance",Haversine, 1000.0);

	TStrV ProjectionV;
	ProjectionV.Add("Places_1.Name");
	ProjectionV.Add("Places_1.Location");	
	ProjectionV.Add("Places_2.Name");
	ProjectionV.Add("Places_2.Location");
	ProjectionV.Add("Distance");
	PlacesJointTable->ProjectInPlace(ProjectionV);
	PlacesJointTable->SelectAtomic("Places_1.Name", "Places_2.Name", NEQ);
	PlacesJointTable->SaveSS("tests/places.out.txt");

	printf("Saved buildings.out.txt and places.out.txt\n");
  return 0;
}
Example #4
0
int main(int argc, char* argv[]){
  //test1();
  TTableContext Context;

  // create scheme
  Schema PostS;
  PostS.Add(TPair<TStr,TAttrType>("Id", atInt));
  PostS.Add(TPair<TStr,TAttrType>("OwnerUserId", atInt));
  PostS.Add(TPair<TStr,TAttrType>("AcceptedAnswerId", atInt));
  PostS.Add(TPair<TStr,TAttrType>("CreationDate", atStr));
  PostS.Add(TPair<TStr,TAttrType>("Score", atInt));
  TIntV RelevantCols;
  RelevantCols.Add(0); RelevantCols.Add(1); RelevantCols.Add(2); RelevantCols.Add(3); RelevantCols.Add(4);

  PTable P = TTable::LoadSS("Posts", PostS, "/dfs/ilfs2/0/ringo/StackOverflow_2/posts.tsv", Context, RelevantCols);
  printf("Load done\n");

  TStrV cols;
  cols.Add("OwnerUserId");

  struct timeval begin, end;
  gettimeofday(&begin, NULL);
  P->Aggregate(cols, aaSum, "Score", "Sum");
  gettimeofday(&end, NULL);

  double diff = (end.tv_sec * 1000000 + end.tv_usec) - (begin.tv_sec * 1000000 + begin.tv_usec);
  printf("Elapsed time:%.3lfs\n", diff / 1000000);
  
  if (atoi(argv[1]) == 0) return 0;

  P->SaveSS("tests/p3.txt");

  return 0;
}
Example #5
0
int main(){
  TTableContext Context;
  // create scheme
  Schema AnimalS;
  AnimalS.Add(TPair<TStr,TAttrType>("Animal", atStr));
  AnimalS.Add(TPair<TStr,TAttrType>("Size", atStr));
  AnimalS.Add(TPair<TStr,TAttrType>("Location", atStr));
  AnimalS.Add(TPair<TStr,TAttrType>("Number", atInt));
  TIntV RelevantCols;
  RelevantCols.Add(0);
  RelevantCols.Add(1);
  RelevantCols.Add(2);
  RelevantCols.Add(3);

  PTable P = TTable::LoadSS("Animals", AnimalS, "tests/animals.txt", Context, RelevantCols);

  P->SaveSS("tests/p1.txt");

  TStrV cols;
  cols.Add("Size");
  cols.Add("Number");

  TVec<PTable> R = P->SpliceByGroup(cols);
  for (TInt i = 0; i < R.Len(); i++) {
    TStr fn = i.GetStr();
    R[i]->SaveSS("tests/sznumber" + fn + ".txt");
  }

  P->Unique(cols, true);

  P->SaveSS("tests/p2.txt");

  TStrV group1;
  group1.Add("Location");
  P->Group(group1, "LocationGroup");

  P->SaveSS("tests/p3.txt");

  return 0;
}
int main(int argc, char** argv){
  TBool debug = false;
  TStr TagsFnm = "/lfs/madmax4/0/yonathan/tags_200000";
  if(debug){ TagsFnm = "/lfs/madmax4/0/yonathan/tags_small";}
  Schema TagS; 
  TagS.Add(TPair<TStr,TAttrType>("UserId", atInt));
  TTableContext Context;
  TTable::SetMP(false);
	
  float ft_max;
  float mu_max;
	
  timeval timer0;
  gettimeofday(&timer0, NULL);
  double t1 = timer0.tv_sec + (timer0.tv_usec/1000000.0);
  PTable Tags = TTable::LoadSS(TagS, TagsFnm + ".tsv", Context);
  gettimeofday(&timer0, NULL);
  double t2 = timer0.tv_sec + (timer0.tv_usec/1000000.0);
  printf("Time to load tags table: %f\n", t2 - t1);
  printf("Table Size:\n");
  Tags->PrintSize();
  Tags->PrintContextSize();
  getmaxcpumem(&ft_max, &mu_max);
  printf("time: %0.3f seconds, memory: %0.3f MB\n", ft_max, mu_max);
  printf("\n");
	
  timeval timer1;
  gettimeofday(&timer1, NULL);
  t1 = timer1.tv_sec + (timer1.tv_usec/1000000.0);
  PTable TagsJoinTag = Tags->SelfJoin("Tag");
  gettimeofday(&timer1, NULL);
  t2 = timer1.tv_sec + (timer1.tv_usec/1000000.0);
  printf("Time to join on tags column: %f\n", t2 - t1);
  printf("Table Size:\n");
  TagsJoinTag->PrintSize();
  if(debug){ TagsJoinTag->SaveSS(TagsFnm + "_join_tag.tsv");}
  getmaxcpumem(&ft_max, &mu_max);
  printf("time: %0.3f seconds, memory: %0.3f MB\n", ft_max, mu_max);
  printf("\n");
	
  return 0;
}
Example #7
0
// Tests load and save from text file.
TEST(TTable, LoadSave) {
  TTableContext Context;
  // Create schema.
  Schema GradeS;
  GradeS.Add(TPair<TStr,TAttrType>("Class", atStr));
  GradeS.Add(TPair<TStr,TAttrType>("Area", atStr));
  GradeS.Add(TPair<TStr,TAttrType>("Quarter", atStr));
  GradeS.Add(TPair<TStr,TAttrType>("Grade 2011", atInt));
  GradeS.Add(TPair<TStr,TAttrType>("Grade 2012", atInt));
  GradeS.Add(TPair<TStr,TAttrType>("Grade 2013", atInt));
  TIntV RelevantCols;
  RelevantCols.Add(0); RelevantCols.Add(1); RelevantCols.Add(2);
  RelevantCols.Add(3); RelevantCols.Add(4); RelevantCols.Add(5);

  PTable P = TTable::LoadSS(GradeS, "table/grades.txt", &Context, RelevantCols);

  EXPECT_EQ(5, P->GetNumRows().Val);
  EXPECT_EQ(5, P->GetNumValidRows().Val); 

  EXPECT_EQ(7, P->GetIntVal("Grade 2011", 0).Val);
  EXPECT_EQ(9, P->GetIntVal("Grade 2013", 4).Val);
  EXPECT_STREQ("Compilers", P->GetStrVal("Class", 3).CStr());

  P->SaveSS("table/p1.txt");

  // Test SaveSS by loading the saved table and testing values again.
  GradeS.Add(TPair<TStr,TAttrType>("_id", atInt));
  P = TTable::LoadSS(GradeS, "table/p1.txt", &Context, RelevantCols);

  EXPECT_EQ(5, P->GetNumRows().Val);
  EXPECT_EQ(5, P->GetNumValidRows().Val); 

  EXPECT_EQ(7, P->GetIntVal("Grade 2011", 0).Val);
  EXPECT_EQ(9, P->GetIntVal("Grade 2013", 4).Val);
  EXPECT_STREQ("Compilers", P->GetStrVal("Class", 3).CStr());
}
Example #8
0
void test1() {
  TTableContext Context;

  // create scheme
  Schema AnimalS;
  AnimalS.Add(TPair<TStr,TAttrType>("Animal", atStr));
  AnimalS.Add(TPair<TStr,TAttrType>("Size", atStr));
  AnimalS.Add(TPair<TStr,TAttrType>("Location", atStr));
  AnimalS.Add(TPair<TStr,TAttrType>("Number", atInt));
  TIntV RelevantCols;
  RelevantCols.Add(0);
  RelevantCols.Add(1);
  RelevantCols.Add(2);
  RelevantCols.Add(3);

  PTable P = TTable::LoadSS("Animals", AnimalS, "tests/s.txt", Context, RelevantCols);
  printf("Load done\n");

  TStrV cols;
  cols.Add("Size");
  cols.Add("Number");

  struct timeval begin, end;
  gettimeofday(&begin, NULL);

  //P->Unique(cols);
  P->Group(cols, "SizeNumberGroup");

  gettimeofday(&end, NULL);

  double diff = (end.tv_sec * 1000000 + end.tv_usec) - (begin.tv_sec * 1000000 + begin.tv_usec);
  printf("Elapsed time:%.3lfs\n", diff / 1000000);

  P->SaveSS("tests/p3.txt");

}
int main(int argc, char** argv) {
    TBool debug = false;
    TStr TagsFnm = "/lfs/madmax4/0/yonathan/tags";
    if(debug) {
        TagsFnm = "/lfs/madmax4/0/yonathan/tags_small";
    }
    Schema TagS;
    TagS.Add(TPair<TStr,TAttrType>("UserId", atInt));
    TagS.Add(TPair<TStr,TAttrType>("Tag", atStr));
    // Load a TTable object and benchmark how long it takes to iterate over all of its records
    TTableContext Context;
    TTable::SetMP(false);

    //float ft0, ft1, ft2, ft3;
    //float mu0, mu1, mu2, mu3;
    float ft_max;
    float mu_max;
    //float tdiff1, tdiff2, dfiff3;
    //float mdiff1, mdiff2, mdiff3;

    //getcpumem(&ft0,&mu0);
    timeval timer0;
    gettimeofday(&timer0, NULL);
    double t1 = timer0.tv_sec + (timer0.tv_usec/1000000.0);
    PTable Tags = TTable::LoadSS(TagS, TagsFnm + ".tsv", Context);
    gettimeofday(&timer0, NULL);
    double t2 = timer0.tv_sec + (timer0.tv_usec/1000000.0);
    printf("Time to load tags table: %f\n", t2 - t1);
    printf("Table Size:\n");
    Tags->PrintSize();
    Tags->PrintContextSize();
    //getcpumem(&ft1,&mu1);
    //tdiff1 = ft1 - ft0;
    //mdiff1 = mu1 - mu0;
    //printf("time: %0.3f seconds, memory: %0.3f MB\n", tdiff1, mdiff1);
    getmaxcpumem(&ft_max, &mu_max);
    printf("time: %0.3f seconds, memory: %0.3f MB\n", ft_max, mu_max);
    printf("\n");

    timeval timer2;
    gettimeofday(&timer2, NULL);
    t1 = timer2.tv_sec + (timer2.tv_usec/1000000.0);
    printf("start join on user\n");
    PTable TagsJoinUser = Tags->SelfJoin("UserId");
    printf("finish join on user\n");
    gettimeofday(&timer2, NULL);
    t2 = timer2.tv_sec + (timer2.tv_usec/1000000.0);
    printf("Time to join on user id column: %f\n", t2 - t1);
    printf("Table Size:\n");
    TagsJoinUser->PrintSize();
    //getcpumem(&ft2,&mu2);
    if(debug) {
        TagsJoinUser->SaveSS(TagsFnm + "_join_user.tsv");
    }
    //tdiff2 = ft2 - ft1;
    //mdiff2 = mu2 - mu1;
    //printf("time: %0.3f seconds, memory: %0.3f MB\n", tdiff2, mdiff2);
    getmaxcpumem(&ft_max, &mu_max);
    printf("time: %0.3f seconds, memory: %0.3f MB\n", ft_max, mu_max);
    printf("\n");

    timeval timer3;
    gettimeofday(&timer3, NULL);
    t1 = timer3.tv_sec + (timer3.tv_usec/1000000.0);
    PTable JavaTags = TTable::New(TagS, Context);
    TIntV SelectedRows;
    if(debug) {
        Tags->SelectAtomicConst(TStr("Tag"), TStr("c#"), EQ, SelectedRows, JavaTags, false, true);
    } else {
        Tags->SelectAtomicConst(TStr("Tag"), TStr("java"), EQ, SelectedRows, JavaTags, false, true);
    }
    gettimeofday(&timer3, NULL);
    t2 = timer3.tv_sec + (timer3.tv_usec/1000000.0);
    printf("Time to select java users: %f\n", t2 - t1);
    printf("Table Size:\n");
    JavaTags->PrintSize();
    //getcpumem(&ft3,&mu3);
    if(debug) {
        JavaTags->SaveSS(TagsFnm + "_select.tsv");
    }
    //tdiff3 = ft3 - ft2;
    //mdiff3 = mu3 - mu2;
    //printf("time: %0.3f seconds, memory: %0.3f MB\n", tdiff3, mdiff3);
    getmaxcpumem(&ft_max, &mu_max);
    printf("time: %0.3f seconds, memory: %0.3f MB\n", ft_max, mu_max);
    printf("\n");
    return 0;
}
Example #10
0
int main(int argc, char* []) {
  
  FILE * outfile;
  outfile = fopen ("benchmark.txt","w");
  
  
  //outfile << "Hello World!\n";
  fprintf(outfile, "Hello World!\n");
  PrintBenchmarks(outfile);
  
  int NTblCnt;
  int ETblCnt;
  printf("Enter the number of node tables and edge tables\n");
  scanf("%d %d", &NTblCnt, &ETblCnt);
  
  TVec<PTable> NTables;
  TVec<PTable> ETables;
  TVec<PTable> OutNTables;
  TVec<TPair<TInt, TInt> > Mapping;
  //TFltV Weights;
  
  TTableContext Context;
  //Read in tables
  for (int i = 0; i < NTblCnt; i++) {
    PTable P = AddNodeTable(Context);
    P->SaveSS("ntable_abc.txt");
    NTables.Add(P);
  }
  for (int i = 0; i < ETblCnt; i++) {
    ETables.Add(AddEdgeTable(Context));
    //printf("Enter the source and destination node table number (index starting from 0), and weight of the edges\n");
    printf("Enter the source and destination node table number (index starting from 0)\n");
    int SrcId;
    int DestId;
    //float Wt;
    //scanf("%d %d %f", &SrcId, &DestId, &Wt);
    scanf("%d %d", &SrcId, &DestId);
    printf("%d %d\n", SrcId, DestId);
    Mapping.Add(TPair<TInt, TInt>(SrcId, DestId));
    //Weights.Add(Wt);
  }
  
  /*
   char nodes_file[200];
   int NodesCnt;
   printf("Enter the filename containing bfs nodes and number of nodes to take");
   scanf("%s %d", nodes_file, &NodesCnt);
   
   FILE* infile = fopen (nodes_file,"r");
   char NodeTypeStr[100];
   char NodeIdStr[200];
   TIntV NodeTypeV;
   TStrV NodeIdV;
   for (int i = 0; i < NodesCnt; i++) {
   fscanf(infile, "%s %s", NodeTypeStr, NodeIdStr);
   int NodeTypeInt;
   TStr NodeIdStr2 = TStr(NodeIdStr);
   if (NodeTypeStr[0] == 'c') { NodeTypeInt = 0; }
   else if (NodeTypeStr[0] == 'l') { NodeTypeInt = 1; }
   else if (NodeTypeStr[0] == 'p') { NodeTypeInt = 2; }
   else if (NodeTypeStr[0] == 't') { NodeTypeInt = 3; }
   else if (NodeTypeStr[0] == 'u') { NodeTypeInt = 4; }
   else { printf("ERROR! Node Type not found!\n"); }
   NodeTypeV.Add(NodeTypeInt);
   NodeIdV.Add(NodeIdStr2);
   
   }
   */
  
  fprintf(outfile, "Tables Loaded\n");
  PrintBenchmarks(outfile);
  printf("Tables Loaded\n");
  
  //Convert to Graph
  printf("Converting to Graph\n");
  TSVNetMP Graph;
  TIntV NTypeV;
  TIntV ETypeV;
  TVec<THash<TStr, TInt> > NodesHV;
  //Adding node types
  for (int i = 0; i < NTblCnt; i++) {
    NTypeV.Add(Graph.AddNType());
  }
  printf("a\n");
  //Adding edge types
  for (int i = 0; i < ETblCnt; i++) {
    ETypeV.Add(Graph.AddEType(NTypeV[Mapping[i].Val1], NTypeV[Mapping[i].Val2]));
  }
  printf("a\n");
  //Adding nodes
  for (int i = 0; i < NTblCnt; i++) {
    THash<TStr, TInt> NodesH;
    NodesHV.Add(NodesH);
    int NType = NTypeV[i];
    Graph.ReserveNodes(i, NTables[i]->GetNumRows());
    for (int j = 0; j < NTables[i]->GetNumRows(); j++) {
      NodesHV[i].AddDat(NTables[i]->GetStrVal("NodeID", j), Graph.AddNode(NType));
    }
    Graph.SetNCnt(i, NTables[i]->GetNumRows());
  }
  //printf("a\n");
  //Adding edges
  for (int i = 0; i < ETblCnt; i++) {
    int EType = ETypeV[i];
    int SrcNType = NTypeV[Mapping[i].Val1];
    int DstNType = NTypeV[Mapping[i].Val2];
    Graph.ReserveEdges(i, ETables[i]->GetNumRows());
    for (int j = 0; j < ETables[i]->GetNumRows(); j++) {
      int SrcNId = NodesHV[SrcNType].GetDat(ETables[i]->GetStrVal("SrcID", j));
      int DstNId = NodesHV[DstNType].GetDat(ETables[i]->GetStrVal("DstID", j));
      Graph.AddEdge(SrcNId, DstNId, EType);
    }
    Graph.SetECnt(i, ETables[i]->GetNumRows());
  }
  //printf("a\n");
  
  TIntV EdgeVec1;
  //EdgeVec.Add(0);
  //EdgeVec.Add(2);
  TIntV NodeVec1;
  NodeVec1.Add(2);
  NodeVec1.Add(4);
  //TIntIntH Offsets1;
  
  TIntV EdgeVec2;
  //EdgeVec.Add(0);
  //EdgeVec.Add(2);
  TIntV NodeVec2;
  NodeVec2.Add(2);
  NodeVec2.Add(3);
  NodeVec2.Add(4);
  //TIntIntH Offsets2;
  
  
  TIntV EdgeVec3;
  //EdgeVec.Add(0);
  //EdgeVec.Add(2);
  TIntV NodeVec3;
  NodeVec3.Add(0);
  NodeVec3.Add(2);
  NodeVec3.Add(3);
  NodeVec3.Add(4);
  //TIntIntH Offsets3;
  
  int iter_count = 10;
  fprintf(outfile, "Converted to Graph\n");
  PrintBenchmarks(outfile);
  printf("Converted to Graph\n");
  printf("Starting subgraph\n");
  
  PSVNetMP Graph1;
  PSVNetMP Graph2;
  PSVNetMP Graph3;
  
  Graph.InitializeTimeV(4);
  
  for (int iter = 0; iter < iter_count; iter++) {
    Graph1 = Graph.GetSubGraphMP(NodeVec1, EdgeVec1);
  }
  
  fprintf(outfile, "subgraph completed\n");
  PrintBenchmarks(outfile);
  Graph.PrintTimeV(outfile);
  printf("subgraph completed\n");
  
  Graph.InitializeTimeV(4);
  for (int iter = 0; iter < iter_count; iter++) {
    Graph2 = Graph.GetSubGraphMP(NodeVec2, EdgeVec2);
  }
  
  fprintf(outfile, "subgraph completed\n");
  PrintBenchmarks(outfile);
  Graph.PrintTimeV(outfile);
  printf("subgraph completed\n");
  
  Graph.InitializeTimeV(4);
  for (int iter = 0; iter < iter_count; iter++) {
    Graph3 = Graph.GetSubGraphMP(NodeVec3, EdgeVec3);
  }
  
  fprintf(outfile, "subgraph completed\n");
  PrintBenchmarks(outfile);
  Graph.PrintTimeV(outfile);
  printf("subgraph completed\n");
  
  printf("Original: Nodes = %d, edges = %d\n", Graph.GetNodes(), Graph.GetEdges());
  printf("Subgraph1: Nodes = %d, edges = %d\n", Graph1->GetNodes(), Graph1->GetEdges());
  printf("Subgraph2: Nodes = %d, edges = %d\n", Graph2->GetNodes(), Graph2->GetEdges());
  printf("Subgraph3: Nodes = %d, edges = %d\n", Graph3->GetNodes(), Graph3->GetEdges());
  //printf("%d\n", Graph.GetSrcNId(2, 0));
  
  
  //Store bfs output
  /*
   printf("Storing Bfs output\n");
   FILE * outpr;
   outpr = fopen ("output_bfs.txt","w");
   for (int i = 0; i < NTblCnt; i++) {
   for (int j = 0; j < NTables[i]->GetNumRows(); j++) {
   fprintf(outpr, "%d \t%s \t%d\n", i, (NTables[i]->GetStrVal("NodeID", j)).CStr(), int(BfsLevelHV[i].GetDat(NodesHV[i].GetDat(NTables[i]->GetStrVal("NodeID", j)))));
   }
   }*/
  
  fprintf(outfile, "Output stored\n");
  PrintBenchmarks(outfile);
  printf("Output stored\n");
  
  
  fclose(outfile);
  //fclose(infile);
  //fclose(outpr);
}
Example #11
0
int main(){
  // create scheme
  TTable::Schema AnimalS;
  AnimalS.Add(TPair<TStr,TTable::TYPE>("Animal", TTable::STR));
  AnimalS.Add(TPair<TStr,TTable::TYPE>("Size", TTable::STR));
  AnimalS.Add(TPair<TStr,TTable::TYPE>("Location", TTable::STR));
  AnimalS.Add(TPair<TStr,TTable::TYPE>("Number", TTable::INT));
  // create table
  PTable T1 = TTable::LoadSS("Animals1", AnimalS, "animals.txt");
  PTable T2 = TTable::LoadSS("Animals2", AnimalS, "animals.txt");
  // test Select
  // create predicate tree: find all animals that are big and african or medium and Australian
  TPredicate::TAtomicPredicate A1(TPredicate::STR, true, TPredicate::EQ, "Size", "", 0, 0, "big");  
  TPredicate::TPredicateNode N1(A1);  // Size == "big"
  TPredicate Pred(&N1);
  T1->Select(Pred);
  T1->SaveSS("animals_out_T1.txt");
  PTable Tj = T1->Join("Location", *T2, "Location");
  TStrV GroupBy;
  GroupBy.Add("Animals1.Animal");
  GroupBy.Add("Animals2.Animal");
  Tj->Group("AnimalPair", GroupBy);
  Tj->Unique("AnimalPair");
  //print table
  Tj->SaveSS("animals_out_Tj_1.txt");

  // Join on Location to get animal pairs
  // select the animal pairs of animals of the same size
  // group by (Animal, Animal)
  // unique by group idx
  /*
  PTable T3 = TTable::LoadSS("Animals3", AnimalS, "../../testfiles/animals.txt");
  //PTable T4 = TTable::LoadSS("Animals4", AnimalS, "../../testfiles/animals.txt");
  TTable T4 = *T3;
  T4.Name = "Animals4";
  PTable To = T3->Join("Location", T4, "Location");
  TPredicate::TAtomicPredicate A2(TPredicate::STR, false, TPredicate::EQ, "Animals3.Size", "Animals4.Size");  
  TPredicate::TPredicateNode N2(A2);
  TPredicate Pred2(&N2);
  To->Select(Pred2);
  TStrV GroupBy1;
  GroupBy1.Add("Animals3.Animal");
  GroupBy1.Add("Animals4.Animal");
  To->Group("AnimalPair", GroupBy1);
  To->Unique("AnimalPair");
  //print table
  To->SaveSS("../../testfiles/animals_out_To_1.txt");
  return 0;
  */

  PTable T3 = TTable::LoadSS("Animals3", AnimalS, "animals.txt");
  PTable T4 = TTable::LoadSS("Animals4", AnimalS, "animals.txt");
  PTable To = T3->Join("Location", *T4, "Location");
  TPredicate::TAtomicPredicate A2(TPredicate::STR, false, TPredicate::EQ, "Animals3.Size", "Animals4.Size");  
  TPredicate::TPredicateNode N2(A2);
  TPredicate Pred2(&N2);
  To->Select(Pred2);
  TStrV GroupBy1;
  GroupBy1.Add("Animals3.Animal");
  GroupBy1.Add("Animals4.Animal");
  To->Group("AnimalPair", GroupBy1);
  To->Unique("AnimalPair");
  //print table
  To->SaveSS("animals_out_To_1.txt");
  return 0;
}