| |
- countset(target_arg, target_arg_value)
- DESCRIPTION:
Function returns the count of the binary bits within the target_arg expression
that are either set to 1 or set to 0, depending on the target_arg_value value.
PARAMETERS:
target_arg:
Required Argument.
Specifies a ColumnExpression of an integer or byte column or a numeric or byte
literal value.
If the argument is NULL, the function returns NULL.
Format of a ColumnExpression of a column: '<dataframe>.<dataframe_column>.expression'.
Supported SQL column types: BYTEINT, SMALLINT, INTEGER, BIGINT, and VARBYTE(n)
target_arg_value:
Optional Argument.
Specifies a ColumnExpression of an integer column or an integer literal representing
a binary bit value, 0 or 1, to be counted within the target_arg expression.
If target_arg_value is not specified, the default is 1.
If the argument is NULL, the function returns NULL.
Format of a ColumnExpression of a column: '<dataframe>.<dataframe_column>.expression'.
Supported SQL column types: INTEGER
NOTE:
Function accepts positional arguments only.
EXAMPLES:
# Load the data to run the example.
>>> load_example_data("dataframe", "bytes_table")
>>>
# Create a DataFrame on 'bytes_table' table.
>>> bytes_table = DataFrame("bytes_table")
>>> bytes_table
byte_col varbyte_col blob_col
id_col
2 b'61' b'616263643132' b'6162636431323233'
1 b'62' b'62717765' b'3331363136323633'
0 b'63' b'627A7863' b'3330363136323633'
>>>
# Example counts number of 0's and 1's in within values of "varbyte_col" column.
# Import func from sqlalchemy to execute countset function.
>>> from sqlalchemy import func
# Note: Function name case does not matter. We can use the function name in
# lower case, upper case or mixed case.
>>> df = bytes_table.assign(count_1s_varbyte_= func.COUNTSET(bytes_table.varbyte_col.expression),
... count_0s_varbyte_= func.countset(bytes_table.varbyte_col.expression, 0)
... )
>>>
>>> print(df)
byte_col varbyte_col blob_col count_0s_varbyte_ count_1s_varbyte_
id_col
2 b'61' b'616263643132' b'6162636431323233' 29 19
1 b'62' b'62717765' b'3331363136323633' 15 17
0 b'63' b'627A7863' b'3330363136323633' 16 16
>>>
|