Lemma 1
Ref: DS/FMU/FEF/029
DRA FRONT END FILTER PROJECT
Issue: Revision : 2 .1
Specification of Query Transformations in HOL (II)
Date: 5 June 2016
Project:
DRA FRONT END FILTER PROJECT
Title:
Specification of Query Transformations in HOL (II)
Ref:
DS/FMU/FEF/029
Status:
Approved
Issue: Revision : 2 .1
Date: 5 June 2016
Type: Specification
Keywords:
Author:
Name
Location
R.D. Arthan
WIN01
Signature
Date
Signature
Date
Authorisation for Issue:
Name
Function
R.B. Jones
HAT Manager
Abstract:
A specification of the SSQL Query Transformations in HOL for the DRA front
end filter project RSRE 1C/6130.
Distribution: HAT FEF File
Simon Wiseman
Page 1 of 45
Lemma 1
0
0.1
Ref: DS/FMU/FEF/029
DRA FRONT END FILTER PROJECT
Issue: Revision : 2 .1
Specification of Query Transformations in HOL (II)
Date: 5 June 2016
DOCUMENT CONTROL
Contents List
0 DOCUMENT CONTROL
0.1 Contents List . . . . . . . .
0.2 Document Cross References
0.3 Changes History . . . . . .
0.4 Changes Forecast . . . . . .
.
.
.
.
2
2
2
3
3
1 GENERAL
1.1 Scope . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1.2 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1.3 ProofPower Preamble . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4
4
4
4
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
2 THE TRANSFORMATIONS
2.1 Incompletely Specified Transformations
2.2 Symbol Table Model . . . . . . . . . . .
2.3 Symbol Table Operations . . . . . . . .
2.4 Transformations Proper . . . . . . . . .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
4
5
6
18
25
3 INTERFACE
43
4 INDEX
44
0.2
Document Cross References
[1] L.Paulson. ML for the Working Programmer. Cambridge University Press, 1991.
[2] Robin Milner, Mads Tofte, and Robert Harper. The Definition of Standard ML. MIT Press,
1990.
[3] DS/FMU/FEF/004. Specification of SSQL Semantics I. G.M. Prout, ICL Secure Systems,
WIN01.
[4] DS/FMU/FEF/014. Specification of SSQL Semantics II. G.M. Prout, ICL Secure Systems,
WIN01.
[5] DS/FMU/FEF/018. Proposal for Phase 2. G.M. Prout, ICL Secure Systems, WIN01.
[6] DS/FMU/FEF/020. Specification of Query Transformations in SML (II). G.M. Prout, ICL
Secure Systems, WIN01.
[7] DS/FMU/FEF/022. SWORD Front End Architectural Model. R.D. Arthan, ICL Secure Systems, WIN01.
[8] DS/FMU/FEF/028. Specification of Query Transformations in HOL (I). R.D. Arthan, ICL
Secure Systems, WIN01.
[9] DS/FMU/FEF/029. Specification of Query Transformations in HOL (II). R.D. Arthan, ICL
Secure Systems, WIN01.
Page 2 of 45
Lemma 1
Ref: DS/FMU/FEF/029
DRA FRONT END FILTER PROJECT
Issue: Revision : 2 .1
Specification of Query Transformations in HOL (II)
Date: 5 June 2016
[10] The Specification of Secure SQL. Simon Wiseman, DRA, 6th July 1992.
[11] SSQL Transformations. Simon Wiseman, DRA, 14th January 1993.
0.3
Changes History
Issue 1.1 (21 May 1993) First draft.
Issue 1.9 (23 August 1993) Minor correction and fix in light of comments received.
Issue Revision : 2 .1 (5 June 2016) Final approved version.
Issue 2.2 Removed dependency on ICL logo font
0.4
Changes Forecast
None.
Page 3 of 45
Lemma 1
1
1.1
Ref: DS/FMU/FEF/029
DRA FRONT END FILTER PROJECT
Issue: Revision : 2 .1
Specification of Query Transformations in HOL (II)
Date: 5 June 2016
GENERAL
Scope
This document gives a formal specification in HOL ([2], [1]) of the SSQL query transformations of
[11]. It constitutes part of deliverable D11 of work package 3, as given in the Proposal for Phase 2,
[5].
The current version of this document is gives only a partial treatment to indicate the flavour of what
can be done in this area. In particular, the main mutually recursive functions which perform the
transformations are in vestigial form, since their structure is heavily dependent on the SSQL syntax
and it was felt best to defer their formalisation in HOL until the SSQL syntax definitions [4] have
been brought into line with the most recent specification of SSQL.
During discussions with DRA, it was agreed that this area of the specification work in HOL was
adequately covered for the purposes of Phase 2, and that attention should be concentrated on the
areas were proof work can be carried out within phase 2 resource limitations.
1.2
Introduction
We provide HOL specifications of the SSQL query transformations of [11]. Preliminary material
needed to support these query transformation specifications may be found in [8].
1.3
ProofPower Preamble
The following commands initialise the ProofPower system to accept the specifications:
SML
open theory"fef028 ";
(force delete theory "fef029 " handle
new theory"fef029 ";
set pc"hol ";
2
=> ());
THE TRANSFORMATIONS
The following error values are required in addition to those introduced in [3].
HOL Constant
internalError
onlyInTriggers
notTriadic
noScope
emptyUnionList
wrongWorth
notMonadic
notSetFunction
wrongScope
:
notTrigger
notDyadic
noSuchParameter
ambiguousName
Error
true
Page 4 of 45
Lemma 1
2.1
Ref: DS/FMU/FEF/029
DRA FRONT END FILTER PROJECT
Issue: Revision : 2 .1
Specification of Query Transformations in HOL (II)
Date: 5 June 2016
Incompletely Specified Transformations
Some functions have not been specified in [11]. They are loosely defined here. Some of them
depend on the state of the transformation process, this is modelled by the following labelled product
type. Of the four components of the state, only the first, the symbol table stack, varies during
the transformation, the other components simply record information supplied as parameters to the
overall transformation process. The projection functions for these parameter components serve for
the functions of the same name from [8, 11].
HOL Labelled Product
TRANS STATE
st stack
query class
query constants class
client clearance
:
:
:
:
ST STACK ;
Class;
Class;
Class
HOL Constant
check enum : Enum × Int × Table spec → BOOL;
check fixed : Fixed × Int × Int → BOOL;
check floating : Float × Int × Int × Int → BOOL;
check interval : Interval × STRING → BOOL;
check time : Time × STRING → BOOL;
timeFormatToInterval : STRING → STRING;
unique name : TRANS STATE → STRING;
contextual data : STRING → Value × Class;
default directory : STRING LIST
true
Notes:
1. check enum is, presumably, parameterised by the structure and content of the database. The
above parameterisation is therefore not very realistic, since it only permits dependence on the
structure of the database (presumed fixed), not its contents.
2. unique name parameterised as above could only produce names which were unique within the
current symbol-table scope, not within the entire transformation process.
We need a function to set up an initial state based on the client clearance:
Page 5 of 45
Lemma 1
Ref: DS/FMU/FEF/029
DRA FRONT END FILTER PROJECT
Issue: Revision : 2 .1
Specification of Query Transformations in HOL (II)
Date: 5 June 2016
HOL Constant
init trans state: Class → TRANS STATE
∀c•
init trans state c =
MkTRANS STATE
(MkST STACK [] [])
c
c
c
2.2
Symbol Table Model
HOL Constant
findcolumn : ColumnSpecification × TableDetail LIST →
(TableDetail × SsqlCol × TsqlCol )LIST
∀cs tdl •
find c o l u m n (cs,tdl ) =
let
look (n, td , scl , tcl ) =
let sctcl = splice scl tcl
in let sctcl ′ = sctcl ↾ {(sc, tc) | sc name sc = mk name s n}
in Map (λ(sc, tc)• (td , sc, tc)) sctcl ′
in let do1td td =
CASE cs [
WHEN anonymous column col •
look (col , td , td columns td , td implementation td );
WHEN specific (ts, col )•
CASE (td tableName td ) [
WHEN name t n ts•
look (col , td , td columns td , td implementation td );
OTHERS []
]
]
in
Flat(Map do1td tdl )
Page 6 of 45
Lemma 1
Ref: DS/FMU/FEF/029
DRA FRONT END FILTER PROJECT
Issue: Revision : 2 .1
Specification of Query Transformations in HOL (II)
Date: 5 June 2016
HOL Constant
findident : ColumnSpecification × IdentDetail LIST →
IdentDetail LIST
∀cs idl •
find i d e n t (cs, idl ) =
CASE cs [
WHEN specific (t, c)• [];
WHEN anonymous column col •
idl ↾ {id | col = id identName id }
]
We replace the function look , which is private to lookupcolumn info in [9, 11] by a top-level function,
lookup column info look (since it is recursive and HOL local functions cannot be recursive).
HOL Constant
lookup column info look :
ColumnSpecification × Scope LIST → (TableInfo × SsqlCol )RESULT
∀cs ti outer •
lookup column info look (cs, []) = Exception [noSuchColumn]
∧
lookup column info look (cs, outer a [ti ]) =
let
t = s tables ti
in let tdsctcl = find c o l u m n (cs, t)
in
if
tdsctcl = []
then lookup column info look (cs, outer )
else if Tl (tdsctcl ) = []
then let (td , sc, tc) = Hd tdsctcl in Ok (td info td , sc)
else
Exception [ambiguousName]
HOL Constant
lookupcolumninf o :
TRANS STATE → ColumnSpecification → (TableInfo × SsqlCol )RESULT
∀st cs•lookup c o l u m n i n f o st cs =
lookup column info look (cs, symbolTable(st stack st))
Page 7 of 45
Ref: DS/FMU/FEF/029
DRA FRONT END FILTER PROJECT
Issue: Revision : 2 .1
Specification of Query Transformations in HOL (II)
Date: 5 June 2016
Lemma 1
HOL Constant
maxBound : BoundInfo → Class
∀bi •
maxBound bi =
CASE bi [
WHEN upb c• c;
WHEN constant c• c
]
HOL Constant
innermost : Scope LIST → Scope LIST
∀outer inner •
innermost [] = []
∧
innermost (outer a [inner ]) =
let tds = s tables inner
in
if
tds = []
then
else
innermost outer a [inner ]
[inner ]
As with lookupcolumn info , we replace the recursive function look local to lookupcol info by a top-level
function look up col spec class look . The comments before the thens below show the corresponding
ML pattern match (cf. [6]).
Page 8 of 45
Lemma 1
Ref: DS/FMU/FEF/029
DRA FRONT END FILTER PROJECT
Issue: Revision : 2 .1
Specification of Query Transformations in HOL (II)
Date: 5 June 2016
HOL Constant
lookup col spec class look
: ColumnSpecification × Scope LIST → (TsqlRepr × Class) RESULT
∀ cs outer ti •
lookup col spec class look (cs,[]) = Exception [noSuchColumn]
∧
lookup col spec class look (cs, outer a [ti ]) =
let
in let
and
in
(∗
(∗
(∗
(∗
(∗
(t, i ) = (s tables ti , s identifiers ti )
cds = find c o l u m n (cs,t)
ids = find i d e n t (cs,i )
if
ids = []
then if
cds = []
([], []) ∗)
then lookup col spec class look (cs, outer )
else
if
Tl cds = []
([(td ,sc,tc)], []) ∗) then let
(td , sc, tc) = Hd cds
in let u = maxBound (sc col class sc)
in
CASE (tc class name tc) [
WHEN anon t c
(Exception[internalError ]);
WHEN name t c s•
Ok (mk column(td genCorr td , s), u);
WHEN constant t c c•
Ok (mk constant class c,u)
]
(xs, []) ∗)
else
Exception [ambiguousName]
else
if
cds = [] ∧ Tl ids = []
([], [id ]) ∗) then let
id = Hd ids
in let cl = id lub i d id
in
CASE (id cName id ) [
WHEN none t (Ok (mk constant class cl , cl ));
WHEN anon t (Exception[internalError ]);
WHEN name t s•Ok (mk local identifier s, cl )
]
(xs, ys) ∗)
else
Exception [ambiguousName]
Page 9 of 45
Lemma 1
Ref: DS/FMU/FEF/029
DRA FRONT END FILTER PROJECT
Issue: Revision : 2 .1
Specification of Query Transformations in HOL (II)
Date: 5 June 2016
HOL Constant
lookupcolspecclass
: TRANS STATE → (BOOL × ColumnSpecification) → (TsqlRepr × Class)RESULT
∀st flg cs•
lookup c o l s p e c c l a s s st (flg, cs) =
if
flg
then lookup col spec class look (cs, innermost(symbolTable(st stack st)))
else
lookup col spec class look (cs, (symbolTable(st stack st)))
Mutatatis mutandis, the remarks about lookup col spec class look above apply both to to other
functions with names of the form XXXl ook below.
Page 10 of 45
Lemma 1
Ref: DS/FMU/FEF/029
DRA FRONT END FILTER PROJECT
Issue: Revision : 2 .1
Specification of Query Transformations in HOL (II)
Date: 5 June 2016
HOL Constant
lookup col spec dinary look
: ColumnSpecification × Scope LIST → TsqlRepr RESULT
∀ cs outer ti •
lookup col spec dinary look (cs,[]) = Exception [noSuchColumn]
∧
lookup col spec dinary look (cs, outer a [ti ]) =
let
in let
and
in
(∗
(∗
(∗
(∗
(∗
(t, i ) = (s tables ti , s identifiers ti )
cds = find c o l u m n (cs,t)
ids = find i d e n t (cs,i )
if
ids = []
then if
cds = []
([], []) ∗)
then lookup col spec dinary look (cs, outer )
else
if
Tl cds = []
([(td ,sc,tc)], []) ∗) then let
(td , sc, tc) = Hd cds
in
CASE (tc dinary name tc) [
WHEN none t
(Exception[internalError ]);
WHEN anon t
(Exception[internalError ]);
WHEN name t s•
Ok (mk column(td genCorr td , s))
]
(xs, []) ∗)
else
Exception [ambiguousName]
else
if
cds = [] ∧ Tl ids = []
([], [id ]) ∗) then let
id = Hd ids
in let (st, w ) = id info id
in
if
w = dinary
then Ok (mk local identifier (id vName id ))
else
Ok (c constant null )
(xs, ys) ∗)
else
Exception [ambiguousName]
HOL Constant
lookupcolspecdinary :
TRANS STATE → (BOOL × ColumnSpecification) → TsqlRepr RESULT
∀st flg cs•
lookup c o l s p e c d i n a r y st (flg, cs) =
if
flg
then lookup col spec dinary look (cs, innermost(symbolTable(st stack st)))
else
lookup col spec dinary look (cs, (symbolTable(st stack st)))
Page 11 of 45
Lemma 1
Ref: DS/FMU/FEF/029
DRA FRONT END FILTER PROJECT
Issue: Revision : 2 .1
Specification of Query Transformations in HOL (II)
Date: 5 June 2016
HOL Constant
lookup col spec sterling look
: ColumnSpecification × Scope LIST → TsqlRepr RESULT
∀ cs outer ti •
lookup col spec sterling look (cs,[]) = Exception [noSuchColumn]
∧
lookup col spec sterling look (cs, outer a [ti ]) =
let
in let
and
in
(∗
(∗
(∗
(∗
(∗
(t, i ) = (s tables ti , s identifiers ti )
cds = find c o l u m n (cs,t)
ids = find i d e n t (cs,i )
if
ids = []
then if
cds = []
([], []) ∗)
then lookup col spec sterling look (cs, outer )
else
if
Tl cds = []
([(td ,sc,tc)], []) ∗) then let
(td , sc, tc) = Hd cds
in
CASE (tc sterling name tc) [
WHEN none t
(Exception[internalError ]);
WHEN anon t
(Exception[internalError ]);
WHEN name t s•
Ok (mk column(td genCorr td , s))
]
(xs, []) ∗)
else
Exception [ambiguousName]
else
if
cds = [] ∧ Tl ids = []
([], [id ]) ∗) then let
id = Hd ids
in let (st, w ) = id info id
in
if
w = sterling
then Ok (mk local identifier (id vName id ))
else
Ok (c constant null )
(xs, ys) ∗)
else
Exception [ambiguousName]
HOL Constant
lookupcolspecsterling :
TRANS STATE → (BOOL × ColumnSpecification) → TsqlRepr RESULT
∀st flg cs•
lookup c o l s p e c s t e r l i n g st (flg, cs) =
if
flg
then lookup col spec sterling look (cs, innermost(symbolTable(st stack st)))
else
lookup col spec sterling look (cs, (symbolTable(st stack st)))
Page 12 of 45
Ref: DS/FMU/FEF/029
DRA FRONT END FILTER PROJECT
Issue: Revision : 2 .1
Specification of Query Transformations in HOL (II)
Date: 5 June 2016
Lemma 1
HOL Constant
lookuplocalcolimplementation
: TRANS STATE → TsqlCol LIST RESULT
∀ st• lookup l o c a l c o l i m p l e m e n t a t i o n st =
let
extract implementation sc =
Fold ($a) (Map td implementation (s tables sc)) []
in let trs =
Fold ($a)
in
(Map
if
then
else
extract implementation (innermost(symbolTable(st stack st))))[]
trs = []
Exception[noScope]
Ok trs
HOL Constant
lookuplocalcolinf o
: TRANS STATE → SsqlCol LIST RESULT
∀ st• lookup l o c a l c o l i n f o st =
let
extract columns sc =
Fold ($a) (Map td columns (s tables sc)) []
in let trs =
Fold ($a)
in
(Map
if
then
else
extract columns (innermost(symbolTable(st stack st))))[]
trs = []
Exception[noScope]
Ok trs
Page 13 of 45
Ref: DS/FMU/FEF/029
DRA FRONT END FILTER PROJECT
Issue: Revision : 2 .1
Specification of Query Transformations in HOL (II)
Date: 5 June 2016
Lemma 1
HOL Constant
lookuplocalcolspecclasses
: TRANS STATE → (TsqlRepr × Class) LIST RESULT
∀ st• lookup l o c a l c o l s p e c c l a s s e s st =
let
look2 (corr ,sc,tc) =
let
u = maxBound (sc col class sc)
in
CASE (tc class name tc) [
WHEN anon t c (Exception[internalError ]);
WHEN name t c s• Ok (mk column(corr , s), u);
WHEN constant t c c• Ok (mk constant class c,u)
]
in let look1 td = at3 (Map look2 )
(seq (Length (td columns td )) (td genCorr td ),
td columns td , td implementation td )
in let look sc = Fold ($a) (Map look1 (s tables sc)) []
in let trs =
in
Fold ($a) (Map look (innermost(symbolTable(st stack st))))[]
if
trs = []
then Exception[noScope]
else
ListOk trs
Page 14 of 45
Ref: DS/FMU/FEF/029
DRA FRONT END FILTER PROJECT
Issue: Revision : 2 .1
Specification of Query Transformations in HOL (II)
Date: 5 June 2016
Lemma 1
HOL Constant
lookuplocalcolspecsterlings
: TRANS STATE → TsqlRepr LIST RESULT
∀ st• lookup l o c a l c o l s p e c s t e r l i n g s st =
let
look2 (corr ,tc) =
CASE (tc sterling name tc) [
WHEN none t (Ok c constant null );
WHEN anon t (Exception[internalError ]);
WHEN name t s• Ok (mk column(corr , s))
]
in let look1 td = at2 (Map look2 )
(seq (Length (td columns td )) (td genCorr td ),
td implementation td )
in let look sc = Fold ($a) (Map look1 (s tables sc)) []
in let trs =
in
Fold ($a) (Map look (innermost(symbolTable(st stack st))))[]
if
trs = []
then Exception[noScope]
else
ListOk trs
HOL Constant
lookuplocalrowclasses
: TRANS STATE → TsqlRepr LIST RESULT
∀ st• lookup l o c a l r o w c l a s s e s st =
let
look1 td =
CASE (td rowClass td ) [
WHEN anon t c (Exception[internalError ]);
WHEN name t c s• Ok (mk column(td genCorr td , s));
WHEN constant t c c• Ok (mk constant class c)
]
in let look sc = Map look1 (s tables sc)
in let trs =
Fold ($a) (Map look (innermost(symbolTable(st stack st))))[]
in
if
then
else
trs = []
Exception[noScope]
ListOk trs
Again mutatatis mutandis, the remarks about lookup col spec class look above apply to to the
following.
Page 15 of 45
Lemma 1
Ref: DS/FMU/FEF/029
DRA FRONT END FILTER PROJECT
Issue: Revision : 2 .1
Specification of Query Transformations in HOL (II)
Date: 5 June 2016
HOL Constant
lookup column row class look
: TRANS STATE → ColumnSpecification × Scope LIST → TsqlRepr RESULT
∀ st cs outer ti •
lookup column row class look st (cs,[]) = Exception [noSuchColumn]
∧
lookup column row class look st (cs, outer a [ti ]) =
let
in let
and
in
(∗
(∗
(∗
(∗
(∗
(t, i ) = (s tables ti , s identifiers ti )
cds = find c o l u m n (cs,t)
ids = find i d e n t (cs,i )
if
ids = []
then if
cds = []
([], []) ∗)
then lookup column row class look st (cs, outer )
else
if
Tl cds = []
([(td ,sc,tc)], []) ∗) then let
(td , sc, tc) = Hd cds
in
CASE (td rowClass td ) [
WHEN anon t c
(Exception[internalError ]);
WHEN name t c s•
Ok (mk column(td genCorr td , s));
WHEN constant t c c•
Ok (mk constant class c)
]
(xs, []) ∗)
else
Exception [ambiguousName]
else
if
cds = [] ∧ Tl ids = []
([], [id ]) ∗) then let
id = Hd ids
in
Ok (mk constant class(query class st))
(xs, ys) ∗)
else
Exception [ambiguousName]
HOL Constant
lookupcolumnrowclass
: TRANS STATE → (BOOL × ColumnSpecification) → TsqlRepr RESULT
∀st flg cs•
lookup c o l u m n r o w c l a s s st (flg, cs) =
if
flg
then lookup column row class look st (cs, innermost(symbolTable(st stack st)))
else
lookup column row class look st (cs, (symbolTable(st stack st)))
Again mutatatis mutandis, the remarks about lookup col spec class look above apply to to the
following.
Page 16 of 45
Lemma 1
Ref: DS/FMU/FEF/029
DRA FRONT END FILTER PROJECT
Issue: Revision : 2 .1
Specification of Query Transformations in HOL (II)
Date: 5 June 2016
HOL Constant
lookup table row class look
: TableSpecification × Scope LIST → TsqlRepr RESULT
∀ts outer ti •
lookup table row class look (ts, []) = Exception [noSuchTable]
∧
lookup table row class look (ts, outer a [ti ]) =
let
look1 (ts, td ) =
CASE (td tableName td ) [
WHEN anon t n [];
WHEN name t n tn•
if
ts = tn
then CASE (td rowClass td ) [
WHEN anon t c [Exception[internalError ]];
WHEN name t c s•
[Ok (mk column(td genCorr td , s))];
WHEN constant t c c•
[Ok (mk constant class c)]
]
else
[]
]
in let (tds, ids) = (s tables ti , s identifiers ti )
in let trs = Fold ($a) (at2 (Map look1 ) (seq (Length tds) (ts), tds)) []
in
if
trs = [] then lookup table row class look (ts, outer )
else if Tl trs = []
then Hd trs
else
Exception[ambiguousName]
HOL Constant
lookuptablerowclass
: TRANS STATE → (BOOL × TableSpecification) → TsqlRepr RESULT
∀st flg ts•
lookup t a b l e r o w c l a s s st (flg, ts) =
if
flg
then lookup table row class look (ts, innermost(symbolTable(st stack st)))
else
lookup table row class look (ts, (symbolTable(st stack st)))
Page 17 of 45
Lemma 1
Ref: DS/FMU/FEF/029
DRA FRONT END FILTER PROJECT
Issue: Revision : 2 .1
Specification of Query Transformations in HOL (II)
Date: 5 June 2016
HOL Constant
lookup table detail look
: TableSpecification × Scope LIST → TableDetail RESULT
∀ts outer ti •
lookup table detail look (ts, []) = Exception [noSuchTable]
∧
lookup table detail look (ts, outer a [ti ]) =
let
look1 (ts, td ) =
CASE (td tableName td ) [
WHEN anon t n [];
WHEN name t n tn•
if
ts = tn
then [td ]
else
[]
]
in let (tds, ids) = (s tables ti , s identifiers ti )
in let tis = Fold ($a) (at2 (Map look1 ) (seq (Length tds) (ts), tds)) []
in
if
tis = [] then lookup table detail look (ts, outer )
else if Tl tis = []
then Ok (Hd tis)
else
Exception[ambiguousName]
HOL Constant
lookuptabledetail
: TRANS STATE → TableSpecification → TableDetail RESULT
∀st ts•
lookup t a b l e d e t a i l st ts =
lookup table detail look (ts, (symbolTable(st stack st)))
2.3
Symbol Table Operations
The following operation on state is a convenient short-hand in defining these operations. It replaces
the top scope in the symbol table in a state with a given value.
Page 18 of 45
Lemma 1
Ref: DS/FMU/FEF/029
DRA FRONT END FILTER PROJECT
Issue: Revision : 2 .1
Specification of Query Transformations in HOL (II)
Date: 5 June 2016
HOL Constant
update top scope : TRANS STATE → Scope → TRANS STATE
∀st sc•
update
let
in let
in let
top scope st sc =
stk = st stack st
symt = symbolTable stk
outer = Rev (Tl (Rev symt))
in let symt ′ = outer a [sc]
in
MkTRANS STATE
(MkST STACK symt ′ (parameterTable stk ))
(query class st) (query constants class st) (client clearance st)
The local function find used in several places in the following has been misspelt as fynd to avoid
clashing with the constant find defined in [4].
Page 19 of 45
Lemma 1
Ref: DS/FMU/FEF/029
DRA FRONT END FILTER PROJECT
Issue: Revision : 2 .1
Specification of Query Transformations in HOL (II)
Date: 5 June 2016
HOL Constant
enteridentif ier
: TRANS STATE → (STRING × ExpType × Class)
→ (TRANS STATE × STRING × STRING)RESULT
∀st name et up•
enter i d e n t i f i e r st (name,et,up) =
let
fynd (n,id ) = if n = id identName id then [id ] else []
in let sl = symbolTable(st stack st)
in
if
sl = []
then Exception[noScope]
else
let
outer = Rev (Tl (Rev sl ))
in let ti = Hd (Rev sl )
in let (tds, ids) = (s tables ti , s identifiers ti )
in
if
tds = []
then let
unv = unique name st
in let unc = unique name st
in let id =
MkIdentDetail
name et up unv (mk name t unc)
in
if
¬
at2 (Map fynd )
(seq(Length ids)name,ids)
= []
then Exception[ambiguousName]
let
sc ′ = MkScope [] (ids a [id ])
in
Ok (update top scope st sc ′ , unv ,unc)
Exception[wrongScope]
else
else
Page 20 of 45
Lemma 1
Ref: DS/FMU/FEF/029
DRA FRONT END FILTER PROJECT
Issue: Revision : 2 .1
Specification of Query Transformations in HOL (II)
Date: 5 June 2016
HOL Constant
enteridentif erconstantclass
: TRANS STATE → (STRING × ExpType × Class)
→ (TRANS STATE × STRING)RESULT
∀st name et clasf •
enter i d e n t i f e r c o n s t a n t c l a s s st (name,et,clasf ) =
let
fynd (n,id ) = if n = id identName id then [id ] else []
in let sl = symbolTable(st stack st)
in
if
sl = []
then Exception[noScope]
else
let
outer = Rev (Tl (Rev sl ))
in let ti = Hd (Rev sl )
in let (tds, ids) = (s tables ti , s identifiers ti )
in
if
tds = []
then let
unv = unique name st
in let id =
MkIdentDetail
name et clasf unv c anon t
in
if
¬
at2 (Map fynd )
(seq(Length ids)name,ids)
= []
then Exception[ambiguousName]
let
sc ′ = MkScope [] (ids a [id ])
in
Ok (update top scope st sc ′ , unv )
Exception[wrongScope]
else
else
HOL Constant
extractparameter : STRING × ParamInfo LIST → ParamInfo LIST
∀name l •
extract p a r a m e t e r (name,l ) = l ↾ {pi | pi name pi = name}
Page 21 of 45
Lemma 1
Ref: DS/FMU/FEF/029
DRA FRONT END FILTER PROJECT
Issue: Revision : 2 .1
Specification of Query Transformations in HOL (II)
Date: 5 June 2016
HOL Constant
enterparameter
: TRANS STATE → STRING × Value × Class → TRANS STATE RESULT
∀st name v clasf •
enter p a r a m e t e r st (name,v ,clasf ) =
let
sl = symbolTable(st stack st)
in let pt = parameterTable(st stack st)
in
if
sl = []
then Exception[noScope]
else if extract p a r a m e t e r (name, pt) = []
then Ok (MkTRANS STATE
(MkST STACK sl (pt a [MkParamInfo name v clasf ]))
(query class st) (query constants class st)
(client clearance st))
else
Exception[ambiguousName]
HOL Constant
entercorrtable
: TRANS STATE
→ (STRING × TableName × TableInfo ×
SsqlCol LIST × TsqlClassName × TsqlCol LIST )
→ (TRANS STATE × STRING)RESULT
∀st cn ts ti scs rcn tcs•
enter c o r r t a b l e st (cn, ts, ti , scs, rcn, tcs) =
let
sl = symbolTable(st stack st)
in
if
sl = []
then Exception[noScope]
else
let
outer = Rev (Tl (Rev sl ))
in let t = Hd (Rev sl )
in let (tds, ids) = (s tables t, s identifiers t)
in
if
ids = []
then let
gc = unique name st
in let td =
MkTableDetail
ts (mk name s cn) gc ti scs rcn
tcs (MkConstraintInfo[][][][][])
in let sc ′ = MkScope (tds a [td ]) []
else
in
Ok (update top scope st sc ′ , gc)
Exception[wrongScope]
Page 22 of 45
Lemma 1
Ref: DS/FMU/FEF/029
DRA FRONT END FILTER PROJECT
Issue: Revision : 2 .1
Specification of Query Transformations in HOL (II)
Date: 5 June 2016
HOL Constant
entertable
: TRANS STATE
→ (TableName × TableInfo × SsqlCol LIST × TsqlClassName × TsqlCol LIST )
→ (TRANS STATE × STRING)RESULT
∀st ts ti scs rcn tcs•
enter t a b l e st (ts, ti , scs, rcn, tcs) =
let
sl = symbolTable(st stack st)
in
if
sl = []
then Exception[noScope]
else
let
outer = Rev (Tl (Rev sl ))
in let t = Hd (Rev sl )
in let (tds, ids) = (s tables t, s identifiers t)
in
if
ids = []
then let
gc = unique name st
in let td =
MkTableDetail
ts (c anon s ) gc ti scs rcn
tcs (MkConstraintInfo[][][][][])
in let sc ′ = MkScope (tds a [td ]) []
else
in
Ok (update top scope st sc ′ , gc)
Exception[wrongScope]
HOL Constant
enter scope : TRANS STATE → TRANS STATE
∀st•
enter
let
in let
in let
scope st =
stk = st stack st
symt = symbolTable stk
outer = Rev (Tl (Rev symt))
in let symt ′ = outer a []
in
MkTRANS STATE
(MkST STACK symt ′ (parameterTable stk ))
(query class st) (query constants class st) (client clearance st)
The block-structured approach we use means that leave scope is not necessary.
Page 23 of 45
Lemma 1
Ref: DS/FMU/FEF/029
DRA FRONT END FILTER PROJECT
Issue: Revision : 2 .1
Specification of Query Transformations in HOL (II)
Date: 5 June 2016
HOL Constant
gettableinf o
: TableSpecification →
(TableInfo × ConstraintInfo × SsqlCol LIST × TsqlClassName × TsqlCol LIST )
true
The function lookup local
table implementation
of [6, 11] is not used so we omit it.
HOL Constant
lookuplocaltableinf o
: TRANS STATE → (TableInfo LIST ) RESULT
∀st•
lookup l o c a l t a b l e i n f o st =
let
look sc = Map td info (s tables sc)
in let trs = Fold ($a)(Map look (innermost(symbolTable(st stack st)))) []
in
if trs = []
then Exception[noScope]
else
Ok trs
HOL Constant
lookupparamdata
: TRANS STATE → STRING → (Value × Class) RESULT
∀st name•
lookup p a r a m d a t a st name =
let infos = extract p a r a m e t e r (name, parameterTable(st stack st))
in
if
infos = []
then Exception[noSuchParameter ]
else if Tl infos = []
then let info = Hd infos in Ok (pi val p info, pi clasf info)
else
Exception[internalError ]
HOL Constant
in new scope
: (TRANS STATE → ′ a → ′ b) → (TRANS STATE → ′ a → ′ b)
∀what•
in new scope what = (λst• (λa• what (enter scope st) a))
Page 24 of 45
Lemma 1
2.4
Ref: DS/FMU/FEF/029
DRA FRONT END FILTER PROJECT
Issue: Revision : 2 .1
Specification of Query Transformations in HOL (II)
Date: 5 June 2016
Transformations Proper
The following glosses over the difference between ColSpecs as defined in [4] and the more recent
versions of [10].
We also do not spell out the details of various checking functions such as monop type etc.
HOL Constant
repr col : TsqlRepr → Col spec RESULT
∀tr •
repr col tr =
CASE tr [
WHEN local identifier name• Ok (denote col spec [name]);
WHEN column(corr ,col )• Ok (denote col spec[corr ;col ]);
WHEN constant class c• Exception[internalError ];
WHEN constant null (Exception[internalError ])
]
HOL Constant
all data columnslocal : TRANS STATE → Col spec LIST RESULT
∀st•
all data columns l o c a l st =
Try
(ListOk o Map repr col )
(lookup l o c a l c o l s p e c s t e r l i n g s st)
HOL Constant
binop type : Op × SwordType × SwordType → SwordType RESULT
true
HOL Constant
monop type : Op × SwordType → SwordType RESULT
true
HOL Constant
triop type : Op × SwordType × SwordType × SwordType → SwordType RESULT
true
Page 25 of 45
Lemma 1
Ref: DS/FMU/FEF/029
DRA FRONT END FILTER PROJECT
Issue: Revision : 2 .1
Specification of Query Transformations in HOL (II)
Date: 5 June 2016
HOL Constant
set func type : Op × SwordType → SwordType RESULT
true
HOL Constant
check boolean : ExpType → ExpType RESULT
true
HOL Constant
check type conversion : SwordType × SwordType → ONE RESULT
true
The following interprets the old-style SSQL column specification as formed from a hierarchical table
directory name followed by a table name followed by a column name.
HOL Constant
convertcolspec : Col spec → ColumnSpecification
∀il •
convert c o l s p e c (denote col spec il ) =
let
col = Hd (Rev il )
in let dir = Hd (Tl (Rev il ))
in let tab = Tl (Tl (Rev il ))
in
mk specific(mk absolute(tab, dir ), col )
HOL Constant
class column : TRANS STATE → Col spec → (Col spec + Class) RESULT
∀st cs•
class column st cs =
let
csc = lookup c o l s p e c c l a s s st (true, convert c o l s p e c cs)
in
if
isVal csc
then let
(tr , lub cl ) = destVal csc
in
CASE tr [
WHEN local identifier name•
Ok (InL(denote col spec [name]));
WHEN column (gen corr , gen col )•
Ok (InL(denote col spec([gen corr ; gen col ])));
WHEN constant class cl • Ok (InR cl );
WHEN constant null (Exception[internalError ])
]
else
giveError (destError csc)
Page 26 of 45
Lemma 1
Ref: DS/FMU/FEF/029
DRA FRONT END FILTER PROJECT
Issue: Revision : 2 .1
Specification of Query Transformations in HOL (II)
Date: 5 June 2016
SML
HOL Constant
denote name : TsqlRepr → Value
∀tr •
denote name tr =
CASE tr [
WHEN local identifier s• contents(denote col spec [s]);
WHEN column(cn,col )• contents(denote col spec [cn;col ]);
WHEN constant class c• denote class c;
WHEN constant null denote null
]
HOL Constant
column data test : TRANS STATE → Col spec → Value LIST RESULT
∀st cs•
column data test st cs =
let
csc = lookup c o l s p e c c l a s s st (true, convert c o l s p e c cs)
in
if
isVal csc
then let
(tr , u) = destVal csc
in
if
client clearance st dom u
then Ok []
else
let cc = denote class(client clearance st)
in
Ok [binop"dom"(cc, denote name tr )]
else
giveError (destError csc)
SML
HOL Constant
col exp : ExpType → ColType RESULT
∀t w •
col exp (t, w ) =
if w = dinary then Ok (c nullType, t)
else if w = sterling then Ok (t, c nullType)
else if w = worthless then Ok (t, c nullType)
else Exception[wrongType]
SML
Page 27 of 45
Lemma 1
Ref: DS/FMU/FEF/029
DRA FRONT END FILTER PROJECT
Issue: Revision : 2 .1
Specification of Query Transformations in HOL (II)
Date: 5 June 2016
HOL Constant
col target : SsqlCol → TsqlCol RESULT
∀ sc•
col target sc =
let
bound bi =
CASE bi [
WHEN upb c• c anon t c ;
WHEN constant c•mk constant t c c
]
in let target ((s, d ), c) =
if
s = c nullType ∧ d = c nullType
then Exception[internalError ]
else if d = c nullType
then Ok (MkTsqlCol c anon t c none t c)
else if s = c nullType
then Ok (MkTsqlCol c none t c anon t c)
else
Ok (MkTsqlCol c anon t c anon t c)
in
target(sc type field sc, bound (sc col class sc))
The following interprets the old-style SSQL table specification as formed from a hierarchical table
directory name followed by a table name followed by a column name.
HOL Constant
converttablespec : Table spec → TableSpecification
∀il •
convert t a b l e s p e c (denote table spec il ) =
let
tab = Hd (Rev il )
in let dir = Tl (Rev il )
in
mk absolute(dir , tab)
HOL Constant
constant valuetype : Value → SwordType
true
HOL Constant
convertssqltype : Type → SwordType
true
Page 28 of 45
Lemma 1
Ref: DS/FMU/FEF/029
DRA FRONT END FILTER PROJECT
Issue: Revision : 2 .1
Specification of Query Transformations in HOL (II)
Date: 5 June 2016
HOL Constant
convert tableSpecification backup
: STRING LIST × N → STRING LIST RESULT
∀d dirs n•
convert tableSpecification backup
= Ok []
∧
convert tableSpecification backup
= Ok (Cons d dirs)
∧
convert tableSpecification backup
= Exception[noSuchDirectory]
∧
convert tableSpecification backup
convert tableSpecification backup
([], 0 )
(Cons d dirs, 0 )
([], n+1 )
(Cons d dirs, n+1 ) =
(dirs, n)
HOL Constant
converttableSpecif cation
: TableSpecification → Table spec RESULT
∀ts•
convert t a b l e S p e c i f c a t i o n ts =
CASE ts [
WHEN absolute(directory,table)•
Ok (denote table spec(directory a [table]));
WHEN default(up,directory,table)•
let
dir = convert tableSpecification backup
(default directory, up)
in
if
isError dir
then giveError (destError dir )
else
Ok (denote table spec(destVal dir a directory a [table]))
]
Page 29 of 45
Lemma 1
Ref: DS/FMU/FEF/029
DRA FRONT END FILTER PROJECT
Issue: Revision : 2 .1
Specification of Query Transformations in HOL (II)
Date: 5 June 2016
HOL Constant
table name
: TableSpecification → STRING
∀ts•
table name ts =
let
in
dot s = s a "."
CASE ts [
WHEN absolute(dir ,tab)•
if
dir = []
then tab
else
Fold ($a) (Map dot dir ) [] a tab;
WHEN default(up,dir ,tab)•
if
dir = []
then Flat(seq up "−") a tab
else
Flat(seq up "−") a Fold ($a) (Map dot dir ) [] a tab
]
HOL Constant
convertswordtype : SwordType → Type
true
HOL Constant
converttype : Type → Type
∀t•
convert t y p e t =
convert s w o r d t y p e (convert s s q l t y p e t)
HOL Constant
denoteclassexp : ExpClass → Value
∀ec•
denote c l a s s e x p ec =
CASE ec [
WHEN variable(v ,c)• v ;
WHEN constant e c c• denote class c
]
Page 30 of 45
Lemma 1
Ref: DS/FMU/FEF/029
DRA FRONT END FILTER PROJECT
Issue: Revision : 2 .1
Specification of Query Transformations in HOL (II)
Date: 5 June 2016
HOL Constant
lubboundinf o : BoundInfo × BoundInfo → BoundInfo
∀bi1 bi2 •
lub b o u n d i n f o (bi1 , bi2 ) =
CASE bi1 [
WHEN upb c1 •
CASE bi2 [
WHEN upb c2 •mk upb(c1 lub c2 );
WHEN constant c2 • mk upb(c1 lub c2 )
];
WHEN constant c1 •
CASE bi2 [
WHEN upb c2 •mk upb(c1 lub c2 );
WHEN constant c2 • if c1 = c2 then bi1 else mk upb(c1 lub c2 )
]
]
HOL Constant
lubexpclass : ExpClass × ExpClass → ExpClass
∀ec1 ec2 •
lub e x p c l a s s (ec1 , ec2 ) =
CASE ec1 [
WHEN variable (v1 , c1 )•
CASE ec2 [
WHEN variable (v2 , c2 )•
mk variable(binop "lub" (v1 , v2 ), c1 lub c2 );
WHEN constant e c c2 •
mk variable(binop "lub" (v1 , denote class c2 ), c1 lub c2 )
];
WHEN constant e c c1 •
CASE ec2 [
WHEN variable (v2 , c2 )•
mk variable(binop "lub" (v2 , denote class c1 ), c1 lub c2 );
WHEN constant e c c2 •
mk constant e c (c1 lub c2 )
]
]
SML
Page 31 of 45
Lemma 1
Ref: DS/FMU/FEF/029
DRA FRONT END FILTER PROJECT
Issue: Revision : 2 .1
Specification of Query Transformations in HOL (II)
Date: 5 June 2016
HOL Constant
lubtype : SwordType × SwordType → SwordType
true
HOL Constant
lubcoltype : ColType × ColType → ColType
∀ s1 d1 s2 d2 •
lub c o l t y p e ((s1 , d1 ), (s2 , d2 )) =
(lub t y p e (s1 ,s2 ),lub t y p e (d1 ,d2 ))
HOL Constant
lubworth : Worth × Worth → Worth
∀ w1 w2 •
lub w o r t h (w1 , w2 ) =
if w1 = w2 then
w1
else if w2 = worthless then w1
else if w1 = worthless then w2
else priceless
HOL Constant
lubexp : ExpType × ExpType → ExpType
∀ t1 w1 t2 w2 •
lub e x p ((t1 , w1 ), (t2 , w2 )) =
(lub t y p e (t1 ,t2 ),lub w o r t h (w1 ,w2 ))
HOL Constant
lubssqlname : SsqlName × SsqlName → SsqlName
∀ sn1 sn2 •
lub s s q l n a m e (sn1 , sn2 ) =
CASE sn1 [
WHEN name s s1 •
CASE sn2 [
WHEN name s s2 • if s1 = s2 then sn1 else c anon s ;
OTHERS c anon s
];
OTHERS c anon s
]
Page 32 of 45
Lemma 1
Ref: DS/FMU/FEF/029
DRA FRONT END FILTER PROJECT
Issue: Revision : 2 .1
Specification of Query Transformations in HOL (II)
Date: 5 June 2016
HOL Constant
lubssqlcol : SsqlCol × SsqlCol → SsqlCol
∀ n1 t1 ce1 cc1 n2 t2 ce2 cc2 •
lub s s q l c o l (MkSsqlCol n1 t1 ce1 cc1 , MkSsqlCol n2 t2 ce2 cc2 ) =
MkSsqlCol
(lub s s q l n a m e (n1 ,n2 )) (lub c o l t y p e (t1 ,t2 ))
(ce1 lub ce2 ) (lub b o u n d i n f o (cc1 ,cc2 ))
HOL Constant
lubtableinf o : TableInfo × TableInfo → TableInfo
∀ tec1 tc1 rc1 tec2 tc2 rc2 •
lub t a b l e i n f o (MkTableInfo tec1 tc1 rc1 , MkTableInfo tec2 tc2 rc2 ) =
MkTableInfo
(tec1 lub tec2 ) (tc1 lub tc2 ) (lub b o u n d i n f o (rc1 ,rc2 ))
HOL Constant
lubtsqlclassname : TsqlClassName × TsqlClassName → TsqlClassName
∀ tcn1 tcn2 •
lub t s q l c l a s s n a m e (tcn1 , tcn2 ) =
CASE tcn1 [
WHEN name t c s1 •
CASE tcn2 [
WHEN name t c s2 • if s1 = s2 then tcn1 else c anon t c ;
OTHERS c anon t c
];
OTHERS c anon t c
]
Page 33 of 45
Lemma 1
Ref: DS/FMU/FEF/029
DRA FRONT END FILTER PROJECT
Issue: Revision : 2 .1
Specification of Query Transformations in HOL (II)
Date: 5 June 2016
HOL Constant
lubtsqlname : TsqlName × TsqlName → TsqlName
∀ tn1 tn2 •
lub t s q l n a m e (tn1 , tn2 ) =
CASE tn1 [
WHEN name t s1 •
CASE tn2 [
WHEN name t s2 • if s1 = s2 then tn1 else c anon t ;
OTHERS c anon t
];
WHEN none t
(CASE tn2 [
WHEN none t c none t ;
OTHERS c anon t
]);
OTHERS c anon t
]
HOL Constant
lubtsqlcol : TsqlCol × TsqlCol → TsqlCol
∀ s1 d1 c1 s2 d2 c2 •
lub t s q l c o l (MkTsqlCol s1 d1 c1 , MkTsqlCol s2 d2 c2 ) =
MkTsqlCol
(lub t s q l n a m e (s1 , s2 ))
(lub t s q l n a m e (d1 , d2 ))
(lub t s q l c l a s s n a m e (c1 , c2 ))
The new Select value category corresponds (at least in its anonynomous option with the old Value,
which appears as the operand to select value).
Page 34 of 45
Lemma 1
Ref: DS/FMU/FEF/029
DRA FRONT END FILTER PROJECT
Issue: Revision : 2 .1
Specification of Query Transformations in HOL (II)
Date: 5 June 2016
HOL Constant
makesv : TsqlCol × TsqlCol → Value LIST RESULT
∀f t• make s v (f , t) =
let
data col (ftn, ttn) = CASE ftn [
WHEN none t
(CASE ttn [
WHEN none t (Ok []);
WHEN anon t (Ok [denote null ]);
WHEN name t ts• Exception[internalError ]]);
WHEN anon t
(CASE ttn [
WHEN none t (Ok [denote null ]);
OTHERS (Exception[internalError ])]);
WHEN name t fs•
(CASE ttn [
WHEN anon t (Ok [contents(denote col spec [fs])]);
WHEN name t ts• Ok [contents(denote col spec [fs])];
WHEN none t (Exception[internalError ])])]
in let class col (fcn, tcn) = CASE fcn [
WHEN constant t c fc•
CASE tcn [
WHEN constant t c tc•
if fc = tc
then Ok []
else Exception[internalError ];
WHEN name t c tn• Ok [denote class fc];
WHEN anon t c (Exception[internalError ])];
WHEN name t c f •
CASE tcn [
WHEN constant t c tc•Exception[internalError ];
WHEN name t c tn• Ok [contents(denote col spec [f ])];
WHEN anon t c (Ok [contents(denote col spec [f ])])];
WHEN anon t c (Exception[internalError ])]
in let ssv = data col (tc sterling name f , tc sterling name t)
in let dsv = data col (tc dinary name f , tc dinary name t)
in let csv = class col (tc class name f , tc class name t)
in
if
isError ssv ∨ isError dsv ∨ isError csv
then Exception[internalError ]
else
Ok (destVal ssv a destVal dsv a destVal csv )
Page 35 of 45
Lemma 1
Ref: DS/FMU/FEF/029
DRA FRONT END FILTER PROJECT
Issue: Revision : 2 .1
Specification of Query Transformations in HOL (II)
Date: 5 June 2016
HOL Constant
remove constants : (Col spec + Class) LIST → Col spec LIST
∀x s•
∧
remove constants [] = []
remove constants (Cons x s) =
if IsL x
then Cons (OutL x ) (remove constants s)
else remove constants s
HOL Constant
remove nulls : TsqlRepr LIST → TsqlRepr LIST
∀x trs•
∧
remove nulls [] = []
remove nulls (Cons x trs) =
CASE x [
WHEN constant null (remove nulls trs);
OTHERS (Cons x (remove nulls trs))]
HOL Constant
upper : ExpClass → Class
∀ec•
upper ec =
CASE ec [
WHEN variable (c, u)• u;
WHEN constant e c u• u]
HOL Constant
make case : Value × ExpClass → Value
∀data ec•
make case (data, ec) =
CASE ec [
WHEN variable (c, u)• case [data] [denote class(lattice top)] c;
WHEN constant e c c• case [data] [denote class(lattice top)] (denote class c)]
Page 36 of 45
Lemma 1
Ref: DS/FMU/FEF/029
DRA FRONT END FILTER PROJECT
Issue: Revision : 2 .1
Specification of Query Transformations in HOL (II)
Date: 5 June 2016
HOL Constant
simplifyands : Value LIST × ExpClass LIST → Value × ExpClass
∀vs cs•
simplify a n d s (vs, cs) =
let
v = fold (binop And ) vs
in let c = case [v ]
[fold (binop "lub")(Map denote c l a s s e x p cs)]
(fold (binop "glb")(at2 (Map make case) (vs,cs)))
in let u = fold (Uncurry $lub) (Map upper cs)
in
(v , mk variable(c, u))
HOL Constant
simplifyors : Value LIST × ExpClass LIST → Value × ExpClass
∀vs cs•
simplify o r s (vs, cs) =
let
v = fold (binop Or ) vs
in let c = case [v ]
[fold (binop "glb")(Map denote c l a s s e x p cs)]
(fold (binop "lub")(at2 (Map make case) (vs,cs)))
in let u = fold (Uncurry $lub) (Map upper cs)
in
(v , mk variable(c, u))
HOL Constant
constant valuedata : Value → Value
true
HOL Constant
dinary columns : TRANS STATE → Col spec LIST → Col spec LIST RESULT
∀st css•
dinary columns st css =
let
look cs = lookup c o l s p e c d i n a r y st (false,convert c o l s p e c cs)
in
Try
(ListOk o Map repr col o remove nulls)
(ListOk (Map look css))
Page 37 of 45
Lemma 1
Ref: DS/FMU/FEF/029
DRA FRONT END FILTER PROJECT
Issue: Revision : 2 .1
Specification of Query Transformations in HOL (II)
Date: 5 June 2016
HOL Constant
sterling columns : TRANS STATE → Col spec LIST → Col spec LIST RESULT
∀st css•
sterling columns st css =
let
look cs = lookup c o l s p e c s t e r l i n g st (false,convert c o l s p e c cs)
in
Try
(ListOk o Map repr col o remove nulls)
(ListOk (Map look css))
HOL Constant
tuple listmaxrowclass : TRANS STATE → Tuple list → ExpClass
∀st t• tuple list m a x r o w c l a s s st t =
mk constant e c (client clearance st)
HOL Constant
upb row class : TableInfo → Class
∀tec tc rowc•
upb row class (MkTableInfo tec tc rowc) =
CASE rowc [
WHEN upb rc• rc;
WHEN constant rc• rc]
In the following, the specifications of internal value c l a s s and value type are incomplete. (all binop,
some binop, all binop list and some binop list are missing from internal value c l a s s and caseVal is
missing from value type.)
HOL Constant
valuedata : TRANS STATE → Value → Value
true
HOL Constant
valuetype : TRANS STATE → Value → ExpType
true
We now have to start breaking up the mutually recursive functions of [6]. We do this by passing the
functions to be recalled recursively as parameters. For example:
Page 38 of 45
Lemma 1
Ref: DS/FMU/FEF/029
DRA FRONT END FILTER PROJECT
Issue: Revision : 2 .1
Specification of Query Transformations in HOL (II)
Date: 5 June 2016
HOL Constant
valueclass
: (TRANS STATE → Value → InternalExpClass RESULT )
→ TRANS STATE → Value → ExpClass RESULT
∀st ivc v •
value c l a s s ivc st v =
let
x = ivc st v
in
if isError x
then giveError (destError x )
else
Ok (CASE (destVal x ) [
WHEN ands(datas, classes)•
let
(v , c) = simplify a n d s (datas,classes)
in
c;
WHEN ors(datas,classes)•
let
(v , c) = simplify o r s (datas,classes)
in c;
WHEN simple ec•
CASE ec [
WHEN variable(exp,up)• mk variable(exp,up);
WHEN constant e c c• mk constant e c c]
])
HOL Constant
tuple listdata :TRANS STATE → Tuple list → Tuple list RESULT
true
HOL Constant
tuple listtype : TRANS STATE → Tuple list → Tuple list RESULT
true
HOL Constant
from specenter : TRANS STATE → From spec → From spec RESULT
true
HOL Constant
select listtype : TRANS STATE → Select list → ExpType RESULT
true
Page 39 of 45
Lemma 1
Ref: DS/FMU/FEF/029
DRA FRONT END FILTER PROJECT
Issue: Revision : 2 .1
Specification of Query Transformations in HOL (II)
Date: 5 June 2016
HOL Constant
select valuetype : TRANS STATE → Value → ExpType RESULT
true
HOL Constant
tuple listinf o : TRANS STATE → Tuple list
→ (TableName × TableInfo × SsqlCol LIST ) RESULT
true
HOL Constant
tuple listmake
: TRANS STATE → Tuple list × TsqlClassName × TsqlCol LIST
→ Tuple list RESULT
true
HOL Constant
from specinf o
: TRANS STATE → From spec
→ (TableInfo × SsqlCol LIST × TsqlClassName × TsqlCol LIST ) RESULT
true
HOL Constant
select listinf o
: TRANS STATE → Select list → SsqlCol LIST RESULT
true
HOL Constant
select valueinf o
: TRANS STATE → Value → SsqlCol RESULT
true
HOL Constant
valueinf o
: TRANS STATE → Value → SsqlCol RESULT
true
Page 40 of 45
Lemma 1
Ref: DS/FMU/FEF/029
DRA FRONT END FILTER PROJECT
Issue: Revision : 2 .1
Specification of Query Transformations in HOL (II)
Date: 5 June 2016
HOL Constant
internal valueclass : TRANS STATE → Value → InternalExpClass RESULT
true
HOL Constant
tuple listclass : TRANS STATE → Tuple list → Tuple list
true
HOL Constant
select listclass : TRANS STATE → Select list → Select list RESULT
true
HOL Constant
select valueclass : TRANS STATE → Value → Value RESULT
true
HOL Constant
select listmake
: TRANS STATE → (Select list × TsqlClassName × TsqlCol LIST )
→ Value LIST RESULT
true
HOL Constant
select valuemake
: TRANS STATE → (Value × TsqlCol LIST ) → Value LIST RESULT
true
HOL Constant
make col : TRANS STATE → (Value × TsqlCol ) → Value LIST RESULT
true
HOL Constant
makedinary : TRANS STATE → (Value × ExpType) → Value RESULT
true
Page 41 of 45
Lemma 1
Ref: DS/FMU/FEF/029
DRA FRONT END FILTER PROJECT
Issue: Revision : 2 .1
Specification of Query Transformations in HOL (II)
Date: 5 June 2016
HOL Constant
makesterling : TRANS STATE → (Value × ExpType) → Value RESULT
true
HOL Constant
select listdata : TRANS STATE → Select list → Select list RESULT
true
HOL Constant
select valuedata : TRANS STATE → Value → Value RESULT
true
HOL Constant
tuple listmakeouter
: TRANS STATE → (Tuple list × BOOL × TsqlClassName × TsqlCol LIST )
→ (Tuple list × Query LIST ) RESULT
true
That is the last of the mutually recursive functions.
HOL Constant
tuple listouterinf o
: TRANS STATE → Tuple list → BOOL RESULT
true
HOL Constant
transformselectquery
: TRANS STATE → Query →
(SsqlCol LIST × Query × BOOL × TsqlClassName × TsqlCol LIST × Query LIST )
RESULT
true
HOL Constant
queryselectquery
: TRANS STATE → Query → Query RESULT
true
Page 42 of 45
Lemma 1
3
Ref: DS/FMU/FEF/029
DRA FRONT END FILTER PROJECT
Issue: Revision : 2 .1
Specification of Query Transformations in HOL (II)
Date: 5 June 2016
INTERFACE
We now wish to define the SSQL Transformation Processor as required by [7]. It is parameterised
by the as yet undefined processing of the various updating queries.
The local function dynamic below computes the list of boolean flags needed by the output filter of
[7] from the list of TsqlCol s produced by transform s e l e c t q u e r y .
Since the processing of updating queries is as yet unspecified, we treat it as an error if the select
query processing fails (e.g, because the query is not a select query).
SML
HOL Constant
STP : (Query, FILTER PARS ) STP TYPE
∀q c• STP (q, c) =
let
st = init trans state c
in let res = transform s e l e c t q u e r y st q
in
if
isError res
then giveError (destError res)
else
Ok
let
(scs, tq, scw , rc, tcs, chks) = destVal res
in let dynamic tc =
CASE tc [WHEN constant t c c• false; OTHERS true]
in let cc = Map (dynamic o tc class name) tcs
in let cr = if dynamic rc then InL c else InR One
in let cq = if chks = [] then InR One else InL(Hd chks)
in
(tq, cq, (scw , cr , cc))
Page 43 of 45
Lemma 1
4
Ref: DS/FMU/FEF/029
DRA FRONT END FILTER PROJECT
Issue: Revision : 2 .1
Specification of Query Transformations in HOL (II)
Date: 5 June 2016
INDEX
all data columns l o c a l . . . . . . . . . . . . . . . . . . . . . . . . 25
ambiguousName . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
binop type . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
check boolean . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
check enum . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
check fixed . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
check floating . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
check interval . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
check time . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
check type conversion . . . . . . . . . . . . . . . . . . . . . . . . 26
class column . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
column data test . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
col exp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
col target . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
constant value d a t a . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
constant value t y p e . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
contextual data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
convert tableSpecification backup . . . . . . . . . . . . . . 29
convert c o l s p e c . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
convert s s q l t y p e . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
convert s w o r d t y p e . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
convert t a b l e S p e c i f c a t i o n . . . . . . . . . . . . . . . . . . . . . 29
convert t a b l e s p e c . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
convert t y p e . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
default directory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
denote name . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
denote c l a s s e x p . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
dinary columns . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
emptyUnionList . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
enter scope . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
enter c o r r t a b l e . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
enter i d e n t i f e r c o n s t a n t c l a s s . . . . . . . . . . . . . . . . . . 21
enter i d e n t i f i e r . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
enter p a r a m e t e r . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
enter t a b l e . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
extract p a r a m e t e r . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
fef029 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
find c o l u m n . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
find i d e n t . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
from spec e n t e r . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
from spec i n f o . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
get t a b l e i n f o . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
innermost . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
internalError . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
internal value c l a s s . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
in new scope . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
lookup column info look . . . . . . . . . . . . . . . . . . . . . . . 7
lookup column row class look . . . . . . . . . . . . . . . . . 16
lookup col spec class look . . . . . . . . . . . . . . . . . . . . . 9
lookup col spec dinary look . . . . . . . . . . . . . . . . . . . 11
lookup col spec sterling look . . . . . . . . . . . . . . . . . . 12
lookup table detail look . . . . . . . . . . . . . . . . . . . . . . 18
lookup table row class look . . . . . . . . . . . . . . . . . . . 17
lookup c o l s p e c c l a s s . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
lookup c o l s p e c d i n a r y . . . . . . . . . . . . . . . . . . . . . . . . . 11
lookup c o l s p e c s t e r l i n g . . . . . . . . . . . . . . . . . . . . . . . . 12
lookup c o l u m n i n f o . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
lookup c o l u m n r o w c l a s s . . . . . . . . . . . . . . . . . . . . . . . . 16
lookup l o c a l c o l i m p l e m e n t a t i o n . . . . . . . . . . . . . . . . . 13
lookup l o c a l c o l i n f o . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
lookup l o c a l c o l s p e c c l a s s e s . . . . . . . . . . . . . . . . . . . . . 14
lookup l o c a l c o l s p e c s t e r l i n g s . . . . . . . . . . . . . . . . . . . 15
lookup l o c a l r o w c l a s s e s . . . . . . . . . . . . . . . . . . . . . . . . 15
lookup l o c a l t a b l e i n f o . . . . . . . . . . . . . . . . . . . . . . . . . 24
lookup p a r a m d a t a . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
lookup t a b l e d e t a i l . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
lookup t a b l e r o w c l a s s . . . . . . . . . . . . . . . . . . . . . . . . . . 17
lub b o u n d i n f o . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
lub c o l t y p e . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
lub e x p c l a s s . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
lub e x p . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
lub s s q l c o l . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
lub s s q l n a m e . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
lub t a b l e i n f o . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
lub t s q l c l a s s n a m e . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
lub t s q l c o l . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
lub t s q l n a m e . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
lub t y p e . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
lub w o r t h . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
make case . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
make col . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
make d i n a r y . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
make s t e r l i n g . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
make s v . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
maxBound . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
monop type . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
noScope . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
noSuchParameter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
notDyadic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
notMonadic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
notSetFunction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
notTriadic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
notTrigger . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
onlyInTriggers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
query s e l e c t q u e r y . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
remove constants . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
remove nulls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
repr col . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
select list c l a s s . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
select list d a t a . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
select list i n f o . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
select list m a k e . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
Page 44 of 45
Lemma 1
Ref: DS/FMU/FEF/029
DRA FRONT END FILTER PROJECT
Issue: Revision : 2 .1
Specification of Query Transformations in HOL (II)
Date: 5 June 2016
select list t y p e . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
select value c l a s s . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
select value d a t a . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
select value i n f o . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
select value m a k e . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
select value t y p e . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
set func type . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
simplify a n d s . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
simplify o r s . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
sterling columns . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
STP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
table name . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
timeFormatToInterval . . . . . . . . . . . . . . . . . . . . . . . . . 5
transform s e l e c t q u e r y . . . . . . . . . . . . . . . . . . . . . . . . . 42
TRANS STATE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
triop type . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
tuple list c l a s s . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
tuple list d a t a . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
tuple list i n f o . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
tuple list m a k e o u t e r . . . . . . . . . . . . . . . . . . . . . . . . . . 42
tuple list m a k e . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
tuple list m a x r o w c l a s s . . . . . . . . . . . . . . . . . . . . . . . . 38
tuple list o u t e r i n f o . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
tuple list t y p e . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
unique name . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
upb row class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
update top scope . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
upper . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
value c l a s s . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
value d a t a . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
value i n f o . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
value t y p e . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
wrongScope . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
wrongWorth . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
Page 45 of 45
© Copyright 2026 Paperzz