set_context - Teradata Python Package

Teradata® Python Package User Guide

Product
Teradata Python Package
Release Number
16.20
Published
February 2020
Language
English (United States)
Last Update
2020-02-29
dita:mapPath
rkb1531260709148.ditamap
dita:ditavalPath
Generic_no_ie_no_tempfilter.ditaval
dita:id
B700-4006
lifecycle
previous
Product Category
Teradata Vantage

The set_context function specifies a Vantage sqlalchemy engine as current context.

  • When overwriting an existing context associated with a Vantage connection, most of the operations on any teradataml DataFrames created before will not work.
  • Running the set_context() triggers garbage collection in teradataml. For more details of Garbage Collection,see Garbage Collection in teradataml.

Example

The following example creates two contexts using different host, then sets the context to the first one.

>>> from teradataml.context.context import *
>>> from teradataml.dataframe.dataframe import DataFrame
Create a connection:
>>> td_connection1 = create_context(host = "myhostname", username="myusername", password = "mypassword")
Overwrite the existing connection with new connection using 'create_context()':
>>> td_connection2 = create_context(host = "myhostname2", username="myusername2", password = "mypassword2")
302: UserWarning: [Teradata][teradataml](TDML_2002) Overwriting an existing context associated with Teradata connection. Most of the operations on any teradataml DataFrames created before this will not work.
  warnings.warn(Messages.get_message(MessageCodes.OVERWRITE_CONTEXT))
Get the engine currently associated with the context:
>>> get_context()
Engine(teradatasql://myusername2:***@myhostname2)
Overwrite the existing context, by passing a sqlalchemy engine object as input to 'set_context()', thereby creating a new context:
>>> set_context(tdsqlengine = td_connection1)
302: UserWarning: [Teradata][teradataml](TDML_2002) Overwriting an existing context associated with Teradata connection. Most of the operations on any teradataml DataFrames created before this will not work.
  warnings.warn(Messages.get_message(MessageCodes.OVERWRITE_CONTEXT))
>>> get_context()
Engine(teradatasql://myusername:***@myhostname)