Skip to content

Commit

Permalink
updating test
Browse files Browse the repository at this point in the history
Signed-off-by: Tanya Gupta <[email protected]>
  • Loading branch information
Tanya Gupta committed Feb 5, 2025
1 parent 584c1f9 commit ec89f1b
Show file tree
Hide file tree
Showing 5 changed files with 140 additions and 1,031 deletions.
121 changes: 2 additions & 119 deletions contrib/babelfishpg_tds/src/backend/tds/tdsresponse.c
Original file line number Diff line number Diff line change
Expand Up @@ -427,112 +427,6 @@ PrintTupPrepareInfo(DR_printtup *myState, TupleDesc typeinfo, int numAttrs)
}
}

static int32
resolve_numeric_typmod_from_append_or_mergeappend(Plan *plan, AttrNumber attno)
{
ListCell *lc;
int32 max_precision = 0,
max_scale = 0,
precision = 0,
scale = 0,
integralDigitCount = 0,
typmod = -1,
result_typmod = -1;
List *planlist = NIL;
if (IsA(plan, Append))
{
planlist = ((Append *) plan)->appendplans;
}
else if(IsA(plan, MergeAppend))
{
planlist = ((MergeAppend *) plan)->mergeplans;
}

Assert(planlist != NIL);
foreach(lc, planlist)
{
TargetEntry *tle;
Plan *outerplan = (Plan *) lfirst(lc);

/* if outerplan is SubqueryScan then use actual subplan */
if (IsA(outerplan, SubqueryScan))
outerplan = ((SubqueryScan *)outerplan)->subplan;

tle = get_tle_by_resno(outerplan->targetlist, attno);
if (IsA(tle->expr, Var))
{
Var *var = (Var *)tle->expr;
if (var->varno == OUTER_VAR)
{
typmod = resolve_numeric_typmod_outer_var(outerplan, var->varattno);
}
else
{
typmod = resolve_numeric_typmod_from_exp(outerplan, (Node *)tle->expr);
}
}
else
{
typmod = resolve_numeric_typmod_from_exp(outerplan, (Node *)tle->expr);
}
if (typmod == -1)
continue;
scale = (typmod - VARHDRSZ) & 0xffff;
precision = ((typmod - VARHDRSZ) >> 16) & 0xffff;
integralDigitCount = Max(precision - scale, max_precision - max_scale);
max_scale = Max(max_scale, scale);
max_precision = integralDigitCount + max_scale;
/*
* If max_precision is more than TDS_MAX_NUM_PRECISION then adjust precision
* to TDS_MAX_NUM_PRECISION at the cost of scale.
*/
if (max_precision > TDS_MAX_NUM_PRECISION)
{
max_scale = Max(0, max_scale - (max_precision - TDS_MAX_NUM_PRECISION));
max_precision = TDS_MAX_NUM_PRECISION;
}
result_typmod = ((max_precision << 16) | max_scale) + VARHDRSZ;
}
/* If max_precision is still default then use tds specific defaults */
if (result_typmod == -1)
{
result_typmod = ((tds_default_numeric_precision << 16) | tds_default_numeric_scale) + VARHDRSZ;
}
return result_typmod;
}

static int32
resolve_numeric_typmod_outer_var(Plan *plan, AttrNumber attno)
{
TargetEntry *tle;
Plan *outerplan = NULL;

if (IsA(plan, Append) || IsA(plan, MergeAppend))
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))
outerplan = ((SubqueryScan *)outerplan)->subplan;

/* outerplan must not be NULL */
Assert(outerplan);
tle = get_tle_by_resno(outerplan->targetlist, attno);
if (IsA(tle->expr, Var))
{
Var *var = (Var *)tle->expr;
if (var->varno == OUTER_VAR)
{
return resolve_numeric_typmod_outer_var(outerplan, var->varattno);
}
}
return resolve_numeric_typmod_from_exp(outerplan, (Node *)tle->expr);
}

static Oid
LookupCastFuncName(Oid castsource, Oid casttarget)
{
Expand Down Expand Up @@ -704,26 +598,15 @@ resolve_numeric_typmod_from_exp(Plan *plan, Node *expr)
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 && outerplan && !(IsA(plan, Result)) && var->varno == OUTER_VAR)
/* If we are in parallel mode or have sort node then from its outer plan then find the original tle from it */
if (plan && outerplan && ((IsA(plan,Agg) && IsA(outerplan, Gather)) || IsA(plan, Gather) || IsA(plan, Sort)))
{
Assert(plan);
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
2 changes: 0 additions & 2 deletions contrib/babelfishpg_tsql/src/pltsql_coerce.c
Original file line number Diff line number Diff line change
Expand Up @@ -2179,8 +2179,6 @@ tsql_select_common_typmod_hook(ParseState *pstate, List *exprs, Oid common_type)
return numeric_result_typmod;

return max_typmods;


}

/*
Expand Down
Loading

0 comments on commit ec89f1b

Please sign in to comment.