cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Robert Stupp (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (CASSANDRA-8289) Allow users to debug/test UDF
Date Wed, 12 Nov 2014 23:58:34 GMT

    [ https://issues.apache.org/jira/browse/CASSANDRA-8289?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14208943#comment-14208943
] 

Robert Stupp commented on CASSANDRA-8289:
-----------------------------------------

Initial draft working. [Code is here|https://github.com/snazy/cassandra/tree/8289-udftest/tools/udftest/src]

Basically allows to write code like the following.
{{penetrate}} calls the UDF with many variations and combinations on input parameters like
{{null}} or {{Double.NaN}} to see if the UDF fails for some (maybe uncommon) argument values.
{{execute}} calls the UDF with the arguments provided.

{code}
public class UDFTestTest
{
    @Test
    public void basicTest() throws Throwable
    {
        UDF udf = UDFs.create("CREATE FUNCTION foo(inp int, d double) RETURNS text LANGUAGE
java AS 'return \"foo\";'");
        udf.penetrate();
    }

    @Test(expected = InvalidRequestException.class)
    public void npeTest() throws Throwable
    {
        UDF udf = UDFs.create("CREATE FUNCTION foo(inp int, d double) RETURNS text LANGUAGE
java AS 'return inp.toString() + d;'");
        udf.penetrate();
    }

    @Test
    public void executionTest() throws Throwable
    {
        UDF udf = UDFs.create("CREATE FUNCTION foo(inp int, d double) RETURNS text LANGUAGE
java AS 'return \"x\" + inp + \"x\" + d + \"x\";'");
        Assert.assertEquals("xnullxnullx", udf.execute(null, null));
        Assert.assertEquals("x5x9.1x", udf.execute(5, 9.1d));
    }
}
{code}


> Allow users to debug/test UDF
> -----------------------------
>
>                 Key: CASSANDRA-8289
>                 URL: https://issues.apache.org/jira/browse/CASSANDRA-8289
>             Project: Cassandra
>          Issue Type: New Feature
>            Reporter: Robert Stupp
>            Assignee: Robert Stupp
>              Labels: udf
>             Fix For: 3.0
>
>
> Currently it's not possible to execute unit tests against UDFs nor is it possible to
debug them.
> Idea is to provide some kind of minimalistic "framework" to execute at least scalar UDFs
from a unit test.
> Basically that UDF-executor would take the information that 'CREATE FUNCTION' takes,
compiles that UDF and allows the user to call it using plain java calls.
> In case of the Java language it could also generate Java source files to enable users
to set breakpoints.
> It could also check for timeouts to identify e.g. "endless loop" scenarios or do some
byte code analysis to check for "evil" package usage.
> For example:
> {code}
> import org.apache.cassandra.udfexec.*
> public class MyUnitTest {
>   @Test
>   public void testIt() {
>     UDFExec sinExec = UDFExec.compile("sin", "java",
>       Double.class, // return type
>       Double.class  // argument type(s)
>     );
>     sinExec.call(2.0d);
>     sinExec.call(null);
>   }
> }
> {code}
> Note: this one is not intended to do some "magic" to start a debugger on a C* node and
debug it there.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Mime
View raw message