Tabular

scalation.database.Tabular
See theTabular companion object
trait Tabular[T <: Tabular[T]](val name: String, val schema: Schema, val domain: Domain, val key: Schema) extends Serializable

The Tabular trait defines relational algebra operators. Supported domains/data-types are 'D'ouble, 'I'nt, 'L'ong, 'S'tring, and 'T'imeNum. 'D' - Double - VectorD - 64 bit double precision floating point number 'I' - Int - VectorI - 32 bit integer 'L' - Long - VectorL - 64 bit long integer 'S' - String - VectorS - variable length numeric string 'X' - String - VectorS - variable length numeric string (for 2x column width) 'T' - TimeNum - VectorT - time numbers for date-time Note: Uses F-Bounded Polymorphism so extending classes don't need to cast

Value parameters

domain

the domains/data-types for the attributes ('D', 'I', 'L', 'S', 'X', 'T')

key

the attributes forming the primary key

name

the name of the table

schema

the attributes for the table

Attributes

Companion
object
Graph
Supertypes
trait Serializable
class Object
trait Matchable
class Any
Known subtypes
class Relation
class Table
class GTable
class KGTable
class LTable
class VTable
Show all

Members list

Value members

Abstract methods

def add(t: Tuple): T

ADD (insert) tuple t into this table checking to make sure the domains are correct. Also, checks referential integrity for any foreign keys in the tuple. Return true iff the tuple passes the type check and reference check.

ADD (insert) tuple t into this table checking to make sure the domains are correct. Also, checks referential integrity for any foreign keys in the tuple. Return true iff the tuple passes the type check and reference check.

Value parameters

t

the tuple to be inserted

Attributes

def addLinkage(fkey: String, refTab: T): Unit

Add LINKAGE from this table to the refTab, by adding a FOREIGN KEY CONSTRAINT to this table specifying the foreign key attribute fkey and the table it references refTab. Caveat: a foreign key may not be composite.

Add LINKAGE from this table to the refTab, by adding a FOREIGN KEY CONSTRAINT to this table specifying the foreign key attribute fkey and the table it references refTab. Caveat: a foreign key may not be composite.

Value parameters

fkey

the foreign key attribute

refTab

the table being referenced (to its primary key)

Attributes

def aggregate(ag: String, f_as: (AggFunction, String)*): T

Assuming this table has been grouped by attribute ag, create a table where the first column is ag and the rest are AGGREGATE FUNCTIONs applied to their corresponding attributes.

Assuming this table has been grouped by attribute ag, create a table where the first column is ag and the rest are AGGREGATE FUNCTIONs applied to their corresponding attributes.

Value parameters

ag

the attribute the table has been grouped on

f_as

the aggregate function and the attribute to apply it to (as varargs)

Attributes

def apply(rng: Range): T

Return the table restricted to the given range of rows.

Return the table restricted to the given range of rows.

Value parameters

rng

the given range of rows

Attributes

def apply(pos: IndexedSeq[Int]): T

Return the table restricted to the given collection of rows.

Return the table restricted to the given collection of rows.

Value parameters

pos

the given collection of rows

Attributes

def contains(u: Tuple): Boolean

Return whether this table contains tuple u.

Return whether this table contains tuple u.

Value parameters

u

the tuple to look for

Attributes

def create_index(rebuild: Boolean): Unit

CREATE/recreate the primary INDEX that maps the primary key to the tuple containing it. Warning, creating an index will remove DUPLICATES based on maintaining UNIQUENESS CONSTRAINT of primary key values.

CREATE/recreate the primary INDEX that maps the primary key to the tuple containing it. Warning, creating an index will remove DUPLICATES based on maintaining UNIQUENESS CONSTRAINT of primary key values.

Value parameters

rebuild

if rebuild is true, use old index to build new index; otherwise, create new index

Attributes

def delete(predicate: Predicate): Boolean

DELETE all tuples in this table satisfying the deletion predicate. If there is an index, remove those tuples from the index as well. Return true iff at least one tuple is deleted.

DELETE all tuples in this table satisfying the deletion predicate. If there is an index, remove those tuples from the index as well. Return true iff at least one tuple is deleted.

Value parameters

predicate

the predicate that specifies which tuples to delete

Attributes

def divide(r2: T): T

DIVIDE this table by table r2. Requires a tuple in the quotient part of this table to be paired with all tuples in table r2.

DIVIDE this table by table r2. Requires a tuple in the quotient part of this table to be paired with all tuples in table r2.

Value parameters

r2

the second table

Attributes

def drop_index(): Unit

DROP the primary INDEX that maps the primary key to the tuple containing it.

DROP the primary INDEX that maps the primary key to the tuple containing it.

Attributes

def getPkey(i: Int): KeyType

Return the i-th primary key.

Return the i-th primary key.

Value parameters

i

the index in the tuples/row index

Attributes

def groupBy(ag: String): T

GROUP this table BY the specified attribute, returning this table. Each value for attribute ag will be mapped to a collection of tuples.

GROUP this table BY the specified attribute, returning this table. Each value for attribute ag will be mapped to a collection of tuples.

Value parameters

ag

the attribute to group by

Attributes

infix def intersect(r2: T): T

INTERSECT this table and r2. Check that the two tables are compatible. If they are not, return the first table.

INTERSECT this table and r2. Check that the two tables are compatible. If they are not, return the first table.

Value parameters

r2

the second table

Attributes

def join(predicate: Predicate2, r2: T): T

JOIN this table and r2 keeping concatenated tuples that satisfy the predicate. Caveat: Assumes both keys are needed for the new key (depending on the predicate both may not be required).

JOIN this table and r2 keeping concatenated tuples that satisfy the predicate. Caveat: Assumes both keys are needed for the new key (depending on the predicate both may not be required).

Value parameters

predicate

the join predicate to be satisfied

r2

the second table

Attributes

def join(condition: String, r2: T): T

Compute the THETA-JOIN of this table and r2 keeping concatenated tuples that satisfy the given simple (3 token) condition.

Compute the THETA-JOIN of this table and r2 keeping concatenated tuples that satisfy the given simple (3 token) condition.

Value parameters

condition

the simple condition "a1 op a2"

r2

the second table

Attributes

def join(x: Schema, y: Schema, r2: T): T

Compute the EQUI-JOIN of this table and r2 keeping concatenated tuples that are equal on specified attributes.

Compute the EQUI-JOIN of this table and r2 keeping concatenated tuples that are equal on specified attributes.

Value parameters

r2

the second table

x

the subschema/attributes for the first/this table

y

the subschema/attributes for the second table

Attributes

def join(ref: (String, T)): T

Compute the EQUI-JOIN via the INDEX of this table and the referenced table keeping concatenated tuples that are equal on the primary key and foreign key attributes. Caveat: Requires the foreign key table to be first [ fkey_table join ((fkey, pkey_table) ]. Usage: deposit join (("cname", customer))

Compute the EQUI-JOIN via the INDEX of this table and the referenced table keeping concatenated tuples that are equal on the primary key and foreign key attributes. Caveat: Requires the foreign key table to be first [ fkey_table join ((fkey, pkey_table) ]. Usage: deposit join (("cname", customer))

Value parameters

ref

the foreign key reference (foreign key attribute, referenced table)

Attributes

infix def join(r2: T): T

Compute the NATURAL JOIN of this table and r2 keeping concatenated tuples that agree on the common attributes.

Compute the NATURAL JOIN of this table and r2 keeping concatenated tuples that agree on the common attributes.

Value parameters

r2

the second table

Attributes

def leftJoin(x: Schema, y: Schema, r2: T): T

Compute the LEFT-EQUI-JOIN of this table and r2 keeping concatenated tuples that are equal on specified attributes. Also, keep all tuples in the left table padding the missing attributes with null.

Compute the LEFT-EQUI-JOIN of this table and r2 keeping concatenated tuples that are equal on specified attributes. Also, keep all tuples in the left table padding the missing attributes with null.

Value parameters

r2

the second table

x

the subschema/attributes for the left/first/this table

y

the subschema/attributes for the right/second table

Attributes

infix def minus(r2: T): T

Compute this table MINUS (set difference) table r2 (this - r2). Check that the two tables are compatible. If they are not, return the first table.

Compute this table MINUS (set difference) table r2 (this - r2). Check that the two tables are compatible. If they are not, return the first table.

Value parameters

r2

the second table

Attributes

def orderBy(x: String*): T

ORDER-BY the given attributes, i.e., reorder the tuples in this table into 'ascending' order. A stable sorting is used to allow sorting on multiple attributes.

ORDER-BY the given attributes, i.e., reorder the tuples in this table into 'ascending' order. A stable sorting is used to allow sorting on multiple attributes.

Value parameters

x

the subschema/attributes to order by

Attributes

def orderByDesc(x: String*): T

ORDER-BY-DESC the given attributes, i.e., reorder the tuples in this table into 'descending' order. A stable sorting is used to allow sorting on multiple attributes.

ORDER-BY-DESC the given attributes, i.e., reorder the tuples in this table into 'descending' order. A stable sorting is used to allow sorting on multiple attributes.

Value parameters

x

the subschema/attributes to order by

Attributes

infix def product(r2: T): T

Compute the CARTESIAN PRODUCT of this table and r2 (this × r2).

Compute the CARTESIAN PRODUCT of this table and r2 (this × r2).

Value parameters

r2

the second table

Attributes

def project(x: Schema): T

PROJECT the tuples in this table onto the given attribute names.

PROJECT the tuples in this table onto the given attribute names.

Value parameters

x

the schema/attribute names to project onto

Attributes

def project(cPos: IndexedSeq[Int]): T

PROJECT onto the columns with the given column positions.

PROJECT onto the columns with the given column positions.

Value parameters

cPos

the column positions to project onto

Attributes

def referenceCheck(t: Tuple): Boolean

Check that all the foreign keys values in tuple t satisfy their REFERENTIAL INTEGRITY CONSTRAINTS.

Check that all the foreign keys values in tuple t satisfy their REFERENTIAL INTEGRITY CONSTRAINTS.

Value parameters

t

the tuple being checked for referential integrity

Attributes

def rename(newName: String): T

RENAME this table, returning a shallow copy of this table.

RENAME this table, returning a shallow copy of this table.

Value parameters

newName

the new name for the table.

Attributes

def rows: Int

Return the size in terms of number of rows in the table.

Return the size in terms of number of rows in the table.

Attributes

def save(): Unit

SAVE this table in a file using serialization.

SAVE this table in a file using serialization.

Attributes

See also

load in Tabular object

def select(a: String, apred: APredicate): T

SELECT the tuples in this table that satisfy the atomic predicate on column a.

SELECT the tuples in this table that satisfy the atomic predicate on column a.

Value parameters

a

the attribute name of the column used for selection

apred

the atomic predicate (Boolean function) to be satisfied

Attributes

def select(predicate: Predicate): T

SELECT the tuples in this table that satisfy the predicate.

SELECT the tuples in this table that satisfy the predicate.

Value parameters

predicate

the predicate (Boolean function) to be satisfied

Attributes

def select(condition: String): T

SELECT the tuples in this table that satisfy the given simple (3 token) condition.

SELECT the tuples in this table that satisfy the given simple (3 token) condition.

Value parameters

condition

the simple condition string "a1 op a2" to be satisfied, where a1 is attribute, op is comparison operator, a2 is attribute or value

Attributes

def select(pkey: KeyType): T

SELECT via the INDEX the tuple with the given primary key value pkey. Returns an empty table if the primary index has not been created.

SELECT via the INDEX the tuple with the given primary key value pkey. Returns an empty table if the primary index has not been created.

Value parameters

pkey

the primary key value

Attributes

def selproject(a: String, apred: APredicate): T

SELECT elements from column a in this table that satisfy the atomic predicate apred and project onto that column.

SELECT elements from column a in this table that satisfy the atomic predicate apred and project onto that column.

Value parameters

a

the attribute name of the column used for selection

apred

the atomic predicate (Boolean function) to be satisfied

Attributes

def show(rng: Range): Unit

SHOW/print this table, one tuple per row.

SHOW/print this table, one tuple per row.

Value parameters

rng

the range of tuples to show, defaults to 0 until 1

Attributes

def show_foreign_keys(): Unit

SHOW/print this table's foreign keys.

SHOW/print this table's foreign keys.

Attributes

def show_index(): Unit

SHOW/print this table's primary index.

SHOW/print this table's primary index.

Attributes

def stats: T

Return the basic statistics for each column of this table.

Return the basic statistics for each column of this table.

Attributes

def toMatrix(cols: Array[Int]): MatrixD

Convert this table to a matrix of doubles by making the necessary type transformations.

Convert this table to a matrix of doubles by making the necessary type transformations.

Value parameters

cols

the column positions to use for forming the matrix

Attributes

def toMatrixV(cols: Array[Int], colj: Int): (MatrixD, VectorD)

Convert this table to a matrix and a vector of doubles by making the necessary type transformations. Usage: table -> (X, y) in linear algebra/regression problem Xb = y.

Convert this table to a matrix and a vector of doubles by making the necessary type transformations. Usage: table -> (X, y) in linear algebra/regression problem Xb = y.

Value parameters

colj

the column position to use for forming the vector

cols

the column positions to use for forming the matrix

Attributes

def toVectorD(colj: Int): VectorD

Convert the colj column of this relation into a vector of doubles, etc.

Convert the colj column of this relation into a vector of doubles, etc.

Value parameters

colj

the column position to use for the vector

Attributes

def toVectorI(colj: Int): VectorI
def toVectorL(colj: Int): VectorL
def toVectorS(colj: Int): VectorS
def toVectorT(colj: Int): VectorT
infix def union(r2: T): T

UNION this table and r2. Check that the two tables are compatible. If they are not, return the first table. Caveat: Assumes the key from the first table still works (@see create_index) Acts like union-all, so to remove duplicates call create_index after union.

UNION this table and r2. Check that the two tables are compatible. If they are not, return the first table. Caveat: Assumes the key from the first table still works (@see create_index) Acts like union-all, so to remove duplicates call create_index after union.

Value parameters

r2

the second table

Attributes

def update(a: String, newVal: ValueType, matchVal: ValueType): Boolean

UPDATE the column with attribute name a using newVal for elements with value matchVal. Return true iff at least one tuple is updated.

UPDATE the column with attribute name a using newVal for elements with value matchVal. Return true iff at least one tuple is updated.

Value parameters

a

the attribute name for the column to be updated

matchVal

the value to be matched to elements

newVal

the value used to assign updated values

Attributes

def update(a: String, func: ValueType => ValueType, matchVal: ValueType): Boolean

UPDATE the column with attribute name a using function func for elements with value matchVal. Return true iff at least one tuple is updated.

UPDATE the column with attribute name a using function func for elements with value matchVal. Return true iff at least one tuple is updated.

Value parameters

a

the attribute name for the column to be updated

func

the function used to assign updated values

matchVal

the value to be matched to elements

Attributes

def writeCSV(fileName: String): Unit

Write this table into a Comma-Separated-Value (CSV) file with each tuple written to a line.

Write this table into a Comma-Separated-Value (CSV) file with each tuple written to a line.

Value parameters

fileName

the file name of the data file

Attributes

def writeJSON(fileName: String): Unit

Write this table into a JavaScript Object Notation (JSON) file.

Write this table into a JavaScript Object Notation (JSON) file.

Value parameters

fileName

the file name of the data file

Attributes

Concrete methods

def +=(v: ValueType*): T
inline def -(r2: T): T
inline def /(r2: T): T
def add(v: ValueType*): T
def colIndices: Range

Return the range of columns numbers for the table.

Return the range of columns numbers for the table.

Attributes

def cols: Int

Return the size in terms of number of columns in the table.

Return the size in terms of number of columns in the table.

Attributes

inline def dims: (Int, Int)

Return the cardinality (number of tuples) and arity (number of attributes).

Return the cardinality (number of tuples) and arity (number of attributes).

Attributes

def incompatible(r2: T): Boolean

Determine whether this table and r2 are incompatible by having differing domains.

Determine whether this table and r2 are incompatible by having differing domains.

Value parameters

r2

the second table

Attributes

def indices: Range

Return the range of row numbers for the table.

Return the range of row numbers for the table.

Attributes

inline def join(x: String, y: String, r2: T): T
infix def leftJoin(r2: T): T

Compute the LEFT-JOIN of this table and r2 keeping concatenated tuples that are equal on specified attributes. Also, keep all tuples in the left table padding the missing attributes with null.

Compute the LEFT-JOIN of this table and r2 keeping concatenated tuples that are equal on specified attributes. Also, keep all tuples in the left table padding the missing attributes with null.

Value parameters

r2

the second table

Attributes

def nullTuple(domain: Domain): Tuple

Create a tuple with missing values for each column according to the given domains. This method is used by leftJoin.

Create a tuple with missing values for each column according to the given domains. This method is used by leftJoin.

Value parameters

domain

the domains of the table for which a null tuple is required

Attributes

inline def project(x: String): T
def pull(t: Tuple, x: Schema): Tuple

Pull the values out of tuple t for the attributes in subschema x.

Pull the values out of tuple t for the attributes in subschema x.

Value parameters

t

the given tuple to pull values out of

x

the subschema/attributes to be collected

Attributes

def pull(t: Tuple, cp: IndexedSeq[Int]): Tuple

Pull the values out of tuple t for the attributes in subschema column positions cp.

Pull the values out of tuple t for the attributes in subschema column positions cp.

Value parameters

cp

the subschema/attribute column positions to be collected

t

the given tuple to pull values out of

Attributes

def pull(t: Row, x: Schema): Row

Pull the values out of row t for the attributes in subschema x.

Pull the values out of row t for the attributes in subschema x.

Value parameters

t

the given row to pull values out of

x

the subschema/attributes to be collected

Attributes

def pull(t: Row, cp: IndexedSeq[Int]): Row

Pull the values out of row t for the attributes in subschema column positions cp.

Pull the values out of row t for the attributes in subschema column positions cp.

Value parameters

cp

the subschema/attribute column positions to be collected

t

the given row to pull values out of

Attributes

def pull(t: Tuple, a: String): ValueType

Pull a value out of tuple t for attribute a.

Pull a value out of tuple t for attribute a.

Value parameters

a

the attribute to be collected

t

the given tuple to pull value out of

Attributes

def pull(x: Schema): Domain

Pull the domains out of this table for the attributes in subschema x.

Pull the domains out of this table for the attributes in subschema x.

Value parameters

x

the subschema/attributes to be collected

Attributes

def pull(cp: IndexedSeq[Int]): Domain

Pull the domains out of this table for the attributes in subschema column positions cp.

Pull the domains out of this table for the attributes in subschema column positions cp.

Value parameters

cp

the subschema/attribute column positions to be collected

Attributes

def rightJoin(x: Schema, y: Schema, r2: T): T

Compute the RIGHT-EQUI-JOIN of this table and r2 keeping concatenated tuples that are equal on specified attributes. Also, keep all tuples in the right table padding the missing attributes with null.

Compute the RIGHT-EQUI-JOIN of this table and r2 keeping concatenated tuples that are equal on specified attributes. Also, keep all tuples in the right table padding the missing attributes with null.

Value parameters

r2

the second table

x

the subschema/attributes for the left/first/this table

y

the subschema/attributes for the right/second table

Attributes

def rightJoin(r2: T): T

Compute the RIGHT-JOIN of this table and r2 keeping concatenated tuples that are equal on specified attributes. Also, keep all tuples in the right table padding the missing attributes with null.

Compute the RIGHT-JOIN of this table and r2 keeping concatenated tuples that are equal on specified attributes. Also, keep all tuples in the right table padding the missing attributes with null.

Value parameters

r2

the second table

Attributes

def showT(tups: ArrayBuffer[Tuple]): String

Convert the tuples in tups into a string, e.g., for displaying a collection of tuples.

Convert the tuples in tups into a string, e.g., for displaying a collection of tuples.

Value parameters

tups

the tuples to be converted to a string

Attributes

def typeCheck(t: Tuple): Boolean

Check the size of the tuple (number of elements) as well as the type of each value to ensure it is from the right domain (satisfies the DOMAIN CONSTRAINTS).

Check the size of the tuple (number of elements) as well as the type of each value to ensure it is from the right domain (satisfies the DOMAIN CONSTRAINTS).

Value parameters

t

the tuple to be type checked

Attributes

inline def ×(r2: T): T
inline def γ(ag: String): T
inline def π(x: String): T
inline def π(cPos: IndexedSeq[Int]): T
inline def ρ(newName: String): T
inline def σ(a: String, apred: APredicate): T
inline def σ(predicate: Predicate): T
inline def σ(condition: String): T
inline def σ(pkey: KeyType): T
inline def σπ(a: String, apred: APredicate): T
inline def (ag: String, f_as: (AggFunction, String)*): T
inline def (x: String*): T
inline def (x: String*): T
inline def (r2: T): T
inline def (r2: T): T
inline def (predicate: Predicate2, r2: T): T
inline def (condition: String, r2: T): T
inline def (x: String, y: String, r2: T): T
inline def (fkey: (String, T)): T
inline def (r2: T): T
inline def (x: Schema, y: Schema, r2: T): T
inline def (r2: T): T
inline def (x: Schema, y: Schema, r2: T): T
inline def (r2: T): T

Concrete fields

val domain: Domain
val key: Schema
val name: String
val on: Map[String, Int]
val schema: Schema