Teradata Package for Python Function Reference - bitand - 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

Product
Teradata Package for Python
Release Number
17.00
Published
November 2021
Language
English (United States)
Last Update
2021-11-19
lifecycle
previous
Product Category
Teradata Vantage
 
 
bitand

 
Functions
       
bitand(target_arg, bit_mask_arg)
DESCRIPTION:
    Function performs the logical AND operation on the corresponding bits from
    the two input arguments.
 
    Function takes two bit patterns of equal length and performs the logical AND
    operation on each pair of corresponding bits. If the bits at the same position
    are both 1, then the result is 1; otherwise, the result is 0.
 
    If the target_arg and bit_mask_arg arguments differ in length, the arguments are
    processed as follows:
        * The target_arg and bit_mask_arg 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.
 
PARAMETERS:
    target_arg:
        Required Argument.
        Specifies a ColumnExpression of a numeric 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, DECIMAL, NUMBER, and VARBYTE(n)
 
    bit_mask_arg:
        Required Argument.
        Specifies a ColumnExpression of a numeric 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'.
 
        Argument Type Rules and Support:
            The data type of the bit_mask_arg parameter varies depending upon the data type
            of the target_arg parameter. The following table shows the supported column/literal
            value types for target_arg and bit_mask_arg parameters and their permitted
            combinations:
             ===============================================
            | target_arg type | bit_mask_arg 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)                  |
             ===============================================
 
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 performs logical AND operation operation on:
    #   1. "id" and "byte_col" columns.
    #   2. "varbyte_col" and "byte_col" columns.
    # Import func from sqlalchemy to execute bitand function.
    >>> from sqlalchemy import func
 
    # Create a sqlalchemy Function object.
    # Note: Function name case does not matter. We can use the function name in
    #       lower case, upper case or mixed case.
    >>> bit_byte_func_ = func.BITAND(bytes_table.id_col.expression, bytes_table.byte_col.expression)
    >>>
 
    # Pass the Function object as input to DataFrame.assign().
    >>> df = bytes_table.assign(bitand_id_=bit_byte_func_,
    ...                         bitand_byte_=func.bitand(bytes_table.varbyte_col.expression, bytes_table.byte_col.expression)
    ...                        )
    >>> print(df)
           byte_col      varbyte_col             blob_col bitand_byte_  bitand_id_
    id_col
    2         b'61'  b'616263643132'  b'6162636431323233'        b'20'           0
    1         b'62'      b'62717765'  b'3331363136323633'        b'60'           0
    0         b'63'      b'627A7863'  b'3330363136323633'        b'63'           0
    >>>