Skip to content

Commit

Permalink
support JSON result
Browse files Browse the repository at this point in the history
  • Loading branch information
bookug committed Feb 28, 2017
1 parent 7d61f6d commit d35d87e
Show file tree
Hide file tree
Showing 10 changed files with 213 additions and 109 deletions.
7 changes: 5 additions & 2 deletions Database/Database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -693,7 +693,10 @@ Database::query(const string _query, ResultSet& _result_set, FILE* _fp)

if (general_evaluation.needOutputAnswer())
{
cout << "There has answer: " << _result_set.ansNum << endl;
int ans_num = max(_result_set.ansNum - _result_set.output_offset, 0);
if (_result_set.output_limit != -1)
ans_num = min(ans_num, _result_set.output_limit);
cout << "There has answer: " << ans_num << endl;
cout << "final result is : " << endl;
_result_set.output(_fp);
fprintf(_fp, "\n");
Expand Down Expand Up @@ -2685,7 +2688,7 @@ Database::getFinalResult(SPARQLquery& _sparql_q, ResultSet& _result_set)
#else
vector<int> keys;
vector<bool> desc;
_result_set.openStream(keys, desc, 0, -1);
_result_set.openStream(keys, desc);
#ifdef DEBUG_PRECISE
printf("getFinalResult:after open stream\n");
#endif
Expand Down
4 changes: 2 additions & 2 deletions Parser/QueryParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -733,8 +733,8 @@ void QueryParser::parseOrderBy(pANTLR3_BASE_TREE node, QueryTree &querytree)
pANTLR3_BASE_TREE gchildNode = (pANTLR3_BASE_TREE) childNode->getChild(childNode, k);

//unary 190
while (childNode->getType(childNode) == 190)
childNode = (pANTLR3_BASE_TREE) childNode->getChild(childNode, 0);
while (gchildNode->getType(gchildNode) == 190)
gchildNode = (pANTLR3_BASE_TREE) gchildNode->getChild(gchildNode, 0);

//var 200
if (gchildNode->getType(gchildNode) == 200)
Expand Down
17 changes: 13 additions & 4 deletions Query/GeneralEvaluation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2338,10 +2338,15 @@ void GeneralEvaluation::getFinalResult(ResultSet &result_str)
for (int i = 0; i < (int)results_id->results.size(); i++)
result_str.ansNum += (int)results_id->results[i].res.size();

#ifdef STREAM_ON
if ((long)result_str.ansNum * (long)result_str.select_var_num > 10000000 || (int)this->query_tree.getOrder().size() > 0 || this->query_tree.getOffset() != 0 || this->query_tree.getLimit() != -1)
result_str.setOutputOffsetLimit(this->query_tree.getOffset(), this->query_tree.getLimit());

#ifdef STREAM_ON
if ((long)result_str.ansNum * (long)result_str.select_var_num > 10000000 || (int)this->query_tree.getOrder().size() > 0)
{
result_str.setUseStream();
#endif
cout << "set use Stream" << endl;
}
#endif

if (!result_str.checkUseStream())
{
Expand All @@ -2362,7 +2367,7 @@ void GeneralEvaluation::getFinalResult(ResultSet &result_str)
desc.push_back(this->query_tree.getOrder()[i].descending);
}
}
result_str.openStream(keys, desc, this->query_tree.getOffset(), this->query_tree.getLimit());
result_str.openStream(keys, desc);
}

int current_result = 0;
Expand Down Expand Up @@ -2477,7 +2482,9 @@ void GeneralEvaluation::getFinalResult(ResultSet &result_str)
count = count_set.size();

stringstream ss;
ss << "\"";
ss << count;
ss << "\"^^<http://www.w3.org/2001/XMLSchema#integer>";
ss >> result_str.answer[0][i];
}
else
Expand All @@ -2503,7 +2510,9 @@ void GeneralEvaluation::getFinalResult(ResultSet &result_str)
}

stringstream ss;
ss << "\"";
ss << count;
ss << "\"^^<http://www.w3.org/2001/XMLSchema#integer>";
ss >> result_str.answer[0][i];
}
}
Expand Down
Loading

0 comments on commit d35d87e

Please sign in to comment.