-
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 #2341 from kuzudb/typed-literal
Add typed-literal storage
- Loading branch information
Showing
27 changed files
with
503 additions
and
243 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
add_subdirectory(copy) | ||
add_subdirectory(ddl) | ||
|
||
add_library( | ||
kuzu_binder_bind | ||
OBJECT | ||
|
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,7 @@ | ||
add_library(kuzu_binder_bind_copy | ||
OBJECT | ||
bind_copy_rdf_graph.cpp) | ||
|
||
set(ALL_OBJECT_FILES | ||
${ALL_OBJECT_FILES} $<TARGET_OBJECTS:kuzu_binder_bind_copy> | ||
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,78 @@ | ||
#include "binder/binder.h" | ||
#include "binder/copy/bound_copy_from.h" | ||
#include "catalog/rel_table_schema.h" | ||
#include "common/constants.h" | ||
#include "common/keyword/rdf_keyword.h" | ||
#include "common/types/rdf_variant_type.h" | ||
#include "storage/storage_manager.h" | ||
|
||
using namespace kuzu::binder; | ||
using namespace kuzu::catalog; | ||
using namespace kuzu::common; | ||
using namespace kuzu::parser; | ||
|
||
namespace kuzu { | ||
namespace binder { | ||
|
||
std::unique_ptr<BoundStatement> Binder::bindCopyRdfNodeFrom( | ||
std::unique_ptr<ReaderConfig> readerConfig, TableSchema* tableSchema) { | ||
bool containsSerial; | ||
auto stringType = LogicalType{LogicalTypeID::STRING}; | ||
auto nodeID = createVariable(std::string(Property::INTERNAL_ID_NAME), LogicalTypeID::INT64); | ||
expression_vector columns; | ||
auto columnName = std::string(InternalKeyword::ANONYMOUS); | ||
readerConfig->columnNames.push_back(columnName); | ||
if (tableSchema->tableName.ends_with(rdf::RESOURCE_TABLE_SUFFIX)) { | ||
containsSerial = false; | ||
readerConfig->columnTypes.push_back(stringType.copy()); | ||
readerConfig->rdfReaderConfig = | ||
std::make_unique<RdfReaderConfig>(RdfReaderMode::RESOURCE, nullptr /* index */); | ||
columns.push_back(createVariable(columnName, stringType)); | ||
} else { | ||
assert(tableSchema->tableName.ends_with(rdf::LITERAL_TABLE_SUFFIX)); | ||
containsSerial = true; | ||
readerConfig->columnTypes.push_back(RdfVariantType::getType()); | ||
readerConfig->rdfReaderConfig = | ||
std::make_unique<RdfReaderConfig>(RdfReaderMode::LITERAL, nullptr /* index */); | ||
columns.push_back(createVariable(columnName, *RdfVariantType::getType())); | ||
} | ||
auto boundFileScanInfo = std::make_unique<BoundFileScanInfo>( | ||
std::move(readerConfig), columns, std::move(nodeID), TableType::NODE); | ||
auto boundCopyFromInfo = std::make_unique<BoundCopyFromInfo>(tableSchema, | ||
std::move(boundFileScanInfo), containsSerial, std::move(columns), nullptr /* extraInfo */); | ||
return std::make_unique<BoundCopyFrom>(std::move(boundCopyFromInfo)); | ||
} | ||
|
||
std::unique_ptr<BoundStatement> Binder::bindCopyRdfRelFrom( | ||
std::unique_ptr<ReaderConfig> readerConfig, TableSchema* tableSchema) { | ||
auto containsSerial = false; | ||
auto offsetType = std::make_unique<LogicalType>(LogicalTypeID::INT64); | ||
expression_vector columns; | ||
for (auto i = 0u; i < 3; ++i) { | ||
auto columnName = std::string(InternalKeyword::ANONYMOUS) + std::to_string(i); | ||
readerConfig->columnNames.push_back(columnName); | ||
readerConfig->columnTypes.push_back(offsetType->copy()); | ||
columns.push_back(createVariable(columnName, *offsetType)); | ||
} | ||
auto relTableSchema = reinterpret_cast<RelTableSchema*>(tableSchema); | ||
auto resourceTableID = relTableSchema->getSrcTableID(); | ||
auto index = storageManager->getNodesStore().getPKIndex(resourceTableID); | ||
if (tableSchema->tableName.ends_with(rdf::RESOURCE_TRIPLE_TABLE_SUFFIX)) { | ||
readerConfig->rdfReaderConfig = | ||
std::make_unique<RdfReaderConfig>(RdfReaderMode::RESOURCE_TRIPLE, index); | ||
} else { | ||
readerConfig->rdfReaderConfig = | ||
std::make_unique<RdfReaderConfig>(RdfReaderMode::LITERAL_TRIPLE, index); | ||
} | ||
auto relID = createVariable(std::string(Property::INTERNAL_ID_NAME), LogicalTypeID::INT64); | ||
auto boundFileScanInfo = std::make_unique<BoundFileScanInfo>( | ||
std::move(readerConfig), columns, relID, TableType::REL); | ||
auto extraInfo = std::make_unique<ExtraBoundCopyRdfRelInfo>(columns[0], columns[1], columns[2]); | ||
columns.push_back(std::move(relID)); | ||
auto boundCopyFromInfo = std::make_unique<BoundCopyFromInfo>(tableSchema, | ||
std::move(boundFileScanInfo), containsSerial, std::move(columns), std::move(extraInfo)); | ||
return std::make_unique<BoundCopyFrom>(std::move(boundCopyFromInfo)); | ||
} | ||
|
||
} // 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
add_library(kuzu_binder_bind_ddl | ||
OBJECT | ||
bind_create_rdf_graph.cpp) | ||
|
||
set(ALL_OBJECT_FILES | ||
${ALL_OBJECT_FILES} $<TARGET_OBJECTS:kuzu_binder_bind_ddl> | ||
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,85 @@ | ||
#include "binder/binder.h" | ||
#include "binder/ddl/bound_create_table.h" | ||
#include "catalog/rdf_graph_schema.h" | ||
#include "catalog/rel_table_schema.h" | ||
#include "common/keyword/rdf_keyword.h" | ||
#include "common/types/rdf_variant_type.h" | ||
#include "parser/ddl/create_table.h" | ||
|
||
using namespace kuzu::parser; | ||
using namespace kuzu::common; | ||
using namespace kuzu::catalog; | ||
|
||
namespace kuzu { | ||
namespace binder { | ||
|
||
static std::string getRdfResourceTableName(const std::string& rdfName) { | ||
return rdfName + std::string(rdf::RESOURCE_TABLE_SUFFIX); | ||
} | ||
|
||
static std::string getRdfLiteralTableName(const std::string& rdfName) { | ||
return rdfName + std::string(rdf::LITERAL_TABLE_SUFFIX); | ||
} | ||
|
||
static inline std::string getRdfResourceTripleTableName(const std::string& rdfName) { | ||
return rdfName + std::string(rdf::RESOURCE_TRIPLE_TABLE_SUFFIX); | ||
} | ||
|
||
static std::string getRdfLiteralTripleTableName(const std::string& rdfName) { | ||
return rdfName + std::string(rdf::LITERAL_TRIPLE_TABLE_SUFFIX); | ||
} | ||
|
||
std::unique_ptr<BoundCreateTableInfo> Binder::bindCreateRdfGraphInfo(const CreateTableInfo* info) { | ||
auto rdfGraphName = info->tableName; | ||
auto stringType = LogicalType(LogicalTypeID::STRING); | ||
auto serialType = LogicalType(LogicalTypeID::SERIAL); | ||
// Resource table. | ||
auto resourceTableName = getRdfResourceTableName(rdfGraphName); | ||
std::vector<std::unique_ptr<Property>> resourceProperties; | ||
resourceProperties.push_back( | ||
std::make_unique<Property>(std::string(rdf::IRI), stringType.copy())); | ||
auto resourceExtraInfo = std::make_unique<BoundExtraCreateNodeTableInfo>( | ||
0 /* primaryKeyIdx */, std::move(resourceProperties)); | ||
auto resourceCreateInfo = std::make_unique<BoundCreateTableInfo>( | ||
TableType::NODE, resourceTableName, std::move(resourceExtraInfo)); | ||
// Literal table. | ||
auto literalTableName = getRdfLiteralTableName(rdfGraphName); | ||
std::vector<std::unique_ptr<Property>> literalProperties; | ||
literalProperties.push_back( | ||
std::make_unique<Property>(std::string(rdf::ID), serialType.copy())); | ||
literalProperties.push_back( | ||
std::make_unique<Property>(std::string(rdf::IRI), RdfVariantType::getType())); | ||
auto literalExtraInfo = std::make_unique<BoundExtraCreateNodeTableInfo>( | ||
0 /* primaryKeyIdx */, std::move(literalProperties)); | ||
auto literalCreateInfo = std::make_unique<BoundCreateTableInfo>( | ||
TableType::NODE, literalTableName, std::move(literalExtraInfo)); | ||
// Resource triple table. | ||
auto resourceTripleTableName = getRdfResourceTripleTableName(rdfGraphName); | ||
std::vector<std::unique_ptr<Property>> resourceTripleProperties; | ||
resourceTripleProperties.push_back(std::make_unique<Property>( | ||
std::string(rdf::PID), std::make_unique<LogicalType>(LogicalTypeID::INT64))); | ||
auto boundResourceTripleExtraInfo = | ||
std::make_unique<BoundExtraCreateRelTableInfo>(RelMultiplicity::MANY_MANY, INVALID_TABLE_ID, | ||
INVALID_TABLE_ID, std::move(resourceTripleProperties)); | ||
auto boundResourceTripleCreateInfo = std::make_unique<BoundCreateTableInfo>( | ||
TableType::REL, resourceTripleTableName, std::move(boundResourceTripleExtraInfo)); | ||
// Literal triple table. | ||
auto literalTripleTableName = getRdfLiteralTripleTableName(rdfGraphName); | ||
std::vector<std::unique_ptr<Property>> literalTripleProperties; | ||
literalTripleProperties.push_back(std::make_unique<Property>( | ||
std::string(rdf::PID), std::make_unique<LogicalType>(LogicalTypeID::INT64))); | ||
auto boundLiteralTripleExtraInfo = | ||
std::make_unique<BoundExtraCreateRelTableInfo>(RelMultiplicity::MANY_MANY, INVALID_TABLE_ID, | ||
INVALID_TABLE_ID, std::move(literalTripleProperties)); | ||
auto boundLiteralTripleCreateInfo = std::make_unique<BoundCreateTableInfo>( | ||
TableType::REL, literalTripleTableName, std::move(boundLiteralTripleExtraInfo)); | ||
// Rdf table. | ||
auto boundExtraInfo = std::make_unique<BoundExtraCreateRdfGraphInfo>( | ||
std::move(resourceCreateInfo), std::move(literalCreateInfo), | ||
std::move(boundResourceTripleCreateInfo), std::move(boundLiteralTripleCreateInfo)); | ||
return std::make_unique<BoundCreateTableInfo>( | ||
TableType::RDF, rdfGraphName, std::move(boundExtraInfo)); | ||
} | ||
|
||
} // 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
Oops, something went wrong.