This is an automated email from the ASF dual-hosted git repository.

edimitrova pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/cassandra-dtest.git


The following commit(s) were added to refs/heads/trunk by this push:
     new bfec30a8 Fix tests for CASSANDRA-18252 - removal of scripted UDFs 
patch by Ekaterina Dimitrova; reviewed by Michael Semb Wever for CASSANDRA-18252
bfec30a8 is described below

commit bfec30a837bdaf52564f4c1fdfc5aae110f525eb
Author: Ekaterina Dimitrova <[email protected]>
AuthorDate: Thu Feb 9 20:05:23 2023 -0500

    Fix tests for CASSANDRA-18252 - removal of scripted UDFs
    patch by Ekaterina Dimitrova; reviewed by Michael Semb Wever for 
CASSANDRA-18252
---
 auth_test.py                                   | 93 ++++++++++++++++++++------
 cqlsh_tests/test_cqlsh.py                      |  2 +-
 schema_metadata_test.py                        |  4 +-
 upgrade_tests/upgrade_through_versions_test.py | 12 +++-
 user_functions_test.py                         | 32 +++++----
 5 files changed, 105 insertions(+), 38 deletions(-)

diff --git a/auth_test.py b/auth_test.py
index f4ab2e87..3d1aa10c 100644
--- a/auth_test.py
+++ b/auth_test.py
@@ -1192,7 +1192,7 @@ class TestAuthRoles(AbstractTestAuth):
         @jira_ticket CASSANDRA-7653
         """
         dtest_setup_overrides = DTestSetupOverrides()
-        if dtest_config.cassandra_version_from_build >= '3.0':
+        if '3.0' <= dtest_config.cassandra_version_from_build < '4.2':
             dtest_setup_overrides.cluster_options = 
ImmutableMapping({'enable_user_defined_functions': 'true',
                                                                       
'enable_scripted_user_defined_functions': 'true'})
         else:
@@ -1364,11 +1364,18 @@ class TestAuthRoles(AbstractTestAuth):
         as_mike.execute("CREATE KEYSPACE ks WITH replication = 
{'class':'SimpleStrategy', 'replication_factor':1}")
         as_mike.execute("CREATE TABLE ks.cf (id int primary key, val int)")
         as_mike.execute("CREATE ROLE role1 WITH PASSWORD = '11111' AND 
SUPERUSER = false AND LOGIN = true")
-        as_mike.execute("""CREATE FUNCTION ks.state_function_1(a int, b int)
-                        CALLED ON NULL INPUT
-                        RETURNS int
-                        LANGUAGE javascript
-                        AS ' a + b'""")
+        if self.cluster.version() < LooseVersion('4.2'):
+            as_mike.execute("""CREATE FUNCTION ks.state_function_1(a int, b 
int)
+                            CALLED ON NULL INPUT
+                            RETURNS int
+                            LANGUAGE javascript
+                            AS ' a + b'""")
+        else:
+            as_mike.execute("""CREATE FUNCTION ks.state_function_1(a int, b 
int)
+                            CALLED ON NULL INPUT
+                            RETURNS int
+                            LANGUAGE java
+                            AS ' return a + b;'""")
         as_mike.execute("""CREATE AGGREGATE ks.simple_aggregate_1(int)
                         SFUNC state_function_1
                         STYPE int
@@ -1654,7 +1661,10 @@ class TestAuthRoles(AbstractTestAuth):
         self.superuser.execute("CREATE TABLE ks.cf (id int primary key, val 
int)")
         self.superuser.execute("CREATE ROLE mike WITH PASSWORD = '12345' AND 
SUPERUSER = false AND LOGIN = true")
         self.superuser.execute("CREATE ROLE role1 WITH SUPERUSER = false AND 
LOGIN = false")
-        self.superuser.execute("CREATE FUNCTION ks.state_func(a int, b int) 
CALLED ON NULL INPUT RETURNS int LANGUAGE javascript AS 'a+b'")
+        if self.cluster.version() < LooseVersion('4.2'):
+            self.superuser.execute("CREATE FUNCTION ks.state_func(a int, b 
int) CALLED ON NULL INPUT RETURNS int LANGUAGE javascript AS 'a+b'")
+        else:
+            self.superuser.execute("CREATE FUNCTION ks.state_func(a int, b 
int) CALLED ON NULL INPUT RETURNS int LANGUAGE java AS ' return a+b;'")
         self.superuser.execute("CREATE AGGREGATE ks.agg_func(int) SFUNC 
state_func STYPE int")
 
         # GRANT ALL ON ALL KEYSPACES grants Permission.ALL_DATA
@@ -2125,8 +2135,12 @@ class TestAuthRoles(AbstractTestAuth):
         """
         self.setup_table()
         self.superuser.execute("CREATE ROLE mike WITH PASSWORD = '12345' AND 
LOGIN = true")
-        self.superuser.execute("CREATE FUNCTION ks.plus_one ( input int ) 
CALLED ON NULL INPUT RETURNS int LANGUAGE javascript AS 'input + 1'")
-        self.superuser.execute("CREATE FUNCTION ks.\"plusOne\" ( input int ) 
CALLED ON NULL INPUT RETURNS int LANGUAGE javascript AS 'input + 1'")
+        if self.cluster.version() < LooseVersion('4.2'):
+            self.superuser.execute("CREATE FUNCTION ks.plus_one ( input int ) 
CALLED ON NULL INPUT RETURNS int LANGUAGE javascript AS 'input + 1'")
+            self.superuser.execute("CREATE FUNCTION ks.\"plusOne\" ( input int 
) CALLED ON NULL INPUT RETURNS int LANGUAGE javascript AS 'input + 1'")
+        else:
+            self.superuser.execute("CREATE FUNCTION ks.plus_one ( input int ) 
CALLED ON NULL INPUT RETURNS int LANGUAGE java AS 'return input + 1;'")
+            self.superuser.execute("CREATE FUNCTION ks.\"plusOne\" ( input int 
) CALLED ON NULL INPUT RETURNS int LANGUAGE java AS 'return input + 1;'")
 
         # grant / revoke on a specific function
         self.superuser.execute("GRANT EXECUTE ON FUNCTION ks.plus_one(int) TO 
mike")
@@ -2170,7 +2184,10 @@ class TestAuthRoles(AbstractTestAuth):
         """
         self.setup_table()
         self.superuser.execute("CREATE ROLE mike")
-        self.superuser.execute("CREATE FUNCTION ks.plus_one ( input int ) 
CALLED ON NULL INPUT RETURNS int LANGUAGE javascript AS 'input + 1'")
+        if self.cluster.version() < LooseVersion('4.2'):
+            self.superuser.execute("CREATE FUNCTION ks.plus_one ( input int ) 
CALLED ON NULL INPUT RETURNS int LANGUAGE javascript AS 'input + 1'")
+        else:
+            self.superuser.execute("CREATE FUNCTION ks.plus_one ( input int ) 
CALLED ON NULL INPUT RETURNS int LANGUAGE java AS 'return input + 1;'")
         self.superuser.execute("GRANT EXECUTE ON FUNCTION ks.plus_one(int) TO 
mike")
         self.superuser.execute("GRANT EXECUTE ON FUNCTION ks.plus_one(int) TO 
mike")
         self.assert_permissions_listed([("mike", "<function 
ks.plus_one(int)>", "EXECUTE")],
@@ -2198,8 +2215,12 @@ class TestAuthRoles(AbstractTestAuth):
         self.superuser.execute("INSERT INTO ks.t1 (k,v) values (1,1)")
         self.superuser.execute("CREATE ROLE mike WITH PASSWORD = '12345' AND 
LOGIN = true")
         self.superuser.execute("GRANT SELECT ON ks.t1 TO mike")
-        self.superuser.execute("CREATE FUNCTION ks.func_one ( input int ) 
CALLED ON NULL INPUT RETURNS int LANGUAGE javascript AS 'input + 1'")
-        self.superuser.execute("CREATE FUNCTION ks.func_two ( input int ) 
CALLED ON NULL INPUT RETURNS int LANGUAGE javascript AS 'input + 1'")
+        if self.cluster.version() < LooseVersion('4.2'):
+            self.superuser.execute("CREATE FUNCTION ks.func_one ( input int ) 
CALLED ON NULL INPUT RETURNS int LANGUAGE javascript AS 'input + 1'")
+            self.superuser.execute("CREATE FUNCTION ks.func_two ( input int ) 
CALLED ON NULL INPUT RETURNS int LANGUAGE javascript AS 'input + 1'")
+        else:
+            self.superuser.execute("CREATE FUNCTION ks.func_one ( input int ) 
CALLED ON NULL INPUT RETURNS int LANGUAGE java AS 'return input + 1;'")
+            self.superuser.execute("CREATE FUNCTION ks.func_two ( input int ) 
CALLED ON NULL INPUT RETURNS int LANGUAGE java AS 'return input + 1;'")
 
         as_mike = self.get_session(user='mike', password='12345')
         select_one = "SELECT k, v, ks.func_one(v) FROM ks.t1 WHERE k = 1"
@@ -2253,12 +2274,18 @@ class TestAuthRoles(AbstractTestAuth):
         * Verify mike can create a new UDF iff he has the CREATE permission
         """
         self.setup_table()
-        self.superuser.execute("CREATE FUNCTION ks.plus_one ( input int ) 
CALLED ON NULL INPUT RETURNS int LANGUAGE javascript AS 'input + 1'")
+        if self.cluster.version() < LooseVersion('4.2'):
+            self.superuser.execute("CREATE FUNCTION ks.plus_one ( input int ) 
CALLED ON NULL INPUT RETURNS int LANGUAGE javascript AS 'input + 1'")
+        else:
+            self.superuser.execute("CREATE FUNCTION ks.plus_one ( input int ) 
CALLED ON NULL INPUT RETURNS int LANGUAGE java AS 'return input + 1;'")
         self.superuser.execute("CREATE ROLE mike WITH PASSWORD = '12345' AND 
LOGIN = true")
         as_mike = self.get_session(user='mike', password='12345')
 
         # can't replace an existing function without ALTER permission on the 
parent ks
-        cql = "CREATE OR REPLACE FUNCTION ks.plus_one( input int ) CALLED ON 
NULL INPUT RETURNS int LANGUAGE javascript as '1 + input'"
+        if self.cluster.version() < LooseVersion('4.2'):
+            cql = "CREATE OR REPLACE FUNCTION ks.plus_one( input int ) CALLED 
ON NULL INPUT RETURNS int LANGUAGE javascript as '1 + input'"
+        else:
+            cql = "CREATE OR REPLACE FUNCTION ks.plus_one( input int ) CALLED 
ON NULL INPUT RETURNS int LANGUAGE java as 'return 1 + input;'"
         assert_unauthorized(as_mike, cql,
                             r"User mike has no ALTER permission on <function 
ks.plus_one\(int\)> or any of its parents")
         self.superuser.execute("GRANT ALTER ON FUNCTION ks.plus_one(int) TO 
mike")
@@ -2298,7 +2325,10 @@ class TestAuthRoles(AbstractTestAuth):
                        InvalidRequest)
 
         # can't create a new function without CREATE on the parent keyspace's 
collection of functions
-        cql = "CREATE FUNCTION ks.plus_one ( input int ) CALLED ON NULL INPUT 
RETURNS int LANGUAGE javascript AS 'input + 1'"
+        if self.cluster.version() < LooseVersion('4.2'):
+            cql = "CREATE FUNCTION ks.plus_one ( input int ) CALLED ON NULL 
INPUT RETURNS int LANGUAGE javascript AS 'input + 1'"
+        else:
+            cql = "CREATE FUNCTION ks.plus_one ( input int ) CALLED ON NULL 
INPUT RETURNS int LANGUAGE java AS 'return input + 1;'"
         assert_unauthorized(as_mike, cql,
                             "User mike has no CREATE permission on <all 
functions in ks> or any of its parents")
         self.superuser.execute("GRANT CREATE ON ALL FUNCTIONS IN KEYSPACE ks 
TO mike")
@@ -2315,7 +2345,10 @@ class TestAuthRoles(AbstractTestAuth):
         """
         self.setup_table()
         self.superuser.execute("CREATE ROLE mike WITH PASSWORD = '12345' AND 
LOGIN = true")
-        self.superuser.execute("CREATE FUNCTION ks.plus_one ( input int ) 
CALLED ON NULL INPUT RETURNS int LANGUAGE javascript AS 'input + 1'")
+        if self.cluster.version() < LooseVersion('4.2'):
+            self.superuser.execute("CREATE FUNCTION ks.plus_one ( input int ) 
CALLED ON NULL INPUT RETURNS int LANGUAGE javascript AS 'input + 1'")
+        else:
+            self.superuser.execute("CREATE FUNCTION ks.plus_one ( input int ) 
CALLED ON NULL INPUT RETURNS int LANGUAGE java AS 'return input + 1;'")
         self.superuser.execute("GRANT EXECUTE ON FUNCTION ks.plus_one(int) TO 
mike")
         self.superuser.execute("GRANT EXECUTE ON ALL FUNCTIONS IN KEYSPACE ks 
TO mike")
         self.superuser.execute("GRANT EXECUTE ON ALL FUNCTIONS TO mike")
@@ -2343,7 +2376,10 @@ class TestAuthRoles(AbstractTestAuth):
         """
         self.setup_table()
         self.superuser.execute("CREATE ROLE mike WITH PASSWORD = '12345' AND 
LOGIN = true")
-        self.superuser.execute("CREATE FUNCTION ks.plus_one ( input int ) 
CALLED ON NULL INPUT RETURNS int LANGUAGE javascript AS 'input + 1'")
+        if self.cluster.version() < LooseVersion('4.2'):
+            self.superuser.execute("CREATE FUNCTION ks.plus_one ( input int ) 
CALLED ON NULL INPUT RETURNS int LANGUAGE javascript AS 'input + 1'")
+        else: 
+            self.superuser.execute("CREATE FUNCTION ks.plus_one ( input int ) 
CALLED ON NULL INPUT RETURNS int LANGUAGE java AS 'return input + 1;'")
         self.superuser.execute("GRANT EXECUTE ON FUNCTION ks.plus_one(int) TO 
mike")
         self.superuser.execute("GRANT EXECUTE ON ALL FUNCTIONS IN KEYSPACE ks 
TO mike")
 
@@ -2371,8 +2407,12 @@ class TestAuthRoles(AbstractTestAuth):
         """
         self.setup_table()
         self.superuser.execute("CREATE ROLE mike WITH PASSWORD = '12345' AND 
LOGIN = true")
-        self.superuser.execute("CREATE FUNCTION ks.plus_one ( input int ) 
CALLED ON NULL INPUT RETURNS int LANGUAGE javascript AS 'input + 1'")
-        self.superuser.execute("CREATE FUNCTION ks.plus_one ( input double ) 
CALLED ON NULL INPUT RETURNS double LANGUAGE javascript AS 'input + 1'")
+        if self.cluster.version() < LooseVersion('4.2'):
+            self.superuser.execute("CREATE FUNCTION ks.plus_one ( input int ) 
CALLED ON NULL INPUT RETURNS int LANGUAGE javascript AS 'input + 1'")
+            self.superuser.execute("CREATE FUNCTION ks.plus_one ( input double 
) CALLED ON NULL INPUT RETURNS double LANGUAGE javascript AS 'input + 1'")
+        else:
+            self.superuser.execute("CREATE FUNCTION ks.plus_one ( input int ) 
CALLED ON NULL INPUT RETURNS int LANGUAGE java AS 'return input + 1;'")
+            self.superuser.execute("CREATE FUNCTION ks.plus_one ( input double 
) CALLED ON NULL INPUT RETURNS double LANGUAGE java AS 'return input + 1;'")
 
         # grant execute on one variant
         self.superuser.execute("GRANT EXECUTE ON FUNCTION ks.plus_one(int) TO 
mike")
@@ -2414,7 +2454,10 @@ class TestAuthRoles(AbstractTestAuth):
         """
         self.setup_table()
         self.superuser.execute("CREATE ROLE mike WITH PASSWORD = '12345' AND 
LOGIN = true")
-        self.superuser.execute("CREATE FUNCTION ks.state_func (a int, b int) 
CALLED ON NULL INPUT RETURNS int LANGUAGE javascript AS 'a + b'")
+        if self.cluster.version() < LooseVersion('4.2'):
+            self.superuser.execute("CREATE FUNCTION ks.state_func (a int, b 
int) CALLED ON NULL INPUT RETURNS int LANGUAGE javascript AS 'a + b'")
+        else:
+            self.superuser.execute("CREATE FUNCTION ks.state_func (a int, b 
int) CALLED ON NULL INPUT RETURNS int LANGUAGE java AS 'return a + b;'")
         self.superuser.execute("CREATE AGGREGATE ks.agg_func (int) SFUNC 
state_func STYPE int")
         self.superuser.execute("GRANT EXECUTE ON FUNCTION ks.state_func(int, 
int) TO mike")
         self.superuser.execute("GRANT EXECUTE ON FUNCTION ks.agg_func(int) TO 
mike")
@@ -2467,7 +2510,10 @@ class TestAuthRoles(AbstractTestAuth):
         @param cql The statement to verify. Should contain the UDF ks.plus_one
         """
         self.setup_table()
-        self.superuser.execute("CREATE FUNCTION ks.plus_one ( input int ) 
CALLED ON NULL INPUT RETURNS int LANGUAGE javascript AS 'input + 1'")
+        if self.cluster.version() < LooseVersion('4.2'):
+            self.superuser.execute("CREATE FUNCTION ks.plus_one ( input int ) 
CALLED ON NULL INPUT RETURNS int LANGUAGE javascript AS 'input + 1'")
+        else:
+            self.superuser.execute("CREATE FUNCTION ks.plus_one ( input int ) 
CALLED ON NULL INPUT RETURNS int LANGUAGE java AS 'return input + 1;'")
         self.superuser.execute("CREATE ROLE mike WITH PASSWORD = '12345' AND 
LOGIN = true")
         self.superuser.execute("GRANT ALL PERMISSIONS ON ks.t1 TO mike")
         self.superuser.execute("INSERT INTO ks.t1 (k,v) values (1,1)")
@@ -2488,7 +2534,10 @@ class TestAuthRoles(AbstractTestAuth):
         self.setup_table()
         self.superuser.execute("CREATE ROLE function_user")
         self.superuser.execute("GRANT EXECUTE ON ALL FUNCTIONS IN KEYSPACE ks 
TO function_user")
-        self.superuser.execute("CREATE FUNCTION ks.plus_one ( input int ) 
CALLED ON NULL INPUT RETURNS int LANGUAGE javascript AS 'input + 1'")
+        if self.cluster.version() < LooseVersion('4.2'):
+            self.superuser.execute("CREATE FUNCTION ks.plus_one ( input int ) 
CALLED ON NULL INPUT RETURNS int LANGUAGE javascript AS 'input + 1'")
+        else:
+            self.superuser.execute("CREATE FUNCTION ks.plus_one ( input int ) 
CALLED ON NULL INPUT RETURNS int LANGUAGE java AS 'return input + 1;'")
         self.superuser.execute("INSERT INTO ks.t1 (k,v) VALUES (1,1)")
         self.superuser.execute("CREATE ROLE mike WITH PASSWORD = '12345' AND 
LOGIN = true")
         self.superuser.execute("GRANT SELECT ON ks.t1 TO mike")
diff --git a/cqlsh_tests/test_cqlsh.py b/cqlsh_tests/test_cqlsh.py
index a72dc5ca..4f4d1b75 100644
--- a/cqlsh_tests/test_cqlsh.py
+++ b/cqlsh_tests/test_cqlsh.py
@@ -105,7 +105,7 @@ class TestCqlsh(Tester, CqlshMixin):
     def fixture_dtest_setup_overrides(self, dtest_config):
         dtest_setup_overrides = DTestSetupOverrides()
 
-        if dtest_config.cassandra_version_from_build >= '3.0':
+        if '3.0' <= dtest_config.cassandra_version_from_build < '4.2':
             dtest_setup_overrides.cluster_options = 
ImmutableMapping({'enable_user_defined_functions': 'true',
                                                                       
'enable_scripted_user_defined_functions': 'true'})
         else:
diff --git a/schema_metadata_test.py b/schema_metadata_test.py
index e6cfb38c..e859ae21 100644
--- a/schema_metadata_test.py
+++ b/schema_metadata_test.py
@@ -503,7 +503,9 @@ class TestSchemaMetadata(Tester):
         cluster = fixture_dtest_setup.cluster
         cluster.schema_event_refresh_window = 0
 
-        if cluster.version() >= '3.0':
+        if cluster.version() >= '4.2':
+            
cluster.set_configuration_options({'enable_user_defined_functions': 'true'})
+        elif cluster.version() >= '3.0':
             
cluster.set_configuration_options({'enable_user_defined_functions': 'true',
                                                
'enable_scripted_user_defined_functions': 'true'})
         elif cluster.version() >= '2.2':
diff --git a/upgrade_tests/upgrade_through_versions_test.py 
b/upgrade_tests/upgrade_through_versions_test.py
index e4f8a17c..58fc02e3 100644
--- a/upgrade_tests/upgrade_through_versions_test.py
+++ b/upgrade_tests/upgrade_through_versions_test.py
@@ -24,7 +24,7 @@ from .upgrade_base import switch_jdks
 from .upgrade_manifest import (build_upgrade_pairs,
                                current_2_1_x, current_2_2_x, current_3_0_x,
                                indev_3_11_x,
-                               current_3_11_x, indev_trunk, CASSANDRA_4_0)
+                               current_3_11_x, indev_trunk, CASSANDRA_4_0, 
CASSANDRA_4_2)
 
 logger = logging.getLogger(__name__)
 
@@ -434,7 +434,6 @@ class TestUpgrade(Tester):
                     self._check_on_subprocs(self.fixture_dtest_setup.subprocs)
                     logger.debug('Successfully upgraded %d of %d nodes to %s' %
                           (num + 1, len(self.cluster.nodelist()), 
version_meta.version))
-
                 self.cluster.set_install_dir(version=version_meta.version)
                 self.install_nodetool_legacy_parsing()
                 
self.fixture_dtest_setup.reinitialize_cluster_for_different_version()
@@ -527,6 +526,8 @@ class TestUpgrade(Tester):
             logger.debug("Set new cassandra dir for %s: %s" % (node.name, 
node.get_install_dir()))
             if internode_ssl and (LooseVersion(version_meta.family) >= 
CASSANDRA_4_0):
                 node.set_configuration_options({'server_encryption_options': 
{'enabled': True, 'enable_legacy_ssl_storage_port': True}})
+            if LooseVersion(version_meta.family) >= CASSANDRA_4_2:
+                
node.set_configuration_options({'enable_scripted_user_defined_functions': 
'false'})
 
         # hacky? yes. We could probably extend ccm to allow this publicly.
         # the topology file needs to be written before any nodes are started
@@ -776,6 +777,10 @@ class BootstrapMixin(object):
         # Check we can bootstrap a new node on the upgraded cluster:
         logger.debug("Adding a node to the cluster")
         nnode = new_node(self.cluster, remote_debug_port=str(2000 + 
len(self.cluster.nodes)))
+
+        if nnode.get_cassandra_version() >= '4.2':
+            
nnode.set_configuration_options({'enable_scripted_user_defined_functions': 
'false'})
+
         nnode.start(use_jna=True, wait_other_notice=240, 
wait_for_binary_proto=True)
         self._write_values()
         self._increment_counters()
@@ -787,6 +792,9 @@ class BootstrapMixin(object):
         logger.debug("Adding a node to the cluster")
         nnode = new_node(self.cluster, remote_debug_port=str(2000 + 
len(self.cluster.nodes)), data_center='dc2')
 
+        if nnode.get_cassandra_version() >= '4.2':
+            
nnode.set_configuration_options({'enable_scripted_user_defined_functions': 
'false'})
+
         nnode.start(use_jna=True, wait_other_notice=240, 
wait_for_binary_proto=True)
         self._write_values()
         self._increment_counters()
diff --git a/user_functions_test.py b/user_functions_test.py
index dced54fa..d0676019 100644
--- a/user_functions_test.py
+++ b/user_functions_test.py
@@ -24,7 +24,7 @@ class TestUserFunctions(Tester):
     def fixture_dtest_setup_overrides(self, dtest_config):
         dtest_setup_overrides = DTestSetupOverrides()
 
-        if dtest_config.cassandra_version_from_build >= '3.0':
+        if '3.0' <= dtest_config.cassandra_version_from_build < '4.2':
             dtest_setup_overrides.cluster_options = 
ImmutableMapping({'enable_user_defined_functions': 'true',
                                                                       
'enable_scripted_user_defined_functions': 'true'})
         else:
@@ -170,6 +170,7 @@ class TestUserFunctions(Tester):
         # should now work - unambiguous
         session.execute("DROP FUNCTION overloaded")
 
+    @since('3.0', max_version='4.1.x')
     def test_udf_scripting(self):
         session = self.prepare()
         session.execute("create table nums (key int primary key, val double);")
@@ -177,19 +178,23 @@ class TestUserFunctions(Tester):
         for x in range(1, 4):
             session.execute("INSERT INTO nums (key, val) VALUES (%d, %d)" % 
(x, float(x)))
 
-        session.execute("CREATE FUNCTION x_sin(val double) called on null 
input returns double language javascript as 'Math.sin(val)'")
+        session.execute(
+            "CREATE FUNCTION x_sin(val double) called on null input returns 
double language javascript as 'Math.sin(val)'")
 
         assert_one(session, "SELECT key, val, x_sin(val) FROM nums where key = 
%d" % 1, [1, 1.0, math.sin(1.0)])
         assert_one(session, "SELECT key, val, x_sin(val) FROM nums where key = 
%d" % 2, [2, 2.0, math.sin(2.0)])
         assert_one(session, "SELECT key, val, x_sin(val) FROM nums where key = 
%d" % 3, [3, 3.0, math.sin(3.0)])
 
-        session.execute("create function y_sin(val double) called on null 
input returns double language javascript as 'Math.sin(val).toString()'")
+        session.execute(
+            "create function y_sin(val double) called on null input returns 
double language javascript as 'Math.sin(val).toString()'")
 
         assert_invalid(session, "select y_sin(val) from nums where key = 1", 
expected=FunctionFailure)
 
-        assert_invalid(session, "create function compilefail(key int) called 
on null input returns double language javascript as 'foo bar';")
+        assert_invalid(session,
+                       "create function compilefail(key int) called on null 
input returns double language javascript as 'foo bar';")
 
-        session.execute("create function plustwo(key int) called on null input 
returns double language javascript as 'key+2'")
+        session.execute(
+            "create function plustwo(key int) called on null input returns 
double language javascript as 'key+2'")
 
         assert_one(session, "select plustwo(key) from nums where key = 3", [5])
 
@@ -206,6 +211,16 @@ class TestUserFunctions(Tester):
         assert_one(session, "SELECT avg(val) FROM nums", [5.0])
         assert_one(session, "SELECT count(*) FROM nums", [9])
 
+        if self.cluster.version() < LooseVersion('4.2'):
+            session.execute("create function test(a int, b double) called on 
null input returns int language javascript as 'a + b;'")
+        else:
+            session.execute("create function test(a int, b double) called on 
null input returns int language java as 'return a + 
Integer.valueOf(b.intValue());'")
+        session.execute("create aggregate aggy(double) sfunc test stype int")
+
+        assert_invalid(session, "create aggregate aggtwo(int) sfunc aggy stype 
int")
+
+        assert_invalid(session, "create aggregate aggthree(int) sfunc test 
stype int finalfunc aggtwo")
+
     def test_aggregate_udf(self):
         session = self.prepare()
         session.execute("create table nums (key int primary key, val int);")
@@ -218,13 +233,6 @@ class TestUserFunctions(Tester):
 
         assert_one(session, "select suma(val) from nums", ["16"])
 
-        session.execute("create function test(a int, b double) called on null 
input returns int language javascript as 'a + b;'")
-        session.execute("create aggregate aggy(double) sfunc test stype int")
-
-        assert_invalid(session, "create aggregate aggtwo(int) sfunc aggy stype 
int")
-
-        assert_invalid(session, "create aggregate aggthree(int) sfunc test 
stype int finalfunc aggtwo")
-
     def test_udf_with_udt(self):
         """
         Test UDFs that operate on non-frozen UDTs.


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to