-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSchema.h
More file actions
91 lines (72 loc) · 2.03 KB
/
Schema.h
File metadata and controls
91 lines (72 loc) · 2.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#ifndef _SCHEMA_H
#define _SCHEMA_H
#include <string>
#include <vector>
#include <iostream>
#include "Config.h"
using namespace std;
/* Data structure for schema attributes:
* name of attribute
* type of attribute
* number of distinct values
*/
class Attribute {
public:
string name;
Type type;
unsigned int noDistinct;
// constructors and destructor
Attribute();
Attribute(const Attribute& _other);
Attribute& operator=(const Attribute& _other);
void Swap(Attribute& _other);
virtual ~Attribute() {}
};
/* Class to manage schema of relations:
* materialized on disk
* intermediate result during query execution
*/
class Schema {
private:
// attributes in schema
vector<Attribute> atts;
public:
// default constructor
Schema() {}
// full constructor
Schema(vector<string>& _attributes, vector<string>& _attributeTypes,
vector<unsigned int>& _distincts);
// copy constructor
Schema(const Schema& _other);
// assignment operator
Schema& operator=(const Schema& _other);
// swap function
void Swap(Schema& _other);
// destructor
virtual ~Schema() {atts.clear();}
// get functions
unsigned int GetNumAtts() {return atts.size();}
vector<Attribute>& GetAtts() {return atts;}
// append other schema
int Append(Schema& _other);
// find index of specified attribute
// return -1 if attribute is not present
int Index(string& _attName);
// find number of distincts of specified attribute
// return -1 if attribute is not present
int GetDistincts(string& _attName);
// rename an attribute
int RenameAtt(string& _oldName, string& _newName);
// project attributes of a schema
// only attributes indexed in the input vector are kept after projection
// index begins from 0
// return -1 if failure, 0 otherwise
int Project(vector<int>& _attsToKeep);
// find type of the specified attribute
// return arbitrary type if attribute is not present
// call only after Index returns valid result
Type FindType(string& _attName);
// operator for printing
friend ostream& operator<<(ostream& _os, Schema& _c);
};
#endif //_SCHEMA