Showing posts with label lakehouse. Show all posts
Showing posts with label lakehouse. Show all posts

28 November 2026

🎯Tomer Shiranet - Collected Quotes

"A big headache with data lakes prior to Apache Iceberg was dealing with the need to change the table’s physical optimization. Too often, when your partitioning needs to change, the only choice you have is to rewrite the entire table, and at scale this can get very expensive. The alternative is to just live with the existing partitioning scheme and sacrifice the performance improvements a better partitioning scheme can provide. With Apache Iceberg you can update how the table is partitioned at any time without the need to rewrite the table and all its data. Since partitioning has everything to do with the metadata, the operations needed to make this change to your table’s structure are quick and cheap." (Tomer Shiranet al, "Apache Iceberg: The Definitive Guide Data Lakehouse Functionality, Performance, and Scalability on the Data Lake", 2024)

"A data warehouse or OLAP database is a centralized repository that supports storing large volumes of data ingested from various sources such as operational systems, application databases, and logs. [...] A data warehouse owns all the technical components in a single system. In other words, all the data is stored in its proprietary file and table formats on its proprietary storage system. This data is then managed exclusively by the data warehouse’s storage engine, is registered in its catalog, and can be accessed only by the user or analytical engines through its compute engine." (Tomer Shiranet al, "Apache Iceberg: The Definitive Guide Data Lakehouse Functionality, Performance, and Scalability on the Data Lake", 2024)

"A semantic layer is a virtual abstraction atop your data lakehouse, providing a structured and business-friendly view of the underlying data. It acts as a translation layer, allowing users and applications to interact with data in a way that’s intuitive and meaningful to them without needing to understand the complexities of the data’s storage or schema. This layer enables governance and security by centralizing control over data access, defining fine-grained permissions, and applying data masking and transformation rules. It simplifies data management, ensuring data consistency, quality, and compliance with organizational policies, all while shielding users from the underlying data intricacies. A semantic layer empowers organizations to manage and secure their data lakehouse efficiently." (Tomer Shiranet al, "Apache Iceberg: The Definitive Guide Data Lakehouse Functionality, Performance, and Scalability on the Data Lake", 2024)

"An important capability in the world of databases and data warehouses is the ability to go back in time to a particular state of the table to query historical data (i.e., data that has been changed or deleted). Apache Iceberg brings a similar time-travel capability to a data lakehouse architecture. This can be particularly useful for scenarios such as analyzing your organization’s data from previous quarters, restoring accidentally deleted rows, or reproducing analysis results." (Tomer Shiranet al, "Apache Iceberg: The Definitive Guide Data Lakehouse Functionality, Performance, and Scalability on the Data Lake", 2024)

"Another challenge with traditional partitioning is that since it relied on the physical structure of the files being laid out into subdirectories, changing how the table was partitioned required you to rewrite the entire table. This becomes an inevitable problem as data and query patterns evolve, necessitating that we rethink how we partition and sort the data. Apache Iceberg solves this problem with its metadata-tracked partitioning as well, because the metadata tracks not only partition values but also historical partition schemes, allowing the partition schemes to evolve. So, if the data in two different files were written based on two different partition schemes, the Iceberg metadata would make the engine aware so that it could create a plan with partition scheme A separately from partition scheme B, creating an overall scan plan at the end." (Tomer Shiranet al, "Apache Iceberg: The Definitive Guide Data Lakehouse Functionality, Performance, and Scalability on the Data Lake", 2024)

"Apache Iceberg aims for existing tools to embrace the standard and is designed to take advantage of existing, popular storage solutions and compute engines in the hope that existing options will support working with the standard. The purpose of this approach is to let the ecosystem of existing data tools build out support for Apache Iceberg tables and let Iceberg become the standard for how engines can recognize and work with tables on the data lake. The goal is for Apache Iceberg to become so ubiquitous in the ecosystem that it becomes another implementation detail that many users don’t have to think about." (Tomer Shiranet al, "Apache Iceberg: The Definitive Guide Data Lakehouse Functionality, Performance, and Scalability on the Data Lake", 2024)

"Apache Iceberg handles partitioning quite differently, addressing many [...] pain points when optimizing your tables with partitioning. One resulting feature of this approach is called hidden partitioning. It starts with how Apache Iceberg tracks partitioning. Instead of tracking it by relying on how files are physically laid out, Iceberg tracks the range of partition values at the snapshot and manifest levels, allowing for many levels of new flexibility: Instead of having to generate additional columns to partition based on transform values, you can use built-in transforms that engines and tools can apply when planning queries from the metadata. Since you don’t need an additional column when using these transforms, you store less in your datafiles. Since the metadata allows the engine to be aware of the transform on the original column, you can filter solely on the original column and get the benefit of partitioning." (Tomer Shiranet al, "Apache Iceberg: The Definitive Guide Data Lakehouse Functionality, Performance, and Scalability on the Data Lake", 2024)

"By breaking data into microbatches, Apache Spark gains several advantages. First, it enhances fault tolerance, as any failures can be more easily managed within each batch. Second, it seamlessly integrates with other Spark components, allowing for a unified ecosystem for both batch and real-time processing. Additionally, this approach enables real-time processing capabilities, as the microbatches are processed continuously at a rapid pace. Lastly, it achieves high throughput, efficiently handling large volumes of data. Overall, Apache Spark’s microbatching approach strikes a balance between responsiveness, data volume handling, and resource efficiency, making it a favored choice in the realm of big data and streaming applications." (Tomer Shiranet al, "Apache Iceberg: The Definitive Guide Data Lakehouse Functionality, Performance, and Scalability on the Data Lake", 2024)

"In Iceberg, partitioning occurs in two parts: the column, which physical partitioning should be based on; and an optional transform to that value including functions such as bucket, truncate, year, month, day, and hour. The ability to apply a transform eliminates the need to create new columns just for partitioning. This results in more intuitive queries benefiting from partitioning as consumers will not need to add extra filter predicates to their queries on additional partitioning columns." (Tomer Shiranet al, "Apache Iceberg: The Definitive Guide Data Lakehouse Functionality, Performance, and Scalability on the Data Lake", 2024)

"Maintaining the highest level of data quality is crucial for deriving meaningful insights. If data quality is compromised at any point in a data engineering workflow, it can adversely affect subsequent analyses such as BI and predictive analytics. For example, consider an extract, transform, and load (ETL) process: it takes data from an operational system and transfers it to an analytical system for use in BI reports or ad hoc analyses. If the original data has duplicates or inconsistencies or if such issues are introduced during the ETL process and are not addressed before reaching the production analytics environment, the result can be flawed insights that can lead to incorrect decisions. This highlights the critical importance of data quality in data engineering workflows. It’s essential, not just in theory but as a practical necessity, to ensure that data is accurate, consistent, and reliable." (Tomer Shiranet al, "Apache Iceberg: The Definitive Guide Data Lakehouse Functionality, Performance, and Scalability on the Data Lake", 2024)

"While migrating to Apache Iceberg promises a more streamlined data architecture, the process itself, as with any migration, can be intricate and demanding. The transition involves adapting existing data structures, modifying data ingestion pipelines, and updating data processing workflows. Moreover, organizations may need to refactor existing data models and restructure data storage in Iceberg-compatible formats. Migrating also requires addressing backward-compatibility concerns and ensuring that existing data seamlessly integrates with the new architecture." (Tomer Shiranet al, "Apache Iceberg: The Definitive Guide Data Lakehouse Functionality, Performance, and Scalability on the Data Lake", 2024)

"Multitable transactions are a fundamental concept in databases that support consistency and atomicity of operations spanning multiple tables. In a multitable transaction, multiple operations, possibly involving different tables, are treated as a single atomic unit of work. This means that either all operations in the transaction succeed, or if any operation fails, all the changes made within that transaction are rolled back, thereby leaving the database in a consistent state. The importance of multitable transactions primarily lies in their ability to maintain data consistency, which is a crucial aspect of database management systems." (Tomer Shiranet al, "Apache Iceberg: The Definitive Guide Data Lakehouse Functionality, Performance, and Scalability on the Data Lake", 2024)

"Reading data from Apache Iceberg tables follows a well-defined sequence of actions, seamlessly allowing queries to be transformed into actionable insights. When a read query is initiated, it is sent to the query engine first. The engine leverages the catalog to retrieve the latest metadata file location, which contains critical information about the table’s schema and other metadata files, such as the manifest list that ultimately leads to the actual datafiles. Statistical information about columns is used in this process to limit the number of files being read, which helps improve query performance." (Tomer Shiranet al, "Apache Iceberg: The Definitive Guide Data Lakehouse Functionality, Performance, and Scalability on the Data Lake", 2024)

"Streaming data refers to the continuous generation and processing of data, often coming from various sources. These sources can include logfiles, sensor data, social media feeds, and financial transactions, among others. The data is sent in small sizes (or packets) to allow real-time insights and reactions. The nature of streaming data is that it is in constant motion and does not have a finite beginning or end."  (Tomer Shiranet al, "Apache Iceberg: The Definitive Guide Data Lakehouse Functionality, Performance, and Scalability on the Data Lake", 2024)

"Table branching in Apache Iceberg allows you to create independent lineages of snapshots, each with its own lifecycle. A branch is essentially a named reference pointing to a divergent chain of snapshots. Each branch points to the head of the branch, which is the most recent snapshot in the branch’s snapshot history. Each branch also has settings for maximum snapshot age and minimum number of snapshots that should exist in the branch." (Tomer Shiranet al, "Apache Iceberg: The Definitive Guide Data Lakehouse Functionality, Performance, and Scalability on the Data Lake", 2024)

"Tabular is a cloud-native headless warehouse (a layer for storage management decoupled from any particular query engine or compute) and automation platform offering a unified solution for managing analytic data with Apache Iceberg tables. It is a centralized hub for Apache Iceberg data storage and cataloging, focusing on versatility and efficiency. Tabular features an access control framework designed to govern and secure access to platform resources. [...] Tabular adopts an RBAC model, where access privileges are assigned to roles, and roles are subsequently assigned to individuals or other roles." (Tomer Shiranet al, "Apache Iceberg: The Definitive Guide Data Lakehouse Functionality, Performance, and Scalability on the Data Lake", 2024)

"The Apache Iceberg table format provides high-performance queries during reads and writes, allowing you to run online analytical processing (OLAP) workloads directly on the data lake. What facilitates this performance is the way the various components of the Iceberg table format are designed. It is therefore critical to understand the structure of these components so that query engines can effectively use them for faster query planning and execution." (Tomer Shiranet al, "Apache Iceberg: The Definitive Guide Data Lakehouse Functionality, Performance, and Scalability on the Data Lake", 2024)

"The data lakehouse architecture decouples the storage and compute from data lakes and brings in mechanisms that allow for more data warehouse– like functionality (ACID transactions, better performance, consistency, etc.). Enabling this functionality are data lake table formats that eliminate all the previous issues with the Hive table format. You store the data in the same places you would store it with a data lake, you use the query engines you would use with a data lake, and your data is stored in the same formats it would be stored in on a data lake. What truly transforms your world from 'read-only' data to a 'center of my data world' data lakehouse is the table format providing a metadata/abstraction layer between the engine and storage for them to interact more intelligently." (Tomer Shiranet al, "Apache Iceberg: The Definitive Guide Data Lakehouse Functionality, Performance, and Scalability on the Data Lake", 2024)

"The metadata layer in Apache Iceberg consists of three components: metadata files, manifest lists, and manifest files. Each time a query engine writes something to an Iceberg table, a new metadata file is created atomically and is defined as the latest version of the metadata file. This ensures that a linear history of the table commits, and it helps during scenarios such as concurrent writes (i.e., multiple engines writing data simultaneously). Also, during read operations, engines will always see the latest version of the table. Query engines interact with the manifest lists to get information about partition specifications that help them skip the nonrequired manifest files for faster performance. Finally, information from the manifest files, such as upper and lower bounds for a specific column, null value counts, and partition-specific data, is used by the engine for file pruning." (Tomer Shiranet al, "Apache Iceberg: The Definitive Guide Data Lakehouse Functionality, Performance, and Scalability on the Data Lake", 2024)

"The metadata layer is an integral part of an Iceberg table’s architecture and contains all the metadata files for an Iceberg table. It’s a tree structure that tracks the datafiles and metadata about them as well as the operations that resulted in their creation. This tree structure is made up of three file types, all of which are colocated with the datafiles: manifest files, manifest lists, and metadata files. The metadata layer is essential for efficiently managing large datasets and enabling core features such as time travel and schema evolution." (Tomer Shiranet al, "Apache Iceberg: The Definitive Guide Data Lakehouse Functionality, Performance, and Scalability on the Data Lake", 2024)

"The practice of isolating changes to your data in a Git-like branch can be significantly valuable in modern data workflows, which is why more practitioners should begin adopting it. This approach allows for the separation of different lines of work, enabling developers to make changes independently without interfering with other developers’ work or destabilizing the main codebase. It’s akin to having multiple parallel universes, where changes in one universe do not affect the others. You can experiment, make mistakes, and learn without the fear of impacting the broader system." (Tomer Shiranet al, "Apache Iceberg: The Definitive Guide Data Lakehouse Functionality, Performance, and Scalability on the Data Lake", 2024) 

"The write process in Apache Iceberg involves a series of steps that enable query engines to efficiently insert and update data. When a write query is initiated, it is sent to the engine for parsing. The catalog is then consulted to ensure consistency and integrity in the data and to write the data as per the defined partition strategies. The datafiles and metadata files are then written based on the query. Finally, the catalog file is updated to reflect the latest metadata, enabling subsequent read operations to access the most up-to-date version of the data." (Tomer Shiranet al, "Apache Iceberg: The Definitive Guide Data Lakehouse Functionality, Performance, and Scalability on the Data Lake", 2024)

"While Apache Iceberg is file format agnostic, in the real world the file format most commonly used is Apache Parquet. Parquet is most common because its columnar structure provides large performance gains for OLAP workloads over row-based file formats, and it has become the de facto standard in the industry, meaning basically every engine and tool supports Parquet. Its columnar structure lays the foundation for performance features such as the ability for a single file to be split multiple ways for increased parallelism, statistics for each of these split points, and increased compression, which provides lower storage volume and higher read throughput." (Tomer Shiranet al, "Apache Iceberg: The Definitive Guide Data Lakehouse Functionality, Performance, and Scalability on the Data Lake", 2024)

"While data warehouses provided a mechanism for running analytics on structured data, they still had several issues: (i) A data warehouse could only store structured data. (ii) Storage in a data warehouse is generally more expensive than on-prem Hadoop clusters or cloud object storage. (iii) Storage and compute in traditional on-prem data warehouses are often commingled and therefore cannot be scaled separately. More storage costs came with more compute costs whether you needed the compute power or not. Addressing these issues required an alternative storage solution that was cheaper and could store all your data without the need to conform to a fixed schema. This alternative solution was the data lake." (Tomer Shiranet al, "Apache Iceberg: The Definitive Guide Data Lakehouse Functionality, Performance, and Scalability on the Data Lake", 2024)

"When it comes to securing your Apache Iceberg tables at the catalog level, several advantages and disadvantages come into play. On the positive side, catalogs offer centralized metadata management, enabling the enforcement of consistent governance policies and metadata-driven security measures. They also support fine-grained access control at this level, granting comprehensive authority over who can access and manipulate tables and databases. Furthermore, catalogs abstract the underlying file structure, simplifying data access for both users and tools. However, there are drawbacks, including the dependency on the catalog for metadata and access control, which means that any catalog issues can impact data access. Additionally, managing intricate access control policies at the catalog level can be challenging depending on the chosen solution. As the catalog grows, handling permissions and metadata can become more intricate, affecting scalability."  (Tomer Shiranet al, "Apache Iceberg: The Definitive Guide Data Lakehouse Functionality, Performance, and Scalability on the Data Lake", 2024)

"When securing your Apache Iceberg tables at the semantic layer level, there are advantages and disadvantages to consider. On the positive side, this layer offers unified access to data, serving as a consistent entry point for queries and enabling standardized data governance and security policies. It also provides data abstraction, simplifying the data view for end users and tools, thus facilitating easier querying and analysis. However, there are drawbacks, including the risk of a single point of failure when relying solely on the semantic layer, potentially impacting query availability." (Tomer Shiranet al, "Apache Iceberg: The Definitive Guide Data Lakehouse Functionality, Performance, and Scalability on the Data Lake", 2024) 

"You can optimize the table’s row-level update patterns to take one of two forms: copy-on-write (COW) or merge-on-read (MOR). When using COW, for a change of any row in a given datafile, the entire file is rewritten (with the row-level change made in the new file) even if a single record in it is updated. When using MOR, for any row-level updates, only a new file that contains the changes to the affected row that is reconciled on reads is written. This gives flexibility to speed up heavy update and delete workloads." (Tomer Shiranet al, "Apache Iceberg: The Definitive Guide Data Lakehouse Functionality, Performance, and Scalability on the Data Lake", 2024)

17 August 2026

🏭𝐌𝐢𝐜𝐫𝐨𝐬𝐨𝐟𝐭 𝐅𝐚𝐛𝐫𝐢𝐜: 𝐃𝐚𝐭𝐚 𝐖𝐚𝐫𝐞𝐡𝐨𝐮𝐬𝐞 (𝐓𝐞𝐜𝐡𝐧𝐢𝐜𝐚𝐥 𝐎𝐯𝐞𝐫𝐯𝐢𝐞𝐰)

 Introduction (Some Background)

Typically, PowerPoint slides and similar content must be broken in small pieces and structured in such a way that the audience can digest the information presented. Thus, a presentation ends up spreading over multiple slides that must be structured in such a way that it facilitates also digestion, retention, and whatever further aspects are targeted. Conversely, on social networks the average author/publisher has only a small chance of capturing an audience's attention, given that the competition for readers' attention increases exponentially in the long sequence of posts. So, what information would we show for this purpose? 

When I want to learn something, typically I need a few pieces of information/knowledge that would allow me to anchor and integrate the text into existing knowledge. It usually starts with high-level definitions of the main concepts that reflect the various aspects that would help me associate and differentiate the respective concepts from similar concepts or knowledge. The volume of such information depends on many aspects - the complexity of the concepts and the contexts they belong to, how many similar concepts or metaphors are available, the gaps available, analogies and differentiators, etc.

A high-level list of the main capabilities for the respective concept(s) would further allow a (wider) surface to anchor the various information of interest. No matter how much text can be included, we shouldn't forget that a (well-chosen) picture is (often) worth a thousand words. Therefore, a well-chosen image that depicts a high-level representation of the concepts/ideas presented, the architecture or even a metaphor can have a considerable impact on the readers.  

Ideally the image should serve as a sketch or sample of the finished product. Then, even if from the used representation one can guess what are the ingredients used, the difference between a good dish and a fiasco often resides in details. Like in preparing a dish, one needs to know what ingredients are needed and how they must be prepared and used together, for the maximum effect. An experienced cook needs at least the list of ingredients and some general information on how the dish differentiates from other dishes. The more inexperienced the cook, the more information needs to be provided and somewhere a line must be drawn, otherwise a simple recipe becomes the cookbook itself. Therefore, like in any cookbook, I must assume that some basic knowledge is available!

So, as part of the learning/teaching process, I started a series of slides on Microsoft Fabric that should help me narrow down the recipes for delivering great products. The information comes from training material, various presentations delivered by Microsoft or third-parties, the various books and other technical material I read over the years. 

Let's start with the basics - the (data) warehouse!

   📣Technical Overview 

    

Conclusion

The slide barely scratches the surface, especially if we consider it from a broader context - what the average professional must know. Even if the gap between the presented information and a business case, for example, or anything similar capable of convincing the audience is considerable, the slide should serve as a starting point, if not a foundation on which something durable can be built. 

Enjoy the ride and feel free to like it, download it, respectively share it further!

21 June 2025

🏭🗒️Microsoft Fabric: Result Set Caching in SQL Analytics Endpoints [Notes] 🆕

Disclaimer: This is work in progress intended to consolidate information from various sources for learning purposes. For the latest information please consult the documentation (see the links below)! 

Last updated: 21-Jun-2025

[Microsoft Fabric] Result Set Caching in SQL Analytics Endpoints

  • {def} built-in performance optimization for Warehouse and Lakehouse that improves read latency [1]
    • fully transparent to the user [3]
    • persists the final result sets for applicable SELECT T-SQL queries
      • caches all the data accessed by a query [3]
      • subsequent runs that "hit" cache will process just the final result set
        • can bypass complex compilation and data processing of the original query[1]
          • ⇐ returns subsequent queries faster [1]
      • the cache creation and reuse is applied opportunistically for queries
    • works on
      • warehouse tables
      • shortcuts to OneLake sources
      • shortcuts to non-Azure sources
    • the management of cache is handled automatically [1]
      • regularly evicts cache as needed
    • as data changes, result consistency is ensured by invalidating cache created earlier [1]
  • {operation} enable setting
    • via ALTER DATABASE <database_name> SET RESULT_SET_CACHING ON
  • {operation} validate setting
    • via SELECT name, is_result_set_caching_on FROM sys.databases
  • {operation} configure setting
    • configurable at item level
      • once enabled, it can then be disabled 
        • at the item level
        • for individual queries
          • e.g. debugging or A/B testing a query
        • via OPTION ( USE HINT ('DISABLE_RESULT_SET_CACHE') 
    • {default} during the preview, result set caching is off for all items [1]
  • [monitoring] 
    • via Message Output
      • applicable to Fabric Query editor, SSMS
      • the statement "Result set cache was used" is displayed after query execution if the query was able to use an existing result set cache
    • via queryinsights.exec_requests_history system view
      • result_cache_hit displays indicates result set cache usage for each query execution [1]
        • {value} 2: the query used result set cache (cache hit)
        • {value} 1: the query created result set cache
        • {value} 0: the query wasn't applicable for result set cache creation or usage [1]
          • {reason} the cache no longer exists
          • {reason} the cache was invalidated by a data change, disqualifying it for reuse [1]
          • {reason} query isn't deterministic
            • isn't eligible for cache creation [1]
          • {reason} query isn't a SELECT statement
  • [warehousing] 
    • {scenario} analytical queries that process large amounts of data to produce a relatively small result [1]
    • {scenario} workloads that trigger the same analytical queries repeatedly [1]
      • the same heavy computation can be triggered multiple times, even though the final result remains the same [1]

References:
[1] Microsoft Learn (2025) Result set caching (preview) [link]
[2] Microsoft Fabric Update Blog (2025) Result Set Caching for Microsoft Fabric Data Warehouse (Preview) [link|aka]
[3] Microsoft Learn (2025) In-memory and disk caching [link]
[4] Microsoft Learn (2025) Performance guidelines in Fabric Data Warehouse [link] 

Resources:
[R1] Microsoft Fabric (2025) Fabric Update - June 2025 [link]

Acronyms:
MF - Microsoft Fabric
SSMS - SQL Server Management Studio

24 May 2025

🏭🗒️Microsoft Fabric: Materialized Lake Views (MLV) [Notes] 🆕🗓️

Disclaimer: This is work in progress intended to consolidate information from various sources for learning purposes. For the latest information please consult the documentation (see the links below)! 

Last updated: 27-Jul-2025

-- create schema
CREATE SCHERA IF NOT EXISTS <lakehouse_name>.<schema_name>

-- create a materialized view
CREATE MATERIALIZED VIEW IF NOT EXISTS <lakehouse_name>.<schema_name>.<view_name> 
[(
    CONSTRAINT <constraint_name> CHECK (<constraint>) ON MISMATCH DROP 
)] 
[PARTITIONED BY (col1, col2, ... )] 
[COMMENT “description or comment”] 
[TBLPROPERTIES (“key1”=”val1”, “key2”=”val2”, 
AS 
SELECT ...
FROM ...
-- WHERE ...
--GROUP BY ...

[Microsoft Fabric] Materialized Lake Views (MLVs)

  • {def} persisted, continuously updated view of data [1]
    • {benefit} allows to build declarative data pipelines using SQL, complete with built-in data quality rules and automatic monitoring of data transformations
      • simplifies the implementation of multi-stage Lakehouse processing [1]
        • ⇐ aids in the creation, management, and monitoring of views [3]
        • ⇐ improves transformations through a declarative approach [3]
        • streamline data workflows
        • enable developers to focus on business logic [1]
          • ⇐ not on infrastructural or data quality-related issues [1]
        • the views can be created in a notebook [2]
    • {benefit} allows developers visualize lineage across all entities in lakehouse, view the dependencies, and track its execution progress [3]
      • can have data quality constraints enforced and visualized for every run, showing completion status and conformance to data quality constraints defined in a single view [1]
      • empowers developers to set up complex data pipelines with just a few SQL statements and then handle the rest automatically [1]
        • faster development cycles 
        • trustworthy data
        • quicker insights
  • {goal} process only the new or changed data instead of reprocessing everything each time [1]
    • ⇐  leverages Delta Lake’s CDF under the hood
      • ⇒ it can update just the portions of data that changed rather than recompute the whole view from scratch [1]
  • {operation} creation
    • allows defining transformations at each layer [1]
      • e.g. aggregation, projection, filters
    • allows specifying certain checks that the data must meet [1]
      • incorporate data quality constraints directly into the pipeline definition
    • via CREATE MATERIALIZED LAKE VIEW
      • the SQL syntax is declarative and Fabric figures out how to produce and maintain it [1]
  • {operation} refresh
    • refreshes only when its source has new data [1]
      • if there’s no change, it can skip running entirely (saving time and resources) [1]
    • via REFRESH MATERIALIZED LAKE VIEW [workspace.lakehouse.schema].MLV_Identifier [FULL];
  • {operation} list views from schema [3]
    • via SHOW MATERIALIZED LAKE VIEWS <IN/FROM> Schema_Name;
  • {opetation} retrieve definition
    • via SHOW CREATE MATERIALIZED LAKE VIEW MLV_Identifier;
  • {operstion} update definition
    • via ALTER MATERIALIZED LAKE VIEW MLV_Identifier RENAME TO MLV_Identifier_New;
  • {operstion} drop view
    • via DROP MATERIALIZED LAKE VIEW MLV_Identifier;
    • {warning} dropping or renaming a materialized lake view affects the lineage view and scheduled refresh [3]
    • {recommendation} update the reference in all dependent materialized lake views [3]
  • {operation} schedule view run
    • lets users set how often the MLV should be refreshed based on business needs and lineage execution timing [5]
    • depends on
      • data update frequency: the frequency with which the data is updated [5]
      • query performance requirements: Business requirement to refresh the data in defined frequent intervals [5]
      • system load: optimizing the time to run the lineage without overloading the system [5]
  • {operation} view run history
    • users can access the last 25 runs including lineage and run metadata
      • available from the dropdown for monitoring and troubleshooting
  • {concept} lineage
    • the sequence of MLV that needs to be executed to refresh the MLV once new data is available [5]
  • {feature} automatically generate a visual report that shows trends on data quality constraints 
    • {benefit} allows to easily identify the checks that introduce maximum errors and the associated MLVs for easy troubleshooting [1]
  • {feature} can be combined with Shortcut Transformation feature for CSV ingestion 
    • {benefit} facilitate the building of end-to-end Medallion architectures
  • {feature} dependency graph
    • allows to see the dependencies existing between the various objects [2]
      • ⇐ automatically generated [2]
  • {feature} data quality
    • {benefit} allows to compose precise queries to exclude poor quality data from the source tables [5]
    • [medallion architecture] ensuring data quality is essential at every stage of the architecture [5]
    • maintained by setting constraints when defining the MLVs [5]
    • {action} FAIL
      • stops refreshing an MLV if any constraint is violated [5]
      • {default} halt is at the first instance
        • even without specifying the FAIL keyword [5]
        • takes precedence over DROP
    • {action} DROP
      • processes the MLV and removes records that don't meet the specified constrain [5]
        • provides the count of removed records in the lineage view [5]
    • {constraint} updating data quality constraints after creating an MLV isn't supported [5]
      • ⇐ the MLV must be recreated
    • {constraint} the use of functions and pattern search with operators in constraint condition is restricted [5]
      • e.g. LIKE, regex 
    • {known issue} the creation and refresh of an MLV with a FAIL action in constraint may result in a "delta table not found" error
      • {recommendation} recreate the MLV and avoid using the FAIL action [5] 
      • {feature} data quality report
        • built-in Power BI dashboard that shows several aggregated metrics [2]
    • {feature} monitor hub
      • centralized portal to browse MLV runs in the lakehouse [7]
      • {operation} view runs' status [7]
      • {operation} search and filter the runs [7]
        • based on different criteria
      • {operation} cancel in-progress run [7]
      • {operation} drill down run execution details [7]
    • doesn't support
      • {feature|planned} PySpark [3]
      • {feature|planned} incremental refresh [3]
      • {feature|planned} integration with Data Activator [3]
      • {feature|planned} API [3]
      • {feature|planned} cross-lakehouse lineage and execution [3]
      • {limitation} Spark properties set at the session level aren't applied during scheduled lineage refresh [4]
      • {limitation} creation with delta time-travel [4]
      • {limitation} DML statements [4]
      • {limitation} UDFs in CTAS [4] 
      • {limitation} temporary views can't be used to define MLVs [4]
    •  {recommendation} create all MLVs for a workspace within a single Lakehouss [8]
      • allows to ensure a consolidated and clear representation in the DAG view [8]

    References:
    [1] Microsoft Fabric Update Blog (2025) Simplifying Medallion Implementation with Materialized Lake Views in Fabric [link|aka]
    [2] Power BI Tips (2025) Microsoft Fabric Notebooks with Materialized Views - Quick Tips [link]
    [3] Microsoft Learn (2025) What are materialized lake views in Microsoft Fabric? [link]
    [4] Microsoft Learn (2025) Materialized lake views Spark SQL reference [link]
    [5] Microsoft Learn (2025) Manage Fabric materialized lake views lineage [link] 
    [6] Microsoft Learn (2025) Data quality in materialized lake views [link]
    [7] Microsoft Learn (2025) Monitor materialized lake views [link] 
    [8] Microsoft Learn (2025) Development and Monitoring [link]

    Resources:
    [R1] Databricks (2025) Use materialized views in Databricks SQL [link]
    [R2] Microsoft Learn (2025) Implement medallion architecture with materialized lake views [link]
    [R3] Mastering Declarative Data Transformations with Materialized Lake Views [link]

    Acronyms:
    API - Application Programming Interface
    CDF - Change Data Feed
    CTAS - Create Tables As Select
    DML - Data Manipulation Language 
    ETL - Extract, Transfer, Load
    MF - Microsoft Fabric
    MLV - Materialized Lake views
    UDF - User-defined functions

    26 April 2025

    🏭🗒️Microsoft Fabric: Deployment Pipelines [Notes]

    Disclaimer: This is work in progress intended to consolidate information from various sources for learning purposes. For the latest information please consult the documentation (see the links below)! 

    Last updated: 26-Apr-2025

    [Microsoft Fabric] Deployment Pipelines

    • {def} a structured process that enables content creators to manage the lifecycle of their organizational assets [5]
      • enable creators to develop and test content in the service before it reaches the users [5]
        • can simplify the deployment process to development, test, and production workspaces [5]
        • one Premium workspace is assigned to each stage [5]
        • each stage can have 
          • different configurations [5]
          • different databases or different query parameters [5]
    • {action} create pipeline
      • from the deployment pipelines entry point in Fabric [5]
        • creating a pipeline from a workspace automatically assigns it to the pipeline [5]
      • {action} define how many stages it should have and what they should be called [5]
        • {default} has three stages
          • e.g. Development, Test, and Production
          • the number of stages can be changed anywhere between 2-10 
          • {action} add another stage,
          • {action} delete stage
          • {action} rename stage 
            • by typing a new name in the box
          • {action} share a pipeline with others
            • users receive access to the pipeline and become pipeline admins [5]
          • ⇐ the number of stages are permanent [5]
            • can't be changed after the pipeline is created [5]
      • {action} add content to the pipeline [5]
        • done by assigning a workspace to the pipeline stage [5]
          • the workspace can be assigned to any stage [5]
      • {action|optional} make a stage public
        • {default} the final stage of the pipeline is made public
        • a consumer of a public stage without access to the pipeline sees it as a regular workspace [5]
          • without the stage name and deployment pipeline icon on the workspace page next to the workspace name [5]
      • {action} deploy to an empty stage
        • when finishing the work in one pipeline stage, the content can be deployed to the next stage [5] 
          • deployment can happen in any direction [5]
        • {option} full deployment 
          • deploy all content to the target stage [5]
        • {option} selective deployment 
          • allows select the content to deploy to the target stage [5]
        • {option} backward deployment 
          • deploy content from a later stage to an earlier stage in the pipeline [5] 
          • {restriction} only possible when the target stage is empty [5]
      • {action} deploy content between pages [5]
        • content can be deployed even if the next stage has content
          • paired items are overwritten [5]
      • {action|optional} create deployment rules
        • when deploying content between pipeline stages, allow changes to content while keeping some settings intact [5] 
        • once a rule is defined or changed, the content must be redeployed
          • the deployed content inherits the value defined in the deployment rule [5]
          • the value always applies as long as the rule is unchanged and valid [5]
      • {feature} deployment history 
        • allows to see the last time content was deployed to each stage [5]
        • allows to to track time between deployments [5]
    • {concept} pairing
      • {def} the process by which an item in one stage of the deployment pipeline is associated with the same item in the adjacent stage
        • applies to reports, dashboards, semantic models
        • paired items appear on the same line in the pipeline content list [5]
          • ⇐ items that aren't paired, appear on a line by themselves [5]
        • the items remain paired even if their name changes
        • items added after the workspace is assigned to a pipeline aren't automatically paired [5]
          • ⇐ one can have identical items in adjacent workspaces that aren't paired [5]
    • [lakehouse]
      • can be removed as a dependent object upon deployment [3]
      • supports mapping different Lakehouses within the deployment pipeline context [3]
      • {default} a new empty Lakehouse object with same name is created in the target workspace [3]
        • ⇐ if nothing is specified during deployment pipeline configuration
        • notebook and Spark job definitions are remapped to reference the new lakehouse object in the new workspace [3]
        • {warning} a new empty Lakehouse object with same name still is created in the target workspace [3]
        • SQL Analytics endpoints and semantic models are provisioned
        • no object inside the Lakehouse is overwritten [3]
        • updates to Lakehouse name can be synchronized across workspaces in a deployment pipeline context [3] 
    • [notebook] deployment rules can be used to customize the behavior of notebooks when deployed [4]
      • e.g. change notebook's default lakehouse [4]
      • {feature} auto-binding
        • binds the default lakehouse and attached environment within the same workspace when deploying to next stage [4]
    • [environment] custom pool is not supported in deployment pipeline
      • the configurations of Compute section in the destination environment are set with default values [6]
      • ⇐ subject to change in upcoming releases [6]
    • [warehouse]
      • [database project] ALTER TABLE to add a constraint or column
        • {limitation} the table will be dropped and recreated when deploying, resulting in data loss
      • {recommendation} do not create a Dataflow Gen2 with an output destination to the warehouse
        • ⇐ deployment would be blocked by a new item named DataflowsStagingWarehouse that appears in the deployment pipeline [10]
      • SQL analytics endpoint is not supported
    • [Eventhouse]
      • {limitation} the connection must be reconfigured in destination that use Direct Ingestion mode [8]
    • [EventStream]
      • {limitation} limited support for cross-workspace scenarios
        • {recommendation} make sure all EventStream destinations within the same workspace [8]
    • KQL database
      • applies to tables, functions, materialized views [7]
    • KQL queryset
      • ⇐ tabs, data sources [7]
    • [real-time dashboard]
      • data sources, parameters, base queries, tiles [7]
    • [SQL database]
      • includes the specific differences between the individual database objects in the development and test workspaces [9]
    • can be also used with

      References:
      [1] Microsoft Learn (2024) Get started with deployment pipelines [link]
      [2] Microsoft Learn (2024) Implement continuous integration and continuous delivery (CI/CD) in Microsoft Fabric [link]
      [3] Microsoft Learn (2024)  Lakehouse deployment pipelines and git integration (Preview) [link]
      [4] Microsoft Learn (2024) Notebook source control and deployment [link] 
      [5] Microsoft Learn (2024) Introduction to deployment pipelines [link]
      [6] Environment Git integration and deployment pipeline [link]
      [7] Microsoft Learn (2024) Microsoft Learn (2024) Real-Time Intelligence: Git integration and deployment pipelines (Preview) [link]
      [8] Microsoft Learn (2024) Eventstream CI/CD - Git Integration and Deployment Pipeline [link]
      [9] Microsoft Learn (2024) Get started with deployment pipelines integration with SQL database in Microsoft Fabric [link]
      [10] Microsoft Learn (2025) Source control with Warehouse (preview) [link] 

      Resources:

      Acronyms:
      CLM - Content Lifecycle Management
      UAT - User Acceptance Testing

      24 April 2025

      💎🏭SQL Reloaded: Microsoft Fabric's Lakehouses at Work (Part I: Proof-of-Concept)


      Introduction

      One way to work with the data files existing in organization is to import them into a lakehouse and build a data model based on them that can be reused in the various solutions (incl. Power BI). As a reminder, a lakehouse is a data architecture platform for storing, managing, and analyzing structured and unstructured data in a single location.

      The tutorials available on lakehouses are pretty useful for getting an idea how to start, though probably each seasoned professional has his/her way of doing things, at least for testing the capabilities before building a proper solution. The target is thus, to create the minimum for testing the capabilities needed for a proof-of-concept solution. 

      The files used in this post are available on Microsoft's GitHub. Download the files and store them to be easily available for the next steps. The following files were considered for the current post: customers.csv, orders.csv and products.csv.

      Create the Lakehouse

      It's recommended to have a naming convention in place for the various items created in a workspace, e.g. a combination between item type (lakehouse, warehouse), system type (Prod, UAT, Dev, PoC) and eventually department (e.g. FIN, SCM, HR, etc.). One should try to balance between meaning and usefulness. Ideally, one should use 2 maximum 4 letters for each part encoded in the name. For example, the following scripts were created in the LH_SCM_PoC lakehouse. 

      More complex naming conventions can include the system (e.g. D365, CRM, EBS) or the company. The target is to easily identify the systems, independently how complex the rules are. Given that it can become challenging to rename the schemas afterwards, ideally the naming convention should be available from the early stages. 

      Create the Schema

      A lakehouse comes with a dbo schema available by default, though it's recommended to create meaningful schema(s) as needed. The schemas should ideally reflect the domain of the data (e.g. departments or other key areas) and the schemas shouldn't change when the objects are deployed between the different environments. Upon case, one should consider creating multiple schemas that reflect the model's key areas. The names should be simple and suggestive.

      -- create schema
      CREATE Schema Orders
      

      Create a Staging Area

      The next step is to create a staging area where the files in scope can be made available and then further loaded in the lakehouse. One needs to compromise between creating a deep hierarchical structure that reflects the business structure and the need to easily identify, respectively manage the files. An hierarchical structure with 1-2 level could provide the needed compromise, though each additional level tends to increase the complexity. 

      One should also consider rules for archiving or even deleting the files.

      Upload the Files

      Microsoft Fabric allows users to upload multiple files together into a single step. Ideally the files should have proper names for each column, otherwise overheads deriving from this may appear later in the process. 

      When the files are available in multiple folders in a complex hierarchical structure, a set of shortcuts could help in their management.

      Load the Data

      A file's data can be loaded into the lakehouse on the fly by providing a valid table name:
      Files >> SCM_Orders >> (select file) >> Load to Tables >> new table >> Load file to new table >> (provide information) >> Load

      Load file to new table


      Of course, the table's name must be unique within the Schema and the further properties must define files' definition. 

      One should consider loading first a couple of tables, performing a rough validation of the data imported, and only after that the remaining tables can be imported. This allows to identify the issues that typically lead to reimports of the data (wrong formatting, invalid column names, duplicated files, etc.) or rework.

      If the files have different characteristics (e.g. delimiters, number of attributes/records, special data types), one should consider this in the initial scope and have at least one example from each category. 

      Review the Metadata

      Once the files were made available, there's the tendency to start directly with the development without analyzing the data, or equally important, the metadata available. To review the metadata of the tables newly created, one can use the objects from the standard INFORMATION_SCHEMA (see post):

      -- retrieve the list of tables
      SELECT * 
      FROM INFORMATION_SCHEMA.TABLES
      
      WHERE TABLE_SCHEMA = 'orders'
      ORDER BY TABLE_SCHEMA  

      Further on, one can review columns' definition:
       
      -- retrieve column metadata
      SELECT TABLE_CATALOG
      , TABLE_SCHEMA
      , TABLE_NAME
      , COLUMN_NAME
      , ORDINAL_POSITION
      , DATA_TYPE
      , CHARACTER_MAXIMUM_LENGTH
      , NUMERIC_PRECISION
      , NUMERIC_SCALE
      , DATETIME_PRECISION
      , CHARACTER_SET_NAME
      FROM INFORMATION_SCHEMA.COLUMNS
      WHERE TABLE_SCHEMA = 'orders'
      ORDER BY ORDINAL_POSITION

      It's a good idea to save the metadata to a file and use it later for reviews, respectively for metadata management, when no other solution is in place for the same (e.g. Purview). That's useful also for the people with limited or no access to the workspace. 

      Alternatively, one can use a notebook with the following SQL-based commands: 

      %%sql
      
      DESCRIBE TABLE LH_SCM_PoC.orders.sales;
      
      DESCRIBE TABLE EXTENDED LH_SCM_PoC.orders.sales;
      

      One can even provide meaningful descriptions for each table and its attributes via scripts like the ones below, however it might be a good idea to do this in the later phases of the PoC, when the logic become stable:

      %%sql
      
      -- modify a table's COMMENT
      COMMENT ON TABLE LH_SCM_PoC.orders.sales IS 'Customer sales orders';
      
      -- modify columns' COMMENT for an existing table
      ALTER TABLE LH_SCM_DWH.orders.sales  
      ALTER COLUMN SalesOrderNumber COMMENT 'Sales Order Number';
      

      Data Validation

      Before diving into building any business logic, besides identifying the primary, foreign keys and further attributes used in bringing the data together, it's recommended to get an overview of data's intrinsic and extrinsic characteristics relevant to the analysis. Some of the rules used typically for studying the quality of data apply to some extent also in here, though one needs to prioritize accordingly, otherwise one replicates the effort that's typically part of the Data Management initiatives. 

      In addition, it's important to check how much the identified issues impact the business logic, respectively on whether the issues can be corrected to match the expectations. Often, no logic can compensate for major  data quality issues, and this can also affect  PoC's results as soon as the outcomes are validated against the expectations! 

      Data Understanding 

      Further on, it makes sense to get a high-level understanding of the data by looking at the distribution of values, respectively at the records participating in the joins. Of course, more similar queries can be built, though again, one should try to focus on the most important aspects!

      The analysis could for example consider the following points:

      /* validation of Products */
      
      -- review duplicated product numbers (should be 0)
      SELECT ProductName
      , count(*) RecordCount
      FROM orders.products
      GROUP BY ProductName
      HAVING count(*)>1
      
      -- review most (in)expensive products
      SELECT top 100 ProductID
      , ProductName
      , Category
      , ListPrice 
      FROM orders.products
      ORDER BY ListPrice DESC --ASC
      
      -- review category distribution
      SELECT Category
      , count(*) RecordCount 
      FROM orders.products
      GROUP BY Category
      ORDER BY RecordCount DESC
      
      -- review price ranges (
      SELECT Len(floor(ListPrice)) RangeCount
      , count(*) RecordCount 
      FROM orders.products
      GROUP BY Len(floor(ListPrice)) 
      ORDER BY RangeCount DESC
      
      /* validation of Customers */
      
      -- duplicated email address 
      SELECT CST.CustomerID
      , CST.FirstName
      , CST.LastName 
      , CST.EmailAddress 
      , DUP.RecordCount
      FROM (-- duplicates
      	SELECT EmailAddress
      	, count(*) RecordCount 
      	FROM orders.customers 
      	GROUP BY EmailAddress 
      	HAVING count(*)>1
      	) DUP
      	JOIN orders.customers CST
      	   ON DUP.EmailAddress = CST.EmailAddress
      ORDER BY DUP.RecordCount DESC
      , DUP.EmailAddress 
      
      -- duplicated Customer names (not necessarily duplicates)
      SELECT CST.CustomerID
      , CST.FirstName
      , CST.LastName 
      , CST.EmailAddress 
      , DUP.RecordCount
      FROM (-- duplicates
      	SELECT FirstName
      	, LastName
      	, count(*) RecordCount 
      	FROM orders.customers 
      	GROUP BY FirstName
      	, LastName 
      	HAVING count(*)>1
      	) DUP
      	JOIN orders.customers CST
      	   ON DUP.FirstName = CST.FirstName
            AND DUP.LastName = CST.LastName
      ORDER BY DUP.RecordCount DESC
      , DUP.FirstName
      , DUP.LastName
      
      /* validation of Orders */
      
      -- review a typical order
      SELECT SalesOrderID
      , OrderDate
      , CustomerID
      , LineItem
      , ProductID
      , OrderQty
      , LineItemTotal
      FROM orders.orders
      WHERE SalesOrderID = 71780
      ORDER BY SalesOrderID 
      , LineItem
      
      -- review orders' distribution by month
      SELECT Year(OrderDate) Year
      , Month(OrderDate) Month
      , count(*) RecordCount
      FROM orders.orders
      GROUP BY Year(OrderDate) 
      , Month(OrderDate) 
      ORDER BY Year
      , Month
      
      -- checking for duplicates
      SELECT SalesOrderID
      , LineItem
      , count(*) RecordCount
      FROM orders.orders ord 
      GROUP BY SalesOrderID
      , LineItem
      HAVING count(*)>1
      
      -- checking for biggest orders
      SELECT SalesOrderID
      , count(*) RecordCount
      FROM orders.orders ord 
      GROUP BY SalesOrderID
      HAVING count(*) > 10
      ORDER BY NoRecords DESC
      
      -- checking for most purchased products
      SELECT ProductID
      , count(*) NoRecords
      FROM orders.orders ord 
      GROUP BY ProductID
      HAVING count(*) > 8
      ORDER BY NoRecords DESC
      
      -- checking for most active customers
      SELECT CustomerID
      , count(*) RecordCount
      FROM orders.orders ord 
      GROUP BY CustomerID
      HAVING count(*) > 10
      ORDER BY RecordCount DESC
      
      /* join checks */
      
      -- Prders without Product (should be 0)
      SELECT count(*) RecordCount
      FROM orders.orders ord 
      	 LEFT JOIN orders.products prd
      	   ON ord.ProductID = prd.ProductID
      WHERE prd.ProductID IS NULL
      
      -- Prders without Customer (should be 0)
      SELECT count(*) RecordCount
      FROM orders.orders ORD 
      	 LEFT JOIN orders.customers CST
      	   ON ORD.CustomerID = CST.CustomerID
      WHERE CST.CustomerID IS NULL
      
      -- Products without Orders (153 records)
      SELECT count(*) RecordCount
      FROM orders.products prd
      	 LEFT JOIN orders.orders ord 
      	   ON prd.ProductID = ord.ProductID 
      WHERE ord.ProductID IS NULL
      
      
      -- Customers without Orders (815 records)
      SELECT count(*) RecordCount
      FROM orders.customers CST
      	 LEFT JOIN orders.orders ORD
      	   ON ORD.CustomerID = CST.CustomerID
      WHERE ORD.CustomerID IS NULL
      

      The more tables are involved, the more complex the validation logic can become. One should focus on the most important aspects.

      Building the Logic

      Once one has an acceptable understanding of the data entities involved and the relation between them, it's time to build the needed business logic by joining the various tables at the various levels of detail. One can focus on the minimum required, respectively attempt to build a general model that can address a broader set of requirements. For the PoC it's usually recommended to start small by addressing the immediate requirements, though some flexibility might be needed for exploring the data and preparing the logic for a broader set of requirements. Independently of the scope, one should consider a set of validations. 

      Usually, it makes sense to encapsulate the logic in several views or table-valued functions that reflect the logic for the main purposes and which allow a high degree of reuse (see [1]). Of course, one can use the standard approach for modelling the bronze, silver, respectively the gold layers adopted by many professionals. For a PoC, even if  that's not mandatory, it might still be a good idea to make steps in the respective direction. 

      In this case, dealing with only three tables - a fact table and two dimensions table - there are several perspectives that can be built:

      a) all records from fact table + dimension records

      The following view provides the lowest level of details for the fact table, allowing thus to look at the data from different perspectives as long as focus is only the values used is Sales Orders:

      -- create the view
      CREATE OR ALTER VIEW orders.vSalesOrders
      -- Sales Orders with Product & Customer information
      AS
      SELECT ORD.SalesOrderID
      , ORD.OrderDate
      , ORD.CustomerID
      , CST.FirstName 
      , CST.LastName
      , CST.EmailAddress
      , ORD.LineItem
      , ORD.ProductID
      , PRD.ProductName 
      , PRD.Category
      , ORD.OrderQty
      , ORD.LineItemTotal
      , PRD.ListPrice 
      , ORD.OrderQty * PRD.ListPrice ListPriceTotal
      FROM orders.orders ORD 
      	 JOIN orders.products PRD
      	   ON ORD.ProductID = PRD.ProductID
      	 JOIN orders.customers CST
      	   ON ORD.CustomerID = CST.CustomerID
      
      -- test the view   
      SELECT *
      FROM orders.vSalesOrders
      WHERE SalesOrderID = 71780
      

      One can use full joins unless some of the references dimensions are not available.  

      b) aggregated data for all dimension combinations

      The previous view allows to aggregate the data at the various levels of details:

      -- Sales volume by Customer & Product
      SELECT ORD.EmailAddress
      , ORD.ProductName 
      , ORD.Category
      , SUM(ORD.OrderQty) OrderQty
      , SUM(ORD.LineItemTotal) LineItemTotal
      FROM orders.vSalesOrders ORD 
      WHERE ORD.OrderDate >= '2022-06-01'
        AND ORD.OrderDate < '2022-07-01'
      GROUP BY ORD.EmailAddress
      , ORD.ProductName 
      , ORD.Category
      ORDER BY ORD.EmailAddress
      , ORD.ProductName 
      

      One can comment out the dimensions not needed. The query can be included in a view as well. 

      c) all records from each dimension table + aggregated fact records

      Sometimes, it's useful to look at the data from a dimension's perspective, though it might be needed to create such an object for each dimension, like in the below examples. For the maximum of flexibility the logic can be included in a table-valued function:

      -- create the user-defined function
      CREATE OR ALTER FUNCTION orders.tvfProductsSalesVolume(
          @StartDate date NULL,
          @EndDate date NULL
      )
      RETURNS TABLE
      -- Sales volume by Product
      AS
      RETURN (
      SELECT PRD.ProductID
      , PRD.ProductName 
      , PRD.Category
      , ORD.FirstOrderDate
      , ORD.LastOrderDate 
      , IsNull(ORD.TotalSalesQty, 0) TotalSalesQty 
      , IsNull(ORD.TotalSalesValue, 0) TotalSalesValue
      , IsNull(ORD.OrderCount, 0) OrderCount
      , IsNull(ORD.LineCount, 0) LineCount
      FROM orders.products PRD
           OUTER APPLY (
      		SELECT Min(ORD.OrderDate) FirstOrderDate
      		, Max(ORD.OrderDate) LastOrderDate 
      		, SUM(ORD.OrderQty) TotalSalesQty
      		, SUM(ORD.LineItemTotal) TotalSalesValue
      		, count(DISTINCT SalesOrderID) OrderCount
      		, count(*) LineCount
      		FROM orders.orders ORD 
      		WHERE ORD.ProductID = PRD.ProductID
      		  AND ORD.OrderDate >= @StartDate 
      		  AND ORD.OrderDate < @EndDate 
      	 ) ORD
      );
      
      -- test the user-defined function
      SELECT *
      FROM orders.tvfProductsSalesVolume('2022-06-01','2022-07-01') PRD
      WHERE TotalSalesValue <> 0
      ORDER BY TotalSalesValue DESC
      , LastOrderDate DESC
      
      
      -- create the user-defined function
      CREATE OR ALTER FUNCTION orders.tvfCustomersSalesVolume(
          @StartDate date NULL,
          @EndDate date NULL
      )
      RETURNS TABLE
      -- Sales volume by Customer
      AS
      RETURN (
      SELECT CST.CustomerID
      , CST.FirstName 
      , CST.LastName
      , CST.EmailAddress
      , ORD.FirstOrderDate
      , ORD.LastOrderDate 
      , IsNull(ORD.TotalSalesValue, 0) TotalSalesValue
      , IsNull(ORD.OrderCount, 0) OrderCount
      , IsNull(ORD.LineCount, 0) LineCount
      FROM orders.customers CST
           OUTER APPLY (
      		SELECT Min(ORD.OrderDate) FirstOrderDate
      		, Max(ORD.OrderDate) LastOrderDate 
      		, SUM(ORD.LineItemTotal) TotalSalesValue
      		, count(DISTINCT SalesOrderID) OrderCount
      		, count(*) LineCount
      		FROM orders.orders ORD 
      		WHERE ORD.CustomerID = CST.CustomerID
      		  AND ORD.OrderDate >= @StartDate 
      		  AND ORD.OrderDate < @EndDate 
      	 ) ORD
      );
      
      -- test the user-defined function
      SELECT *
      FROM orders.tvfCustomersSalesVolume('2022-06-01','2022-07-01') PRD
      WHERE TotalSalesValue <> 0
      ORDER BY TotalSalesValue DESC
      , LastOrderDate DESC
      

      When restructuring the queries in similar ways, there's always a compromise between the various factors: (re)usability, performance or completeness. 

      Further Comments

      The above database objects should allow users to address most of the requirements, though, as usual, there can be also exceptions, especially when the data needs to be aggregated at a different level of detail that requires the query to be structured differently.

      The number of perspectives can increase also with the number of fact tables used to model a certain entity (e.g. Sales order headers vs. lines). For example, 

      In theory, one can also find ways to automate the process of creating database objects, though one must choose the relevant attributes, respectively include logic that makes sense only within a certain perspective. 

      No matter the data, respectively systems used as source, expect surprises and test your assumptions! For example, in the file used to create the orders.customers table, there seem to be duplicated entities with the same name and email address. One must clarify how such entities must be handled in data analysis, respectively in data modeling. For example, a person can appear twice because of the roles associated with the name or can be other entitled reasons. 

      The files in scope of this post are small compared with the files existing in organizations. In many scenarios files' size could range from GB to TB and thus require partitioning and different other strategies. 

      |>> Next Post

      References
      [1] sql-troubles (2023) Architecture Part IV: Building a Modern Data Warehouse with Azure Synapse [link]

      Resources
      [1] Microsoft Learn (2024) Fabric: Lakehouse and Delta Lake tables [link]

      Related Posts Plugin for WordPress, Blogger...

      About Me

      My photo
      Koeln, NRW, Germany
      IT Professional with more than 25 years experience in IT in the area of full life-cycle of Web/Desktop/Database Applications Development, Software Engineering, Consultancy, Data Management, Data Quality, Data Migrations, Reporting, ERP implementations & support, Team/Project/IT Management, etc.