diff --git a/src/iobeamdb.c b/src/iobeamdb.c index 096b1815e..9b10a7684 100644 --- a/src/iobeamdb.c +++ b/src/iobeamdb.c @@ -744,7 +744,8 @@ prev_ProcessUtility(Node *parsetree, } -/* Hook-intercept for ProcessUtility. Used to make COPY use a temp copy table. */ +/* Hook-intercept for ProcessUtility. Used to make COPY use a temp copy table and */ +/* blocking renaming of hypertables. */ void iobeamdb_ProcessUtility(Node *parsetree, const char *queryString, ProcessUtilityContext context, @@ -752,7 +753,13 @@ void iobeamdb_ProcessUtility(Node *parsetree, DestReceiver *dest, char *completionTag) { - if (IobeamLoaded() && IsA(parsetree, CopyStmt)) + + if (!IobeamLoaded()){ + prev_ProcessUtility(parsetree, queryString, context, params, dest, completionTag); + return; + } + + if (IsA(parsetree, CopyStmt)) { CopyStmt *copystmt = (CopyStmt *) parsetree; Oid relId = RangeVarGetRelid(copystmt->relation, NoLock, true); @@ -764,9 +771,24 @@ void iobeamdb_ProcessUtility(Node *parsetree, } } prev_ProcessUtility((Node *)copystmt, queryString, context, params, dest, completionTag); + return; } - else + + /* We don't support renaming hypertables yet so we need to block it */ + if (IsA(parsetree, RenameStmt)) { - prev_ProcessUtility(parsetree, queryString, context, params, dest, completionTag); + RenameStmt *renamestmt = (RenameStmt *) parsetree; + Oid relId = RangeVarGetRelid(renamestmt->relation, NoLock, true); + if (OidIsValid(relId)) { + hypertable_info* hinfo = get_hypertable_info(relId); + if (hinfo != NULL && renamestmt->renameType == OBJECT_TABLE) + ereport(ERROR, + (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), + errmsg("Renaming hypertables is not yet supported"))); + } + prev_ProcessUtility((Node *)renamestmt, queryString, context, params, dest, completionTag); + return; } + + prev_ProcessUtility(parsetree, queryString, context, params, dest, completionTag); } diff --git a/test/expected/drop_hypertable.out b/test/expected/drop_rename_hypertable.out similarity index 96% rename from test/expected/drop_hypertable.out rename to test/expected/drop_rename_hypertable.out index 4b5d951f9..68423f286 100644 --- a/test/expected/drop_hypertable.out +++ b/test/expected/drop_rename_hypertable.out @@ -125,6 +125,19 @@ Child tables: _iobeamdb_internal._hyper_2_2_0_3_data, device_id | text | | extended | | Child tables: _iobeamdb_internal._hyper_2_0_replica +-- Test that renaming hypertable is blocked +\set ON_ERROR_STOP 0 +ALTER TABLE "testNs" RENAME TO "newname"; +ERROR: Renaming hypertables is not yet supported +\set ON_ERROR_STOP 1 +-- Test that renaming ordinary table works +CREATE TABLE renametable (foo int); +ALTER TABLE "renametable" RENAME TO "newname"; +SELECT * FROM "newname"; + foo +----- +(0 rows) + SELECT * FROM _iobeamdb_catalog.hypertable; id | schema_name | table_name | associated_schema_name | associated_table_prefix | root_schema_name | root_table_name | replication_factor | placement | time_column_name | time_column_type | created_on | chunk_size_bytes ----+-------------+--------------------+------------------------+-------------------------+--------------------+-----------------+--------------------+-----------+------------------+------------------+------------+------------------ @@ -159,7 +172,8 @@ SELECT * FROM _iobeamdb_catalog.hypertable; Schema | Name | Type | Owner --------+--------------------+-------+---------- public | chunk_closing_test | table | postgres -(1 row) + public | newname | table | postgres +(2 rows) \dt "_iobeamdb_catalog".* List of relations diff --git a/test/sql/drop_hypertable.sql b/test/sql/drop_hypertable.sql deleted file mode 100644 index 42f9cbaa8..000000000 --- a/test/sql/drop_hypertable.sql +++ /dev/null @@ -1,16 +0,0 @@ -\set ON_ERROR_STOP 1 -\o /dev/null -\ir include/insert_single.sql -\o -\set ECHO ALL - -\c single -\d+ "_iobeamdb_internal".* - -SELECT * FROM _iobeamdb_catalog.hypertable; -DROP TABLE "testNs"; - -SELECT * FROM _iobeamdb_catalog.hypertable; -\dt "public".* -\dt "_iobeamdb_catalog".* -\dt+ "_iobeamdb_internal".*