SwatDB
|
#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, FieldId > | field_map |
std::vector< FieldEntry > | field_list |
std::vector< FieldId > | primary_key |
Friends | |
class | IndexFile |
class | RelOpsManager |
class | Select |
class | Record |
class | Key |
class | SearchKeyFormat |
class | SwatDB |
class | FileManager |
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.
Schema::Schema | ( | const Schema & | other | ) |
Disable copy assignment constructor.
Copy assignment constructor.
Schema::Schema | ( | std::vector< FieldEntry > | field_list, |
std::vector< std::string > | primary_key | ||
) |
Constructor of Schema.
InvalidFieldNameSchema | if the the length of any field name exceeds MAX_FIELD_NAME. |
Schema::Schema | ( | std::ifstream * | in_file | ) |
Schema Constructor that initializes schema based on saved metadata.
in_file | std::ifsream* to read from. |
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.
returns the field type given a field_id
FieldId | field_id corresponds to desired field |
void Schema::printFields | ( | ) |
NOTE: THIS METHOD IS FOR DEBUGGING ONLY
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
out_file | std::ofsream* to output to. |
|
private |
This vector is a maintains the list of FieldEntry, which stores field name, FieldType and max length of each field.
|
private |
Mapping from field name to FieldId
|
private |
This is the vector of field identifiers that make up the primary key fields. No two records can have identical primary key values.