Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Numeric/ decimal datatype typmod handling for computed column #3233

Open
wants to merge 26 commits into
base: BABEL_4_X_DEV
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 31 additions & 5 deletions contrib/babelfishpg_tds/src/backend/tds/tdsresponse.c
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,9 @@ resolve_numeric_typmod_outer_var(Plan *plan, AttrNumber attno)
return resolve_numeric_typmod_from_append_or_mergeappend(plan, attno);
else
outerplan = outerPlan(plan);
// outerplan = outerPlan(plan);
// tle = get_tle_by_resno(outerplan->targetlist, attno);
// return resolve_numeric_typmod_from_exp(outerplan, (Node *)tle->expr);

/* if outerplan is SubqueryScan then use actual subplan */
if (IsA(outerplan, SubqueryScan))
Expand Down Expand Up @@ -696,13 +699,30 @@ resolve_numeric_typmod_from_exp(Plan *plan, Node *expr)
case T_Var:
{
Var *var = (Var *) expr;
Plan *outerplan = NULL;
TargetEntry *tle;
if (plan)
outerplan = outerPlan(plan);

/* If this var referes to tuple returned by its outer plan then find the original tle from it */
if (plan != NULL && var->varno == OUTER_VAR)
if (plan && outerplan && (IsA(outerplan, Gather) || IsA(plan, Gather)))
{
Assert(plan);
return (resolve_numeric_typmod_outer_var(plan, var->varattno));
Assert(outerplan);
tle = get_tle_by_resno(outerplan->targetlist, var->varattno);
return resolve_numeric_typmod_from_exp(outerplan, (Node *)tle->expr);
}

/* If this var referes to tuple returned by its outer plan then find the original tle from it */
// if (plan && var->varno == OUTER_VAR)
// {
// Assert(plan);
// return (resolve_numeric_typmod_outer_var(plan, var->varattno));
// } // if gather node then
// outerplan = outerPlan(plan);
// Assert(outerplan);
// tle = get_tle_by_resno(outerplan->targetlist, var->varattno);
// return resolve_numeric_typmod_from_exp(outerplan, (Node *)tle->expr);
return var->vartypmod;
}
case T_OpExpr:
Expand Down Expand Up @@ -1031,6 +1051,12 @@ resolve_numeric_typmod_from_exp(Plan *plan, Node *expr)
int32 typmod;
uint8_t precision,
scale;
// Plan *outerplan = NULL;
// TargetEntry *tle;
// if (plan && IsA(plan, Gather))
// {
// Assert(plan);
// outerplan = outerPlan(plan);

Assert(aggref->args != NIL);

Expand Down Expand Up @@ -1921,9 +1947,9 @@ PrepareRowDescription(TupleDesc typeinfo, PlannedStmt *plannedstmt, List *target
{
Oid serverCollationOid;
TdsIoFunctionInfo finfo;
Form_pg_attribute att = TupleDescAttr(typeinfo, attno);
Form_pg_attribute att = TupleDescAttr(typeinfo, attno); // able to extract from var
Oid atttypid = att->atttypid;
int32 atttypmod = att->atttypmod;
int32 atttypmod = att->atttypmod; // -1
TdsColumnMetaData *col = &colMetaData[attno];
uint32_t tdsVersion = GetClientTDSVersion();
TargetEntry *tle = NULL;
Expand All @@ -1936,7 +1962,7 @@ PrepareRowDescription(TupleDesc typeinfo, PlannedStmt *plannedstmt, List *target
/*
* Get the IO function info from our type cache
*/
if (atttypmod == TSQLMaxTypmod)
if (atttypmod == TSQLMaxTypmod)
atttypmod = -1;
finfo = TdsLookupTypeFunctionsByOid(atttypid, &atttypmod);
/* atttypid = getBaseTypeAndTypmod(atttypid, &atttypmod); */
Expand Down
2 changes: 2 additions & 0 deletions contrib/babelfishpg_tsql/src/pltsql_coerce.c
Original file line number Diff line number Diff line change
Expand Up @@ -2183,6 +2183,8 @@ tsql_select_common_typmod_hook(ParseState *pstate, List *exprs, Oid common_type)
return numeric_result_typmod;

return max_typmods;


}

/*
Expand Down
Loading
Loading