Top Banner
J ´ acome Cunha Flatten from/to Relational – 1 / 21 Flatten from/to Relational J ´ acome Cunha Jo ˜ ao Saraiva Joost Visser CIC 2007 22-23 October * Universidade do Minho Software Improvement Group
24

Flatten from/to Relational - Alexandra Silva Cunha´ Flatten from/to Relational – 1 / 21 Flatten from/to Relational Jacome Cunha´ ∗ Joao Saraiva˜ ∗ Joost Visser† CIC 2007

May 18, 2018

Download

Documents

duongdiep
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Flatten from/to Relational - Alexandra Silva Cunha´ Flatten from/to Relational – 1 / 21 Flatten from/to Relational Jacome Cunha´ ∗ Joao Saraiva˜ ∗ Joost Visser† CIC 2007

Jacome Cunha Flatten from/to Relational – 1 / 21

Flatten from/to Relational

Jacome Cunha∗ Joao Saraiva∗ Joost Visser†

CIC 2007

22-23 October

∗Universidade do Minho†Software Improvement Group

Page 2: Flatten from/to Relational - Alexandra Silva Cunha´ Flatten from/to Relational – 1 / 21 Flatten from/to Relational Jacome Cunha´ ∗ Joao Saraiva˜ ∗ Joost Visser† CIC 2007

Overview

Introduction

The Transformation

Example

Conclusions

Jacome Cunha Flatten from/to Relational – 2 / 21

Introduction

The Transformation

Example

Conclusions

Page 3: Flatten from/to Relational - Alexandra Silva Cunha´ Flatten from/to Relational – 1 / 21 Flatten from/to Relational Jacome Cunha´ ∗ Joao Saraiva˜ ∗ Joost Visser† CIC 2007

Introduction

Introduction

• Motivation• Bidirectionaltransformation

• What is a spreadsheet?

• Relational database

• Advantages of DB

The Transformation

Example

Conclusions

Jacome Cunha Flatten from/to Relational – 3 / 21

Page 4: Flatten from/to Relational - Alexandra Silva Cunha´ Flatten from/to Relational – 1 / 21 Flatten from/to Relational Jacome Cunha´ ∗ Joao Saraiva˜ ∗ Joost Visser† CIC 2007

Motivation

Introduction

• Motivation• Bidirectionaltransformation

• What is a spreadsheet?

• Relational database

• Advantages of DB

The Transformation

Example

Conclusions

Jacome Cunha Flatten from/to Relational – 4 / 21

Spreadsheets are considered one of the largest pro-gramming languages in the world

Their languages/systems lack structured programmingfeatures

Programming in a spreadsheet environment is an errorprone task

Data manipulation is not so supported as in otherparadigms

Page 5: Flatten from/to Relational - Alexandra Silva Cunha´ Flatten from/to Relational – 1 / 21 Flatten from/to Relational Jacome Cunha´ ∗ Joao Saraiva˜ ∗ Joost Visser† CIC 2007

Bidirectional transformation

Introduction

• Motivation• Bidirectionaltransformation

• What is a spreadsheet?

• Relational database

• Advantages of DB

The Transformation

Example

Conclusions

Jacome Cunha Flatten from/to Relational – 5 / 21

DBSS

The flatten model of a spreadsheet is mapped into arelational database model

The other way around is also shown

Page 6: Flatten from/to Relational - Alexandra Silva Cunha´ Flatten from/to Relational – 1 / 21 Flatten from/to Relational Jacome Cunha´ ∗ Joao Saraiva˜ ∗ Joost Visser† CIC 2007

What is a spreadsheet?

Introduction

• Motivation• Bidirectionaltransformation

• What is a spreadsheet?

• Relational database

• Advantages of DB

The Transformation

Example

Conclusions

Jacome Cunha Flatten from/to Relational – 6 / 21

celltext

formulasgraphics

incrementalreferences to other cells

Page 7: Flatten from/to Relational - Alexandra Silva Cunha´ Flatten from/to Relational – 1 / 21 Flatten from/to Relational Jacome Cunha´ ∗ Joao Saraiva˜ ∗ Joost Visser† CIC 2007

Relational database

Introduction

• Motivation• Bidirectionaltransformation

• What is a spreadsheet?

• Relational database

• Advantages of DB

The Transformation

Example

Conclusions

Jacome Cunha Flatten from/to Relational – 7 / 21

It is a structured collection of records distributed overtables

Some concepts:

Primary key it is a set of attributes in the record thatuniquely determine all the others

Functional dependency a set of attributes X function-ally determines a set of attributes Y iff each X valueis associated with only one Y value

Foreign key it is a reference to another entry in othertable

Page 8: Flatten from/to Relational - Alexandra Silva Cunha´ Flatten from/to Relational – 1 / 21 Flatten from/to Relational Jacome Cunha´ ∗ Joao Saraiva˜ ∗ Joost Visser† CIC 2007

Advantages of DB

Introduction

• Motivation• Bidirectionaltransformation

• What is a spreadsheet?

• Relational database

• Advantages of DB

The Transformation

Example

Conclusions

Jacome Cunha Flatten from/to Relational – 8 / 21

The existence of database management system(DBMS) allows:

• insert, remove and update data in the DB• chance the format of the DB• ensures the integrity of the DB• backup and replication• give permissions to users or deny them

Examples:

• Oracle, Microsoft Access, MySQL, PostgreSQL

Page 9: Flatten from/to Relational - Alexandra Silva Cunha´ Flatten from/to Relational – 1 / 21 Flatten from/to Relational Jacome Cunha´ ∗ Joao Saraiva˜ ∗ Joost Visser† CIC 2007

The Transformation

Introduction

The Transformation

• The big picture

• Inferring FDs

• Normalisation

• Data migration

Example

Conclusions

Jacome Cunha Flatten from/to Relational – 9 / 21

Page 10: Flatten from/to Relational - Alexandra Silva Cunha´ Flatten from/to Relational – 1 / 21 Flatten from/to Relational Jacome Cunha´ ∗ Joao Saraiva˜ ∗ Joost Visser† CIC 2007

The big picture

Introduction

The Transformation

• The big picture

• Inferring FDs

• Normalisation

• Data migration

Example

Conclusions

Jacome Cunha Flatten from/to Relational – 10 / 21

a11 . . . a1n...

...am1 . . . amn

:: (A1 × . . . × An)∗

ց↓ extract FDs

↓ 2LT Π(Ai . . . Ak ⇀ Aj . . . Al)

↓ normalisation

(am . . . av ⇀ an . . . ay)∗ :: Π(Am . . . Av ⇀ An . . . At)

Page 11: Flatten from/to Relational - Alexandra Silva Cunha´ Flatten from/to Relational – 1 / 21 Flatten from/to Relational Jacome Cunha´ ∗ Joao Saraiva˜ ∗ Joost Visser† CIC 2007

Inferring FDs

Introduction

The Transformation

• The big picture

• Inferring FDs

• Normalisation

• Data migration

Example

Conclusions

Jacome Cunha Flatten from/to Relational – 11 / 21

We assume that the table has only data, not code orformulas or other things

Information about relation between columns is neededotherwise there will be too many FDs and will becomeuseless

The FUN algorithm (Noel Novelli and Rosine Cicchetti)is used to infer the FDs

Page 12: Flatten from/to Relational - Alexandra Silva Cunha´ Flatten from/to Relational – 1 / 21 Flatten from/to Relational Jacome Cunha´ ∗ Joao Saraiva˜ ∗ Joost Visser† CIC 2007

Normalisation

Introduction

The Transformation

• The big picture

• Inferring FDs

• Normalisation

• Data migration

Example

Conclusions

Jacome Cunha Flatten from/to Relational – 12 / 21

For each association of columns several FDs areyielded by the algorithm

One is chosen and a table is created according to it

The columns that are not referred are collected into atable where the primary key is a set constituted by theprimary keys from other tables

Page 13: Flatten from/to Relational - Alexandra Silva Cunha´ Flatten from/to Relational – 1 / 21 Flatten from/to Relational Jacome Cunha´ ∗ Joao Saraiva˜ ∗ Joost Visser† CIC 2007

Data migration

Introduction

The Transformation

• The big picture

• Inferring FDs

• Normalisation

• Data migration

Example

Conclusions

Jacome Cunha Flatten from/to Relational – 13 / 21

Performed by implementing refinement laws into 2LT

kA ⇀ B

to

((

∼= [kA × B]

from

hh

Abstraction (from) and representation (to) functionsare needed to witness the refinement

Page 14: Flatten from/to Relational - Alexandra Silva Cunha´ Flatten from/to Relational – 1 / 21 Flatten from/to Relational Jacome Cunha´ ∗ Joao Saraiva˜ ∗ Joost Visser† CIC 2007

Example

Introduction

The Transformation

Example

• Internships

• Company’s table

• Student’s tables

• DB model

Conclusions

Jacome Cunha Flatten from/to Relational – 14 / 21

Page 15: Flatten from/to Relational - Alexandra Silva Cunha´ Flatten from/to Relational – 1 / 21 Flatten from/to Relational Jacome Cunha´ ∗ Joao Saraiva˜ ∗ Joost Visser† CIC 2007

Internships

Introduction

The Transformation

Example

• Internships

• Company’s table

• Student’s tables

• DB model

Conclusions

Jacome Cunha Flatten from/to Relational – 15 / 21

Page 16: Flatten from/to Relational - Alexandra Silva Cunha´ Flatten from/to Relational – 1 / 21 Flatten from/to Relational Jacome Cunha´ ∗ Joao Saraiva˜ ∗ Joost Visser† CIC 2007

Internships

Introduction

The Transformation

Example

• Internships

• Company’s table

• Student’s tables

• DB model

Conclusions

Jacome Cunha Flatten from/to Relational – 15 / 21

There should be “enough” cases to represent the reality

Page 17: Flatten from/to Relational - Alexandra Silva Cunha´ Flatten from/to Relational – 1 / 21 Flatten from/to Relational Jacome Cunha´ ∗ Joao Saraiva˜ ∗ Joost Visser† CIC 2007

Company’s table

Introduction

The Transformation

Example

• Internships

• Company’s table

• Student’s tables

• DB model

Conclusions

Jacome Cunha Flatten from/to Relational – 16 / 21

company, contacts and location are related

company -> contacts, location

contacts -> company, location

Page 18: Flatten from/to Relational - Alexandra Silva Cunha´ Flatten from/to Relational – 1 / 21 Flatten from/to Relational Jacome Cunha´ ∗ Joao Saraiva˜ ∗ Joost Visser† CIC 2007

Company’s table

Introduction

The Transformation

Example

• Internships

• Company’s table

• Student’s tables

• DB model

Conclusions

Jacome Cunha Flatten from/to Relational – 16 / 21

company, contacts and location are related

company -> contacts, location

contacts -> company, location

companycontactslocation

Company

Page 19: Flatten from/to Relational - Alexandra Silva Cunha´ Flatten from/to Relational – 1 / 21 Flatten from/to Relational Jacome Cunha´ ∗ Joao Saraiva˜ ∗ Joost Visser† CIC 2007

Student’s tables

Introduction

The Transformation

Example

• Internships

• Company’s table

• Student’s tables

• DB model

Conclusions

Jacome Cunha Flatten from/to Relational – 17 / 21

st.number, st.name and graduation are alsorelated

st.number -> st.name, graduation

Page 20: Flatten from/to Relational - Alexandra Silva Cunha´ Flatten from/to Relational – 1 / 21 Flatten from/to Relational Jacome Cunha´ ∗ Joao Saraiva˜ ∗ Joost Visser† CIC 2007

Student’s tables

Introduction

The Transformation

Example

• Internships

• Company’s table

• Student’s tables

• DB model

Conclusions

Jacome Cunha Flatten from/to Relational – 17 / 21

st.number, st.name and graduation are alsorelated

st.number -> st.name, graduation

number

namegraduation

Student

Page 21: Flatten from/to Relational - Alexandra Silva Cunha´ Flatten from/to Relational – 1 / 21 Flatten from/to Relational Jacome Cunha´ ∗ Joao Saraiva˜ ∗ Joost Visser† CIC 2007

DB model

Introduction

The Transformation

Example

• Internships

• Company’s table

• Student’s tables

• DB model

Conclusions

Jacome Cunha Flatten from/to Relational – 18 / 21

companycontactslocation

companynumber

salarystatus

descriptiontime

number

namegraduation

Company Internship Student

Company (_company, contacts, location)

Student (_st.number, st.name, graduation)

Internship (_company, _st.number, salary, status, description, time)

foreign key (company)

references Company(company)

foreign key (st.number)

references Student(st.number)

Page 22: Flatten from/to Relational - Alexandra Silva Cunha´ Flatten from/to Relational – 1 / 21 Flatten from/to Relational Jacome Cunha´ ∗ Joao Saraiva˜ ∗ Joost Visser† CIC 2007

Conclusions

Introduction

The Transformation

Example

Conclusions

• Conclusions

• Future work

Jacome Cunha Flatten from/to Relational – 19 / 21

Page 23: Flatten from/to Relational - Alexandra Silva Cunha´ Flatten from/to Relational – 1 / 21 Flatten from/to Relational Jacome Cunha´ ∗ Joao Saraiva˜ ∗ Joost Visser† CIC 2007

Conclusions

Introduction

The Transformation

Example

Conclusions

• Conclusions

• Future work

Jacome Cunha Flatten from/to Relational – 20 / 21

Start with a flatten data table, a spreadsheet

Determine FDs (automatically) and the relational DBschema (not so automatically)

Allows the migration to a well known and supportedparadigm

Page 24: Flatten from/to Relational - Alexandra Silva Cunha´ Flatten from/to Relational – 1 / 21 Flatten from/to Relational Jacome Cunha´ ∗ Joao Saraiva˜ ∗ Joost Visser† CIC 2007

Future work

Introduction

The Transformation

Example

Conclusions

• Conclusions

• Future work

Jacome Cunha Flatten from/to Relational – 21 / 21

Import a spreadsheet (and other formats) to HASKELL

Tune the FDs inference/normalisation

Integration into 2LT framework

Create ways of export the new model to SQL or tospreadsheet