AWS emr: EMR Spark materialized views: Hive sources and system-managed views
Summary
Adds documentation for Apache Hive (non-Iceberg) source tables in Spark materialized views (new config flags, ETag-based change detection, no incremental refresh) and for system-managed materialized views, where only AWS Glue can write the view's data and metadata, plus updated support/limitation statements.
Security assessment
The new 'System-managed materialized views' section documents a write-protection/integrity control: only AWS Glue may write the view's data and metadata, and attempts to modify them via another engine, a direct AWS Glue UpdateTable call, or a direct write to the underlying Iceberg table are rejected. This is security-relevant guidance (tamper resistance, trusted shared datasets) but it documents a feature rather than remediating a specific vulnerability or incident; the remaining changes (Hive source table support, ETag change detection, stale-view rewrite behavior) are functional.
Evidence
With a system-managed materialized view, only AWS Glue can write to the materialized view. AWS Glue writes both its data and its definition, and no other engine or user can modify it. This protects the materialized view from unintended changes, so you can share it as a trusted, consistent dataset. AWS Glue stores the materialized view as a standard Apache Iceberg table in an Amazon S3 Tables bucket within your account.
Diff
diff --git a/emr/latest/ReleaseGuide/emr-spark-materialized-views.md b/emr/latest/ReleaseGuide/emr-spark-materialized-views.md index eab6440..c0e0f95 100644 --- a//emr/latest/ReleaseGuide/emr-spark-materialized-views.md +++ b//emr/latest/ReleaseGuide/emr-spark-materialized-views.md @@ -7 +7 @@ -How materialized views work with Amazon EMRPrerequisitesConfiguring Spark to use materialized viewsCreating materialized viewsQuerying materialized viewsRefreshing materialized viewsManaging materialized viewsPermissions for materialized viewsMonitoring materialized view operationsExample: Complete workflowConsiderations and limitations +How materialized views work with Amazon EMRPrerequisitesConfiguring Spark to use materialized viewsCreating materialized viewsQuerying materialized viewsRefreshing materialized viewsManaging materialized viewsPermissions for materialized viewsMonitoring materialized view operationsExample: Complete workflowSystem-managed materialized viewsConsiderations and limitations @@ -36,0 +37,2 @@ When you create a materialized view using Spark on Amazon EMR, the view definiti + * System-managed materialized views + @@ -48 +50 @@ The AWS Glue Data Catalog handles all operational aspects of materialized view m - * Detecting changes in source tables using Apache Iceberg's metadata layer + * Detecting changes in source tables. For Apache Iceberg source tables, change detection uses Apache Iceberg's metadata layer. For Apache Hive (non-Iceberg) source tables, change detection compares the ETags of the source data files against those recorded at the last refresh. @@ -69 +71 @@ To use materialized views with Amazon EMR, you need: - * Source tables in Apache Iceberg format registered in the AWS Glue Data Catalog + * Source tables registered in the AWS Glue Data Catalog. Apache Iceberg source tables are supported on Amazon EMR release 7.12.0 and later. Apache Hive (non-Iceberg) source tables with a PARQUET, ORC, CSV, or JSON provider are supported on Amazon EMR release 7.14.0 and later. @@ -143,0 +146,4 @@ The following configuration parameters control materialized view behavior: + * `spark.sql.materializedView.v1SourceTables.enabled` – Allows Apache Hive (non-Iceberg) tables with a PARQUET, ORC, CSV, or JSON provider in the AWS Glue Data Catalog to be used as source tables for a materialized view. Set to true to create materialized views over Hive source tables. Available on Amazon EMR release 7.14.0 and later. + + * `spark.sql.materializedView.v1ETagVersioning.enabled` – Set to true to detect changes in Apache Hive (non-Iceberg) source tables by comparing the ETags of the source data files. This is required to refresh a materialized view that references Hive source tables. Available on Amazon EMR release 7.14.0 and later. + @@ -218,0 +225,24 @@ When your source tables are in a different catalog than your materialized view, +### Creating a materialized view over Apache Hive source tables + +Starting with Amazon EMR release 7.14.0, you can create a materialized view whose source tables are Apache Hive (non-Iceberg) tables, without first migrating those tables to Apache Iceberg. The materialized view itself is still stored as an Apache Iceberg table; only the source tables can be Hive. A single materialized view can reference a mix of Hive and Iceberg source tables. + +Hive source tables are supported when the table's provider is PARQUET, ORC, CSV, or JSON (created with `CREATE TABLE ... USING `format``). A table with a `hive` provider (SerDe-based) is not supported, even if it stores Parquet data underneath. To check a table's provider, use `DESCRIBE EXTENDED `table_name``. + +To use Hive source tables, set `spark.sql.materializedView.v1SourceTables.enabled` and `spark.sql.materializedView.v1ETagVersioning.enabled` to `true` in your Spark session. For more information, see Configuration parameters. + +The following example creates a materialized view over a Hive source table: + + + CREATE MATERIALIZED VIEW s3t_catalog.analytics.customer_summary + AS + SELECT + customer_name, + COUNT(*) as order_count, + SUM(amount) as total_amount + FROM spark_catalog.sales.orders + GROUP BY customer_name; + +###### Note + +Hive source tables do not expose row-level change history, so incremental refresh is not available for a materialized view that references any Hive source table. Each refresh recomputes the entire materialized view. For more information, see Refreshing materialized views. + @@ -239,0 +270,2 @@ The Spark optimizer automatically rewrites this query to use the customer_orders +Starting with Amazon EMR release 8.1.0, automatic query rewrite can also rewrite queries over Apache Hive (non-Iceberg) source tables to use a matching materialized view. If the materialized view is stale, the optimizer does not rewrite the query and instead reads directly from the source tables, so a stale materialized view is never used to answer a query. + @@ -467,0 +500,54 @@ The following example demonstrates a complete workflow for creating and using a +## System-managed materialized views + +With a system-managed materialized view, only AWS Glue can write to the materialized view. AWS Glue writes both its data and its definition, and no other engine or user can modify it. This protects the materialized view from unintended changes, so you can share it as a trusted, consistent dataset. AWS Glue stores the materialized view as a standard Apache Iceberg table in an Amazon S3 Tables bucket within your account. + +System-managed materialized views are available with Amazon EMR release 7.14.0 and later, and with Amazon EMR release 8.1.0 and later. They are stored only in Amazon S3 Tables; Amazon S3 general purpose buckets are not supported. + +### Enabling system-managed materialized views + +To create system-managed materialized views, set `spark.sql.mv.managed.enabled` to `true` in your Spark session, along with your Amazon S3 Tables catalog configuration: + + + spark-sql \ + --conf spark.sql.extensions=org.apache.iceberg.spark.extensions.IcebergSparkSessionExtensions \ + --conf spark.sql.catalog.s3t_catalog=org.apache.iceberg.spark.SparkCatalog \ + --conf spark.sql.catalog.s3t_catalog.type=glue \ + --conf spark.sql.catalog.s3t_catalog.glue.id=111122223333:s3tablescatalog/amzn-s3-demo-table-bucket \ + --conf spark.sql.catalog.s3t_catalog.warehouse=s3://amzn-s3-demo-bucket/mv-warehouse \ + --conf spark.sql.catalog.s3t_catalog.glue.region=us-east-1 \ + --conf spark.sql.defaultCatalog=s3t_catalog \ + --conf spark.sql.mv.managed.enabled=true + +### Creating a system-managed materialized view + +Create the materialized view with the MANAGED keyword, in a session that has `spark.sql.mv.managed.enabled` set to `true`: + + + CREATE MANAGED MATERIALIZED VIEW s3t_catalog.analytics.customer_summary + AS + SELECT + customer_name, + COUNT(*) as order_count, + SUM(amount) as total_amount + FROM glue_catalog.sales.orders + GROUP BY customer_name; + +AWS Glue computes and writes the materialized view for you; your Spark session does not write it directly. The CREATE MANAGED MATERIALIZED VIEW statement waits until AWS Glue finishes creating the materialized view before it returns, so it can take longer than creating a regular materialized view. + +### Write protection + +Only AWS Glue writes the materialized view's data and its metadata, such as its schema and storage location. Any attempt to change these is rejected, whether it comes from another query engine, a direct AWS Glue `UpdateTable` call, or a direct write to the underlying Apache Iceberg table. + +You can still perform the following operations on a system-managed materialized view: + + * Refresh the materialized view. AWS Glue runs the refresh and writes the results for you. + + * Change the refresh schedule and table properties. + + * Drop the materialized view, if you have permission to drop it. + + + + +Schema evolution is not supported for a system-managed materialized view. To change the materialized view's SQL definition, drop the materialized view and create it again. + @@ -474 +560 @@ Consider the following when using materialized views with Amazon EMR: - * Source tables must be Apache Iceberg tables registered in the AWS Glue Data Catalog. Apache Hive, Apache Hudi, and Linux Foundation Delta Lake tables are not supported at launch. + * Source tables must be registered in the AWS Glue Data Catalog. Apache Iceberg source tables are supported on Amazon EMR release 7.12.0 and later. Apache Hive (non-Iceberg) source tables are supported on Amazon EMR release 7.14.0 and later. Apache Hudi and Linux Foundation Delta Lake source tables are not supported. @@ -478 +564,3 @@ Consider the following when using materialized views with Amazon EMR: - * Materialized views cannot reference AWS Glue Data Catalog views, multi-dialect views, or other materialized views as source tables. + * Materialized views cannot reference AWS Glue Data Catalog views or multi-dialect views as source tables. + + * A materialized view can reference another materialized view as a source table.