Skip to content

Commit

Permalink
In plpython functions: Replaced "from madlib import ..." by try/catch…
Browse files Browse the repository at this point in the history
… block -> We always want to install Python modules in the PostgreSQL/Greenplum hierarchy, which might not be in sys.path by default
  • Loading branch information
Florian Schoppmann authored and Florian Schoppmann committed Jan 29, 2011
1 parent 35bfbdf commit a4505af
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 26 deletions.
17 changes: 10 additions & 7 deletions methods/k-means/src/pg_gp/kmeans_create.sql_in
Expand Up @@ -234,12 +234,15 @@ CREATE AGGREGATE MADLIB_SCHEMA.__kmeans_meanPosition( MADLIB_SCHEMA.SVEC )
CREATE OR REPLACE FUNCTION MADLIB_SCHEMA.kmeans_run( input_table text, k int, goodness int, run_id text, output_table text)
RETURNS text
AS $$

from madlib import kmeans

plpy.execute( 'set client_min_messages=warning');
return kmeans.kmeans_run( input_table, k, goodness, run_id, output_table);

import sys
try:
from madlib import kmeans
except:
sys.path.append("PLPYTHON_LIBDIR")
from madlib import kmeans

plpy.execute( 'set client_min_messages=warning');
return kmeans.kmeans_run( input_table, k, goodness, run_id, output_table);
$$ LANGUAGE plpythonu;

COMMIT;
COMMIT;
17 changes: 10 additions & 7 deletions methods/profile/src/pg_gp/profile_create.sql_in
Expand Up @@ -79,10 +79,13 @@ seems to be present as of version 2.3.2. The simple workaround is to use
CREATE OR REPLACE FUNCTION MADLIB_SCHEMA.profile_run( input_table text)
RETURNS text
AS $$

from madlib import profile

plpy.execute( 'set client_min_messages=warning');
return profile.profile_run( input_table);

$$ LANGUAGE plpythonu;
import sys
try:
from madlib import profile
except:
sys.path.append("PLPYTHON_LIBDIR")
from madlib import profile

plpy.execute( 'set client_min_messages=warning');
return profile.profile_run( input_table);
$$ LANGUAGE plpythonu;
2 changes: 1 addition & 1 deletion methods/regress/src/pg_gp/logRegress.py_in
Expand Up @@ -227,7 +227,7 @@ def compute_logregr_coef(**kwargs):
in the log-likelihood of less than <tt>precision</tt>. In other
words, we terminate if the objective function value has converged.
If this parameter is 0.0, then the algorithm will not check for
convergence and only terminate after <tt><em>numIterations</em></tt>
convergence and only terminate after <tt>numIterations</tt>
iterations.

@return array with coefficients in case of convergence, otherwise None
Expand Down
35 changes: 30 additions & 5 deletions methods/regress/src/pg_gp/regression.sql_in
Expand Up @@ -501,7 +501,13 @@ CREATE FUNCTION MADLIB_SCHEMA.logregr_coef(
"depColumn" VARCHAR,
"indepColumn" VARCHAR)
RETURNS DOUBLE PRECISION[] AS $$
from madlib import logRegress
import sys
try:
ifdef(<nom4>DEBUG</nom4>,,<nom4>from madlib </nom4>)import logRegress
except:
sys.path.append("PLPYTHON_LIBDIR")
ifdef(<nom4>DEBUG</nom4>,,<nom4>from madlib </nom4>)import logRegress

return logRegress.compute_logregr_coef(**globals())
$$ LANGUAGE plpythonu VOLATILE;

Expand All @@ -511,7 +517,13 @@ CREATE FUNCTION MADLIB_SCHEMA.logregr_coef(
"indepColumn" VARCHAR,
"numIterations" INTEGER)
RETURNS DOUBLE PRECISION[] AS $$
from madlib import logRegress
import sys
try:
ifdef(<nom4>DEBUG</nom4>,,<nom4>from madlib </nom4>)import logRegress
except:
sys.path.append("PLPYTHON_LIBDIR")
ifdef(<nom4>DEBUG</nom4>,,<nom4>from madlib </nom4>)import logRegress

return logRegress.compute_logregr_coef(**globals())
$$ LANGUAGE plpythonu VOLATILE;

Expand All @@ -522,7 +534,13 @@ CREATE FUNCTION MADLIB_SCHEMA.logregr_coef(
"numIterations" INTEGER,
"optimizer" VARCHAR)
RETURNS DOUBLE PRECISION[] AS $$
from madlib import logRegress
import sys
try:
ifdef(<nom4>DEBUG</nom4>,,<nom4>from madlib </nom4>)import logRegress
except:
sys.path.append("PLPYTHON_LIBDIR")
ifdef(<nom4>DEBUG</nom4>,,<nom4>from madlib </nom4>)import logRegress

return logRegress.compute_logregr_coef(**globals())
$$ LANGUAGE plpythonu VOLATILE;

Expand Down Expand Up @@ -553,7 +571,8 @@ $$ LANGUAGE plpythonu VOLATILE;
* 0.001);</tt>
*
* @internal
* @sa This function is a wrapper for logRegress::compute_logregr_coef().
* @sa This function is a wrapper for logRegress::compute_logregr_coef(), which
* sets the default values.
*/
CREATE FUNCTION MADLIB_SCHEMA.logregr_coef(
"source" VARCHAR,
Expand All @@ -563,7 +582,13 @@ CREATE FUNCTION MADLIB_SCHEMA.logregr_coef(
"optimizer" VARCHAR /*+ DEFAULT 'irls' */,
"precision" DOUBLE PRECISION /*+ DEFAULT 0.0001 */)
RETURNS DOUBLE PRECISION[] AS $$
from madlib import logRegress
import sys
try:
ifdef(<nom4>DEBUG</nom4>,,<nom4>from madlib </nom4>)import logRegress
except:
sys.path.append("PLPYTHON_LIBDIR")
ifdef(<nom4>DEBUG</nom4>,,<nom4>from madlib </nom4>)import logRegress

return logRegress.compute_logregr_coef(**globals())
$$ LANGUAGE plpythonu VOLATILE;

Expand Down
15 changes: 9 additions & 6 deletions methods/svd-mf/src/pg_gp/svdmf_create.sql_in
Expand Up @@ -127,10 +127,13 @@ CREATE OR REPLACE FUNCTION MADLIB_SCHEMA.svdmf_run(
)
RETURNS TEXT
AS $$

from madlib import svdmf

plpy.execute( 'set client_min_messages=warning');
return svdmf.svdmf_run( input_table, col_name, row_name, value, num_features);

import sys
try:
from madlib import svdmf
except:
sys.path.append("PLPYTHON_LIBDIR")
from madlib import svdmf

plpy.execute( 'set client_min_messages=warning');
return svdmf.svdmf_run( input_table, col_name, row_name, value, num_features);
$$ LANGUAGE plpythonu;

0 comments on commit a4505af

Please sign in to comment.