Skip to main content

Databricks AWS Utils

Project description

Databricks AWS Utils

Databricks AWS Utils is a library to abstract Databricks integration with AWS Services

Features

  • Convert Delta Table to be consumed by AWS Athena with Schema evolution
  • Run queries against AWS RDS using AWS Secrets Manager to retrieve the connection properties and returns as Spark DataFrame

Install

pip install databricks-aws-utils

Delta Table to AWS Athena

Motivation

Currently, delta tables are only compatible with AWS Athena engine v3, however, even with the compatibility, there are some limitations regarding the schema evolution, where the schema is not fully or correctly synchronized with the AWS Glue catalog, causing problems when querying the table.

To solve this problem, we created this library to convert the delta table columns to be compatible with the AWS Glue catalog and update the table metadata, allowing the table to be queried correctly by AWS Athena.

Usage

from databricks_aws_utils.delta_table import DeltaTableUtils

...

DeltaTableUtils(spark, 'my_schema.my_table_name').to_athena_v3()

The to_athena_v3 function uses the spark session to capture the current delta schema and update the glue table.

NOTE: This feature is only compatible with AWS Athena engine v3, and the Databricks cluster must have access to the AWS Glue catalog.

NOTE: This feature is not supported by Databricks Unity Catalog, since it does not allow queries from AWS Athena.

Custom IAM Role

If you need to use a custom IAM Role to update the AWS Glue table, you can pass the role name as a parameter to the DeltaTableUtils class.

from databricks_aws_utils.delta_table import DeltaTableUtils

...

DeltaTableUtils(
    spark,
    'my_schema.my_table_name',
    iam_role='my_custom_iam_role'
).to_athena_v3()

NOTE: The Databricks cluster must have permission to assume the custom IAM Role.

Athena Engine v2

AWS Athena engine v2 doesn't support delta tables, so, to query a delta table using AWS Athena engine v2, it's necessary to generate Hive Symlink from the delta table and point to a different table.

from databricks_aws_utils.delta_table import DeltaTableUtils

...

DeltaTableUtils(spark, 'my_schema.my_table_name').to_athena('my_schema', 'my_symlink_table_name')

NOTE: The schema name provided in the to_athena doesn't need to be the same as the delta table schema.

Contributing

Change Log

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

databricks_aws_utils-1.5.1.tar.gz (8.7 kB view details)

Uploaded Source

Built Distribution

databricks_aws_utils-1.5.1-py3-none-any.whl (10.3 kB view details)

Uploaded Python 3

File details

Details for the file databricks_aws_utils-1.5.1.tar.gz.

File metadata

  • Download URL: databricks_aws_utils-1.5.1.tar.gz
  • Upload date:
  • Size: 8.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.12.3

File hashes

Hashes for databricks_aws_utils-1.5.1.tar.gz
Algorithm Hash digest
SHA256 b079db39c02dc65d615949f527df9430597b183d8ce1056dc9b12d28b36df9e3
MD5 5d7d3798185d6fb2b6f0d3afd88fe5fb
BLAKE2b-256 caf423762932940095250ab4bafc94dd35cff670ac215365dd3a105df30ad6a3

See more details on using hashes here.

File details

Details for the file databricks_aws_utils-1.5.1-py3-none-any.whl.

File metadata

File hashes

Hashes for databricks_aws_utils-1.5.1-py3-none-any.whl
Algorithm Hash digest
SHA256 0ae188a49ec5101e2420a1d11d2c69c0eb6bfe02ec21b00131aea6c2496ff627
MD5 7d171fc355615a5b45fde9da1410325a
BLAKE2b-256 fd2f47579f1ddbdea4936493dce8cff1bb6a69936ce3f4094a95355d9dd467f8

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page