Skip to content

Commit

Permalink
Support IDENTITY() function in SELECT-INTO (babelfish-for-postgresql#166
Browse files Browse the repository at this point in the history
)

Engine changes for Identity support
Added hooks for identity
Added fields in into clause to pass information

Task : BABEL-539
Signed-off-by: Deepakshi Mittal <[email protected]>
  • Loading branch information
deepakshi-mittal authored and priyansx committed Nov 22, 2023
1 parent 4984129 commit e192a00
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 2 deletions.
9 changes: 9 additions & 0 deletions src/backend/commands/createas.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,19 @@
#include "nodes/makefuncs.h"
#include "nodes/nodeFuncs.h"
#include "parser/parse_clause.h"
#include "parser/parser.h"
#include "rewrite/rewriteHandler.h"
#include "storage/smgr.h"
#include "tcop/tcopprot.h"
#include "tcop/utility.h"
#include "utils/builtins.h"
#include "utils/lsyscache.h"
#include "utils/rel.h"
#include "utils/rls.h"
#include "utils/snapmgr.h"

bbfSelectIntoAddIdentity_hook_type bbfSelectIntoAddIdentity_hook = NULL;

typedef struct
{
DestReceiver pub; /* publicly-known function pointers */
Expand Down Expand Up @@ -110,6 +114,11 @@ create_ctas_internal(List *attrList, IntoClause *into)
create->if_not_exists = false;
create->accessMethod = into->accessMethod;

if (sql_dialect == SQL_DIALECT_TSQL)
{
if(into->identityName && bbfSelectIntoAddIdentity_hook)
(*bbfSelectIntoAddIdentity_hook)(into, create->tableElts);
}
/*
* Create the relation. (This will error out if there's an existing view,
* so we don't need more code to complain if "replace" is false.)
Expand Down
11 changes: 9 additions & 2 deletions src/backend/tcop/utility.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
/* Hook for plugins to get control in ProcessUtility() */
ProcessUtility_hook_type ProcessUtility_hook = NULL;
bbfCustomProcessUtility_hook_type bbfCustomProcessUtility_hook = NULL;
bbfSelectIntoUtility_hook_type bbfSelectIntoUtility_hook = NULL;

/* local function declarations */
static int ClassifyUtilityCommandAsReadOnly(Node *parsetree);
Expand Down Expand Up @@ -1681,8 +1682,14 @@ ProcessUtilitySlow(ParseState *pstate,
break;

case T_CreateTableAsStmt:
address = ExecCreateTableAs(pstate, (CreateTableAsStmt *) parsetree,
params, queryEnv, qc);
{
if(sql_dialect == SQL_DIALECT_TSQL && bbfSelectIntoUtility_hook)
(*bbfSelectIntoUtility_hook)(pstate, pstmt, queryString, NULL, params, qc);
else{
address = ExecCreateTableAs(pstate, (CreateTableAsStmt *) parsetree,
params, queryEnv, qc);
}
}
break;

case T_RefreshMatViewStmt:
Expand Down
2 changes: 2 additions & 0 deletions src/include/nodes/primnodes.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ typedef struct IntoClause
char *tableSpaceName; /* table space to use, or NULL */
Node *viewQuery; /* materialized view's SELECT query */
bool skipData; /* true for WITH NO DATA */
char *identityName; /* resname for Identity Column*/
char *identityType; /* pg type for Identity Column*/
} IntoClause;


Expand Down
6 changes: 6 additions & 0 deletions src/include/tcop/utility.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,5 +111,11 @@ extern bool CommandIsReadOnly(PlannedStmt *pstmt);
typedef bool (*bbfCustomProcessUtility_hook_type)(struct ParseState *pstate, PlannedStmt *pstmt, const char *queryString, ProcessUtilityContext context,
ParamListInfo params, QueryCompletion *qc);
extern PGDLLIMPORT bbfCustomProcessUtility_hook_type bbfCustomProcessUtility_hook;
typedef void (*bbfSelectIntoUtility_hook_type)(struct ParseState *pstate, PlannedStmt *pstmt, const char *queryString, QueryEnvironment *queryEnv,
ParamListInfo params, QueryCompletion *qc);
extern PGDLLIMPORT bbfSelectIntoUtility_hook_type bbfSelectIntoUtility_hook;

typedef void (*bbfSelectIntoAddIdentity_hook_type)(IntoClause *into, List *tableElts);
extern PGDLLIMPORT bbfSelectIntoAddIdentity_hook_type bbfSelectIntoAddIdentity_hook;

#endif /* UTILITY_H */

0 comments on commit e192a00

Please sign in to comment.