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

Hide catalog content #2502

Merged
merged 1 commit into from
Nov 29, 2023
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
6 changes: 2 additions & 4 deletions src/binder/bind/bind_comment_on.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "binder/binder.h"
#include "binder/bound_comment_on.h"
#include "main/client_context.h"
#include "parser/comment_on.h"

namespace kuzu {
Expand All @@ -9,11 +10,8 @@ std::unique_ptr<BoundStatement> Binder::bindCommentOn(const parser::Statement& s
auto& commentOnStatement = reinterpret_cast<const parser::CommentOn&>(statement);
auto tableName = commentOnStatement.getTable();
auto comment = commentOnStatement.getComment();

validateTableExist(tableName);
auto catalogContent = catalog.getReadOnlyVersion();
auto tableID = catalogContent->getTableID(tableName);

auto tableID = catalog.getTableID(clientContext->getTx(), tableName);
andyfengHKU marked this conversation as resolved.
Show resolved Hide resolved
return std::make_unique<BoundCommentOn>(tableID, tableName, comment);
}

Expand Down
18 changes: 9 additions & 9 deletions src/binder/bind/bind_copy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "common/exception/message.h"
#include "common/string_format.h"
#include "function/table_functions/bind_input.h"
#include "main/client_context.h"
#include "parser/copy.h"

using namespace kuzu::binder;
Expand Down Expand Up @@ -62,12 +63,11 @@ static void validateCopyNpyNotForRelTables(TableSchema* schema) {

std::unique_ptr<BoundStatement> Binder::bindCopyFromClause(const Statement& statement) {
auto& copyStatement = reinterpret_cast<const CopyFrom&>(statement);
auto catalogContent = catalog.getReadOnlyVersion();
auto tableName = copyStatement.getTableName();
validateTableExist(tableName);
// Bind to table schema.
auto tableID = catalogContent->getTableID(tableName);
auto tableSchema = catalogContent->getTableSchema(tableID);
auto tableID = catalog.getTableID(clientContext->getTx(), tableName);
auto tableSchema = catalog.getTableSchema(clientContext->getTx(), tableID);
switch (tableSchema->tableType) {
case TableType::REL_GROUP:
case TableType::RDF: {
Expand Down Expand Up @@ -120,7 +120,7 @@ std::unique_ptr<BoundStatement> Binder::bindCopyNodeFrom(const Statement& statem
tableSchema, copyStatement.getColumnNames(), expectedColumnNames, expectedColumnTypes);
auto bindInput = std::make_unique<function::ScanTableFuncBindInput>(
memoryManager, *config, std::move(expectedColumnNames), std::move(expectedColumnTypes));
auto bindData = func->bindFunc(clientContext, bindInput.get(), catalog.getReadOnlyVersion());
auto bindData = func->bindFunc(clientContext, bindInput.get(), (Catalog*)&catalog);
expression_vector columns;
for (auto i = 0u; i < bindData->columnTypes.size(); i++) {
columns.push_back(createVariable(bindData->columnNames[i], *bindData->columnTypes[i]));
Expand All @@ -147,7 +147,7 @@ std::unique_ptr<BoundStatement> Binder::bindCopyRelFrom(const parser::Statement&
tableSchema, copyStatement.getColumnNames(), expectedColumnNames, expectedColumnTypes);
auto bindInput = std::make_unique<function::ScanTableFuncBindInput>(memoryManager,
std::move(*config), std::move(expectedColumnNames), std::move(expectedColumnTypes));
auto bindData = func->bindFunc(clientContext, bindInput.get(), catalog.getReadOnlyVersion());
auto bindData = func->bindFunc(clientContext, bindInput.get(), (Catalog*)&catalog);
expression_vector columns;
for (auto i = 0u; i < bindData->columnTypes.size(); i++) {
columns.push_back(createVariable(bindData->columnNames[i], *bindData->columnTypes[i]));
Expand All @@ -158,9 +158,9 @@ std::unique_ptr<BoundStatement> Binder::bindCopyRelFrom(const parser::Statement&
std::make_unique<BoundFileScanInfo>(func, std::move(bindData), columns, offset);
auto relTableSchema = reinterpret_cast<RelTableSchema*>(tableSchema);
auto srcTableSchema =
catalog.getReadOnlyVersion()->getTableSchema(relTableSchema->getSrcTableID());
catalog.getTableSchema(clientContext->getTx(), relTableSchema->getSrcTableID());
auto dstTableSchema =
catalog.getReadOnlyVersion()->getTableSchema(relTableSchema->getDstTableID());
catalog.getTableSchema(clientContext->getTx(), relTableSchema->getDstTableID());
auto srcKey = columns[0];
auto dstKey = columns[1];
auto srcNodeID = createVariable(std::string(InternalKeyword::SRC_OFFSET), LogicalTypeID::INT64);
Expand Down Expand Up @@ -228,9 +228,9 @@ void Binder::bindExpectedRelColumns(TableSchema* tableSchema,
KU_ASSERT(columnNames.empty() && columnTypes.empty());
auto relTableSchema = reinterpret_cast<RelTableSchema*>(tableSchema);
auto srcTable = reinterpret_cast<NodeTableSchema*>(
catalog.getReadOnlyVersion()->getTableSchema(relTableSchema->getSrcTableID()));
catalog.getTableSchema(clientContext->getTx(), relTableSchema->getSrcTableID()));
auto dstTable = reinterpret_cast<NodeTableSchema*>(
catalog.getReadOnlyVersion()->getTableSchema(relTableSchema->getDstTableID()));
catalog.getTableSchema(clientContext->getTx(), relTableSchema->getDstTableID()));
columnNames.push_back("from");
columnNames.push_back("to");
auto srcPKColumnType = srcTable->getPrimaryKey()->getDataType()->copy();
Expand Down
3 changes: 2 additions & 1 deletion src/binder/bind/bind_create_macro.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "common/exception/binder.h"
#include "common/string_format.h"
#include "common/string_utils.h"
#include "main/client_context.h"
#include "parser/create_macro.h"

using namespace kuzu::common;
Expand All @@ -15,7 +16,7 @@ std::unique_ptr<BoundStatement> Binder::bindCreateMacro(const Statement& stateme
auto& createMacro = reinterpret_cast<const CreateMacro&>(statement);
auto macroName = createMacro.getMacroName();
StringUtils::toUpper(macroName);
if (catalog.getReadOnlyVersion()->containMacro(macroName)) {
if (catalog.containsMacro(clientContext->getTx(), macroName)) {
throw BinderException{stringFormat("Macro {} already exists.", macroName)};
}
parser::default_macro_args defaultArgs;
Expand Down
32 changes: 14 additions & 18 deletions src/binder/bind/bind_ddl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "common/exception/binder.h"
#include "common/string_format.h"
#include "common/string_utils.h"
#include "main/client_context.h"
#include "parser/ddl/alter.h"
#include "parser/ddl/create_table.h"
#include "parser/ddl/drop.h"
Expand Down Expand Up @@ -155,7 +156,7 @@ std::unique_ptr<BoundCreateTableInfo> Binder::bindCreateRelTableGroupInfo(
std::unique_ptr<BoundStatement> Binder::bindCreateTable(const parser::Statement& statement) {
auto& createTable = reinterpret_cast<const CreateTable&>(statement);
auto tableName = createTable.getTableName();
if (catalog.getReadOnlyVersion()->containsTable(tableName)) {
if (catalog.containsTable(clientContext->getTx(), tableName)) {
throw BinderException(tableName + " already exists in catalog.");
}
auto boundCreateInfo = bindCreateTableInfo(createTable.getInfo());
Expand All @@ -166,12 +167,11 @@ std::unique_ptr<BoundStatement> Binder::bindDropTable(const Statement& statement
auto& dropTable = reinterpret_cast<const Drop&>(statement);
auto tableName = dropTable.getTableName();
validateTableExist(tableName);
auto catalogContent = catalog.getReadOnlyVersion();
auto tableID = catalogContent->getTableID(tableName);
auto tableSchema = catalogContent->getTableSchema(tableID);
auto tableID = catalog.getTableID(clientContext->getTx(), tableName);
auto tableSchema = catalog.getTableSchema(clientContext->getTx(), tableID);
switch (tableSchema->tableType) {
case TableType::NODE: {
for (auto& schema : catalogContent->getRelTableSchemas()) {
for (auto& schema : catalog.getRelTableSchemas(clientContext->getTx())) {
auto relTableSchema = reinterpret_cast<RelTableSchema*>(schema);
if (relTableSchema->isSrcOrDstTable(tableID)) {
throw BinderException(
Expand All @@ -181,7 +181,7 @@ std::unique_ptr<BoundStatement> Binder::bindDropTable(const Statement& statement
}
} break;
case TableType::REL: {
for (auto& schema : catalogContent->getRelTableGroupSchemas()) {
for (auto& schema : catalog.getRelTableGroupSchemas(clientContext->getTx())) {
auto relTableGroupSchema = reinterpret_cast<RelTableGroupSchema*>(schema);
for (auto& relTableID : relTableGroupSchema->getRelTableIDs()) {
if (relTableID == tableSchema->getTableID()) {
Expand Down Expand Up @@ -226,12 +226,11 @@ std::unique_ptr<BoundStatement> Binder::bindRenameTable(const Statement& stateme
auto extraInfo = reinterpret_cast<ExtraRenameTableInfo*>(info->extraInfo.get());
auto tableName = info->tableName;
auto newName = extraInfo->newName;
auto catalogContent = catalog.getReadOnlyVersion();
validateTableExist(tableName);
if (catalogContent->containsTable(newName)) {
if (catalog.containsTable(clientContext->getTx(), newName)) {
throw BinderException("Table: " + newName + " already exists.");
}
auto tableID = catalogContent->getTableID(tableName);
auto tableID = catalog.getTableID(clientContext->getTx(), tableName);
auto boundExtraInfo = std::make_unique<BoundExtraRenameTableInfo>(newName);
auto boundInfo = std::make_unique<BoundAlterInfo>(
AlterType::RENAME_TABLE, tableName, tableID, std::move(boundExtraInfo));
Expand Down Expand Up @@ -273,9 +272,8 @@ std::unique_ptr<BoundStatement> Binder::bindAddProperty(const Statement& stateme
auto dataType = bindDataType(extraInfo->dataType);
auto propertyName = extraInfo->propertyName;
validateTableExist(tableName);
auto catalogContent = catalog.getReadOnlyVersion();
auto tableID = catalogContent->getTableID(tableName);
auto tableSchema = catalogContent->getTableSchema(tableID);
auto tableID = catalog.getTableID(clientContext->getTx(), tableName);
auto tableSchema = catalog.getTableSchema(clientContext->getTx(), tableID);
validatePropertyDDLOnTable(tableSchema, "add");
validatePropertyNotExist(tableSchema, propertyName);
if (dataType->getLogicalTypeID() == LogicalTypeID::SERIAL) {
Expand All @@ -297,9 +295,8 @@ std::unique_ptr<BoundStatement> Binder::bindDropProperty(const Statement& statem
auto tableName = info->tableName;
auto propertyName = extraInfo->propertyName;
validateTableExist(tableName);
auto catalogContent = catalog.getReadOnlyVersion();
auto tableID = catalogContent->getTableID(tableName);
auto tableSchema = catalogContent->getTableSchema(tableID);
auto tableID = catalog.getTableID(clientContext->getTx(), tableName);
auto tableSchema = catalog.getTableSchema(clientContext->getTx(), tableID);
validatePropertyDDLOnTable(tableSchema, "drop");
validatePropertyExist(tableSchema, propertyName);
auto propertyID = tableSchema->getPropertyID(propertyName);
Expand All @@ -321,9 +318,8 @@ std::unique_ptr<BoundStatement> Binder::bindRenameProperty(const Statement& stat
auto propertyName = extraInfo->propertyName;
auto newName = extraInfo->newName;
validateTableExist(tableName);
auto catalogContent = catalog.getReadOnlyVersion();
auto tableID = catalogContent->getTableID(tableName);
auto tableSchema = catalogContent->getTableSchema(tableID);
auto tableID = catalog.getTableID(clientContext->getTx(), tableName);
auto tableSchema = catalog.getTableSchema(clientContext->getTx(), tableID);
validatePropertyDDLOnTable(tableSchema, "rename");
validatePropertyExist(tableSchema, propertyName);
auto propertyID = tableSchema->getPropertyID(propertyName);
Expand Down
49 changes: 24 additions & 25 deletions src/binder/bind/bind_graph_pattern.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -262,18 +262,19 @@ std::shared_ptr<RelExpression> Binder::createNonRecursiveQueryRel(const std::str
}
auto extraInfo = std::make_unique<StructTypeInfo>(fieldNames, fieldTypes);
RelType::setExtraTypeInfo(queryRel->getDataTypeReference(), std::move(extraInfo));
auto readVersion = catalog.getReadOnlyVersion();
if (readVersion->getTableSchema(tableIDs[0])->getTableType() == TableType::RDF) {
auto tableSchema = catalog.getTableSchema(clientContext->getTx(), tableIDs[0]);
if (tableSchema->getTableType() == TableType::RDF) {
auto predicateID =
expressionBinder.bindNodeOrRelPropertyExpression(*queryRel, std::string(rdf::PID));
std::vector<common::table_id_t> resourceTableIDs;
std::vector<TableSchema*> resourceTableSchemas;
for (auto& tableID : tableIDs) {
auto rdfGraphSchema =
reinterpret_cast<RdfGraphSchema*>(readVersion->getTableSchema(tableID));
auto rdfGraphSchema = reinterpret_cast<RdfGraphSchema*>(
catalog.getTableSchema(clientContext->getTx(), tableID));
auto resourceTableID = rdfGraphSchema->getResourceTableID();
resourceTableIDs.push_back(resourceTableID);
resourceTableSchemas.push_back(readVersion->getTableSchema(resourceTableID));
resourceTableSchemas.push_back(
catalog.getTableSchema(clientContext->getTx(), resourceTableID));
}
auto predicateIRI = createPropertyExpression(std::string(rdf::IRI),
queryRel->getUniqueName(), queryRel->getVariableName(), resourceTableSchemas);
Expand Down Expand Up @@ -305,7 +306,7 @@ std::shared_ptr<RelExpression> Binder::createRecursiveQueryRel(const parser::Rel
std::unordered_set<table_id_t> nodeTableIDs;
for (auto relTableID : relTableIDs) {
auto relTableSchema = reinterpret_cast<RelTableSchema*>(
catalog.getReadOnlyVersion()->getTableSchema(relTableID));
catalog.getTableSchema(clientContext->getTx(), relTableID));
nodeTableIDs.insert(relTableSchema->getSrcTableID());
nodeTableIDs.insert(relTableSchema->getDstTableID());
}
Expand Down Expand Up @@ -463,7 +464,7 @@ std::pair<uint64_t, uint64_t> Binder::bindVariableLengthRelBound(
void Binder::bindQueryRelProperties(RelExpression& rel) {
std::vector<TableSchema*> tableSchemas;
for (auto tableID : rel.getTableIDs()) {
tableSchemas.push_back(catalog.getReadOnlyVersion()->getTableSchema(tableID));
tableSchemas.push_back(catalog.getTableSchema(clientContext->getTx(), tableID));
}
auto propertyNames = getPropertyNames(tableSchemas);
for (auto& propertyName : propertyNames) {
Expand Down Expand Up @@ -539,7 +540,7 @@ std::shared_ptr<NodeExpression> Binder::createQueryNode(
}

void Binder::bindQueryNodeProperties(NodeExpression& node) {
auto tableSchemas = catalog.getReadOnlyVersion()->getTableSchemas(node.getTableIDs());
auto tableSchemas = catalog.getTableSchemas(clientContext->getTx(), node.getTableIDs());
auto propertyNames = getPropertyNames(tableSchemas);
for (auto& propertyName : propertyNames) {
auto property = createPropertyExpression(
Expand All @@ -550,26 +551,26 @@ void Binder::bindQueryNodeProperties(NodeExpression& node) {

std::vector<table_id_t> Binder::bindTableIDs(
const std::vector<std::string>& tableNames, bool nodePattern) {
auto catalogContent = catalog.getReadOnlyVersion();
auto tx = clientContext->getTx();
std::unordered_set<common::table_id_t> tableIDSet;
if (tableNames.empty()) { // Rewrite empty table names as all tables.
if (catalogContent->containsRdfGraph()) {
if (catalog.containsRdfGraph(tx)) {
// If catalog contains rdf graph then it should NOT have any property graph table.
for (auto tableID : catalogContent->getRdfGraphIDs()) {
for (auto tableID : catalog.getRdfGraphIDs(tx)) {
tableIDSet.insert(tableID);
}
} else if (nodePattern) {
if (!catalogContent->containsNodeTable()) {
if (!catalog.containsNodeTable(tx)) {
throw BinderException("No node table exists in database.");
}
for (auto tableID : catalogContent->getNodeTableIDs()) {
for (auto tableID : catalog.getNodeTableIDs(tx)) {
tableIDSet.insert(tableID);
}
} else { // rel
if (!catalogContent->containsRelTable()) {
if (!catalog.containsRelTable(tx)) {
throw BinderException("No rel table exists in database.");
}
for (auto tableID : catalogContent->getRelTableIDs()) {
for (auto tableID : catalog.getRelTableIDs(tx)) {
tableIDSet.insert(tableID);
}
}
Expand All @@ -584,14 +585,13 @@ std::vector<table_id_t> Binder::bindTableIDs(
}

std::vector<table_id_t> Binder::getNodeTableIDs(const std::vector<table_id_t>& tableIDs) {
auto readVersion = catalog.getReadOnlyVersion();
auto tableType = readVersion->getTableSchema(tableIDs[0])->getTableType();
auto tableType = catalog.getTableSchema(clientContext->getTx(), tableIDs[0])->getTableType();
switch (tableType) {
case TableType::RDF: { // extract node table ID from rdf graph schema.
std::vector<table_id_t> result;
for (auto& tableID : tableIDs) {
auto rdfGraphSchema =
reinterpret_cast<RdfGraphSchema*>(readVersion->getTableSchema(tableID));
auto rdfGraphSchema = reinterpret_cast<RdfGraphSchema*>(
catalog.getTableSchema(clientContext->getTx(), tableID));
result.push_back(rdfGraphSchema->getResourceTableID());
result.push_back(rdfGraphSchema->getLiteralTableID());
}
Expand All @@ -606,14 +606,13 @@ std::vector<table_id_t> Binder::getNodeTableIDs(const std::vector<table_id_t>& t
}

std::vector<table_id_t> Binder::getRelTableIDs(const std::vector<table_id_t>& tableIDs) {
auto readVersion = catalog.getReadOnlyVersion();
auto tableType = readVersion->getTableSchema(tableIDs[0])->getTableType();
auto tableType = catalog.getTableSchema(clientContext->getTx(), tableIDs[0])->getTableType();
switch (tableType) {
case TableType::RDF: { // extract rel table ID from rdf graph schema.
std::vector<table_id_t> result;
for (auto& tableID : tableIDs) {
auto rdfGraphSchema =
reinterpret_cast<RdfGraphSchema*>(readVersion->getTableSchema(tableID));
auto rdfGraphSchema = reinterpret_cast<RdfGraphSchema*>(
catalog.getTableSchema(clientContext->getTx(), tableID));
result.push_back(rdfGraphSchema->getResourceTripleTableID());
result.push_back(rdfGraphSchema->getLiteralTripleTableID());
}
Expand All @@ -622,8 +621,8 @@ std::vector<table_id_t> Binder::getRelTableIDs(const std::vector<table_id_t>& ta
case TableType::REL_GROUP: { // extract rel table ID from rel group schema.
std::vector<table_id_t> result;
for (auto& tableID : tableIDs) {
auto relGroupSchema =
reinterpret_cast<RelTableGroupSchema*>(readVersion->getTableSchema(tableID));
auto relGroupSchema = reinterpret_cast<RelTableGroupSchema*>(
catalog.getTableSchema(clientContext->getTx(), tableID));
for (auto& relTableID : relGroupSchema->getRelTableIDs()) {
result.push_back(relTableID);
}
Expand Down
6 changes: 2 additions & 4 deletions src/binder/bind/bind_reading_clause.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,7 @@ std::unique_ptr<BoundReadingClause> Binder::bindInQueryCall(const ReadingClause&
catalog.getBuiltInFunctions()->matchScalarFunction(funcName, inputTypes));
auto bindInput = std::make_unique<function::TableFuncBindInput>();
bindInput->inputs = std::move(inputValues);
auto bindData =
tableFunction->bindFunc(clientContext, bindInput.get(), catalog.getReadOnlyVersion());
auto bindData = tableFunction->bindFunc(clientContext, bindInput.get(), (Catalog*)&catalog);
expression_vector columns;
for (auto i = 0u; i < bindData->columnTypes.size(); i++) {
columns.push_back(createVariable(bindData->columnNames[i], *bindData->columnTypes[i]));
Expand Down Expand Up @@ -175,8 +174,7 @@ std::unique_ptr<BoundReadingClause> Binder::bindLoadFrom(
getScanFunction(readerConfig->fileType, readerConfig->csvReaderConfig->parallel);
auto bindInput = std::make_unique<function::ScanTableFuncBindInput>(memoryManager,
*readerConfig, std::move(expectedColumnNames), std::move(expectedColumnTypes));
auto bindData =
scanFunction->bindFunc(clientContext, bindInput.get(), catalog.getReadOnlyVersion());
auto bindData = scanFunction->bindFunc(clientContext, bindInput.get(), (Catalog*)&catalog);
expression_vector columns;
for (auto i = 0u; i < bindData->columnTypes.size(); i++) {
columns.push_back(createVariable(bindData->columnNames[i], *bindData->columnTypes[i]));
Expand Down
Loading