-
Notifications
You must be signed in to change notification settings - Fork 86
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 #1896 from kuzudb/parser-reorg
Reorg parser module
- Loading branch information
Showing
22 changed files
with
1,247 additions
and
1,147 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
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
File renamed without changes.
File renamed without changes.
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
2 changes: 1 addition & 1 deletion
2
src/parser/macro/create_macro.cpp → src/parser/create_macro.cpp
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
#include "parser/macro/create_macro.h" | ||
#include "parser/create_macro.h" | ||
|
||
namespace kuzu { | ||
namespace parser { | ||
|
This file was deleted.
Oops, something went wrong.
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,16 @@ | ||
add_library(kuzu_parser_transform | ||
OBJECT | ||
transform_copy.cpp | ||
transform_ddl.cpp | ||
transform_expression.cpp | ||
transform_graph_pattern.cpp | ||
transform_macro.cpp | ||
transform_projection.cpp | ||
transform_query.cpp | ||
transform_reading_clause.cpp | ||
transform_standalone_call.cpp | ||
transform_updating_clause.cpp) | ||
|
||
set(ALL_OBJECT_FILES | ||
${ALL_OBJECT_FILES} $<TARGET_OBJECTS:kuzu_parser_transform> | ||
PARENT_SCOPE) |
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,53 @@ | ||
#include "parser/copy.h" | ||
#include "parser/transformer.h" | ||
|
||
namespace kuzu { | ||
namespace parser { | ||
|
||
std::unique_ptr<Statement> Transformer::transformCopyTo(CypherParser::KU_CopyTOContext& ctx) { | ||
std::string filePath = transformStringLiteral(*ctx.StringLiteral()); | ||
auto regularQuery = transformQuery(*ctx.oC_Query()); | ||
return std::make_unique<CopyTo>(std::move(filePath), std::move(regularQuery)); | ||
} | ||
|
||
std::unique_ptr<Statement> Transformer::transformCopyFromCSV( | ||
CypherParser::KU_CopyFromCSVContext& ctx) { | ||
auto filePaths = transformFilePaths(ctx.kU_FilePaths()->StringLiteral()); | ||
auto tableName = transformSchemaName(*ctx.oC_SchemaName()); | ||
auto parsingOptions = ctx.kU_ParsingOptions() ? | ||
transformParsingOptions(*ctx.kU_ParsingOptions()) : | ||
std::unordered_map<std::string, std::unique_ptr<ParsedExpression>>(); | ||
return std::make_unique<CopyFrom>(std::move(filePaths), std::move(tableName), | ||
std::move(parsingOptions), common::CopyDescription::FileType::UNKNOWN); | ||
} | ||
|
||
std::unique_ptr<Statement> Transformer::transformCopyFromNPY( | ||
CypherParser::KU_CopyFromNPYContext& ctx) { | ||
auto filePaths = transformFilePaths(ctx.StringLiteral()); | ||
auto tableName = transformSchemaName(*ctx.oC_SchemaName()); | ||
auto parsingOptions = std::unordered_map<std::string, std::unique_ptr<ParsedExpression>>(); | ||
return std::make_unique<CopyFrom>(std::move(filePaths), std::move(tableName), | ||
std::move(parsingOptions), common::CopyDescription::FileType::NPY); | ||
} | ||
|
||
std::vector<std::string> Transformer::transformFilePaths( | ||
std::vector<antlr4::tree::TerminalNode*> stringLiteral) { | ||
std::vector<std::string> csvFiles; | ||
for (auto& csvFile : stringLiteral) { | ||
csvFiles.push_back(transformStringLiteral(*csvFile)); | ||
} | ||
return csvFiles; | ||
} | ||
|
||
std::unordered_map<std::string, std::unique_ptr<ParsedExpression>> | ||
Transformer::transformParsingOptions(CypherParser::KU_ParsingOptionsContext& ctx) { | ||
std::unordered_map<std::string, std::unique_ptr<ParsedExpression>> copyOptions; | ||
for (auto loadOption : ctx.kU_ParsingOption()) { | ||
auto optionName = transformSymbolicName(*loadOption->oC_SymbolicName()); | ||
copyOptions.emplace(optionName, transformLiteral(*loadOption->oC_Literal())); | ||
} | ||
return copyOptions; | ||
} | ||
|
||
} // namespace parser | ||
} // 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
#include "parser/ddl/add_property.h" | ||
#include "parser/ddl/create_node_clause.h" | ||
#include "parser/ddl/create_rel_clause.h" | ||
#include "parser/ddl/drop_property.h" | ||
#include "parser/ddl/drop_table.h" | ||
#include "parser/ddl/rename_property.h" | ||
#include "parser/ddl/rename_table.h" | ||
#include "parser/expression/parsed_literal_expression.h" | ||
#include "parser/transformer.h" | ||
|
||
namespace kuzu { | ||
namespace parser { | ||
|
||
std::unique_ptr<Statement> Transformer::transformDDL(CypherParser::KU_DDLContext& ctx) { | ||
if (ctx.kU_CreateNode()) { | ||
return transformCreateNodeClause(*ctx.kU_CreateNode()); | ||
} else if (root.oC_Statement()->kU_DDL()->kU_CreateRel()) { | ||
return transformCreateRelClause(*root.oC_Statement()->kU_DDL()->kU_CreateRel()); | ||
} else if (root.oC_Statement()->kU_DDL()->kU_DropTable()) { | ||
return transformDropTable(*root.oC_Statement()->kU_DDL()->kU_DropTable()); | ||
} else { | ||
return transformAlterTable(*root.oC_Statement()->kU_DDL()->kU_AlterTable()); | ||
} | ||
} | ||
|
||
std::unique_ptr<Statement> Transformer::transformAlterTable( | ||
CypherParser::KU_AlterTableContext& ctx) { | ||
if (ctx.kU_AlterOptions()->kU_AddProperty()) { | ||
return transformAddProperty(ctx); | ||
} else if (ctx.kU_AlterOptions()->kU_DropProperty()) { | ||
return transformDropProperty(ctx); | ||
} else if (ctx.kU_AlterOptions()->kU_RenameTable()) { | ||
return transformRenameTable(ctx); | ||
} else { | ||
return transformRenameProperty(ctx); | ||
} | ||
} | ||
|
||
std::unique_ptr<Statement> Transformer::transformCreateNodeClause( | ||
CypherParser::KU_CreateNodeContext& ctx) { | ||
auto schemaName = transformSchemaName(*ctx.oC_SchemaName()); | ||
auto propertyDefinitions = transformPropertyDefinitions(*ctx.kU_PropertyDefinitions()); | ||
auto pkColName = | ||
ctx.kU_CreateNodeConstraint() ? transformPrimaryKey(*ctx.kU_CreateNodeConstraint()) : ""; | ||
return std::make_unique<CreateNodeTableClause>( | ||
std::move(schemaName), std::move(propertyDefinitions), pkColName); | ||
} | ||
|
||
std::unique_ptr<Statement> Transformer::transformCreateRelClause( | ||
CypherParser::KU_CreateRelContext& ctx) { | ||
auto schemaName = transformSchemaName(*ctx.oC_SchemaName(0)); | ||
auto propertyDefinitions = ctx.kU_PropertyDefinitions() ? | ||
transformPropertyDefinitions(*ctx.kU_PropertyDefinitions()) : | ||
std::vector<std::pair<std::string, std::string>>(); | ||
auto relMultiplicity = | ||
ctx.oC_SymbolicName() ? transformSymbolicName(*ctx.oC_SymbolicName()) : "MANY_MANY"; | ||
return make_unique<CreateRelClause>(std::move(schemaName), std::move(propertyDefinitions), | ||
relMultiplicity, transformSchemaName(*ctx.oC_SchemaName(1)), | ||
transformSchemaName(*ctx.oC_SchemaName(2))); | ||
} | ||
|
||
std::unique_ptr<Statement> Transformer::transformDropTable(CypherParser::KU_DropTableContext& ctx) { | ||
return std::make_unique<DropTable>(transformSchemaName(*ctx.oC_SchemaName())); | ||
} | ||
|
||
std::unique_ptr<Statement> Transformer::transformRenameTable( | ||
CypherParser::KU_AlterTableContext& ctx) { | ||
return std::make_unique<RenameTable>(transformSchemaName(*ctx.oC_SchemaName()), | ||
transformSchemaName(*ctx.kU_AlterOptions()->kU_RenameTable()->oC_SchemaName())); | ||
} | ||
|
||
std::unique_ptr<Statement> Transformer::transformAddProperty( | ||
CypherParser::KU_AlterTableContext& ctx) { | ||
return std::make_unique<AddProperty>(transformSchemaName(*ctx.oC_SchemaName()), | ||
transformPropertyKeyName(*ctx.kU_AlterOptions()->kU_AddProperty()->oC_PropertyKeyName()), | ||
transformDataType(*ctx.kU_AlterOptions()->kU_AddProperty()->kU_DataType()), | ||
ctx.kU_AlterOptions()->kU_AddProperty()->oC_Expression() ? | ||
transformExpression(*ctx.kU_AlterOptions()->kU_AddProperty()->oC_Expression()) : | ||
std::make_unique<ParsedLiteralExpression>( | ||
std::make_unique<common::Value>(common::Value::createNullValue()), "NULL")); | ||
} | ||
|
||
std::unique_ptr<Statement> Transformer::transformDropProperty( | ||
CypherParser::KU_AlterTableContext& ctx) { | ||
return std::make_unique<DropProperty>(transformSchemaName(*ctx.oC_SchemaName()), | ||
transformPropertyKeyName(*ctx.kU_AlterOptions()->kU_DropProperty()->oC_PropertyKeyName())); | ||
} | ||
|
||
std::unique_ptr<Statement> Transformer::transformRenameProperty( | ||
CypherParser::KU_AlterTableContext& ctx) { | ||
return std::make_unique<RenameProperty>(transformSchemaName(*ctx.oC_SchemaName()), | ||
transformPropertyKeyName( | ||
*ctx.kU_AlterOptions()->kU_RenameProperty()->oC_PropertyKeyName()[0]), | ||
transformPropertyKeyName( | ||
*ctx.kU_AlterOptions()->kU_RenameProperty()->oC_PropertyKeyName()[1])); | ||
} | ||
|
||
std::vector<std::pair<std::string, std::string>> Transformer::transformPropertyDefinitions( | ||
CypherParser::KU_PropertyDefinitionsContext& ctx) { | ||
std::vector<std::pair<std::string, std::string>> propertyNameDataTypes; | ||
for (auto property : ctx.kU_PropertyDefinition()) { | ||
propertyNameDataTypes.emplace_back( | ||
transformPropertyKeyName(*property->oC_PropertyKeyName()), | ||
transformDataType(*property->kU_DataType())); | ||
} | ||
return propertyNameDataTypes; | ||
} | ||
|
||
std::string Transformer::transformDataType(CypherParser::KU_DataTypeContext& ctx) { | ||
return ctx.getText(); | ||
} | ||
|
||
std::string Transformer::transformPrimaryKey(CypherParser::KU_CreateNodeConstraintContext& ctx) { | ||
return transformPropertyKeyName(*ctx.oC_PropertyKeyName()); | ||
} | ||
|
||
} // namespace parser | ||
} // namespace kuzu |
Oops, something went wrong.