Skip to content
Open
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
78 changes: 78 additions & 0 deletions c/driver/postgresql/postgresql_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1825,6 +1825,84 @@ TEST_F(PostgresStatementTest, SqlQueryInt2vector) {
ASSERT_EQ(reader.array->release, nullptr);
}

TEST_F(PostgresStatementTest, PostgresCompositeTypeTest) {
ASSERT_THAT(AdbcStatementNew(&connection, &statement, &error), IsOkStatus(&error));
{
adbc_validation::StreamReader reader;

// Types are cached on the AdbcDatabase so this test has to totally recreate
// its AdbcDatabase (see the call to ResetTest in the body here).

// Cleanup. We have to drop the table before we drop the type.
ASSERT_THAT(
AdbcStatementSetSqlQuery(
&statement, "DROP TABLE IF EXISTS adbc_postgresql_composite_type_test_table;",
&error),
IsOkStatus(&error));
ASSERT_THAT(AdbcStatementExecuteQuery(&statement, &reader.stream.value,
&reader.rows_affected, &error),
IsOkStatus(&error));
ASSERT_THAT(AdbcStatementSetSqlQuery(
&statement, "DROP TYPE IF EXISTS my_composite_type;", &error),
IsOkStatus(&error));
ASSERT_THAT(AdbcStatementExecuteQuery(&statement, &reader.stream.value,
&reader.rows_affected, &error),
IsOkStatus(&error));

// Create type and table, fill with data
ASSERT_THAT(
AdbcStatementSetSqlQuery(
&statement, "CREATE TYPE my_composite_type AS (x integer, y text);", &error),
IsOkStatus(&error));
ASSERT_THAT(AdbcStatementExecuteQuery(&statement, &reader.stream.value,
&reader.rows_affected, &error),
IsOkStatus(&error));

ASSERT_THAT(
AdbcStatementSetSqlQuery(&statement,
"CREATE TABLE adbc_postgresql_composite_type_test_table "
"(a my_composite_type);",
&error),
IsOkStatus(&error));
ASSERT_THAT(AdbcStatementExecuteQuery(&statement, &reader.stream.value,
&reader.rows_affected, &error),
IsOkStatus(&error));

ASSERT_THAT(AdbcStatementSetSqlQuery(
&statement,
"INSERT INTO adbc_postgresql_composite_type_test_table "
"(a) VALUES (ROW(1, 'a')), (ROW(2,' b')), (ROW(3,' c'));",
&error),
IsOkStatus(&error));
ASSERT_THAT(AdbcStatementExecuteQuery(&statement, &reader.stream.value,
&reader.rows_affected, &error),
IsOkStatus(&error));

// AdbcDatabase currently caches types so we need to recreate it
// https://github.com/apache/arrow-adbc/pull/3196#pullrequestreview-3103472826
ResetTest();

ASSERT_THAT(AdbcStatementNew(&connection, &statement, &error), IsOkStatus(&error));
ASSERT_THAT(AdbcStatementSetSqlQuery(
&statement,
"SELECT * FROM adbc_postgresql_composite_type_test_table;", &error),
IsOkStatus(&error));
ASSERT_THAT(AdbcStatementExecuteQuery(&statement, &reader.stream.value,
&reader.rows_affected, &error),
IsOkStatus(&error));

ASSERT_NO_FATAL_FAILURE(reader.GetSchema());
ASSERT_EQ(reader.schema->n_children, 1);
ASSERT_STREQ(reader.schema->children[0]->name, "a");
ASSERT_STREQ(reader.schema->children[0]->format, "+s");
ASSERT_EQ(reader.schema->children[0]->n_children, 2);
ASSERT_STREQ(reader.schema->children[0]->children[0]->name, "x");
ASSERT_STREQ(reader.schema->children[0]->children[0]->format, "i");
ASSERT_STREQ(reader.schema->children[0]->children[1]->name, "y");
ASSERT_STREQ(reader.schema->children[0]->children[1]->format, "u");
}
}

TEST_F(PostgresStatementTest, UnknownOid) {
// Regression test for https://github.com/apache/arrow-adbc/issues/2448
ASSERT_THAT(AdbcStatementNew(&connection, &statement, &error), IsOkStatus(&error));
Expand Down
1 change: 1 addition & 0 deletions c/validation/adbc_validation.h
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,7 @@ class StatementTest {

void SetUpTest();
void TearDownTest();
void ResetTest();

// Test methods
void TestNewInit();
Expand Down
5 changes: 5 additions & 0 deletions c/validation/adbc_validation_statement.cc
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ void StatementTest::TearDownTest() {
}
}

void StatementTest::ResetTest() {
TearDownTest();
SetUpTest();
}

void StatementTest::TestNewInit() {
ASSERT_THAT(AdbcStatementNew(&connection, &statement, &error), IsOkStatus(&error));
ASSERT_THAT(AdbcStatementRelease(&statement, &error), IsOkStatus(&error));
Expand Down
Loading