Query data with DuckDB
Overview
Notebooks include DuckDB 2.0, a hosted SQL engine that runs in the notebook kernel. DuckDB powers SQL cells for fast, lightweight in-notebook SQL analytics. Because DuckDB runs in the kernel, it is distinct from the other SQL options in notebooks, such as Spark SQL, which runs on Spark compute engines that you select through Spark Connect, and Amazon Athena, which runs as a managed query service.
DuckDB 2.0 capabilities
DuckDB 2.0 delivers faster queries over data in Amazon S3 and a simpler way to work with semi-structured data such as JSON logs. You can run these queries directly in SQL cells without configuring or managing separate infrastructure.
Extensions
You can discover and manage the DuckDB library of official extensions through a built-in experience. Extensions span additional file formats, data source connectors, and specialized functions such as geospatial and full-text search.
For example, you can use DuckDB 2.0 with the Iceberg and Excel extensions to join revenue data stored in Amazon S3 with an uploaded targets spreadsheet in a single query.
Load an extension
Before you work with an extension, load it. You can load an extension in one of the following ways:
-
In a SQL cell, choose DuckDB, write a load statement for the extension that you need (for example, a statement that loads the
excelextension), and then start working with it. -
Open the built-in extensions experience to explore the available DuckDB extensions, and then install and load core extensions from the list.
Many core extensions load automatically the first time you reference them, so you often don't need to load them explicitly. Load an extension manually when you want to install or update it ahead of time, or when automatic loading is turned off.
Supported official extensions include httpfs, aws,
iceberg, avro (for Iceberg), sqlite, and
excel. For the full list, see the DuckDB core extensions
documentation
Query multiple data sources from one cell
From a single SQL cell and a single statement, you can work across files in Amazon S3
buckets or uploaded files. You can also work across data sources including the
AWS Glue Data Catalog and Amazon S3 Tables, and query open table formats such as Apache Iceberg. Load
and attach the extensions for the sources that you want to query, such as the
iceberg and aws extensions.
You don't need to preload data into a dataframe before you query. You can query across these sources directly in SQL and join across sources in a single statement instead of staging each source separately.
The Amazon Athena DuckDB extension is available in preview. The DuckDB 2.0 upgrade and support for the official DuckDB extensions are generally available.
Attach and query data catalogs
You can attach your project's data catalogs to DuckDB, including Lakehouse catalogs (Apache Iceberg) and Amazon S3 Tables. Attached catalogs appear under the same names that they have in the Data Explorer. You can then do the following:
-
Use
CREATE TABLE ASstatements with table options, such as specifying an Apache Iceberg table location. -
Run SQL with DuckDB syntax in Amazon Athena workgroups that use the DuckDB engine.
When to use DuckDB or Amazon Athena
Choose between DuckDB and Amazon Athena based on your query requirements:
-
Use DuckDB when you want to take advantage of extensions installed on your notebook, or when your query doesn't need additional memory or compute to run.
-
Use Amazon Athena when you need fine-grained access control, which DuckDB doesn't support.