-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
102 lines (92 loc) · 3.06 KB
/
main.cpp
File metadata and controls
102 lines (92 loc) · 3.06 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
92
93
94
95
96
97
98
99
100
101
102
/**
* @brief entry point for the Mini Columnar Query Engine
* @desc CLI interface for running unit tests, TPC-H query tests, and queries.
* Supports multiple execution modes via command-line arguments:
* - unit-test: Run unit tests only
* - queries-test: Run all TPC-H query tests
* - all-test: Run full suite (unit + queries)
* - 1-22: Run a specific TPC-H query test
* - run <1-22>: Execute a query and output to console
* - run-all: Execute all queries with console output
*/
#include <iostream>
#include <string>
#include "core/engine/test_runner.h"
#include "core/engine/QueryRunner.h"
/**
* @brief checks if a string contains only digit characters
* @param str string to check
* @return true if all characters are digits and string is non-empty
*/
bool isNumericString( const std::string& str ) {
if ( str.empty() ) {
return false;
}
for ( size_t i = 0; i < str.length(); i++ ) {
if ( str[i] < '0' || str[i] > '9' ) {
return false;
}
}
return true;
}
/**
* @brief parses command line arguments and runs the appropriate mode
* @param argc argument count
* @param argv argument values
* @return 0 on success, 1 on error
*/
int main( int argc, char* argv[] ) {
TestRunner testRunner;
QueryRunner queryRunner;
// no arguments: show usage and query list
if ( argc == 1 ) {
TestRunner::printUsage();
TestRunner::printQueryList();
return 0;
}
std::string arg = argv[1];
// check for named test modes
if ( arg == "unit-test" ) {
return testRunner.run( TestMode::UNIT_TESTS_ONLY );
}
if ( arg == "queries-test" ) {
return testRunner.run( TestMode::ALL_QUERIES_ONLY );
}
if ( arg == "all-test" ) {
return testRunner.run( TestMode::FULL_SUITE );
}
// check for run modes
if ( arg == "run" ) {
// run requires a query number as second argument
if ( argc < 3 ) {
std::cerr << "Error: 'run' requires a query number (1-22)" << std::endl;
return 1;
}
std::string queryArg = argv[2];
if ( !isNumericString( queryArg ) ) {
std::cerr << "Error: Invalid query number '" << queryArg << "'" << std::endl;
return 1;
}
int queryNum = std::stoi( queryArg );
if ( queryNum < 1 || queryNum > 22 ) {
std::cerr << "Error: Query number must be 1-22" << std::endl;
return 1;
}
return queryRunner.run( RunMode::SINGLE_QUERY, queryNum );
}
if ( arg == "run-all" ) {
return queryRunner.run( RunMode::ALL_QUERIES );
}
// try to parse as query number (1-22) for test mode
if ( isNumericString( arg ) ) {
int queryNum = std::stoi( arg );
if ( queryNum >= 1 && queryNum <= 22 ) {
return testRunner.run( TestMode::SINGLE_QUERY, queryNum );
}
}
// invalid argument
std::cerr << "Error: Unknown option '" << arg << "'" << std::endl;
std::cerr << std::endl;
TestRunner::printUsage();
return 1;
}