Skip to content
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

Add new attributes to the front for better interactive querying #5

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ src:=parser/ASTBase.cpp parser/SaneQLLexer.cpp infra/Schema.cpp semana/Functions
gensrc:=$(PREFIX)parser/saneql_parser.cpp
obj:=$(addprefix $(PREFIX),$(src:.cpp=.o)) $(gensrc:.cpp=.o)

CXXFLAGS:=-std=c++23 -I$(PREFIX) -I. -g -Wall -Wextra
CXXFLAGS:=-std=c++20 -I$(PREFIX) -I. -g -Wall -Wextra

-include $(addprefix $(PREFIX),$(src:.cpp=.d)) $(gensrc:.cpp=.d)

Expand Down
20 changes: 13 additions & 7 deletions semana/SemanticAnalysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ SemanticAnalysis::BindingInfo::Scope* SemanticAnalysis::BindingInfo::addScope(co
return &(scopes[name]);
}
//---------------------------------------------------------------------------
void SemanticAnalysis::BindingInfo::addBinding(Scope* scope, const string& column, const algebra::IU* iu)
void SemanticAnalysis::BindingInfo::addBinding(Scope* scope, const string& column, const algebra::IU* iu, bool toEnd)
// Add a binding
{
if (scope) {
Expand All @@ -198,7 +198,13 @@ void SemanticAnalysis::BindingInfo::addBinding(Scope* scope, const string& colum
e = ambiguousIU;
else
e = iu;
columns.push_back({column, iu});
columns.insert((toEnd ? columns.end() : columns.begin()), 1, {column, iu});
}
//---------------------------------------------------------------------------
void SemanticAnalysis::BindingInfo::addBindingAtFront(Scope* scope, const string& column, const algebra::IU* iu)
// Add a binding
{
addBinding(scope, column, iu, false);
}
//---------------------------------------------------------------------------
const algebra::IU* SemanticAnalysis::BindingInfo::lookup(const string& name) const
Expand Down Expand Up @@ -246,7 +252,7 @@ SemanticAnalysis::BindingInfo::ArgumentInformation SemanticAnalysis::BindingInfo
void SemanticAnalysis::BindingInfo::join(const BindingInfo& other)
// Merge after a join
{
columns.insert(columns.end(), other.columns.begin(), other.columns.end());
columns.insert(columns.begin(), other.columns.begin(), other.columns.end());
for (auto& c : other.columnLookup) {
if (!columnLookup.count(c.first)) {
columnLookup.insert(c);
Expand Down Expand Up @@ -768,10 +774,10 @@ SemanticAnalysis::ExpressionResult SemanticAnalysis::analyzeMap(ExpressionResult
name = to_string(scope->columns.size() + 1);
}
if (auto iuref = dynamic_cast<algebra::IURef*>(results[slot].value.get())) {
resultBinding.addBinding(scope, name, iuref->getIU());
resultBinding.addBindingAtFront(scope, name, iuref->getIU());
results[slot].iu.reset();
} else {
resultBinding.addBinding(scope, name, results[slot].iu.get());
resultBinding.addBindingAtFront(scope, name, results[slot].iu.get());
}
++slot;
}
Expand Down Expand Up @@ -869,10 +875,10 @@ SemanticAnalysis::ExpressionResult SemanticAnalysis::analyzeWindow(ExpressionRes
name = to_string(scope->columns.size() + 1);
}
if (auto iuref = dynamic_cast<algebra::IURef*>(results[slot].value.get())) {
resultBinding.addBinding(scope, name, iuref->getIU());
resultBinding.addBindingAtFront(scope, name, iuref->getIU());
results[slot].iu.reset();
} else {
resultBinding.addBinding(scope, name, results[slot].iu.get());
resultBinding.addBindingAtFront(scope, name, results[slot].iu.get());
}
++slot;
}
Expand Down
4 changes: 3 additions & 1 deletion semana/SemanticAnalysis.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,9 @@ class SemanticAnalysis {
/// Add a new scope, mark it as ambiguous if it already exists
Scope* addScope(const std::string& name);
/// Add a binding
void addBinding(Scope* scope, const std::string& column, const algebra::IU* iu);
void addBinding(Scope* scope, const std::string& column, const algebra::IU* iu, bool toEnd=true);
/// Add a binding at the front of the columns list
void addBindingAtFront(Scope* scope, const std::string& column, const algebra::IU* iu);

/// Lookup a column
const algebra::IU* lookup(const std::string& name) const;
Expand Down