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

[CBRD-24945] Correct value node print in dblink query rewritten #4608

Merged
merged 3 commits into from
Aug 25, 2023
Merged
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
26 changes: 25 additions & 1 deletion src/parser/name_resolution.c
Original file line number Diff line number Diff line change
Expand Up @@ -4850,6 +4850,27 @@ PT_TYPE_ENUM pt_type[CCI_U_TYPE_LAST + 1] = {
PT_TYPE_JSON
};

static T_CCI_U_TYPE
pt_dblink_get_basic_utype (T_CCI_U_EXT_TYPE u_ext_type)
{
if (CCI_IS_SET_TYPE (u_ext_type))
{
return CCI_U_TYPE_SET;
}
else if (CCI_IS_MULTISET_TYPE (u_ext_type))
{
return CCI_U_TYPE_MULTISET;
}
else if (CCI_IS_SEQUENCE_TYPE (u_ext_type))
{
return CCI_U_TYPE_SEQUENCE;
}
else
{
return (T_CCI_U_TYPE) CCI_GET_COLLECTION_DOMAIN (u_ext_type);
}
}

static bool
pt_dblink_table_fill_attr_def (PARSER_CONTEXT * parser, PT_NODE * attr_def_node, const S_REMOTE_COL_ATTR * attr)
{
Expand All @@ -4858,7 +4879,7 @@ pt_dblink_table_fill_attr_def (PARSER_CONTEXT * parser, PT_NODE * attr_def_node,

attr_def_node->data_type = NULL;
/* it needs to convert ext type to CCI_U_TYPE */
attr_def_node->type_enum = pt_type[(T_CCI_U_TYPE) CCI_GET_COLLECTION_DOMAIN (attr->type_idx)];
attr_def_node->type_enum = pt_type[pt_dblink_get_basic_utype (attr->type_idx)];
switch (attr_def_node->type_enum)
{
case PT_TYPE_JSON:
Expand All @@ -4874,6 +4895,9 @@ pt_dblink_table_fill_attr_def (PARSER_CONTEXT * parser, PT_NODE * attr_def_node,
case PT_TYPE_CLOB:
case PT_TYPE_OBJECT:
case PT_TYPE_ENUMERATION:
case PT_TYPE_SET:
case PT_TYPE_MULTISET:
case PT_TYPE_SEQUENCE:
PT_ERRORmf (parser, attr_def_node, MSGCAT_SET_PARSER_SEMANTIC,
MSGCAT_SEMANTIC_DBLINK_NOT_SUPPORTED_TYPE, pt_show_type_enum (attr_def_node->type_enum));
return false;
Expand Down
1 change: 1 addition & 0 deletions src/parser/parse_tree.h
Original file line number Diff line number Diff line change
Expand Up @@ -3772,6 +3772,7 @@ struct parser_node
unsigned is_system_generated_stmt:1; /* is internally generated by system */
unsigned use_auto_commit:1; /* use autocommit */
unsigned done_reduce_equality_terms:1; /* reduce_equality_terms() is already called */
unsigned print_in_value_for_dblink:1; /* for select ... where in (...) to print (...) not {...} */
} flag;
PT_STATEMENT_INFO info; /* depends on 'node_type' field */
};
Expand Down
8 changes: 4 additions & 4 deletions src/parser/parse_tree_cl.c
Original file line number Diff line number Diff line change
Expand Up @@ -15908,17 +15908,18 @@ pt_print_value (PARSER_CONTEXT * parser, PT_NODE * p)
case PT_TYPE_SET:
case PT_TYPE_MULTISET:
case PT_TYPE_SEQUENCE:
if (p->spec_ident || (parser->custom_print & PT_PRINT_SUPPRESS_FOR_DBLINK))
if (p->spec_ident || ((parser->custom_print & PT_PRINT_SUPPRESS_FOR_DBLINK) && p->flag.print_in_value_for_dblink))
{
/* this is tagged as an "in" clause right hand side Print it as a parenthesized list */
/* print_in_value_for_dblink is a flag as same meaning for dblink */
r1 = pt_print_bytes_l (parser, p->info.value.data_value.set);
q = pt_append_nulstring (parser, q, "(");
q = pt_append_varchar (parser, q, r1);
q = pt_append_nulstring (parser, q, ")");
}
else
{
if (p->type_enum != PT_TYPE_SEQUENCE)
if (p->type_enum != PT_TYPE_SEQUENCE && !(parser->custom_print & PT_PRINT_SUPPRESS_FOR_DBLINK))
{
q = pt_append_nulstring (parser, q, pt_show_type_enum (p->type_enum));
}
Expand All @@ -15940,8 +15941,7 @@ pt_print_value (PARSER_CONTEXT * parser, PT_NODE * p)
case PT_TYPE_INTEGER:
case PT_TYPE_BIGINT:
case PT_TYPE_SMALLINT:
if (p->info.value.text != NULL
&& !(parser->custom_print & (PT_PRINT_SUPPRESS_FOR_DBLINK | PT_SUPPRESS_BIGINT_CAST)))
if (p->info.value.text != NULL && !(parser->custom_print & PT_SUPPRESS_BIGINT_CAST))
{
r = p->info.value.text;
}
Expand Down
15 changes: 15 additions & 0 deletions src/parser/parser_support.c
Original file line number Diff line number Diff line change
Expand Up @@ -11899,13 +11899,28 @@ pt_convert_dml (PARSER_CONTEXT * parser, PT_NODE * node, void *arg, int *continu
} while(0)
// *INDENT-ON*

static PT_NODE *
pt_set_print_in_value_for_dblink (PARSER_CONTEXT * parser, PT_NODE * node, void *arg, int *continue_walk)
{
PT_NODE *spec = (PT_NODE *) arg;

if (node->node_type == PT_EXPR && (node->info.expr.op == PT_IS_IN || node->info.expr.op == PT_IS_NOT_IN))
{
node->info.expr.arg2->flag.print_in_value_for_dblink = 1;
}

return node;
}

void
pt_rewrite_for_dblink (PARSER_CONTEXT * parser, PT_NODE * stmt)
{
SERVER_NAME_LIST snl;

memset (&snl, 0x00, sizeof (SERVER_NAME_LIST));

parser_walk_tree (parser, stmt, pt_set_print_in_value_for_dblink, NULL, NULL, NULL);

switch (stmt->node_type)
{
case PT_INSERT:
Expand Down
Loading