Skip to Content
v0.13.2: New interface + queries as text Download
DocumentationData Extraction Guide

Data Extraction Guide

In practice, process data is often not available as an OCEL file, but stored in tables of a database or in CSV, Excel, or Parquet files. Data extraction blueprints describe how the rows of such tables are turned into events, objects, and their relations. OCPQ executes the blueprint and loads the resulting OCEL, which can then be queried as usual.

In this guide, we use the publicly available Northwind sample database as a SQLite file. To follow along, you can download northwind.db (25 MB). The database contains the orders of a fictional trading company, together with their customers, employees, products, and shippers. As a first example, we turn each row of the Orders table into a place order event, related to the customer who placed the order and the employee who handled it.

Creating a Blueprint

First, open Extraction in the sidebar 1 and create a new blueprint 2.

Data extraction does not require a loaded OCEL.

Data extraction overview

Connecting a Source

In the new blueprint, click on Connect a source and then on Open a file.... There, select the source type 1 (here, SQLite) and enter the path to the database file 2. In the desktop app, Browse... opens a file picker instead. Besides SQLite databases, blueprints can also read CSV, Excel, and Parquet files, or connect to a PostgreSQL server.

OCPQ saves each blueprint together with its connected sources, so they are still there the next time you open it.

Configuring the data source

Mapping a Table

Add table lists the tables of all connected sources, from which we select Orders 1.

Picking a table

The dialog then asks what the rows of the table should be turned into 1, i.e., events, objects, E2O or O2O relations, or the result of a transformation (filter, join, or union). We keep Event, such that each row of Orders produces one event.

For events, you can set their type 2 and their timestamp 3. Each value can come from

  • a column,
  • a template combining several columns (e.g., {OrderID}-{ProductID}),
  • a constant, or
  • the first non-empty value of several options (coalesce). For our example, we use the constant type place order and the column OrderDate as the timestamp.
Mapping rows to events

Further down, Link an object relates the event to objects referenced in the same row 1. Each related object requires an ID 2 (here, the column CustomerID) and an object type 3 (here, customer). Similarly, a second link relates each event to the employee in the EmployeeID column, as an object of type employee.

Relating events to objects

Add Event then places the mapping next to its table on the canvas. The blueprint is validated while you edit it, and its status is shown next to Extract OCEL 1.

Blueprint with one table and one event mapping

Extracting the OCEL

Extract OCEL executes the blueprint. Afterwards, a report lists for each mapping how many rows were read and how many events, objects, and relations were produced.

Extraction report

The extracted OCEL replaces the currently loaded one and can be used in all other views of OCPQ. For example, the OCEL Info page shows its event and object types, and it can be exported as an OCEL 2.0 file in the JSON, XML, or SQLite format.

Extracted OCEL

Complete Example

Next, we present a complete blueprint, which extracts a larger OCEL from the same Northwind database, with six object types, four event types, as well as relations between objects.

The SQLite file used here is an extended version of the classic Northwind database, with 16,282 orders between 2012 and 2023 (instead of the original 830).

Objects

Five tables become objects, each with a few of their columns as attributes. For orders and employees, the attribute values are timestamped with the OrderDate and HireDate, respectively.

TableObject typeIDAttributes
OrdersorderOrderIDfreight, ship country
Order Detailsorder lineOrderID and ProductIDquantity, unit price, discount
CustomerscustomerCustomerIDcompany, country
ProductsproductProductIDname, list price
EmployeesemployeeEmployeeIDname, title
ShippersshipperShipperIDcompany

Events

Four columns of the database contain timestamps of activities, each of which becomes an event type. The related objects of each event are listed with their qualifier in parentheses.

Event typeTableTimestampRelated objects
place orderOrdersOrderDateorder (order), customer (customer), employee (sales rep)
order dueOrdersRequiredDateorder (order)
ship orderOrders, filteredShippedDateorder (order), shipper in ShipVia (carrier)
hire employeeEmployeesHireDateemployee (employee)

Two of these need a short explanation:

  • order due marks the date requested by the customer. Of course, this is a deadline and not an actual activity, but it allows checking which orders were shipped late (3,755 of them).
  • ship order reads from a filter transformation, which keeps only orders with a ShippedDate (all but 21 orders).

Object-to-Object Relations

TableSourceTargetQualifier
Order Detailsorderorder linecontains
Order Detailsorder lineproductproduct
Employeesemployeeemployee in ReportsToreports to

For the one employee without a manager, the reports to relation has no target, and the row is skipped (reported as No usable id).

Northwind blueprint. You can copy it using the button on the right or download it as a file. The blueprint reads the Northwind SQLite file, which can be downloaded here (25 MB).

Download northwind.blueprint.json
Show the JSON
{
  "version": 1,
  "id_rendering": "type-prefixed",
  "on_missing_endpoint": "create",
  "on_duplicate_object": "first-wins",
  "nodes": [
    {
      "id": "orders",
      "label": "Orders",
      "op": {
        "type": "source",
        "source_id": "northwind",
        "table": "Orders"
      }
    },
    {
      "id": "order_details",
      "label": "Order Details",
      "op": {
        "type": "source",
        "source_id": "northwind",
        "table": "Order Details"
      }
    },
    {
      "id": "customers",
      "label": "Customers",
      "op": {
        "type": "source",
        "source_id": "northwind",
        "table": "Customers"
      }
    },
    {
      "id": "employees",
      "label": "Employees",
      "op": {
        "type": "source",
        "source_id": "northwind",
        "table": "Employees"
      }
    },
    {
      "id": "products",
      "label": "Products",
      "op": {
        "type": "source",
        "source_id": "northwind",
        "table": "Products"
      }
    },
    {
      "id": "shippers",
      "label": "Shippers",
      "op": {
        "type": "source",
        "source_id": "northwind",
        "table": "Shippers"
      }
    },
    {
      "id": "shipped_orders",
      "label": "Shipped orders",
      "op": {
        "type": "filter",
        "input": "orders",
        "condition": {
          "type": "not",
          "condition": {
            "type": "is-null",
            "column": "ShippedDate"
          }
        }
      }
    }
  ],
  "mappings": [
    {
      "type": "single",
      "label": "Customers",
      "node": "customers",
      "target": {
        "type": "object",
        "object_type": {
          "type": "constant",
          "value": "customer"
        },
        "id": {
          "type": "column",
          "column": "CustomerID"
        },
        "attributes": [
          {
            "name": "company",
            "source_column": "CompanyName"
          },
          {
            "name": "country",
            "source_column": "Country"
          }
        ]
      }
    },
    {
      "type": "single",
      "label": "Employees",
      "node": "employees",
      "target": {
        "type": "object",
        "object_type": {
          "type": "constant",
          "value": "employee"
        },
        "id": {
          "type": "column",
          "column": "EmployeeID"
        },
        "attributes": [
          {
            "name": "name",
            "source_column": "LastName"
          },
          {
            "name": "title",
            "source_column": "Title"
          }
        ],
        "timestamp": {
          "type": "value",
          "source": {
            "type": "column",
            "column": "HireDate"
          }
        }
      }
    },
    {
      "type": "single",
      "label": "Products",
      "node": "products",
      "target": {
        "type": "object",
        "object_type": {
          "type": "constant",
          "value": "product"
        },
        "id": {
          "type": "column",
          "column": "ProductID"
        },
        "attributes": [
          {
            "name": "name",
            "source_column": "ProductName"
          },
          {
            "name": "list price",
            "source_column": "UnitPrice",
            "value_type": "Float"
          }
        ]
      }
    },
    {
      "type": "single",
      "label": "Shippers",
      "node": "shippers",
      "target": {
        "type": "object",
        "object_type": {
          "type": "constant",
          "value": "shipper"
        },
        "id": {
          "type": "column",
          "column": "ShipperID"
        },
        "attributes": [
          {
            "name": "company",
            "source_column": "CompanyName"
          }
        ]
      }
    },
    {
      "type": "single",
      "label": "Orders",
      "node": "orders",
      "target": {
        "type": "object",
        "object_type": {
          "type": "constant",
          "value": "order"
        },
        "id": {
          "type": "column",
          "column": "OrderID"
        },
        "attributes": [
          {
            "name": "freight",
            "source_column": "Freight",
            "value_type": "Float"
          },
          {
            "name": "ship country",
            "source_column": "ShipCountry"
          }
        ],
        "timestamp": {
          "type": "value",
          "source": {
            "type": "column",
            "column": "OrderDate"
          }
        }
      }
    },
    {
      "type": "single",
      "label": "Reports to",
      "node": "employees",
      "target": {
        "type": "o2o",
        "source": {
          "id": {
            "type": "column",
            "column": "EmployeeID"
          },
          "object_type": {
            "type": "constant",
            "value": "employee"
          }
        },
        "target": {
          "id": {
            "type": "column",
            "column": "ReportsTo"
          },
          "object_type": {
            "type": "constant",
            "value": "employee"
          }
        },
        "qualifier": {
          "type": "constant",
          "value": "reports to"
        }
      }
    },
    {
      "type": "single",
      "label": "Order lines",
      "node": "order_details",
      "target": {
        "type": "object",
        "object_type": {
          "type": "constant",
          "value": "order line"
        },
        "id": {
          "type": "template",
          "template": "{OrderID}-{ProductID}"
        },
        "attributes": [
          {
            "name": "quantity",
            "source_column": "Quantity",
            "value_type": "Integer"
          },
          {
            "name": "unit price",
            "source_column": "UnitPrice",
            "value_type": "Float"
          },
          {
            "name": "discount",
            "source_column": "Discount",
            "value_type": "Float"
          }
        ]
      }
    },
    {
      "type": "single",
      "label": "Order has line",
      "node": "order_details",
      "target": {
        "type": "o2o",
        "source": {
          "id": {
            "type": "column",
            "column": "OrderID"
          },
          "object_type": {
            "type": "constant",
            "value": "order"
          }
        },
        "target": {
          "id": {
            "type": "template",
            "template": "{OrderID}-{ProductID}"
          },
          "object_type": {
            "type": "constant",
            "value": "order line"
          }
        },
        "qualifier": {
          "type": "constant",
          "value": "contains"
        }
      }
    },
    {
      "type": "single",
      "label": "Line of product",
      "node": "order_details",
      "target": {
        "type": "o2o",
        "source": {
          "id": {
            "type": "template",
            "template": "{OrderID}-{ProductID}"
          },
          "object_type": {
            "type": "constant",
            "value": "order line"
          }
        },
        "target": {
          "id": {
            "type": "column",
            "column": "ProductID"
          },
          "object_type": {
            "type": "constant",
            "value": "product"
          }
        },
        "qualifier": {
          "type": "constant",
          "value": "product"
        }
      }
    },
    {
      "type": "single",
      "label": "Place order",
      "node": "orders",
      "target": {
        "type": "event",
        "event_type": {
          "type": "constant",
          "value": "place order"
        },
        "id": {
          "type": "template",
          "template": "{OrderID}"
        },
        "timestamp": {
          "type": "value",
          "source": {
            "type": "column",
            "column": "OrderDate"
          }
        },
        "objects": [
          {
            "object": {
              "id": {
                "type": "column",
                "column": "OrderID"
              },
              "object_type": {
                "type": "constant",
                "value": "order"
              }
            },
            "qualifier": {
              "type": "constant",
              "value": "order"
            }
          },
          {
            "object": {
              "id": {
                "type": "column",
                "column": "CustomerID"
              },
              "object_type": {
                "type": "constant",
                "value": "customer"
              }
            },
            "qualifier": {
              "type": "constant",
              "value": "customer"
            }
          },
          {
            "object": {
              "id": {
                "type": "column",
                "column": "EmployeeID"
              },
              "object_type": {
                "type": "constant",
                "value": "employee"
              }
            },
            "qualifier": {
              "type": "constant",
              "value": "sales rep"
            }
          }
        ]
      }
    },
    {
      "type": "single",
      "label": "Order due",
      "node": "orders",
      "target": {
        "type": "event",
        "event_type": {
          "type": "constant",
          "value": "order due"
        },
        "id": {
          "type": "template",
          "template": "{OrderID}"
        },
        "timestamp": {
          "type": "value",
          "source": {
            "type": "column",
            "column": "RequiredDate"
          }
        },
        "objects": [
          {
            "object": {
              "id": {
                "type": "column",
                "column": "OrderID"
              },
              "object_type": {
                "type": "constant",
                "value": "order"
              }
            },
            "qualifier": {
              "type": "constant",
              "value": "order"
            }
          }
        ]
      }
    },
    {
      "type": "single",
      "label": "Hire employee",
      "node": "employees",
      "target": {
        "type": "event",
        "event_type": {
          "type": "constant",
          "value": "hire employee"
        },
        "id": {
          "type": "template",
          "template": "{EmployeeID}"
        },
        "timestamp": {
          "type": "value",
          "source": {
            "type": "column",
            "column": "HireDate"
          }
        },
        "objects": [
          {
            "object": {
              "id": {
                "type": "column",
                "column": "EmployeeID"
              },
              "object_type": {
                "type": "constant",
                "value": "employee"
              }
            },
            "qualifier": {
              "type": "constant",
              "value": "employee"
            }
          }
        ]
      }
    },
    {
      "type": "single",
      "label": "Ship order",
      "node": "shipped_orders",
      "target": {
        "type": "event",
        "event_type": {
          "type": "constant",
          "value": "ship order"
        },
        "id": {
          "type": "template",
          "template": "{OrderID}"
        },
        "timestamp": {
          "type": "value",
          "source": {
            "type": "column",
            "column": "ShippedDate"
          }
        },
        "objects": [
          {
            "object": {
              "id": {
                "type": "column",
                "column": "OrderID"
              },
              "object_type": {
                "type": "constant",
                "value": "order"
              }
            },
            "qualifier": {
              "type": "constant",
              "value": "order"
            }
          },
          {
            "object": {
              "id": {
                "type": "column",
                "column": "ShipVia"
              },
              "object_type": {
                "type": "constant",
                "value": "shipper"
              }
            },
            "qualifier": {
              "type": "constant",
              "value": "carrier"
            }
          }
        ]
      }
    }
  ]
}

Loading the Blueprint

For loading the blueprint, create a new blueprint and click on File. In the Load tab 1, paste the JSON 2 and click on Load 3. Alternatively, Choose a file... loads the downloaded file.

Loading a blueprint from JSON

The Save tab of the same dialog allows copying or downloading your own blueprints. As connection strings might contain passwords, they are only included if you explicitly enable it.

Connecting the Source

Blueprint files name their sources (here, northwind), but by default do not include where they are located (see the Save tab above). Thus, after loading the blueprint, open Connections and click on Connect 1 next to northwind.

A source the blueprint needs

In the form that opens, select SQLite 1 and enter the path to your copy of northwind.db 2. The source id 3 is already set to northwind, matching the name used in the blueprint.

Connecting the northwind source

As soon as the file can be read, OCPQ lists its tables, and you can browse their columns and rows. Done closes the dialog.

The connected source with its tables

Once the source is connected, the canvas shows each table on the left and the mappings reading from it on the right.

The Northwind blueprint

Extracting the OCEL

Extract OCEL executes all thirteen mappings. Notably, the Order Details table alone yields 609,283 order lines, each related to its order and its product.

Extraction report of the Northwind blueprint

The resulting OCEL contains 48,834 events and 625,747 objects. On the OCEL Info page, the type relations show all four event types and six object types, as well as the object-to-object relations as dashed edges.

OCEL extracted with the Northwind blueprint

Querying the Result

The extracted OCEL can be queried like any other OCEL in OCPQ. For example, the following constraint considers small orders and states that every order with at most 3 order lines should be shipped at most one week after it was placed. In the Northwind data, 541 of the 1,232 small orders (43.9%) take longer. You can copy the query using the button on the right and paste it into the query editor with Ctrl+V.

Small Orders Ship Within a Week

  • Constraint

For every order with at most 3 order lines (counted as A by the child box), the ship order event should occur at most one week after the place order event.

Last updated on