From ef3ee20fa09b0672768693cba72f8737fe7d7177 Mon Sep 17 00:00:00 2001 From: Kushaal Shroff <51415286+KushaalShroff@users.noreply.github.com> Date: Wed, 25 May 2022 13:35:00 +0530 Subject: [PATCH] BABEL: BCP Related Bug-fixes (#15) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In this commit we fix 3 issues: Bcp does not handle ‘db..table’ syntax. The issue was pertaining to sp_describe_first_resultset where SPI API was not able to resolve the DB..TABLE name. To fix this we are making use of ANTLR Parser to resolve the full name, in addition it also provides syntax checks. Bcp-in does not handle identity column. The issue was with views created from select statement does not inherit the constraints from the base columns which was the reason why sp_describe_first_resultset sent wrong values for identity columns. To Fix this we lookup the catalog at the time of view creation in TSQL Dialect to initialise the constraints for it. We had restricted sp_describe_first_result_set to only work with SELECT statements and for non-select statements we threw an error. With this commit we return 0 rows for any valid non-select query. Task: BABEL-3193, BABEL-3194, BABEL-3208 Author: Kushaal Shroff (kushaal@amazon.com) Signed-off-by: Kuntal Ghosh (kuntalgh@amazon.com) (cherry picked from commit d7610a64f34fdcd38e49c441fcd5de0ea5701cd6) --- src/postgres/src/backend/commands/view.c | 5 +++++ src/postgres/src/include/commands/view.h | 2 ++ 2 files changed, 7 insertions(+) diff --git a/src/postgres/src/backend/commands/view.c b/src/postgres/src/backend/commands/view.c index b32cf5d23e26..fb4b98b5b0bf 100644 --- a/src/postgres/src/backend/commands/view.c +++ b/src/postgres/src/backend/commands/view.c @@ -41,6 +41,8 @@ static void checkViewTupleDesc(TupleDesc newdesc, TupleDesc olddesc); +inherit_view_constraints_from_table_hook_type inherit_view_constraints_from_table_hook = NULL; + /*--------------------------------------------------------------------- * DefineVirtualRelation * @@ -76,6 +78,9 @@ DefineVirtualRelation(RangeVar *relation, List *tlist, bool replace, exprTypmod((Node *) tle->expr), exprCollation((Node *) tle->expr)); + if (inherit_view_constraints_from_table_hook) + (*inherit_view_constraints_from_table_hook) (def, tle->resorigtbl, tle->resorigcol); + /* * It's possible that the column is of a collatable type but the * collation could not be resolved, so double-check. diff --git a/src/postgres/src/include/commands/view.h b/src/postgres/src/include/commands/view.h index 05fe44aadc47..b354e8f064e9 100644 --- a/src/postgres/src/include/commands/view.h +++ b/src/postgres/src/include/commands/view.h @@ -22,4 +22,6 @@ extern ObjectAddress DefineView(ViewStmt *stmt, const char *queryString, extern void StoreViewQuery(Oid viewOid, Query *viewParse, bool replace); +typedef void (*inherit_view_constraints_from_table_hook_type) (ColumnDef *col, Oid tableOid, AttrNumber colId); +extern PGDLLIMPORT inherit_view_constraints_from_table_hook_type inherit_view_constraints_from_table_hook; #endif /* VIEW_H */