GLM-multinom: Use non-temp tables in GroupIterationController
There is a potential issue with pg_temp not cleaning up correctly in
the case of a failure in GLM and multinom. This commit changes the
default value to create the temp table used for state aggregation to
avoid the temporary tables.
Co-authored-by: Bhuvnesh Chaudhary <bchaudhary@pivotal.io>
diff --git a/src/ports/postgres/modules/glm/glm.py_in b/src/ports/postgres/modules/glm/glm.py_in
index bdf7318..742cb57 100644
--- a/src/ports/postgres/modules/glm/glm.py_in
+++ b/src/ports/postgres/modules/glm/glm.py_in
@@ -195,7 +195,8 @@
'rel_state': unique_string(),
'col_grp_iteration': unique_string(),
'col_grp_state': unique_string(),
- 'state_type': schema_madlib + ".bytea8"
+ 'state_type': schema_madlib + ".bytea8",
+ 'temporaryTables': False
}
args.update(optim_params)
args.update(family_params)
@@ -350,7 +351,7 @@
**args))
# clean up
- plpy.execute("""DROP TABLE IF EXISTS pg_temp.{rel_state} """.format(**args))
+ plpy.execute("""DROP TABLE IF EXISTS {rel_state} """.format(**args))
plpy.execute("SET client_min_messages TO " + old_msg_level)
return None
diff --git a/src/ports/postgres/modules/glm/multinom.py_in b/src/ports/postgres/modules/glm/multinom.py_in
index 1293f57..7adfcb0 100644
--- a/src/ports/postgres/modules/glm/multinom.py_in
+++ b/src/ports/postgres/modules/glm/multinom.py_in
@@ -186,7 +186,8 @@
'ref_category': ref_category,
'n_categories': len(category_list),
'link': link_func,
- 'state_type': schema_madlib + ".bytea8"
+ 'state_type': schema_madlib + ".bytea8",
+ 'temporaryTables': False
}
args.update(optim_params_dict)
@@ -341,7 +342,7 @@
# clean up
plpy.execute("""
- DROP TABLE IF EXISTS pg_temp.{rel_state}
+ DROP TABLE IF EXISTS {rel_state}
""".format(**args))
plpy.execute("SET client_min_messages TO " + old_msg_level)
diff --git a/src/ports/postgres/modules/utilities/in_mem_group_control.py_in b/src/ports/postgres/modules/utilities/in_mem_group_control.py_in
index 86f0c17..68834c0 100644
--- a/src/ports/postgres/modules/utilities/in_mem_group_control.py_in
+++ b/src/ports/postgres/modules/utilities/in_mem_group_control.py_in
@@ -222,6 +222,7 @@
if arg_dict["grouping_col"] is None
else arg_dict["grouping_col"]),
)
+ self.kwargs['temporaryTables'] = self.kwargs.get('temporaryTables', True)
self.grp_to_n_tuples = {}
self.failed_grp_keys = []
@@ -287,9 +288,10 @@
else "{grouping_col}").format(**self.kwargs)
groupby_str = ("{col_grp_null}" if self.is_group_null
else "{grouping_col}").format(**self.kwargs)
+ temp = 'TEMPORARY' if self.kwargs['temporaryTables'] else ''
plpy.execute("""
DROP TABLE IF EXISTS {rel_state};
- CREATE TEMPORARY TABLE {rel_state} AS (
+ CREATE {temp} TABLE {rel_state} AS (
SELECT
array_to_string(ARRAY[{grouping_str}], ',') AS {col_grp_key},
0::integer AS {col_grp_iteration},
@@ -303,6 +305,7 @@
);
""".format(group_col=group_col,
groupby_str=groupby_str,
+ temp=temp,
**self.kwargs))
############################