ETL Notes

ETL

Designing the ETL Plan

  • The logical data map, provided by the data warehouse architect, serves as the instructions for the ETL team to create physical ETL jobs.

  • This is sometimes called the data lineage report.

  • The logical data map is the foundation of the metadata presented to quality-assurance testers and end-users, describing the processing between the source system and the data warehouse.

Components of the Logical Data Map

  • Target table name: The physical name of the table in the data warehouse.

  • Target column name: The name of the column in the data warehouse table.

  • Table type: Indicates if the table is a fact, dimension, or sub-dimension (outrigger).

  • SCD (Slowly Changing Dimension) type: For dimensions, indicates Type-1, -2, or -3 SCD approach. This can vary for each column in the dimension.

  • Source database: The name of the database instance where the source data resides, often the connection string. Can also be the name/path of a file.

  • Source table name: The name of the table where the source data originates. Multiple tables may be listed if required to populate the target.

  • Source column name: The column(s) needed to populate the target. Associations are documented in the transformation section.

  • Transformation: The manipulation required of the source data to match the expected format of the target. Usually expressed in SQL or pseudo-code.

Logical Data Map Considerations

  • Table type dictates the ordinal position of data load processes: dimensions first, then facts.

  • Source database, table name, and column name can be combined into a single source column, delimited with a period (e.g., ORDERS.STATUS.STATUS CODE).

  • It's crucial to know which columns have historic relevance and the strategy required for capturing the history before load development.

  • Data types between source and target may require conversion (e.g., from 255 characters to 75 characters).

  • Implied conversions are common but risky. The ETL team must explicitly handle these data conversions to avoid errors.

Transformation Details

  • The transformation can range from an absolute solution to nothing at all.

  • Often, the transformation is expressed in SQL, which may be a complete statement or a segment of code (e.g., the WHERE clause).

  • Transformations might be non-SQL specific, explained in plain English, like instructions to preload from a flat file or to reject known data anomalies into a reject file.

  • A blank transformation means a straight load from source-to-target with no transformation needed.

Analysis of the Source System

  • The complete logical data mapping cannot exist until source systems are identified and analyzed.

  • Analysis is broken into two phases:

    • Data discovery phase: Identify and examine the data sources based on the target's needs.

    • Data content analysis / anomaly detection phase: Identify data anomalies.

      • A data anomaly is data that doesn't fit into the domain of the rest of the data.

Data Discovery Phase

  • Collecting and Documenting Source Systems

  • Keeping Track of the Source Systems

  • Determining the System-of-Record

  • Analyzing the Source System: Using Findings from Data Profiling

Collecting and Documenting Source Systems

  • Source systems are often documented in various places, including interview notes and reports.

  • The ETL team, along with system and business analysts, tracks down appropriate source systems.

  • In large organizations, the ETL team must find the data source for each user group.

  • Organizations have many distinct systems, and the ETL team is responsible for tracking discovered systems and investigating their usefulness as a data warehouse source.

System Analyst

  • A systems analyst is an IT professional specializing in analyzing, designing, and implementing information systems.

  • They assess the suitability of information systems for their intended outcomes and liaise with end-users, software vendors, and programmers.

  • A systems analyst solves business problems using information technology, employing analysis and design techniques.

  • They may act as change agents, identifying organizational improvements, designing systems to implement changes, and training/motivating others to use the systems.

Business Analyst

  • Business analysts (or management analysts) evaluate how an organization operates and recommend improvements to management to improve productivity and reduce costs.

  • They gather and examine data, develop models, examine financials, and research customer habits.

  • A business analyst uses this information to recommend ways to improve systems or processes.

Keeping Track of the Source Systems

  • Important attributes to track include:

    • Subject Area: Name of the data mart the source system feeds.

    • Interface Name: Name of the transaction application the source system supports.

    • Business Name: Common name used by business users.

    • Priority: Ranking to determine which data sources to load first, based on the data warehouse bus matrix.

    • Department/Business Use: Primary department using the database (e.g., Accounting, HR) and the business use (e.g., Inventory Control, Client tracking).

    • Business Owner: Contact person/group for issues related to application/database use. Typically the data steward for the subject area.

    • Technical Owner: DBA or IT project manager for maintaining the database.

    • DBMS: Source database management system name (e.g., Oracle, DB2, Sybase) or non-relational data stores (e.g., Lotus Notes, VSAM).

    • Production Server/OS: Physical server name and operating system. Needed for designing OS-level scripts for ETL.

    • # Daily Users: Number of employees exposed to the data.

    • DB Size: Raw size of the source data, useful for determining ETL priorities and efforts.

    • DB Complexity: Number of tables and view objects in the system

    • # Transactions per Day: Estimate for capacity requirements for incremental load process.

    • Comments: General observations, including notes about future versions or reasons for being/not being a system-of-record.

Common Dimensions

The transcript shows a matrix relating business processes to potential dimensions. For instance:

  • Issue Purchase Orders: Related to Date, Product, Warehouse, Vendor, Shipper.

  • Receive Warehouse Deliveries: Related to Date, Product, Warehouse.

  • Warehouse Inventory: Related to Date, Product, Warehouse.

  • Receive Store Deliveries: Related to Date, Product, Store.

  • Store Inventory: Related to Date, Product, Store.

  • Retail Sales: Related to Date, Product, Store, Promotion, Customer, Employee.

  • Retail Sales Forecast: Related to Date, Product, Store, Promotion.

  • Retail Promotion Tracking: Related to Date, Product, Store, Promotion.

  • Customer Returns: Related to Date, Product, Store, Customer.

  • Returns to Vendor: Related to Date, Product, Warehouse, Vendor.

  • Frequent Shopper Sign-Ups: Related to Date, Customer.

Data Content Analysis

  • Common anomalies to be aware of include:

    1. NULL values:

      • Check for NULL values in every foreign key in the source database.

      • Use outer joins when NULL values are present in foreign keys to include all rows regardless of matching values.

      • If NULL data is in a non-foreign key column required by the business, get a business rule on how to handle the NULL data.

      • Avoid storing NULL values unless it is an unknown measure.

      • Create default values to replace NULL values whenever possible.

    2. Dates in non-date fields:

      • Dates can have various formats even with the same meaning.

      • Database systems usually support different formats for display but store them in a standard format.

      • Dates are sometimes stored in text fields, especially in legacy applications, which can have varied formats.

      • Examples include: 13-JAN-22, January 13, 2022, 01-13-2022, 13/01/2022, 01/13/2022 2:24 PM, 01/13/202214:24:49, 20220113, 13012022.

Collecting Business Rules in the ETL Process

  • Data modeling and ETL teams need different business rules.

  • Example:

    • Data Modeling Definition:

      • Status Code: A four-digit code that uniquely identifies the status of the product with a short description (one word) and a long description (one sentence).

    • ETL Definition:

      • Status Code: A four-digit code. Legacy codes may be three digits and need conversion.

      • All three-digit codes must be converted to their four-digit equivalent code.

      • If the code name contains "OBSOLETE", remove it and set the obsolete flag to 'Y'.

      • The description should always be in sentence case, regardless of source system case.

Integrating Heterogeneous Data Sources

Analogy: Corporate Merger

  • During corporate mergers, companies join another similar (or dissimilar) companies.

  • Business decides which company is the surviving company and which companies get consumed

    • The surviving company in a merger takes over the rights and responsibilities of the firms that undergo the merger.

  • Parent company may incorporate practices and techniques of subsidiaries.

  • A successful merger results in a cohesive organization with a single business interest.

  • Requires aligning terminology (dimension attributes) and aligning key performance indicators (facts in fact tables).

Loading Conformed Dimensions

  • The most direct form of data integration is the implementation of conformed dimensions.

  • Conformed dimensions are a cohesive design that unifies disparate data systems.

Data Profiling

  • Data profiling is a necessary precursor to design any system to use that data.

  • As per Jack Olson data profiling employs analytics methods for looking at data for the purpose of developing thorough understanding of the content, structure ,and quality of the data

  • A good data profiling system can process very large amount of data and with the skills of the analyst uncover all sorts of issues that need to be addressed

System of Record

  • System of record SOR is an ISRS (information storage and retrieval system) that is the authoritative source for a particular data element in a system containing multiple source of the same element.

  • To ensure data integrity, there must be one and only one system of record for a given piece of information.

  • Systems of engagement are the programs and applications that workers interact in their daily work lives.

  • Systems of engagement are decentralized , their design is based on the needs of a given business unit, and are built for frontline team.

Steps for Loading Conformed Dimensions in a Disparate Source System Environment:

  1. Identify the source systems

    • During data-profiling phase of the construction of the logical data mapping, data warehouse team must work together to detect the various sources of your target dimensions and facts.

    • The data warehouse architect should uncover most of the potential sources of each element in the data warehouse and attempt to appoint a system-of-record for each element.

    • The system-of-record is considered the ultimate source for the data being loaded.

  2. Understand the source systems

    • Understand all of the attributes of all of the entities of all of the systems under consideration.

    • This phase declares the reliability of the source system for the elements under scrutiny.

    • During this phase of the project, the assignment of the system-of-record can actually be reassigned if data-quality issues persist or if reliability of the data is problematic for any reason.

  3. Create record matching logic

    • Objective is to design the matching algorithm to enable entities across the disparate systems to be joined.

    • Sometimes, the matching algorithm is as simple as identifying the primary key of the various customer tables.

    • Disparate systems may not share primary keys. Social security number, last name, email address and telephone number combinations might be needed.

    • Various business areas must be involved with and approve of your final matching logic.

    • Record-matching logic must be consistent with the various legislated privacy rules, such as HIPAA in the health care arena.

  4. Establish Survivorship rules

    • Once your system-of-record has been identified and the matching logic has been approved, you can establish the surviving record when data collisions occur in your ETL process.

    • Business must decide which system has overriding power when attributes overlap (e.g., Accounts Receivable vs. Sales systems customer tables).

  5. Establish nonkey attribute business rules

    • Dimensions are sourced from tables and columns within a system.

    • Source systems contain different attributes that ultimately feed into a target dimension.

    • E.g., Department lists from HR, accounting codes from Finance.

    • Even if HR is SOR, attributes may be more reliable from other systems.

    • Assigning business rules is important when attributes exist in several systems but not the system-of-record.

    • Documentation and publishing of data lineage metadata is crucial.

  6. Load conformed dimension

    • Physically load the conformed dimension.

    • Consider the slowly changing dimension (SCD) type and update late-arriving data as needed.

The Challenge of Extracting from Disparate Platforms

Connecting to Diverse Sources through ODBC

  • Open Database Connectivity (ODBC) was created to enable users to access databases from their Windows applications.

  • The original intention for ODBC was to make applications portable (database changes from DB2 to Oracle).

    • Simply change the ODBC driver, which is transparent to the application.

  • ODBC drivers are available for most DBMS on any platform.

  • You can also use ODBC to access flat files.

The topology of ODBC in the ETL process

  • For the ETL process to utilize data via ODBC, two layers are added between the ETL system and the underlying database.

    • ODBC manager.

      • The ODBC manager is a program that accepts SQL from the ETL application and routes it to the appropriate ODBC driver.

      • It also maintains the connection between the application and the ODBC driver.

    • ODBC driver.

      • The ODBC driver is the real workhorse in the ODBC environment.

      • The ODBC driver translates ODBC SQL to the native SQL of the underlying database.

  • Drawbacks:

    • Performance cost for ODBC’s flexibility.

    • Loss of DBMS-specific functionality.

    • Non-ANSI standard SQL commands are not accepted.

  • For high performance and native DBMS functionality, use a native database driver.

  • ODBC can provide a common format gateway to troublesome data sources.

Mainframe Sources

  • Much of the day-to-day business data is processed and stored on mainframe systems (and AS/400).

  • Integrating data from these systems into the data warehouse involves some unique challenges.

  • COBOL remains the dominant programming language, and the file layout for data is described in COBOL copybooks.

  • A copybook defines the field names and data types for a mainframe data file.

  • Only two data types exist in mainframe flat files: text and numeric.

  • Numeric values are stored in a variety of ways.

  • Dates are stored as strings of numbers (or text) and require transformation to be stored in date columns in the data warehouse.

Example Copybook

A simple copybook describes an employee record with fields such as FIRST-NAME, MIDDLE-INITIAL, LAST-NAME, SSN, EMP-DOB (with nested DOB-YYYY, DOB-MM, DOB-DD), EMP-ID, HIRE-DATE, TERM-DATE and TERM-REASON-CODE.

  • Text and numeric data types are denoted using the PIC clauses. PIC X denotes text fields, while PIC 9 means the field is numeric.

  • Field lengths are specified with numbers following the type. For example, the clause PIC 9(4) indicates a four-byte numeric field, whereas PIC X(15) indicates a 15-byte text field.

EBCDIC

  • EBCDIC (extended binary-coded decimal interchange code) is a data-encoding system developed by IBM.

  • It uses a unique eight-bit binary code for each number, alphabetic character, punctuation mark, accented letter, and non-alphabetic characters.

  • It differs from Unicode and ASCII.

  • It divides the eight bits for each character into two four-bit zones: one indicating the type of character, and the other indicating the value within this type.

EBCDIC to ASCII Conversion

  • Conversion is automatic assuming you use File Transfer Protocol (FTP) to transfer the data from the mainframe to your data warehouse platform.

  • An FTP connection requires two nodes—a host and a client.

  • The FTP client identifies its operating system environment to the FTP host, and the host determines whether any translation is required.

  • The FTP host translates mainframe data from EBCDIC to ASCII as it transfers the data to a UNIX or Windows system.

  • FTP also adds the special line feed and carriage return characters used to designate the end of a line (or record) of data on UNIX and Windows.

  • FTP translates from ASCII to EBCDIC if the data moves from UNIX or Windows to the mainframe.

Flat Files

  • File layouts consists of Record Type, SSN, First Name, Middle Initial, Last Name, Name Suffix, Birth Date, Status Code, Office Code, Department Code Position Code, Filler, Add Date and Modified Date .

  • In most ETL tools, you have to manually input the file layout.

  • If the file layout changes or the data shifts off of its assigned positions, the ETL process must be programmed to raise an error.

  • Most ETL tools have a delimited file wizard that detects delimiters within the file to specify the file layout.

  • Most often, the first row of delimited files contains its column names.

  • The ETL tool should be intelligent enough to recognize the column names supplied in the first row to assign logical column names in the metadata layer and then ignore the row during all subsequent data processing.

Web Log Sources

  • Web logs record every object either posted to or served from the Web server.

  • Web logs are important because they reveal the user traffic on the Web site.

  • Understanding user behavior is as valuable as following a customer around a store.

  • Parsing Web logs and storing the results in a data mart to analyze customer activity is known as clickstream data warehousing.

ERP System Sources

  • ERP systems are designed to be an integrated enterprise solution across sales, accounting, HR, inventory, and production control on the same platform, database, and application framework.

  • However, it’s very rare for an entire enterprise to use only an ERP system to run a company.

  • Performing system and data analysis from scratch is cost and time prohibitive with much room for error.

  • If your data warehouse sources are from an existing ERP system, it is best to acquire someone with vast experience of the underlying database structure of your specific ERP system as well as the business objectives of the application.

  • Many ETL vendors offer ERP adapters to communicate with the popular ERP systems.

  • They can help you navigate the metadata in these systems and make sense of the application.

Extracting Changed Data

  • During the initial load, capturing changes to data content in the source data is unimportant because you are most likely extracting the entire data source or a potion of it from a predetermined point in time.

  • The ETL team is responsible for capturing data-content changes during the incremental load.

  • Desires and hopes are dictated by the users, and the realities of the feasibility of those hopes are revealed by the source system DBA team.

Detecting Changes Using Audit Columns

  • In most cases, the source system contains audit columns.

  • Audit columns are appended to the end of each table to store the date and time a record was added or modified.

  • Audit columns are usually populated via database triggers fired off automatically as records are inserted or updated.

  • Sometimes, for performance reasons, the columns are populated by the front-end application instead of database triggers.

  • When these fields are loaded by any means other than database triggers, you must pay special attention to their integrity.

  • You must analyze and test each of the columns to ensure that it is a reliable source to indicate changed data.

  • If you find any NULL values, you must to find an alternative approach for detecting change.

  • The most common environment situation that prevents the ETL process from using audit columns is when the fields are populated by the front-end application and the DBA team allows back-end scripts to modify data.

  • If this is the situation in your environment, you face a high risk that you will eventually miss changed data during your incremental loads.

  • A preventative measure to minimize your risk is to stipulate that all back-end scripts be validated by a quality-assurance team that insists and tests that the audit fields are populated by the script before it is approved.

  • Once you are confident that audit columns are dependable, you need a strategy for utilizing them.

  • There are various methods to implement the utilization of audit columns to capture changes to data.

  • All of the methods have the same logical objective; to compare the last modified date and time of each record to the maximum date and time that existed during the previous load and take all those that are greater.

Audit Columns Utilization

  • Process selects the maximum date and time from create date and last modified date columns.

  • Some columns are updated upon insertion and with each change to the record.

  • Others are left NULL upon insertion and updated only with changes after the record has already been inserted.

  • When the last modified date is not populated, you must default it with an arbitrary old date in order to not lose new records.

  • In cases where the rows in the fact table are inserted but never updated, you can simply select records from the source system where the create date and time is greater than the maximum date and time of the previous load and ignore the last modified date column.

  • Since fact tables and dimension tables can be sourced from many different tables and systems, and since fact tables consist only of foreign keys and measures, you do not store the audit dates in the fact table directly.

  • You need to create an ETL last-change table that captures each source table and the maximum date time found in the source system audit columns at the time of each extract.

Database Log Scraping

  • Log Scraping take a snapshot of the database redo log at a scheduled poind in time (usually midnight) and scores it for transaction that affect the tables you care about for the ETL load.

  • Scraping the log for transactions is probably the messiest of all techniques. Its not rare for transactions logs to blow out, meaning they get full and prevent new transactions from occurring.

  • If you have exhausted all other techniques and find log scraping is your last resort for finding new or changed records, persuade the DBA to create a special log to meet your specific needs.

  • Those tables can populate your dedicated log via insert and update triggers.

Timed Extracts

  • Select all of the rows where the date in the Create or Modified date fields equal SYSDATE-1, meaning you’ve got all of yesterday’s records.

  • Problems:

    • Time-based data selection loads duplicate rows when it is restarted from mid process failures.

    • If the nightly load process fails to run and misses a day, a risk exists that the missed data will never make it into the data warehouse.

  • Unless your ETL process is extremely straightforward and the data volume is exceptionally small, avoid loading data based purely on time.

Process of Elimination

  • Process of elimination preserves exactly one copy of each previous extraction in the staging area for future use.

  • Process takes the entire source table(s) into the staging area and makes data from the last process.

  • Only differences (deltas) are sent to the data warehouse.

  • Process of elimination is the most reliable of all incremental load techniques for capturing changed data.

  • Because the process makes a row-by-row comparison, looking for changes, it’s virtually impossible to miss any data.

  • This technique also has the advantage that rows deleted from the source can be detected.

Current and Previous Load Tables

  • Create two tables: previous load and current load.

  • The initial process bulk loads into the current load table.

  • Since change detection is irrelevant during the initial load, the data continues on to be transformed and loaded into the ultimate target fact table.

  • When the process is complete, it renames the current load table to previous load, and creates an empty current load table.

  • Since none of these tasks involve database logging, they are very fast.

  • The next time the load process is run, the current load table is populated.

  • Select the current load table MINUS the previous load table.

  • Transform and load the result set into the data warehouse. Upon completion, drop the previous load table and rename the current load table to previous load.

  • Finally, create an empty current load table.

Extraction Tips

  • Constrain on indexed columns.

    • Work with the DBA to ensure all of the columns in your WHERE clause are indexed in the source system; otherwise you will probably provoke a relation scan of the entire production database.

  • Retrieve the data you need.

    • The optimal query returns exactly what you need. You shouldn’t retrieve an entire table and filter out unwanted data later in the ETL tool.

Extraction Tips Continued

  • Use DISTINCT sparingly.

    • The DISTINCT clause is notoriously slow.
      Finding the balance between performing a DISTINCT during the extract query versus aggregating or grouping the results in your ETL tool is challenging and usually varies depending on the percentage of duplicates in the source.

  • Use SET operators sparingly.

    • UNION, MINUS, and INTERSECT are SET operators.

    • These, like DISTINCT, are notoriously slow.

    • It’s understood that sometimes these operators cannot be avoided.

    • A tip is to use UNION ALL instead of UNION. UNION performs the equivalent of a DISTINCT, slowing the process. The hitch is that UNION ALL returns duplicates, so handle with care.

  • Use HINT as necessary.

    • Most databases support the HINT keyword.

    • You can use a HINT for all kinds of things, but most importantly to force your query to use a particular index.

    • This capability is especially important when you are using an IN or OR operator, which usually opts for scanning a full table scan rather than using indexes, even when usable indexes exist.

  • Avoid NOT.

    • If at all possible, avoid non-equi constraints and joins. Whether you use the keyword NOT or the operators ‘< >’, your database will most likely opt to scan a full table rather than utilize indexes.

  • Avoid functions in your where clause.

    • This is a difficult one to avoid, especially when constraining on dates and such. Experiment with different techniques before committing to use of a function in your WHERE clause. Try using comparison keywords instead of functions whenever possible.

    • LIKE 'J%' instead of SUBSTR('LAST_NAME',1,1 ) = 'J'

    • EFFDATE BETWEEN '01-JAN-2002' AND '31-JAN-2002' instead of TOCHAR(EFF_DATE, 'YYY-MON' ) = '2002-JAN'

Detecting Deleted or Overwritten Fact Records at the Source

  • Measurement (fact) records deleted or overwritten from source systems can pose a very difficult challenge for the data warehouse if no notification of the deletion or overwrite occurs.

  • Negotiate with source system owners, if possible, explicit notification of all deleted or overwritten measurement records.

  • Periodically check historical totals of measurements from the source system to alert the ETL staff that something has changed. When a change is detected, drill down as far as possible to isolate the change.

  • In cases of deleted or modified fact records, rather than just performing a deletion or update in the data warehouse, we prefer that a new record be inserted that implements the change in the fact by canceling or negating the originally posted value.

  • In many applications, this will sum the reported fact to the correct quantity (if it is additive) as well as provide a kind of audit trail that the correction occurred. In these cases, it may also be convenient to carry an extra administrative time stamp that identifies when the database actions took place.