Skip to main content

Export Lakehouse Query Results to Azure SQL DB

Execute a Query against the Lakehouse and export the results to Azure SQL DB.

Category: Export Data from Lakehouse | Tags: Export

How it works

Execute Query '<<DeltaQuery>>' against the Delta Lake and copy results to Azure SQL database table '<<TargetSchemaName>>.<<TargetTableName>>'

To use this activity within the API, use an ActivityCode of DELTA-QUERY-AZSQL.

Available Connections​

SourceConnection:

TargetConnection:

Example JSON​

An example of what the Task Config would look like for a task using this activity. Some of these variables would be set at the group level to avoid duplication between tasks.

{
"SourceConnection": "",
"TargetConnection": "",
"TargetSchemaName": "",
"TargetTableName": ""
}

Variable Reference​

The following variables are supported:

  • AutoCreateTable (Optional) - Should the target table be created automatically?

  • DatabricksComputeId (Optional) - The Id of the Databricks compute resource to use to run the Notebook or Query.

  • DatabricksJobClusterSpec (Required) - JSON configuration for the job cluster. See help for examples.

    Show more details

    Job Cluster Spec

    JSON configuration for the ephemeral job cluster. A new cluster is created for each run and terminated on completion.

    Required properties

    • RuntimeVersion — Databricks Runtime version (e.g. "17.3")
    • NodeTypeId or InstancePoolId — one must be specified

    Optional properties

    • NumWorkers — number of worker nodes (omit or set to 0 for single-node)
    • DriverNodeTypeId — override the driver node type
    • DriverInstancePoolId — use a separate pool for the driver node
    • SparkVersionFull — override the full Spark version string (e.g. "17.3.x-gpu-ml-scala2.12")
    • Libraries — additional libraries to install on the cluster
    • Availability — OnDemand (default), Spot or SpotWithFallback. See Spot instances below.
    • FirstOnDemand — how many nodes, driver first, stay on on-demand instances. Defaults to 1 on a multi-node cluster. Needs Availability Spot or SpotWithFallback.

    azure-keyvault-secrets is always installed automatically.

    Spot instances

    Spot instances cost less, but the cloud provider can reclaim them during a run.

    • Spot — runs on spot instances only.
    • SpotWithFallback — uses on-demand instances when spot capacity is not available.

    Losing the driver ends the run, and the task fails, so the driver should stay on-demand: leave FirstOnDemand at 1 or more. On Azure this is required. FirstOnDemand must be at least 1 there, so only the workers of a multi-node cluster can run on spot, and a single-node cluster can't.

    Availability and FirstOnDemand can't be set with InstancePoolId: the pool's own settings decide.

    Example — Standard job cluster

    {
    "RuntimeVersion": "17.3",
    "NodeTypeId": "Standard_DS3_v2",
    "NumWorkers": 4
    }

    Example — Spot workers, on-demand driver

    {
    "RuntimeVersion": "17.3",
    "NodeTypeId": "Standard_DS3_v2",
    "NumWorkers": 4,
    "Availability": "SpotWithFallback"
    }

    Example — Using instance pools

    {
    "RuntimeVersion": "17.3",
    "InstancePoolId": "0101-120000-pool123",
    "NumWorkers": 0,
    "Libraries": [{ "pypi": { "package": "pandas==2.0.0" } }]
    }
  • DatabricksServerlessSpec (Optional) - Optional JSON configuration for serverless job runs: the Python packages to install and the environment version. See help for examples.

    Show more details

    Serverless Job Spec

    Optional JSON configuration for serverless job runs. Sets the Python packages to install and the environment version. All properties are optional.

    Required properties

    None.

    Optional properties

    • Libraries — list of pip requirement strings to install
    • Dependencies — the same as Libraries. Both names are accepted and the two lists are merged, so one task configuration works on every factory.
    • EnvironmentVersion — Databricks environment version, a plain number such as "5". Taken from the compute ID suffix (for example SERVERLESS_PERFORMANCE_V5) when it is not set here; set here, it overrides the suffix. When neither supplies one, the factory default is used.

    Example — Packages only. Takes the environment version from the compute ID suffix

    {
    "Libraries": ["pandas", "numpy>=1.21.0"]
    }

    Example — Packages and a pinned environment version

    {
    "Dependencies": ["pandas==2.0.0"],
    "EnvironmentVersion": "5"
    }

    Notes

    • Only the properties listed above are accepted. Anything else is rejected, so a misspelling such as "Dependancies" is reported on the task run rather than ignored.
    • Entries must be pip requirement strings, for example "pandas==2.0.0". Databricks library objects such as {"pypi": {"package": "pandas"}} are rejected: serverless installs packages through the environment, not through cluster libraries.
    • Request each package once. The same package requested twice at different versions is rejected rather than resolved.
    • azure-keyvault-secrets is always installed and does not need requesting.
    • The spec is only applied to serverless runs (compute IDs starting with SERVERLESS). It is ignored for existing clusters and job clusters.
    • Libraries and Dependencies both map to environments[].spec.dependencies in the Databricks Jobs API.
  • DeltaQuery (Optional) - Query to run against the Lakehouse.

  • DIUsToUseForCopyActivity (Optional) - Specifies the powerfulness of the copy executor. Value can be between 2 and 256. When left at default, the Data Factory dynamically applies the optimal DIU setting based on the source-sink pair and data pattern.

  • ExtractControlQuery (Optional) - For incremental loads only, a SQL query to get a 'high-water' mark for extract control. For instance, this could be the maximum value of an modified_date or an identity column. NOTE: The column returned must be aliased as ExtractControl e.g. select max(modified_date) as ExtractControl from some_table.

    Show more details

    **Extract Control Query **

    For incremental data extraction, the SQL statement that will be executed on the source database to extract the high-water mark for this data prior to extracting. This could be the maximum value of a modified date or an identity column and will be used in the next data extraction.

    NOTE: The column returned must be aliased as ExtractControl. For example:

    select max(modified_date) as ExtractControl
    from some_table;
  • ExtractControlVariableName (Optional) - For incremental loads only, the name to assign the Extract Control variable in State Config for the ExtractControl value derived from the Extract Control Query above.

  • ExtractControlVariableSeedValue (Optional) - The initial value to set for the Extract Control variable in State Config - this will have no impact beyond the original seeding of the Extract Control variable in State Config.

  • IsFederated (Optional) - Makes task available to other Insight Factories within this organisation.

  • Links (Optional)

  • MaximumNumberOfAttemptsAllowed (Optional) - The total number of times the running of this Task can be attempted.

  • MaximumRunTimeHours (Optional) - The maximum number of hours a task run is expected to take. If a run exceeds this duration it will be flagged as stuck.

  • MinutesToWaitBeforeNextAttempt (Optional) - If a Task run fails, the number of minutes to wait before re-attempting the Task.

  • PreCopyScript (Optional) - Script to execute on target database prior to Copy.

  • SaveExportToHistory (Optional) - Save the exported data to history in the Lakehouse?

  • SourceConnection (Required) - Source connection to use.

  • TargetConnection (Required) - Target connection to use.

  • TargetSchemaName (Required) - Name of the schema within target Azure SQL Database (e.g. dbo).

  • TargetTableName (Required) - Name of the table within target Azure SQL Database (e.g. Climate).

  • UpsertKeyColumns (Optional) - A comma-separated list of column names comprising the unique key of the target table.

  • WriteBehaviour (Optional) - The method of writing data to the target table.