Skip to content

Latest commit

 

History

History
57 lines (39 loc) · 1.99 KB

Specification.md

File metadata and controls

57 lines (39 loc) · 1.99 KB

Here is the specification of the operators in the form of Racket code:

#lang racket
;; Some framework code to wrap racket contracts into nicer API
(require racket/contract)   
(struct Relation ())
(struct Expression ())

(define-syntax-rule (define-operator (Operator-Name args ...) c) (define/contract (Operator-Name args ...) c (Relation)))
(define-syntax-rule (define-statement (Operator-Name args ...) c) (define/contract (Operator-Name args ...) c (void)))
(define-syntax-rule (define-expression (Operator-Name args ...) c) (define/contract (Operator-Name args ...) c (Expression)))


;;; DDL

(define-statement (CreateTable identifier attributeNames ...)
  (symbol? symbol? ... . -> . void?))

  
;;; Operator Definitions

(define-operator (Select input predicate)
  (Relation? Expression? . -> . Relation?))
(define-operator (Join left-input right-input predicate)
  (Relation? Relation? Expression? . -> . Relation?))
(define-operator (Group input groupExpression aggregateExpressions ...)
  (Relation? Expression? Expression? ... . -> . Relation?))
(define-operator (Project input projection)
  (Relation? Expression? . -> . Relation?))
(define-operator (Order input orderPredicate)
  (Relation? Expression? . -> . Relation?))
(define-operator (Top input orderPredicate number)
  (Relation? Expression? integer? . -> . Relation?))

  
(define-expression (Where predicate) (any/c . -> . Expression?))

(define-expression (Greater left right) ((or/c integer? symbol?) (or/c integer? symbol?) . -> . Expression?))
(define-expression (Plus operands ...) (integer? ... . -> . integer?))

;;; Insertion

(define ImputedValue? (or/c (=/c '(Mean)) (=/c '(HotDeck)) (=/c '(DecisionTree)))) ;; Defining Currently Supported Imputation

(define-operator (InsertInto relation values ...)
  (Relation? (or integer? string? ImputedValue?) ... . -> . void?))
  
;;; Some Examples

(CreateTable 'LINEITEM 'price 'name)

(InsertInto 'LINEITEM 50 "apple")
(InsertInto 'LINEITEM '(Mean) "pear")

(Select 'LINEITEM (Where (> 'price 9)))