Teradata Package for Python Function Reference | 17.10 - rotateright - 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.10
Published
April 2022
Language
English (United States)
Last Update
2022-08-19
lifecycle
previous
Product Category
Teradata Vantage
 
 
rotateright

 
Functions
       
rotateright(target_arg, num_bits_arg)
DESCRIPTION:
    Function returns an expression rotated to the right by the specified number of bits,
    with the least significant bits wrapping around to the left.
 
    Following rules apply to the function:
        * If num_bits_arg is equal to zero, then the function returns target_arg
          unchanged.
        * If num_bits_arg is negative, then the function rotates the bits to the left
          instead of the right.
        * If target_arg and/or num_bits_arg are NULL, then the function returns NULL.
        * If num_bits_arg is larger than the size of target_arg, then the function rotates
          (num_bits_arg MOD sizeof(target_arg)) bits. The scope of the rotation operation
          is bounded by the size of the target_arg expression.
 
PARAMETERS:
    target_arg:
        Required Argument.
        Specifies a ColumnExpression of an integer or byte column or a numeric or byte
        literal value.
        Format of a ColumnExpression of a column: '<dataframe>.<dataframe_column>.expression'.
        Supported SQL column types: BYTEINT, SMALLINT, INTEGER, BIGINT, and VARBYTE(n)
        Note:
            When operating against an integer value (BYTEINT, SMALLINT, INTEGER, or BIGINT),
            rotating a bit into the most significant position will result in the integer
            becoming negative. This is because all integers in Vantage are signed integers.
 
    num_bits_arg:
        Required Argument.
        Specifies a ColumnExpression of an integer column or an integer literal
        indicating the number of bit positions to rotate.
        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 rotates values in "varbyte_col" column to right by 3 bits.
    # Import func from sqlalchemy to execute rotateright 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(rotateright_varbyte_= func.rotateright(bytes_table.varbyte_col.expression, 3))
    >>> print(df)
           byte_col      varbyte_col             blob_col rotateright_varbyte_
    id_col
    2         b'61'  b'616263643132'  b'6162636431323233'      b'4C2C4C6C8626'
    1         b'62'      b'62717765'  b'3331363136323633'         b'-53B1D114'
    0         b'63'      b'627A7863'  b'3330363136323633'          b'6C4F4F0C'
    >>>