Skip to content

Commit

Permalink
Refractor code
Browse files Browse the repository at this point in the history
Signed-off-by: Shameem Ahmed <[email protected]>
  • Loading branch information
ahmed-shameem committed Jan 13, 2025
1 parent aae6e31 commit 4ddc2a7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 17 deletions.
17 changes: 3 additions & 14 deletions contrib/babelfishpg_tsql/src/hooks.c
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ static PlannedStmt *pltsql_planner_hook(Query *parse, const char *query_string,
* parser Hook
*****************************************/
static Oid set_param_collation(Param *param);
static Oid default_collation_for_builtin_type(Type typ, bool handle_text);
static Oid default_collation_for_builtin_type(Type typ);
static char* pltsql_get_object_identity_event_trigger(ObjectAddress *addr);
static const char *remove_db_name_in_schema(const char *schema_name, const char *object_type);

Expand Down Expand Up @@ -5620,15 +5620,14 @@ set_param_collation(Param *param)
* @return - default collation for the given builtin type based on dialect
*/
static Oid
default_collation_for_builtin_type(Type typ, bool handle_pg_type)
default_collation_for_builtin_type(Type typ)
{
Form_pg_type typtup;
Oid oid = InvalidOid;

typtup = (Form_pg_type) GETSTRUCT(typ);
if (OidIsValid(typtup->typcollation) &&
sql_dialect == SQL_DIALECT_TSQL &&
(typtup->typnamespace == sys_schema_oid))
sql_dialect == SQL_DIALECT_TSQL)
{
/*
* Always set CLUSTER_COLLATION_OID() for babelfish collatable types so that
Expand All @@ -5641,16 +5640,6 @@ default_collation_for_builtin_type(Type typ, bool handle_pg_type)
oid = typtup->typcollation;
}

/*
* Special handling for PG datatypes such as TEXT because Babelfish does not define sys.TEXT.
* This is required as Babelfish currently does not handle collation of String Const node correctly.
* TODO: Fix the handling of the collation for String Const node.
*/
if (handle_pg_type && oid == DEFAULT_COLLATION_OID)
{
oid = CLUSTER_COLLATION_OID();
}

return oid;
}

Expand Down
8 changes: 5 additions & 3 deletions contrib/babelfishpg_tsql/src/pltsql_ruleutils.c
Original file line number Diff line number Diff line change
Expand Up @@ -2650,11 +2650,13 @@ get_coercion_expr(Node *arg, deparse_context *context,
}
else
{
const char *dump_restore = GetConfigOption("babelfishpg_tsql.dump_restore", true, false);
if (!PRETTY_PAREN(context) && (!dump_restore || (dump_restore && strcmp(dump_restore, "on") != 0)))
// const char *dump_restore = GetConfigOption("babelfishpg_tsql.dump_restore", true, false);
// if (!PRETTY_PAREN(context) && (!dump_restore || (dump_restore && strcmp(dump_restore, "on") != 0)))
if (!PRETTY_PAREN(context))
appendStringInfoChar(buf, '(');
get_rule_expr_paren(arg, context, false, parentNode);
if (!PRETTY_PAREN(context) && (!dump_restore || (dump_restore && strcmp(dump_restore, "on") != 0)))
// if (!PRETTY_PAREN(context) && (!dump_restore || (dump_restore && strcmp(dump_restore, "on") != 0)))
if (!PRETTY_PAREN(context))
appendStringInfoChar(buf, ')');
}

Expand Down

0 comments on commit 4ddc2a7

Please sign in to comment.