-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1836 from kuzudb/macro
Implement scalar macro
- Loading branch information
Showing
61 changed files
with
5,272 additions
and
3,858 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#include "binder/binder.h" | ||
#include "binder/macro/bound_create_macro.h" | ||
#include "common/string_utils.h" | ||
#include "parser/macro/create_macro.h" | ||
|
||
namespace kuzu { | ||
namespace binder { | ||
|
||
std::unique_ptr<BoundStatement> Binder::bindCreateMacro(const parser::Statement& statement) { | ||
auto& createMacro = reinterpret_cast<const parser::CreateMacro&>(statement); | ||
auto macroName = createMacro.getMacroName(); | ||
if (catalog.getReadOnlyVersion()->containMacro(macroName)) { | ||
throw common::BinderException{ | ||
common::StringUtils::string_format("Macro {} already exists.", macroName)}; | ||
} | ||
parser::default_macro_args defaultArgs; | ||
for (auto& defaultArg : createMacro.getDefaultArgs()) { | ||
defaultArgs.emplace_back(defaultArg.first, defaultArg.second->copy()); | ||
} | ||
auto scalarMacro = | ||
std::make_unique<function::ScalarMacroFunction>(createMacro.getMacroExpression()->copy(), | ||
createMacro.getPositionalArgs(), std::move(defaultArgs)); | ||
return std::make_unique<BoundCreateMacro>(macroName, std::move(scalarMacro)); | ||
} | ||
|
||
} // namespace binder | ||
} // namespace kuzu |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#include "function/scalar_macro_function.h" | ||
|
||
namespace kuzu { | ||
namespace function { | ||
|
||
macro_parameter_value_map ScalarMacroFunction::getDefaultParameterVals() const { | ||
macro_parameter_value_map defaultArgsToReturn; | ||
for (auto& defaultArg : defaultArgs) { | ||
defaultArgsToReturn.emplace(defaultArg.first, defaultArg.second.get()); | ||
} | ||
return defaultArgsToReturn; | ||
} | ||
|
||
std::unique_ptr<ScalarMacroFunction> ScalarMacroFunction::copy() const { | ||
parser::default_macro_args defaultArgsCopy; | ||
for (auto& defaultArg : defaultArgs) { | ||
defaultArgsCopy.emplace_back(defaultArg.first, defaultArg.second->copy()); | ||
} | ||
return std::make_unique<ScalarMacroFunction>( | ||
expression->copy(), positionalArgs, std::move(defaultArgsCopy)); | ||
} | ||
|
||
} // namespace function | ||
} // namespace kuzu |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#pragma once | ||
|
||
#include "binder/bound_statement.h" | ||
#include "function/scalar_macro_function.h" | ||
|
||
namespace kuzu { | ||
namespace binder { | ||
|
||
class BoundCreateMacro : public BoundStatement { | ||
public: | ||
explicit BoundCreateMacro( | ||
std::string macroName, std::unique_ptr<function::ScalarMacroFunction> macro) | ||
: BoundStatement{common::StatementType::CREATE_MACRO, | ||
BoundStatementResult::createSingleStringColumnResult("result" /* columnName */)}, | ||
macroName{std::move(macroName)}, macro{std::move(macro)} {} | ||
|
||
inline std::string getMacroName() const { return macroName; } | ||
|
||
inline std::unique_ptr<function::ScalarMacroFunction> getMacro() const { return macro->copy(); } | ||
|
||
private: | ||
std::string macroName; | ||
std::unique_ptr<function::ScalarMacroFunction> macro; | ||
}; | ||
|
||
} // namespace binder | ||
} // namespace kuzu |
Oops, something went wrong.