You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cassandra.apache.org by sl...@apache.org on 2013/06/05 20:05:57 UTC
git commit: Evaluate now() function at execution time
Updated Branches:
refs/heads/cassandra-1.2 ca3c75ecb -> b853630e3
Evaluate now() function at execution time
patch by slebresne; reviewed by iamaleksey for CASSANDRA-5616
Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo
Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/b853630e
Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/b853630e
Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/b853630e
Branch: refs/heads/cassandra-1.2
Commit: b853630e305bae63e07a7766a179319f185e724d
Parents: ca3c75e
Author: Sylvain Lebresne <sy...@datastax.com>
Authored: Wed Jun 5 20:05:09 2013 +0200
Committer: Sylvain Lebresne <sy...@datastax.com>
Committed: Wed Jun 5 20:05:09 2013 +0200
----------------------------------------------------------------------
CHANGES.txt | 1 +
.../cassandra/cql3/functions/AbstractFunction.java | 6 ++++++
.../apache/cassandra/cql3/functions/Function.java | 3 +++
.../cassandra/cql3/functions/FunctionCall.java | 4 +++-
.../cassandra/cql3/functions/TimeuuidFcts.java | 6 ++++++
5 files changed, 19 insertions(+), 1 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cassandra/blob/b853630e/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index b569b4a..edbb94d 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -18,6 +18,7 @@
* Expose whether jna is enabled and memory is locked via JMX (CASSANDRA-5508)
* cqlsh: fix COPY FROM with ReversedType (CASSANDRA-5610)
* Allow creating CUSTOM indexes on collections (CASSANDRA-5615)
+ * Evaluate now() function at execution time (CASSANDRA-5616)
Merged from 1.1:
* Remove buggy thrift max message length option (CASSANDRA-5529)
* Fix NPE in Pig's widerow mode (CASSANDRA-5488)
http://git-wip-us.apache.org/repos/asf/cassandra/blob/b853630e/src/java/org/apache/cassandra/cql3/functions/AbstractFunction.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/cql3/functions/AbstractFunction.java b/src/java/org/apache/cassandra/cql3/functions/AbstractFunction.java
index ec5ebee..5dbfbf3 100644
--- a/src/java/org/apache/cassandra/cql3/functions/AbstractFunction.java
+++ b/src/java/org/apache/cassandra/cql3/functions/AbstractFunction.java
@@ -50,6 +50,12 @@ public abstract class AbstractFunction implements Function
return returnType;
}
+ // Most of our functions are pure, the other ones should override this
+ public boolean isPure()
+ {
+ return true;
+ }
+
/**
* Creates a trivial factory that always return the provided function.
*/
http://git-wip-us.apache.org/repos/asf/cassandra/blob/b853630e/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 bae5593..7adc7ca 100644
--- a/src/java/org/apache/cassandra/cql3/functions/Function.java
+++ b/src/java/org/apache/cassandra/cql3/functions/Function.java
@@ -31,6 +31,9 @@ public interface Function
public ByteBuffer execute(List<ByteBuffer> parameters) throws InvalidRequestException;
+ // Whether the function is a pure function (as in doesn't depend on, nor produce side effects).
+ public boolean isPure();
+
public interface Factory
{
// We allow the function to be parametered by the table it is part of because the
http://git-wip-us.apache.org/repos/asf/cassandra/blob/b853630e/src/java/org/apache/cassandra/cql3/functions/FunctionCall.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/cql3/functions/FunctionCall.java b/src/java/org/apache/cassandra/cql3/functions/FunctionCall.java
index 074e3ce..dcc3d8b 100644
--- a/src/java/org/apache/cassandra/cql3/functions/FunctionCall.java
+++ b/src/java/org/apache/cassandra/cql3/functions/FunctionCall.java
@@ -111,7 +111,9 @@ public class FunctionCall extends Term.NonTerminal
parameters.add(t);
}
- return allTerminal
+ // If all parameters are terminal and the function is pure, we can
+ // evaluate it now, otherwise we'd have to wait execution time
+ return allTerminal && fun.isPure()
? makeTerminal(fun, execute(fun, parameters))
: new FunctionCall(fun, parameters);
}
http://git-wip-us.apache.org/repos/asf/cassandra/blob/b853630e/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 fd60d51..e325e8f 100644
--- a/src/java/org/apache/cassandra/cql3/functions/TimeuuidFcts.java
+++ b/src/java/org/apache/cassandra/cql3/functions/TimeuuidFcts.java
@@ -35,6 +35,12 @@ public abstract class TimeuuidFcts
{
return ByteBuffer.wrap(UUIDGen.getTimeUUIDBytes());
}
+
+ @Override
+ public boolean isPure()
+ {
+ return false;
+ }
};
public static final Function minTimeuuidFct = new AbstractFunction("mintimeuuid", TimeUUIDType.instance, DateType.instance)