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

Clear unnecessary smart ptr parser #2622

Merged
merged 1 commit into from
Jan 1, 2024
Merged
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
4 changes: 3 additions & 1 deletion src/binder/bind/bind_copy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ std::unique_ptr<BoundStatement> Binder::bindCopyToClause(const Statement& statem
auto fileType = bindFileType(boundFilePath);
std::vector<std::string> columnNames;
std::vector<std::unique_ptr<LogicalType>> columnTypes;
auto query = bindQuery(*copyToStatement.getRegularQuery());
auto parsedQuery =
ku_dynamic_cast<const Statement*, const RegularQuery*>(copyToStatement.getStatement());
auto query = bindQuery(*parsedQuery);
auto columns = query->getStatementResult()->getColumns();
for (auto& column : columns) {
auto columnName = column->hasAlias() ? column->getAlias() : column->toString();
Expand Down
8 changes: 4 additions & 4 deletions src/binder/bind/bind_ddl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,10 @@ std::unique_ptr<BoundCreateTableInfo> Binder::bindCreateRelTableGroupInfo(
.append(srcTableName)
.append("_")
.append(dstTableName);
auto relExtraInfo =
auto relCreateInfo = std::make_unique<CreateTableInfo>(TableType::REL, relTableName);
relCreateInfo->propertyNameDataTypes = info->propertyNameDataTypes;
relCreateInfo->extraInfo =
std::make_unique<ExtraCreateRelTableInfo>(relMultiplicity, srcTableName, dstTableName);
auto relCreateInfo = std::make_unique<CreateTableInfo>(
TableType::REL, relTableName, info->propertyNameDataTypes, std::move(relExtraInfo));
boundCreateRelTableInfos.push_back(bindCreateRelTableInfo(relCreateInfo.get()));
}
auto boundExtraInfo =
Expand All @@ -156,7 +156,7 @@ std::unique_ptr<BoundCreateTableInfo> Binder::bindCreateRelTableGroupInfo(

std::unique_ptr<BoundStatement> Binder::bindCreateTable(const Statement& statement) {
auto& createTable = ku_dynamic_cast<const Statement&, const CreateTable&>(statement);
auto tableName = createTable.getTableName();
auto tableName = createTable.getInfo()->tableName;
if (catalog.containsTable(clientContext->getTx(), tableName)) {
throw BinderException(tableName + " already exists in catalog.");
}
Expand Down
4 changes: 2 additions & 2 deletions src/binder/bind/bind_graph_pattern.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ namespace binder {
// We do not store key-value pairs in query graph primarily because we will merge key-value
// std::pairs with other predicates specified in WHERE clause.
std::unique_ptr<BoundGraphPattern> Binder::bindGraphPattern(
const std::vector<std::unique_ptr<PatternElement>>& graphPattern) {
const std::vector<PatternElement>& graphPattern) {
auto propertyCollection = std::make_unique<PropertyKeyValCollection>();
auto queryGraphCollection = std::make_unique<QueryGraphCollection>();
for (auto& patternElement : graphPattern) {
queryGraphCollection->addAndMergeQueryGraphIfConnected(
bindPatternElement(*patternElement, *propertyCollection));
bindPatternElement(patternElement, *propertyCollection));
}
auto boundPattern = std::make_unique<BoundGraphPattern>();
boundPattern->queryGraphCollection = std::move(queryGraphCollection);
Expand Down
2 changes: 1 addition & 1 deletion src/binder/bind/bind_projection_clause.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ std::unique_ptr<BoundProjectionBody> Binder::bindProjectionBody(
}

expression_vector Binder::bindProjectionExpressions(
const parsed_expression_vector& projectionExpressions) {
const parsed_expr_vector& projectionExpressions) {
expression_vector result;
for (auto& expression : projectionExpressions) {
if (expression->getExpressionType() == ExpressionType::STAR) {
Expand Down
11 changes: 5 additions & 6 deletions src/binder/bind/bind_reading_clause.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ std::unique_ptr<BoundReadingClause> Binder::bindReadingClause(const ReadingClaus

std::unique_ptr<BoundReadingClause> Binder::bindMatchClause(const ReadingClause& readingClause) {
auto& matchClause = ku_dynamic_cast<const ReadingClause&, const MatchClause&>(readingClause);
auto boundGraphPattern = bindGraphPattern(matchClause.getPatternElements());
auto boundGraphPattern = bindGraphPattern(matchClause.getPatternElementsRef());
if (matchClause.hasWherePredicate()) {
boundGraphPattern->where = bindWhereExpression(*matchClause.getWherePredicate());
}
Expand Down Expand Up @@ -105,11 +105,10 @@ std::unique_ptr<BoundReadingClause> Binder::bindInQueryCall(const ReadingClause&
auto funcName = funcExpr->getFunctionName();
StringUtils::toUpper(funcName);
if (funcName == common::READ_PANDAS_FUNC_NAME && clientContext->replaceFunc) {
auto replacedValue = clientContext->replaceFunc(
ku_dynamic_cast<ParsedExpression*, ParsedLiteralExpression*>(funcExpr->getChild(0))
->getValue());
auto parameterExpression =
std::make_unique<ParsedLiteralExpression>(std::move(replacedValue), "pd");
auto literalExpr =
ku_dynamic_cast<ParsedExpression*, ParsedLiteralExpression*>(funcExpr->getChild(0));
auto replacedValue = clientContext->replaceFunc(literalExpr->getValueUnsafe());
auto parameterExpression = std::make_unique<ParsedLiteralExpression>(*replacedValue, "pd");
auto inQueryCallParameterReplacer = std::make_unique<InQueryCallParameterReplacer>(
std::make_pair(funcName, parameterExpression.get()));
funcExpr = inQueryCallParameterReplacer->visit(funcExpr);
Expand Down
4 changes: 2 additions & 2 deletions src/include/binder/binder.h
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ class Binder {
const expression_vector& projectionExpressions);

expression_vector bindProjectionExpressions(
const parser::parsed_expression_vector& parsedExpressions);
const parser::parsed_expr_vector& parsedExpressions);

expression_vector bindOrderByExpressions(
const std::vector<std::unique_ptr<parser::ParsedExpression>>& orderByExpressions);
Expand All @@ -221,7 +221,7 @@ class Binder {

/*** bind graph pattern ***/
std::unique_ptr<BoundGraphPattern> bindGraphPattern(
const std::vector<std::unique_ptr<parser::PatternElement>>& graphPattern);
const std::vector<parser::PatternElement>& graphPattern);

std::unique_ptr<QueryGraph> bindPatternElement(
const parser::PatternElement& patternElement, PropertyKeyValCollection& collection);
Expand Down
4 changes: 4 additions & 0 deletions src/include/common/copy_constructors.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@

#define DELETE_COPY_CONSTRUCT(Object) Object(const Object& other) = delete
#define DELETE_COPY_ASSN(Object) Object& operator=(const Object& other) = delete
// NOLINTBEGIN
#define DELETE_MOVE_CONSTRUCT(Object) Object(Object&& other) = delete
#define DELETE_MOVE_ASSN(Object) Object& operator=(Object&& other) = delete
// NOLINTEND

#define DELETE_BOTH_COPY(Object) \
DELETE_COPY_CONSTRUCT(Object); \
Expand All @@ -15,8 +17,10 @@
DELETE_MOVE_CONSTRUCT(Object); \
DELETE_MOVE_ASSN(Object)

// NOLINTBEGIN
#define DEFAULT_MOVE_CONSTRUCT(Object) Object(Object&& other) = default
#define DEFAULT_MOVE_ASSN(Object) Object& operator=(Object&& other) = default
// NOLINTEND

#define DEFAULT_BOTH_MOVE(Object) \
DEFAULT_MOVE_CONSTRUCT(Object); \
Expand Down
11 changes: 5 additions & 6 deletions src/include/parser/copy.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#include <vector>

#include "parser/expression/parsed_expression.h"
#include "parser/query/regular_query.h"
#include "parser/statement.h"

namespace kuzu {
Expand Down Expand Up @@ -44,16 +43,16 @@ class CopyFrom : public Copy {

class CopyTo : public Copy {
public:
CopyTo(std::string filePath, std::unique_ptr<RegularQuery> regularQuery)
: Copy{common::StatementType::COPY_TO}, filePath{std::move(filePath)},
regularQuery{std::move(regularQuery)} {}
CopyTo(std::string filePath, std::unique_ptr<Statement> statement)
: Copy{common::StatementType::COPY_TO}, filePath{std::move(filePath)}, statement{std::move(
statement)} {}

inline std::string getFilePath() const { return filePath; }
inline RegularQuery* getRegularQuery() const { return regularQuery.get(); }
inline const Statement* getStatement() const { return statement.get(); }

private:
std::string filePath;
std::unique_ptr<RegularQuery> regularQuery;
std::unique_ptr<Statement> statement;
};

} // namespace parser
Expand Down
6 changes: 3 additions & 3 deletions src/include/parser/ddl/alter.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ namespace parser {

class Alter : public Statement {
public:
explicit Alter(std::unique_ptr<AlterInfo> info)
explicit Alter(AlterInfo info)
: Statement{common::StatementType::ALTER}, info{std::move(info)} {}

inline AlterInfo* getInfo() const { return info.get(); }
inline const AlterInfo* getInfo() const { return &info; }

private:
std::unique_ptr<AlterInfo> info;
AlterInfo info;
};

} // namespace parser
Expand Down
2 changes: 2 additions & 0 deletions src/include/parser/ddl/alter_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <string>

#include "common/copy_constructors.h"
#include "common/enums/alter_type.h"
#include "parser/expression/parsed_expression.h"

Expand All @@ -20,6 +21,7 @@ struct AlterInfo {
AlterInfo(
common::AlterType type, std::string tableName, std::unique_ptr<ExtraAlterInfo> extraInfo)
: type{type}, tableName{std::move(tableName)}, extraInfo{std::move(extraInfo)} {}
DELETE_COPY_DEFAULT_MOVE(AlterInfo);
};

struct ExtraRenameTableInfo : public ExtraAlterInfo {
Expand Down
12 changes: 6 additions & 6 deletions src/include/parser/ddl/create_table.h
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
#pragma once

#include "create_table_info.h"
#include "ddl.h"
#include "parser/statement.h"

namespace kuzu {
namespace parser {

class CreateTable : public DDL {
class CreateTable final : public Statement {
public:
CreateTable(std::string tableName, std::unique_ptr<CreateTableInfo> info)
: DDL{common::StatementType::CREATE_TABLE, std::move(tableName)}, info{std::move(info)} {}
explicit CreateTable(CreateTableInfo info)
: Statement{common::StatementType::CREATE_TABLE}, info{std::move(info)} {}

inline CreateTableInfo* getInfo() const { return info.get(); }
inline const CreateTableInfo* getInfo() const { return &info; }

private:
std::unique_ptr<CreateTableInfo> info;
CreateTableInfo info;
};

} // namespace parser
Expand Down
8 changes: 2 additions & 6 deletions src/include/parser/ddl/create_table_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <utility>
#include <vector>

#include "common/copy_constructors.h"
#include "common/enums/table_type.h"

namespace kuzu {
Expand All @@ -22,12 +23,7 @@ struct CreateTableInfo {

CreateTableInfo(common::TableType tableType, std::string tableName)
: tableType{tableType}, tableName{std::move(tableName)}, extraInfo{nullptr} {}
CreateTableInfo(common::TableType tableType, std::string tableName,
std::vector<std::pair<std::string, std::string>> propertyNameDataTypes,
std::unique_ptr<ExtraCreateTableInfo> extraInfo)
: tableType{tableType}, tableName{std::move(tableName)},
propertyNameDataTypes{std::move(propertyNameDataTypes)}, extraInfo{
std::move(extraInfo)} {};
DELETE_COPY_DEFAULT_MOVE(CreateTableInfo);
};

struct ExtraCreateNodeTableInfo : public ExtraCreateTableInfo {
Expand Down
22 changes: 0 additions & 22 deletions src/include/parser/ddl/ddl.h

This file was deleted.

32 changes: 18 additions & 14 deletions src/include/parser/expression/parsed_case_expression.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once

#include "common/copy_constructors.h"
#include "parsed_expression.h"

namespace kuzu {
Expand All @@ -9,42 +10,42 @@
std::unique_ptr<ParsedExpression> whenExpression;
std::unique_ptr<ParsedExpression> thenExpression;

ParsedCaseAlternative() = default;
ParsedCaseAlternative(std::unique_ptr<ParsedExpression> whenExpression,
std::unique_ptr<ParsedExpression> thenExpression)
: whenExpression{std::move(whenExpression)}, thenExpression{std::move(thenExpression)} {}
ParsedCaseAlternative(const ParsedCaseAlternative& other)
: whenExpression{other.whenExpression->copy()}, thenExpression{
other.thenExpression->copy()} {}
DEFAULT_BOTH_MOVE(ParsedCaseAlternative);

void serialize(common::Serializer& serializer) const;
static std::unique_ptr<ParsedCaseAlternative> deserialize(common::Deserializer& deserializer);

inline std::unique_ptr<ParsedCaseAlternative> copy() const {
return std::make_unique<ParsedCaseAlternative>(
whenExpression->copy(), thenExpression->copy());
}
static ParsedCaseAlternative deserialize(common::Deserializer& deserializer);
};

// Cypher supports 2 types of CaseExpression
// 1. CASE a.age
// WHEN 20 THEN ...
// 2. CASE
// WHEN a.age = 20 THEN ...
class ParsedCaseExpression : public ParsedExpression {
class ParsedCaseExpression final : public ParsedExpression {

Check warning on line 31 in src/include/parser/expression/parsed_case_expression.h

View check run for this annotation

Codecov / codecov/patch

src/include/parser/expression/parsed_case_expression.h#L31

Added line #L31 was not covered by tests
friend class ParsedExpressionChildrenVisitor;

public:
explicit ParsedCaseExpression(std::string raw)
: ParsedExpression{common::ExpressionType::CASE_ELSE, std::move(raw)} {};

ParsedCaseExpression(std::string alias, std::string rawName, parsed_expression_vector children,
ParsedCaseExpression(std::string alias, std::string rawName, parsed_expr_vector children,
std::unique_ptr<ParsedExpression> caseExpression,
std::vector<std::unique_ptr<ParsedCaseAlternative>> caseAlternatives,
std::vector<ParsedCaseAlternative> caseAlternatives,
std::unique_ptr<ParsedExpression> elseExpression)
: ParsedExpression{common::ExpressionType::CASE_ELSE, std::move(alias), std::move(rawName),
std::move(children)},
caseExpression{std::move(caseExpression)}, caseAlternatives{std::move(caseAlternatives)},
elseExpression{std::move(elseExpression)} {}

ParsedCaseExpression(std::unique_ptr<ParsedExpression> caseExpression,
std::vector<std::unique_ptr<ParsedCaseAlternative>> caseAlternatives,
std::vector<ParsedCaseAlternative> caseAlternatives,
std::unique_ptr<ParsedExpression> elseExpression)
: ParsedExpression{common::ExpressionType::CASE_ELSE}, caseExpression{std::move(
caseExpression)},
Expand All @@ -57,12 +58,15 @@
inline bool hasCaseExpression() const { return caseExpression != nullptr; }
inline ParsedExpression* getCaseExpression() const { return caseExpression.get(); }

inline void addCaseAlternative(std::unique_ptr<ParsedCaseAlternative> caseAlternative) {
inline void addCaseAlternative(ParsedCaseAlternative caseAlternative) {
caseAlternatives.push_back(std::move(caseAlternative));
}
inline uint32_t getNumCaseAlternative() const { return caseAlternatives.size(); }
inline ParsedCaseAlternative* getCaseAlternative(uint32_t idx) const {
return caseAlternatives[idx].get();
inline ParsedCaseAlternative* getCaseAlternativeUnsafe(uint32_t idx) {
return &caseAlternatives[idx];
}
inline const ParsedCaseAlternative* getCaseAlternative(uint32_t idx) const {
return &caseAlternatives[idx];
}

inline void setElseExpression(std::unique_ptr<ParsedExpression> expression) {
Expand All @@ -81,7 +85,7 @@
private:
// Optional. If not specified, directly check next whenExpression
std::unique_ptr<ParsedExpression> caseExpression;
std::vector<std::unique_ptr<ParsedCaseAlternative>> caseAlternatives;
std::vector<ParsedCaseAlternative> caseAlternatives;
// Optional. If not specified, evaluate as null
std::unique_ptr<ParsedExpression> elseExpression;
};
Expand Down
16 changes: 9 additions & 7 deletions src/include/parser/expression/parsed_expression.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <unordered_map>
#include <vector>

#include "common/copy_constructors.h"
#include "common/enums/expression_type.h"

namespace kuzu {
Expand All @@ -19,9 +20,10 @@

class ParsedExpression;
class ParsedExpressionChildrenVisitor;
using parsed_expression_vector = std::vector<std::unique_ptr<ParsedExpression>>;
using parsed_expression_pair =
using parsed_expr_vector = std::vector<std::unique_ptr<ParsedExpression>>;
using parsed_expr_pair =
std::pair<std::unique_ptr<ParsedExpression>, std::unique_ptr<ParsedExpression>>;
using s_parsed_expr_pair = std::pair<std::string, std::unique_ptr<ParsedExpression>>;

class ParsedExpression {
friend class ParsedExpressionChildrenVisitor;
Expand All @@ -39,10 +41,10 @@
explicit ParsedExpression(common::ExpressionType type) : type{type} {}

ParsedExpression(common::ExpressionType type, std::string alias, std::string rawName,
parsed_expression_vector children)
parsed_expr_vector children)
: type{type}, alias{std::move(alias)}, rawName{std::move(rawName)}, children{std::move(
children)} {}

DELETE_COPY_DEFAULT_MOVE(ParsedExpression);
virtual ~ParsedExpression() = default;

inline common::ExpressionType getExpressionType() const { return type; }
Expand All @@ -69,16 +71,16 @@
static std::unique_ptr<ParsedExpression> deserialize(common::Deserializer& deserializer);

protected:
parsed_expression_vector copyChildren() const;
parsed_expr_vector copyChildren() const;

private:
virtual inline void serializeInternal(common::Serializer& /*serializer*/) const {}
virtual inline void serializeInternal(common::Serializer&) const {}

Check warning on line 77 in src/include/parser/expression/parsed_expression.h

View check run for this annotation

Codecov / codecov/patch

src/include/parser/expression/parsed_expression.h#L77

Added line #L77 was not covered by tests

protected:
common::ExpressionType type;
std::string alias;
std::string rawName;
parsed_expression_vector children;
parsed_expr_vector children;
};

using parsing_option_t = std::unordered_map<std::string, std::unique_ptr<parser::ParsedExpression>>;
Expand Down
Loading