Teradata Package for Python Function Reference | 20.00 - bit_and - Teradata Package for Python - Look here for syntax, methods and examples for the functions included in the Teradata Package for Python.
Teradata® Package for Python Function Reference - 20.00
- Deployment
- VantageCloud
- VantageCore
- Edition
- Enterprise
- IntelliFlex
- VMware
- Product
- Teradata Package for Python
- Release Number
- 20.00.00.03
- Published
- December 2024
- ft:locale
- en-US
- ft:lastEdition
- 2024-12-19
- dita:id
- TeradataPython_FxRef_Enterprise_2000
- lifecycle
- latest
- Product Category
- Teradata Vantage
- teradataml.dataframe.sql.DataFrameColumn.bit_and = bit_and(bit_mask)
- DESCRIPTION:
Function performs the logical AND operation on the binary representation of
the integer or byte value in column and corresponding bits from input argument.
Function takes two bit patterns of equal length and performs the logical AND
operation on each pair of corresponding bits as follows:
* The result is 0 if either of the two bits are 0 or both the bits are 0.
* The result is 1 if both the bits at same position is 1.
If the binary representation of the integer or byte value in column and "bit_mask"
argument differ in length, the arguments are processed as follows:
* The value in column and "bit_mask" arguments are aligned on their least
significant byte/bit.
* The smaller argument is padded with zeros to the left until it becomes
the same size as the larger argument.
ALTERNATE NAME:
bitand
PARAMETERS:
bit_mask:
Required Argument.
Specifies a ColumnExpression of a numeric or byte column or a numeric or byte
literal value.
Note:
1. If the argument is NULL, the function returns NULL.
Format of a ColumnExpression of a column: '<dataframe>.<dataframe_column>'.
Types:
ColumnExpression, int
The data type of the "bit_mask" parameter varies depending upon the data type
of the bits in column. The following table shows the supported column/literal
value types for bits in column and "bit_mask" parameters and their permitted
combinations:
===================================================
| bits in column type | "bit_mask" type |
===================================================
| BYTEINT | BYTE(1) or BYTEINT |
| SMALLINT | BYTE(2) or SMALLINT |
| INTEGER | BYTE(4) or INTEGER |
| BIGINT | BYTE(8) or BIGINT |
| NUMBER(38,0) | VARBYTE(16) or NUMBER(38,0) |
| VARBYTE(n) | VARBYTE(n) |
===================================================
RAISES:
TypeError, ValueError, TeradataMlException
RETURNS:
DataFrameColumn
EXAMPLES:
# Load the data to run the example.
>>> load_example_data("dataframe", "bytes_table")
# Create a DataFrame on 'bytes_table' table.
>>> df = DataFrame("bytes_table")
>>> print(df)
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'
# Example1: Performs logical AND operation operation on "id" and "byte_col" columns
# and pass it as input to DataFrame.assign().
>>> res_df = df.assign(col = df.id_col.bit_and(df.byte_col))
>>> print(res_df)
byte_col varbyte_col blob_col col
id_col
2 b'61' b'627A7863' b'6162636431323233' 0
1 b'62' b'616263643132' b'3331363136323633' 0
0 b'63' b'62717765' b'3330363136323633' 0
# Example2: Performs logical AND operation operation on "varbyte_col" and "byte_col"
# columns and pass it as input to DataFrame.assign().
>>> res_df = df.assign(col = df.varbyte_col.bit_and(df.byte_col))
>>> print(res_df)
byte_col varbyte_col blob_col col
id_col
2 b'61' b'627A7863' b'6162636431323233' b'61'
1 b'62' b'616263643132' b'3331363136323633' b'22'
0 b'63' b'62717765' b'3330363136323633' b'61'