Skip to content

Commit

Permalink
Merge branch 'BABEL_3_X_DEV' into vector_support
Browse files Browse the repository at this point in the history
  • Loading branch information
KushaalShroff committed Jan 29, 2024
2 parents 498e93e + 1ea412a commit 56a9a05
Show file tree
Hide file tree
Showing 186 changed files with 11,358 additions and 742 deletions.
5 changes: 5 additions & 0 deletions contrib/babelfishpg_common/src/typecode.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ type_info_t type_infos[TOTAL_TYPECODE_COUNT] =
{0, 1, "rowversion", "timestamp", 8, 32, 3},
{0, 1, "timestamp", "timestamp", 8, 33, 3},
{0, 1, "vector", "vector", 9, 34, 3}
/*
* Geospatial types cannot be stored in SQL variant so setting sqlvariant header size to 1
*/
{0, 1, "geometry", "geometry", 5, 34, 1},
{0, 1, "geography", "geography", 5, 35, 1}
};

/* Hash tables to help backward searching (from OID to Persist ID) */
Expand Down
2 changes: 1 addition & 1 deletion contrib/babelfishpg_common/src/typecode.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
#define FIXEDDECIMAL_MULTIPLIER 10000LL
#endif

#define TOTAL_TYPECODE_COUNT 34
#define TOTAL_TYPECODE_COUNT 36

struct Node;

Expand Down
2 changes: 1 addition & 1 deletion contrib/babelfishpg_tds/error_mapping.txt
Original file line number Diff line number Diff line change
Expand Up @@ -185,5 +185,5 @@ XX000 ERRCODE_INTERNAL_ERROR "The table-valued parameter \"%s\" must be declared
22023 ERRCODE_INVALID_PARAMETER_VALUE "The datepart %s is not supported by date function %s for data type %s." SQL_ERROR_9810 16
22008 ERRCODE_DATETIME_VALUE_OUT_OF_RANGE "Adding a value to a \'%s\' column caused an overflow." SQL_ERROR_517 16
42P01 ERRCODE_UNDEFINED_TABLE "FOR JSON AUTO requires at least one table for generating JSON objects. Use FOR JSON PATH or add a FROM clause with a table name." SQL_ERROR_13600 16
42P01 ERRCODE_FEATURE_NOT_SUPPORTED "Values for json auto is not currently supported." SQL_ERROR_13600 16
42P01 ERRCODE_FEATURE_NOT_SUPPORTED "sub-select and values for json auto are not currently supported." SQL_ERROR_13600 16

8 changes: 7 additions & 1 deletion contrib/babelfishpg_tds/src/backend/tds/tdsresponse.c
Original file line number Diff line number Diff line change
Expand Up @@ -2773,7 +2773,13 @@ TdsPrintTup(TupleTableSlot *slot, DestReceiver *self)
* NBCROW (0xD2). Count the number of nullable columns and build the
* null bitmap just in case while we are at it.
*/
nullMapSize = (natts + 7) / 8;

if (sendRowStat)
/* Extra bit for the ROWSTAT column */
nullMapSize = (natts + 1 + 7) >> 3;
else
nullMapSize = (natts + 7) >> 3;

nullMap = palloc0(nullMapSize);
MemSet(nullMap, 0, nullMapSize * sizeof(int8_t));
for (attno = 0; attno < natts; attno++)
Expand Down
163 changes: 47 additions & 116 deletions contrib/babelfishpg_tds/src/backend/tds/tdsrpc.c
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,8 @@ static void SPPrepExec(TDSRequestSP req);
static void SPCustomType(TDSRequestSP req);
static void SPUnprepare(TDSRequestSP req);
static void TDSLogStatementCursorHandler(TDSRequestSP req, char *stmt, int option);
static void LogStatementNoError(const char *header, const int handle, const char *msg, const uint16 nparams);

static InlineCodeBlockArgs *DeclareVariables(TDSRequestSP req, FunctionCallInfo *fcinfo, unsigned long options);
List *tvp_lookup_list = NIL;
bool lockForFaultInjection = false;
Expand Down Expand Up @@ -580,35 +582,7 @@ SPExecuteSQL(TDSRequestSP req)
/* command type - execute (0xe0) */
TdsSendDone(TDS_TOKEN_DONEPROC, TDS_DONE_FINAL, 0xe0, 0);

/*
* Log immediately if dictated by log_statement
*/
if (pltsql_plugin_handler_ptr->stmt_needs_logging || TDS_DEBUG_ENABLED(TDS_DEBUG2))
{

ErrorContextCallback *plerrcontext = error_context_stack;

error_context_stack = plerrcontext->previous;

/* In certain cases TVP can throw error for errdetail_params. */
PG_TRY();
{
ereport(LOG,
(errmsg("sp_executesql statement: %s", s.data),
errhidestmt(true),
errdetail_params(req->nTotalParams)));
}
PG_CATCH();
{
ereport(LOG,
(errmsg("sp_executesql statement: %s", s.data),
errhidestmt(true)));
}
PG_END_TRY();

pltsql_plugin_handler_ptr->stmt_needs_logging = false;
error_context_stack = plerrcontext;
}
LogStatementNoError("sp_executesql:", -1, s.data, req->nTotalParams);

/*
* Print TDS log duration, if log_duration is set
Expand Down Expand Up @@ -796,34 +770,7 @@ SPExecute(TDSRequestSP req)
/* Command type - execute (0xe0). */
TdsSendDone(TDS_TOKEN_DONEPROC, TDS_DONE_FINAL, 0xe0, 0);

/*
* Log immediately if dictated by log_statement
*/
if (pltsql_plugin_handler_ptr->stmt_needs_logging || TDS_DEBUG_ENABLED(TDS_DEBUG2))
{
ErrorContextCallback *plerrcontext = error_context_stack;

error_context_stack = plerrcontext->previous;

/* In certain cases TVP can throw error for errdetail_params. */
PG_TRY();
{
ereport(LOG,
(errmsg("sp_execute handle: %d", req->handle),
errhidestmt(true),
errdetail_params(req->nTotalParams)));
}
PG_CATCH();
{
ereport(LOG,
(errmsg("sp_execute handle: %d", req->handle),
errhidestmt(true)));
}
PG_END_TRY();

pltsql_plugin_handler_ptr->stmt_needs_logging = false;
error_context_stack = plerrcontext;
}
LogStatementNoError("sp_execute", req->handle, "", req->nTotalParams);

/*
* Print TDS log duration, if log_duration is set
Expand Down Expand Up @@ -938,36 +885,7 @@ SPPrepExec(TDSRequestSP req)
/* command type - execute (0xe0) */
TdsSendDone(TDS_TOKEN_DONEPROC, TDS_DONE_FINAL, 0xe0, 0);

/*
* Log immediately if dictated by log_statement
*/
if (pltsql_plugin_handler_ptr->stmt_needs_logging || TDS_DEBUG_ENABLED(TDS_DEBUG2))
{
ErrorContextCallback *plerrcontext = error_context_stack;

error_context_stack = plerrcontext->previous;

/* In certain cases TVP can throw error for errdetail_params. */
PG_TRY();
{
ereport(LOG,
(errmsg("sp_prepexec handle: %d, "
"statement: %s", req->handle, s.data),
errhidestmt(true),
errdetail_params(req->nTotalParams)));
}
PG_CATCH();
{
ereport(LOG,
(errmsg("sp_prepexec handle: %d, "
"statement: %s", req->handle, s.data),
errhidestmt(true)));
}
PG_END_TRY();

pltsql_plugin_handler_ptr->stmt_needs_logging = false;
error_context_stack = plerrcontext;
}
LogStatementNoError("sp_prepexec", req->handle, s.data, req->nTotalParams);

/*
* Print TDS log duration, if log_duration is set
Expand Down Expand Up @@ -1190,34 +1108,7 @@ SPCustomType(TDSRequestSP req)
/* command type - execute (0xe0) */
TdsSendDone(TDS_TOKEN_DONEPROC, TDS_DONE_FINAL, 0xe0, 0);

/*
* Log immediately if dictated by log_statement
*/
if (pltsql_plugin_handler_ptr->stmt_needs_logging || TDS_DEBUG_ENABLED(TDS_DEBUG2))
{
ErrorContextCallback *plerrcontext = error_context_stack;

error_context_stack = plerrcontext->previous;

/* In certain cases TVP can throw error for errdetail_params. */
PG_TRY();
{
ereport(LOG,
(errmsg("stored procedure: %s", req->name.data),
errhidestmt(true),
errdetail_params(req->nTotalParams)));
}
PG_CATCH();
{
ereport(LOG,
(errmsg("stored procedure: %s", req->name.data),
errhidestmt(true)));
}
PG_END_TRY();

pltsql_plugin_handler_ptr->stmt_needs_logging = false;
error_context_stack = plerrcontext;
}
LogStatementNoError("stored procedure:", -1, req->name.data, req->nTotalParams);

/*
* Print TDS log duration, if log_duration is set
Expand Down Expand Up @@ -4025,11 +3916,11 @@ TDSLogStatementCursorHandler(TDSRequestSP req, char *stmt, int option)
if (pltsql_plugin_handler_ptr->stmt_needs_logging || TDS_DEBUG_ENABLED(TDS_DEBUG2))
{
ErrorContextCallback *plerrcontext = error_context_stack;

error_context_stack = plerrcontext->previous;

switch (option)
{

case PRINT_CURSOR_HANDLE:
ereport(LOG,
(errmsg("sp_cursor handle: %d; statement: %s",
Expand All @@ -4050,6 +3941,7 @@ TDSLogStatementCursorHandler(TDSRequestSP req, char *stmt, int option)
req->cursorHandle, req->cursorPreparedHandle, stmt),
errhidestmt(true),
errdetail_params(req->nTotalParams)));

break;
default:
break;
Expand All @@ -4062,3 +3954,42 @@ TDSLogStatementCursorHandler(TDSRequestSP req, char *stmt, int option)
/* Print TDS log duration, if log_duration is set */
TDSLogDuration(stmt);
}

/*
* Log msg ignoring any error during ereport.
* This should only be called when it is safe to call FlushErrorState
* ie: ignoring any previous error that happened prior
* */
static void LogStatementNoError(const char *header, const int handle, const char *msg, const uint16 nparams)
{
MemoryContext curr = CurrentMemoryContext;

ErrorContextCallback *plerrcontext = error_context_stack;
error_context_stack = plerrcontext->previous;

if (pltsql_plugin_handler_ptr->stmt_needs_logging || TDS_DEBUG_ENABLED(TDS_DEBUG2))
{
PG_TRY();
{
ereport(LOG,
(errmsg("%s handle: %d "
"statement: %s",
header, handle, msg),
errhidestmt(true),
errdetail_params(nparams)));
}
PG_CATCH();
{
MemoryContextSwitchTo(curr);
FlushErrorState();

ereport(LOG,
(errmsg("%s statement: %s", header, msg),
errhidestmt(true)));
}
PG_END_TRY();
}

pltsql_plugin_handler_ptr->stmt_needs_logging = false;
error_context_stack = plerrcontext;
}
15 changes: 15 additions & 0 deletions contrib/babelfishpg_tsql/antlr/TSqlLexer.g4
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,9 @@ LAG: L A G;
LANGUAGE: L A N G U A G E;
LAST: L A S T;
LAST_VALUE: L A S T UNDERLINE V A L U E;
LAT: 'Lat';
LAT_DOUBLE_QUOTE: ["] LAT ["] {pltsql_quoted_identifier == true}?;
LAT_SQBRACKET: '[' LAT ']';
LEAD: L E A D;
LEDGER: L E D G E R;
LEFT: L E F T;
Expand All @@ -531,6 +534,9 @@ LOCK_ESCALATION: L O C K UNDERLINE E S C A L A
LOG: L O G;
LOG10: L O G '10';
LOGIN: L O G I N;
LONG: 'Long';
LONG_DOUBLE_QUOTE: ["] LONG ["] {pltsql_quoted_identifier == true}?;
LONG_SQBRACKET: '[' LONG ']';
LOOP: L O O P;
LOW: L O W;
MANUAL: M A N U A L;
Expand Down Expand Up @@ -933,6 +939,8 @@ START: S T A R T;
STARTED: S T A R T E D;
STARTUP_STATE: S T A R T U P UNDERLINE S T A T E;
START_DATE: S T A R T UNDERLINE D A T E;
STASBINARY: 'STAsBinary';
STASTEXT: 'STAsText';
STATE: S T A T E;
STATEMENT: S T A T E M E N T;
STATIC: S T A T I C;
Expand All @@ -944,6 +952,7 @@ STATUS: S T A T U S;
STATUSONLY: S T A T U S O N L Y;
STDEV: S T D E V;
STDEVP: S T D E V P;
STDISTANCE: 'STDistance';
STOP: S T O P;
STOPAT: S T O P A T;
STOPATMARK: S T O P A T M A R K;
Expand All @@ -954,6 +963,12 @@ STOP_ON_ERROR: S T O P UNDERLINE O N UNDERL
STRING_AGG: S T R I N G UNDERLINE A G G;
STRING_DELIMITER: S T R I N G UNDERLINE D E L I M I T E R;
STUFF: S T U F F;
STX: 'STX';
STX_DOUBLE_QUOTE: ["] STX ["] {pltsql_quoted_identifier == true}?;
STX_SQBRACKET: '[' STX ']';
STY: 'STY';
STY_DOUBLE_QUOTE: ["] STY ["] {pltsql_quoted_identifier == true}?;
STY_SQBRACKET: '[' STY ']';
SUBJECT: S U B J E C T;
SUBSCRIBE: S U B S C R I B E;
SUBSCRIPTION: S U B S C R I P T I O N;
Expand Down
Loading

0 comments on commit 56a9a05

Please sign in to comment.