Split`with` for multiple expressions into nested calls

When calling multiple expressions in a `with` statement using `and`,
only the last expression gets executed. In order to ensure all
expressions are executed, we can either use a `,` between the
expressions or call individual expressions using nested `with`
statements. Since `,` is not supported in Python versions < 2.7,
updating code to use nested `with` statement.

Co-authored-by: Nikhil Kak <nkak@vmware.com>
diff --git a/src/ports/postgres/modules/deep_learning/madlib_keras_automl.sql_in b/src/ports/postgres/modules/deep_learning/madlib_keras_automl.sql_in
index 113ec16..dc5cc6e 100644
--- a/src/ports/postgres/modules/deep_learning/madlib_keras_automl.sql_in
+++ b/src/ports/postgres/modules/deep_learning/madlib_keras_automl.sql_in
@@ -626,9 +626,10 @@
       skip_last             INTEGER DEFAULT 0
 ) RETURNS VOID AS $$
     PythonFunctionBodyOnly(`deep_learning', `madlib_keras_automl_hyperband')
-    with AOControl(False) and MinWarning('warning'):
-        schedule_loader = madlib_keras_automl_hyperband.HyperbandSchedule(schedule_table, r, eta, skip_last)
-        schedule_loader.load()
+    with AOControl(False):
+        with MinWarning('warning'):
+            schedule_loader = madlib_keras_automl_hyperband.HyperbandSchedule(schedule_table, r, eta, skip_last)
+            schedule_loader.load()
 $$ LANGUAGE plpythonu VOLATILE
               m4_ifdef(`__HAS_FUNCTION_PROPERTIES__', `MODIFIES SQL DATA', `');
 
@@ -652,12 +653,14 @@
 ) RETURNS VOID AS $$
 if automl_method is None or automl_method.lower() == 'hyperband':
     PythonFunctionBodyOnly(`deep_learning', `madlib_keras_automl_hyperband')
-    with AOControl(False) and MinWarning('warning'):
-        schedule_loader = madlib_keras_automl_hyperband.AutoMLHyperband(**globals())
+    with AOControl(False):
+        with MinWarning('warning'):
+            schedule_loader = madlib_keras_automl_hyperband.AutoMLHyperband(**globals())
 elif automl_method.lower() == 'hyperopt':
     PythonFunctionBodyOnly(`deep_learning', `madlib_keras_automl_hyperopt')
-    with AOControl(False) and MinWarning('warning'):
-        schedule_loader = madlib_keras_automl_hyperopt.AutoMLHyperopt(**globals())
+    with AOControl(False):
+        with MinWarning('warning'):
+            schedule_loader = madlib_keras_automl_hyperopt.AutoMLHyperopt(**globals())
 else:
     plpy.error("madlib_keras_automl: The chosen automl method must be 'hyperband' or 'hyperopt'")
 $$ LANGUAGE plpythonu VOLATILE
diff --git a/src/ports/postgres/modules/deep_learning/madlib_keras_gpu_info.sql_in b/src/ports/postgres/modules/deep_learning/madlib_keras_gpu_info.sql_in
index d2418e4..66cbcc2 100644
--- a/src/ports/postgres/modules/deep_learning/madlib_keras_gpu_info.sql_in
+++ b/src/ports/postgres/modules/deep_learning/madlib_keras_gpu_info.sql_in
@@ -256,9 +256,9 @@
 RETURNS VOID AS
 $$
     PythonFunctionBodyOnly(`deep_learning', `madlib_keras_gpu_info')
-    from utilities.control import MinWarning
-    with AOControl(False) and MinWarning("error"):
-        madlib_keras_gpu_info.gpu_configuration(schema_madlib, output_table, source)
+    with AOControl(False):
+        with MinWarning("error"):
+            madlib_keras_gpu_info.gpu_configuration(schema_madlib, output_table, source)
 $$
 LANGUAGE plpythonu
 m4_ifdef(`__HAS_FUNCTION_PROPERTIES__', `NO SQL', `');
diff --git a/src/ports/postgres/modules/lda/lda.sql_in b/src/ports/postgres/modules/lda/lda.sql_in
index 814b0ae..32b22fd 100644
--- a/src/ports/postgres/modules/lda/lda.sql_in
+++ b/src/ports/postgres/modules/lda/lda.sql_in
@@ -1057,9 +1057,10 @@
 RETURNS SETOF MADLIB_SCHEMA.lda_result AS $$
     PythonFunctionBodyOnly(`lda', `lda')
     from utilities.control import MinWarning
-    with AOControl(False) and MinWarning("error"):
-        lda.lda_train(schema_madlib, data_table, model_table, output_data_table,
-                      voc_size, topic_num, iter_num, alpha, beta, None, None)
+    with AOControl(False):
+        with MinWarning("error"):
+            lda.lda_train(schema_madlib, data_table, model_table, output_data_table,
+                        voc_size, topic_num, iter_num, alpha, beta, None, None)
     return [[model_table, 'model table'],
         [output_data_table, 'output data table']]
 $$ LANGUAGE plpythonu
@@ -1135,8 +1136,9 @@
 RETURNS SETOF MADLIB_SCHEMA.lda_result AS $$
     PythonFunctionBodyOnly(`lda', `lda')
     from utilities.control import MinWarning
-    with AOControl(False) and MinWarning("error"):
-        lda.lda_predict(schema_madlib, data_table, model_table, output_table)
+    with AOControl(False):
+        with MinWarning("error"):
+            lda.lda_predict(schema_madlib, data_table, model_table, output_table)
     return [[
         output_table,
         'per-doc topic distribution and per-word topic assignments']]
@@ -1197,8 +1199,9 @@
 RETURNS SETOF MADLIB_SCHEMA.lda_result AS $$
     PythonFunctionBodyOnly(`lda', `lda')
     from utilities.control import MinWarning
-    with AOControl(False) and MinWarning("error"):
-        lda.get_word_topic_count(schema_madlib, model_table, output_table)
+    with AOControl(False):
+        with MinWarning("error"):
+            lda.get_word_topic_count(schema_madlib, model_table, output_table)
     return [[output_table, 'per-word topic counts']]
 $$ LANGUAGE plpythonu STRICT
 m4_ifdef(`__HAS_FUNCTION_PROPERTIES__', `MODIFIES SQL DATA', `');
@@ -1221,8 +1224,9 @@
 RETURNS SETOF MADLIB_SCHEMA.lda_result AS $$
     PythonFunctionBodyOnly(`lda', `lda')
     from utilities.control import MinWarning
-    with AOControl(False) and MinWarning("error"):
-        lda.get_topic_desc(schema_madlib, model_table, vocab_table, desc_table, top_k)
+    with AOControl(False):
+        with MinWarning("error"):
+            lda.get_topic_desc(schema_madlib, model_table, vocab_table, desc_table, top_k)
     return [[
         desc_table,
         """topic description, use "ORDER BY topicid, prob DESC" to check the
@@ -1244,8 +1248,9 @@
 RETURNS SETOF MADLIB_SCHEMA.lda_result AS $$
     PythonFunctionBodyOnly(`lda', `lda')
     from utilities.control import MinWarning
-    with AOControl(False) and MinWarning("error"):
-        lda.get_word_topic_mapping(schema_madlib, lda_output_table, mapping_table)
+    with AOControl(False):
+        with MinWarning("error"):
+            lda.get_word_topic_mapping(schema_madlib, lda_output_table, mapping_table)
     return [[mapping_table, 'wordid - topicid mapping']]
 $$ LANGUAGE plpythonu STRICT
 m4_ifdef(`__HAS_FUNCTION_PROPERTIES__', `MODIFIES SQL DATA', `');
diff --git a/src/ports/postgres/modules/utilities/text_utilities.sql_in b/src/ports/postgres/modules/utilities/text_utilities.sql_in
index 478e751..c48b206 100644
--- a/src/ports/postgres/modules/utilities/text_utilities.sql_in
+++ b/src/ports/postgres/modules/utilities/text_utilities.sql_in
@@ -325,8 +325,9 @@
 AS $$
     PythonFunctionBodyOnly(`utilities', `text_utilities')
     from utilities.control import MinWarning
-    with AOControl(False) and MinWarning("error"):
-        return text_utilities.term_frequency(input_table, doc_id_col, word_vec_col,
+    with AOControl(False):
+        with MinWarning("error"):
+            return text_utilities.term_frequency(input_table, doc_id_col, word_vec_col,
                                              output_table, compute_vocab=compute_vocab)
 $$
 LANGUAGE plpythonu