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

Deprecate table metadata printing functions #2207

Merged
merged 2 commits into from
Oct 13, 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
30 changes: 0 additions & 30 deletions src/c_api/connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,36 +87,6 @@ kuzu_query_result* kuzu_connection_execute(
return c_query_result;
}

char* kuzu_connection_get_node_table_names(kuzu_connection* connection) {
auto node_table_names = static_cast<Connection*>(connection->_connection)->getNodeTableNames();
char* node_table_names_c = (char*)malloc(node_table_names.size() + 1);
strcpy(node_table_names_c, node_table_names.c_str());
return node_table_names_c;
}

char* kuzu_connection_get_rel_table_names(kuzu_connection* connection) {
auto rel_table_names = static_cast<Connection*>(connection->_connection)->getRelTableNames();
char* rel_table_names_c = (char*)malloc(rel_table_names.size() + 1);
strcpy(rel_table_names_c, rel_table_names.c_str());
return rel_table_names_c;
}

char* kuzu_connection_get_node_property_names(kuzu_connection* connection, const char* table_name) {
auto node_property_names =
static_cast<Connection*>(connection->_connection)->getNodePropertyNames(table_name);
char* node_property_names_c = (char*)malloc(node_property_names.size() + 1);
strcpy(node_property_names_c, node_property_names.c_str());
return node_property_names_c;
}

char* kuzu_connection_get_rel_property_names(kuzu_connection* connection, const char* table_name) {
auto rel_property_names =
static_cast<Connection*>(connection->_connection)->getRelPropertyNames(table_name);
char* rel_property_names_c = (char*)malloc(rel_property_names.size() + 1);
strcpy(rel_property_names_c, rel_property_names.c_str());
return rel_property_names_c;
}

void kuzu_connection_interrupt(kuzu_connection* connection) {
static_cast<Connection*>(connection->_connection)->interrupt();
}
Expand Down
24 changes: 0 additions & 24 deletions src/include/c_api/kuzu.h
Original file line number Diff line number Diff line change
Expand Up @@ -324,30 +324,6 @@ KUZU_C_API kuzu_prepared_statement* kuzu_connection_prepare(
*/
KUZU_C_API kuzu_query_result* kuzu_connection_execute(
kuzu_connection* connection, kuzu_prepared_statement* prepared_statement);
/**
* @brief Returns all node table names of the database.
* @param connection The connection instance to return all node table names.
*/
KUZU_C_API char* kuzu_connection_get_node_table_names(kuzu_connection* connection);
/**
* @brief Returns all rel table names of the database.
* @param connection The connection instance to return all rel table names.
*/
KUZU_C_API char* kuzu_connection_get_rel_table_names(kuzu_connection* connection);
/**
* @brief Returns all property names of the given node table.
* @param connection The connection instance to return all property names.
* @param table_name The table name to return all property names.
*/
KUZU_C_API char* kuzu_connection_get_node_property_names(
kuzu_connection* connection, const char* table_name);
/**
* @brief Returns all property names of the given rel table.
* @param connection The connection instance to return all property names.
* @param table_name The table name to return all property names.
*/
KUZU_C_API char* kuzu_connection_get_rel_property_names(
kuzu_connection* connection, const char* table_name);
/**
* @brief Interrupts the current query execution in the connection.
* @param connection The connection instance to interrupt.
Expand Down
19 changes: 0 additions & 19 deletions src/include/main/connection.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,25 +94,6 @@ class Connection {
*/
KUZU_API std::unique_ptr<QueryResult> executeWithParams(PreparedStatement* preparedStatement,
std::unordered_map<std::string, std::shared_ptr<common::Value>>& inputParams);
/**
* @return all node table names in string format.
*/
KUZU_API std::string getNodeTableNames();
/**
* @return all rel table names in string format.
*/
KUZU_API std::string getRelTableNames();
/**
* @param nodeTableName The name of the node table.
* @return all property names of the given table.
*/
KUZU_API std::string getNodePropertyNames(const std::string& tableName);
/**
* @param relTableName The name of the rel table.
* @return all property names of the given table.
*/
KUZU_API std::string getRelPropertyNames(const std::string& relTableName);

/**
* @brief interrupts all queries currently executing within this connection.
*/
Expand Down
73 changes: 0 additions & 73 deletions src/main/connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,79 +147,6 @@ std::unique_ptr<PreparedStatement> Connection::prepareNoLock(
return preparedStatement;
}

std::string Connection::getNodeTableNames() {
lock_t lck{mtx};
std::string result = "Node tables: \n";
std::vector<std::string> nodeTableNames;
for (auto& nodeTableSchema : database->catalog->getReadOnlyVersion()->getNodeTableSchemas()) {
nodeTableNames.push_back(nodeTableSchema->tableName);
}
std::sort(nodeTableNames.begin(), nodeTableNames.end());
for (auto& nodeTableName : nodeTableNames) {
result += "\t" + nodeTableName + "\n";
}
return result;
}

std::string Connection::getRelTableNames() {
lock_t lck{mtx};
std::string result = "Rel tables: \n";
std::vector<std::string> relTableNames;
for (auto relTableSchema : database->catalog->getReadOnlyVersion()->getRelTableSchemas()) {
relTableNames.push_back(relTableSchema->tableName);
}
std::sort(relTableNames.begin(), relTableNames.end());
for (auto& relTableName : relTableNames) {
result += "\t" + relTableName + "\n";
}
return result;
}

std::string Connection::getNodePropertyNames(const std::string& tableName) {
lock_t lck{mtx};
auto catalogContent = database->catalog->getReadOnlyVersion();
if (!catalogContent->containsNodeTable(tableName)) {
throw RuntimeException("Cannot find node table " + tableName);
}
std::string result = tableName + " properties: \n";
auto tableID = catalogContent->getTableID(tableName);
auto nodeTableSchema =
reinterpret_cast<catalog::NodeTableSchema*>(catalogContent->getTableSchema(tableID));
auto primaryKeyPropertyID = nodeTableSchema->getPrimaryKey()->getPropertyID();
for (auto property : nodeTableSchema->getProperties()) {
result += "\t" + property->getName() + " " +
LogicalTypeUtils::dataTypeToString(*property->getDataType());
result += property->getPropertyID() == primaryKeyPropertyID ? "(PRIMARY KEY)\n" : "\n";
}
return result;
}

std::string Connection::getRelPropertyNames(const std::string& relTableName) {
lock_t lck{mtx};
auto catalogContent = database->catalog->getReadOnlyVersion();
if (!catalogContent->containsRelTable(relTableName)) {
throw RuntimeException("Cannot find rel table " + relTableName);
}
auto relTableID = catalogContent->getTableID(relTableName);
auto relTableSchema =
reinterpret_cast<RelTableSchema*>(catalogContent->getTableSchema(relTableID));
auto srcTableID = relTableSchema->getBoundTableID(FWD);
auto srcTableSchema = catalogContent->getTableSchema(srcTableID);
auto dstTableID = relTableSchema->getBoundTableID(BWD);
auto dstTableSchema = catalogContent->getTableSchema(dstTableID);
std::string result = relTableName + " src node: " + srcTableSchema->tableName + "\n";
result += relTableName + " dst node: " + dstTableSchema->tableName + "\n";
result += relTableName + " properties: \n";
for (auto property : relTableSchema->getProperties()) {
if (catalog::TableSchema::isReservedPropertyName(property->getName())) {
continue;
}
result += "\t" + property->getName() + " " +
LogicalTypeUtils::dataTypeToString(*property->getDataType()) + "\n";
}
return result;
}

void Connection::interrupt() {
clientContext->interrupt();
}
Expand Down
58 changes: 0 additions & 58 deletions test/c_api/connection_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,64 +95,6 @@ TEST_F(CApiConnectionTest, Execute) {
kuzu_query_result_destroy(result);
}

TEST_F(CApiConnectionTest, GetNodeTableNames) {
auto connection = getConnection();
auto result = kuzu_connection_get_node_table_names(connection);
ASSERT_NE(result, nullptr);
auto resultString = std::string(result);
ASSERT_EQ(resultString, "Node tables: \n"
"\tmovies\n"
"\torganisation\n"
"\tperson\n");
free(result);
}

TEST_F(CApiConnectionTest, GetRelTableNames) {
auto connection = getConnection();
auto result = kuzu_connection_get_rel_table_names(connection);
ASSERT_NE(result, nullptr);
auto resultString = std::string(result);
ASSERT_EQ(resultString, "Rel tables: \n"
"\tknows\n"
"\tmarries\n"
"\tmeets\n"
"\tstudyAt\n"
"\tworkAt\n");
free(result);
}

TEST_F(CApiConnectionTest, GetNodePropertyNames) {
auto connection = getConnection();
auto result = kuzu_connection_get_node_property_names(connection, "movies");
ASSERT_NE(result, nullptr);
auto resultString = std::string(result);
ASSERT_EQ(resultString, "movies properties: \n"
"\tname STRING(PRIMARY KEY)\n"
"\tlength INT32\n"
"\tnote STRING\n"
"\tdescription STRUCT(rating:DOUBLE, stars:INT8, views:INT64, "
"release:TIMESTAMP, film:DATE, u8:UINT8, u16:UINT16, u32:UINT32, "
"u64:UINT64)\n"
"\tcontent BLOB\n"
"\taudience MAP(STRING: INT64)\n"
"\tgrade UNION(credit:BOOL, grade1:DOUBLE, grade2:INT64)\n");
free(result);
}

TEST_F(CApiConnectionTest, GetRelPropertyNames) {
auto connection = getConnection();
auto result = kuzu_connection_get_rel_property_names(connection, "meets");
ASSERT_NE(result, nullptr);
auto resultString = std::string(result);
ASSERT_EQ(resultString, "meets src node: person\n"
"meets dst node: person\n"
"meets properties: \n"
"\tlocation FLOAT[2]\n"
"\ttimes INT32\n"
"\tdata BLOB\n");
free(result);
}

TEST_F(CApiConnectionTest, QueryTimeout) {
auto connection = getConnection();
kuzu_connection_set_query_timeout(connection, 1);
Expand Down
32 changes: 0 additions & 32 deletions tools/java_api/src/jni/kuzu_java.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -315,38 +315,6 @@ JNIEXPORT jobject JNICALL Java_com_kuzudb_KuzuNative_kuzu_1connection_1execute(
return ret;
}

JNIEXPORT jstring JNICALL Java_com_kuzudb_KuzuNative_kuzu_1connection_1get_1node_1table_1names(
JNIEnv* env, jclass, jobject thisConn) {
Connection* conn = getConnection(env, thisConn);
jstring result = env->NewStringUTF(conn->getNodeTableNames().c_str());
return result;
}

JNIEXPORT jstring JNICALL Java_com_kuzudb_KuzuNative_kuzu_1connection_1get_1rel_1table_1names(
JNIEnv* env, jclass, jobject thisConn) {
Connection* conn = getConnection(env, thisConn);
jstring result = env->NewStringUTF(conn->getRelTableNames().c_str());
return result;
}

JNIEXPORT jstring JNICALL Java_com_kuzudb_KuzuNative_kuzu_1connection_1get_1node_1property_1names(
JNIEnv* env, jclass, jobject thisConn, jstring table_name) {
Connection* conn = getConnection(env, thisConn);
const char* name = env->GetStringUTFChars(table_name, JNI_FALSE);
jstring result = env->NewStringUTF(conn->getNodePropertyNames(name).c_str());
env->ReleaseStringUTFChars(table_name, name);
return result;
}

JNIEXPORT jstring JNICALL Java_com_kuzudb_KuzuNative_kuzu_1connection_1get_1rel_1property_1names(
JNIEnv* env, jclass, jobject thisConn, jstring table_name) {
Connection* conn = getConnection(env, thisConn);
const char* name = env->GetStringUTFChars(table_name, JNI_FALSE);
jstring result = env->NewStringUTF(conn->getRelPropertyNames(name).c_str());
env->ReleaseStringUTFChars(table_name, name);
return result;
}

JNIEXPORT void JNICALL Java_com_kuzudb_KuzuNative_kuzu_1connection_1interrupt(
JNIEnv* env, jclass, jobject thisConn) {
Connection* conn = getConnection(env, thisConn);
Expand Down
42 changes: 0 additions & 42 deletions tools/java_api/src/main/java/com/kuzudb/KuzuConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -139,48 +139,6 @@ public KuzuQueryResult execute(KuzuPreparedStatement ps, Map<String, KuzuValue>
return KuzuNative.kuzu_connection_execute(this, ps, m);
}

/**
* Get names of all node tables in the database.
* @return Names of all node tables in the database.
* @throws KuzuObjectRefDestroyedException If the connection has been destroyed.
*/
public String getNodeTableNames() throws KuzuObjectRefDestroyedException {
checkNotDestroyed();
return KuzuNative.kuzu_connection_get_node_table_names(this);
}

/**
* Get names of all relationship tables in the database.
* @return Names of all relationship tables in the database.
* @throws KuzuObjectRefDestroyedException If the connection has been destroyed.
*/
public String getRelTableNames() throws KuzuObjectRefDestroyedException {
checkNotDestroyed();
return KuzuNative.kuzu_connection_get_rel_table_names(this);
}

/**
* Get names of all node properties in the given table.
* @param tableName: The table name.
* @return Names of all node properties in the given table.
* @throws KuzuObjectRefDestroyedException If the connection has been destroyed.
*/
public String getNodePropertyNames(String tableName) throws KuzuObjectRefDestroyedException {
checkNotDestroyed();
return KuzuNative.kuzu_connection_get_node_property_names(this, tableName);
}

/**
* Get names of all relationship properties in the given table.
* @param tableName: The table name.
* @return Names of all relationship properties in the given table.
* @throws KuzuObjectRefDestroyedException If the connection has been destroyed.
*/
public String getRelPropertyNames(String tableName) throws KuzuObjectRefDestroyedException {
checkNotDestroyed();
return KuzuNative.kuzu_connection_get_rel_property_names(this, tableName);
}

/**
* Interrupts all queries currently executed within this connection.
* @throws KuzuObjectRefDestroyedException If the connection has been destroyed.
Expand Down
10 changes: 0 additions & 10 deletions tools/java_api/src/main/java/com/kuzudb/KuzuNative.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,16 +88,6 @@ protected static native KuzuPreparedStatement kuzu_connection_prepare(
protected static native KuzuQueryResult kuzu_connection_execute(
KuzuConnection connection, KuzuPreparedStatement prepared_statement, Map<String, KuzuValue> param);

protected static native String kuzu_connection_get_node_table_names(KuzuConnection connection);

protected static native String kuzu_connection_get_rel_table_names(KuzuConnection connection);

protected static native String kuzu_connection_get_node_property_names(
KuzuConnection connection, String table_name);

protected static native String kuzu_connection_get_rel_property_names(
KuzuConnection connection, String table_name);

protected static native void kuzu_connection_interrupt(KuzuConnection connection);

protected static native void kuzu_connection_set_query_timeout(
Expand Down
Loading