Repository: cassandra Updated Branches: refs/heads/trunk 6288dd9d2 -> b2abcb7fc
Remove DETERMINISTIC/NON DETERMINISTIC function distinction patch by Carl Yeksigian; reviewed by Aleksey Yeschenko for CASSANDRA-9383 Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/b2abcb7f Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/b2abcb7f Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/b2abcb7f Branch: refs/heads/trunk Commit: b2abcb7fc9afde553a071c4050ba4573122c2329 Parents: 6288dd9 Author: Carl Yeksigian <[email protected]> Authored: Thu May 14 12:42:46 2015 -0400 Committer: Aleksey Yeschenko <[email protected]> Committed: Thu May 14 21:02:23 2015 +0300 ---------------------------------------------------------------------- doc/cql3/CQL.textile | 3 - pylib/cqlshlib/cql3handling.py | 1 - src/java/org/apache/cassandra/cql3/Cql.g | 8 +- .../cassandra/cql3/functions/Function.java | 7 - .../cql3/functions/JavaSourceUDFFactory.java | 12 +- .../cql3/functions/NativeFunction.java | 6 - .../cql3/functions/ScriptBasedUDF.java | 5 +- .../cassandra/cql3/functions/TimeuuidFcts.java | 6 - .../cassandra/cql3/functions/UDAggregate.java | 5 - .../cassandra/cql3/functions/UDFunction.java | 34 +- .../cassandra/cql3/functions/UuidFcts.java | 6 - .../statements/CreateFunctionStatement.java | 5 +- .../cassandra/schema/LegacySchemaTables.java | 5 +- .../org/apache/cassandra/cql3/UFAuthTest.java | 319 +++---------------- 14 files changed, 65 insertions(+), 357 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cassandra/blob/b2abcb7f/doc/cql3/CQL.textile ---------------------------------------------------------------------- diff --git a/doc/cql3/CQL.textile b/doc/cql3/CQL.textile index 8a227fb..89bd1b9 100644 --- a/doc/cql3/CQL.textile +++ b/doc/cql3/CQL.textile @@ -590,7 +590,6 @@ __Syntax:__ bc(syntax).. <create-function-stmt> ::= CREATE ( OR REPLACE )? - ( ( NON )? DETERMINISTIC )? FUNCTION ( IF NOT EXISTS )? ( ( <keyspace> '.' )? <function-name> )? '(' <arg-name> <arg-type> ( ',' <arg-name> <arg-type> )* ')' @@ -618,8 +617,6 @@ CREATE FUNCTION akeyspace.fname IF NOT EXISTS @CREATE FUNCTION@ creates or replaces a user-defined function. -Functions are either @DETERMINISTIC@ or @NON DETERMINISTIC@. A deterministic function always returns the same value for the same input values. A non-deterministic function may not. Examples of deterministic functions are math functions like _add_ or _sin_. Examples of non-deterministic functions are: _now_ or _random_. Functions are assumed to be deterministic by default. - h4(#functionSignature). Function Signature Signatures are used to distinguish individual functions. The signature consists of: http://git-wip-us.apache.org/repos/asf/cassandra/blob/b2abcb7f/pylib/cqlshlib/cql3handling.py ---------------------------------------------------------------------- diff --git a/pylib/cqlshlib/cql3handling.py b/pylib/cqlshlib/cql3handling.py index bc638b6..add4a7f 100644 --- a/pylib/cqlshlib/cql3handling.py +++ b/pylib/cqlshlib/cql3handling.py @@ -1023,7 +1023,6 @@ syntax_rules += r''' <createFunctionStatement> ::= "CREATE" ("OR" "REPLACE")? "FUNCTION" ("IF" "NOT" "EXISTS")? - ("NON"? "DETERMINISTIC")? <userFunctionName> ( "(" ( newcol=<cident> <storageType> ( "," [newcolname]=<cident> <storageType> )* )? http://git-wip-us.apache.org/repos/asf/cassandra/blob/b2abcb7f/src/java/org/apache/cassandra/cql3/Cql.g ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/cql3/Cql.g b/src/java/org/apache/cassandra/cql3/Cql.g index ca68396..bd47825 100644 --- a/src/java/org/apache/cassandra/cql3/Cql.g +++ b/src/java/org/apache/cassandra/cql3/Cql.g @@ -593,12 +593,10 @@ createFunctionStatement returns [CreateFunctionStatement expr] boolean orReplace = false; boolean ifNotExists = false; - boolean deterministic = true; List<ColumnIdentifier> argsNames = new ArrayList<>(); List<CQL3Type.Raw> argsTypes = new ArrayList<>(); } : K_CREATE (K_OR K_REPLACE { orReplace = true; })? - ((K_NON { deterministic = false; })? K_DETERMINISTIC)? K_FUNCTION (K_IF K_NOT K_EXISTS { ifNotExists = true; })? fn=functionName @@ -611,7 +609,7 @@ createFunctionStatement returns [CreateFunctionStatement expr] K_RETURNS rt = comparatorType K_LANGUAGE language = IDENT K_AS body = STRING_LITERAL - { $expr = new CreateFunctionStatement(fn, $language.text.toLowerCase(), $body.text, deterministic, argsNames, argsTypes, rt, orReplace, ifNotExists); } + { $expr = new CreateFunctionStatement(fn, $language.text.toLowerCase(), $body.text, argsNames, argsTypes, rt, orReplace, ifNotExists); } ; dropFunctionStatement returns [DropFunctionStatement expr] @@ -1550,8 +1548,6 @@ basic_unreserved_keyword returns [String str] | K_INITCOND | K_RETURNS | K_LANGUAGE - | K_NON - | K_DETERMINISTIC | K_JSON ) { $str = $k.text; } ; @@ -1680,10 +1676,8 @@ K_FINALFUNC: F I N A L F U N C; K_INITCOND: I N I T C O N D; K_RETURNS: R E T U R N S; K_LANGUAGE: L A N G U A G E; -K_NON: N O N; K_OR: O R; K_REPLACE: R E P L A C E; -K_DETERMINISTIC: D E T E R M I N I S T I C; K_JSON: J S O N; http://git-wip-us.apache.org/repos/asf/cassandra/blob/b2abcb7f/src/java/org/apache/cassandra/cql3/functions/Function.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/cql3/functions/Function.java b/src/java/org/apache/cassandra/cql3/functions/Function.java index 6fb9ba2..56119f7 100644 --- a/src/java/org/apache/cassandra/cql3/functions/Function.java +++ b/src/java/org/apache/cassandra/cql3/functions/Function.java @@ -30,13 +30,6 @@ public interface Function public AbstractType<?> returnType(); /** - * Checks whether the function is a pure function (as in doesn't depend on, nor produce side effects) or not. - * - * @return <code>true</code> if the function is a pure function, <code>false</code> otherwise. - */ - public boolean isPure(); - - /** * Checks whether the function is a native/hard coded one or not. * * @return <code>true</code> if the function is a native/hard coded one, <code>false</code> otherwise. http://git-wip-us.apache.org/repos/asf/cassandra/blob/b2abcb7f/src/java/org/apache/cassandra/cql3/functions/JavaSourceUDFFactory.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/cql3/functions/JavaSourceUDFFactory.java b/src/java/org/apache/cassandra/cql3/functions/JavaSourceUDFFactory.java index 1abb40b..eddb2e6 100644 --- a/src/java/org/apache/cassandra/cql3/functions/JavaSourceUDFFactory.java +++ b/src/java/org/apache/cassandra/cql3/functions/JavaSourceUDFFactory.java @@ -52,8 +52,7 @@ public final class JavaSourceUDFFactory List<ColumnIdentifier> argNames, List<AbstractType<?>> argTypes, AbstractType<?> returnType, - String body, - boolean deterministic) + String body) throws InvalidRequestException { // argDataTypes is just the C* internal argTypes converted to the Java Driver DataType @@ -99,11 +98,11 @@ public final class JavaSourceUDFFactory cc.toClass().getDeclaredConstructor( FunctionName.class, List.class, List.class, DataType[].class, AbstractType.class, DataType.class, - String.class, boolean.class); + String.class); return (UDFunction) ctor.newInstance( name, argNames, argTypes, argDataTypes, returnType, returnDataType, - body, deterministic); + body); } catch (NotFoundException | CannotCompileException | NoSuchMethodException | LinkageError | InstantiationException | IllegalAccessException e) { @@ -145,9 +144,8 @@ public final class JavaSourceUDFFactory "com.datastax.driver.core.DataType[] argDataTypes, " + "org.apache.cassandra.db.marshal.AbstractType returnType, " + "com.datastax.driver.core.DataType returnDataType, " + - "String body," + - "boolean deterministic)\n{" + - " super(name, argNames, argTypes, argDataTypes, returnType, returnDataType, \"java\", body, deterministic);\n" + + "String body)\n{" + + " super(name, argNames, argTypes, argDataTypes, returnType, returnDataType, \"java\", body);\n" + "}"; } http://git-wip-us.apache.org/repos/asf/cassandra/blob/b2abcb7f/src/java/org/apache/cassandra/cql3/functions/NativeFunction.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/cql3/functions/NativeFunction.java b/src/java/org/apache/cassandra/cql3/functions/NativeFunction.java index bff7688..df66ea0 100644 --- a/src/java/org/apache/cassandra/cql3/functions/NativeFunction.java +++ b/src/java/org/apache/cassandra/cql3/functions/NativeFunction.java @@ -31,12 +31,6 @@ public abstract class NativeFunction extends AbstractFunction super(FunctionName.nativeFunction(name), Arrays.asList(argTypes), returnType); } - // Most of our functions are pure, the other ones should override this - public boolean isPure() - { - return true; - } - public boolean isNative() { return true; http://git-wip-us.apache.org/repos/asf/cassandra/blob/b2abcb7f/src/java/org/apache/cassandra/cql3/functions/ScriptBasedUDF.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/cql3/functions/ScriptBasedUDF.java b/src/java/org/apache/cassandra/cql3/functions/ScriptBasedUDF.java index 4fe6ac9..b38f483 100644 --- a/src/java/org/apache/cassandra/cql3/functions/ScriptBasedUDF.java +++ b/src/java/org/apache/cassandra/cql3/functions/ScriptBasedUDF.java @@ -67,11 +67,10 @@ public class ScriptBasedUDF extends UDFunction List<AbstractType<?>> argTypes, AbstractType<?> returnType, String language, - String body, - boolean deterministic) + String body) throws InvalidRequestException { - super(name, argNames, argTypes, returnType, language, body, deterministic); + super(name, argNames, argTypes, returnType, language, body); Compilable scriptEngine = scriptEngines.get(language); if (scriptEngine == null) http://git-wip-us.apache.org/repos/asf/cassandra/blob/b2abcb7f/src/java/org/apache/cassandra/cql3/functions/TimeuuidFcts.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/cql3/functions/TimeuuidFcts.java b/src/java/org/apache/cassandra/cql3/functions/TimeuuidFcts.java index c1c3490..d24572b 100644 --- a/src/java/org/apache/cassandra/cql3/functions/TimeuuidFcts.java +++ b/src/java/org/apache/cassandra/cql3/functions/TimeuuidFcts.java @@ -35,12 +35,6 @@ public abstract class TimeuuidFcts { return ByteBuffer.wrap(UUIDGen.getTimeUUIDBytes()); } - - @Override - public boolean isPure() - { - return false; - } }; public static final Function minTimeuuidFct = new NativeScalarFunction("mintimeuuid", TimeUUIDType.instance, TimestampType.instance) http://git-wip-us.apache.org/repos/asf/cassandra/blob/b2abcb7f/src/java/org/apache/cassandra/cql3/functions/UDAggregate.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/cql3/functions/UDAggregate.java b/src/java/org/apache/cassandra/cql3/functions/UDAggregate.java index e4cbd55..f5a1af0 100644 --- a/src/java/org/apache/cassandra/cql3/functions/UDAggregate.java +++ b/src/java/org/apache/cassandra/cql3/functions/UDAggregate.java @@ -113,11 +113,6 @@ public class UDAggregate extends AbstractFunction implements AggregateFunction return true; } - public boolean isPure() - { - return false; - } - public boolean isNative() { return false; http://git-wip-us.apache.org/repos/asf/cassandra/blob/b2abcb7f/src/java/org/apache/cassandra/cql3/functions/UDFunction.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/cql3/functions/UDFunction.java b/src/java/org/apache/cassandra/cql3/functions/UDFunction.java index 4672451..a56af6e 100644 --- a/src/java/org/apache/cassandra/cql3/functions/UDFunction.java +++ b/src/java/org/apache/cassandra/cql3/functions/UDFunction.java @@ -46,7 +46,6 @@ public abstract class UDFunction extends AbstractFunction implements ScalarFunct protected final String language; protected final String body; - protected final boolean isDeterministic; protected final DataType[] argDataTypes; protected final DataType returnDataType; @@ -56,11 +55,10 @@ public abstract class UDFunction extends AbstractFunction implements ScalarFunct List<AbstractType<?>> argTypes, AbstractType<?> returnType, String language, - String body, - boolean isDeterministic) + String body) { this(name, argNames, argTypes, UDHelper.driverTypes(argTypes), returnType, - UDHelper.driverType(returnType), language, body, isDeterministic); + UDHelper.driverType(returnType), language, body); } protected UDFunction(FunctionName name, @@ -70,15 +68,13 @@ public abstract class UDFunction extends AbstractFunction implements ScalarFunct AbstractType<?> returnType, DataType returnDataType, String language, - String body, - boolean isDeterministic) + String body) { super(name, argTypes, returnType); assert new HashSet<>(argNames).size() == argNames.size() : "duplicate argument names"; this.argNames = argNames; this.language = language; this.body = body; - this.isDeterministic = isDeterministic; this.argDataTypes = argDataTypes; this.returnDataType = returnDataType; } @@ -88,14 +84,13 @@ public abstract class UDFunction extends AbstractFunction implements ScalarFunct List<AbstractType<?>> argTypes, AbstractType<?> returnType, String language, - String body, - boolean isDeterministic) + String body) throws InvalidRequestException { switch (language) { - case "java": return JavaSourceUDFFactory.buildUDF(name, argNames, argTypes, returnType, body, isDeterministic); - default: return new ScriptBasedUDF(name, argNames, argTypes, returnType, language, body, isDeterministic); + case "java": return JavaSourceUDFFactory.buildUDF(name, argNames, argTypes, returnType, body); + default: return new ScriptBasedUDF(name, argNames, argTypes, returnType, language, body); } } @@ -116,7 +111,7 @@ public abstract class UDFunction extends AbstractFunction implements ScalarFunct String body, final InvalidRequestException reason) { - return new UDFunction(name, argNames, argTypes, returnType, language, body, true) + return new UDFunction(name, argNames, argTypes, returnType, language, body) { public ByteBuffer execute(int protocolVersion, List<ByteBuffer> parameters) throws InvalidRequestException { @@ -134,11 +129,6 @@ public abstract class UDFunction extends AbstractFunction implements ScalarFunct return false; } - public boolean isPure() - { - return isDeterministic; - } - public boolean isNative() { return false; @@ -149,11 +139,6 @@ public abstract class UDFunction extends AbstractFunction implements ScalarFunct return argNames; } - public boolean isDeterministic() - { - return isDeterministic; - } - public String body() { return body; @@ -201,14 +186,13 @@ public abstract class UDFunction extends AbstractFunction implements ScalarFunct && Functions.typeEquals(argTypes, that.argTypes) && Functions.typeEquals(returnType, that.returnType) && Objects.equal(language, that.language) - && Objects.equal(body, that.body) - && Objects.equal(isDeterministic, that.isDeterministic); + && Objects.equal(body, that.body); } @Override public int hashCode() { - return Objects.hashCode(name, argNames, argTypes, returnType, language, body, isDeterministic); + return Objects.hashCode(name, argNames, argTypes, returnType, language, body); } public void userTypeUpdated(String ksName, String typeName) http://git-wip-us.apache.org/repos/asf/cassandra/blob/b2abcb7f/src/java/org/apache/cassandra/cql3/functions/UuidFcts.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/cql3/functions/UuidFcts.java b/src/java/org/apache/cassandra/cql3/functions/UuidFcts.java index afb5aae..0aa3ac4 100644 --- a/src/java/org/apache/cassandra/cql3/functions/UuidFcts.java +++ b/src/java/org/apache/cassandra/cql3/functions/UuidFcts.java @@ -32,11 +32,5 @@ public abstract class UuidFcts { return UUIDSerializer.instance.serialize(UUID.randomUUID()); } - - @Override - public boolean isPure() - { - return false; - } }; } http://git-wip-us.apache.org/repos/asf/cassandra/blob/b2abcb7f/src/java/org/apache/cassandra/cql3/statements/CreateFunctionStatement.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/cql3/statements/CreateFunctionStatement.java b/src/java/org/apache/cassandra/cql3/statements/CreateFunctionStatement.java index 4e1e03a..faab043 100644 --- a/src/java/org/apache/cassandra/cql3/statements/CreateFunctionStatement.java +++ b/src/java/org/apache/cassandra/cql3/statements/CreateFunctionStatement.java @@ -45,7 +45,6 @@ public final class CreateFunctionStatement extends SchemaAlteringStatement private FunctionName functionName; private final String language; private final String body; - private final boolean deterministic; private final List<ColumnIdentifier> argNames; private final List<CQL3Type.Raw> argRawTypes; @@ -59,7 +58,6 @@ public final class CreateFunctionStatement extends SchemaAlteringStatement public CreateFunctionStatement(FunctionName functionName, String language, String body, - boolean deterministic, List<ColumnIdentifier> argNames, List<CQL3Type.Raw> argRawTypes, CQL3Type.Raw rawReturnType, @@ -69,7 +67,6 @@ public final class CreateFunctionStatement extends SchemaAlteringStatement this.functionName = functionName; this.language = language; this.body = body; - this.deterministic = deterministic; this.argNames = argNames; this.argRawTypes = argRawTypes; this.rawReturnType = rawReturnType; @@ -161,7 +158,7 @@ public final class CreateFunctionStatement extends SchemaAlteringStatement functionName, returnType.asCQL3Type(), old.returnType().asCQL3Type())); } - this.udFunction = UDFunction.create(functionName, argNames, argTypes, returnType, language, body, deterministic); + this.udFunction = UDFunction.create(functionName, argNames, argTypes, returnType, language, body); this.replaced = old != null; MigrationManager.announceNewFunction(udFunction, isLocalOnly); http://git-wip-us.apache.org/repos/asf/cassandra/blob/b2abcb7f/src/java/org/apache/cassandra/schema/LegacySchemaTables.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/schema/LegacySchemaTables.java b/src/java/org/apache/cassandra/schema/LegacySchemaTables.java index 51040a1..4eb800b 100644 --- a/src/java/org/apache/cassandra/schema/LegacySchemaTables.java +++ b/src/java/org/apache/cassandra/schema/LegacySchemaTables.java @@ -160,7 +160,6 @@ public class LegacySchemaTables + "argument_names list<text>," + "argument_types list<text>," + "body text," - + "is_deterministic boolean," + "language text," + "return_type text," + "PRIMARY KEY ((keyspace_name), function_name, signature))"); @@ -1284,7 +1283,6 @@ public class LegacySchemaTables } adder.add("body", function.body()); - adder.add("is_deterministic", function.isDeterministic()); adder.add("language", function.language()); adder.add("return_type", function.returnType().toString()); } @@ -1333,13 +1331,12 @@ public class LegacySchemaTables AbstractType<?> returnType = parseType(row.getString("return_type")); - boolean isDeterministic = row.getBoolean("is_deterministic"); String language = row.getString("language"); String body = row.getString("body"); try { - return UDFunction.create(name, argNames, argTypes, returnType, language, body, isDeterministic); + return UDFunction.create(name, argNames, argTypes, returnType, language, body); } catch (InvalidRequestException e) { http://git-wip-us.apache.org/repos/asf/cassandra/blob/b2abcb7f/test/unit/org/apache/cassandra/cql3/UFAuthTest.java ---------------------------------------------------------------------- diff --git a/test/unit/org/apache/cassandra/cql3/UFAuthTest.java b/test/unit/org/apache/cassandra/cql3/UFAuthTest.java index 3f0768e..1d63d29 100644 --- a/test/unit/org/apache/cassandra/cql3/UFAuthTest.java +++ b/test/unit/org/apache/cassandra/cql3/UFAuthTest.java @@ -78,9 +78,9 @@ public class UFAuthTest extends CQLTester } @Test - public void nonDeterministicFunctionInSelection() throws Throwable + public void functionInSelection() throws Throwable { - String functionName = createSimpleFunction(false); + String functionName = createSimpleFunction(); String cql = String.format("SELECT k, %s FROM %s WHERE k = 1;", functionCall(functionName), KEYSPACE + "." + currentTable()); @@ -88,29 +88,9 @@ public class UFAuthTest extends CQLTester } @Test - public void deterministicFunctionInSelection() throws Throwable + public void functionInSelectPKRestriction() throws Throwable { - String functionName = createSimpleFunction(true); - String cql = String.format("SELECT k, %s FROM %s WHERE k = 1;", - functionCall(functionName), - KEYSPACE + "." + currentTable()); - assertPermissionsOnFunction(cql, functionName); - } - - @Test - public void nonDeterministicFunctionInSelectPKRestriction() throws Throwable - { - String functionName = createSimpleFunction(false); - String cql = String.format("SELECT * FROM %s WHERE k = %s", - KEYSPACE + "." + currentTable(), - functionCall(functionName)); - assertPermissionsOnFunction(cql, functionName); - } - - @Test - public void deterministicFunctionInSelectPKRestriction() throws Throwable - { - String functionName = createSimpleFunction(true); + String functionName = createSimpleFunction(); String cql = String.format("SELECT * FROM %s WHERE k = %s", KEYSPACE + "." + currentTable(), functionCall(functionName)); @@ -118,19 +98,9 @@ public class UFAuthTest extends CQLTester } @Test - public void nonDeterministicFunctionInSelectClusteringRestriction() throws Throwable - { - String functionName = createSimpleFunction(false); - String cql = String.format("SELECT * FROM %s WHERE k = 0 AND v1 = %s", - KEYSPACE + "." + currentTable(), - functionCall(functionName)); - assertPermissionsOnFunction(cql, functionName); - } - - @Test - public void deterministicFunctionInSelectClusteringRestriction() throws Throwable + public void functionInSelectClusteringRestriction() throws Throwable { - String functionName = createSimpleFunction(true); + String functionName = createSimpleFunction(); String cql = String.format("SELECT * FROM %s WHERE k = 0 AND v1 = %s", KEYSPACE + "." + currentTable(), functionCall(functionName)); @@ -138,20 +108,9 @@ public class UFAuthTest extends CQLTester } @Test - public void nonDeterministicFunctionInSelectInRestriction() throws Throwable - { - String functionName = createSimpleFunction(false); - String cql = String.format("SELECT * FROM %s WHERE k IN (%s, %s)", - KEYSPACE + "." + currentTable(), - functionCall(functionName), - functionCall(functionName)); - assertPermissionsOnFunction(cql, functionName); - } - - @Test - public void deterministicFunctionInSelectInRestriction() throws Throwable + public void functionInSelectInRestriction() throws Throwable { - String functionName = createSimpleFunction(true); + String functionName = createSimpleFunction(); String cql = String.format("SELECT * FROM %s WHERE k IN (%s, %s)", KEYSPACE + "." + currentTable(), functionCall(functionName), @@ -160,10 +119,10 @@ public class UFAuthTest extends CQLTester } @Test - public void nonDeterministicFunctionInSelectMultiColumnInRestriction() throws Throwable + public void functionInSelectMultiColumnInRestriction() throws Throwable { setupTable("CREATE TABLE %s (k int, v1 int, v2 int, v3 int, PRIMARY KEY (k, v1, v2))"); - String functionName = createSimpleFunction(false); + String functionName = createSimpleFunction(); String cql = String.format("SELECT * FROM %s WHERE k=0 AND (v1, v2) IN ((%s, %s))", KEYSPACE + "." + currentTable(), functionCall(functionName), @@ -172,35 +131,10 @@ public class UFAuthTest extends CQLTester } @Test - public void deterministicFunctionInSelectMultiColumnInRestriction() throws Throwable - { - setupTable("CREATE TABLE %s (k int, v1 int, v2 int, v3 int, PRIMARY KEY (k, v1, v2))"); - String functionName = createSimpleFunction(true); - String cql = String.format("SELECT * FROM %s WHERE k=0 AND (v1, v2) IN ((%s, %s))", - KEYSPACE + "." + currentTable(), - functionCall(functionName), - functionCall(functionName)); - assertPermissionsOnFunction(cql, functionName); - } - - - @Test - public void nonDeterministicFunctionInSelectMultiColumnEQRestriction() throws Throwable - { - setupTable("CREATE TABLE %s (k int, v1 int, v2 int, v3 int, PRIMARY KEY (k, v1, v2))"); - String functionName = createSimpleFunction(false); - String cql = String.format("SELECT * FROM %s WHERE k=0 AND (v1, v2) = (%s, %s)", - KEYSPACE + "." + currentTable(), - functionCall(functionName), - functionCall(functionName)); - assertPermissionsOnFunction(cql, functionName); - } - - @Test - public void deterministicFunctionInSelectMultiColumnEQRestriction() throws Throwable + public void functionInSelectMultiColumnEQRestriction() throws Throwable { setupTable("CREATE TABLE %s (k int, v1 int, v2 int, v3 int, PRIMARY KEY (k, v1, v2))"); - String functionName = createSimpleFunction(true); + String functionName = createSimpleFunction(); String cql = String.format("SELECT * FROM %s WHERE k=0 AND (v1, v2) = (%s, %s)", KEYSPACE + "." + currentTable(), functionCall(functionName), @@ -209,22 +143,10 @@ public class UFAuthTest extends CQLTester } @Test - public void nonDeterministicFunctionInSelectMultiColumnSliceRestriction() throws Throwable - { - setupTable("CREATE TABLE %s (k int, v1 int, v2 int, v3 int, PRIMARY KEY (k, v1, v2))"); - String functionName = createSimpleFunction(false); - String cql = String.format("SELECT * FROM %s WHERE k=0 AND (v1, v2) > (%s, %s)", - KEYSPACE + "." + currentTable(), - functionCall(functionName), - functionCall(functionName)); - assertPermissionsOnFunction(cql, functionName); - } - - @Test - public void deterministicFunctionInSelectMultiColumnSliceRestriction() throws Throwable + public void functionInSelectMultiColumnSliceRestriction() throws Throwable { setupTable("CREATE TABLE %s (k int, v1 int, v2 int, v3 int, PRIMARY KEY (k, v1, v2))"); - String functionName = createSimpleFunction(true); + String functionName = createSimpleFunction(); String cql = String.format("SELECT * FROM %s WHERE k=0 AND (v1, v2) < (%s, %s)", KEYSPACE + "." + currentTable(), functionCall(functionName), @@ -233,19 +155,9 @@ public class UFAuthTest extends CQLTester } @Test - public void nonDeterministicFunctionInSelectTokenEQRestriction() throws Throwable - { - String functionName = createSimpleFunction(false); - String cql = String.format("SELECT * FROM %s WHERE token(k) = token(%s)", - KEYSPACE + "." + currentTable(), - functionCall(functionName)); - assertPermissionsOnFunction(cql, functionName); - } - - @Test - public void deterministicFunctionInSelectTokenEQRestriction() throws Throwable + public void functionInSelectTokenEQRestriction() throws Throwable { - String functionName = createSimpleFunction(true); + String functionName = createSimpleFunction(); String cql = String.format("SELECT * FROM %s WHERE token(k) = token(%s)", KEYSPACE + "." + currentTable(), functionCall(functionName)); @@ -253,38 +165,19 @@ public class UFAuthTest extends CQLTester } @Test - public void nonDeterministicFunctionInSelectTokenSliceRestriction() throws Throwable - { - String functionName = createSimpleFunction(false); - String cql = String.format("SELECT * FROM %s WHERE token(k) > token(%s)", - KEYSPACE + "." + currentTable(), - functionCall(functionName)); - assertPermissionsOnFunction(cql, functionName); - } - - @Test - public void deterministicFunctionInSelectTokenSliceRestriction() throws Throwable + public void functionInSelectTokenSliceRestriction() throws Throwable { - String functionName = createSimpleFunction(true); + String functionName = createSimpleFunction(); String cql = String.format("SELECT * FROM %s WHERE token(k) < token(%s)", KEYSPACE + "." + currentTable(), functionCall(functionName)); assertPermissionsOnFunction(cql, functionName); } - @Test - public void nonDeterministicFunctionInPKForInsert() throws Throwable - { - String functionName = createSimpleFunction(false); - String cql = String.format("INSERT INTO %s (k, v1 ,v2) VALUES (%s, 0, 0)", - KEYSPACE + "." + currentTable(), - functionCall(functionName)); - assertPermissionsOnFunction(cql, functionName); - } @Test - public void deterministicFunctionInPKForInsert() throws Throwable + public void functionInPKForInsert() throws Throwable { - String functionName = createSimpleFunction(true); + String functionName = createSimpleFunction(); String cql = String.format("INSERT INTO %s (k, v1, v2) VALUES (%s, 0, 0)", KEYSPACE + "." + currentTable(), functionCall(functionName)); @@ -292,19 +185,9 @@ public class UFAuthTest extends CQLTester } @Test - public void nonDeterministicFunctionInClusteringValuesForInsert() throws Throwable - { - String functionName = createSimpleFunction(false); - String cql = String.format("INSERT INTO %s (k, v1, v2) VALUES (0, %s, 0)", - KEYSPACE + "." + currentTable(), - functionCall(functionName)); - assertPermissionsOnFunction(cql, functionName); - } - - @Test - public void deterministicFunctionInClusteringValuesForInsert() throws Throwable + public void functionInClusteringValuesForInsert() throws Throwable { - String functionName = createSimpleFunction(true); + String functionName = createSimpleFunction(); String cql = String.format("INSERT INTO %s (k, v1, v2) VALUES (0, %s, 0)", KEYSPACE + "." + currentTable(), functionCall(functionName)); @@ -312,19 +195,9 @@ public class UFAuthTest extends CQLTester } @Test - public void nonDeterministicFunctionInPKForDelete() throws Throwable - { - String functionName = createSimpleFunction(false); - String cql = String.format("DELETE FROM %s WHERE k = %s", - KEYSPACE + "." + currentTable(), - functionCall(functionName)); - assertPermissionsOnFunction(cql, functionName); - } - - @Test - public void deterministicFunctionInPKForDelete() throws Throwable + public void functionInPKForDelete() throws Throwable { - String functionName = createSimpleFunction(true); + String functionName = createSimpleFunction(); String cql = String.format("DELETE FROM %s WHERE k = %s", KEYSPACE + "." + currentTable(), functionCall(functionName)); @@ -332,20 +205,9 @@ public class UFAuthTest extends CQLTester } @Test - public void nonDeterministicFunctionInClusteringValuesForDelete() throws Throwable + public void functionInClusteringValuesForDelete() throws Throwable { - String functionName = createSimpleFunction(false); - String cql = String.format("DELETE FROM %s WHERE k = 0 AND v1 = %s", - KEYSPACE + "." + currentTable(), - functionCall(functionName)); - assertPermissionsOnFunction(cql, functionName); - } - - @Test - - public void deterministicFunctionInClusteringValuesForDelete() throws Throwable - { - String functionName = createSimpleFunction(true); + String functionName = createSimpleFunction(); String cql = String.format("DELETE FROM %s WHERE k = 0 AND v1 = %s", KEYSPACE + "." + currentTable(), functionCall(functionName)); @@ -359,7 +221,7 @@ public class UFAuthTest extends CQLTester List<String> functions = new ArrayList<>(); for (int i = 0; i < 3; i++) { - String functionName = createSimpleFunction(false); + String functionName = createSimpleFunction(); ModificationStatement stmt = (ModificationStatement) getStatement(String.format("INSERT INTO %s (k, v1, v2) " + "VALUES (%s, %s, %s)", @@ -382,21 +244,9 @@ public class UFAuthTest extends CQLTester } @Test - public void testNestedNonDeterministicFunctions() throws Throwable - { - String innerFunctionName = createSimpleFunction(false); - String outerFunctionName = createFunction("int", - "CREATE NON DETERMINISTIC FUNCTION %s(input int) " + - " RETURNS int" + - " LANGUAGE java" + - " AS 'return Integer.valueOf(0);'"); - assertPermissionsOnNestedFunctions(innerFunctionName, outerFunctionName); - } - - @Test - public void testNestedDeterministicFunctions() throws Throwable + public void testNestedFunctions() throws Throwable { - String innerFunctionName = createSimpleFunction(true); + String innerFunctionName = createSimpleFunction(); String outerFunctionName = createFunction("int", "CREATE FUNCTION %s(input int) " + " RETURNS int" + @@ -406,41 +256,10 @@ public class UFAuthTest extends CQLTester } @Test - public void testNestedMixedFunctions() throws Throwable - { - String innerFunctionName = createSimpleFunction(true); - String outerFunctionName = createFunction("int", - "CREATE NON DETERMINISTIC FUNCTION %s(input int) " + - " RETURNS int" + - " LANGUAGE java" + - " AS 'return Integer.valueOf(0);'"); - assertPermissionsOnNestedFunctions(innerFunctionName, outerFunctionName); - - innerFunctionName = createSimpleFunction(false); - outerFunctionName = createFunction("int", - "CREATE FUNCTION %s(input int) " + - " RETURNS int" + - " LANGUAGE java" + - " AS 'return Integer.valueOf(0);'"); - assertPermissionsOnNestedFunctions(innerFunctionName, outerFunctionName); - } - - @Test - public void nonDeterministicFunctionInStaticColumnRestrictionInSelect() throws Throwable - { - setupTable("CREATE TABLE %s (k int, s int STATIC, v1 int, v2 int, PRIMARY KEY(k, v1))"); - String functionName = createSimpleFunction(false); - String cql = String.format("SELECT k FROM %s WHERE k = 0 AND s = %s", - KEYSPACE + "." + currentTable(), - functionCall(functionName)); - assertPermissionsOnFunction(cql, functionName); - } - - @Test - public void deterministicFunctionInStaticColumnRestrictionInSelect() throws Throwable + public void functionInStaticColumnRestrictionInSelect() throws Throwable { setupTable("CREATE TABLE %s (k int, s int STATIC, v1 int, v2 int, PRIMARY KEY(k, v1))"); - String functionName = createSimpleFunction(true); + String functionName = createSimpleFunction(); String cql = String.format("SELECT k FROM %s WHERE k = 0 AND s = %s", KEYSPACE + "." + currentTable(), functionCall(functionName)); @@ -448,41 +267,19 @@ public class UFAuthTest extends CQLTester } @Test - public void nonDeterministicFunctionInRegularCondition() throws Throwable - { - String functionName = createSimpleFunction(false); - String cql = String.format("UPDATE %s SET v2 = 0 WHERE k = 0 AND v1 = 0 IF v2 = %s", - KEYSPACE + "." + currentTable(), - functionCall(functionName)); - assertPermissionsOnFunction(cql, functionName); - } - - @Test - public void deterministicFunctionInRegularCondition() throws Throwable + public void functionInRegularCondition() throws Throwable { - String functionName = createSimpleFunction(true); + String functionName = createSimpleFunction(); String cql = String.format("UPDATE %s SET v2 = 0 WHERE k = 0 AND v1 = 0 IF v2 = %s", KEYSPACE + "." + currentTable(), functionCall(functionName)); assertPermissionsOnFunction(cql, functionName); } - - @Test - public void nonDeterministicFunctionInStaticColumnCondition() throws Throwable - { - setupTable("CREATE TABLE %s (k int, s int STATIC, v1 int, v2 int, PRIMARY KEY(k, v1))"); - String functionName = createSimpleFunction(false); - String cql = String.format("UPDATE %s SET v2 = 0 WHERE k = 0 AND v1 = 0 IF s = %s", - KEYSPACE + "." + currentTable(), - functionCall(functionName)); - assertPermissionsOnFunction(cql, functionName); - } - @Test - public void deterministicFunctionInStaticColumnCondition() throws Throwable + public void functionInStaticColumnCondition() throws Throwable { setupTable("CREATE TABLE %s (k int, s int STATIC, v1 int, v2 int, PRIMARY KEY(k, v1))"); - String functionName = createSimpleFunction(true); + String functionName = createSimpleFunction(); String cql = String.format("UPDATE %s SET v2 = 0 WHERE k = 0 AND v1 = 0 IF s = %s", KEYSPACE + "." + currentTable(), functionCall(functionName)); @@ -490,22 +287,10 @@ public class UFAuthTest extends CQLTester } @Test - public void nonDeterministicFunctionInCollectionLiteralCondition() throws Throwable - { - setupTable("CREATE TABLE %s (k int, v1 int, m_val map<int, int>, PRIMARY KEY(k))"); - String functionName = createSimpleFunction(false); - String cql = String.format("UPDATE %s SET v1 = 0 WHERE k = 0 IF m_val = {%s : %s}", - KEYSPACE + "." + currentTable(), - functionCall(functionName), - functionCall(functionName)); - assertPermissionsOnFunction(cql, functionName); - } - - @Test - public void deterministicFunctionInCollectionLiteralCondition() throws Throwable + public void functionInCollectionLiteralCondition() throws Throwable { setupTable("CREATE TABLE %s (k int, v1 int, m_val map<int, int>, PRIMARY KEY(k))"); - String functionName = createSimpleFunction(true); + String functionName = createSimpleFunction(); String cql = String.format("UPDATE %s SET v1 = 0 WHERE k = 0 IF m_val = {%s : %s}", KEYSPACE + "." + currentTable(), functionCall(functionName), @@ -514,22 +299,10 @@ public class UFAuthTest extends CQLTester } @Test - public void nonDeterministicFunctionInCollectionElementCondition() throws Throwable - { - setupTable("CREATE TABLE %s (k int, v1 int, m_val map<int, int>, PRIMARY KEY(k))"); - String functionName = createSimpleFunction(false); - String cql = String.format("UPDATE %s SET v1 = 0 WHERE k = 0 IF m_val[%s] = %s", - KEYSPACE + "." + currentTable(), - functionCall(functionName), - functionCall(functionName)); - assertPermissionsOnFunction(cql, functionName); - } - - @Test - public void deterministicFunctionInCollectionElementCondition() throws Throwable + public void functionInCollectionElementCondition() throws Throwable { setupTable("CREATE TABLE %s (k int, v1 int, m_val map<int, int>, PRIMARY KEY(k))"); - String functionName = createSimpleFunction(true); + String functionName = createSimpleFunction(); String cql = String.format("UPDATE %s SET v1 = 0 WHERE k = 0 IF m_val[%s] = %s", KEYSPACE + "." + currentTable(), functionCall(functionName), @@ -546,7 +319,7 @@ public class UFAuthTest extends CQLTester getStatement(cql).checkAccess(clientState); // with non-terminal arguments, so evaluated at execution - String functionName = createSimpleFunction(false); + String functionName = createSimpleFunction(); grantExecuteOnFunction(functionName); cql = String.format("UPDATE %s SET v2 = 0 WHERE k = blobasint(intasblob(%s))", KEYSPACE + "." + currentTable(), @@ -612,10 +385,10 @@ public class UFAuthTest extends CQLTester } @Test - public void nonDeterministicFunctionWrappingAggregate() throws Throwable + public void functionWrappingAggregate() throws Throwable { String outerFunc = createFunction("int", - "CREATE NON DETERMINISTIC FUNCTION %s(input int) " + + "CREATE FUNCTION %s(input int) " + "RETURNS int " + "LANGUAGE java " + "AS 'return input;'"); @@ -643,10 +416,10 @@ public class UFAuthTest extends CQLTester } @Test - public void aggregateWrappingNonDeterministicFunction() throws Throwable + public void aggregateWrappingFunction() throws Throwable { String innerFunc = createFunction("int", - "CREATE NON DETERMINISTIC FUNCTION %s(input int) " + + "CREATE FUNCTION %s(input int) " + "RETURNS int " + "LANGUAGE java " + "AS 'return input;'"); @@ -809,10 +582,10 @@ public class UFAuthTest extends CQLTester "AS 'return a;'"); } - private String createSimpleFunction(boolean deterministic) throws Throwable + private String createSimpleFunction() throws Throwable { return createFunction("", - "CREATE " + (deterministic ? "" : " NON ") + " DETERMINISTIC FUNCTION %s() " + + "CREATE FUNCTION %s() " + " RETURNS int " + " LANGUAGE java " + " AS 'return Integer.valueOf(0);'");
