Column Store
Validators.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <memory>
4 
5 #include "DataRecord.h"
6 
11 namespace ColumnStore {
17  public:
25  virtual bool validate(DataRecord &record) { return true; }
26 
32 };
33 
39 typedef std::shared_ptr<RecordValidatorInterface> RecordValidator;
40 
50  protected:
56 
57  public:
64 };
65 
72 
73  public:
80 
88  bool validate(DataRecord &record) { return !condition->validate(record); }
89 };
90 
98 
99  public:
108 
116  bool validate(DataRecord &record) {
117  return validator1->validate(record) && validator2->validate(record);
118  }
119 };
120 
128 
129  public:
138 
146  bool validate(DataRecord &record) {
147  return validator1->validate(record) || validator2->validate(record);
148  }
149 };
150 
157  std::any value;
159 
160  public:
168  EqualRecordValidator(std::string columnName, std::any value,
169  Metadata _metadata)
171  auto &metadata = *(this->metadata.get());
172  columnIndex = metadata[columnName].index;
173  dataType = metadata[columnName].type;
174  }
175 
185  bool validate(DataRecord &record) {
186  if (dataType == DataType::INT) {
187  return std::any_cast<int>(value) == record[columnIndex].as<int>();
188  } else if (dataType == DataType::FLOAT) {
189  return std::any_cast<float>(value) ==
190  record[columnIndex].as<float>();
191  } else if (dataType == DataType::STRING) {
192  return std::any_cast<std::string>(value) ==
193  record[columnIndex].as<std::string>();
194  }
195 
196  throw "Unknown DataType";
197  }
198 };
199 
206  std::any value;
208 
209  public:
217  LessThanRecordValidator(std::string columnName, std::any value,
218  Metadata _metadata)
220  columnIndex = metadata->operator[](columnName).index;
221  dataType = (*metadata)[columnName].type;
222  }
223 
231  bool validate(DataRecord &record) {
232  if (dataType == DataType::INT) {
233  return std::any_cast<int>(value) > record[columnIndex].as<int>();
234  } else if (dataType == DataType::FLOAT) {
235  return std::any_cast<float>(value) >
236  record[columnIndex].as<float>();
237  } else if (dataType == DataType::STRING) {
238  return std::any_cast<std::string>(value) >
239  record[columnIndex].as<std::string>();
240  }
241 
242  throw "Unknown DataType";
243  }
244 };
245 }; // namespace ColumnStore
ColumnStore::OrRecordValidator::validator1
RecordValidator validator1
Definition: Validators.h:126
ColumnStore::LessThanRecordValidator::value
std::any value
Definition: Validators.h:206
ColumnStore::AndRecordValidator::validator2
RecordValidator validator2
Definition: Validators.h:97
ColumnStore::RecordValidatorInterface
Base RecordValidator Interface.
Definition: Validators.h:16
ColumnStore::NotRecordValidator
Inverts RecordValidator.
Definition: Validators.h:70
ColumnStore::ReccordValidatorMetadataInterface::ReccordValidatorMetadataInterface
ReccordValidatorMetadataInterface(Metadata metadata)
Construct a new Condition Metadata Interface object.
Definition: Validators.h:63
ColumnStore::NotRecordValidator::condition
RecordValidator condition
Definition: Validators.h:71
ColumnStore::RecordValidator
std::shared_ptr< RecordValidatorInterface > RecordValidator
Shared Pointer for RecordValidator Interface.
Definition: Validators.h:39
ColumnStore::DataType
DataType
Different datatypes supported by this project.
Definition: Column.h:16
ColumnStore::EqualRecordValidator::dataType
DataType dataType
Definition: Validators.h:158
ColumnStore::OrRecordValidator::validator2
RecordValidator validator2
Definition: Validators.h:127
ColumnStore
Definition: ColStoreDataGenerator.h:22
ColumnStore::AndRecordValidator
Logical AND RecordValidator.
Definition: Validators.h:95
ColumnStore::AndRecordValidator::validator1
RecordValidator validator1
Definition: Validators.h:96
ColumnStore::OrRecordValidator::validate
bool validate(DataRecord &record)
Applies logical OR condition to validator1 and validator2.
Definition: Validators.h:146
ColumnStore::DataType::STRING
@ STRING
ColumnStore::OrRecordValidator::OrRecordValidator
OrRecordValidator(RecordValidator validator1, RecordValidator validator2)
Construct a new Or Record Validator object.
Definition: Validators.h:136
ColumnStore::EqualRecordValidator::validate
bool validate(DataRecord &record)
Compares the equality of the column.
Definition: Validators.h:185
ColumnStore::AndRecordValidator::validate
bool validate(DataRecord &record)
Applies logical AND on validator1 and validator2.
Definition: Validators.h:116
ColumnStore::Metadata
std::shared_ptr< DataRecordMetadata > Metadata
Shared pointer to DataRecordMetadata.
Definition: DataRecord.h:208
ColumnStore::LessThanRecordValidator::dataType
DataType dataType
Definition: Validators.h:207
ColumnStore::DataRecord
Stores a row of data.
Definition: DataRecord.h:64
DataRecord.h
Data storage structures.
ColumnStore::EqualRecordValidator
Checks equality of a data field.
Definition: Validators.h:155
ColumnStore::ReccordValidatorMetadataInterface
Extended RecordValidator Interface which handles Metadata.
Definition: Validators.h:49
ColumnStore::NotRecordValidator::NotRecordValidator
NotRecordValidator(RecordValidator condition)
Construct a new Not Record Validator object.
Definition: Validators.h:79
ColumnStore::RecordValidatorInterface::~RecordValidatorInterface
virtual ~RecordValidatorInterface()
Destroy the Record Validator Interface object.
Definition: Validators.h:31
ColumnStore::DataType::INT
@ INT
ColumnStore::LessThanRecordValidator::columnIndex
int columnIndex
Definition: Validators.h:205
ColumnStore::EqualRecordValidator::columnIndex
int columnIndex
Definition: Validators.h:156
ColumnStore::OrRecordValidator
Logical OR RecordValidator.
Definition: Validators.h:125
ColumnStore::EqualRecordValidator::value
std::any value
Definition: Validators.h:157
ColumnStore::LessThanRecordValidator::LessThanRecordValidator
LessThanRecordValidator(std::string columnName, std::any value, Metadata _metadata)
Construct a new Less Than Record Validator object.
Definition: Validators.h:217
ColumnStore::LessThanRecordValidator::validate
bool validate(DataRecord &record)
Compares the value with given value.
Definition: Validators.h:231
ColumnStore::ReccordValidatorMetadataInterface::metadata
Metadata metadata
metadata object Use this object to extract column information such as column index and column type
Definition: Validators.h:55
ColumnStore::DataType::FLOAT
@ FLOAT
ColumnStore::EqualRecordValidator::EqualRecordValidator
EqualRecordValidator(std::string columnName, std::any value, Metadata _metadata)
Construct a new Equal Record Validator object.
Definition: Validators.h:168
ColumnStore::AndRecordValidator::AndRecordValidator
AndRecordValidator(RecordValidator validator1, RecordValidator validator2)
Construct a new And Record Validator object.
Definition: Validators.h:106
ColumnStore::RecordValidatorInterface::validate
virtual bool validate(DataRecord &record)
Validates record as per query conditions.
Definition: Validators.h:25
ColumnStore::NotRecordValidator::validate
bool validate(DataRecord &record)
inverts the value of the condition
Definition: Validators.h:88
ColumnStore::LessThanRecordValidator
Checks if value of a field is less than given value.
Definition: Validators.h:204