flytekit.extend.SQLTask

class flytekit.extend.SQLTask(*args, **kwargs)[source]

Base task types for all SQL tasks. See flytekit.extras.sqlite3.task.SQLite3Task and flytekitplugins.athena.task.AthenaTask for examples of how to use it as a base class.

class SQLite3Task(*args, **kwargs)

Run client side SQLite3 queries that optionally return a FlyteSchema object.

Note

This is a pre-built container task. That is, your user container will not be used at task execution time. Instead the image defined in this task definition will be used instead.

DB_LOCATION = "https://cdn.sqlitetutorial.net/wp-content/uploads/2018/03/chinook.zip"

sql_task = SQLite3Task(
    "test",
    query_template="select TrackId, Name from tracks limit {{.inputs.limit}}",
    inputs=kwtypes(limit=int),
    output_schema_type=FlyteSchema[kwtypes(TrackId=int, Name=str)],
    task_config=SQLite3Config(
        uri=DB_LOCATION,
        compressed=True,
    ),
)

See the cookbook for additional usage examples and the base class flytekit.extend.PythonCustomizedContainerTask as well.

Parameters
  • name – unique name for the task, usually the function’s module and name.

  • task_config – Configuration object for Task. Should be a unique type for that specific Task

  • container_image – This is the external container image the task should run at platform-run-time.

  • executor – This is an executor which will actually provide the business logic.

  • task_resolver – Custom resolver - if you don’t make one, use the default task template resolver.

  • task_type – String task type to be associated with this Task

  • requests – custom resource request settings.

  • limits – custom resource limit settings.

  • environment – Environment variables you want the task to have when run.

  • secret_requests (List[Secret]) –

    Secrets that are requested by this container execution. These secrets will be mounted based on the configuration in the Secret and available through the SecretManager using the name of the secret as the group Ideally the secret keys should also be semi-descriptive. The key values will be available from runtime, if the backend is configured to provide secrets and if secrets are available in the configured secrets store. Possible options for secret stores are

This SQLTask should mostly just be used as a base class for other SQL task types and should not be used directly. See flytekit.extras.sqlite3.task.SQLite3Task

__init__(name, query_template, task_type='sql_task', inputs=None, metadata=None, task_config=None, outputs=None, **kwargs)[source]

This SQLTask should mostly just be used as a base class for other SQL task types and should not be used directly. See flytekit.extras.sqlite3.task.SQLite3Task

Parameters
  • name (str) –

  • query_template (str) –

  • inputs (Optional[Dict[str, Type]]) –

  • metadata (Optional[flytekit.core.base_task.TaskMetadata]) –

  • task_config (Optional[flytekit.core.base_sql_task.T]) –

  • outputs (Optional[Dict[str, Type]]) –

Methods

__init__(name, query_template[, task_type, ...])

This SQLTask should mostly just be used as a base class for other SQL task types and should not be used directly.

compile(ctx, *args, **kwargs)

Generates a node that encapsulates this task in a workflow definition.

construct_node_metadata()

Used when constructing the node that encapsulates this task as part of a broader workflow definition.

dispatch_execute(ctx, input_literal_map)

This method translates Flyte's Type system based input values and invokes the actual call to the executor This method is also invoked during runtime.

execute(**kwargs)

This method will be invoked to execute the task.

find_lhs()

get_config(settings)

Returns the task config as a serializable dictionary.

get_container(settings)

Returns the container definition (if any) that is used to run the task on hosted Flyte.

get_custom(settings)

Return additional plugin-specific custom data (if any) as a serializable dictionary.

get_input_types()

Returns the names and python types as a dictionary for the inputs of this task.

get_k8s_pod(settings)

Returns the kubernetes pod definition (if any) that is used to run the task on hosted Flyte.

get_query(**kwargs)

get_sql(settings)

Returns the Sql definition (if any) that is used to run the task on hosted Flyte.

get_type_for_input_var(k, v)

Returns the python type for an input variable by name.

get_type_for_output_var(k, v)

Returns the python type for the specified output variable by name.

interpolate_query(query_template, **kwargs)

This function will fill in the query template with the provided kwargs and return the interpolated query Please note that when SQL tasks run in Flyte, this step is done by the

local_execute(ctx, **kwargs)

This function is used only in the local execution path and is responsible for calling dispatch execute.

post_execute(user_params, rval)

Post execute is called after the execution has completed, with the user_params and can be used to clean-up, or alter the outputs to match the intended tasks outputs.

pre_execute(user_params)

This is the method that will be invoked directly before executing the task method and before all the inputs are converted.

Attributes

environment

Any environment variables that supplied during the execution of the task.

instantiated_in

interface

lhs

location

metadata

name

python_interface

Returns this task's python interface.

query_template

security_context

task_config

Returns the user-specified task config which is used for plugin-specific handling of the task.

task_type

task_type_version