User Defined Functions/Aggregates in ModelQuerySet

19 views
Skip to first unread message

Earl Lapus

unread,
Aug 31, 2017, 2:46:12 AM8/31/17
to DataStax Python Driver for Apache Cassandra User Mailing List
Hi,

Is there a way to use to a user defined function/aggregate inside a ModelQuerySet?
I browsed through the docs: https://datastax.github.io/python-driver/api/index.html but could not find anything related to this topic.

If this is not possible, what are my other alternatives? Should I be defining an equivalent function in my python program that emulates what the user define function does?
PS: posted the same inquiry at the Cassandra mailing list: https://www.mail-archive.com/us...@cassandra.apache.org/msg53382.html

Cheers, Earl

Alan Boudreault

unread,
Sep 11, 2017, 2:22:02 PM9/11/17
to python-dr...@lists.datastax.com
Hello Earl,

Here are your options to use UDF/UDA with the driver:

1- Use the core-driver to execute your request:
    
    session.execute('SELECT my_user_function_or_agg(field_a) FROM test;')

2- For CQLEngine, you need to create a wrapper like the existing ones(Token, MinTimeUUID, MaxTimeUUID). See:


Also, you might prefer to write your user functions in Python directly rather than calling them on the server in some cases. e.g. There is not much benefit calling a function like `bigintAsBlob` since you will get the same result with a function defined at the application level.

Regards,
Alan

--
You received this message because you are subscribed to the Google Groups "DataStax Python Driver for Apache Cassandra User Mailing List" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python-driver-user+unsub...@lists.datastax.com.



--

Alan Boudreault
Software Engineer (Drivers) | alan.bo...@datastax.com


Earl Lapus

unread,
Sep 11, 2017, 10:41:07 PM9/11/17
to python-dr...@lists.datastax.com
Hi Alan,

On Tue, 12 Sep 2017 at 2:22 AM Alan Boudreault <alan.bo...@datastax.com> wrote:
Hello Earl,

Here are your options to use UDF/UDA with the driver:

1- Use the core-driver to execute your request:
    
    session.execute('SELECT my_user_function_or_agg(field_a) FROM test;')

I've tried this method already... it is straightfoward and it works.


2- For CQLEngine, you need to create a wrapper like the existing ones(Token, MinTimeUUID, MaxTimeUUID). See:


This one I'll have to check and try.



Also, you might prefer to write your user functions in Python directly rather than calling them on the server in some cases. e.g. There is not much benefit calling a function like `bigintAsBlob` since you will get the same result with a function defined at the application level.

I'll keep this in mind when writing my code. Thank you for the response, I appreciate it.

Cheers,
Earl
--
There are seven words in this sentence.
Reply all
Reply to author
Forward
0 new messages