You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@madlib.apache.org by kh...@apache.org on 2020/10/27 20:18:11 UTC
[madlib] 06/08: Split`with` for multiple expressions into nested
calls
This is an automated email from the ASF dual-hosted git repository.
khannaekta pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/madlib.git
commit 30db0e6e28a25d29c4673a12bbe434df9b5b7ad0
Author: Ekta Khanna <ek...@vmware.com>
AuthorDate: Mon Oct 19 13:33:25 2020 -0700
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 <nk...@vmware.com>
---
.../deep_learning/madlib_keras_automl.sql_in | 17 ++++++++------
.../deep_learning/madlib_keras_gpu_info.sql_in | 6 ++---
src/ports/postgres/modules/lda/lda.sql_in | 27 +++++++++++++---------
.../modules/utilities/text_utilities.sql_in | 5 ++--
4 files changed, 32 insertions(+), 23 deletions(-)
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 @@ CREATE OR REPLACE FUNCTION MADLIB_SCHEMA.hyperband_schedule(
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 @@ CREATE OR REPLACE FUNCTION MADLIB_SCHEMA.madlib_keras_automl(
) 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 @@ CREATE OR REPLACE FUNCTION MADLIB_SCHEMA.gpu_configuration(output_table text, so
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 @@ MADLIB_SCHEMA.lda_train
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 @@ MADLIB_SCHEMA.lda_predict
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 @@ MADLIB_SCHEMA.lda_get_word_topic_count
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 @@ MADLIB_SCHEMA.lda_get_topic_desc
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 @@ MADLIB_SCHEMA.lda_get_word_topic_mapping
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 @@ RETURNS TEXT
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