set_context | Teradata Python Package - set_context - Teradata Vantage

Teradata® VantageCloud Lake

Deployment
VantageCloud
Edition
Lake
Product
Teradata Vantage
Published
January 2023
Language
English (United States)
Last Update
2024-04-03
dita:mapPath
phg1621910019905.ditamap
dita:ditavalPath
pny1626732985837.ditaval
dita:id
phg1621910019905

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)