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

 
Functions
       
hashbucket(expression)
DESCRIPTION:
    Function returns the hash bucket number that corresponds to a specified row hash value.
    If no row hash value is specified, functions returns the highest hash bucket number.
 
PARAMETERS:
    expression:
        Optional Argument.
        Specifies a ColumnExpression of a column that evaluates to a valid BYTE(4)
        row hash value.
        Format for the argument: '<dataframe>.<dataframe_column>.expression'.
        If expression does not appear in the argument list, then function returns an
        INTEGER value that is the highest hash bucket number.
        If expression evaluates to NULL, then function returns NULL.
        If expression evaluates to a valid BYTE(4) row hash value, then function
        returns the hash bucket number corresponding to the row hash value.
        The range of values for hash bucket numbers depends on the system setting
        of the hash bucket size.
            * If the hash bucket size is 16 bits, the hash bucket numbers can have
              a value from 0 to 65535.
            * If the hash bucket size is 20 bits, the hash bucket numbers can have
              a value from 0 to 1048575.
 
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
    0         b'63'      b'627A7863'  b'3330363136323633'
    2         b'61'  b'616263643132'  b'6162636431323233'
    1         b'62'      b'62717765'  b'3331363136323633'
    >>>
 
    # Import func from sqlalchemy to execute hashbucket() function.
    >>> from sqlalchemy import func
 
    # Example 1: Return the maximum hash bucket values. To do so, execute function without any argument.
    # Create a sqlalchemy Function object.
    >>> hashbucket_func_ = func.hashbucket()
    >>>
 
    # Pass the Function object as input to DataFrame.assign().
    >>> df = bytes_table.assign(hashbucket_max_=hashbucket_func_)
    >>> print(df)
           byte_col      varbyte_col             blob_col  hashbucket_max_
    id_col
    0         b'63'      b'627A7863'  b'3330363136323633'          1048575
    2         b'61'  b'616263643132'  b'6162636431323233'          1048575
    1         b'62'      b'62717765'  b'3331363136323633'          1048575
    >>>
 
    # Example 2: Return the maximum hash bucket values corresponding to values in "byte_col" column.
    # Create a sqlalchemy Function object.
    # Function accepts column of type BYTE(4) only. Let's cast byte_col column to BYTE(4).
    >>> from teradatasqlalchemy import BYTE
    >>> hashbucket_func_ = func.hashbucket(bytes_table.byte_col.cast(BYTE(4)).expression)
    >>>
 
    # Pass the Function object as input to DataFrame.assign().
    >>> df = bytes_table.assign(hashbucket_byte_col_=hashbucket_func_)
    >>> print(df)
           byte_col      varbyte_col             blob_col  hashbucket_byte_col_
    id_col
    0         b'63'      b'627A7863'  b'3330363136323633'           405504
    2         b'61'  b'616263643132'  b'6162636431323233'           397312
    1         b'62'      b'62717765'  b'3331363136323633'           401408
    >>>