Teradata Package for Python Function Reference on VantageCloud Lake - set_data - 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 on VantageCloud Lake

Deployment
VantageCloud
Edition
Lake
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_Lake_2000
Product Category
Teradata Vantage
teradataml.table_operators.Apply.set_data = set_data(self, data, data_partition_column=None, data_hash_column=None, data_order_column=None, is_local_order=False, sort_ascending=True, nulls_first=True)
DESCRIPTION:
    Function enables user to set data and data related arguments without having to
    re-create Apply object.
 
PARAMETERS:
    data:
        Required Argument.
        Specifies a teradataml DataFrame containing the input data.
 
    data_partition_column:
        Optional Argument.
        Specifies Partition By columns for data.
        Values to this argument can be provided as a list, if multiple
        columns are used for partition. If there is no "data_partition_column",
        then the entire result set delivered by the function, constitutes a single
        group or partition.
        Default Value: ANY
        Types: str OR list of Strings (str)
        Notes:
            1) "data_partition_column" can not be specified along with
               "data_hash_column".
            2) "data_partition_column" can not be specified along with
               "is_local_order = True".
 
    data_hash_column:
        Optional Argument.
        Specifies the column to be used for hashing.
        The rows in the input data are redistributed to AMPs based on the hash value of the
        column specified.
        If there is no data_hash_column, then the entire result set,
        delivered by the function, constitutes a single group or partition.
        Types: str
        Note:
            "data_hash_column" can not be specified along with "data_partition_column",
            "is_local_order" and "data_order_column".
 
    data_order_column:
        Optional Argument.
        Specifies Order By columns for data.
        Values to this argument can be provided as a list, if multiple
        columns are used for ordering.
        This argument is used in both cases:
        "is_local_order = True" and "is_local_order = False".
        Types: str OR list of Strings (str)
        Note:
            "data_order_column" can not be specified along with
            "data_hash_column".
 
    is_local_order:
        Optional Argument.
        Specifies a boolean value to determine whether the input data is to be
        ordered locally or not. Order by specifies the order in which the
        values in a group or partition are sorted. Local Order By specifies
        orders qualified rows on each AMP in preparation to be input to a table
        function. This argument is ignored, if "data_order_column" is None. When
        set to True, data is ordered locally.
        Default Value: False
        Types: bool
        Note:
            1) "is_local_order" can not be specified along with
               "data_hash_column".
            2) When "is_local_order" is set to True, "data_order_column" should be
               specified, and the columns specified in "data_order_column" are
               used for local ordering.
 
    sort_ascending:
        Optional Argument.
        Specifies a boolean value to determine if the result set is to be sorted
        on the column specified in "data_order_column", in ascending or descending
        order.
        The sorting is ascending when this argument is set to True, and descending
        when set to False.
        This argument is ignored, if "data_order_column" is None.
        Default Value: True
        Types: bool
 
    nulls_first:
        Optional Argument.
        Specifies a boolean value to determine whether NULLS are listed first or
        last during ordering.
        This argument is ignored, if "data_order_column" is None.
        NULLS are listed first when this argument is set to True, and
        last when set to False.
        Default Value: True
        Types: bool
 
RETURNS:
    None.
 
RAISES:
    TeradataMlException
 
EXAMPLES:
    # Load example data.
    >>> load_example_data("Script", ["barrier", "barrier_new"])
 
    # Create teradataml DataFrame objects.
    >>> barrierdf = DataFrame.from_table("barrier")
    >>> barrierdf
                            Name
    Id
    1   Old Macdonald Had A Farm
    >>>
 
    # List base environments.
    >>> from teradataml import list_base_envs, create_env
    >>> list_base_envs()
           base_name language version
    0  python_3.7.13   Python  3.7.13
    1  python_3.8.13   Python  3.8.13
    2  python_3.9.13   Python  3.9.13
    >>>
 
    # Create an environment.
    >>> demo_env = create_env(env_name = 'demo_env', base_env = 'python_3.8.13', desc = 'Demo Environment')
    User environment 'demo_env' created.
    >>>
 
    >>> import teradataml
    >>> from teradatasqlalchemy import VARCHAR
    >>> td_path = os.path.dirname(teradataml.__file__)
 
    # The script mapper.py reads in a line of text input
    # ("Old Macdonald Had A Farm") from csv and
    # splits the line into individual words, emitting a new row for each word.
    # Create an APPLY object with data and its arguments.
    >>> apply_obj = Apply(data = barrierdf,
    ...                   script_name='mapper.py',
    ...                   files_local_path= os.path.join(td_path,'data', 'scripts'),
    ...                   apply_command='python3 mapper.py',
    ...                   data_order_column="Id",
    ...                   is_local_order=False,
    ...                   nulls_first=False,
    ...                   sort_ascending=False,
    ...                   returns={"word": VARCHAR(15), "count_input": VARCHAR(10)},
    ...                   env_name=demo_env,
    ...                   delimiter='   ')
 
    # Install file in environment.
    >>> apply_obj.install_file('mapper.py')
    File 'mapper.py' installed successfully in the remote user environment 'demo_env'.
    >>>
 
    >>> apply_obj.execute_script()
            word count_input
    0  Macdonald           1
    1          A           1
    2       Farm           1
    3        Had           1
    4        Old           1
    5          1           1
    >>>
 
    # Now run the script on a new DataFrame.
    >>> barrierdf_new = DataFrame.from_table("barrier_new")
    >>> barrierdf_new
                            Name
    Id
    1   Old Macdonald Had A Farm
    2   On his farm he had a cow
    >>>
 
    # Note:
    #    All data related arguments that are not specified in set_data() are
    #    reset to default values.
    >>> apply_obj.set_data(data=barrierdf_new,
    ...                    data_order_column='Id',
    ...                    nulls_first = True)
    >>>
 
    # Execute the user script on Vantage.
    >>> apply_obj.execute_script()
            word count_input
    0        his           1
    1         he           1
    2        had           1
    3          a           1
    4          1           1
    5        Old           1
    6  Macdonald           1
    7        Had           1
    8          A           1
    9       Farm           1
    >>>