Why vertica queries can be run from JavaUdx but not from PythonUdx?

priteshpritesh Vertica Customer

I have a java based udx function which connects to vertica (9.2.x) and execute queries but the same thing in python is not working. I am using "vertica_python" package and since it generates .egg file , i am end up getting imprort vertica_python error. Need help!!

Best Answer

  • priteshpritesh Vertica Customer
    Answer ✓

    Ok, so my test_vertica_queries_udx.py file looks like this.
    import vertica_python
    conn_info = { XXXXX }
    connection = vertica_python.connect(**conn_info)
    db_cursor = connection.cursor()

    class test_datatypes(vertica_sdk.ScalarFunction):
    """Testing If Vertica Queries Can be Run From Here Returns None """
    def init(self):
    pass
    def setup(self, server_interface, col_types):
    pass
    def processBlock(self, server_interface, arg_reader, res_writer):
    server_interface.log(" $$$ ")
    while(True):
    fn = arg_reader.getString(0)
    t_name = arg_reader.getString(1)
    q = """ Insert Query """
    db_cursor.execute(q)
    db_cursor.execute("COMMIT;")
    res_writer.setString("File Name : "+fn + ", Table Name : " + t_name)
    res_writer.next()
    if not arg_reader.next():
    break

    def destroy(self, server_interface, col_types):
        pass
    

    class test_datatypes_factory(vertica_sdk.ScalarFunctionFactory):
    def createScalarFunction(self, srv):
    return test_datatypes()
    def getPrototype(self, srv_interface, arg_types, return_type):
    arg_types.addVarchar()
    arg_types.addVarchar()
    return_type.addVarchar()
    def getReturnType(self, srv_interface, arg_types, return_type):
    return_type.addVarchar(256)

    This is how my .py file looks like. I am just trying to run query inside (taking random params as of now--ignorable)
    Creating Libs Here:
    CREATE LIBRARY test_datatypes_lib AS '/test/user/test_datatype_udx.py' DEPENDS '/test/user/site-packages/' LANGUAGE 'Python';
    CREATE FUNCTION test_datatypes AS LANGUAGE 'Python' NAME 'test_datatypes_factory' LIBRARY test_datatypes_lib;

Answers

  • SruthiASruthiA Vertica Employee Administrator

    Can you share me more details? If you can please share me your python UDx

  • Bryan_HBryan_H Vertica Employee Administrator

    Hi, you should be able to run Vertica queries using the recent driver from Github that works on Python 3.x: https://github.com/vertica/vertica-python
    Is there a specific error from your code? Did you try the sample code from the Github README?

  • priteshpritesh Vertica Customer

    thanks for the answer, but as i have already pasted the code above, i am using the recent drive and i have also tried "vertica_db_client" python client driver section. The package that you mentioned upon installing generates a .egg file, which can not be imported, the error looks straight "**import error --> vertica_python.py not found". i have posted you discussion please see that also. 'Vertica v9.2.0-7 Jdbc Driver for Python2.7(.x) but same doesn't support Python2.7?'

  • priteshpritesh Vertica Customer

    Thanks @Bryan_H , your solution worked. Thanks a lot !!

Leave a Comment

BoldItalicStrikethroughOrdered listUnordered list
Emoji
Image
Align leftAlign centerAlign rightToggle HTML viewToggle full pageToggle lights
Drop image/file