SwatDB
Loading...
Searching...
No Matches
Public Member Functions | Private Attributes | Friends | List of all members
Schema Class Reference

#include <schema.h>

Public Member Functions

 Schema ()=delete
 Disable default Constructor.
 
 Schema (const Schema &other)
 Disable copy assignment constructor.
 
 Schema (std::vector< FieldEntry > field_list, std::vector< std::string > primary_key)
 Constructor of Schema.
 
 Schema (std::ifstream *in_file)
 Schema Constructor that initializes schema based on saved metadata.
 
 ~Schema ()
 Destructor.
 
std::string getFieldName (FieldId field_id)
 
FieldId getFieldId (std::string field_name)
 getter function for the FieldId associated with a field name.
 
FieldType getFieldType (FieldId field_id)
 returns the field type given a field_id
 
void saveToFile (std::ofstream *out_file)
 save schema metadata to a file.
 
void printFields ()
 

Private Attributes

std::unordered_map< std::string, FieldIdfield_map
 
std::vector< FieldEntryfield_list
 
std::vector< FieldIdprimary_key
 

Friends

class IndexFile
 
class RelOpsManager
 
class Select
 
class Record
 
class Key
 
class SearchKeyFormat
 
class SwatDB
 
class FileManager
 

Detailed Description

SwatDB Schema Class. This is a class to represent the schema for a relation. It stores data structures, including mapping from field names to FieldId, field types, etc , reverse mapping from FieldId to field names, and list of primary keys. This is also a class used to represent key format. Strictly speaking, key format is DIFFERENT from relation schema, but as the data strcuctures used to represent the two are very similar, a common class is used in SwatDB for simplicity.

Constructor & Destructor Documentation

◆ Schema() [1/3]

Schema::Schema ( const Schema other)

Disable copy assignment constructor.

Copy assignment constructor.

◆ Schema() [2/3]

Schema::Schema ( std::vector< FieldEntry field_list,
std::vector< std::string >  primary_key 
)

Constructor of Schema.

Precondition
Valid field_list, a vector of FieldEntry and valid vector of field names for primary key are provided
Postcondition
The field_list and primary_key are initialized.
Exceptions
InvalidFieldNameSchemaif the the length of any field name exceeds MAX_FIELD_NAME.

◆ Schema() [3/3]

Schema::Schema ( std::ifstream *  in_file)

Schema Constructor that initializes schema based on saved metadata.

Parameters
in_filestd::ifsream* to read from.
Postcondition
The field_list and primary_key are initialized from the metadata file. The assumed format is:

Number of Fields Field Name for Field 0 Field Type for Field 0 (integer associated with FieldType data type) Max Size for Field 0 (in bytes) Field Name for Field 1 Field Type for Field 1(integer associated with FieldType data type) Max Size for Field 1 ... Number of Primary Key Fields FieldId for first field FieldId for second field ...

Example:

3 StudentId 0 4 Name 3 256 Gpa 2 4 1 0

This is the format that the saveToFile function outputs.

Member Function Documentation

◆ getFieldType()

FieldType Schema::getFieldType ( FieldId  field_id)

returns the field type given a field_id

Parameters
FieldIdfield_id corresponds to desired field
Returns
FieldType of desired field_id

◆ printFields()

void Schema::printFields ( )

NOTE: THIS METHOD IS FOR DEBUGGING ONLY

◆ saveToFile()

void Schema::saveToFile ( std::ofstream *  out_file)

save schema metadata to a file.

Saves data in this format: Num fields name – type | for each field max_size – (field_id implicit in order) ...

Num Primary Key Fields field ids ] in order

Parameters
out_filestd::ofsream* to output to.

Friends And Related Symbol Documentation

◆ IndexFile

friend class IndexFile
friend

IndexFile has access to private fields of Schema.

Member Data Documentation

◆ field_list

std::vector<FieldEntry> Schema::field_list
private

This vector is a maintains the list of FieldEntry, which stores field name, FieldType and max length of each field.

◆ field_map

std::unordered_map<std::string, FieldId> Schema::field_map
private

Mapping from field name to FieldId

◆ primary_key

std::vector<FieldId> Schema::primary_key
private

This is the vector of field identifiers that make up the primary key fields. No two records can have identical primary key values.


The documentation for this class was generated from the following file: