Skip to content

Commit

Permalink
Merge pull request #1787 from kuzudb/fix-version-function
Browse files Browse the repository at this point in the history
Fix kuzu version function
  • Loading branch information
acquamarin committed Jul 9, 2023
2 parents 863c462 + 606fba5 commit bfacd23
Show file tree
Hide file tree
Showing 11 changed files with 1,620 additions and 1,579 deletions.
2 changes: 1 addition & 1 deletion src/antlr4/Cypher.g4
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ oC_ReadingClause
;

kU_InQueryCall
: CALL SP oC_FunctionName SP? '(' oC_Literal? ')' ;
: CALL SP oC_FunctionName SP? '(' oC_Literal* ')' ;

oC_Match
: ( OPTIONAL SP )? MATCH SP? oC_Pattern (SP? oC_Where)? ;
Expand Down
16 changes: 9 additions & 7 deletions src/binder/bind/bind_reading_clause.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include "binder/call/bound_in_query_call.h"
#include "binder/expression/literal_expression.h"
#include "binder/query/reading_clause/bound_unwind_clause.h"
#include "parser/call/in_query_call.h"
#include "parser/query/reading_clause/in_query_call_clause.h"
#include "parser/query/reading_clause/unwind_clause.h"

using namespace kuzu::common;
Expand All @@ -20,7 +20,7 @@ std::unique_ptr<BoundReadingClause> Binder::bindReadingClause(const ReadingClaus
return bindUnwindClause((UnwindClause&)readingClause);
}
case ClauseType::InQueryCall: {
return bindInQueryCall((InQueryCall&)readingClause);
return bindInQueryCall((InQueryCallClause&)readingClause);
}
default:
throw NotImplementedException("bindReadingClause().");
Expand Down Expand Up @@ -58,14 +58,16 @@ std::unique_ptr<BoundReadingClause> Binder::bindUnwindClause(const ReadingClause
}

std::unique_ptr<BoundReadingClause> Binder::bindInQueryCall(const ReadingClause& readingClause) {
auto& callStatement = reinterpret_cast<const parser::InQueryCall&>(readingClause);
auto& callStatement = reinterpret_cast<const parser::InQueryCallClause&>(readingClause);
auto tableFunctionDefinition =
catalog.getBuiltInTableFunction()->mathTableFunction(callStatement.getFuncName());
auto boundExpr = expressionBinder.bindLiteralExpression(*callStatement.getParameter());
auto inputValue = reinterpret_cast<LiteralExpression*>(boundExpr.get())->getValue();
auto inputValues = std::vector<common::Value>{};
for (auto& parameter : callStatement.getParameters()) {
auto boundExpr = expressionBinder.bindLiteralExpression(*parameter);
inputValues.push_back(*reinterpret_cast<LiteralExpression*>(boundExpr.get())->getValue());
}
auto bindData = tableFunctionDefinition->bindFunc(clientContext,
function::TableFuncBindInput{std::vector<common::Value>{*inputValue}},
catalog.getReadOnlyVersion());
function::TableFuncBindInput{std::move(inputValues)}, catalog.getReadOnlyVersion());
expression_vector outputExpressions;
for (auto i = 0u; i < bindData->returnColumnNames.size(); i++) {
outputExpressions.push_back(
Expand Down
2 changes: 1 addition & 1 deletion src/function/table_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ std::unique_ptr<TableFuncBindData> DBVersionFunction::bindFunc(main::ClientConte
kuzu::function::TableFuncBindInput input, catalog::CatalogContent* catalog) {
std::vector<std::string> returnColumnNames;
std::vector<common::LogicalType> returnTypes;
returnColumnNames.emplace_back("KUZU_Version");
returnColumnNames.emplace_back("version");
returnTypes.emplace_back(common::LogicalTypeID::STRING);
return std::make_unique<TableFuncBindData>(
std::move(returnTypes), std::move(returnColumnNames), 1 /* one row result */);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,20 @@
namespace kuzu {
namespace parser {

class InQueryCall : public ReadingClause {
class InQueryCallClause : public ReadingClause {
public:
InQueryCall(std::string optionName, std::unique_ptr<ParsedExpression> optionValue)
InQueryCallClause(
std::string optionName, std::vector<std::unique_ptr<ParsedExpression>> parameters)
: ReadingClause{common::ClauseType::InQueryCall}, funcName{std::move(optionName)},
parameter{std::move(optionValue)} {}
parameters{std::move(parameters)} {}

inline std::string getFuncName() const { return funcName; }

inline ParsedExpression* getParameter() const { return parameter.get(); }
std::vector<ParsedExpression*> getParameters() const;

private:
std::string funcName;
std::unique_ptr<ParsedExpression> parameter;
std::vector<std::unique_ptr<ParsedExpression>> parameters;
};

} // namespace parser
Expand Down
2 changes: 2 additions & 0 deletions src/parser/query/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
add_subdirectory(reading_clause)

add_library(kuzu_parser_query
OBJECT
single_query.cpp)
Expand Down
7 changes: 7 additions & 0 deletions src/parser/query/reading_clause/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
add_library(kuzu_reading_clause
OBJECT
in_query_call_clause.cpp)

set(ALL_OBJECT_FILES
${ALL_OBJECT_FILES} $<TARGET_OBJECTS:kuzu_reading_clause>
PARENT_SCOPE)
16 changes: 16 additions & 0 deletions src/parser/query/reading_clause/in_query_call_clause.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#include "parser/query/reading_clause/in_query_call_clause.h"

namespace kuzu {
namespace parser {

std::vector<ParsedExpression*> InQueryCallClause::getParameters() const {
std::vector<ParsedExpression*> parametersToReturn;
parametersToReturn.reserve(parameters.size());
for (auto& parameter : parameters) {
parametersToReturn.push_back(parameter.get());
}
return parametersToReturn;
}

} // namespace parser
} // namespace kuzu
9 changes: 6 additions & 3 deletions src/parser/transformer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

#include "common/copier_config/copier_config.h"
#include "common/string_utils.h"
#include "parser/call/in_query_call.h"
#include "parser/call/standalone_call.h"
#include "parser/copy.h"
#include "parser/ddl/add_property.h"
Expand All @@ -20,6 +19,7 @@
#include "parser/expression/parsed_property_expression.h"
#include "parser/expression/parsed_subquery_expression.h"
#include "parser/expression/parsed_variable_expression.h"
#include "parser/query/reading_clause/in_query_call_clause.h"
#include "parser/query/reading_clause/unwind_clause.h"
#include "parser/query/updating_clause/create_clause.h"
#include "parser/query/updating_clause/delete_clause.h"
Expand Down Expand Up @@ -150,8 +150,11 @@ std::unique_ptr<ReadingClause> Transformer::transformUnwind(CypherParser::OC_Unw
std::unique_ptr<ReadingClause> Transformer::transformInQueryCall(
CypherParser::KU_InQueryCallContext& ctx) {
auto funcName = transformFunctionName(*ctx.oC_FunctionName());
auto parameter = transformLiteral(*ctx.oC_Literal());
return std::make_unique<InQueryCall>(std::move(funcName), std::move(parameter));
std::vector<std::unique_ptr<ParsedExpression>> parameter;
for (auto& literal : ctx.oC_Literal()) {
parameter.push_back(transformLiteral(*literal));
}
return std::make_unique<InQueryCallClause>(std::move(funcName), std::move(parameter));
}

std::unique_ptr<UpdatingClause> Transformer::transformCreate(CypherParser::OC_CreateContext& ctx) {
Expand Down
2 changes: 1 addition & 1 deletion test/test_files/tinysnb/function/table.test
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,6 @@ height
<FILE>:function_table_info_answer.txt

-LOG ReturnDBVersion
-STATEMENT CALL db_version('') RETURN KUZU_Version
-STATEMENT CALL db_version() RETURN version
---- 1
v0.4.0
Loading

0 comments on commit bfacd23

Please sign in to comment.