Repository: cassandra Updated Branches: refs/heads/cassandra-2.2 947edf1f1 -> 716b253a7
Fix mixing min, max, and count aggregates for blob type patch by Aleksey Yeschenko; reviewed by Robert Stupp for CASSANDRA-9622 Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/716b253a Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/716b253a Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/716b253a Branch: refs/heads/cassandra-2.2 Commit: 716b253a771d50c2365608cf7cbc992e3683feed Parents: 947edf1 Author: Aleksey Yeschenko <[email protected]> Authored: Fri Jun 19 14:29:22 2015 +0300 Committer: Aleksey Yeschenko <[email protected]> Committed: Fri Jun 19 17:55:20 2015 +0300 ---------------------------------------------------------------------- CHANGES.txt | 1 + .../cassandra/cql3/functions/Functions.java | 38 +++++++++++++++----- 2 files changed, 30 insertions(+), 9 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cassandra/blob/716b253a/CHANGES.txt ---------------------------------------------------------------------- diff --git a/CHANGES.txt b/CHANGES.txt index 56f0dc0..4886850 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,4 +1,5 @@ 2.2 + * Fix mixing min, max, and count aggregates for blob type (CASSANRA-9622) * Rename class for DATE type in Java driver (CASSANDRA-9563) * Duplicate compilation of UDFs on coordinator (CASSANDRA-9475) * Fix connection leak in CqlRecordWriter (CASSANDRA-9576) http://git-wip-us.apache.org/repos/asf/cassandra/blob/716b253a/src/java/org/apache/cassandra/cql3/functions/Functions.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/cql3/functions/Functions.java b/src/java/org/apache/cassandra/cql3/functions/Functions.java index d6a8ab0..018c35c 100644 --- a/src/java/org/apache/cassandra/cql3/functions/Functions.java +++ b/src/java/org/apache/cassandra/cql3/functions/Functions.java @@ -64,18 +64,25 @@ public abstract class Functions { // Note: because text and varchar ends up being synonymous, our automatic makeToBlobFunction doesn't work // for varchar, so we special case it below. We also skip blob for obvious reasons. - if (type == CQL3Type.Native.VARCHAR || type == CQL3Type.Native.BLOB) - continue; - - declare(BytesConversionFcts.makeToBlobFunction(type.getType())); - declare(BytesConversionFcts.makeFromBlobFunction(type.getType())); - - declare(AggregateFcts.makeCountFunction(type.getType())); - declare(AggregateFcts.makeMaxFunction(type.getType())); - declare(AggregateFcts.makeMinFunction(type.getType())); + if (type != CQL3Type.Native.VARCHAR && type != CQL3Type.Native.BLOB) + { + declare(BytesConversionFcts.makeToBlobFunction(type.getType())); + declare(BytesConversionFcts.makeFromBlobFunction(type.getType())); + } } declare(BytesConversionFcts.VarcharAsBlobFct); declare(BytesConversionFcts.BlobAsVarcharFact); + + for (CQL3Type type : CQL3Type.Native.values()) + { + // special case varchar to avoid duplicating functions for UTF8Type + if (type != CQL3Type.Native.VARCHAR) + { + declare(AggregateFcts.makeCountFunction(type.getType())); + declare(AggregateFcts.makeMaxFunction(type.getType())); + declare(AggregateFcts.makeMinFunction(type.getType())); + } + } declare(AggregateFcts.sumFunctionForInt32); declare(AggregateFcts.sumFunctionForLong); declare(AggregateFcts.sumFunctionForFloat); @@ -340,6 +347,19 @@ public abstract class Functions return all; } + /* + * We need to compare the CQL3 representation of the type because comparing + * the AbstractType will fail for example if a UDT has been changed. + * Reason is that UserType.equals() takes the field names and types into account. + * Example CQL sequence that would fail when comparing AbstractType: + * CREATE TYPE foo ... + * CREATE FUNCTION bar ( par foo ) RETURNS foo ... + * ALTER TYPE foo ADD ... + * or + * ALTER TYPE foo ALTER ... + * or + * ALTER TYPE foo RENAME ... + */ public static boolean typeEquals(AbstractType<?> t1, AbstractType<?> t2) { return t1.asCQL3Type().toString().equals(t2.asCQL3Type().toString());
