You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@madlib.apache.org by GitBox <gi...@apache.org> on 2021/03/04 00:24:39 UTC

[GitHub] [madlib] fmcquillan99 commented on pull request #554: DL: Check if the owner of the object table is a superuser

fmcquillan99 commented on pull request #554:
URL: https://github.com/apache/madlib/pull/554#issuecomment-790183101


   If I run this 1x it works
   ```
   # import database connector psycopg2 and create connection cursor
   import psycopg2 as p2
   conn = p2.connect('postgresql://gpadmin@localhost:8000/madlib')
   cur = conn.cursor()
   
   # import Dill and define functions
   import dill
   
   # custom loss
   def squared_error(y_true, y_pred):
       import tensorflow.keras.backend as K
       return K.square(y_pred - y_true)
   pb_squared_error=dill.dumps(squared_error)
   
   # custom metric
   def rmse(y_true, y_pred):
       import tensorflow.keras.backend as K
       return K.sqrt(K.mean(K.square(y_pred - y_true), axis=-1))
   pb_rmse=dill.dumps(rmse)
   
   # call load function
   cur.execute("DROP TABLE IF EXISTS custom_function_table")
   cur.execute("SELECT madlib.load_custom_function('custom_function_table',  %s,'squared_error', 'squared error')", [p2.Binary(pb_squared_error)])
   cur.execute("SELECT madlib.load_custom_function('custom_function_table',  %s,'rmse', 'root mean square error')", [p2.Binary(pb_rmse)])
   conn.commit()
   ```
   But if I run it a second time I get this error:
   ```
   ---------------------------------------------------------------------------
   InternalError_                            Traceback (most recent call last)
   <ipython-input-20-03935b6aea23> in <module>()
        21 # call load function
        22 cur.execute("DROP TABLE IF EXISTS custom_function_table")
   ---> 23 cur.execute("SELECT madlib.load_custom_function('custom_function_table',  %s,'squared_error', 'squared error')", [p2.Binary(pb_squared_error)])
        24 cur.execute("SELECT madlib.load_custom_function('custom_function_table',  %s,'rmse', 'root mean square error')", [p2.Binary(pb_rmse)])
        25 conn.commit()
   
   InternalError_: plpy.Error: Function 'squared_error' already exists in madlib.custom_function_table (plpython.c:5038)
   CONTEXT:  Traceback (most recent call last):
     PL/Python function "load_custom_function", line 21, in <module>
       madlib_keras_custom_function.load_custom_function(**globals())
     PL/Python function "load_custom_function", line 42, in wrapper
     PL/Python function "load_custom_function", line 120, in load_custom_function
   PL/Python function "load_custom_function"
   ```
   
   It look like it created the `custom_function_table` in the madlib schema even though I was working in the public schema. So the `DROP TABLE IF EXISTS custom_function_table`  did not work.  If I change it to `DROP TABLE IF EXISTS madlib.custom_function_table` then it does work.
   
   Is that the intended behavior?


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org