Skip to content

Commit

Permalink
update business_cpp output
Browse files Browse the repository at this point in the history
  • Loading branch information
ncbd committed Sep 6, 2024
1 parent 27bc695 commit d3606fd
Show file tree
Hide file tree
Showing 123 changed files with 503 additions and 476 deletions.
33 changes: 33 additions & 0 deletions include/lgraph/olap_on_db.h
Original file line number Diff line number Diff line change
Expand Up @@ -1503,6 +1503,39 @@ class OlapOnDB : public OlapBase<EdgeData> {
}
}

/**
* @brief Write vertex data to a file.
*
* @param vertex_data The parallel vector storing the vertex data.
* @param output_file The path to the output file.
*
*/
template <typename VertexData>
void WriteToFile(bool detail_output, ParallelVector<VertexData> &vertex_data,
const std::string &output_file,
std::function<bool(size_t vid, VertexData &vdata)> output_filter = nullptr) {
FILE* fout = fopen(output_file.c_str(), "w");
if (fout == nullptr) {
THROW_CODE(InputError, "Unable to open file for writting!");
}
for (size_t i = 0; i < this->num_vertices_; ++i) {
if (output_filter != nullptr && !output_filter(i, vertex_data[i])) {
continue;
}
auto vit = txn_.GetVertexIterator(OriginalVid(i));
auto vit_label = vit.GetLabel();
auto primary_field = txn_.GetVertexPrimaryField(vit_label);
auto field_data = vit.GetField(primary_field);
json curJson;
curJson["vid"] = OriginalVid(i);
curJson["label"] = vit_label;
curJson["primary_field"] = primary_field;
curJson["field_data"] = field_data.ToString();
curJson["result"] = vertex_data[i];
fprintf(fout, "%s\n", curJson.dump().c_str());
}
}

/**
* @brief Write vertex data to the graph database.
*
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ extern "C" bool Process(GraphDB& db, const std::string& request, std::string& re
// output
start_time = get_time();
if (output_file != "") {
olapondb.WriteToFile(score, output_file);
olapondb.WriteToFile(true, score, output_file);
}
auto output_cost = get_time() - start_time;

Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ extern "C" bool Process(GraphDB& db, const std::string& request, std::string& re
start_time = get_time();
// TODO(any): write parent back to graph
if (output_file != "") {
olapondb.WriteToFile<size_t>(parent, output_file, [&](size_t vid, size_t vdata) -> bool {
olapondb.WriteToFile<size_t>(true, parent, output_file,
[&](size_t vid, size_t vdata) -> bool {
return vdata != (size_t)-1;
});
}
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ extern "C" bool Process(GraphDB& db, const std::string& request, std::string& re
// output
start_time = get_time();
if (output_file != "") {
olapondb.WriteToFile<double>(score, output_file);
olapondb.WriteToFile<double>(true, score, output_file);
}
auto output_cost = get_time() - start_time;

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ extern "C" bool Process(GraphDB& db, const std::string& request, std::string& re

// core
start_time = get_time();
std::vector<std::tuple<std::string, std::string, double>> result_list;
std::vector< std::tuple<size_t, std::string, std::string, std::string,
size_t, std::string, std::string, std::string, double> > result_list;

for (auto search_pair : search_list) {
auto src_string = search_pair.first;
Expand All @@ -69,7 +70,24 @@ extern "C" bool Process(GraphDB& db, const std::string& request, std::string& re
txn.GetVertexIndexIterator(dst_label, dst_field, dst_string, dst_string).GetVid();
auto id_pair = std::make_pair(src_vid, dst_vid);
double score = JiCore(olapondb, id_pair);
result_list.push_back(std::make_tuple(src_string, dst_string, score));

auto vit_first = txn.GetVertexIterator(src_vid, false);
auto vit_first_label = vit_first.GetLabel();
auto vit_first_primary_field = txn.GetVertexPrimaryField(vit_first_label);
auto vit_first_field_data = vit_first.GetField(vit_first_primary_field);
auto vit_second = txn.GetVertexIterator(dst_vid, false);
auto vit_second_label = vit_second.GetLabel();
auto vit_second_primary_field = txn.GetVertexPrimaryField(vit_second_label);
auto vit_second_field_data = vit_second.GetField(vit_second_primary_field);
result_list.push_back(std::make_tuple(src_vid,
vit_first_label,
vit_first_primary_field,
vit_first_field_data.ToString(),
dst_vid,
vit_second_label,
vit_second_primary_field,
vit_second_field_data.ToString(),
score));
}

auto core_cost = get_time() - start_time;
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ extern "C" bool Process(GraphDB& db, const std::string& request, std::string& re
// output
start_time = get_time();
if (output_file != "") {
olapondb.WriteToFile<double>(score, output_file);
olapondb.WriteToFile<double>(true, score, output_file);
}
txn.Commit();

Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ extern "C" bool Process(GraphDB& db, const std::string& request, std::string& re
// output
start_time = get_time();
if (output_file != "") {
olapondb.WriteToFile<size_t>(label, output_file);
olapondb.WriteToFile<size_t>(true, label, output_file);
}

double output_cost = get_time() - start_time;
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ extern "C" bool Process(GraphDB& db, const std::string& request, std::string& re
// output
start_time = get_time();
if (output_file != "") {
olapondb.WriteToFile<size_t>(label, output_file);
olapondb.WriteToFile<size_t>(true, label, output_file);
}
txn.Commit();

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ extern "C" bool Process(GraphDB& db, const std::string& request, std::string& re
// output
start_time = get_time();
if (output_file != "") {
olapondb.WriteToFile<double>(pr, output_file);
olapondb.WriteToFile<double>(true, pr, output_file);
}
txn.Commit();

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ extern "C" bool Process(GraphDB& db, const std::string& request, std::string& re
// output
start_time = get_time();
if (output_file != "") {
olapondb.WriteToFile<double>(distance, output_file, [&](size_t vid, double& vdata) -> bool {
olapondb.WriteToFile<double>(true, distance, output_file,
[&](size_t vid, double& vdata) -> bool {
return vdata != SSSP_INIT_VALUE;
});
}
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ extern "C" bool Process(GraphDB& db, const std::string& request, std::string& re
// output
start_time = get_time();
if (output_file != "") {
olapondb.WriteToFile<double>(curr, output_file);
olapondb.WriteToFile<double>(true, curr, output_file);
}
// TODO(any): write curr back to graph
auto output_cost = get_time() - start_time;
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ extern "C" bool Process(GraphDB& db, const std::string& request, std::string& re
// output
start_time = get_time();
if (output_file != "") {
olapondb.WriteToFile<size_t>(label, output_file);
olapondb.WriteToFile<size_t>(true, label, output_file);
}

size_t num_components, max_component;
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit d3606fd

Please sign in to comment.