Dataflow Diagrams

Question:
[Joe Celko’s Dataflow Diagrams Puzzle]

Tom Bragg posted a version of this problem on the CASE Forum on CompuServe. You have a table of dataflow diagrams (DFDs), which has the name of the diagram, the names of the bubbles in each diagram and the labels on the flow lines. It looks like this:

    CREATE TABLE DFD        (diagram CHAR(10) NOT NULL,        bubble CHAR(10) NOT NULL,        flow CHAR(10) NOT NULL,        PRIMARY KEY (diagram, bubble, flow));
To explain the problem, let’s use this table:
    DFD    diagram  bubble  flow    =========================    Proc1    input   guesses    Proc1    input   opinions    Proc1    crunch  facts    Proc1    crunch  guesses    Proc1    crunch  opinions    Proc1    output  facts    Proc1    output  guesses    Proc2    reckon  guesses    Proc2    reckon  opinions    …
What we want to find is what flows. Do NOT go into each bubble within the diagrams. This will be part of a diagram validation routine that will search for missing dataflows. To make this easier, assume that all bubbles should have all flows. This would mean that (Proc1, input) is missing the ‘facts’ flow, and that (Proc1, output) is missing the ‘opinions’ flow.

Answer:
We could use this SQL-92 query:

    SELECT F1.diagram, F1.bubble, F2.flow        FROM (SELECT F1.diagram, F1.bubble FROM DFD AS F1            CROSS JOIN             SELECT DISTINCT F2.flow FROM DFD AS F2)            EXCEPT              SELECT F3.diagram, F3.bubble, F3.flow FROM DFD AS F3        ORDER BY F1.diagram, F1.bubble, F2.flow;
Basically, it makes all possible combinations of diagrams, and flows, then removes the ones we already have. The bad news is that you will probably have to do this with VIEWs in most current SQL products.

Another SQL-92 query would be:

    SELECT F1.diagram, F1.bubble, F2.flow         FROM (SELECT F1.diagram, F1.bubble FROM DFD AS F1            CROSS JOIN             SELECT DISTINCT F2.flow                 FROM DFD AS F2                WHERE flow NOT IN (SELECT F3.flow                     FROM DFD AS F3                    WHERE F3.diagram = F1.diagram                        AND F3.bubble = F1.bubble)        ORDER BY F1.diagram, F1.bubble, F2.flow;
Or to answer the puzzle in SQL-89, you will need to use VIEWs:
    — build a set of all the flows     CREATE VIEW AllDFDFlows (flow)        AS SELECT DISTINCT flow FROM DFD;    — attach all the flows to each row of the original table    CREATE VIEW NewDFD (diagram, bubble, flow, missingflow)        SELECT DISTINCT F1.diagram, F1.bubble, F1.flow, F2.flow            FROM DFD AS F1, AllDFDFlows AS F2            WHERE F1.flow <> F2.flow;    — Show me the (diagram, bubble) pairs and missing flow    — where the missing flow was not somewhere in the flow column    — of the pair.    SELECT DISTINCT diagram, bubble, missingflow        FROM NewDFD AS ND1        WHERE NOT EXISTS (SELECT *             FROM NewDFD AS ND2            WHERE ND1.diagram = ND2.diagram                AND ND1.bubble = ND2.bubble            AND ND1.flow = ND2.missingflow)        ORDER BY diagram, bubble, missingflow;
I probably overdid the DISTINCTs, but you can experiment with it for execution speed. This should still run faster than moving all the rows across the network.

Puzzle provided courtesy of:
Joe Celko
[email protected]

Share the Post:
Share on facebook
Share on twitter
Share on linkedin

Overview

The Latest

homes in the real estate industry

Exploring the Latest Tech Trends Impacting the Real Estate Industry

The real estate industry is changing thanks to the newest technological advancements. These new developments — from blockchain and AI to virtual reality and 3D printing — are poised to change how we buy and sell homes. Real estate brokers, buyers, sellers, wholesale real estate professionals, fix and flippers, and beyond may

man on floor with data

DevX Quick Guide to Data Ingestion

One of the biggest trends of the 21st century is the massive surge in internet usage. With major innovations such as smart technology, social media, and online shopping sites, the internet has become an essential part of everyday life for a large portion of the population. Due to this internet

payment via phone

7 Ways Technology Has Changed Traditional Payments

In today’s digital world, technology has changed how we make payments. From contactless cards to mobile wallets, it’s now easier to pay for goods and services without carrying cash or using a checkbook. This article will look at seven of the most significant ways technology has transformed traditional payment methods.