You are viewing a plain text version of this content. The canonical link for it is here.
Posted to pr@cassandra.apache.org by GitBox <gi...@apache.org> on 2022/12/02 12:23:00 UTC
[GitHub] [cassandra] adelapena opened a new pull request, #2037: CASSANDRA-18085 trunk: Add support for singletons on CQL collection functions
adelapena opened a new pull request, #2037:
URL: https://github.com/apache/cassandra/pull/2037
Thanks for sending a pull request! Here are some tips if you're new here:
* Ensure you have added or run the [appropriate tests](https://cassandra.apache.org/_/development/testing.html) for your PR.
* Be sure to keep the PR description updated to reflect all changes.
* Write your PR title to summarize what this PR proposes.
* If possible, provide a concise example to reproduce the issue for a faster review.
* Read our [contributor guidelines](https://cassandra.apache.org/_/development/index.html)
* If you're making a documentation change, see our [guide to documentation contribution](https://cassandra.apache.org/_/development/documentation.html)
Commit messages should follow the following format:
```
<One sentence description, usually Jira title or CHANGES.txt summary>
<Optional lengthier description (context on patch)>
patch by <Authors>; reviewed by <Reviewers> for CASSANDRA-#####
Co-authored-by: Name1 <email1>
Co-authored-by: Name2 <email2>
```
The [Cassandra Jira](https://issues.apache.org/jira/projects/CASSANDRA/issues/)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org
[GitHub] [cassandra] adelapena commented on a diff in pull request #2037: CASSANDRA-18085 trunk: Add support for singletons on CQL collection functions
Posted by GitBox <gi...@apache.org>.
adelapena commented on code in PR #2037:
URL: https://github.com/apache/cassandra/pull/2037#discussion_r1039520468
##########
src/java/org/apache/cassandra/cql3/functions/CollectionFcts.java:
##########
@@ -169,6 +208,22 @@ public ByteBuffer execute(ProtocolVersion protocolVersion, List<ByteBuffer> para
};
}
+ private static NativeScalarFunction makeCollectionCountFunction(String name, AbstractType<?> inputType)
+ {
+ return new NativeScalarFunction(name, Int32Type.instance, inputType)
+ {
+ @Override
+ public ByteBuffer execute(ProtocolVersion protocolVersion, List<ByteBuffer> parameters)
+ {
+ ByteBuffer value = parameters.get(0);
+ if (value == null)
+ return null;
Review Comment:
Yes, it does. CQL functions applied to `null` generally return `null`, as in SQL. This function is only used for not-collection functions, where `collection_count` is either `null` or `1`. Right below there is the function overload for collections, that also returns `null` for `null` collections, and the collection size for not-null collections.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org
[GitHub] [cassandra] yifan-c commented on a diff in pull request #2037: CASSANDRA-18085 trunk: Add support for singletons on CQL collection functions
Posted by GitBox <gi...@apache.org>.
yifan-c commented on code in PR #2037:
URL: https://github.com/apache/cassandra/pull/2037#discussion_r1038382390
##########
doc/modules/cassandra/pages/cql/functions.adoc:
##########
@@ -270,15 +270,15 @@ A number of functions are provided to operate on collection columns.
| `map_values` | `map` | Gets the values of the `map` argument, returned as a `list`.
-| `collection_count` | `map`, `set` or `list` | Gets the number of elements in the collection argument.
+| `collection_count` | Any value | Gets the number of elements in a `map`, `set` or `list` argument. For other type of argument it returns `1`.
-| `collection_min` | `set` or `list` | Gets the minimum element in the collection argument.
+| `collection_min` | Any value | Gets the minimum element in a `set` or `list` argument. Any other type of not-collection argument is returned unmodified.
-| `collection_max` | `set` or `list` | Gets the maximum element in the collection argument.
+| `collection_max` | Any value | Gets the maximum element in a `set` or `list` argument. Any other type of not-collection argument is returned unmodified.
-| `collection_sum` | numeric `set` or `list` | Computes the sum of the elements in the collection argument. The returned value is of the same type as the input collection elements, so there is a risk of overflowing the data type if the sum of the values exceeds the maximum value that the type can represent.
+| `collection_sum` | Number or numeric `set` or `list` | Computes the sum of the elements in a `set` or `list` argument. Any other numeric not-collection argument is returned unmodified. The returned value is of the same type as the input collection elements, so there is a risk of overflowing the data type if the sum of the values exceeds the maximum value that the type can represent.
Review Comment:
nit: How about "Number or numeric `set` or numeric `list`"? The current phrase has an ambiguity that the function can take a general list.
##########
src/java/org/apache/cassandra/cql3/functions/FunctionParameter.java:
##########
@@ -115,66 +115,11 @@ public String toString()
};
}
- /**
- * @return a function parameter definition that accepts values of type {@link CollectionType}, independently of the
- * types of its elements.
- */
- public static FunctionParameter anyCollection()
- {
- return new FunctionParameter()
- {
- @Override
- public void validateType(FunctionName name, AssignmentTestable arg, AbstractType<?> argType)
- {
- if (!argType.isCollection())
- throw new InvalidRequestException(format("Function %s requires a collection argument, " +
- "but found argument %s of type %s",
- name, arg, argType.asCQL3Type()));
- }
-
- @Override
- public String toString()
- {
- return "collection";
- }
- };
- }
-
- /**
- * @return a function parameter definition that accepts values of type {@link SetType} or {@link ListType}.
- */
- public static FunctionParameter setOrList()
- {
- return new FunctionParameter()
- {
- @Override
- public void validateType(FunctionName name, AssignmentTestable arg, AbstractType<?> argType)
- {
- if (argType.isCollection())
- {
- CollectionType.Kind kind = ((CollectionType<?>) argType).kind;
- if (kind == CollectionType.Kind.SET || kind == CollectionType.Kind.LIST)
- return;
- }
-
- throw new InvalidRequestException(format("Function %s requires a set or list argument, " +
- "but found argument %s of type %s",
- name, arg, argType.asCQL3Type()));
- }
-
- @Override
- public String toString()
- {
- return "numeric_set_or_list";
- }
- };
- }
-
/**
* @return a function parameter definition that accepts values of type {@link SetType} or {@link ListType},
* provided that its elements are numeric.
Review Comment:
nit: need to update the java doc since it now accepts number type too.
##########
src/java/org/apache/cassandra/cql3/functions/CollectionFcts.java:
##########
@@ -169,6 +208,22 @@ public ByteBuffer execute(ProtocolVersion protocolVersion, List<ByteBuffer> para
};
}
+ private static NativeScalarFunction makeCollectionCountFunction(String name, AbstractType<?> inputType)
+ {
+ return new NativeScalarFunction(name, Int32Type.instance, inputType)
+ {
+ @Override
+ public ByteBuffer execute(ProtocolVersion protocolVersion, List<ByteBuffer> parameters)
+ {
+ ByteBuffer value = parameters.get(0);
+ if (value == null)
+ return null;
Review Comment:
Does it mean if counting `null`, it returns `null`, otherwise returns 1?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org
[GitHub] [cassandra] adelapena commented on a diff in pull request #2037: CASSANDRA-18085 trunk: Add support for singletons on CQL collection functions
Posted by GitBox <gi...@apache.org>.
adelapena commented on code in PR #2037:
URL: https://github.com/apache/cassandra/pull/2037#discussion_r1039513625
##########
src/java/org/apache/cassandra/cql3/functions/FunctionParameter.java:
##########
@@ -115,66 +115,11 @@ public String toString()
};
}
- /**
- * @return a function parameter definition that accepts values of type {@link CollectionType}, independently of the
- * types of its elements.
- */
- public static FunctionParameter anyCollection()
- {
- return new FunctionParameter()
- {
- @Override
- public void validateType(FunctionName name, AssignmentTestable arg, AbstractType<?> argType)
- {
- if (!argType.isCollection())
- throw new InvalidRequestException(format("Function %s requires a collection argument, " +
- "but found argument %s of type %s",
- name, arg, argType.asCQL3Type()));
- }
-
- @Override
- public String toString()
- {
- return "collection";
- }
- };
- }
-
- /**
- * @return a function parameter definition that accepts values of type {@link SetType} or {@link ListType}.
- */
- public static FunctionParameter setOrList()
- {
- return new FunctionParameter()
- {
- @Override
- public void validateType(FunctionName name, AssignmentTestable arg, AbstractType<?> argType)
- {
- if (argType.isCollection())
- {
- CollectionType.Kind kind = ((CollectionType<?>) argType).kind;
- if (kind == CollectionType.Kind.SET || kind == CollectionType.Kind.LIST)
- return;
- }
-
- throw new InvalidRequestException(format("Function %s requires a set or list argument, " +
- "but found argument %s of type %s",
- name, arg, argType.asCQL3Type()));
- }
-
- @Override
- public String toString()
- {
- return "numeric_set_or_list";
- }
- };
- }
-
/**
* @return a function parameter definition that accepts values of type {@link SetType} or {@link ListType},
* provided that its elements are numeric.
Review Comment:
Right, updated.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org
[GitHub] [cassandra] adelapena commented on a diff in pull request #2037: CASSANDRA-18085 trunk: Add support for singletons on CQL collection functions
Posted by GitBox <gi...@apache.org>.
adelapena commented on code in PR #2037:
URL: https://github.com/apache/cassandra/pull/2037#discussion_r1039513857
##########
doc/modules/cassandra/pages/cql/functions.adoc:
##########
@@ -270,15 +270,15 @@ A number of functions are provided to operate on collection columns.
| `map_values` | `map` | Gets the values of the `map` argument, returned as a `list`.
-| `collection_count` | `map`, `set` or `list` | Gets the number of elements in the collection argument.
+| `collection_count` | Any value | Gets the number of elements in a `map`, `set` or `list` argument. For other type of argument it returns `1`.
-| `collection_min` | `set` or `list` | Gets the minimum element in the collection argument.
+| `collection_min` | Any value | Gets the minimum element in a `set` or `list` argument. Any other type of not-collection argument is returned unmodified.
-| `collection_max` | `set` or `list` | Gets the maximum element in the collection argument.
+| `collection_max` | Any value | Gets the maximum element in a `set` or `list` argument. Any other type of not-collection argument is returned unmodified.
-| `collection_sum` | numeric `set` or `list` | Computes the sum of the elements in the collection argument. The returned value is of the same type as the input collection elements, so there is a risk of overflowing the data type if the sum of the values exceeds the maximum value that the type can represent.
+| `collection_sum` | Number or numeric `set` or `list` | Computes the sum of the elements in a `set` or `list` argument. Any other numeric not-collection argument is returned unmodified. The returned value is of the same type as the input collection elements, so there is a risk of overflowing the data type if the sum of the values exceeds the maximum value that the type can represent.
Review Comment:
Makes sense, done.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org