Skip to content

Commit

Permalink
Fix protocol violation error happening due to Const node in append node
Browse files Browse the repository at this point in the history
  • Loading branch information
Dipesh Dhameliya committed Jul 9, 2024
1 parent dc7712a commit e1a0ac2
Show file tree
Hide file tree
Showing 3 changed files with 536 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 e1a0ac2

Please sign in to comment.