public void TestFixtureSetup() { if (CassandraVersion < Version.Parse("2.2")) { return; } _testCluster = TestClusterManager.GetTestCluster(1, 0, false, DefaultMaxClusterCreateRetries, false, false); _testCluster.UpdateConfig("enable_user_defined_functions: true"); _testCluster.Start(1); using (var cluster = Cluster.Builder().AddContactPoint(_testCluster.InitialContactPoint).Build()) { var session = cluster.Connect(); var queries = new[] { "CREATE KEYSPACE ks_udf WITH replication = {'class': 'SimpleStrategy', 'replication_factor' : 1}", "CREATE FUNCTION ks_udf.return_one() RETURNS NULL ON NULL INPUT RETURNS int LANGUAGE java AS 'return 1;'", "CREATE FUNCTION ks_udf.plus(s int, v int) RETURNS NULL ON NULL INPUT RETURNS int LANGUAGE java AS 'return s+v;'", "CREATE FUNCTION ks_udf.plus(s bigint, v bigint) RETURNS NULL ON NULL INPUT RETURNS bigint LANGUAGE java AS 'return s+v;'", "CREATE AGGREGATE ks_udf.sum(int) SFUNC plus STYPE int INITCOND 1", "CREATE AGGREGATE ks_udf.sum(bigint) SFUNC plus STYPE bigint INITCOND 2" }; foreach (var q in queries) { session.Execute(q); } } }
public void TestFixtureSetup() { if (TestClusterManager.CheckCassandraVersion(false, Version.Parse("2.2"), Comparison.LessThan)) { return; } _testCluster = TestClusterManager.GetTestCluster(1, 0, false, DefaultMaxClusterCreateRetries, false, false); _testCluster.UpdateConfig("enable_user_defined_functions: true"); _testCluster.Start(1); using (var cluster = ClusterBuilder().AddContactPoint(_testCluster.InitialContactPoint).Build()) { var session = cluster.Connect(); var queries = new List <string> { "CREATE KEYSPACE ks_udf WITH replication = {'class': 'SimpleStrategy', 'replication_factor' : 1}", "CREATE FUNCTION ks_udf.return_one() RETURNS NULL ON NULL INPUT RETURNS int LANGUAGE java AS 'return 1;'", "CREATE FUNCTION ks_udf.plus(s int, v int) RETURNS NULL ON NULL INPUT RETURNS int LANGUAGE java AS 'return s+v;'", "CREATE FUNCTION ks_udf.plus(s bigint, v bigint) RETURNS NULL ON NULL INPUT RETURNS bigint LANGUAGE java AS 'return s+v;'", "CREATE AGGREGATE ks_udf.sum(int) SFUNC plus STYPE int INITCOND 1", "CREATE AGGREGATE ks_udf.sum(bigint) SFUNC plus STYPE bigint INITCOND 2" }; if (TestClusterManager.CheckDseVersion(new Version(6, 0), Comparison.GreaterThanOrEqualsTo)) { queries.Add("CREATE FUNCTION ks_udf.deterministic(dividend int, divisor int) " + "CALLED ON NULL INPUT RETURNS int DETERMINISTIC LANGUAGE java AS " + "'return dividend / divisor;'"); queries.Add("CREATE FUNCTION ks_udf.monotonic(dividend int, divisor int) " + "CALLED ON NULL INPUT RETURNS int MONOTONIC LANGUAGE java AS " + "'return dividend / divisor;'"); queries.Add("CREATE FUNCTION ks_udf.md(dividend int, divisor int) " + "CALLED ON NULL INPUT RETURNS int DETERMINISTIC MONOTONIC LANGUAGE java AS " + "'return dividend / divisor;'"); queries.Add("CREATE FUNCTION ks_udf.monotonic_on(dividend int, divisor int) " + "CALLED ON NULL INPUT RETURNS int MONOTONIC ON dividend LANGUAGE java AS " + "'return dividend / divisor;'"); queries.Add("CREATE AGGREGATE ks_udf.deta(int) SFUNC plus STYPE int INITCOND 0 DETERMINISTIC;"); } foreach (var q in queries) { session.Execute(q); } } }