CountMatches / Array Layer
Count occurrences of a specific value in fixed-length arrays. Similar to Python's count() method or R's sum(x == value). Returns an integer column with the count of matches in each array.
Example transformation (arrays of length 3):
arrays | count_3 |
---|---|
[1, 3, 5] | 1 |
[3, 3, 3] | 3 |
[1, 2, 4] | 0 |
[null, 3, null] | 1 |
Common applications:
- Frequency analysis
- Duplicate detection
- Pattern matching
- Event counting
- Occurrence tracking
Note: Arrays must have the same fixed length across all rows. Type-sensitive comparison. Null values are ignored in counting unless array contains all nulls, then returns null.
Select
columnThe fixed-length array column to analyze. Supports various array types:
- Numeric: [1, 2, 3]
- String: [red, blue, green]
- Boolean: [true, false, true]
- Dates: [2024-01-01, 2024-01-01, 2024-02-01] All arrays must have the same length. Mixed types not supported.
Item
stringThe value to count. Must match array type. Examples:
- Numeric: 42
- String: blue
- Boolean: true
- Date: 2024-01-31
- Time: 15:30:00
AsColumn
nameName for the new column. If not provided, the system generates a unique name. If AsColumn
matches an existing column, the existing column is replaced. The name should follow valid column naming conventions.