Skip to content

Commit

Permalink
Fix protocol violation error happening due to Const node under append…
Browse files Browse the repository at this point in the history
… node (#2720)

Previously, certain driver was running into an protocol violation error when Const node in target list appears under
Append node. This was happening because resolve_numeric_typmod_from_exp was not implemented to handle Const
node properly for decimal data types. This commit fixes that issue by properly handling decimal data type for Const
node under Append node.

Task: BABEL-5086
Signed-off-by: Dipesh Dhameliya <[email protected]>
  • Loading branch information
Deepesh125 authored and tanscorpio7 committed Jul 10, 2024
1 parent dc7712a commit 6b6c6b8
Show file tree
Hide file tree
Showing 3 changed files with 584 additions and 9 deletions.
33 changes: 25 additions & 8 deletions contrib/babelfishpg_tds/src/backend/tds/tdsresponse.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@
#include "catalog/pg_proc.h"
#include "catalog/pg_type.h"
#include "miscadmin.h"
#include "nodes/makefuncs.h"
#include "nodes/pathnodes.h"
#include "parser/parse_coerce.h"
#include "parser/parse_type.h"
#include "parser/parsetree.h"
#include "utils/fmgroids.h"
#include "utils/lsyscache.h"
Expand Down Expand Up @@ -125,6 +127,8 @@ static bool markErrorFlag = false;
static TdsColumnMetaData *colMetaData = NULL;
static List *relMetaDataInfoList = NULL;

static Oid decimal_oid = InvalidOid;

static void FillTabNameWithNumParts(StringInfo buf, uint8 numParts, TdsRelationMetaDataInfo relMetaDataInfo);
static void FillTabNameWithoutNumParts(StringInfo buf, uint8 numParts, TdsRelationMetaDataInfo relMetaDataInfo);
static void SetTdsEstateErrorData(void);
Expand Down Expand Up @@ -508,6 +512,24 @@ resolve_numeric_typmod_outer_var(Plan *plan, AttrNumber attno)
return resolve_numeric_typmod_from_exp(outerplan, (Node *)tle->expr);
}

/*
* is_numeric_datatype - returns bool if given datatype is numeric or decimal.
*/
static bool
is_numeric_datatype(Oid typid)
{
if (typid == NUMERICOID)
{
return true;
}
if (!OidIsValid(decimal_oid))
{
TypeName *typename = makeTypeNameFromNameList(list_make2(makeString("sys"), makeString("decimal")));
decimal_oid = LookupTypeNameOid(NULL, typename, false);
}
return decimal_oid == typid;
}

/* look for a typmod to return from a numeric expression */
static int32
resolve_numeric_typmod_from_exp(Plan *plan, Node *expr)
Expand All @@ -521,15 +543,10 @@ resolve_numeric_typmod_from_exp(Plan *plan, Node *expr)
Const *con = (Const *) expr;
Numeric num;

/*
* TODO: We used a workaround here, that we will assume typmod
* is 0 if the value we have is not numeric. See walkaround in
* T_FuncExpr part of this function. JIRA: BABEL-1007
*/
if (con->consttype != NUMERICOID || con->constisnull)
if (!is_numeric_datatype(con->consttype) || con->constisnull)
{
return 0;
/* Typmod doesn 't really matter since it' s a const NULL. */
/* typmod is undefined */
return -1;
}
else
{
Expand Down
Loading

0 comments on commit 6b6c6b8

Please sign in to comment.