-
Notifications
You must be signed in to change notification settings - Fork 37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Starting 'Select *' implementation #546
Changes from 1 commit
3ada215
fe6577e
7b8c3d8
c45ad7a
c176e1f
8cb8570
3bb4aaa
085f23d
4054695
43d7f9c
ed8ea69
c331fc4
afdbb93
c40cb3f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -99,28 +99,30 @@ QueryExecutionTree::generateResults(const SelectedVarsOrAsterisk & selectedVarsO | |
LOG(DEBUG) << "Resolving strings for finished binary result...\n"; | ||
vector<std::optional<pair<size_t, ResultTable::ResultType>>> validIndices; | ||
if(selectedVarsOrAsterisk.isAsterisk()) { | ||
list<string> orderedVariables = selectedVarsOrAsterisk.retrieveOrder(); | ||
auto allVars = getVariableColumns(); | ||
for (const auto& var : orderedVariables) { | ||
auto it = allVars.find(var); | ||
if (it != allVars.end()) { | ||
auto orderedVariablesFromQuery = selectedVarsOrAsterisk.retrieveOrder(); | ||
auto variablesFromExecutionTree = getVariableColumns(); | ||
for (const auto& variableFromQuery : orderedVariablesFromQuery) { | ||
auto it = variablesFromExecutionTree.find(variableFromQuery); | ||
if (it != variablesFromExecutionTree.end()) { | ||
validIndices.emplace_back(pair<size_t, ResultTable::ResultType>( | ||
it->second, resultTable->getResultType(it->second))); | ||
allVars.erase(it); | ||
variablesFromExecutionTree.erase(it); | ||
} else { | ||
validIndices.emplace_back(std::nullopt); | ||
} | ||
} | ||
for(const auto& var : allVars){ | ||
LOG(DEBUG) << "Variable " << var.first << " was not parsed!! \n"; | ||
for(const auto& variableFromQuery : variablesFromExecutionTree){ | ||
LOG(WARN) << "The variable \"" << variableFromQuery.first << | ||
"\" was found in the execution tree, but not in the original query. " | ||
"This is likely a bug\n"; | ||
} | ||
} | ||
else { | ||
for (auto var : selectedVarsOrAsterisk.getSelectVariables()) { | ||
if (ad_utility::startsWith(var, "TEXT(")) { | ||
var = var.substr(5, var.rfind(')') - 5); | ||
for (auto variableFromQuery : selectedVarsOrAsterisk.getSelectVariables()) { | ||
if (ad_utility::startsWith(variableFromQuery, "TEXT(")) { | ||
variableFromQuery = variableFromQuery.substr(5, variableFromQuery.rfind(')') - 5); | ||
} | ||
auto it = getVariableColumns().find(var); | ||
auto it = getVariableColumns().find(variableFromQuery); | ||
if (it != getVariableColumns().end()) { | ||
validIndices.emplace_back(pair<size_t, ResultTable::ResultType>( | ||
it->second, resultTable->getResultType(it->second))); | ||
|
@@ -156,19 +158,26 @@ template ad_utility::stream_generator::stream_generator QueryExecutionTree:: | |
// ___________________________________________________________________________ | ||
QueryExecutionTree::ColumnIndicesAndTypes | ||
QueryExecutionTree::selectedVariablesToColumnIndices( | ||
SelectedVarsOrAsterisk selectedVarsOrAsterisk, | ||
const SelectedVarsOrAsterisk & selectedVarsOrAsterisk, | ||
const ResultTable& resultTable) const { | ||
ColumnIndicesAndTypes exportColumns; | ||
if(selectedVarsOrAsterisk.isAsterisk()) { | ||
for(auto var: selectedVarsOrAsterisk.retrieveOrder()){ | ||
if (getVariableColumns().contains(var)) { | ||
auto columnIndex = getVariableColumns().at(var); | ||
auto variablesFromExecutionTree = getVariableColumns(); | ||
for(auto variableFromQuery: selectedVarsOrAsterisk.retrieveOrder()){ | ||
if (getVariableColumns().contains(variableFromQuery)) { | ||
auto columnIndex = getVariableColumns().at(variableFromQuery); | ||
exportColumns.push_back(VariableAndColumnIndex{ | ||
var, columnIndex, resultTable.getResultType(columnIndex)}); | ||
variableFromQuery, columnIndex, resultTable.getResultType(columnIndex)}); | ||
variablesFromExecutionTree.erase(variableFromQuery); | ||
} else { | ||
exportColumns.emplace_back(std::nullopt); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also add the complementary warning here. |
||
} | ||
} | ||
for(const auto& variableFromQuery : variablesFromExecutionTree){ | ||
LOG(WARN) << "The variable \"" << variableFromQuery.first << | ||
"\" was found in the execution tree, but not in the original query. " | ||
"This is likely a bug\n"; | ||
} | ||
} | ||
else { | ||
for (auto var : selectedVarsOrAsterisk.getSelectVariables()) { | ||
|
@@ -285,7 +294,7 @@ nlohmann::json QueryExecutionTree::writeResultAsSparqlJson( | |
}; | ||
|
||
for (size_t rowIndex = offset; rowIndex < upperBound; ++rowIndex) { | ||
// Due to be an 'nlohmann' object, object keys are alphabetically sorted! | ||
// TODO: ordered_json` entries are ordered alphabetically, but insertion order would be preferable. | ||
nlohmann::ordered_json binding; | ||
for (const auto& column : columns) { | ||
const auto& currentId = idTable(rowIndex, column->_columnIndex); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,7 +41,7 @@ string ParsedQuery::asString() const { | |
os << "\nSELECT: {\n\t"; | ||
if(usesAsterisk) { | ||
auto list = selectClause._varsOrAsterisk.retrieveOrder(); | ||
std::list<string>::iterator it; | ||
std::vector<string>::iterator it; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. still There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (I'm sorry, I think one of my comments got lost here). |
||
for (it = list.begin(); it != list.end(); ){ | ||
os << it->c_str(); | ||
if (++it != list.end()) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -308,24 +308,14 @@ class ParsedQuery { | |
}; | ||
|
||
typedef std::variant<vector<string>,char> SelectVarsOrAsterisk; | ||
// Representation of the 'Selector: All (*)' xor 'Selector: (VarName)+' | ||
// template <typename T> | ||
// Represents either "all Variables" (Select *) or a list of explicitly | ||
// selected Variables (Select ?a ?b). | ||
struct SelectedVarsOrAsterisk { | ||
private: | ||
SelectVarsOrAsterisk _varsOrAsterisk; | ||
std::list<string> _variablesOrder; | ||
|
||
void setAsterisk() { | ||
_varsOrAsterisk = '*'; | ||
} | ||
std::vector<string> _variablesOrder; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Call this member |
||
|
||
public: | ||
/* | ||
// Clone of the private variable typed 'variant' (vector) | ||
[[nodiscard]] SelectVarsOrAsterisk get() const { | ||
return SelectVarsOrAsterisk{_varsOrAsterisk}; | ||
} | ||
*/ | ||
|
||
[[nodiscard]] bool isAsterisk() const { | ||
return std::holds_alternative<char>(_varsOrAsterisk); | ||
|
@@ -337,15 +327,8 @@ class ParsedQuery { | |
|
||
// Sets the Selector to 'All' (*) only if the Selector is still undefined | ||
// Returned value maybe unused due to Syntax Check | ||
[[maybe_unused]] bool setsAsterisk() { | ||
/* | ||
* Needs (std::monostate_t) but unnecessary due to Syntax Check | ||
*/ | ||
// if (!isAsterisk() && !isVariables()) { | ||
setAsterisk(); | ||
return true; | ||
// } | ||
// else return false; | ||
void setsAsterisk() { | ||
_varsOrAsterisk = '*'; | ||
} | ||
joka921 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
[[nodiscard]] char getAsterisk() const { | ||
|
@@ -360,28 +343,25 @@ class ParsedQuery { | |
return std::get<std::vector<string>>(_varsOrAsterisk); | ||
} | ||
|
||
void pushVariablesOrder(const string& variable) { | ||
// Add a variable, that was found in the query body. The added variables | ||
// will only be used if `isAsterisk` is true. | ||
void addVariableFromQueryBody (const string& variable) { | ||
if(!(std::find(_variablesOrder.begin(), | ||
joka921 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
_variablesOrder.end(), | ||
variable) != _variablesOrder.end())) { | ||
_variablesOrder.emplace_back(variable); | ||
} | ||
} | ||
|
||
|
||
[[nodiscard]] std::list<string>& retrieveOrder() { | ||
return _variablesOrder; | ||
} | ||
|
||
[[nodiscard]] std::list<string> retrieveOrder() const { | ||
[[nodiscard]] auto retrieveOrder() const { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here one of my comments disappeared: |
||
return _variablesOrder; | ||
} | ||
}; | ||
|
||
joka921 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// Represents the Select Clause with all the possible outcomes | ||
struct SelectClause { | ||
// `_aliases` will be empty if Selector '*' is present. | ||
// Essentially, there is a `SELECT *` clause in the query. | ||
// This means, that there is a `SELECT *` clause in the query. | ||
std::vector<Alias> _aliases; | ||
SelectedVarsOrAsterisk _varsOrAsterisk; | ||
bool _reduced = false; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This else branch should also warn:
OG(WARN) << "The variable "" << variableFromQuery <<
"" was found in the original, query, but not in the execution tree. "
"This is likely a bug\n";