From 4e71f89a4797cfcc9f3a5e4159673e7464dc1649 Mon Sep 17 00:00:00 2001 From: Firas Abuzaid Date: Fri, 12 Jan 2018 16:53:30 -0800 Subject: [PATCH] more cleanup --- cpp/.clang-format | 90 -- cpp/.gitignore | 7 - cpp/Makefile | 20 - cpp/README.md | 1 - cpp/compare_by.h | 84 -- cpp/datagen.py | 29 - cpp/demo.sql | 20 - cpp/io_util.h | 135 --- cpp/libsqlparser.so | 1 - cpp/main.cpp | 383 ------- cpp/sql-parser/.gitignore | 50 - cpp/sql-parser/.travis.yml | 51 - cpp/sql-parser/Makefile | 147 --- cpp/sql-parser/README.md | 75 -- cpp/sql-parser/benchmark/README.md | 14 - cpp/sql-parser/benchmark/benchmark.cpp | 28 - cpp/sql-parser/benchmark/benchmark_utils.cpp | 44 - cpp/sql-parser/benchmark/benchmark_utils.h | 41 - cpp/sql-parser/benchmark/parser_benchmark.cpp | 87 -- cpp/sql-parser/benchmark/queries.cpp | 47 - cpp/sql-parser/benchmark/queries.h | 56 - cpp/sql-parser/docs/.gitignore | 1 - cpp/sql-parser/docs/README.md | 16 - cpp/sql-parser/docs/dev-docs.md | 63 - cpp/sql-parser/docs/known-limitations.md | 18 - cpp/sql-parser/docs/syntax-support.md | 53 - cpp/sql-parser/example/.gitignore | 1 - cpp/sql-parser/example/Makefile | 6 - cpp/sql-parser/example/example.cpp | 41 - cpp/sql-parser/src/SQLParser.cpp | 80 -- cpp/sql-parser/src/SQLParser.h | 38 - cpp/sql-parser/src/SQLParserResult.cpp | 112 -- cpp/sql-parser/src/SQLParserResult.h | 93 -- cpp/sql-parser/src/parser/.gitignore | 6 - cpp/sql-parser/src/parser/Makefile | 17 - cpp/sql-parser/src/parser/bison_parser.y | 1020 ----------------- cpp/sql-parser/src/parser/flex_lexer.l | 227 ---- .../src/parser/keywordlist_generator.py | 46 - cpp/sql-parser/src/parser/parser_typedef.h | 33 - cpp/sql-parser/src/sql/CreateStatement.h | 49 - cpp/sql-parser/src/sql/DeleteStatement.h | 22 - cpp/sql-parser/src/sql/DropStatement.h | 29 - cpp/sql-parser/src/sql/ExecuteStatement.h | 20 - cpp/sql-parser/src/sql/Expr.cpp | 224 ---- cpp/sql-parser/src/sql/Expr.h | 169 --- cpp/sql-parser/src/sql/ImportStatement.h | 24 - cpp/sql-parser/src/sql/InsertStatement.h | 28 - cpp/sql-parser/src/sql/PrepareStatement.cpp | 15 - cpp/sql-parser/src/sql/PrepareStatement.h | 22 - cpp/sql-parser/src/sql/SQLStatement.cpp | 32 - cpp/sql-parser/src/sql/SQLStatement.h | 49 - cpp/sql-parser/src/sql/SelectStatement.h | 63 - cpp/sql-parser/src/sql/ShowStatement.h | 26 - cpp/sql-parser/src/sql/Table.h | 83 -- cpp/sql-parser/src/sql/UpdateStatement.h | 27 - cpp/sql-parser/src/sql/statements.cpp | 293 ----- cpp/sql-parser/src/sql/statements.h | 15 - cpp/sql-parser/src/util/sqlhelper.cpp | 232 ---- cpp/sql-parser/src/util/sqlhelper.h | 28 - cpp/sql-parser/test/auto_query_file_test.cpp | 98 -- cpp/sql-parser/test/diff-queries-bad.sql | 7 - cpp/sql-parser/test/diff-queries-good.sql | 17 - cpp/sql-parser/test/prepare_tests.cpp | 98 -- cpp/sql-parser/test/queries/queries-bad.sql | 12 - cpp/sql-parser/test/queries/queries-good.sql | 53 - cpp/sql-parser/test/queries/tpc-h-01.sql | 9 - cpp/sql-parser/test/queries/tpc-h-02.sql | 10 - cpp/sql-parser/test/queries/tpc-h-03.sql | 7 - cpp/sql-parser/test/queries/tpc-h-04.sql | 6 - cpp/sql-parser/test/queries/tpc-h-05.sql | 9 - cpp/sql-parser/test/queries/tpc-h-06.sql | 5 - cpp/sql-parser/test/queries/tpc-h-07.sql | 11 - cpp/sql-parser/test/queries/tpc-h-08.sql | 10 - cpp/sql-parser/test/queries/tpc-h-09.sql | 10 - cpp/sql-parser/test/queries/tpc-h-10.sql | 9 - cpp/sql-parser/test/queries/tpc-h-11.sql | 10 - cpp/sql-parser/test/queries/tpc-h-12.sql | 10 - cpp/sql-parser/test/queries/tpc-h-13.sql | 8 - cpp/sql-parser/test/queries/tpc-h-14.sql | 5 - cpp/sql-parser/test/queries/tpc-h-15.sql | 15 - cpp/sql-parser/test/queries/tpc-h-16.sql | 9 - cpp/sql-parser/test/queries/tpc-h-17.sql | 4 - cpp/sql-parser/test/queries/tpc-h-18.sql | 7 - cpp/sql-parser/test/queries/tpc-h-19.sql | 9 - cpp/sql-parser/test/queries/tpc-h-20.sql | 8 - cpp/sql-parser/test/queries/tpc-h-21.sql | 11 - cpp/sql-parser/test/queries/tpc-h-22.sql | 9 - cpp/sql-parser/test/select_tests.cpp | 250 ---- cpp/sql-parser/test/sql_asserts.h | 23 - cpp/sql-parser/test/sql_parser.cpp | 44 - cpp/sql-parser/test/sql_tests.cpp | 201 ---- cpp/sql-parser/test/test.sh | 76 -- .../test/thirdparty/microtest/microtest.h | 224 ---- cpp/sql-parser/test/tpc_h_tests.cpp | 124 -- cpp/time_util.h | 23 - cpp/types.h | 9 - cpp/util.h | 34 - 97 files changed, 6215 deletions(-) delete mode 100644 cpp/.clang-format delete mode 100644 cpp/.gitignore delete mode 100644 cpp/Makefile delete mode 100644 cpp/README.md delete mode 100644 cpp/compare_by.h delete mode 100644 cpp/datagen.py delete mode 100644 cpp/demo.sql delete mode 100644 cpp/io_util.h delete mode 120000 cpp/libsqlparser.so delete mode 100644 cpp/main.cpp delete mode 100644 cpp/sql-parser/.gitignore delete mode 100644 cpp/sql-parser/.travis.yml delete mode 100644 cpp/sql-parser/Makefile delete mode 100644 cpp/sql-parser/README.md delete mode 100644 cpp/sql-parser/benchmark/README.md delete mode 100644 cpp/sql-parser/benchmark/benchmark.cpp delete mode 100644 cpp/sql-parser/benchmark/benchmark_utils.cpp delete mode 100644 cpp/sql-parser/benchmark/benchmark_utils.h delete mode 100644 cpp/sql-parser/benchmark/parser_benchmark.cpp delete mode 100644 cpp/sql-parser/benchmark/queries.cpp delete mode 100644 cpp/sql-parser/benchmark/queries.h delete mode 100644 cpp/sql-parser/docs/.gitignore delete mode 100644 cpp/sql-parser/docs/README.md delete mode 100644 cpp/sql-parser/docs/dev-docs.md delete mode 100644 cpp/sql-parser/docs/known-limitations.md delete mode 100644 cpp/sql-parser/docs/syntax-support.md delete mode 100644 cpp/sql-parser/example/.gitignore delete mode 100644 cpp/sql-parser/example/Makefile delete mode 100644 cpp/sql-parser/example/example.cpp delete mode 100644 cpp/sql-parser/src/SQLParser.cpp delete mode 100644 cpp/sql-parser/src/SQLParser.h delete mode 100644 cpp/sql-parser/src/SQLParserResult.cpp delete mode 100644 cpp/sql-parser/src/SQLParserResult.h delete mode 100644 cpp/sql-parser/src/parser/.gitignore delete mode 100644 cpp/sql-parser/src/parser/Makefile delete mode 100644 cpp/sql-parser/src/parser/bison_parser.y delete mode 100644 cpp/sql-parser/src/parser/flex_lexer.l delete mode 100644 cpp/sql-parser/src/parser/keywordlist_generator.py delete mode 100644 cpp/sql-parser/src/parser/parser_typedef.h delete mode 100644 cpp/sql-parser/src/sql/CreateStatement.h delete mode 100644 cpp/sql-parser/src/sql/DeleteStatement.h delete mode 100644 cpp/sql-parser/src/sql/DropStatement.h delete mode 100644 cpp/sql-parser/src/sql/ExecuteStatement.h delete mode 100644 cpp/sql-parser/src/sql/Expr.cpp delete mode 100644 cpp/sql-parser/src/sql/Expr.h delete mode 100644 cpp/sql-parser/src/sql/ImportStatement.h delete mode 100644 cpp/sql-parser/src/sql/InsertStatement.h delete mode 100644 cpp/sql-parser/src/sql/PrepareStatement.cpp delete mode 100644 cpp/sql-parser/src/sql/PrepareStatement.h delete mode 100644 cpp/sql-parser/src/sql/SQLStatement.cpp delete mode 100644 cpp/sql-parser/src/sql/SQLStatement.h delete mode 100644 cpp/sql-parser/src/sql/SelectStatement.h delete mode 100644 cpp/sql-parser/src/sql/ShowStatement.h delete mode 100644 cpp/sql-parser/src/sql/Table.h delete mode 100644 cpp/sql-parser/src/sql/UpdateStatement.h delete mode 100644 cpp/sql-parser/src/sql/statements.cpp delete mode 100644 cpp/sql-parser/src/sql/statements.h delete mode 100644 cpp/sql-parser/src/util/sqlhelper.cpp delete mode 100644 cpp/sql-parser/src/util/sqlhelper.h delete mode 100644 cpp/sql-parser/test/auto_query_file_test.cpp delete mode 100644 cpp/sql-parser/test/diff-queries-bad.sql delete mode 100644 cpp/sql-parser/test/diff-queries-good.sql delete mode 100644 cpp/sql-parser/test/prepare_tests.cpp delete mode 100644 cpp/sql-parser/test/queries/queries-bad.sql delete mode 100644 cpp/sql-parser/test/queries/queries-good.sql delete mode 100644 cpp/sql-parser/test/queries/tpc-h-01.sql delete mode 100644 cpp/sql-parser/test/queries/tpc-h-02.sql delete mode 100644 cpp/sql-parser/test/queries/tpc-h-03.sql delete mode 100644 cpp/sql-parser/test/queries/tpc-h-04.sql delete mode 100644 cpp/sql-parser/test/queries/tpc-h-05.sql delete mode 100644 cpp/sql-parser/test/queries/tpc-h-06.sql delete mode 100644 cpp/sql-parser/test/queries/tpc-h-07.sql delete mode 100644 cpp/sql-parser/test/queries/tpc-h-08.sql delete mode 100644 cpp/sql-parser/test/queries/tpc-h-09.sql delete mode 100644 cpp/sql-parser/test/queries/tpc-h-10.sql delete mode 100644 cpp/sql-parser/test/queries/tpc-h-11.sql delete mode 100644 cpp/sql-parser/test/queries/tpc-h-12.sql delete mode 100644 cpp/sql-parser/test/queries/tpc-h-13.sql delete mode 100644 cpp/sql-parser/test/queries/tpc-h-14.sql delete mode 100644 cpp/sql-parser/test/queries/tpc-h-15.sql delete mode 100644 cpp/sql-parser/test/queries/tpc-h-16.sql delete mode 100644 cpp/sql-parser/test/queries/tpc-h-17.sql delete mode 100644 cpp/sql-parser/test/queries/tpc-h-18.sql delete mode 100644 cpp/sql-parser/test/queries/tpc-h-19.sql delete mode 100644 cpp/sql-parser/test/queries/tpc-h-20.sql delete mode 100644 cpp/sql-parser/test/queries/tpc-h-21.sql delete mode 100644 cpp/sql-parser/test/queries/tpc-h-22.sql delete mode 100644 cpp/sql-parser/test/select_tests.cpp delete mode 100644 cpp/sql-parser/test/sql_asserts.h delete mode 100644 cpp/sql-parser/test/sql_parser.cpp delete mode 100644 cpp/sql-parser/test/sql_tests.cpp delete mode 100755 cpp/sql-parser/test/test.sh delete mode 100644 cpp/sql-parser/test/thirdparty/microtest/microtest.h delete mode 100644 cpp/sql-parser/test/tpc_h_tests.cpp delete mode 100644 cpp/time_util.h delete mode 100644 cpp/types.h delete mode 100644 cpp/util.h diff --git a/cpp/.clang-format b/cpp/.clang-format deleted file mode 100644 index 17d370f05..000000000 --- a/cpp/.clang-format +++ /dev/null @@ -1,90 +0,0 @@ ---- -Language: Cpp -# BasedOnStyle: Google -AccessModifierOffset: -1 -AlignAfterOpenBracket: Align -AlignConsecutiveAssignments: false -AlignConsecutiveDeclarations: false -AlignEscapedNewlinesLeft: true -AlignOperands: true -AlignTrailingComments: true -AllowAllParametersOfDeclarationOnNextLine: true -AllowShortBlocksOnASingleLine: false -AllowShortCaseLabelsOnASingleLine: false -AllowShortFunctionsOnASingleLine: All -AllowShortIfStatementsOnASingleLine: true -AllowShortLoopsOnASingleLine: true -AlwaysBreakAfterDefinitionReturnType: None -AlwaysBreakAfterReturnType: None -AlwaysBreakBeforeMultilineStrings: true -AlwaysBreakTemplateDeclarations: true -BinPackArguments: true -BinPackParameters: true -BraceWrapping: - AfterClass: false - AfterControlStatement: false - AfterEnum: false - AfterFunction: false - AfterNamespace: false - AfterObjCDeclaration: false - AfterStruct: false - AfterUnion: false - BeforeCatch: false - BeforeElse: false - IndentBraces: false -BreakBeforeBinaryOperators: None -BreakBeforeBraces: Attach -BreakBeforeTernaryOperators: true -BreakConstructorInitializersBeforeComma: false -ColumnLimit: 80 -CommentPragmas: '^ IWYU pragma:' -ConstructorInitializerAllOnOneLineOrOnePerLine: true -ConstructorInitializerIndentWidth: 4 -ContinuationIndentWidth: 4 -Cpp11BracedListStyle: true -DerivePointerAlignment: true -DisableFormat: false -ExperimentalAutoDetectBinPacking: false -ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH ] -IncludeCategories: - - Regex: '^<.*\.h>' - Priority: 1 - - Regex: '^<.*' - Priority: 2 - - Regex: '.*' - Priority: 3 -IndentCaseLabels: true -IndentWidth: 2 -IndentWrappedFunctionNames: false -KeepEmptyLinesAtTheStartOfBlocks: false -MacroBlockBegin: '' -MacroBlockEnd: '' -MaxEmptyLinesToKeep: 1 -NamespaceIndentation: None -ObjCBlockIndentWidth: 2 -ObjCSpaceAfterProperty: false -ObjCSpaceBeforeProtocolList: false -PenaltyBreakBeforeFirstCallParameter: 1 -PenaltyBreakComment: 300 -PenaltyBreakFirstLessLess: 120 -PenaltyBreakString: 1000 -PenaltyExcessCharacter: 1000000 -PenaltyReturnTypeOnItsOwnLine: 200 -PointerAlignment: Left -ReflowComments: true -SortIncludes: true -SpaceAfterCStyleCast: false -SpaceBeforeAssignmentOperators: true -SpaceBeforeParens: ControlStatements -SpaceInEmptyParentheses: false -SpacesBeforeTrailingComments: 2 -SpacesInAngles: false -SpacesInContainerLiterals: true -SpacesInCStyleCastParentheses: false -SpacesInParentheses: false -SpacesInSquareBrackets: false -Standard: Auto -TabWidth: 8 -UseTab: Never -... - diff --git a/cpp/.gitignore b/cpp/.gitignore deleted file mode 100644 index c2d556bde..000000000 --- a/cpp/.gitignore +++ /dev/null @@ -1,7 +0,0 @@ -macrodiff -macrodiff.dSYM/ -*.swp -*.tsv -*.txt -*.csv -*.parquet diff --git a/cpp/Makefile b/cpp/Makefile deleted file mode 100644 index 2984f2a2b..000000000 --- a/cpp/Makefile +++ /dev/null @@ -1,20 +0,0 @@ - -CC=clang++ -CFLAGS=-std=c++11 -lstdc++ -march=native -WARNINGS=-Wall -Werror -Wnull-dereference -INCLUDES= -LDFLAGS=-L./sql-parser -lsqlparser -lreadline -SRC=main.cpp -TARGET=macrodiff - - -.PHONY: all clean - -all: - $(CC) $(CFLAGS) -g -O3 $(WARNINGS) $(INCLUDES) $(LDFLAGS) $(SRC) -o $(TARGET) - -debug: - $(CC) $(CFLAGS) -g -O0 -DDEBUG $(WARNINGS) $(INCLUDES) $(LDFLAGS) $(SRC) -o $(TARGET) - -clean: - rm -rf $(TARGET) diff --git a/cpp/README.md b/cpp/README.md deleted file mode 100644 index 766e38509..000000000 --- a/cpp/README.md +++ /dev/null @@ -1 +0,0 @@ -# macrodiff diff --git a/cpp/compare_by.h b/cpp/compare_by.h deleted file mode 100644 index 53f741588..000000000 --- a/cpp/compare_by.h +++ /dev/null @@ -1,84 +0,0 @@ -#ifndef _COMPARE_BY_H_ -#define _COMPARE_BY_H_ - -#include -#include -#include -#include "util.h" - -using std::numeric_limits; - -typedef double (*macrodiff_compare_by_func)(const uint32_t, const uint32_t, - const uint32_t, const uint32_t); - -/** - * P(exposure| outlier ) / P(exposure | ~outlier) - */ -inline double prevalence_ratio(const uint32_t matched_outlier, - const uint32_t matched_total, - const uint32_t outlier_count, - const uint32_t total_count) { - if (outlier_count == 0 || matched_outlier == 0) { - return 0; - } - - const uint32_t inlier_count = total_count - outlier_count; - uint32_t matched_inlier = matched_total - matched_outlier; - - if (matched_inlier == 0) { - matched_inlier += 1; // increment by 1 to avoid divide-by-zero error - } - - return ((double)matched_outlier / outlier_count) / - ((double)matched_inlier / inlier_count); -} - -/** - * P(outlier | exposure) / P(outlier | ~exposure) - * Used in epidemiology - */ -inline double risk_ratio(const uint32_t matched_outlier, - const uint32_t matched_total, - const uint32_t outlier_count, - const uint32_t total_count) { - const double unmatched_outlier = outlier_count - matched_outlier; - const double unmatched_total = total_count - matched_total; - - if (matched_total == 0 || unmatched_total == 0) { - return 0; - } - // all outliers had this pattern - if (unmatched_outlier == 0) { - return numeric_limits::max(); - } - - return (matched_outlier / matched_total) / - (unmatched_outlier / unmatched_total); -} - -/** - * P(outlier | exposure) / P(outlier) - * Exponential pairwise mutual information - * Doesn't have NaN / Infty errors in edge cases as much as risk ratio does - */ -inline double pmi_ratio(const uint32_t matched_outlier, - const uint32_t matched_total, - const uint32_t outlier_count, - const uint32_t total_count) { - return (matched_outlier / (double)matched_total) / - (outlier_count / (double)total_count); -} - -// TODO: code-generation maybe? -macrodiff_compare_by_func get_compare_by_func(const std::string fn_name) { - if (equals_ignorecase(fn_name, "prevalence_ratio")) { - return prevalence_ratio; - } else if (equals_ignorecase(fn_name, "pmi_ratio")) { - return pmi_ratio; - } else { - // default, TODO: throw exception if fn_name isn't valid - // TODO: risk_ratio - return pmi_ratio; - } -} -#endif diff --git a/cpp/datagen.py b/cpp/datagen.py deleted file mode 100644 index 86a63959f..000000000 --- a/cpp/datagen.py +++ /dev/null @@ -1,29 +0,0 @@ -#! /usr/bin/env python - - -# Generate CSV data with outliers in specific order - -"A1,B2" - -import argparse -import numpy as np -from itertools import product - -def main(): - parser = argparse.ArgumentParser() - parser.add_argument('--cardinalities', required=True) - args = parser.parse_args() - - np.random.randint - cardinalities = [int(x) for x in args.cardinalities.strip().split(',')] - outlier_indices = [np.random.randint(val) for val in cardinalities] - print('Outlier: ' + str(outlier_indices)) - cols = [chr(i + ord('A')) for i in range(len(cardinalities))] - for value in product(*[range(x) for x in cardinalities]): - print(value) - - - - -if __name__ == '__main__': - main() diff --git a/cpp/demo.sql b/cpp/demo.sql deleted file mode 100644 index d764e74d3..000000000 --- a/cpp/demo.sql +++ /dev/null @@ -1,20 +0,0 @@ -IMPORT FROM CSV FILE '../core/demo/sample.csv' INTO sample; - -SELECT * FROM - DIFF - (SELECT * FROM sample WHERE usage > 1000.0) outliers, - (SELECT * FROM sample WHERE usage < 1000.0) inliers - ON - location, version - COMPARE BY - risk_ratio(COUNT(*)); - -SELECT * FROM - DIFF - (SELECT * FROM sample WHERE usage > 1000.0) outliers, - (SELECT * FROM sample WHERE usage < 1000.0) inliers - ON - location, version - COMPARE BY - risk_ratio(COUNT(*)) -WHERE risk_ratio > 10.0; diff --git a/cpp/io_util.h b/cpp/io_util.h deleted file mode 100644 index 83ce04a6b..000000000 --- a/cpp/io_util.h +++ /dev/null @@ -1,135 +0,0 @@ -#ifndef _IO_UTIL_H_ -#define _IO_UTIL_H_ - -#include -#include -#include -#include -#include -#include -#include - -#include "sql-parser/src/SQLParser.h" -#include "types.h" - -using std::string; -using std::vector; -using std::map; -using std::setw; -using std::setfill; -using std::cout; -using std::cin; -using std::endl; -using std::cerr; -using std::ifstream; - -string read_repl_input() { - string query_str = ""; - char* temp = readline("macrodiff> "); - if (temp == NULL) { - return ""; - } - - query_str += temp; - free(temp); - - while (*(query_str.end() - 1) != ';') { - temp = readline("... "); - if (temp == NULL) { - return ""; - } - query_str += "\n"; - query_str += temp; - free(temp); - } - return query_str; -} - -void read_csv(const char* filename, vector& data, - map& schema) { - ifstream input(filename); - // Parse header first to get schema (TODO: handle schemaless CSVs) - string line; - getline(input, line); - size_t last = 0; - size_t next = 0; - auto ind = 0u; - while ((next = line.find(',', last)) != string::npos) { - schema[line.substr(last, next - last)] = ind++; - last = next + 1; - } - schema[line.substr(last)] = ind; - - // Parse remaining rows - for (; getline(input, line);) { - if (line == "") { - continue; - } - Row row; - size_t last = 0; - size_t next = 0; - while ((next = line.find(',', last)) != string::npos) { - row.push_back(line.substr(last, next - last)); - last = next + 1; - } - row.push_back(line.substr(last)); - data.push_back(row); - } -} - -void import_table(const hsql::ImportStatement* query, vector& data, - map& schema) { - read_csv(query->filePath, data, schema); -} - -void print_table(const vector& data, const map& schema, - const uint32_t num_lines = 10, const uint32_t col_width = 10) { - const uint32_t num_attrs = schema.size(); - vector schemaAsVec(num_attrs); - for (auto it = schema.begin(); it != schema.end(); ++it) { - schemaAsVec[it->second] = it->first; - } - - cout << setfill('-') << setw((col_width + 1) * schemaAsVec.size() + 2) - << '\n'; - cout << setfill(' ') << "|"; - for (auto it = schemaAsVec.begin(); it != schemaAsVec.end(); ++it) { - cout << setw(col_width) << *it << "|"; - } - cout << endl; - cout << setfill('-') << setw((col_width + 1) * schemaAsVec.size() + 2) - << '\n'; - cout << setfill(' '); - - if (data.size() < num_lines) { - for (auto i = 0u; i < data.size(); ++i) { - const Row row = data[i]; - cout << "|"; - for (auto j = 0u; j < num_attrs; ++j) { - cout << setw(col_width) << row[j] << "|"; - } - cout << endl; - } - } else { - // print first 5 lines and last 5 lines - for (auto i = 0u; i < 5; ++i) { - const Row row = data[i]; - cout << "|"; - for (auto j = 0u; j < num_attrs; ++j) { - cout << setw(col_width) << row[j] << "|"; - } - cout << endl; - } - cout << "..." << endl; - for (auto i = data.size() - 5; i < data.size(); ++i) { - const Row row = data[i]; - cout << "|"; - for (auto j = 0u; j < num_attrs; ++j) { - cout << setw(col_width) << row[j] << "|"; - } - cout << endl; - } - } -} - -#endif diff --git a/cpp/libsqlparser.so b/cpp/libsqlparser.so deleted file mode 120000 index 8e77c7c7a..000000000 --- a/cpp/libsqlparser.so +++ /dev/null @@ -1 +0,0 @@ -sql-parser/libsqlparser.so \ No newline at end of file diff --git a/cpp/main.cpp b/cpp/main.cpp deleted file mode 100644 index 41b27d9ca..000000000 --- a/cpp/main.cpp +++ /dev/null @@ -1,383 +0,0 @@ -#include -#include -#include -#include -#include -#include - -#include "compare_by.h" -#include "io_util.h" -#include "sql-parser/src/SQLParser.h" -#include "time_util.h" -#include "types.h" -#include "util.h" - -#ifdef DEBUG -#include "sql-parser/src/util/sqlhelper.h" -#endif - -using std::cout; -using std::endl; -using std::map; -using std::min; -using std::string; -using std::tuple; -using std::vector; - -void diff(hsql::DiffDefinition* diff, const vector& input, - const map& input_schema, vector& output, - map& output_schema); - -void apply_where_predicates(hsql::Expr* whereClause, const vector& input, - const map& input_schema, - vector& output) { - const hsql::OperatorType op = whereClause->opType; - const string column_name = whereClause->expr->name; - // TODO: handle multiple types - const float val = whereClause->expr2->fval; - const uint32_t column_ind = input_schema.at(column_name); -#ifdef DEBUG - cout << "Where Operator Type: " << op << endl; - cout << "Where Column: " << column_name << endl; - - cout << "Where Value: " << val << endl; -#endif - - for (auto i = 0u; i < input.size(); ++i) { - Row row = input[i]; - switch (op) { - case hsql::kOpEquals: - if (std::stof(row[column_ind]) == val) { - output.push_back(row); - } - break; - case hsql::kOpNotEquals: - if (std::stof(row[column_ind]) != val) { - output.push_back(row); - } - break; - case hsql::kOpLess: - if (std::stof(row[column_ind]) < val) { - output.push_back(row); - } - break; - case hsql::kOpLessEq: - if (std::stof(row[column_ind]) <= val) { - output.push_back(row); - } - break; - case hsql::kOpGreater: - if (std::stof(row[column_ind]) > val) { - output.push_back(row); - } - break; - case hsql::kOpGreaterEq: - if (std::stof(row[column_ind]) >= val) { - output.push_back(row); - } - break; - - case hsql::kOpNone: - // Ternary operators - case hsql::kOpBetween: - case hsql::kOpCase: - // Binary operators. - case hsql::kOpPlus: - case hsql::kOpMinus: - case hsql::kOpAsterisk: - case hsql::kOpSlash: - case hsql::kOpPercentage: - case hsql::kOpCaret: - - case hsql::kOpLike: - case hsql::kOpNotLike: - case hsql::kOpILike: - case hsql::kOpAnd: - case hsql::kOpOr: - case hsql::kOpIn: - case hsql::kOpConcat: - - // Unary operators. - case hsql::kOpNot: - case hsql::kOpUnaryMinus: - case hsql::kOpIsNull: - case hsql::kOpExists: - default: - break; - } - } -} - -// TODO: handle projections -void select(const hsql::SelectStatement* stmt, const vector& input, - const map& input_schema, vector& output, - map& output_schema) { - const hsql::TableRef* fromTable = stmt->fromTable; - - if (fromTable->type == hsql::kTableDiff) { - if (stmt->whereClause != nullptr) { - vector diff_output; - diff(stmt->fromTable->diff, input, input_schema, diff_output, output_schema); - apply_where_predicates(stmt->whereClause, diff_output, output_schema, - output); - } else { - diff(stmt->fromTable->diff, input, input_schema, output, output_schema); - } - return; - } - - if (stmt->whereClause != nullptr) { - apply_where_predicates(stmt->whereClause, input, input_schema, output); - } -} - -/** - * Input: - * |usage|latency|location|version - * ratio: pmi_ratio - * metric col: usage - * attribute cols: location, version - * Return: - * |location|version|avg_usage|pmi_ratio|support_ratio - * - * @param input: the input table - * @param counts: the stats we're returning - * @param attr_indices: vector that contains indices for the attribute cols - * in the _input table. With these inputs, it would be `attr_indices = {2, 3}`. - * @param max_combo: The maximum number of combinations for a given explanation - * (i.e., in the output, there can only be a max_combo values in a single row - * that are non-null). - **/ -void count_diff_stats(const vector& input, map& counts, - const vector& attr_indices, - const uint32_t max_combo) { - const uint32_t num_rows = input.size(); - const uint32_t num_compare_attrs = attr_indices.size(); - - for (auto i = 0u; i < num_rows; ++i) { - const Row input_row = input[i]; - - for (auto j = 0u; j < num_compare_attrs; ++j) { - const uint32_t first_attr_index = attr_indices[j]; - const string first_attr = input_row[first_attr_index]; - Row order_one_attr_key(num_compare_attrs, "null"); - order_one_attr_key[j] = first_attr; - counts[order_one_attr_key] += 1; - - // TODO: code-gen? Right now, we only support max_combo = {1-3} - if (max_combo > 1) { - // 2-order combinations - for (auto k = j + 1; k < num_compare_attrs; ++k) { - const uint32_t second_attr_index = attr_indices[k]; - const string second_attr = input_row[second_attr_index]; - Row order_two_attr_key(order_one_attr_key); - order_two_attr_key[k] = second_attr; - counts[order_two_attr_key] += 1; - - if (max_combo > 2) { - // 3-order combinations - for (auto l = k + 1; l < num_compare_attrs; ++l) { - const uint32_t third_attr_index = attr_indices[l]; - const string third_attr = input_row[third_attr_index]; - Row order_three_attr_key(order_two_attr_key); - order_three_attr_key[l] = third_attr; - counts[order_three_attr_key] += 1; - } - } - } - } - } - } -} - -vector get_attribute_indices( - const std::vector& attribute_cols, - const map& schema) { - vector indices; - for (string col : attribute_cols) { - indices.push_back(schema.at(col)); - } - return indices; -} - -void diff(hsql::DiffDefinition* diff, const vector& input, - const map& input_schema, vector& output, - map& output_schema) { - vector outliers; - map dummy_schema; // TODO: this is janky; get rid of this - select(diff->first->select, input, input_schema, outliers, dummy_schema); - vector inliers; - // TODO: handle case where->diff->second == null - select(diff->second->select, input, input_schema, inliers, dummy_schema); - - const string compare_by_fn_name = diff->compare_by->getName(); - const string metric_col = diff->compare_by->exprList->at(0)->getName(); - - const std::vector attribute_cols = - get_attribute_cols(diff->attribute_cols); - vector attr_indices = - get_attribute_indices(attribute_cols, input_schema); - const uint32_t max_combo = - min((uint32_t)attribute_cols.size(), (uint32_t)diff->max_combo->ival); -#ifdef DEBUG - cout << "Attribute cols: "; - for (auto col : attribute_cols) { - cout << col << ", "; - } - cout << endl; - cout << "Compare By function: " << compare_by_fn_name << endl; - cout << "Max Combo: " << max_combo << endl; -#endif - - macrodiff_compare_by_func compare_by_fn = - get_compare_by_func(compare_by_fn_name); - -#ifdef DEBUG - bench_timer_t start = time_start(); - cout << "Beginning APriori" << endl; -#endif - - const uint32_t outlier_count = outliers.size(); - const uint32_t inlier_count = inliers.size(); - const uint32_t total_count = inlier_count + outlier_count; - - map outlier_counts; - count_diff_stats(outliers, outlier_counts, attr_indices, max_combo); - - map inlier_counts; - count_diff_stats(inliers, inlier_counts, attr_indices, max_combo); - -#ifdef DEBUG - cout << "Total outlier count: " << outlier_count << endl; - cout << "Total count: " << total_count << endl; -#endif - - // Create new output_schema - uint32_t ind = 0; - for (auto col : attribute_cols) { - // copy the attributes to the output schema - output_schema[col] = ind++; - } - // add the metric column, ratio column, and support column - output_schema[metric_col] = ind++; - output_schema[compare_by_fn_name] = ind++; - output_schema["support"] = ind++; - - for (auto it = outlier_counts.begin(); it != outlier_counts.end(); ++it) { - Row attrs_and_vals; - Row attrs = it->first; - attrs_and_vals.insert(std::begin(attrs_and_vals), std::begin(attrs), - std::end(attrs)); - - const uint32_t matched_outlier_count = it->second; - const uint32_t matched_inlier_count = inlier_counts[attrs]; - const uint32_t matched_total_count = - matched_outlier_count + matched_inlier_count; - - const double ratio_for_attrs = compare_by_fn( - matched_outlier_count, matched_total_count, outlier_count, total_count); - const double support_ratio = matched_outlier_count / (double)outlier_count; - - attrs_and_vals.push_back(std::to_string(matched_outlier_count)); - attrs_and_vals.push_back(std::to_string(ratio_for_attrs)); - attrs_and_vals.push_back(std::to_string(support_ratio)); - - output.push_back(attrs_and_vals); - } - -#ifdef DEBUG - const double time = time_stop(start); - cout << "APriori Time: " << time << endl; -#endif -} - -void repl() { - rl_bind_key('\t', rl_complete); - map input_schema; - vector INPUT; - map output_schema; - vector OUTPUT; - - while (true) { - const string query_str = read_repl_input(); - if (query_str == "") { - break; - } - - // Add query to history. - add_history(query_str.c_str()); - - // parse a given query_str - hsql::SQLParserResult query; - hsql::SQLParser::parseSQLString(query_str, &query); - - // check whether the parsing was successful - if (query.isValid()) { - assert(query.size() == 1); - const hsql::SQLStatement* query_statement = query.getStatement(0); -#ifdef DEBUG - cout << "Parsed successfully!" << endl; - cout << "Number of statements: " << query.size() << endl; - // Print a statement summary. - hsql::printStatementInfo(query_statement); -#endif - - switch (query_statement->type()) { - case hsql::kStmtImport: - INPUT.clear(); - import_table( - static_cast(query_statement), INPUT, - input_schema); - cout << "Num rows: " << INPUT.size() << endl; - print_table(INPUT, input_schema); - break; - case hsql::kStmtSelect: - OUTPUT.clear(); - output_schema.clear(); - select(static_cast(query_statement), - INPUT, input_schema, OUTPUT, output_schema); - print_table(OUTPUT, output_schema); - break; - case hsql::kStmtError: // unused - case hsql::kStmtInsert: - case hsql::kStmtUpdate: - case hsql::kStmtDelete: - case hsql::kStmtCreate: - case hsql::kStmtDrop: - case hsql::kStmtPrepare: - case hsql::kStmtExecute: - case hsql::kStmtExport: - case hsql::kStmtRename: - case hsql::kStmtAlter: - case hsql::kStmtShow: - default: - break; - } - - } else { - fprintf(stderr, "Given string is not a valid SQL query.\n"); - fprintf(stderr, "%s (L%d:%d)\n", query.errorMsg(), query.errorLine(), - query.errorColumn()); - } - } -} - -void print_welcome() { - const string ascii_art = - R"!( -Welcome to - __ ___ ___ ________ - / |/ /___ _______________ ____/ (_) __/ __/ - / /|_/ / __ `/ ___/ ___/ __ \/ __ / / /_/ /_ - / / / / /_/ / /__/ / / /_/ / /_/ / / __/ __/ -/_/ /_/\__,_/\___/_/ \____/\__,_/_/_/ /_/ - -)!"; - cout << ascii_art << endl; -} - -int main(/*int argc, const char* argv[]*/) { - print_welcome(); - repl(); - return 0; -} diff --git a/cpp/sql-parser/.gitignore b/cpp/sql-parser/.gitignore deleted file mode 100644 index d47c92ef4..000000000 --- a/cpp/sql-parser/.gitignore +++ /dev/null @@ -1,50 +0,0 @@ -build/ -utils/ -bin/ -lib-test/ - -# Compiled Object files -*.slo -*.lo -*.o -*.obj - -# Precompiled Headers -*.gch -*.pch - -# Compiled Dynamic libraries -*.so -*.dylib -*.dll - -# Fortran module files -*.mod - -# Compiled Static libraries -*.lai -*.la -*.a -*.lib - -# Executables -*.exe -*.out -*.app - -# IDE -.idea/ - -# CMAKE -cmake-build-debug/ - -*.cpp.orig -*.h.orig - -# Vim Swap Files -*.swp - -*.csv - -# macOS compilation dirs -*.dSYM diff --git a/cpp/sql-parser/.travis.yml b/cpp/sql-parser/.travis.yml deleted file mode 100644 index 4bbbb5921..000000000 --- a/cpp/sql-parser/.travis.yml +++ /dev/null @@ -1,51 +0,0 @@ - -language: cpp - -install: - - sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test - - sudo apt-get -qq update - - sudo apt-get install -y g++-6 libstdc++-6-dev - - sudo apt-get install -y valgrind - - sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-6 90 - - sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-6 90 - - # Install bison 3.0.4. - - wget http://ftp.gnu.org/gnu/bison/bison-3.0.4.tar.gz - - tar -xvzf bison-3.0.4.tar.gz - - cd bison-3.0.4 - - ./configure && make && sudo make install - - cd .. - - # Install flex 2.6.4 - - wget https://github.com/westes/flex/releases/download/v2.6.4/flex-2.6.4.tar.gz - - tar -xvzf flex-2.6.4.tar.gz - - cd flex-2.6.4 - - ./configure && make && sudo make install - - cd .. - - # Show installed versions. - - which g++ - - g++ -v - - bison --version - - flex --version - - valgrind --version - - if [ "$CXX" = "clang++" ]; then export CXXFLAGS="-stdlib=libc++"; fi - -compiler: - - gcc - - clang - -script: - # bi build with flex/bison files checked into repo - - make -j4 - - make test - - make test_example - - # build flex/bison files in CI - - make cleanall - - make -j4 - - make test - - make test_example - - # Test if benchmark can be built. - # - make benchmark diff --git a/cpp/sql-parser/Makefile b/cpp/sql-parser/Makefile deleted file mode 100644 index 5800fc526..000000000 --- a/cpp/sql-parser/Makefile +++ /dev/null @@ -1,147 +0,0 @@ -all: library - -####################################### -############# Directories ############# -####################################### -BIN = bin -SRC = src -SRCPARSER = src/parser - -INSTALL = /usr/local - -###################################### -############ Compile Mode ############ -###################################### -# Set compile mode to -g or -O3. -# Debug mode: make mode=debug - -mode ?= release -MODE_LOG = "" -OPT_FLAG = -ifeq ($(mode), debug) - OPT_FLAG = -g - MODE_LOG = "Building in \033[1;31mdebug\033[0m mode" -else - OPT_FLAG = -O3 - MODE_LOG = "Building in \033[0;32mrelease\033[0m mode ('make mode=debug' for debug mode)" -endif - -GMAKE = make mode=$(mode) - - - -####################################### -############### Library ############### -####################################### -PARSER_CPP = $(SRCPARSER)/bison_parser.cpp $(SRCPARSER)/flex_lexer.cpp -PARSER_H = $(SRCPARSER)/bison_parser.h $(SRCPARSER)/flex_lexer.h - -LIB_BUILD = libsqlparser.so -LIB_CFLAGS = -std=c++1z -Wall -Werror -fPIC $(OPT_FLAG) -LIB_LFLAGS = -shared $(OPT_FLAG) -LIB_CPP = $(shell find $(SRC) -name '*.cpp' -not -path "$(SRCPARSER)/*") $(PARSER_CPP) -LIB_H = $(shell find $(SRC) -name '*.h' -not -path "$(SRCPARSER)/*") $(PARSER_H) -LIB_ALL = $(shell find $(SRC) -name '*.cpp' -not -path "$(SRCPARSER)/*") $(shell find $(SRC) -name '*.h' -not -path "$(SRCPARSER)/*") -LIB_OBJ = $(LIB_CPP:%.cpp=%.o) - -library: $(LIB_BUILD) - -$(LIB_BUILD): $(LIB_OBJ) - $(CXX) $(LIB_LFLAGS) -o $(LIB_BUILD) $(LIB_OBJ) - -$(SRCPARSER)/flex_lexer.o: $(SRCPARSER)/flex_lexer.cpp $(SRCPARSER)/bison_parser.cpp - $(CXX) $(LIB_CFLAGS) -c -o $@ $< -Wno-register -Wno-sign-compare -Wno-unneeded-internal-declaration - -%.o: %.cpp $(PARSER_CPP) $(LIB_H) - $(CXX) $(LIB_CFLAGS) -c -o $@ $< - -$(SRCPARSER)/bison_parser.cpp: $(SRCPARSER)/bison_parser.y - $(GMAKE) -C $(SRCPARSER)/ bison_parser.cpp - -$(SRCPARSER)/flex_lexer.cpp: $(SRCPARSER)/flex_lexer.l - $(GMAKE) -C $(SRCPARSER)/ flex_lexer.cpp - -$(SRCPARSER)/bison_parser.h: $(SRCPARSER)/bison_parser.cpp -$(SRCPARSER)/flex_lexer.h: $(SRCPARSER)/flex_lexer.cpp - -clean: - rm -f $(LIB_BUILD) - rm -rf $(BIN) - find $(SRC) -type f -name '*.o' -delete - -cleanparser: - $(GMAKE) -C $(SRCPARSER)/ clean - -cleanall: clean cleanparser - -install: - cp $(LIB_BUILD) $(INSTALL)/lib/$(LIB_BUILD) - rm -rf $(INSTALL)/include/hsql - cp -r src $(INSTALL)/include/hsql - find $(INSTALL)/include/hsql -not -name '*.h' -type f | xargs rm - - - -####################################### -############## Benchmark ############## -####################################### -BM_BUILD = $(BIN)/benchmark -BM_CFLAGS = -std=c++17 -Wall -Isrc/ -L./ $(OPT_FLAG) -BM_PATH = benchmark -BM_CPP = $(shell find $(BM_PATH)/ -name '*.cpp') -BM_ALL = $(shell find $(BM_PATH)/ -name '*.cpp' -or -name '*.h') - -benchmark: $(BM_BUILD) - -run_benchmarks: benchmark - ./$(BM_BUILD) --benchmark_counters_tabular=true - # --benchmark_filter="abc - -save_benchmarks: benchmark - ./$(BM_BUILD) --benchmark_format=csv > benchmarks.csv - -$(BM_BUILD): $(BM_ALL) $(LIB_BUILD) - @mkdir -p $(BIN)/ - $(CXX) $(BM_CFLAGS) $(BM_CPP) -o $(BM_BUILD) -lbenchmark -lpthread -lsqlparser -lstdc++ -lstdc++fs - - - -######################################## -############ Test & Example ############ -######################################## -TEST_BUILD = $(BIN)/tests -TEST_CFLAGS = -std=c++1z -Wall -Werror -Isrc/ -Itest/ -L./ $(OPT_FLAG) -TEST_CPP = $(shell find test/ -name '*.cpp') -TEST_ALL = $(shell find test/ -name '*.cpp') $(shell find test/ -name '*.h') -EXAMPLE_SRC = $(shell find example/ -name '*.cpp') $(shell find example/ -name '*.h') - -test: $(TEST_BUILD) - bash test/test.sh - -$(TEST_BUILD): $(TEST_ALL) $(LIB_BUILD) - @mkdir -p $(BIN)/ - $(CXX) $(TEST_CFLAGS) $(TEST_CPP) -o $(TEST_BUILD) -lsqlparser -lstdc++ - -test_example: - $(GMAKE) -C example/ - LD_LIBRARY_PATH=./ \ - ./example/example "SELECT * FROM students WHERE name = 'Max Mustermann';" - -test_format: - @! astyle --options=astyle.options $(LIB_ALL) | grep -q "Formatted" - @! astyle --options=astyle.options $(TEST_ALL) | grep -q "Formatted" - - - -######################################## -################# Misc ################# -######################################## - -format: - astyle --options=astyle.options $(LIB_ALL) - astyle --options=astyle.options $(TEST_ALL) - astyle --options=astyle.options $(EXAMPLE_SRC) - -log_mode: - @echo $(MODE_LOG) - diff --git a/cpp/sql-parser/README.md b/cpp/sql-parser/README.md deleted file mode 100644 index af4bab2aa..000000000 --- a/cpp/sql-parser/README.md +++ /dev/null @@ -1,75 +0,0 @@ -C++ SQL Parser -========================= -[![GitHub release](https://img.shields.io/github/release/hyrise/sql-parser.svg?maxAge=2592000)]() -[![Build Status](https://img.shields.io/travis/hyrise/sql-parser.svg?maxAge=2592000)](https://travis-ci.org/hyrise/sql-parser) - - -This is a SQL Parser for C++. It parses the given SQL query into C++ objects. -It has been developed for integration in [Hyrise](https://github.com/hyrise/hyrise), but can be used perfectly well in other environments as well. - -In March 2015 we've also written a short paper outlining discussing some development details and the integration into our database Hyrise. You can find the paper [here](http://torpedro.com/paper/HyriseSQL-03-2015.pdf). - - -## Usage - -**Note:** You can also find a detailed usage description at this [blog post](http://torpedro.github.io/tech/c++/sql/parser/2016/02/27/c++-sql-parser.html). - -**Requirements:** - * gcc 4.8+ (or clang 3.4+) - -To use the SQL parser in your own projects you simply have to follow these few steps. The only requirement for is gcc 4.8+. Older versions of gcc/clang might also work, but are untested. - - 1. Download the [latest release here](https://github.com/hyrise/sql-parser/releases) - 2. Compile the library `make` to create `libsqlparser.so` - 3. *(Optional, Recommended)* Run `make install` to copy the library to `/usr/local/lib/` - 4. Run the tests `make test` to make sure everything worked - 5. Include the `SQLParser.h` from `src/` (or from `/usr/local/lib/hsql/` if you installed it) and link the library in your project - 6. Take a look at the [example project here](https://github.com/hyrise/sql-parser/tree/master/example) - -```cpp -#include "hsql/SQLParser.h" - -/* ... */ - -{ - // Basic Usage Example - - const std::string query = "..."; - hsql::SQLParserResult result; - hsql::SQLParser::parse(query, &result); - - if (result.isValid() && result.size() > 0) { - const hsql::SQLStatement* statement = result.getStatement(0); - - if (statement.isType(hsql::SelectStatement)) { - const hsql::SelectStatement* select = (const hsql::SelectStatement*) statement; - /* ... */ - } - } -} -``` - -Quick Links: - - * [SQLParser.h](src/SQLParser.h) - * [SQLParserResult.h](src/SQLParserResult.h) - * [SelectStatement.h](src/sql/SelectStatement.h) - -## How to Contribute - -**[Developer Documentation](docs/)** - -We strongly encourage you to contribute to this project! If you want to contribute to this project there are several options. If you've noticed a bug or would like an improvement let us know by creating a [new issue](https://github.com/hyrise/sql-parser/issues). If you want to develop a new feature yourself or just improve the quality of the system, feel free to fork the reposistory and implement your changes. Open a pull request as soon as your done and we will look over it. If we think it's good then your pull request will be merged into this repository. - - -## License - -HYRISE sql-parser is licensed as open source after the OpenSource "Licence of the Hasso-Plattner Institute" declared in the LICENSE file of this project. - - -## Contributers - -The following people contributed to HYRISE sql-parser in various forms. - -* Pedro Flemming ([@torpedro](https://github.com/torpedro)) -* David Schwalb ([@schwald](https://github.com/schwald)) diff --git a/cpp/sql-parser/benchmark/README.md b/cpp/sql-parser/benchmark/README.md deleted file mode 100644 index 6c038baa0..000000000 --- a/cpp/sql-parser/benchmark/README.md +++ /dev/null @@ -1,14 +0,0 @@ -# Benchmark - -This directory contains the scripts to execute benchmarks of the parser. We use [Google Benchmark](https://github.com/google/benchmark) to define and run benchmarks. - -## Install Google Benchmark - -```bash -cmake -DCMAKE_BUILD_TYPE=Release - -make - -make install -``` - diff --git a/cpp/sql-parser/benchmark/benchmark.cpp b/cpp/sql-parser/benchmark/benchmark.cpp deleted file mode 100644 index e1435504b..000000000 --- a/cpp/sql-parser/benchmark/benchmark.cpp +++ /dev/null @@ -1,28 +0,0 @@ -#include "benchmark/benchmark.h" - -#include "benchmark_utils.h" -#include "queries.h" - -int main(int argc, char** argv) { - // Create parse and tokenize benchmarks for TPC-H queries. - const auto tpch_queries = getTPCHQueries(); - for (const auto& query : tpch_queries) { - std::string p_name = query.first + "-parse"; - benchmark::RegisterBenchmark(p_name.c_str(), &BM_ParseBenchmark, query.second); - std::string t_name = query.first + "-tokenize"; - benchmark::RegisterBenchmark(t_name.c_str(), &BM_TokenizeBenchmark, query.second); - } - - // Create parse and tokenize benchmarks for all queries in sql_queries array. - for (unsigned i = 0; i < sql_queries.size(); ++i) { - const auto& query = sql_queries[i]; - std::string p_name = getQueryName(i) + "-parse"; - benchmark::RegisterBenchmark(p_name.c_str(), &BM_ParseBenchmark, query.second); - - std::string t_name = getQueryName(i) + "-tokenize"; - benchmark::RegisterBenchmark(t_name.c_str(), &BM_TokenizeBenchmark, query.second); - } - - benchmark::Initialize(&argc, argv); - benchmark::RunSpecifiedBenchmarks(); -} diff --git a/cpp/sql-parser/benchmark/benchmark_utils.cpp b/cpp/sql-parser/benchmark/benchmark_utils.cpp deleted file mode 100644 index 27fb66c4e..000000000 --- a/cpp/sql-parser/benchmark/benchmark_utils.cpp +++ /dev/null @@ -1,44 +0,0 @@ -#include "benchmark_utils.h" - -#include -#include - -#include "SQLParser.h" - -size_t getNumTokens(const std::string& query) { - std::vector tokens; - hsql::SQLParser::tokenize(query, &tokens); - return tokens.size(); -} - -void BM_TokenizeBenchmark(benchmark::State& st, const std::string& query) { - st.counters["num_tokens"] = getNumTokens(query); - st.counters["num_chars"] = query.size(); - - while (st.KeepRunning()) { - std::vector tokens(512); - hsql::SQLParser::tokenize(query, &tokens); - } -} - -void BM_ParseBenchmark(benchmark::State& st, const std::string& query) { - st.counters["num_tokens"] = getNumTokens(query); - st.counters["num_chars"] = query.size(); - - while (st.KeepRunning()) { - hsql::SQLParserResult result; - hsql::SQLParser::parse(query, &result); - if (!result.isValid()) { - std::cout << query << std::endl; - std::cout << result.errorMsg() << std::endl; - st.SkipWithError("Parsing failed!"); - } - } -} - -std::string readFileContents(const std::string& file_path) { - std::ifstream t(file_path.c_str()); - std::string text((std::istreambuf_iterator(t)), - std::istreambuf_iterator()); - return text; -} diff --git a/cpp/sql-parser/benchmark/benchmark_utils.h b/cpp/sql-parser/benchmark/benchmark_utils.h deleted file mode 100644 index 7eb54d809..000000000 --- a/cpp/sql-parser/benchmark/benchmark_utils.h +++ /dev/null @@ -1,41 +0,0 @@ -#ifndef __BENCHMARK_UTILS_H__ -#define __BENCHMARK_UTILS_H__ - -#include "benchmark/benchmark.h" - -size_t getNumTokens(const std::string& query); - -void BM_TokenizeBenchmark(benchmark::State& st, const std::string& query); - -void BM_ParseBenchmark(benchmark::State& st, const std::string& query); - -std::string readFileContents(const std::string& file_path); - - - - -#define TIME_DIFF(end, start)\ - std::chrono::duration_cast>(end - start); - -#define NOW()\ - std::chrono::high_resolution_clock::now(); - -#define PARSE_QUERY_BENCHMARK(name, query)\ - static void name(benchmark::State& st) {\ - BM_ParseBenchmark(st, query);\ - }\ - BENCHMARK(name); - -#define TOKENIZE_QUERY_BENCHMARK(name, query)\ - static void name(benchmark::State& st) {\ - BM_TokenizeBenchmark(st, query);\ - }\ - BENCHMARK(name); - - -#define BENCHMARK_QUERY(test_name, query)\ - TOKENIZE_QUERY_BENCHMARK(test_name##Tokenize, query)\ - PARSE_QUERY_BENCHMARK(test_name##Parse, query) - - -#endif \ No newline at end of file diff --git a/cpp/sql-parser/benchmark/parser_benchmark.cpp b/cpp/sql-parser/benchmark/parser_benchmark.cpp deleted file mode 100644 index 47928f0a7..000000000 --- a/cpp/sql-parser/benchmark/parser_benchmark.cpp +++ /dev/null @@ -1,87 +0,0 @@ - -#include -#include -#include "benchmark/benchmark.h" - -#include "SQLParser.h" -#include "parser/bison_parser.h" -#include "parser/flex_lexer.h" - -#include "benchmark_utils.h" - -// Benchmark the influence of increasing size of the query, while -// the number of tokens remains unchanged. -static void BM_CharacterCount(benchmark::State& st) { - const size_t querySize = st.range(0); - - // Base query has size of 18 characters. - std::string query = "SELECT %name% FROM test;"; - - const uint pad = querySize - 18; - const std::string filler = std::string(pad, 'a'); - query.replace(7, 6, filler); - - st.counters["num_tokens"] = getNumTokens(query); - st.counters["num_chars"] = query.size(); - while (st.KeepRunning()) { - hsql::SQLParserResult result; - hsql::SQLParser::parse(query, &result); - } -} -BENCHMARK(BM_CharacterCount) - ->RangeMultiplier(1 << 2) - ->Ranges({{1 << 5, 1 << 15}, - {5, 5}}); - -// Benchmark the influence of increasing number of tokens, while -// the number of characters remains unchanged. -static void BM_ConditionalTokens(benchmark::State& st) { - const size_t targetSize = st.range(0); - const size_t numTokens = st.range(1); - - // Base query contains 6 tokens. - std::string query = "SELECT * FROM test"; - - // Create conditional. - std::stringstream condStream; - size_t missingTokens = numTokens - 4; - if (missingTokens > 0) { - condStream << " WHERE a"; - missingTokens -= 2; - - while (missingTokens > 0) { - condStream << " AND a"; - missingTokens -= 2; - } - } - - query += condStream.str(); - - if (targetSize >= query.size()) { - const size_t pad = targetSize - query.size(); - const std::string filler = std::string(pad, 'a'); - query.replace(7, 1, filler); - - } else { - // Query can't be the same length as in the other benchmarks. - // Running this will result in unusable data. - fprintf(stderr, "Too many tokens. Query too long for benchmark char limit (%lu > %lu).\n", - query.size(), targetSize); - return; - } - - st.counters["num_tokens"] = getNumTokens(query); - st.counters["num_chars"] = query.size(); - while (st.KeepRunning()) { - hsql::SQLParserResult result; - hsql::SQLParser::parse(query, &result); - if (!result.isValid()) st.SkipWithError("Parsing failed!"); - } -} -BENCHMARK(BM_ConditionalTokens) - ->RangeMultiplier(1 << 2) - ->Ranges({{1 << 14, 1 << 14}, - {1 << 2, 1 << 11}}); - - - diff --git a/cpp/sql-parser/benchmark/queries.cpp b/cpp/sql-parser/benchmark/queries.cpp deleted file mode 100644 index 8b6d7e021..000000000 --- a/cpp/sql-parser/benchmark/queries.cpp +++ /dev/null @@ -1,47 +0,0 @@ -#include "queries.h" - -#include -#include -#include -#include - -#include "benchmark_utils.h" - -namespace filesystem = std::experimental::filesystem; - -std::string getQueryName(unsigned i) { - if (sql_queries[i].first.empty()) { - std::string name = "#" + std::to_string(i + 1); - return name; - } - return std::string("") + sql_queries[i].first; -} - -std::vector getQueriesFromDirectory(const std::string& dir_path) { - std::regex query_file_regex("\\.sql$"); - std::vector files; - - for (auto& entry : filesystem::directory_iterator(dir_path)) { - if (filesystem::is_regular_file(entry)) { - std::string path_str = filesystem::path(entry); - - if (std::regex_search(path_str, query_file_regex)) { - files.push_back(path_str); - } - } - } - - std::sort(files.begin(), files.end()); - - std::vector queries; - for (const std::string& file_path : files) { - const filesystem::path p(file_path); - const std::string query = readFileContents(file_path); - queries.emplace_back(p.filename(), query); - } - return queries; -} - -std::vector getTPCHQueries() { - return getQueriesFromDirectory("test/queries/"); -} diff --git a/cpp/sql-parser/benchmark/queries.h b/cpp/sql-parser/benchmark/queries.h deleted file mode 100644 index 357bee61f..000000000 --- a/cpp/sql-parser/benchmark/queries.h +++ /dev/null @@ -1,56 +0,0 @@ -#ifndef __QUERIES_H__ -#define __QUERIES_H__ - -#include -#include - -typedef std::pair SQLQuery; - -// name, query -static std::vector sql_queries = { - {"Q1", "SELECT * FROM test;"}, - {"Q2", "SELECT a, b AS address FROM (SELECT * FROM test WHERE c < 100 AND b > 3) t1 WHERE a < 10 AND b < 100;"}, - {"Q3", "SELECT \"left\".a, \"left\".b, \"right\".a, \"right\".b FROM table_a AS \"left\" JOIN table_b AS \"right\" ON \"left\".a = \"right\".a;"}, - {"Q4", "" -"SELECT" -" l_orderkey," -" SUM(l_extendedprice * (1 - l_discount)) AS revenue," -" o_orderdate," -" o_shippriority" -" FROM" -" customer," -" orders," -" lineitem" -" WHERE" -" c_mktsegment = '%s'" -" and c_custkey = o_custkey" -" and l_orderkey = o_orderkey" -" and o_orderdate < '%s'" -" and l_shipdate > '%s'" -" GROUP BY" -" l_orderkey," -" o_orderdate," -" o_shippriority" -" ORDER BY" -" revenue DESC," -" o_orderdate;" -}, - - {"LongSelectList26", "SELECT a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z FROM test;"}, - {"LongSelectElement26", "SELECT abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxy FROM test;"}, - {"LongSelectList52", "SELECT a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z FROM test;"}, - {"LongSelectElement52", "SELECT abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxy FROM test;"}, - {"TwoSelects", "SELECT * FROM test; SELECT age, street AS address FROM data;"}, - {"ExecuteNoParams", "EXECUTE procedure;"}, - {"Execute2Params", "EXECUTE procedure(11, 'test');"}, - {"Execute10Params", "EXECUTE procedure(11, 'test', 5.6, 4.2, 'abc', 6, 7, 8, 9, 10000);"}, - // {"name", "query"}, -}; - -std::string getQueryName(unsigned i); - -std::vector getQueriesFromDirectory(const std::string& dir_path); - -std::vector getTPCHQueries(); - -#endif diff --git a/cpp/sql-parser/docs/.gitignore b/cpp/sql-parser/docs/.gitignore deleted file mode 100644 index a3925495e..000000000 --- a/cpp/sql-parser/docs/.gitignore +++ /dev/null @@ -1 +0,0 @@ -__doxygen__/ \ No newline at end of file diff --git a/cpp/sql-parser/docs/README.md b/cpp/sql-parser/docs/README.md deleted file mode 100644 index f80ee5a36..000000000 --- a/cpp/sql-parser/docs/README.md +++ /dev/null @@ -1,16 +0,0 @@ -Documentation -============= - -Internal Links: - - * [Developer Documentation](dev-docs.md) - * [Supported SQL Queries](syntax-support.md) - * [Known Limitations & Missing Features](known-limitations.md) - - -External Resources: - - * [Original Dev-Paper (2015)](http://torpedro.com/paper/HyriseSQL-03-2015.pdf) - * [Blog Post about Basic Usage](http://torpedro.github.io/tech/c++/sql/parser/2016/02/27/c++-sql-parser.html) - - diff --git a/cpp/sql-parser/docs/dev-docs.md b/cpp/sql-parser/docs/dev-docs.md deleted file mode 100644 index 1d7aa6c94..000000000 --- a/cpp/sql-parser/docs/dev-docs.md +++ /dev/null @@ -1,63 +0,0 @@ -Developer Documentation -======================= - -## Basic Requirements - -**Requirements for development:** - * gcc 4.8+ (or clang 3.4+) - * [bison](https://www.gnu.org/software/bison/) (v3.0.2+) - * [flex](http://flex.sourceforge.net/) (v2.5.5+) - -First step to extending this parser is cloning the repository `git clone git@github.com:hyrise/sql-parser.git` and making sure everything works by running the following steps: - -```bash -make parser # builds the bison parser and flex lexer -make library # builds the libsqlparser.so -make test # runs the tests with the library -``` - -Rerun these steps whenever you change part of the parse. To execute the entire pipeline automatically you can run: - -```bash -make cleanall # cleans the parser build and library build -make test # build parser, library and runs the tests -``` - - -## Developing New Functionality - -This section contains information about how to extend this parser with new functionalities. - - -### Implementing a new Statement - -Create a new file and class in `src/sql/` or extend any of the existing Statements. Every statement needs to have the base class SQLStatement and needs to call its super constructor with its type. If your defining a new statement type, you need to define a new StatementType in `SQLStatement.h`. - -It is important that you create an appropriate constructor for your statement that zero-initializes all its pointer variables and that your create an appropriate destructor. - -Finally you will need to include your new file in `src/sql/statements.h`. - - -### Extending the Grammar - -Related files: -``` -src/parser/bison_parser.y -src/parser/flex_lexer.l -src/parser/keywordlist_generator.py -src/parser/sql_keywords.txt -``` - -To extend the grammar the file you will mostly have to deal with is the bison grammar definition in `src/parser/bison_parser.y`. - -If your extending an existing statement, skip to the non-terminal definition for that statement. I.e. for an InsertStatement the non-terminal insert_statement. - -If your defining a new statement, you will need to define your type in the \%union directive `hsql::ExampleStatement example_stmt`. Next you need to associate this type with a non-terminal `\%type example_statement`. Then you have to define the non-terminal `example_statement`. Look the other non-terminals for statements to figure out how. - - - -## Implementing Tests - -All test related files are in `test/`. Take a look to see how tests are implemented. - - diff --git a/cpp/sql-parser/docs/known-limitations.md b/cpp/sql-parser/docs/known-limitations.md deleted file mode 100644 index 0c91b044a..000000000 --- a/cpp/sql-parser/docs/known-limitations.md +++ /dev/null @@ -1,18 +0,0 @@ -Known Limitations & Missing Features -==================================== - -This page contains an overview of known missing limitations and missing features in our SQL parser project. In general, we would like to see all of these features being supported at some point. If you are particularly interested in a specific feature, feel free to contribute to this project through a pull request. - -### Completely Missing Statement Types - - * EXPLAIN - * EXPORT - * RENAME - * ALTER - -Additionally, there are a lot of statement types that are specific to certain database systems. Supporting all of these is not on our roadmap, but if someone implements support for such a statement, we can also integrate it. - -### Other SQL Limitations - - * Tables names ignore the schema name (see grammar rule `table_name`). This affects, for example, `INSERT, IMPORT, DROP, DELETE`. - * Column data types only support `INT, DOUBLE, TEXT`. diff --git a/cpp/sql-parser/docs/syntax-support.md b/cpp/sql-parser/docs/syntax-support.md deleted file mode 100644 index 59d08b940..000000000 --- a/cpp/sql-parser/docs/syntax-support.md +++ /dev/null @@ -1,53 +0,0 @@ -Supported SQL Queries -===================== - -This page contains a short list of queries that can be correctly parsed with our parser. If you are interested in finding out if a certain feature is supported, it is probably the easiest to checkout the repository and try the example project or check our [list of known limitations](known-limitations.md). Also the file [queries-good.sql](../test/queries/queries-good.sql) shows a list of queries which are parsable with the current version. - - -## Select Statements - -We implement a broad support for the most common elements for `SELECT` statements. Following are a few examples of basic constructs that are supported. - -```sql -SELECT name, city, * - FROM students AS t1 JOIN students AS t2 ON t1.city = t2.city - WHERE t1.grade < 2.0 AND - t2.grade > 2.0 AND - t1.city = 'Frohnau' - ORDER BY t1.grade DESC; - -SELECT city, AVG(grade) AS average, - MIN(grade) AS best, MAX(grade) AS worst - FROM students - GROUP BY city; -``` - -## Data Definition & Modification - -**Create Tables** -```sql -CREATE TABLE students ( - name TEXT, - student_number INTEGER, - city TEXT, - grade DOUBLE -); -``` - -**Update and Delete** -```sql -UPDATE students SET name='Max Mustermann' WHERE name = 'Ralf Mustermann'; - -DELETE FROM students WHERE name = 'Max Mustermann'; -``` - - -## Prepared Statements - -The definition and execution of prepared statements is supported using the following syntax. - -```sql -PREPARE select_test FROM 'SELECT * FROM customer WHERE c_name = ?;'; - -EXECUTE select_test('Max Mustermann'); -``` diff --git a/cpp/sql-parser/example/.gitignore b/cpp/sql-parser/example/.gitignore deleted file mode 100644 index 96236f815..000000000 --- a/cpp/sql-parser/example/.gitignore +++ /dev/null @@ -1 +0,0 @@ -example \ No newline at end of file diff --git a/cpp/sql-parser/example/Makefile b/cpp/sql-parser/example/Makefile deleted file mode 100644 index 387b553ef..000000000 --- a/cpp/sql-parser/example/Makefile +++ /dev/null @@ -1,6 +0,0 @@ - -CFLAGS = -std=c++1z -lstdc++ -Wall -Werror -I../src/ -L../ - -all: - $(CXX) $(CFLAGS) example.cpp -o example -lsqlparser - diff --git a/cpp/sql-parser/example/example.cpp b/cpp/sql-parser/example/example.cpp deleted file mode 100644 index 943de4b25..000000000 --- a/cpp/sql-parser/example/example.cpp +++ /dev/null @@ -1,41 +0,0 @@ - -#include -#include - -// include the sql parser -#include "SQLParser.h" - -// contains printing utilities -#include "util/sqlhelper.h" - -int main(int argc, char* argv[]) { - if (argc <= 1) { - fprintf(stderr, "Usage: ./example \"SELECT * FROM test;\"\n"); - return -1; - } - std::string query = argv[1]; - - // parse a given query - hsql::SQLParserResult result; - hsql::SQLParser::parse(query, &result); - - // check whether the parsing was successful - - if (result.isValid()) { - printf("Parsed successfully!\n"); - printf("Number of statements: %lu\n", result.size()); - - for (auto i = 0u; i < result.size(); ++i) { - // Print a statement summary. - hsql::printStatementInfo(result.getStatement(i)); - } - return 0; - } else { - fprintf(stderr, "Given string is not a valid SQL query.\n"); - fprintf(stderr, "%s (L%d:%d)\n", - result.errorMsg(), - result.errorLine(), - result.errorColumn()); - return -1; - } -} diff --git a/cpp/sql-parser/src/SQLParser.cpp b/cpp/sql-parser/src/SQLParser.cpp deleted file mode 100644 index 930f8d393..000000000 --- a/cpp/sql-parser/src/SQLParser.cpp +++ /dev/null @@ -1,80 +0,0 @@ - -#include "SQLParser.h" -#include "parser/bison_parser.h" -#include "parser/flex_lexer.h" -#include -#include - -namespace hsql { - - SQLParser::SQLParser() { - fprintf(stderr, "SQLParser only has static methods atm! Do not initialize!\n"); - } - - // static - bool SQLParser::parse(const std::string& sql, SQLParserResult* result) { - yyscan_t scanner; - YY_BUFFER_STATE state; - - if (hsql_lex_init(&scanner)) { - // Couldn't initialize the lexer. - fprintf(stderr, "SQLParser: Error when initializing lexer!\n"); - return false; - } - const char* text = sql.c_str(); - state = hsql__scan_string(text, scanner); - - // Parse the tokens. - // If parsing fails, the result will contain an error object. - int ret = hsql_parse(result, scanner); - bool success = (ret == 0); - result->setIsValid(success); - - hsql__delete_buffer(state, scanner); - hsql_lex_destroy(scanner); - - return true; - } - - // static - bool SQLParser::parseSQLString(const char* sql, SQLParserResult* result) { - return parse(sql, result); - } - - bool SQLParser::parseSQLString(const std::string& sql, SQLParserResult* result) { - return parse(sql, result); - } - - // static - bool SQLParser::tokenize(const std::string& sql, std::vector* tokens) { - // Initialize the scanner. - yyscan_t scanner; - if (hsql_lex_init(&scanner)) { - fprintf(stderr, "SQLParser: Error when initializing lexer!\n"); - return false; - } - - YY_BUFFER_STATE state; - state = hsql__scan_string(sql.c_str(), scanner); - - YYSTYPE yylval; - YYLTYPE yylloc; - - // Step through the string until EOF is read. - // Note: hsql_lex returns int, but we know that its range is within 16 bit. - int16_t token = hsql_lex(&yylval, &yylloc, scanner); - while (token != 0) { - tokens->push_back(token); - token = hsql_lex(&yylval, &yylloc, scanner); - - if (token == SQL_IDENTIFIER || token == SQL_STRING) { - free(yylval.sval); - } - } - - hsql__delete_buffer(state, scanner); - hsql_lex_destroy(scanner); - return true; - } - -} // namespace hsql diff --git a/cpp/sql-parser/src/SQLParser.h b/cpp/sql-parser/src/SQLParser.h deleted file mode 100644 index 244bf3a0a..000000000 --- a/cpp/sql-parser/src/SQLParser.h +++ /dev/null @@ -1,38 +0,0 @@ -#ifndef __SQLPARSER__SQLPARSER_H__ -#define __SQLPARSER__SQLPARSER_H__ - -#include "SQLParserResult.h" -#include "sql/statements.h" - -namespace hsql { - - // Static methods used to parse SQL strings. - class SQLParser { - public: - - // Parses a given constant character SQL string into the result object. - // Returns true if the lexer and parser could run without internal errors. - // This does NOT mean that the SQL string was valid SQL. To check that - // you need to check result->isValid(); - static bool parse(const std::string& sql, SQLParserResult* result); - - // Run tokenization on the given string and store the tokens in the output vector. - static bool tokenize(const std::string& sql, std::vector* tokens); - - // Deprecated. - // Old method to parse SQL strings. Replaced by parse(). - static bool parseSQLString(const char* sql, SQLParserResult* result); - - // Deprecated. - // Old method to parse SQL strings. Replaced by parse(). - static bool parseSQLString(const std::string& sql, SQLParserResult* result); - - private: - SQLParser(); - }; - - -} // namespace hsql - - -#endif \ No newline at end of file diff --git a/cpp/sql-parser/src/SQLParserResult.cpp b/cpp/sql-parser/src/SQLParserResult.cpp deleted file mode 100644 index 47a5300c1..000000000 --- a/cpp/sql-parser/src/SQLParserResult.cpp +++ /dev/null @@ -1,112 +0,0 @@ - -#include "SQLParserResult.h" -#include - -namespace hsql { - - SQLParserResult::SQLParserResult() : - isValid_(false), - errorMsg_(nullptr) {}; - - SQLParserResult::SQLParserResult(SQLStatement* stmt) : - isValid_(false), - errorMsg_(nullptr) { - addStatement(stmt); - }; - - // Move constructor. - SQLParserResult::SQLParserResult(SQLParserResult&& moved) { - isValid_ = moved.isValid_; - errorMsg_ = moved.errorMsg_; - statements_ = std::move(moved.statements_); - - moved.errorMsg_ = nullptr; - moved.reset(); - } - - SQLParserResult::~SQLParserResult() { - reset(); - } - - void SQLParserResult::addStatement(SQLStatement* stmt) { - statements_.push_back(stmt); - } - - const SQLStatement* SQLParserResult::getStatement(int index) const { - return statements_[index]; - } - - SQLStatement* SQLParserResult::getMutableStatement(int index) { - return statements_[index]; - } - - size_t SQLParserResult::size() const { - return statements_.size(); - } - - bool SQLParserResult::isValid() const { - return isValid_; - } - - const char* SQLParserResult::errorMsg() const { - return errorMsg_; - } - - int SQLParserResult::errorLine() const { - return errorLine_; - } - - int SQLParserResult::errorColumn() const { - return errorColumn_; - } - - void SQLParserResult::setIsValid(bool isValid) { - isValid_ = isValid; - } - - void SQLParserResult::setErrorDetails(char* errorMsg, int errorLine, int errorColumn) { - errorMsg_ = errorMsg; - errorLine_ = errorLine; - errorColumn_ = errorColumn; - } - - const std::vector& SQLParserResult::getStatements() const { - return statements_; - } - - std::vector SQLParserResult::releaseStatements() { - std::vector copy = statements_; - - statements_.clear(); - - return copy; - } - - void SQLParserResult::reset() { - for (SQLStatement* statement : statements_) { - delete statement; - } - statements_.clear(); - - isValid_ = false; - - free(errorMsg_); - errorMsg_ = nullptr; - errorLine_ = -1; - errorColumn_ = -1; - } - - // Does NOT take ownership. - void SQLParserResult::addParameter(Expr* parameter) { - parameters_.push_back(parameter); - std::sort(parameters_.begin(), parameters_.end(), - [](const Expr * a, const Expr * b) { - return a->ival < b->ival; - }); - } - - const std::vector& SQLParserResult::parameters() { - return parameters_; - } - -} // namespace hsql diff --git a/cpp/sql-parser/src/SQLParserResult.h b/cpp/sql-parser/src/SQLParserResult.h deleted file mode 100644 index 66b78a877..000000000 --- a/cpp/sql-parser/src/SQLParserResult.h +++ /dev/null @@ -1,93 +0,0 @@ -#ifndef __SQLPARSER__SQLPARSER_RESULT_H__ -#define __SQLPARSER__SQLPARSER_RESULT_H__ - -#include "sql/SQLStatement.h" - -namespace hsql { - // Represents the result of the SQLParser. - // If parsing was successful it contains a list of SQLStatement. - class SQLParserResult { - public: - // Initialize with empty statement list. - SQLParserResult(); - - // Initialize with a single statement. - // Takes ownership of the statement. - SQLParserResult(SQLStatement* stmt); - - // Move constructor. - SQLParserResult(SQLParserResult&& moved); - - // Deletes all statements in the result. - virtual ~SQLParserResult(); - - // Set whether parsing was successful. - void setIsValid(bool isValid); - - // Returns true if parsing was successful. - bool isValid() const; - - // Returns the number of statements in the result. - size_t size() const; - - // Set the details of the error, if available. - // Takes ownership of errorMsg. - void setErrorDetails(char* errorMsg, int errorLine, int errorColumn); - - // Returns the error message, if an error occurred. - const char* errorMsg() const; - - // Returns the line number of the occurrance of the error in the query. - int errorLine() const; - - // Returns the column number of the occurrance of the error in the query. - int errorColumn() const; - - // Adds a statement to the result list of statements. - // SQLParserResult takes ownership of the statement. - void addStatement(SQLStatement* stmt); - - // Gets the SQL statement with the given index. - const SQLStatement* getStatement(int index) const; - - // Gets the non const SQL statement with the given index. - SQLStatement* getMutableStatement(int index); - - // Get the list of all statements. - const std::vector& getStatements() const; - - // Returns a copy of the list of all statements in this result. - // Removes them from this result. - std::vector releaseStatements(); - - // Deletes all statements and other data within the result. - void reset(); - - // Does NOT take ownership. - void addParameter(Expr* parameter); - - const std::vector& parameters(); - - private: - // List of statements within the result. - std::vector statements_; - - // Flag indicating the parsing was successful. - bool isValid_; - - // Error message, if an error occurred. - char* errorMsg_; - - // Line number of the occurrance of the error in the query. - int errorLine_; - - // Column number of the occurrance of the error in the query. - int errorColumn_; - - // Does NOT have ownership. - std::vector parameters_; - }; - -} // namespace hsql - -#endif // __SQLPARSER__SQLPARSER_RESULT_H__ \ No newline at end of file diff --git a/cpp/sql-parser/src/parser/.gitignore b/cpp/sql-parser/src/parser/.gitignore deleted file mode 100644 index 7524c5d8b..000000000 --- a/cpp/sql-parser/src/parser/.gitignore +++ /dev/null @@ -1,6 +0,0 @@ -*.output -conflict_test.cpp -bison_parser.cpp -bison_parser.h -flex_lexer.cpp -flex_lexer.h \ No newline at end of file diff --git a/cpp/sql-parser/src/parser/Makefile b/cpp/sql-parser/src/parser/Makefile deleted file mode 100644 index d8482b9fc..000000000 --- a/cpp/sql-parser/src/parser/Makefile +++ /dev/null @@ -1,17 +0,0 @@ - -all: bison_parser.cpp flex_lexer.cpp - -bison_parser.cpp: bison_parser.y - @bison --version | head -n 1 - bison bison_parser.y --output=bison_parser.cpp --defines=bison_parser.h --verbose - -flex_lexer.cpp: flex_lexer.l - @flex --version - flex flex_lexer.l - -clean: - rm -f bison_parser.cpp flex_lexer.cpp bison_parser.h flex_lexer.h *.output - -# Tests if the parser builds correctly and doesn't contain conflicts. -test: - ! bison bison_parser.y -v --output=conflict_test.cpp 2>&1 | grep "conflict" >&2 diff --git a/cpp/sql-parser/src/parser/bison_parser.y b/cpp/sql-parser/src/parser/bison_parser.y deleted file mode 100644 index 2ebdac436..000000000 --- a/cpp/sql-parser/src/parser/bison_parser.y +++ /dev/null @@ -1,1020 +0,0 @@ -%{ -/** - * bison_parser.y - * defines bison_parser.h - * outputs bison_parser.c - * - * Grammar File Spec: http://dinosaur.compilertools.net/bison/bison_6.html - * - */ -/********************************* - ** Section 1: C Declarations - *********************************/ - -#include "bison_parser.h" -#include "flex_lexer.h" - -#include -#include - -using namespace hsql; - -int yyerror(YYLTYPE* llocp, SQLParserResult* result, yyscan_t scanner, const char *msg) { - result->setIsValid(false); - result->setErrorDetails(strdup(msg), llocp->first_line, llocp->first_column); - return 0; -} - -%} -/********************************* - ** Section 2: Bison Parser Declarations - *********************************/ - - -// Specify code that is included in the generated .h and .c files -%code requires { -// %code requires block - -#include "../sql/statements.h" -#include "../SQLParserResult.h" -#include "parser_typedef.h" - -// Auto update column and line number -#define YY_USER_ACTION \ - yylloc->first_line = yylloc->last_line; \ - yylloc->first_column = yylloc->last_column; \ - for(int i = 0; yytext[i] != '\0'; i++) { \ - yylloc->total_column++; \ - if(yytext[i] == '\n') { \ - yylloc->last_line++; \ - yylloc->last_column = 0; \ - } \ - else { \ - yylloc->last_column++; \ - } \ - } -} - -// Define the names of the created files (defined in Makefile) -// %output "bison_parser.cpp" -// %defines "bison_parser.h" - -// Tell bison to create a reentrant parser -%define api.pure full - -// Prefix the parser -%define api.prefix {hsql_} -%define api.token.prefix {SQL_} - -%define parse.error verbose -%locations - -%initial-action { - // Initialize - @$.first_column = 0; - @$.last_column = 0; - @$.first_line = 0; - @$.last_line = 0; - @$.total_column = 0; -}; - - -// Define additional parameters for yylex (http://www.gnu.org/software/bison/manual/html_node/Pure-Calling.html) -%lex-param { yyscan_t scanner } - -// Define additional parameters for yyparse -%parse-param { hsql::SQLParserResult* result } -%parse-param { yyscan_t scanner } - - -/********************************* - ** Define all data-types (http://www.gnu.org/software/bison/manual/html_node/Union-Decl.html) - *********************************/ -%union { - double fval; - int64_t ival; - char* sval; - uintmax_t uval; - bool bval; - - hsql::SQLStatement* statement; - hsql::SelectStatement* select_stmt; - hsql::ImportStatement* import_stmt; - hsql::CreateStatement* create_stmt; - hsql::InsertStatement* insert_stmt; - hsql::DeleteStatement* delete_stmt; - hsql::UpdateStatement* update_stmt; - hsql::DropStatement* drop_stmt; - hsql::PrepareStatement* prep_stmt; - hsql::ExecuteStatement* exec_stmt; - hsql::ShowStatement* show_stmt; - - hsql::TableRef* table; - hsql::Expr* expr; - hsql::OrderDescription* order; - hsql::OrderType order_type; - hsql::LimitDescription* limit; - hsql::ColumnDefinition* column_t; - hsql::GroupByDescription* group_t; - hsql::UpdateClause* update_t; - - std::vector* stmt_vec; - - std::vector* str_vec; - std::vector* table_vec; - std::vector* column_vec; - std::vector* update_vec; - std::vector* expr_vec; - std::vector* order_vec; -} - - -/********************************* - ** Descrutor symbols - *********************************/ -%destructor { } -%destructor { free( ($$) ); } -%destructor { - if (($$) != nullptr) { - for (auto ptr : *($$)) { - delete ptr; - } - } - delete ($$); -} -%destructor { delete ($$); } <*> - - -/********************************* - ** Token Definition - *********************************/ -%token IDENTIFIER STRING -%token FLOATVAL -%token INTVAL - -/* SQL Keywords */ -%token DEALLOCATE PARAMETERS INTERSECT TEMPORARY TIMESTAMP -%token DISTINCT NVARCHAR RESTRICT TRUNCATE ANALYZE BETWEEN -%token CASCADE COLUMNS COMPARE CONTROL DEFAULT EXECUTE -%token EXPLAIN HISTORY INTEGER NATURAL PREPARE PRIMARY -%token SCHEMAS SPATIAL VIRTUAL BEFORE COLUMN CREATE DELETE -%token DIRECT DOUBLE ESCAPE EXCEPT EXISTS GLOBAL HAVING -%token IMPORT INSERT ISNULL OFFSET RENAME SCHEMA SELECT -%token SORTED TABLES UNIQUE UNLOAD UPDATE VALUES AFTER ALTER -%token ARRAY COMBO CROSS DELTA GROUP INDEX INNER LIMIT LOCAL -%token MERGE MINUS ORDER OUTER RIGHT TABLE UNION USING WHERE -%token CALL CASE DATE DESC DIFF DROP ELSE FILE FROM FULL -%token HASH HINT INTO JOIN LEFT LIKE LOAD NULL PART PLAN -%token SHOW TEXT THEN TIME VIEW WHEN WITH ADD ALL AND ASC -%token CSV END FOR INT KEY MAX NOT OFF SET TBL TOP AS BY IF -%token IN IS OF ON OR TO - -/********************************* - ** Non-Terminal types (http://www.gnu.org/software/bison/manual/html_node/Type-Decl.html) - *********************************/ -%type statement_list -%type statement preparable_statement -%type execute_statement -%type prepare_statement -%type select_statement select_with_paren select_no_paren select_clause select_paren_or_clause -%type import_statement -%type create_statement -%type insert_statement -%type delete_statement truncate_statement -%type update_statement -%type drop_statement -%type show_statement -%type table_name opt_alias alias file_path prepare_target_query -%type opt_not_exists opt_distinct -%type import_file_type opt_join_type column_type -%type from_clause table_ref table_ref_diff table_ref_atomic table_ref_name nonjoin_table_ref_atomic -%type
join_clause table_ref_name_no_alias -%type expr operand scalar_expr unary_expr binary_expr logic_expr exists_expr -%type function_expr between_expr expr_alias param_expr opt_max_combo -%type column_name literal int_literal num_literal string_literal -%type comp_expr opt_where join_condition opt_having case_expr in_expr hint -%type array_expr array_index null_literal -%type opt_limit opt_top -%type order_desc -%type opt_order_type -%type column_def -%type update_clause -%type opt_group - -%type ident_commalist opt_column_list -%type expr_list select_list literal_list hint_list opt_hints -%type table_ref_commalist -%type opt_order order_list -%type update_clause_commalist -%type column_def_commalist - -/****************************** - ** Token Precedence and Associativity - ** Precedence: lowest to highest - ******************************/ -%left OR -%left AND -%right NOT -%nonassoc '=' EQUALS NOTEQUALS LIKE ILIKE -%nonassoc '<' '>' LESS GREATER LESSEQ GREATEREQ - -%nonassoc NOTNULL -%nonassoc ISNULL -%nonassoc IS /* sets precedence for IS NULL, etc */ -%left '+' '-' -%left '*' '/' '%' -%left '^' -%left CONCAT - -/* Unary Operators */ -%right UMINUS -%left '[' ']' -%left '(' ')' -%left '.' -%left JOIN -%% -/********************************* - ** Section 3: Grammar Definition - *********************************/ - -// Defines our general input. -input: - statement_list opt_semicolon { - for (SQLStatement* stmt : *$1) { - // Transfers ownership of the statement. - result->addStatement(stmt); - } - - unsigned param_id = 0; - for (void* param : yyloc.param_list) { - if (param != nullptr) { - Expr* expr = (Expr*) param; - expr->ival = param_id; - result->addParameter(expr); - ++param_id; - } - } - delete $1; - } - ; - - -statement_list: - statement { $$ = new std::vector(); $$->push_back($1); } - | statement_list ';' statement { $1->push_back($3); $$ = $1; } - ; - -statement: - prepare_statement opt_hints { - $$ = $1; - $$->hints = $2; - } - | preparable_statement opt_hints { - $$ = $1; - $$->hints = $2; - } - | show_statement { - $$ = $1; - } - ; - - -preparable_statement: - select_statement { $$ = $1; } - | import_statement { $$ = $1; } - | create_statement { $$ = $1; } - | insert_statement { $$ = $1; } - | delete_statement { $$ = $1; } - | truncate_statement { $$ = $1; } - | update_statement { $$ = $1; } - | drop_statement { $$ = $1; } - | execute_statement { $$ = $1; } - ; - - -/****************************** - * Hints - ******************************/ - -opt_hints: - WITH HINT '(' hint_list ')' { $$ = $4; } - | /* empty */ { $$ = nullptr; } - ; - - -hint_list: - hint { $$ = new std::vector(); $$->push_back($1); } - | hint_list ',' hint { $1->push_back($3); $$ = $1; } - ; - -hint: - IDENTIFIER { - $$ = Expr::make(kExprHint); - $$->name = $1; - } - | IDENTIFIER '(' literal_list ')' { - $$ = Expr::make(kExprHint); - $$->name = $1; - $$->exprList = $3; - } - ; - - -/****************************** - * Prepared Statement - ******************************/ -prepare_statement: - PREPARE IDENTIFIER FROM prepare_target_query { - $$ = new PrepareStatement(); - $$->name = $2; - $$->query = $4; - } - ; - -prepare_target_query: STRING - -execute_statement: - EXECUTE IDENTIFIER { - $$ = new ExecuteStatement(); - $$->name = $2; - } - | EXECUTE IDENTIFIER '(' literal_list ')' { - $$ = new ExecuteStatement(); - $$->name = $2; - $$->parameters = $4; - } - ; - - -/****************************** - * Import Statement - ******************************/ -import_statement: - IMPORT FROM import_file_type FILE file_path INTO table_name { - $$ = new ImportStatement((ImportType) $3); - $$->filePath = $5; - $$->tableName = $7; - } - ; - -import_file_type: - CSV { $$ = kImportCSV; } - ; - -file_path: - string_literal { $$ = strdup($1->name); delete $1; } - ; - - -/****************************** - * Show Statement - * SHOW TABLES; - ******************************/ - -show_statement: - SHOW TABLES { - $$ = new ShowStatement(kShowTables); - } - | SHOW COLUMNS table_name { - $$ = new ShowStatement(kShowColumns); - $$->name = $3; - } - ; - - -/****************************** - * Create Statement - * CREATE TABLE students (name TEXT, student_number INTEGER, city TEXT, grade DOUBLE) - * CREATE TABLE students FROM TBL FILE 'test/students.tbl' - ******************************/ -create_statement: - CREATE TABLE opt_not_exists table_name FROM TBL FILE file_path { - $$ = new CreateStatement(kCreateTableFromTbl); - $$->ifNotExists = $3; - $$->tableName = $4; - $$->filePath = $8; - } - | CREATE TABLE opt_not_exists table_name '(' column_def_commalist ')' { - $$ = new CreateStatement(kCreateTable); - $$->ifNotExists = $3; - $$->tableName = $4; - $$->columns = $6; - } - | CREATE VIEW opt_not_exists table_name opt_column_list AS select_statement { - $$ = new CreateStatement(kCreateView); - $$->ifNotExists = $3; - $$->tableName = $4; - $$->viewColumns = $5; - $$->select = $7; - } - ; - -opt_not_exists: - IF NOT EXISTS { $$ = true; } - | /* empty */ { $$ = false; } - ; - -column_def_commalist: - column_def { $$ = new std::vector(); $$->push_back($1); } - | column_def_commalist ',' column_def { $1->push_back($3); $$ = $1; } - ; - -column_def: - IDENTIFIER column_type { - $$ = new ColumnDefinition($1, (ColumnDefinition::DataType) $2); - } - ; - - -column_type: - INT { $$ = ColumnDefinition::INT; } - | INTEGER { $$ = ColumnDefinition::INT; } - | DOUBLE { $$ = ColumnDefinition::DOUBLE; } - | TEXT { $$ = ColumnDefinition::TEXT; } - ; - -/****************************** - * Drop Statement - * DROP TABLE students; - * DEALLOCATE PREPARE stmt; - ******************************/ - -drop_statement: - DROP TABLE table_name { - $$ = new DropStatement(kDropTable); - $$->name = $3; - } - | DROP VIEW table_name { - $$ = new DropStatement(kDropView); - $$->name = $3; - } - | DEALLOCATE PREPARE IDENTIFIER { - $$ = new DropStatement(kDropPreparedStatement); - $$->name = $3; - } - ; - -/****************************** - * Delete Statement / Truncate statement - * DELETE FROM students WHERE grade > 3.0 - * DELETE FROM students <=> TRUNCATE students - ******************************/ -delete_statement: - DELETE FROM table_name opt_where { - $$ = new DeleteStatement(); - $$->tableName = $3; - $$->expr = $4; - } - ; - -truncate_statement: - TRUNCATE table_name { - $$ = new DeleteStatement(); - $$->tableName = $2; - } - ; - -/****************************** - * Insert Statement - * INSERT INTO students VALUES ('Max', 1112233, 'Musterhausen', 2.3) - * INSERT INTO employees SELECT * FROM students - ******************************/ -insert_statement: - INSERT INTO table_name opt_column_list VALUES '(' literal_list ')' { - $$ = new InsertStatement(kInsertValues); - $$->tableName = $3; - $$->columns = $4; - $$->values = $7; - } - | INSERT INTO table_name opt_column_list select_no_paren { - $$ = new InsertStatement(kInsertSelect); - $$->tableName = $3; - $$->columns = $4; - $$->select = $5; - } - ; - - -opt_column_list: - '(' ident_commalist ')' { $$ = $2; } - | /* empty */ { $$ = nullptr; } - ; - - -/****************************** - * Update Statement - * UPDATE students SET grade = 1.3, name='Felix Fürstenberg' WHERE name = 'Max Mustermann'; - ******************************/ - -update_statement: - UPDATE table_ref_name_no_alias SET update_clause_commalist opt_where { - $$ = new UpdateStatement(); - $$->table = $2; - $$->updates = $4; - $$->where = $5; - } - ; - -update_clause_commalist: - update_clause { $$ = new std::vector(); $$->push_back($1); } - | update_clause_commalist ',' update_clause { $1->push_back($3); $$ = $1; } - ; - -update_clause: - IDENTIFIER '=' expr { - $$ = new UpdateClause(); - $$->column = $1; - $$->value = $3; - } - ; - -/****************************** - * Select Statement - ******************************/ - -select_statement: - select_with_paren - | select_no_paren - | select_with_paren set_operator select_paren_or_clause opt_order opt_limit { - // TODO: allow multiple unions (through linked list) - // TODO: capture type of set_operator - // TODO: might overwrite order and limit of first select here - $$ = $1; - $$->unionSelect = $3; - $$->order = $4; - - // Limit could have been set by TOP. - if ($5 != nullptr) { - delete $$->limit; - $$->limit = $5; - } - } - ; - -select_with_paren: - '(' select_no_paren ')' { $$ = $2; } - | '(' select_with_paren ')' { $$ = $2; } - ; - -select_paren_or_clause: - select_with_paren - | select_clause - ; - -select_no_paren: - select_clause opt_order opt_limit { - $$ = $1; - $$->order = $2; - - // Limit could have been set by TOP. - if ($3 != nullptr) { - delete $$->limit; - $$->limit = $3; - } - } - | select_clause set_operator select_paren_or_clause opt_order opt_limit { - // TODO: allow multiple unions (through linked list) - // TODO: capture type of set_operator - // TODO: might overwrite order and limit of first select here - $$ = $1; - $$->unionSelect = $3; - $$->order = $4; - - // Limit could have been set by TOP. - if ($5 != nullptr) { - delete $$->limit; - $$->limit = $5; - } - } - ; - -set_operator: - set_type opt_all - ; - -set_type: - UNION - | INTERSECT - | EXCEPT - ; - -opt_all: - ALL - | /* empty */ - ; - -select_clause: - SELECT opt_top opt_distinct select_list from_clause opt_where opt_group { - $$ = new SelectStatement(); - $$->limit = $2; - $$->selectDistinct = $3; - $$->selectList = $4; - $$->fromTable = $5; - $$->whereClause = $6; - $$->groupBy = $7; - } - ; - -opt_distinct: - DISTINCT { $$ = true; } - | /* empty */ { $$ = false; } - ; - -select_list: - expr_list - ; - -from_clause: - FROM table_ref { $$ = $2; } - ; - - -opt_where: - WHERE expr { $$ = $2; } - | /* empty */ { $$ = nullptr; } - ; - -opt_group: - GROUP BY expr_list opt_having { - $$ = new GroupByDescription(); - $$->columns = $3; - $$->having = $4; - } - | /* empty */ { $$ = nullptr; } - ; - -opt_having: - HAVING expr { $$ = $2; } - | /* empty */ { $$ = nullptr; } - -opt_order: - ORDER BY order_list { $$ = $3; } - | /* empty */ { $$ = nullptr; } - ; - -order_list: - order_desc { $$ = new std::vector(); $$->push_back($1); } - | order_list ',' order_desc { $1->push_back($3); $$ = $1; } - ; - -order_desc: - expr opt_order_type { $$ = new OrderDescription($2, $1); } - ; - -opt_order_type: - ASC { $$ = kOrderAsc; } - | DESC { $$ = kOrderDesc; } - | /* empty */ { $$ = kOrderAsc; } - ; - -// TODO: TOP and LIMIT can take more than just int literals. - -opt_top: - TOP int_literal { $$ = new LimitDescription($2->ival, kNoOffset); delete $2; } - | /* empty */ { $$ = nullptr; } - ; - -opt_limit: - LIMIT int_literal { $$ = new LimitDescription($2->ival, kNoOffset); delete $2; } - | LIMIT int_literal OFFSET int_literal { $$ = new LimitDescription($2->ival, $4->ival); delete $2; delete $4; } - | /* empty */ { $$ = nullptr; } - ; - -/****************************** - * Expressions - ******************************/ -expr_list: - expr_alias { $$ = new std::vector(); $$->push_back($1); } - | expr_list ',' expr_alias { $1->push_back($3); $$ = $1; } - ; - -literal_list: - literal { $$ = new std::vector(); $$->push_back($1); } - | literal_list ',' literal { $1->push_back($3); $$ = $1; } - ; - -expr_alias: - expr opt_alias { - $$ = $1; - $$->alias = $2; - } - ; - -expr: - operand - | between_expr - | logic_expr - | exists_expr - | in_expr - ; - -operand: - '(' expr ')' { $$ = $2; } - | array_index - | scalar_expr - | unary_expr - | binary_expr - | case_expr - | function_expr - | array_expr - | '(' select_no_paren ')' { $$ = Expr::makeSelect($2); } - ; - -scalar_expr: - column_name - | literal - ; - -unary_expr: - '-' operand { $$ = Expr::makeOpUnary(kOpUnaryMinus, $2); } - | NOT operand { $$ = Expr::makeOpUnary(kOpNot, $2); } - | operand ISNULL { $$ = Expr::makeOpUnary(kOpIsNull, $1); } - | operand IS NULL { $$ = Expr::makeOpUnary(kOpIsNull, $1); } - | operand IS NOT NULL { $$ = Expr::makeOpUnary(kOpNot, Expr::makeOpUnary(kOpIsNull, $1)); } - ; - -binary_expr: - comp_expr - | operand '-' operand { $$ = Expr::makeOpBinary($1, kOpMinus, $3); } - | operand '+' operand { $$ = Expr::makeOpBinary($1, kOpPlus, $3); } - | operand '/' operand { $$ = Expr::makeOpBinary($1, kOpSlash, $3); } - | operand '*' operand { $$ = Expr::makeOpBinary($1, kOpAsterisk, $3); } - | operand '%' operand { $$ = Expr::makeOpBinary($1, kOpPercentage, $3); } - | operand '^' operand { $$ = Expr::makeOpBinary($1, kOpCaret, $3); } - | operand LIKE operand { $$ = Expr::makeOpBinary($1, kOpLike, $3); } - | operand NOT LIKE operand { $$ = Expr::makeOpBinary($1, kOpNotLike, $4); } - | operand ILIKE operand { $$ = Expr::makeOpBinary($1, kOpILike, $3); } - | operand CONCAT operand { $$ = Expr::makeOpBinary($1, kOpConcat, $3); } - ; - -logic_expr: - expr AND expr { $$ = Expr::makeOpBinary($1, kOpAnd, $3); } - | expr OR expr { $$ = Expr::makeOpBinary($1, kOpOr, $3); } - ; - -in_expr: - operand IN '(' expr_list ')' { $$ = Expr::makeInOperator($1, $4); } - | operand NOT IN '(' expr_list ')' { $$ = Expr::makeOpUnary(kOpNot, Expr::makeInOperator($1, $5)); } - | operand IN '(' select_no_paren ')' { $$ = Expr::makeInOperator($1, $4); } - | operand NOT IN '(' select_no_paren ')' { $$ = Expr::makeOpUnary(kOpNot, Expr::makeInOperator($1, $5)); } - ; - -// TODO: allow no else specified -case_expr: - CASE WHEN expr THEN operand END { $$ = Expr::makeCase($3, $5); } - | - CASE WHEN expr THEN operand ELSE operand END { $$ = Expr::makeCase($3, $5, $7); } - ; - -exists_expr: - EXISTS '(' select_no_paren ')' { $$ = Expr::makeExists($3); } - | NOT EXISTS '(' select_no_paren ')' { $$ = Expr::makeOpUnary(kOpNot, Expr::makeExists($4)); } - ; - -comp_expr: - operand '=' operand { $$ = Expr::makeOpBinary($1, kOpEquals, $3); } - | operand NOTEQUALS operand { $$ = Expr::makeOpBinary($1, kOpNotEquals, $3); } - | operand '<' operand { $$ = Expr::makeOpBinary($1, kOpLess, $3); } - | operand '>' operand { $$ = Expr::makeOpBinary($1, kOpGreater, $3); } - | operand LESSEQ operand { $$ = Expr::makeOpBinary($1, kOpLessEq, $3); } - | operand GREATEREQ operand { $$ = Expr::makeOpBinary($1, kOpGreaterEq, $3); } - ; - -function_expr: - IDENTIFIER '(' ')' { $$ = Expr::makeFunctionRef($1, new std::vector(), false); } - | IDENTIFIER '(' opt_distinct expr_list ')' { $$ = Expr::makeFunctionRef($1, $4, $3); } - ; - -array_expr: - ARRAY '[' expr_list ']' { $$ = Expr::makeArray($3); } - ; - -array_index: - operand '[' int_literal ']' { $$ = Expr::makeArrayIndex($1, $3->ival); } - ; - -between_expr: - operand BETWEEN operand AND operand { $$ = Expr::makeBetween($1, $3, $5); } - ; - -column_name: - IDENTIFIER { $$ = Expr::makeColumnRef($1); } - | IDENTIFIER '.' IDENTIFIER { $$ = Expr::makeColumnRef($1, $3); } - | '*' { $$ = Expr::makeStar(); } - | IDENTIFIER '.' '*' { $$ = Expr::makeStar($1); } - ; - -literal: - string_literal - | num_literal - | null_literal - | param_expr - ; - -string_literal: - STRING { $$ = Expr::makeLiteral($1); } - ; - - -num_literal: - FLOATVAL { $$ = Expr::makeLiteral($1); } - | int_literal - ; - -int_literal: - INTVAL { $$ = Expr::makeLiteral($1); } - ; - -null_literal: - NULL { $$ = Expr::makeNullLiteral(); } - ; - -param_expr: - '?' { - $$ = Expr::makeParameter(yylloc.total_column); - $$->ival2 = yyloc.param_list.size(); - yyloc.param_list.push_back($$); - } - ; - - -/****************************** - * Table - ******************************/ -table_ref: - table_ref_diff - | table_ref_atomic - | table_ref_atomic ',' table_ref_commalist { - $3->push_back($1); - auto tbl = new TableRef(kTableCrossProduct); - tbl->list = $3; - $$ = tbl; - } - ; - -/****************************** - * Macrodiff definition - ******************************/ -table_ref_diff: - /* two relations */ - DIFF table_ref_atomic ',' table_ref_atomic ON expr_list COMPARE BY function_expr opt_max_combo { - $$ = new TableRef(kTableDiff); - $$->diff = new DiffDefinition(); - $$->diff->first = $2; - $$->diff->second = $4; - $$->diff->attribute_cols = $6; - $$->diff->compare_by = $9; - $$->diff->max_combo = $10; - } - /* one relation */ - | DIFF table_ref_atomic ON expr_list COMPARE BY function_expr opt_max_combo { - $$ = new TableRef(kTableDiff); - $$->diff = new DiffDefinition(); - $$->diff->first = $2; - $$->diff->second = nullptr; - $$->diff->attribute_cols = $4; - $$->diff->compare_by = $7; - $$->diff->max_combo = $8; - } - ; - -opt_max_combo: - MAX COMBO int_literal { $$ = $3; } - | /* empty */ { $$ = Expr::makeLiteral((int64_t) 3); } - ; - -table_ref_atomic: - nonjoin_table_ref_atomic - | join_clause - ; - -nonjoin_table_ref_atomic: - table_ref_name - | '(' select_statement ')' opt_alias { - auto tbl = new TableRef(kTableSelect); - tbl->select = $2; - tbl->alias = $4; - $$ = tbl; - } - ; - -table_ref_commalist: - table_ref_atomic { $$ = new std::vector(); $$->push_back($1); } - | table_ref_commalist ',' table_ref_atomic { $1->push_back($3); $$ = $1; } - ; - - -table_ref_name: - table_name opt_alias { - auto tbl = new TableRef(kTableName); - tbl->name = $1; - tbl->alias = $2; - $$ = tbl; - } - ; - - -table_ref_name_no_alias: - table_name { - $$ = new TableRef(kTableName); - $$->name = $1; - } - ; - - -table_name: - IDENTIFIER - | IDENTIFIER '.' IDENTIFIER { $$ = $3; } - ; - - -alias: - AS IDENTIFIER { $$ = $2; } - | IDENTIFIER - ; - -opt_alias: - alias - | /* empty */ { $$ = nullptr; } - - -/****************************** - * Join Statements - ******************************/ - -join_clause: - table_ref_atomic NATURAL JOIN nonjoin_table_ref_atomic - { - $$ = new TableRef(kTableJoin); - $$->join = new JoinDefinition(); - $$->join->type = kJoinNatural; - $$->join->left = $1; - $$->join->right = $4; - } - | table_ref_atomic opt_join_type JOIN table_ref_atomic ON join_condition - { - $$ = new TableRef(kTableJoin); - $$->join = new JoinDefinition(); - $$->join->type = (JoinType) $2; - $$->join->left = $1; - $$->join->right = $4; - $$->join->condition = $6; - } - | - table_ref_atomic opt_join_type JOIN table_ref_atomic USING '(' column_name ')' - { - $$ = new TableRef(kTableJoin); - $$->join = new JoinDefinition(); - $$->join->type = (JoinType) $2; - $$->join->left = $1; - $$->join->right = $4; - auto left_col = Expr::makeColumnRef(strdup($7->name)); - if ($7->alias != nullptr) left_col->alias = strdup($7->alias); - if ($1->getName() != nullptr) left_col->table = strdup($1->getName()); - auto right_col = Expr::makeColumnRef(strdup($7->name)); - if ($7->alias != nullptr) right_col->alias = strdup($7->alias); - if ($4->getName() != nullptr) right_col->table = strdup($4->getName()); - $$->join->condition = Expr::makeOpBinary(left_col, kOpEquals, right_col); - delete $7; - } - ; - -opt_join_type: - INNER { $$ = kJoinInner; } - | OUTER { $$ = kJoinOuter; } - | LEFT OUTER { $$ = kJoinLeftOuter; } - | RIGHT OUTER { $$ = kJoinRightOuter; } - | LEFT { $$ = kJoinLeft; } - | RIGHT { $$ = kJoinRight; } - | CROSS { $$ = kJoinCross; } - | /* empty, default */ { $$ = kJoinInner; } - ; - - -join_condition: - expr - ; - - -/****************************** - * Misc - ******************************/ - -opt_semicolon: - ';' - | /* empty */ - ; - - -ident_commalist: - IDENTIFIER { $$ = new std::vector(); $$->push_back($1); } - | ident_commalist ',' IDENTIFIER { $1->push_back($3); $$ = $1; } - ; - -%% -/********************************* - ** Section 4: Additional C code - *********************************/ - -/* empty */ - diff --git a/cpp/sql-parser/src/parser/flex_lexer.l b/cpp/sql-parser/src/parser/flex_lexer.l deleted file mode 100644 index 86fb5a5ed..000000000 --- a/cpp/sql-parser/src/parser/flex_lexer.l +++ /dev/null @@ -1,227 +0,0 @@ -/** - * lexer - * - * - */ - - -/*************************** - ** Section 1: Definitions - ***************************/ -%{ - -#include "../sql/Expr.h" -#include "bison_parser.h" -#include - -#define TOKEN(name) { return SQL_##name; } - -%} -/*************************** - ** Section 2: Rules - ***************************/ - -/* Define the output files */ -%option header-file="flex_lexer.h" -%option outfile="flex_lexer.cpp" - -/* Make reentrant */ -%option reentrant -%option bison-bridge - -/* performance tweeks */ -%option never-interactive -%option batch - -/* other flags */ -%option noyywrap -%option nounput -%option warn -%option case-insensitive -%option prefix="hsql_" -%option bison-locations -/* %option nodefault */ - - -%s COMMENT - -/*************************** - ** Section 3: Rules - ***************************/ -%% - --- BEGIN(COMMENT); -[^\n]* /* skipping comment content until a end of line is read */; -\n BEGIN(INITIAL); - -[ \t\n]+ /* skip whitespace */; - -DEALLOCATE TOKEN(DEALLOCATE) -PARAMETERS TOKEN(PARAMETERS) -INTERSECT TOKEN(INTERSECT) -TEMPORARY TOKEN(TEMPORARY) -TIMESTAMP TOKEN(TIMESTAMP) -DISTINCT TOKEN(DISTINCT) -NVARCHAR TOKEN(NVARCHAR) -RESTRICT TOKEN(RESTRICT) -TRUNCATE TOKEN(TRUNCATE) -ANALYZE TOKEN(ANALYZE) -BETWEEN TOKEN(BETWEEN) -CASCADE TOKEN(CASCADE) -COLUMNS TOKEN(COLUMNS) -COMPARE TOKEN(COMPARE) -CONTROL TOKEN(CONTROL) -DEFAULT TOKEN(DEFAULT) -EXECUTE TOKEN(EXECUTE) -EXPLAIN TOKEN(EXPLAIN) -HISTORY TOKEN(HISTORY) -INTEGER TOKEN(INTEGER) -NATURAL TOKEN(NATURAL) -PREPARE TOKEN(PREPARE) -PRIMARY TOKEN(PRIMARY) -SCHEMAS TOKEN(SCHEMAS) -SPATIAL TOKEN(SPATIAL) -VIRTUAL TOKEN(VIRTUAL) -BEFORE TOKEN(BEFORE) -COLUMN TOKEN(COLUMN) -CREATE TOKEN(CREATE) -DELETE TOKEN(DELETE) -DIRECT TOKEN(DIRECT) -DOUBLE TOKEN(DOUBLE) -ESCAPE TOKEN(ESCAPE) -EXCEPT TOKEN(EXCEPT) -EXISTS TOKEN(EXISTS) -GLOBAL TOKEN(GLOBAL) -HAVING TOKEN(HAVING) -IMPORT TOKEN(IMPORT) -INSERT TOKEN(INSERT) -ISNULL TOKEN(ISNULL) -OFFSET TOKEN(OFFSET) -RENAME TOKEN(RENAME) -SCHEMA TOKEN(SCHEMA) -SELECT TOKEN(SELECT) -SORTED TOKEN(SORTED) -TABLES TOKEN(TABLES) -UNIQUE TOKEN(UNIQUE) -UNLOAD TOKEN(UNLOAD) -UPDATE TOKEN(UPDATE) -VALUES TOKEN(VALUES) -AFTER TOKEN(AFTER) -ALTER TOKEN(ALTER) -ARRAY TOKEN(ARRAY) -COMBO TOKEN(COMBO) -CROSS TOKEN(CROSS) -DELTA TOKEN(DELTA) -GROUP TOKEN(GROUP) -INDEX TOKEN(INDEX) -INNER TOKEN(INNER) -LIMIT TOKEN(LIMIT) -LOCAL TOKEN(LOCAL) -MERGE TOKEN(MERGE) -MINUS TOKEN(MINUS) -ORDER TOKEN(ORDER) -OUTER TOKEN(OUTER) -RIGHT TOKEN(RIGHT) -TABLE TOKEN(TABLE) -UNION TOKEN(UNION) -USING TOKEN(USING) -WHERE TOKEN(WHERE) -CALL TOKEN(CALL) -CASE TOKEN(CASE) -DATE TOKEN(DATE) -DESC TOKEN(DESC) -DIFF TOKEN(DIFF) -DROP TOKEN(DROP) -ELSE TOKEN(ELSE) -FILE TOKEN(FILE) -FROM TOKEN(FROM) -FULL TOKEN(FULL) -HASH TOKEN(HASH) -HINT TOKEN(HINT) -INTO TOKEN(INTO) -JOIN TOKEN(JOIN) -LEFT TOKEN(LEFT) -LIKE TOKEN(LIKE) -LOAD TOKEN(LOAD) -NULL TOKEN(NULL) -PART TOKEN(PART) -PLAN TOKEN(PLAN) -SHOW TOKEN(SHOW) -TEXT TOKEN(TEXT) -THEN TOKEN(THEN) -TIME TOKEN(TIME) -VIEW TOKEN(VIEW) -WHEN TOKEN(WHEN) -WITH TOKEN(WITH) -ADD TOKEN(ADD) -ALL TOKEN(ALL) -AND TOKEN(AND) -ASC TOKEN(ASC) -CSV TOKEN(CSV) -END TOKEN(END) -FOR TOKEN(FOR) -INT TOKEN(INT) -KEY TOKEN(KEY) -MAX TOKEN(MAX) -NOT TOKEN(NOT) -OFF TOKEN(OFF) -SET TOKEN(SET) -TBL TOKEN(TBL) -TOP TOKEN(TOP) -AS TOKEN(AS) -BY TOKEN(BY) -IF TOKEN(IF) -IN TOKEN(IN) -IS TOKEN(IS) -OF TOKEN(OF) -ON TOKEN(ON) -OR TOKEN(OR) -TO TOKEN(TO) - -"!=" TOKEN(NOTEQUALS) -"<>" TOKEN(NOTEQUALS) -"<=" TOKEN(LESSEQ) -">=" TOKEN(GREATEREQ) -"||" TOKEN(CONCAT) - -[-+*/(){},.;<>=^%:?[\]|] { return yytext[0]; } - --?[0-9]+"."[0-9]* | -"."[0-9]* { - yylval->fval = atof(yytext); - return SQL_FLOATVAL; -} - --?[0-9]+ { - yylval->ival = atol(yytext); - return SQL_INTVAL; -} - -\"[^\"\n]+\" { - // Crop the leading and trailing quote char - yylval->sval = hsql::substr(yytext, 1, strlen(yytext)-1); - return SQL_IDENTIFIER; -} - -[A-Za-z][A-Za-z0-9_]* { - yylval->sval = strdup(yytext); - return SQL_IDENTIFIER; -} - -'[^'\n]*' { - // Crop the leading and trailing quote char - yylval->sval = hsql::substr(yytext, 1, strlen(yytext)-1); - return SQL_STRING; -} - -. { fprintf(stderr, "[SQL-Lexer-Error] Unknown Character: %c\n", yytext[0]); return 0; } - - -%% -/*************************** - ** Section 3: User code - ***************************/ - -int yyerror(const char *msg) { - fprintf(stderr, "[SQL-Lexer-Error] %s\n",msg); return 0; -} diff --git a/cpp/sql-parser/src/parser/keywordlist_generator.py b/cpp/sql-parser/src/parser/keywordlist_generator.py deleted file mode 100644 index ae4c0f0af..000000000 --- a/cpp/sql-parser/src/parser/keywordlist_generator.py +++ /dev/null @@ -1,46 +0,0 @@ - -import math - - -with open("sql_keywords.txt", 'r') as fh: - keywords = [line.strip() for line in fh.readlines() if not line.strip().startswith("//") and len(line.strip()) > 0] - - keywords = sorted(set(keywords)) # Sort by name - keywords = sorted(keywords, key=lambda x: len(x), reverse=True) # Sort by length - - ################# - # Flex - - max_len = len(max(keywords, key=lambda x: len(x))) + 1 - max_len = 4 * int(math.ceil(max_len / 4.0)) - - for keyword in keywords: - len_diff = (max_len) - len(keyword) - num_tabs = int(math.floor(len_diff / 4.0)) - - if len_diff % 4 != 0: num_tabs += 1 - - tabs = ''.join(['\t' for _ in range(num_tabs)]) - print "%s%sTOKEN(%s)" % (keyword, tabs, keyword) - - # - ################# - - - ################# - # Bison - line = "%token" - max_len = 60 - - print "/* SQL Keywords */" - for keyword in keywords: - - if len(line + " " + keyword) > max_len: - print line - line = "%token " + keyword - else: - line = line + " " + keyword - print line - - # - ################# \ No newline at end of file diff --git a/cpp/sql-parser/src/parser/parser_typedef.h b/cpp/sql-parser/src/parser/parser_typedef.h deleted file mode 100644 index a16770ed0..000000000 --- a/cpp/sql-parser/src/parser/parser_typedef.h +++ /dev/null @@ -1,33 +0,0 @@ -#ifndef __PARSER_TYPEDEF_H__ -#define __PARSER_TYPEDEF_H__ - -#include - - -#ifndef YYtypeDEF_YY_SCANNER_T -#define YYtypeDEF_YY_SCANNER_T -typedef void* yyscan_t; -#endif - - -#define YYSTYPE HSQL_STYPE -#define YYLTYPE HSQL_LTYPE - - -struct HSQL_CUST_LTYPE { - int first_line; - int first_column; - int last_line; - int last_column; - - int total_column; - - // Parameters. - // int param_id; - std::vector param_list; -}; - -#define HSQL_LTYPE HSQL_CUST_LTYPE -#define HSQL_LTYPE_IS_DECLARED 1 - -#endif \ No newline at end of file diff --git a/cpp/sql-parser/src/sql/CreateStatement.h b/cpp/sql-parser/src/sql/CreateStatement.h deleted file mode 100644 index c34121959..000000000 --- a/cpp/sql-parser/src/sql/CreateStatement.h +++ /dev/null @@ -1,49 +0,0 @@ -#ifndef __SQLPARSER__CREATE_STATEMENT_H__ -#define __SQLPARSER__CREATE_STATEMENT_H__ - -#include "SQLStatement.h" - -// Note: Implementations of constructors and destructors can be found in statements.cpp. -namespace hsql { - struct SelectStatement; - - // Represents definition of a table column - struct ColumnDefinition { - enum DataType { - UNKNOWN, - TEXT, - INT, - DOUBLE - }; - - ColumnDefinition(char* name, DataType type); - virtual ~ColumnDefinition(); - - char* name; - DataType type; - }; - - enum CreateType { - kCreateTable, - kCreateTableFromTbl, // Hyrise file format - kCreateView - }; - - // Represents SQL Create statements. - // Example: "CREATE TABLE students (name TEXT, student_number INTEGER, city TEXT, grade DOUBLE)" - struct CreateStatement : SQLStatement { - CreateStatement(CreateType type); - virtual ~CreateStatement(); - - CreateType type; - bool ifNotExists; // default: false - char* filePath; // default: nullptr - char* tableName; // default: nullptr - std::vector* columns; // default: nullptr - std::vector* viewColumns; - SelectStatement* select; - }; - -} // namespace hsql - -#endif diff --git a/cpp/sql-parser/src/sql/DeleteStatement.h b/cpp/sql-parser/src/sql/DeleteStatement.h deleted file mode 100644 index 2aed8a50e..000000000 --- a/cpp/sql-parser/src/sql/DeleteStatement.h +++ /dev/null @@ -1,22 +0,0 @@ -#ifndef __SQLPARSER__DELETE_STATEMENT_H__ -#define __SQLPARSER__DELETE_STATEMENT_H__ - -#include "SQLStatement.h" - -// Note: Implementations of constructors and destructors can be found in statements.cpp. -namespace hsql { - - // Represents SQL Delete statements. - // Example: "DELETE FROM students WHERE grade > 3.0" - // Note: if (expr == nullptr) => delete all rows (truncate) - struct DeleteStatement : SQLStatement { - DeleteStatement(); - virtual ~DeleteStatement(); - - char* tableName; - Expr* expr; - }; - -} // namespace hsql - -#endif diff --git a/cpp/sql-parser/src/sql/DropStatement.h b/cpp/sql-parser/src/sql/DropStatement.h deleted file mode 100644 index 594446393..000000000 --- a/cpp/sql-parser/src/sql/DropStatement.h +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef __SQLPARSER__DROP_STATEMENT_H__ -#define __SQLPARSER__DROP_STATEMENT_H__ - -#include "SQLStatement.h" - -// Note: Implementations of constructors and destructors can be found in statements.cpp. -namespace hsql { - - enum DropType { - kDropTable, - kDropSchema, - kDropIndex, - kDropView, - kDropPreparedStatement - }; - - // Represents SQL Delete statements. - // Example "DROP TABLE students;" - struct DropStatement : SQLStatement { - - DropStatement(DropType type); - virtual ~DropStatement(); - - DropType type; - char* name; - }; - -} // namespace hsql -#endif \ No newline at end of file diff --git a/cpp/sql-parser/src/sql/ExecuteStatement.h b/cpp/sql-parser/src/sql/ExecuteStatement.h deleted file mode 100644 index 99b87e743..000000000 --- a/cpp/sql-parser/src/sql/ExecuteStatement.h +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef __SQLPARSER__EXECUTE_STATEMENT_H__ -#define __SQLPARSER__EXECUTE_STATEMENT_H__ - -#include "SQLStatement.h" - -namespace hsql { - - // Represents SQL Execute statements. - // Example: "EXECUTE ins_prep(100, "test", 2.3);" - struct ExecuteStatement : SQLStatement { - ExecuteStatement(); - virtual ~ExecuteStatement(); - - char* name; - std::vector* parameters; - }; - -} // namsepace hsql - -#endif diff --git a/cpp/sql-parser/src/sql/Expr.cpp b/cpp/sql-parser/src/sql/Expr.cpp deleted file mode 100644 index ca566ef5b..000000000 --- a/cpp/sql-parser/src/sql/Expr.cpp +++ /dev/null @@ -1,224 +0,0 @@ - -#include "Expr.h" -#include -#include -#include "SelectStatement.h" - -namespace hsql { - - Expr::Expr(ExprType type) - : type(type), - expr(nullptr), - expr2(nullptr), - exprList(nullptr), - select(nullptr), - name(nullptr), - table(nullptr), - alias(nullptr) {}; - - Expr::~Expr() { - delete expr; - delete expr2; - delete select; - free(name); - free(table); - free(alias); - - if (exprList != nullptr) { - for (Expr* e : *exprList) { - delete e; - } - delete exprList; - } - } - - Expr* Expr::make(ExprType type) { - Expr* e = new Expr(type); - return e; - } - - Expr* Expr::makeOpUnary(OperatorType op, Expr* expr) { - Expr* e = new Expr(kExprOperator); - e->opType = op; - e->expr = expr; - e->expr2 = nullptr; - return e; - } - - Expr* Expr::makeOpBinary(Expr* expr1, OperatorType op, Expr* expr2) { - Expr* e = new Expr(kExprOperator); - e->opType = op; - e->expr = expr1; - e->expr2 = expr2; - return e; - } - - Expr* Expr::makeBetween(Expr* expr, Expr* left, Expr* right) { - Expr* e = new Expr(kExprOperator); - e->expr = expr; - e->opType = kOpBetween; - e->exprList = new std::vector(); - e->exprList->push_back(left); - e->exprList->push_back(right); - return e; - } - - Expr* Expr::makeCase(Expr* expr, Expr* then) { - Expr* e = new Expr(kExprOperator); - e->expr = expr; - e->opType = kOpCase; - e->exprList = new std::vector(); - e->exprList->push_back(then); - return e; - } - - Expr* Expr::makeCase(Expr* expr, Expr* then, Expr* other) { - Expr* e = new Expr(kExprOperator); - e->expr = expr; - e->opType = kOpCase; - e->exprList = new std::vector(); - e->exprList->push_back(then); - e->exprList->push_back(other); - return e; - } - - Expr* Expr::makeLiteral(int64_t val) { - Expr* e = new Expr(kExprLiteralInt); - e->ival = val; - return e; - } - - Expr* Expr::makeLiteral(double value) { - Expr* e = new Expr(kExprLiteralFloat); - e->fval = value; - return e; - } - - Expr* Expr::makeLiteral(char* string) { - Expr* e = new Expr(kExprLiteralString); - e->name = string; - return e; - } - - Expr* Expr::makeNullLiteral() { - Expr* e = new Expr(kExprLiteralNull); - return e; - } - - Expr* Expr::makeColumnRef(char* name) { - Expr* e = new Expr(kExprColumnRef); - e->name = name; - return e; - } - - Expr* Expr::makeColumnRef(char* table, char* name) { - Expr* e = new Expr(kExprColumnRef); - e->name = name; - e->table = table; - return e; - } - - Expr* Expr::makeStar(void) { - Expr* e = new Expr(kExprStar); - return e; - } - - Expr* Expr::makeStar(char* table) { - Expr* e = new Expr(kExprStar); - e->table = table; - return e; - } - - Expr* Expr::makeFunctionRef(char* func_name, std::vector* exprList, - bool distinct) { - Expr* e = new Expr(kExprFunctionRef); - e->name = func_name; - e->exprList = exprList; - e->distinct = distinct; - return e; - } - - Expr* Expr::makeArray(std::vector* exprList) { - Expr* e = new Expr(kExprArray); - e->exprList = exprList; - return e; - } - - Expr* Expr::makeArrayIndex(Expr* expr, int64_t index) { - Expr* e = new Expr(kExprArrayIndex); - e->expr = expr; - e->ival = index; - return e; - } - - Expr* Expr::makeParameter(int id) { - Expr* e = new Expr(kExprParameter); - e->ival = id; - return e; - } - - Expr* Expr::makeSelect(SelectStatement* select) { - Expr* e = new Expr(kExprSelect); - e->select = select; - return e; - } - - Expr* Expr::makeExists(SelectStatement* select) { - Expr* e = new Expr(kExprOperator); - e->opType = kOpExists; - e->select = select; - return e; - } - - Expr* Expr::makeInOperator(Expr* expr, std::vector* exprList) { - Expr* e = new Expr(kExprOperator); - e->opType = kOpIn; - e->expr = expr; - e->exprList = exprList; - - return e; - } - - Expr* Expr::makeInOperator(Expr* expr, SelectStatement* select) { - Expr* e = new Expr(kExprOperator); - e->opType = kOpIn; - e->expr = expr; - e->select = select; - - return e; - } - - bool Expr::isType(ExprType exprType) const { - return exprType == type; - } - - bool Expr::isLiteral() const { - return isType(kExprLiteralInt) || isType(kExprLiteralFloat) || - isType(kExprLiteralString) || isType(kExprParameter) || - isType(kExprLiteralNull); - } - - bool Expr::hasAlias() const { - return alias != nullptr; - } - - bool Expr::hasTable() const { - return table != nullptr; - } - - const char* Expr::getName() const { - if (alias != nullptr) - return alias; - else - return name; - } - - char* substr(const char* source, int from, int to) { - int len = to - from; - char* copy = (char*)malloc(len + 1); - ; - strncpy(copy, source + from, len); - copy[len] = '\0'; - return copy; - } -} // namespace hsql diff --git a/cpp/sql-parser/src/sql/Expr.h b/cpp/sql-parser/src/sql/Expr.h deleted file mode 100644 index dcaddee4e..000000000 --- a/cpp/sql-parser/src/sql/Expr.h +++ /dev/null @@ -1,169 +0,0 @@ -#ifndef __SQLPARSER__EXPR_H__ -#define __SQLPARSER__EXPR_H__ - -#include -#include -#include - -namespace hsql { - struct SelectStatement; - -// Helper function used by the lexer. -// TODO: move to more appropriate place. - char* substr(const char* source, int from, int to); - - enum ExprType { - kExprLiteralFloat, - kExprLiteralString, - kExprLiteralInt, - kExprLiteralNull, - kExprStar, - kExprParameter, - kExprColumnRef, - kExprFunctionRef, - kExprOperator, - kExprSelect, - kExprHint, - kExprArray, - kExprArrayIndex - }; - -// Operator types. These are important for expressions of type kExprOperator. - enum OperatorType { - kOpNone, - - // Ternary operators - kOpBetween, - kOpCase, - - // Binary operators. - kOpPlus, - kOpMinus, - kOpAsterisk, - kOpSlash, - kOpPercentage, - kOpCaret, - - kOpEquals, - kOpNotEquals, - kOpLess, - kOpLessEq, - kOpGreater, - kOpGreaterEq, - kOpLike, - kOpNotLike, - kOpILike, - kOpAnd, - kOpOr, - kOpIn, - kOpConcat, - - // Unary operators. - kOpNot, - kOpUnaryMinus, - kOpIsNull, - kOpExists - }; - - typedef struct Expr Expr; - -// Represents SQL expressions (i.e. literals, operators, column_refs). -// TODO: When destructing a placeholder expression, we might need to alter the -// placeholder_list. - struct Expr { - Expr(ExprType type); - virtual ~Expr(); - - ExprType type; - - // TODO: Replace expressions by list. - Expr* expr; - Expr* expr2; - std::vector* exprList; - SelectStatement* select; - char* name; - char* table; - char* alias; - float fval; - int64_t ival; - int64_t ival2; - - OperatorType opType; - bool distinct; - - // Convenience accessor methods. - - bool isType(ExprType exprType) const; - - bool isLiteral() const; - - bool hasAlias() const; - - bool hasTable() const; - - const char* getName() const; - - // Static constructors. - - static Expr* make(ExprType type); - - static Expr* makeOpUnary(OperatorType op, Expr* expr); - - static Expr* makeOpBinary(Expr* expr1, OperatorType op, Expr* expr2); - - static Expr* makeBetween(Expr* expr, Expr* left, Expr* right); - - static Expr* makeCase(Expr* expr, Expr* then); - - static Expr* makeCase(Expr* expr, Expr* then, Expr* other); - - static Expr* makeLiteral(int64_t val); - - static Expr* makeLiteral(double val); - - static Expr* makeLiteral(char* val); - - static Expr* makeNullLiteral(); - - static Expr* makeColumnRef(char* name); - - static Expr* makeColumnRef(char* table, char* name); - - static Expr* makeStar(void); - - static Expr* makeStar(char* table); - - static Expr* makeFunctionRef(char* func_name, std::vector* exprList, - bool distinct); - - static Expr* makeArray(std::vector* exprList); - - static Expr* makeArrayIndex(Expr* expr, int64_t index); - - static Expr* makeParameter(int id); - - static Expr* makeSelect(SelectStatement* select); - - static Expr* makeExists(SelectStatement* select); - - static Expr* makeInOperator(Expr* expr, std::vector* exprList); - - static Expr* makeInOperator(Expr* expr, SelectStatement* select); - }; - -// Zero initializes an Expr object and assigns it to a space in the heap -// For Hyrise we still had to put in the explicit NULL constructor -// http://www.ex-parrot.com/~chris/random/initialise.html -// Unused -#define ALLOC_EXPR(var, type) \ - Expr* var; \ - do { \ - Expr zero = {type}; \ - var = (Expr*)malloc(sizeof *var); \ - *var = zero; \ - } while (0); -#undef ALLOC_EXPR - -} // namespace hsql - -#endif diff --git a/cpp/sql-parser/src/sql/ImportStatement.h b/cpp/sql-parser/src/sql/ImportStatement.h deleted file mode 100644 index 1a63518fe..000000000 --- a/cpp/sql-parser/src/sql/ImportStatement.h +++ /dev/null @@ -1,24 +0,0 @@ -#ifndef __SQLPARSER__IMPORT_STATEMENT_H__ -#define __SQLPARSER__IMPORT_STATEMENT_H__ - -#include "SQLStatement.h" - -namespace hsql { - enum ImportType { - kImportCSV, - kImportTbl, // Hyrise file format - }; - - // Represents SQL Import statements. - struct ImportStatement : SQLStatement { - ImportStatement(ImportType type); - virtual ~ImportStatement(); - - ImportType type; - const char* filePath; - const char* tableName; - }; - -} // namespace hsql - -#endif diff --git a/cpp/sql-parser/src/sql/InsertStatement.h b/cpp/sql-parser/src/sql/InsertStatement.h deleted file mode 100644 index bea006ec2..000000000 --- a/cpp/sql-parser/src/sql/InsertStatement.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef __SQLPARSER__INSERT_STATEMENT_H__ -#define __SQLPARSER__INSERT_STATEMENT_H__ - -#include "SQLStatement.h" -#include "SelectStatement.h" - -namespace hsql { - enum InsertType { - kInsertValues, - kInsertSelect - }; - - // Represents SQL Insert statements. - // Example: "INSERT INTO students VALUES ('Max', 1112233, 'Musterhausen', 2.3)" - struct InsertStatement : SQLStatement { - InsertStatement(InsertType type); - virtual ~InsertStatement(); - - InsertType type; - char* tableName; - std::vector* columns; - std::vector* values; - SelectStatement* select; - }; - -} // namsepace hsql - -#endif diff --git a/cpp/sql-parser/src/sql/PrepareStatement.cpp b/cpp/sql-parser/src/sql/PrepareStatement.cpp deleted file mode 100644 index 6ca272e0b..000000000 --- a/cpp/sql-parser/src/sql/PrepareStatement.cpp +++ /dev/null @@ -1,15 +0,0 @@ - -#include "PrepareStatement.h" - -namespace hsql { - // PrepareStatement - PrepareStatement::PrepareStatement() : - SQLStatement(kStmtPrepare), - name(nullptr), - query(nullptr) {} - - PrepareStatement::~PrepareStatement() { - free(name); - free(query); - } -} // namespace hsql diff --git a/cpp/sql-parser/src/sql/PrepareStatement.h b/cpp/sql-parser/src/sql/PrepareStatement.h deleted file mode 100644 index 4642af97e..000000000 --- a/cpp/sql-parser/src/sql/PrepareStatement.h +++ /dev/null @@ -1,22 +0,0 @@ -#ifndef __SQLPARSER__PREPARE_STATEMENT_H__ -#define __SQLPARSER__PREPARE_STATEMENT_H__ - -#include "SQLStatement.h" - -namespace hsql { - - // Represents SQL Prepare statements. - // Example: PREPARE test FROM 'SELECT * FROM test WHERE a = ?;' - struct PrepareStatement : SQLStatement { - PrepareStatement(); - virtual ~PrepareStatement(); - - char* name; - - // The query that is supposed to be prepared. - char* query; - }; - -} // namsepace hsql - -#endif diff --git a/cpp/sql-parser/src/sql/SQLStatement.cpp b/cpp/sql-parser/src/sql/SQLStatement.cpp deleted file mode 100644 index 2d8252d55..000000000 --- a/cpp/sql-parser/src/sql/SQLStatement.cpp +++ /dev/null @@ -1,32 +0,0 @@ - -#include "SQLStatement.h" - -namespace hsql { - - // SQLStatement - SQLStatement::SQLStatement(StatementType type) : - hints(nullptr), - type_(type) {}; - - SQLStatement::~SQLStatement() { - if (hints != nullptr) { - for (Expr* hint : *hints) { - delete hint; - } - } - delete hints; - } - - StatementType SQLStatement::type() const { - return type_; - } - - bool SQLStatement::isType(StatementType type) const { - return (type_ == type); - } - - bool SQLStatement::is(StatementType type) const { - return isType(type); - } - -} \ No newline at end of file diff --git a/cpp/sql-parser/src/sql/SQLStatement.h b/cpp/sql-parser/src/sql/SQLStatement.h deleted file mode 100644 index db7cbf1d0..000000000 --- a/cpp/sql-parser/src/sql/SQLStatement.h +++ /dev/null @@ -1,49 +0,0 @@ -#ifndef __SQLPARSER__SQLSTATEMENT_H__ -#define __SQLPARSER__SQLSTATEMENT_H__ - -#include - -#include "Expr.h" - -namespace hsql { - enum StatementType { - kStmtError, // unused - kStmtSelect, - kStmtImport, - kStmtInsert, - kStmtUpdate, - kStmtDelete, - kStmtCreate, - kStmtDrop, - kStmtPrepare, - kStmtExecute, - kStmtExport, - kStmtRename, - kStmtAlter, - kStmtShow - }; - - // Base struct for every SQL statement - struct SQLStatement { - - SQLStatement(StatementType type); - - virtual ~SQLStatement(); - - StatementType type() const; - - bool isType(StatementType type) const; - - // Shorthand for isType(type). - bool is(StatementType type) const; - - std::vector* hints; - - private: - StatementType type_; - - }; - -} // namespace hsql - -#endif // __SQLPARSER__SQLSTATEMENT_H__ diff --git a/cpp/sql-parser/src/sql/SelectStatement.h b/cpp/sql-parser/src/sql/SelectStatement.h deleted file mode 100644 index d826db393..000000000 --- a/cpp/sql-parser/src/sql/SelectStatement.h +++ /dev/null @@ -1,63 +0,0 @@ -#ifndef __SQLPARSER__SELECT_STATEMENT_H__ -#define __SQLPARSER__SELECT_STATEMENT_H__ - -#include "SQLStatement.h" -#include "Expr.h" -#include "Table.h" - -namespace hsql { - enum OrderType { - kOrderAsc, - kOrderDesc - }; - - - // Description of the order by clause within a select statement. - struct OrderDescription { - OrderDescription(OrderType type, Expr* expr); - virtual ~OrderDescription(); - - OrderType type; - Expr* expr; - }; - - const int64_t kNoLimit = -1; - const int64_t kNoOffset = -1; - - // Description of the limit clause within a select statement. - struct LimitDescription { - LimitDescription(int64_t limit, int64_t offset); - - int64_t limit; - int64_t offset; - }; - - // Description of the group-by clause within a select statement. - struct GroupByDescription { - GroupByDescription(); - virtual ~GroupByDescription(); - - std::vector* columns; - Expr* having; - }; - - // Representation of a full SQL select statement. - // TODO: add union_order and union_limit. - struct SelectStatement : SQLStatement { - SelectStatement(); - virtual ~SelectStatement(); - - TableRef* fromTable; - bool selectDistinct; - std::vector* selectList; - Expr* whereClause; - GroupByDescription* groupBy; - - SelectStatement* unionSelect; - std::vector* order; - LimitDescription* limit; - }; - -} // namespace hsql - -#endif diff --git a/cpp/sql-parser/src/sql/ShowStatement.h b/cpp/sql-parser/src/sql/ShowStatement.h deleted file mode 100644 index 206a819f0..000000000 --- a/cpp/sql-parser/src/sql/ShowStatement.h +++ /dev/null @@ -1,26 +0,0 @@ -#ifndef __SQLPARSER__SHOW_STATEMENT_H__ -#define __SQLPARSER__SHOW_STATEMENT_H__ - -#include "SQLStatement.h" - -// Note: Implementations of constructors and destructors can be found in statements.cpp. -namespace hsql { - - enum ShowType { - kShowColumns, - kShowTables - }; - - // Represents SQL SHOW statements. - // Example "SHOW TABLES;" - struct ShowStatement : SQLStatement { - - ShowStatement(ShowType type); - virtual ~ShowStatement(); - - ShowType type; - char* name; - }; - -} // namespace hsql -#endif diff --git a/cpp/sql-parser/src/sql/Table.h b/cpp/sql-parser/src/sql/Table.h deleted file mode 100644 index 1fd01b105..000000000 --- a/cpp/sql-parser/src/sql/Table.h +++ /dev/null @@ -1,83 +0,0 @@ -#ifndef __SQLPARSER__TABLEREF_H__ -#define __SQLPARSER__TABLEREF_H__ - -#include "Expr.h" -#include -#include - -namespace hsql { - - struct SelectStatement; - struct JoinDefinition; - struct DiffDefinition; - struct TableRef; - - // Possible table reference types. - enum TableRefType { - kTableDiff, - kTableName, - kTableSelect, - kTableJoin, - kTableCrossProduct - }; - - // Holds reference to tables. Can be either table names or a select statement. - struct TableRef { - TableRef(TableRefType type); - virtual ~TableRef(); - - TableRefType type; - - char* schema; - char* name; - char* alias; - - SelectStatement* select; - std::vector* list; - JoinDefinition* join; - DiffDefinition* diff; - - // Returns true if a schema is set. - bool hasSchema() const; - - // Returns the alias, if it is set. Otherwise the name. - const char* getName() const; - }; - - // Possible types of joins. - enum JoinType { - kJoinInner, - kJoinOuter, - kJoinLeft, - kJoinRight, - kJoinLeftOuter, - kJoinRightOuter, - kJoinCross, - kJoinNatural - }; - - // Definition of a join construct. - struct JoinDefinition { - JoinDefinition(); - virtual ~JoinDefinition(); - - TableRef* left; - TableRef* right; - Expr* condition; - - JoinType type; - }; - - struct DiffDefinition { - DiffDefinition(); - virtual ~DiffDefinition(); - - TableRef* first; - TableRef* second; - std::vector* attribute_cols; - Expr* compare_by; - Expr* max_combo; - }; - -} // namespace hsql -#endif diff --git a/cpp/sql-parser/src/sql/UpdateStatement.h b/cpp/sql-parser/src/sql/UpdateStatement.h deleted file mode 100644 index eb07a6a4b..000000000 --- a/cpp/sql-parser/src/sql/UpdateStatement.h +++ /dev/null @@ -1,27 +0,0 @@ -#ifndef __SQLPARSER__UPDATE_STATEMENT_H__ -#define __SQLPARSER__UPDATE_STATEMENT_H__ - -#include "SQLStatement.h" - -namespace hsql { - - // Represents "column = value" expressions. - struct UpdateClause { - char* column; - Expr* value; - }; - - // Represents SQL Update statements. - struct UpdateStatement : SQLStatement { - UpdateStatement(); - virtual ~UpdateStatement(); - - // TODO: switch to char* instead of TableRef - TableRef* table; - std::vector* updates; - Expr* where; - }; - -} // namsepace hsql - -#endif diff --git a/cpp/sql-parser/src/sql/statements.cpp b/cpp/sql-parser/src/sql/statements.cpp deleted file mode 100644 index d783a39fc..000000000 --- a/cpp/sql-parser/src/sql/statements.cpp +++ /dev/null @@ -1,293 +0,0 @@ - -#include "statements.h" - -namespace hsql { - - // ColumnDefinition - ColumnDefinition::ColumnDefinition(char* name, DataType type) : - name(name), - type(type) {}; - - ColumnDefinition::~ColumnDefinition() { - free(name); - } - - // CreateStatemnet - CreateStatement::CreateStatement(CreateType type) : - SQLStatement(kStmtCreate), - type(type), - ifNotExists(false), - filePath(nullptr), - tableName(nullptr), - columns(nullptr), - viewColumns(nullptr), - select(nullptr) {}; - - CreateStatement::~CreateStatement() { - free(filePath); - free(tableName); - delete select; - - if (columns != nullptr) { - for (ColumnDefinition* def : *columns) { - delete def; - } - delete columns; - } - - if (viewColumns != nullptr) { - for (char* column : *viewColumns) { - free(column); - } - delete viewColumns; - } - } - - // DeleteStatement - DeleteStatement::DeleteStatement() : - SQLStatement(kStmtDelete), - tableName(nullptr), - expr(nullptr) {}; - - DeleteStatement::~DeleteStatement() { - free(tableName); - delete expr; - } - - // DropStatament - DropStatement::DropStatement(DropType type) : - SQLStatement(kStmtDrop), - type(type), - name(nullptr) {} - - DropStatement::~DropStatement() { - free(name); - } - - // ExecuteStatement - ExecuteStatement::ExecuteStatement() : - SQLStatement(kStmtExecute), - name(nullptr), - parameters(nullptr) {} - - ExecuteStatement::~ExecuteStatement() { - free(name); - - if (parameters != nullptr) { - for (Expr* param : *parameters) { - delete param; - } - delete parameters; - } - } - - // ImportStatement - ImportStatement::ImportStatement(ImportType type) : - SQLStatement(kStmtImport), - type(type), - filePath(nullptr), - tableName(nullptr) {}; - - ImportStatement::~ImportStatement() { - delete filePath; - delete tableName; - } - - // InsertStatement - InsertStatement::InsertStatement(InsertType type) : - SQLStatement(kStmtInsert), - type(type), - tableName(nullptr), - columns(nullptr), - values(nullptr), - select(nullptr) {} - - InsertStatement::~InsertStatement() { - free(tableName); - delete select; - - if (columns != nullptr) { - for (char* column : *columns) { - free(column); - } - delete columns; - } - - if (values != nullptr) { - for (Expr* expr : *values) { - delete expr; - } - delete values; - } - } - - // ShowStatament - ShowStatement::ShowStatement(ShowType type) : - SQLStatement(kStmtShow), - type(type), - name(nullptr) {} - - ShowStatement::~ShowStatement() { - free(name); - } - - // SelectStatement.h - - // OrderDescription - OrderDescription::OrderDescription(OrderType type, Expr* expr) : - type(type), - expr(expr) {} - - OrderDescription::~OrderDescription() { - delete expr; - } - - // LimitDescription - LimitDescription::LimitDescription(int64_t limit, int64_t offset) : - limit(limit), - offset(offset) {} - - // GroypByDescription - GroupByDescription::GroupByDescription() : - columns(nullptr), - having(nullptr) {} - - GroupByDescription::~GroupByDescription() { - delete having; - - if (columns != nullptr) { - for (Expr* expr : *columns) { - delete expr; - } - delete columns; - } - } - - // SelectStatement - SelectStatement::SelectStatement() : - SQLStatement(kStmtSelect), - fromTable(nullptr), - selectDistinct(false), - selectList(nullptr), - whereClause(nullptr), - groupBy(nullptr), - unionSelect(nullptr), - order(nullptr), - limit(nullptr) {}; - - SelectStatement::~SelectStatement() { - delete fromTable; - delete whereClause; - delete groupBy; - delete unionSelect; - delete limit; - - // Delete each element in the select list. - if (selectList != nullptr) { - for (Expr* expr : *selectList) { - delete expr; - } - delete selectList; - } - - if (order != nullptr) { - for (OrderDescription* desc : *order) { - delete desc; - } - delete order; - } - } - - // UpdateStatement - UpdateStatement::UpdateStatement() : - SQLStatement(kStmtUpdate), - table(nullptr), - updates(nullptr), - where(nullptr) {} - - UpdateStatement::~UpdateStatement() { - delete table; - delete where; - - if (updates != nullptr) { - for (UpdateClause* update : *updates) { - free(update->column); - delete update->value; - delete update; - } - delete updates; - } - } - - // TableRef - TableRef::TableRef(TableRefType type) : - type(type), - schema(nullptr), - name(nullptr), - alias(nullptr), - select(nullptr), - list(nullptr), - join(nullptr) {} - - TableRef::~TableRef() { - free(schema); - free(name); - free(alias); - - delete select; - delete join; - - if (list != nullptr) { - for (TableRef* table : *list) { - delete table; - } - delete list; - } - } - - bool TableRef::hasSchema() const { - return schema != nullptr; - } - - const char* TableRef::getName() const { - if (alias != nullptr) return alias; - else return name; - } - - // JoinDefinition - JoinDefinition::JoinDefinition() : - left(nullptr), - right(nullptr), - condition(nullptr), - type(kJoinInner) {} - - JoinDefinition::~JoinDefinition() { - delete left; - delete right; - delete condition; - } - - // DiffDefinition - DiffDefinition::DiffDefinition() : - first(nullptr), - second(nullptr), - attribute_cols(nullptr), - compare_by(nullptr), - max_combo(nullptr) {} - - DiffDefinition::~DiffDefinition() { - delete first; - if (second != nullptr) { - delete second; - } - if (attribute_cols != nullptr) { - for (Expr* e : *attribute_cols) { - delete e; - } - delete attribute_cols; - } - delete compare_by; - delete max_combo; - } - -} // namespace hsql diff --git a/cpp/sql-parser/src/sql/statements.h b/cpp/sql-parser/src/sql/statements.h deleted file mode 100644 index 0838256f7..000000000 --- a/cpp/sql-parser/src/sql/statements.h +++ /dev/null @@ -1,15 +0,0 @@ -#ifndef __SQLPARSER__STATEMENTS_H__ -#define __SQLPARSER__STATEMENTS_H__ - -#include "SelectStatement.h" -#include "ImportStatement.h" -#include "CreateStatement.h" -#include "InsertStatement.h" -#include "UpdateStatement.h" -#include "DeleteStatement.h" -#include "DropStatement.h" -#include "PrepareStatement.h" -#include "ExecuteStatement.h" -#include "ShowStatement.h" - -#endif // __SQLPARSER__STATEMENTS_H__ diff --git a/cpp/sql-parser/src/util/sqlhelper.cpp b/cpp/sql-parser/src/util/sqlhelper.cpp deleted file mode 100644 index 5962543fe..000000000 --- a/cpp/sql-parser/src/util/sqlhelper.cpp +++ /dev/null @@ -1,232 +0,0 @@ - -#include "sqlhelper.h" -#include -#include - -namespace hsql { - - void printOperatorExpression(Expr* expr, uintmax_t numIndent); - - std::string indent(uintmax_t numIndent) { - return std::string(numIndent, '\t'); - } - void inprint(int64_t val, uintmax_t numIndent) { - std::cout << indent(numIndent).c_str() << val << " " << std::endl; - } - void inprint(float val, uintmax_t numIndent) { - std::cout << indent(numIndent).c_str() << val << std::endl; - } - void inprint(const char* val, uintmax_t numIndent) { - std::cout << indent(numIndent).c_str() << val << std::endl; - } - void inprint(const char* val, const char* val2, uintmax_t numIndent) { - std::cout << indent(numIndent).c_str() << val << "->" << val2 << std::endl; - } - void inprintC(char val, uintmax_t numIndent) { - std::cout << indent(numIndent).c_str() << val << std::endl; - } - void inprintU(uint64_t val, uintmax_t numIndent) { - std::cout << indent(numIndent).c_str() << val << std::endl; - } - - void printTableRefInfo(TableRef* table, uintmax_t numIndent) { - switch (table->type) { - case kTableName: - inprint(table->name, numIndent); - break; - case kTableSelect: - printSelectStatementInfo(table->select, numIndent); - break; - case kTableJoin: - inprint("Join Table", numIndent); - inprint("Left", numIndent + 1); - printTableRefInfo(table->join->left, numIndent + 2); - inprint("Right", numIndent + 1); - printTableRefInfo(table->join->right, numIndent + 2); - inprint("Join Condition", numIndent + 1); - printExpression(table->join->condition, numIndent + 2); - break; - case kTableCrossProduct: - for (TableRef* tbl : *table->list) printTableRefInfo(tbl, numIndent); - break; - case kTableDiff: - // Print out Macrodiff query - inprint("Diff", numIndent); - inprint("First", numIndent + 1); - printTableRefInfo(table->diff->first, numIndent + 2); - inprint("Second", numIndent + 1); - if (table->diff->second != nullptr) { - printTableRefInfo(table->diff->second, numIndent + 2); - } else { - inprint("None", numIndent + 2); - } - inprint("On:", numIndent + 1); - for (Expr* expr : *table->diff->attribute_cols) - printExpression(expr, numIndent + 2); - inprint("COMPARE BY:", numIndent + 1); - printExpression(table->diff->compare_by, numIndent + 2); - inprint("MAX COMBO:", numIndent + 1); - printExpression(table->diff->max_combo, numIndent + 2); - break; - } - if (table->alias != nullptr) { - inprint("Alias", numIndent + 1); - inprint(table->alias, numIndent + 2); - } - } - - void printOperatorExpression(Expr* expr, uintmax_t numIndent) { - if (expr == nullptr) { - inprint("null", numIndent); - return; - } - - switch (expr->opType) { - case kOpAnd: - inprint("AND", numIndent); - break; - case kOpOr: - inprint("OR", numIndent); - break; - case kOpNot: - inprint("NOT", numIndent); - break; - default: - inprintU(expr->opType, numIndent); - break; - } - printExpression(expr->expr, numIndent + 1); - if (expr->expr2 != nullptr) printExpression(expr->expr2, numIndent + 1); - } - - void printExpression(Expr* expr, uintmax_t numIndent) { - switch (expr->type) { - case kExprStar: - inprint("*", numIndent); - break; - case kExprColumnRef: - inprint(expr->name, numIndent); - break; - // case kExprTableColumnRef: inprint(expr->table, expr->name, numIndent); break; - case kExprLiteralFloat: - inprint(expr->fval, numIndent); - break; - case kExprLiteralInt: - inprint(expr->ival, numIndent); - break; - case kExprLiteralString: - inprint(expr->name, numIndent); - break; - case kExprFunctionRef: - inprint(expr->name, numIndent); - for (Expr* e : *expr->exprList) inprint(e->name, numIndent + 1); - break; - case kExprOperator: - printOperatorExpression(expr, numIndent); - break; - default: - std::cerr << "Unrecognized expression type " << expr->type << std::endl; - return; - } - if (expr->alias != nullptr) { - inprint("Alias", numIndent + 1); - inprint(expr->alias, numIndent + 2); - } - } - - void printSelectStatementInfo(const SelectStatement* stmt, uintmax_t numIndent) { - inprint("SelectStatement", numIndent); - inprint("Fields:", numIndent + 1); - for (Expr* expr : *stmt->selectList) printExpression(expr, numIndent + 2); - - inprint("Sources:", numIndent + 1); - printTableRefInfo(stmt->fromTable, numIndent + 2); - - if (stmt->whereClause != nullptr) { - inprint("Search Conditions:", numIndent + 1); - printExpression(stmt->whereClause, numIndent + 2); - } - - if (stmt->groupBy != nullptr) { - inprint("GroupBy:", numIndent + 1); - for (Expr* expr : *stmt->groupBy->columns) printExpression(expr, numIndent + 2); - if (stmt->groupBy->having != nullptr) { - inprint("Having:", numIndent + 1); - printExpression(stmt->groupBy->having, numIndent + 2); - } - } - - if (stmt->unionSelect != nullptr) { - inprint("Union:", numIndent + 1); - printSelectStatementInfo(stmt->unionSelect, numIndent + 2); - } - - if (stmt->order != nullptr) { - inprint("OrderBy:", numIndent + 1); - printExpression(stmt->order->at(0)->expr, numIndent + 2); - if (stmt->order->at(0)->type == kOrderAsc) inprint("ascending", numIndent + 2); - else inprint("descending", numIndent + 2); - } - - if (stmt->limit != nullptr) { - inprint("Limit:", numIndent + 1); - inprint(stmt->limit->limit, numIndent + 2); - } - } - - - - void printImportStatementInfo(const ImportStatement* stmt, uintmax_t numIndent) { - inprint("ImportStatment", numIndent); - inprint(stmt->filePath, numIndent + 1); - inprint(stmt->tableName, numIndent + 1); - } - - void printCreateStatementInfo(const CreateStatement* stmt, uintmax_t numIndent) { - inprint("CreateStatment", numIndent); - inprint(stmt->tableName, numIndent + 1); - inprint(stmt->filePath, numIndent + 1); - } - - void printInsertStatementInfo(const InsertStatement* stmt, uintmax_t numIndent) { - inprint("InsertStatment", numIndent); - inprint(stmt->tableName, numIndent + 1); - if (stmt->columns != nullptr) { - inprint("Columns", numIndent + 1); - for (char* col_name : *stmt->columns) { - inprint(col_name, numIndent + 2); - } - } - switch (stmt->type) { - case kInsertValues: - inprint("Values", numIndent + 1); - for (Expr* expr : *stmt->values) { - printExpression(expr, numIndent + 2); - } - break; - case kInsertSelect: - printSelectStatementInfo(stmt->select, numIndent + 1); - break; - } - } - - void printStatementInfo(const SQLStatement* stmt) { - switch (stmt->type()) { - case kStmtSelect: - printSelectStatementInfo((const SelectStatement*) stmt, 0); - break; - case kStmtInsert: - printInsertStatementInfo((const InsertStatement*) stmt, 0); - break; - case kStmtCreate: - printCreateStatementInfo((const CreateStatement*) stmt, 0); - break; - case kStmtImport: - printImportStatementInfo((const ImportStatement*) stmt, 0); - break; - default: - break; - } - } - -} // namespace hsql diff --git a/cpp/sql-parser/src/util/sqlhelper.h b/cpp/sql-parser/src/util/sqlhelper.h deleted file mode 100644 index 7c7e811e1..000000000 --- a/cpp/sql-parser/src/util/sqlhelper.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef __SQLPARSER__SQLHELPER_H__ -#define __SQLPARSER__SQLHELPER_H__ - -#include "../sql/statements.h" - -namespace hsql { - - // Prints a summary of the given SQLStatement. - void printStatementInfo(const SQLStatement* stmt); - - // Prints a summary of the given SelectStatement with the given indentation. - void printSelectStatementInfo(const SelectStatement* stmt, uintmax_t num_indent); - - // Prints a summary of the given ImportStatement with the given indentation. - void printImportStatementInfo(const ImportStatement* stmt, uintmax_t num_indent); - - // Prints a summary of the given InsertStatement with the given indentation. - void printInsertStatementInfo(const InsertStatement* stmt, uintmax_t num_indent); - - // Prints a summary of the given CreateStatement with the given indentation. - void printCreateStatementInfo(const CreateStatement* stmt, uintmax_t num_indent); - - // Prints a summary of the given Expression with the given indentation. - void printExpression(Expr* expr, uintmax_t num_indent); - -} // namespace hsql - -#endif diff --git a/cpp/sql-parser/test/auto_query_file_test.cpp b/cpp/sql-parser/test/auto_query_file_test.cpp deleted file mode 100644 index ce18300fd..000000000 --- a/cpp/sql-parser/test/auto_query_file_test.cpp +++ /dev/null @@ -1,98 +0,0 @@ -#include -#include -#include -#include -#include -#include - -#include "thirdparty/microtest/microtest.h" -#include "SQLParser.h" - -// Read all lines from the given file path. Skips comment lines. -std::vector readlines(std::string path); - -// Read the queries from all files that were supplied to the test -// through the -f argument. For all queries it is checked whether they -// can be parsed successfully. -TEST(AutoQueryFileTest) { - const std::vector& args = mt::Runtime::args(); - - std::vector query_files; - - // Parse command line arguments to retrieve query files. - uint i = 1; - for (; i < args.size(); ++i) { - if (args[i] == "-f") { - query_files.push_back(args[++i]); - } - } - - - // Read list of queries from all input files. - std::vector lines; - for (std::string path : query_files) { - std::vector tmp = readlines(path); - lines.insert(lines.end(), tmp.begin(), tmp.end()); - } - - // Execute queries. - size_t num_executed = 0; - size_t num_failed = 0; - for (std::string line : lines) { - bool expected_result = true; - std::string query = line; - - // If a line starts with '!' parsing is expected to fail. - if (query.at(0) == '!') { - expected_result = false; - query = query.substr(1); - } - - // Measuring the parsing time. - std::chrono::time_point start, end; - start = std::chrono::system_clock::now(); - - // Parse the query. - hsql::SQLParserResult result; - hsql::SQLParser::parse(query, &result); - - end = std::chrono::system_clock::now(); - std::chrono::duration elapsed_seconds = end - start; - double us = elapsed_seconds.count() * 1000 * 1000; - - if (expected_result == result.isValid()) { - printf("\033[0;32m{ ok} (%.1fus)\033[0m %s\n", us, line.c_str()); - } else { - printf("\033[0;31m{ failed}\033[0m\n"); - printf("\t\033[0;31m%s (L%d:%d)\n\033[0m", result.errorMsg(), result.errorLine(), result.errorColumn()); - printf("\t%s\n", line.c_str()); - ++num_failed; - } - ++num_executed; - } - - if (num_failed == 0) { - printf("\033[0;32m{ ok} \033[0mAll %lu grammar tests completed successfully!\n", num_executed); - } else { - fprintf(stderr, "\033[0;31m{ failed} \033[0mSome grammar tests failed! %lu out of %lu tests failed!\n", num_failed, num_executed); - } - ASSERT_EQ(num_failed, 0); -} - -std::vector readlines(std::string path) { - std::ifstream infile(path); - std::vector lines; - std::string line; - while (std::getline(infile, line)) { - std::istringstream iss(line); - - // Skip comments. - if (line[0] == '#' || - (line[0] == '-' && line[1] == '-')) { - continue; - } - - lines.push_back(line); - } - return lines; -} diff --git a/cpp/sql-parser/test/diff-queries-bad.sql b/cpp/sql-parser/test/diff-queries-bad.sql deleted file mode 100644 index 60ed7c5ab..000000000 --- a/cpp/sql-parser/test/diff-queries-bad.sql +++ /dev/null @@ -1,7 +0,0 @@ -# This file contains a list of strings that are NOT valid SQL queries. -# Each line contains a single SQL query. -# Each line starts with a '!' char to indicate that parsing should fail. -!SELECT * FROM DIFF t1, t2 ON *; -!SELECT * FROM DIFF t1, t2, t3 ON * COMPARE BY a; -!SELECT * FROM DIFF t1, t2 ON a, b COMPARE BY c ORDER BY a MAX COMBO 4; -!SELECT * FROM DIFF t1, t2 ON * COMPARE BY a; diff --git a/cpp/sql-parser/test/diff-queries-good.sql b/cpp/sql-parser/test/diff-queries-good.sql deleted file mode 100644 index 8b0c2bdd1..000000000 --- a/cpp/sql-parser/test/diff-queries-good.sql +++ /dev/null @@ -1,17 +0,0 @@ -# This file contains a list of strings that are valid SQL queries using the DIFF operator -# Each line contains a single SQL query. -SELECT * FROM DIFF t1 ON * COMPARE BY risk_ratio(a); -SELECT * FROM DIFF t1, t2 ON * COMPARE BY risk_ratio(a); -SELECT * FROM DIFF t1, t2 ON a COMPARE BY risk_ratio(b); -SELECT * FROM DIFF t1, t2 ON a COMPARE BY risk_ratio(COUNT(*)); -SELECT * FROM DIFF t1, t2 ON a, b COMPARE BY risk_ratio(c); -SELECT * FROM DIFF t1, t2 ON a, b COMPARE BY risk_ratio(c) ORDER BY a; -SELECT * FROM DIFF t1, t2 ON a, b COMPARE BY risk_ratio(c) ORDER BY a DESC; -SELECT * FROM DIFF t1, t2 ON a, b COMPARE BY risk_ratio(c) LIMIT 5; -SELECT * FROM DIFF t1, t2 ON a, b COMPARE BY risk_ratio(c) ORDER BY a DESC LIMIT 1; -SELECT * FROM DIFF t1, t2 ON a, b COMPARE BY risk_ratio(c) MAX COMBO 4; -SELECT * FROM DIFF t1, t2 ON a, b COMPARE BY risk_ratio(c) MAX COMBO 4 ORDER BY a; -SELECT * FROM DIFF t1, t2 ON a, b COMPARE BY risk_ratio(c) MAX COMBO 4 ORDER BY a DESC; -SELECT * FROM DIFF t1, t2 ON a, b COMPARE BY risk_ratio(c) MAX COMBO 4 ORDER BY a DESC LIMIT 1; -SELECT * FROM DIFF t1, t2 ON a, b COMPARE BY risk_ratio(COUNT(*)) MAX COMBO 4 WHERE d = 1 ORDER BY a DESC LIMIT 1; -SELECT * FROM DIFF (SELECT * FROM t1) x, (SELECT * FROM t2) y ON a, b, c COMPARE BY risk_ratio(COUNT(distinct d)) MAX COMBO 2; diff --git a/cpp/sql-parser/test/prepare_tests.cpp b/cpp/sql-parser/test/prepare_tests.cpp deleted file mode 100644 index c8302d77b..000000000 --- a/cpp/sql-parser/test/prepare_tests.cpp +++ /dev/null @@ -1,98 +0,0 @@ - -#include "thirdparty/microtest/microtest.h" -#include "sql_asserts.h" -#include "SQLParser.h" - -using hsql::kExprParameter; -using hsql::kExprLiteralInt; - -using hsql::kStmtDrop; -using hsql::kStmtExecute; -using hsql::kStmtInsert; -using hsql::kStmtPrepare; -using hsql::kStmtSelect; - -using hsql::kDropPreparedStatement; - -using hsql::DropStatement; -using hsql::ExecuteStatement; -using hsql::InsertStatement; -using hsql::PrepareStatement; -using hsql::SelectStatement; - - -TEST(PrepareSingleStatementTest) { - TEST_PARSE_SINGLE_SQL( - "PREPARE test FROM 'SELECT * FROM students WHERE grade = ?';", - kStmtPrepare, - PrepareStatement, - result, - prepare); - - ASSERT_STREQ(prepare->name, "test"); - ASSERT_STREQ(prepare->query, "SELECT * FROM students WHERE grade = ?"); - - TEST_PARSE_SINGLE_SQL( - prepare->query, - kStmtSelect, - SelectStatement, - result2, - select); - - ASSERT_EQ(result2.parameters().size(), 1); - ASSERT(select->whereClause->expr2->isType(kExprParameter)) - ASSERT_EQ(select->whereClause->expr2->ival, 0) - -} - -TEST(DeallocatePrepareStatementTest) { - TEST_PARSE_SINGLE_SQL( - "DEALLOCATE PREPARE test;", - kStmtDrop, - DropStatement, - result, - drop); - - ASSERT_EQ(drop->type, kDropPreparedStatement); - ASSERT_STREQ(drop->name, "test"); -} - - -TEST(StatementWithParameters) { - TEST_PARSE_SINGLE_SQL( - "SELECT * FROM test WHERE a = ? AND b = ?", - kStmtSelect, - SelectStatement, - result, - stmt); - - const hsql::Expr* eq1 = stmt->whereClause->expr; - const hsql::Expr* eq2 = stmt->whereClause->expr2; - - ASSERT_EQ(result.parameters().size(), 2); - - ASSERT_EQ(eq1->opType, hsql::kOpEquals) - ASSERT(eq1->expr->isType(hsql::kExprColumnRef)) - ASSERT(eq1->expr2->isType(kExprParameter)) - ASSERT_EQ(eq1->expr2->ival, 0) - ASSERT_EQ(result.parameters()[0], eq1->expr2); - - - ASSERT_EQ(eq2->opType, hsql::kOpEquals) - ASSERT(eq2->expr->isType(hsql::kExprColumnRef)) - ASSERT(eq2->expr2->isType(kExprParameter)) - ASSERT_EQ(eq2->expr2->ival, 1) - ASSERT_EQ(result.parameters()[1], eq2->expr2); -} - -TEST(ExecuteStatementTest) { - TEST_PARSE_SINGLE_SQL( - "EXECUTE test(1, 2);", - kStmtExecute, - ExecuteStatement, - result, - stmt); - - ASSERT_STREQ(stmt->name, "test"); - ASSERT_EQ(stmt->parameters->size(), 2); -} diff --git a/cpp/sql-parser/test/queries/queries-bad.sql b/cpp/sql-parser/test/queries/queries-bad.sql deleted file mode 100644 index 5437c4fa4..000000000 --- a/cpp/sql-parser/test/queries/queries-bad.sql +++ /dev/null @@ -1,12 +0,0 @@ -# This file contains a list of strings that are NOT valid SQL queries. -# Each line contains a single SQL query. -# Each line starts with a '!' char to indicate that parsing should fail. -! -!1 -!gibberish; -!SELECT abc; -!CREATE TABLE "table" FROM TBL FILE 'students.tbl';SELECT 1 -!CREATE TABLE "table" FROM TBL FILE 'students.tbl';1 -!INSERT INTO test_table VALUESd (1, 2, 'test'); -!SELECT * FROM t WHERE a = ? AND b = ?;SELECT 1; -!SHOW COLUMNS; diff --git a/cpp/sql-parser/test/queries/queries-good.sql b/cpp/sql-parser/test/queries/queries-good.sql deleted file mode 100644 index 121f198cf..000000000 --- a/cpp/sql-parser/test/queries/queries-good.sql +++ /dev/null @@ -1,53 +0,0 @@ -# This file contains a list of strings that are valid SQL queries. -# Each line contains a single SQL query. -# SELECT statement -SELECT * FROM orders; -SELECT a FROM foo WHERE a > 12 OR b > 3 AND NOT c LIMIT 10 -SELECT col1 AS myname, col2, 'test' FROM "table", foo AS t WHERE age > 12 AND zipcode = 12345 GROUP BY col1; -SELECT * from "table" JOIN table2 ON a = b WHERE (b OR NOT a) AND a = 12.5 -(SELECT a FROM foo WHERE a > 12 OR b > 3 AND c NOT LIKE 's%' LIMIT 10); -SELECT * FROM "table" LIMIT 10 OFFSET 10; SELECT * FROM second; -SELECT * FROM t1 UNION SELECT * FROM t2 ORDER BY col1; -SELECT * FROM (SELECT * FROM t1); -SELECT * FROM t1 UNION (SELECT * FROM t2 UNION SELECT * FROM t3) ORDER BY col1; -SELECT TOP 10 * FROM t1 ORDER BY col1, col2; -SELECT a, MAX(b), MAX(c, d), CUSTOM(q, UP(r)) AS f FROM t1; -SELECT * FROM t WHERE a BETWEEN 1 and c; -SELECT * FROM t WHERE a = ? AND b = ?; -SELECT City.name, Product.category, SUM(price) FROM fact INNER JOIN City ON fact.city_id = City.id INNER JOIN Product ON fact.product_id = Product.id GROUP BY City.name, Product.category; -# JOIN -SELECT t1.a, t1.b, t2.c FROM "table" AS t1 JOIN (SELECT * FROM foo JOIN bar ON foo.id = bar.id) t2 ON t1.a = t2.b WHERE (t1.b OR NOT t1.a) AND t2.c = 12.5 -SELECT * FROM t1 JOIN t2 ON c1 = c2; -SELECT a, SUM(b) FROM t2 GROUP BY a HAVING SUM(b) > 100; -# CREATE statement -CREATE TABLE "table" FROM TBL FILE 'students.tbl' -CREATE TABLE IF NOT EXISTS "table" FROM TBL FILE 'students.tbl' -CREATE TABLE students (name TEXT, student_number INTEGER, city TEXT, grade DOUBLE) -# Multiple statements -CREATE TABLE "table" FROM TBL FILE 'students.tbl'; SELECT * FROM "table"; -# INSERT -INSERT INTO test_table VALUES (1, 2, 'test'); -INSERT INTO test_table (id, value, name) VALUES (1, 2, 'test'); -INSERT INTO test_table SELECT * FROM students; -# DELETE -DELETE FROM students WHERE grade > 3.0 -DELETE FROM students -TRUNCATE students -# UPDATE -UPDATE students SET grade = 1.3 WHERE name = 'Max Mustermann'; -UPDATE students SET grade = 1.3, name='Felix Fürstenberg' WHERE name = 'Max Mustermann'; -UPDATE students SET grade = 1.0; -# DROP -DROP TABLE students; -# PREPARE -PREPARE prep_inst FROM 'INSERT INTO test VALUES (?, ?, ?)'; -PREPARE prep2 FROM 'INSERT INTO test VALUES (?, 0, 0); INSERT INTO test VALUES (0, ?, 0); INSERT INTO test VALUES (0, 0, ?);'; -EXECUTE prep_inst(1, 2, 3); -EXECUTE prep; -DEALLOCATE PREPARE prep; -# HINTS -SELECT * FROM test WITH HINT(NO_CACHE); -SELECT * FROM test WITH HINT(NO_CACHE, NO_SAMPLING); -SELECT * FROM test WITH HINT(NO_CACHE, SAMPLE_RATE(0.1), OMW(1.0, 'test')); -SHOW TABLES; -SHOW COLUMNS students; diff --git a/cpp/sql-parser/test/queries/tpc-h-01.sql b/cpp/sql-parser/test/queries/tpc-h-01.sql deleted file mode 100644 index 580b3b52c..000000000 --- a/cpp/sql-parser/test/queries/tpc-h-01.sql +++ /dev/null @@ -1,9 +0,0 @@ --- http://www.sqlserver-dba.com/2011/09/this-is-a-followup-on-my-earlier-post-of-sql-server-test-data-generation-testing-tools-i-had-some-requests-for-my-set-up-pr.html -SELECT L_RETURNFLAG, L_LINESTATUS, SUM(L_QUANTITY) AS SUM_QTY, - SUM(L_EXTENDEDPRICE) AS SUM_BASE_PRICE, SUM(L_EXTENDEDPRICE*(1-L_DISCOUNT)) AS SUM_DISC_PRICE, - SUM(L_EXTENDEDPRICE*(1-L_DISCOUNT)*(1+L_TAX)) AS SUM_CHARGE, AVG(L_QUANTITY) AS AVG_QTY, - AVG(L_EXTENDEDPRICE) AS AVG_PRICE, AVG(L_DISCOUNT) AS AVG_DISC, COUNT(*) AS COUNT_ORDER -FROM LINEITEM -WHERE L_SHIPDATE <= dateadd(dd, -90, cast('1998-12-01' as datetime)) -GROUP BY L_RETURNFLAG, L_LINESTATUS -ORDER BY L_RETURNFLAG,L_LINESTATUS \ No newline at end of file diff --git a/cpp/sql-parser/test/queries/tpc-h-02.sql b/cpp/sql-parser/test/queries/tpc-h-02.sql deleted file mode 100644 index 5fd5b504f..000000000 --- a/cpp/sql-parser/test/queries/tpc-h-02.sql +++ /dev/null @@ -1,10 +0,0 @@ --- http://www.sqlserver-dba.com/2011/09/this-is-a-followup-on-my-earlier-post-of-sql-server-test-data-generation-testing-tools-i-had-some-requests-for-my-set-up-pr.html -SELECT TOP 100 S_ACCTBAL, S_NAME, N_NAME, P_PARTKEY, P_MFGR, S_ADDRESS, S_PHONE, S_COMMENT -FROM "PART", SUPPLIER, PARTSUPP, NATION, REGION -WHERE P_PARTKEY = PS_PARTKEY AND S_SUPPKEY = PS_SUPPKEY AND P_SIZE = 15 AND -P_TYPE LIKE '%%BRASS' AND S_NATIONKEY = N_NATIONKEY AND N_REGIONKEY = R_REGIONKEY AND -R_NAME = 'EUROPE' AND -PS_SUPPLYCOST = (SELECT MIN(PS_SUPPLYCOST) FROM PARTSUPP, SUPPLIER, NATION, REGION - WHERE P_PARTKEY = PS_PARTKEY AND S_SUPPKEY = PS_SUPPKEY - AND S_NATIONKEY = N_NATIONKEY AND N_REGIONKEY = R_REGIONKEY AND R_NAME = 'EUROPE') -ORDER BY S_ACCTBAL DESC, N_NAME, S_NAME, P_PARTKEY \ No newline at end of file diff --git a/cpp/sql-parser/test/queries/tpc-h-03.sql b/cpp/sql-parser/test/queries/tpc-h-03.sql deleted file mode 100644 index 5608c1420..000000000 --- a/cpp/sql-parser/test/queries/tpc-h-03.sql +++ /dev/null @@ -1,7 +0,0 @@ --- http://www.sqlserver-dba.com/2011/09/this-is-a-followup-on-my-earlier-post-of-sql-server-test-data-generation-testing-tools-i-had-some-requests-for-my-set-up-pr.html -SELECT TOP 10 L_ORDERKEY, SUM(L_EXTENDEDPRICE*(1-L_DISCOUNT)) AS REVENUE, O_ORDERDATE, O_SHIPPRIORITY -FROM CUSTOMER, ORDERS, LINEITEM -WHERE C_MKTSEGMENT = 'BUILDING' AND C_CUSTKEY = O_CUSTKEY AND L_ORDERKEY = O_ORDERKEY AND -O_ORDERDATE < '1995-03-15' AND L_SHIPDATE > '1995-03-15' -GROUP BY L_ORDERKEY, O_ORDERDATE, O_SHIPPRIORITY -ORDER BY REVENUE DESC, O_ORDERDATE; \ No newline at end of file diff --git a/cpp/sql-parser/test/queries/tpc-h-04.sql b/cpp/sql-parser/test/queries/tpc-h-04.sql deleted file mode 100644 index 3d420b381..000000000 --- a/cpp/sql-parser/test/queries/tpc-h-04.sql +++ /dev/null @@ -1,6 +0,0 @@ --- http://www.sqlserver-dba.com/2011/09/this-is-a-followup-on-my-earlier-post-of-sql-server-test-data-generation-testing-tools-i-had-some-requests-for-my-set-up-pr.html -SELECT O_ORDERPRIORITY, COUNT(*) AS ORDER_COUNT FROM ORDERS -WHERE O_ORDERDATE >= '1993-07-01' AND O_ORDERDATE < dateadd(mm,3, cast('1993-07-01' as datetime)) -AND EXISTS (SELECT * FROM LINEITEM WHERE L_ORDERKEY = O_ORDERKEY AND L_COMMITDATE < L_RECEIPTDATE) -GROUP BY O_ORDERPRIORITY -ORDER BY O_ORDERPRIORITY \ No newline at end of file diff --git a/cpp/sql-parser/test/queries/tpc-h-05.sql b/cpp/sql-parser/test/queries/tpc-h-05.sql deleted file mode 100644 index 95d292328..000000000 --- a/cpp/sql-parser/test/queries/tpc-h-05.sql +++ /dev/null @@ -1,9 +0,0 @@ --- http://www.sqlserver-dba.com/2011/09/this-is-a-followup-on-my-earlier-post-of-sql-server-test-data-generation-testing-tools-i-had-some-requests-for-my-set-up-pr.html -SELECT N_NAME, SUM(L_EXTENDEDPRICE*(1-L_DISCOUNT)) AS REVENUE -FROM CUSTOMER, ORDERS, LINEITEM, SUPPLIER, NATION, REGION -WHERE C_CUSTKEY = O_CUSTKEY AND L_ORDERKEY = O_ORDERKEY AND L_SUPPKEY = S_SUPPKEY -AND C_NATIONKEY = S_NATIONKEY AND S_NATIONKEY = N_NATIONKEY AND N_REGIONKEY = R_REGIONKEY -AND R_NAME = 'ASIA' AND O_ORDERDATE >= '1994-01-01' -AND O_ORDERDATE < DATEADD(YY, 1, cast('1994-01-01' as datetime)) -GROUP BY N_NAME -ORDER BY REVENUE DESC \ No newline at end of file diff --git a/cpp/sql-parser/test/queries/tpc-h-06.sql b/cpp/sql-parser/test/queries/tpc-h-06.sql deleted file mode 100644 index 394bba9f8..000000000 --- a/cpp/sql-parser/test/queries/tpc-h-06.sql +++ /dev/null @@ -1,5 +0,0 @@ --- http://www.sqlserver-dba.com/2011/09/this-is-a-followup-on-my-earlier-post-of-sql-server-test-data-generation-testing-tools-i-had-some-requests-for-my-set-up-pr.html -SELECT SUM(L_EXTENDEDPRICE*L_DISCOUNT) AS REVENUE -FROM LINEITEM -WHERE L_SHIPDATE >= '1994-01-01' AND L_SHIPDATE < dateadd(yy, 1, cast('1994-01-01' as datetime)) -AND L_DISCOUNT BETWEEN .06 - 0.01 AND .06 + 0.01 AND L_QUANTITY < 24 \ No newline at end of file diff --git a/cpp/sql-parser/test/queries/tpc-h-07.sql b/cpp/sql-parser/test/queries/tpc-h-07.sql deleted file mode 100644 index 449cc2609..000000000 --- a/cpp/sql-parser/test/queries/tpc-h-07.sql +++ /dev/null @@ -1,11 +0,0 @@ --- http://www.sqlserver-dba.com/2011/09/this-is-a-followup-on-my-earlier-post-of-sql-server-test-data-generation-testing-tools-i-had-some-requests-for-my-set-up-pr.html -SELECT SUPP_NATION, CUST_NATION, L_YEAR, SUM(VOLUME) AS REVENUE -FROM ( SELECT N1.N_NAME AS SUPP_NATION, N2.N_NAME AS CUST_NATION, datepart(yy, L_SHIPDATE) AS L_YEAR, - L_EXTENDEDPRICE*(1-L_DISCOUNT) AS VOLUME - FROM SUPPLIER, LINEITEM, ORDERS, CUSTOMER, NATION N1, NATION N2 - WHERE S_SUPPKEY = L_SUPPKEY AND O_ORDERKEY = L_ORDERKEY AND C_CUSTKEY = O_CUSTKEY - AND S_NATIONKEY = N1.N_NATIONKEY AND C_NATIONKEY = N2.N_NATIONKEY AND ((N1.N_NAME = 'FRANCE' AND N2.N_NAME = 'GERMANY') OR - (N1.N_NAME = 'GERMANY' AND N2.N_NAME = 'FRANCE')) AND - L_SHIPDATE BETWEEN '1995-01-01' AND '1996-12-31' ) AS SHIPPING -GROUP BY SUPP_NATION, CUST_NATION, L_YEAR -ORDER BY SUPP_NATION, CUST_NATION, L_YEAR \ No newline at end of file diff --git a/cpp/sql-parser/test/queries/tpc-h-08.sql b/cpp/sql-parser/test/queries/tpc-h-08.sql deleted file mode 100644 index 77f8c64a8..000000000 --- a/cpp/sql-parser/test/queries/tpc-h-08.sql +++ /dev/null @@ -1,10 +0,0 @@ --- http://www.sqlserver-dba.com/2011/09/this-is-a-followup-on-my-earlier-post-of-sql-server-test-data-generation-testing-tools-i-had-some-requests-for-my-set-up-pr.html -SELECT O_YEAR, SUM(CASE WHEN NATION = 'BRAZIL' THEN VOLUME ELSE 0 END)/SUM(VOLUME) AS MKT_SHARE -FROM (SELECT datepart(yy,O_ORDERDATE) AS O_YEAR, L_EXTENDEDPRICE*(1-L_DISCOUNT) AS VOLUME, N2.N_NAME AS NATION - FROM "PART", SUPPLIER, LINEITEM, ORDERS, CUSTOMER, NATION N1, NATION N2, REGION - WHERE P_PARTKEY = L_PARTKEY AND S_SUPPKEY = L_SUPPKEY AND L_ORDERKEY = O_ORDERKEY - AND O_CUSTKEY = C_CUSTKEY AND C_NATIONKEY = N1.N_NATIONKEY AND - N1.N_REGIONKEY = R_REGIONKEY AND R_NAME = 'AMERICA' AND S_NATIONKEY = N2.N_NATIONKEY - AND O_ORDERDATE BETWEEN '1995-01-01' AND '1996-12-31' AND P_TYPE= 'ECONOMY ANODIZED STEEL') AS ALL_NATIONS -GROUP BY O_YEAR -ORDER BY O_YEAR \ No newline at end of file diff --git a/cpp/sql-parser/test/queries/tpc-h-09.sql b/cpp/sql-parser/test/queries/tpc-h-09.sql deleted file mode 100644 index bb9fd6f3c..000000000 --- a/cpp/sql-parser/test/queries/tpc-h-09.sql +++ /dev/null @@ -1,10 +0,0 @@ --- http://www.sqlserver-dba.com/2011/09/this-is-a-followup-on-my-earlier-post-of-sql-server-test-data-generation-testing-tools-i-had-some-requests-for-my-set-up-pr.html -SELECT NATION, O_YEAR, SUM(AMOUNT) AS SUM_PROFIT -FROM (SELECT N_NAME AS NATION, datepart(yy, O_ORDERDATE) AS O_YEAR, - L_EXTENDEDPRICE*(1-L_DISCOUNT)-PS_SUPPLYCOST*L_QUANTITY AS AMOUNT - FROM "PART", SUPPLIER, LINEITEM, PARTSUPP, ORDERS, NATION - WHERE S_SUPPKEY = L_SUPPKEY AND PS_SUPPKEY= L_SUPPKEY AND PS_PARTKEY = L_PARTKEY AND - P_PARTKEY= L_PARTKEY AND O_ORDERKEY = L_ORDERKEY AND S_NATIONKEY = N_NATIONKEY AND - P_NAME LIKE '%%green%%') AS PROFIT -GROUP BY NATION, O_YEAR -ORDER BY NATION, O_YEAR DESC \ No newline at end of file diff --git a/cpp/sql-parser/test/queries/tpc-h-10.sql b/cpp/sql-parser/test/queries/tpc-h-10.sql deleted file mode 100644 index 7229b24eb..000000000 --- a/cpp/sql-parser/test/queries/tpc-h-10.sql +++ /dev/null @@ -1,9 +0,0 @@ --- http://www.sqlserver-dba.com/2011/09/this-is-a-followup-on-my-earlier-post-of-sql-server-test-data-generation-testing-tools-i-had-some-requests-for-my-set-up-pr.html -SELECT TOP 20 C_CUSTKEY, C_NAME, SUM(L_EXTENDEDPRICE*(1-L_DISCOUNT)) AS REVENUE, C_ACCTBAL, -N_NAME, C_ADDRESS, C_PHONE, C_COMMENT -FROM CUSTOMER, ORDERS, LINEITEM, NATION -WHERE C_CUSTKEY = O_CUSTKEY AND L_ORDERKEY = O_ORDERKEY AND O_ORDERDATE>= '1993-10-01' AND -O_ORDERDATE < dateadd(mm, 3, cast('1993-10-01' as datetime)) AND -L_RETURNFLAG = 'R' AND C_NATIONKEY = N_NATIONKEY -GROUP BY C_CUSTKEY, C_NAME, C_ACCTBAL, C_PHONE, N_NAME, C_ADDRESS, C_COMMENT -ORDER BY REVENUE DESC \ No newline at end of file diff --git a/cpp/sql-parser/test/queries/tpc-h-11.sql b/cpp/sql-parser/test/queries/tpc-h-11.sql deleted file mode 100644 index 41954bb45..000000000 --- a/cpp/sql-parser/test/queries/tpc-h-11.sql +++ /dev/null @@ -1,10 +0,0 @@ --- http://www.sqlserver-dba.com/2011/09/this-is-a-followup-on-my-earlier-post-of-sql-server-test-data-generation-testing-tools-i-had-some-requests-for-my-set-up-pr.html --- TPC_H Query 11 - Important Stock Identification -SELECT PS_PARTKEY, SUM(PS_SUPPLYCOST*PS_AVAILQTY) AS VALUE -FROM PARTSUPP, SUPPLIER, NATION -WHERE PS_SUPPKEY = S_SUPPKEY AND S_NATIONKEY = N_NATIONKEY AND N_NAME = 'GERMANY' -GROUP BY PS_PARTKEY -HAVING SUM(PS_SUPPLYCOST*PS_AVAILQTY) > (SELECT SUM(PS_SUPPLYCOST*PS_AVAILQTY) * 0.0001000000 - FROM PARTSUPP, SUPPLIER, NATION - WHERE PS_SUPPKEY = S_SUPPKEY AND S_NATIONKEY = N_NATIONKEY AND N_NAME = 'GERMANY') -ORDER BY VALUE DESC; \ No newline at end of file diff --git a/cpp/sql-parser/test/queries/tpc-h-12.sql b/cpp/sql-parser/test/queries/tpc-h-12.sql deleted file mode 100644 index 59a91b056..000000000 --- a/cpp/sql-parser/test/queries/tpc-h-12.sql +++ /dev/null @@ -1,10 +0,0 @@ --- TPC_H Query 12 - Shipping Modes and Order Priority -SELECT L_SHIPMODE, -SUM(CASE WHEN O_ORDERPRIORITY = '1-URGENT' OR O_ORDERPRIORITY = '2-HIGH' THEN 1 ELSE 0 END) AS HIGH_LINE_COUNT, -SUM(CASE WHEN O_ORDERPRIORITY <> '1-URGENT' AND O_ORDERPRIORITY <> '2-HIGH' THEN 1 ELSE 0 END ) AS LOW_LINE_COUNT -FROM ORDERS, LINEITEM -WHERE O_ORDERKEY = L_ORDERKEY AND L_SHIPMODE IN ('MAIL','SHIP') -AND L_COMMITDATE < L_RECEIPTDATE AND L_SHIPDATE < L_COMMITDATE AND L_RECEIPTDATE >= '1994-01-01' -AND L_RECEIPTDATE < dateadd(mm, 1, cast('1995-09-01' as datetime)) -GROUP BY L_SHIPMODE -ORDER BY L_SHIPMODE; \ No newline at end of file diff --git a/cpp/sql-parser/test/queries/tpc-h-13.sql b/cpp/sql-parser/test/queries/tpc-h-13.sql deleted file mode 100644 index dd2614cd8..000000000 --- a/cpp/sql-parser/test/queries/tpc-h-13.sql +++ /dev/null @@ -1,8 +0,0 @@ --- TPC_H Query 13 - Customer Distribution -SELECT C_COUNT, COUNT(*) AS CUSTDIST -FROM (SELECT C_CUSTKEY, COUNT(O_ORDERKEY) - FROM CUSTOMER left outer join ORDERS on C_CUSTKEY = O_CUSTKEY - AND O_COMMENT not like '%%special%%requests%%' - GROUP BY C_CUSTKEY) AS C_ORDERS -GROUP BY C_COUNT -ORDER BY CUSTDIST DESC, C_COUNT DESC; \ No newline at end of file diff --git a/cpp/sql-parser/test/queries/tpc-h-14.sql b/cpp/sql-parser/test/queries/tpc-h-14.sql deleted file mode 100644 index 12fea0def..000000000 --- a/cpp/sql-parser/test/queries/tpc-h-14.sql +++ /dev/null @@ -1,5 +0,0 @@ --- TPC_H Query 14 - Promotion Effect -SELECT 100.00* SUM(CASE WHEN P_TYPE LIKE 'PROMO%%' THEN L_EXTENDEDPRICE*(1-L_DISCOUNT) -ELSE 0 END) / SUM(L_EXTENDEDPRICE*(1-L_DISCOUNT)) AS PROMO_REVENUE -FROM LINEITEM, "PART" -WHERE L_PARTKEY = P_PARTKEY AND L_SHIPDATE >= '1995-09-01' AND L_SHIPDATE < dateadd(mm, 1, '1995-09-01'); \ No newline at end of file diff --git a/cpp/sql-parser/test/queries/tpc-h-15.sql b/cpp/sql-parser/test/queries/tpc-h-15.sql deleted file mode 100644 index 5593df185..000000000 --- a/cpp/sql-parser/test/queries/tpc-h-15.sql +++ /dev/null @@ -1,15 +0,0 @@ --- TPC_H Query 15.1 - Create View for Top Supplier Query -CREATE VIEW REVENUE0 (SUPPLIER_NO, TOTAL_REVENUE) AS -SELECT L_SUPPKEY, SUM(L_EXTENDEDPRICE*(1-L_DISCOUNT)) FROM LINEITEM -WHERE L_SHIPDATE >= '1996-01-01' AND L_SHIPDATE < dateadd(mm, 3, cast('1996-01-01' as datetime)) -GROUP BY L_SUPPKEY; - - --- TPC_H Query 15.2 - Top Supplier -SELECT S_SUPPKEY, S_NAME, S_ADDRESS, S_PHONE, TOTAL_REVENUE -FROM SUPPLIER, REVENUE0 -WHERE S_SUPPKEY = SUPPLIER_NO AND TOTAL_REVENUE = (SELECT MAX(TOTAL_REVENUE) FROM REVENUE0) -ORDER BY S_SUPPKEY; - --- TPC_H Query 15.3 - Drop View -DROP VIEW REVENUE0; \ No newline at end of file diff --git a/cpp/sql-parser/test/queries/tpc-h-16.sql b/cpp/sql-parser/test/queries/tpc-h-16.sql deleted file mode 100644 index 7bf0bbc1d..000000000 --- a/cpp/sql-parser/test/queries/tpc-h-16.sql +++ /dev/null @@ -1,9 +0,0 @@ --- http://www.sqlserver-dba.com/2011/09/this-is-a-followup-on-my-earlier-post-of-sql-server-test-data-generation-testing-tools-i-had-some-requests-for-my-set-up-pr.html --- TPC_H Query 16 - Parts/Supplier Relationship -SELECT P_BRAND, P_TYPE, P_SIZE, COUNT(DISTINCT PS_SUPPKEY) AS SUPPLIER_CNT -FROM PARTSUPP, "PART" -WHERE P_PARTKEY = PS_PARTKEY AND P_BRAND <> 'Brand#45' AND P_TYPE NOT LIKE 'MEDIUM POLISHED%%' -AND P_SIZE IN (49, 14, 23, 45, 19, 3, 36, 9) AND PS_SUPPKEY NOT IN (SELECT S_SUPPKEY FROM SUPPLIER - WHERE S_COMMENT LIKE '%%Customer%%Complaints%%') -GROUP BY P_BRAND, P_TYPE, P_SIZE -ORDER BY SUPPLIER_CNT DESC, P_BRAND, P_TYPE, P_SIZE; \ No newline at end of file diff --git a/cpp/sql-parser/test/queries/tpc-h-17.sql b/cpp/sql-parser/test/queries/tpc-h-17.sql deleted file mode 100644 index e6d50ac1e..000000000 --- a/cpp/sql-parser/test/queries/tpc-h-17.sql +++ /dev/null @@ -1,4 +0,0 @@ --- TPC_H Query 17 - Small-Quantity-Order Revenue -SELECT SUM(L_EXTENDEDPRICE)/7.0 AS AVG_YEARLY FROM LINEITEM, "PART" -WHERE P_PARTKEY = L_PARTKEY AND P_BRAND = 'Brand#23' AND P_CONTAINER = 'MED BOX' -AND L_QUANTITY < (SELECT 0.2*AVG(L_QUANTITY) FROM LINEITEM WHERE L_PARTKEY = P_PARTKEY); \ No newline at end of file diff --git a/cpp/sql-parser/test/queries/tpc-h-18.sql b/cpp/sql-parser/test/queries/tpc-h-18.sql deleted file mode 100644 index 57e9a34fb..000000000 --- a/cpp/sql-parser/test/queries/tpc-h-18.sql +++ /dev/null @@ -1,7 +0,0 @@ --- TPC_H Query 18 - Large Volume Customer -SELECT TOP 100 C_NAME, C_CUSTKEY, O_ORDERKEY, O_ORDERDATE, O_TOTALPRICE, SUM(L_QUANTITY) -FROM CUSTOMER, ORDERS, LINEITEM -WHERE O_ORDERKEY IN (SELECT L_ORDERKEY FROM LINEITEM GROUP BY L_ORDERKEY HAVING - SUM(L_QUANTITY) > 300) AND C_CUSTKEY = O_CUSTKEY AND O_ORDERKEY = L_ORDERKEY -GROUP BY C_NAME, C_CUSTKEY, O_ORDERKEY, O_ORDERDATE, O_TOTALPRICE -ORDER BY O_TOTALPRICE DESC, O_ORDERDATE; \ No newline at end of file diff --git a/cpp/sql-parser/test/queries/tpc-h-19.sql b/cpp/sql-parser/test/queries/tpc-h-19.sql deleted file mode 100644 index 8000b9691..000000000 --- a/cpp/sql-parser/test/queries/tpc-h-19.sql +++ /dev/null @@ -1,9 +0,0 @@ --- TPC_H Query 19 - Discounted Revenue -SELECT SUM(L_EXTENDEDPRICE* (1 - L_DISCOUNT)) AS REVENUE -FROM LINEITEM, "PART" -WHERE (P_PARTKEY = L_PARTKEY AND P_BRAND = 'Brand#12' AND P_CONTAINER IN ('SM CASE', 'SM BOX', 'SM PACK', 'SM PKG') AND L_QUANTITY >= 1 AND L_QUANTITY <= 1 + 10 AND P_SIZE BETWEEN 1 AND 5 -AND L_SHIPMODE IN ('AIR', 'AIR REG') AND L_SHIPINSTRUCT = 'DELIVER IN PERSON') -OR (P_PARTKEY = L_PARTKEY AND P_BRAND ='Brand#23' AND P_CONTAINER IN ('MED BAG', 'MED BOX', 'MED PKG', 'MED PACK') AND L_QUANTITY >=10 AND L_QUANTITY <=10 + 10 AND P_SIZE BETWEEN 1 AND 10 -AND L_SHIPMODE IN ('AIR', 'AIR REG') AND L_SHIPINSTRUCT = 'DELIVER IN PERSON') -OR (P_PARTKEY = L_PARTKEY AND P_BRAND = 'Brand#34' AND P_CONTAINER IN ( 'LG CASE', 'LG BOX', 'LG PACK', 'LG PKG') AND L_QUANTITY >=20 AND L_QUANTITY <= 20 + 10 AND P_SIZE BETWEEN 1 AND 15 -AND L_SHIPMODE IN ('AIR', 'AIR REG') AND L_SHIPINSTRUCT = 'DELIVER IN PERSON'); \ No newline at end of file diff --git a/cpp/sql-parser/test/queries/tpc-h-20.sql b/cpp/sql-parser/test/queries/tpc-h-20.sql deleted file mode 100644 index 9803a254a..000000000 --- a/cpp/sql-parser/test/queries/tpc-h-20.sql +++ /dev/null @@ -1,8 +0,0 @@ --- TPC_H Query 20 - Potential Part Promotion -SELECT S_NAME, S_ADDRESS FROM SUPPLIER, NATION -WHERE S_SUPPKEY IN (SELECT PS_SUPPKEY FROM PARTSUPP - WHERE PS_PARTKEY in (SELECT P_PARTKEY FROM "PART" WHERE P_NAME like 'forest%%') AND - PS_AVAILQTY > (SELECT 0.5*sum(L_QUANTITY) FROM LINEITEM WHERE L_PARTKEY = PS_PARTKEY AND - L_SUPPKEY = PS_SUPPKEY AND L_SHIPDATE >= '1994-01-01' AND - L_SHIPDATE < dateadd(yy,1,'1994-01-01'))) AND S_NATIONKEY = N_NATIONKEY AND N_NAME = 'CANADA' -ORDER BY S_NAME; \ No newline at end of file diff --git a/cpp/sql-parser/test/queries/tpc-h-21.sql b/cpp/sql-parser/test/queries/tpc-h-21.sql deleted file mode 100644 index 27be0c6d0..000000000 --- a/cpp/sql-parser/test/queries/tpc-h-21.sql +++ /dev/null @@ -1,11 +0,0 @@ --- TPC_H Query 21 - Suppliers Who Kept Orders Waiting -SELECT TOP 100 S_NAME, COUNT(*) AS NUMWAIT -FROM SUPPLIER, LINEITEM L1, ORDERS, NATION WHERE S_SUPPKEY = L1.L_SUPPKEY AND -O_ORDERKEY = L1.L_ORDERKEY AND O_ORDERSTATUS = 'F' AND L1.L_RECEIPTDATE> L1.L_COMMITDATE -AND EXISTS (SELECT * FROM LINEITEM L2 WHERE L2.L_ORDERKEY = L1.L_ORDERKEY - AND L2.L_SUPPKEY <> L1.L_SUPPKEY) AND -NOT EXISTS (SELECT * FROM LINEITEM L3 WHERE L3.L_ORDERKEY = L1.L_ORDERKEY AND - L3.L_SUPPKEY <> L1.L_SUPPKEY AND L3.L_RECEIPTDATE > L3.L_COMMITDATE) AND -S_NATIONKEY = N_NATIONKEY AND N_NAME = 'SAUDI ARABIA' -GROUP BY S_NAME -ORDER BY NUMWAIT DESC, S_NAME; \ No newline at end of file diff --git a/cpp/sql-parser/test/queries/tpc-h-22.sql b/cpp/sql-parser/test/queries/tpc-h-22.sql deleted file mode 100644 index 4d1d11e38..000000000 --- a/cpp/sql-parser/test/queries/tpc-h-22.sql +++ /dev/null @@ -1,9 +0,0 @@ --- TPC_H Query 22 - Global Sales Opportunity */ -SELECT CNTRYCODE, COUNT(*) AS NUMCUST, SUM(C_ACCTBAL) AS TOTACCTBAL -FROM (SELECT SUBSTRING(C_PHONE,1,2) AS CNTRYCODE, C_ACCTBAL - FROM CUSTOMER WHERE SUBSTRING(C_PHONE,1,2) IN ('13', '31', '23', '29', '30', '18', '17') AND - C_ACCTBAL > (SELECT AVG(C_ACCTBAL) FROM CUSTOMER WHERE C_ACCTBAL > 0.00 AND - SUBSTRING(C_PHONE,1,2) IN ('13', '31', '23', '29', '30', '18', '17')) AND - NOT EXISTS ( SELECT * FROM ORDERS WHERE O_CUSTKEY = C_CUSTKEY)) AS CUSTSALE -GROUP BY CNTRYCODE -ORDER BY CNTRYCODE; \ No newline at end of file diff --git a/cpp/sql-parser/test/select_tests.cpp b/cpp/sql-parser/test/select_tests.cpp deleted file mode 100644 index 594f212d4..000000000 --- a/cpp/sql-parser/test/select_tests.cpp +++ /dev/null @@ -1,250 +0,0 @@ - - -#include "thirdparty/microtest/microtest.h" -#include "sql_asserts.h" -#include "SQLParser.h" - -using namespace hsql; - -TEST(SelectTest) { - TEST_PARSE_SINGLE_SQL( - "SELECT * FROM students;", - kStmtSelect, - SelectStatement, - result, - stmt); - - ASSERT_NULL(stmt->whereClause); - ASSERT_NULL(stmt->groupBy); -} - -TEST(SelectExprTest) { - TEST_PARSE_SINGLE_SQL( - "SELECT a, MAX(b), CUSTOM(c, F(un)) FROM students;", - kStmtSelect, - SelectStatement, - result, - stmt); - - ASSERT_NULL(stmt->whereClause); - ASSERT_NULL(stmt->groupBy); - - ASSERT_EQ(stmt->selectList->size(), 3); - - ASSERT(stmt->selectList->at(0)->isType(kExprColumnRef)); - ASSERT_STREQ(stmt->selectList->at(0)->getName(), "a"); - - ASSERT(stmt->selectList->at(1)->isType(kExprFunctionRef)); - ASSERT_STREQ(stmt->selectList->at(1)->getName(), "MAX"); - ASSERT_NOTNULL(stmt->selectList->at(1)->exprList); - ASSERT_EQ(stmt->selectList->at(1)->exprList->size(), 1); - ASSERT(stmt->selectList->at(1)->exprList->at(0)->isType(kExprColumnRef)); - ASSERT_STREQ(stmt->selectList->at(1)->exprList->at(0)->getName(), "b"); - - ASSERT(stmt->selectList->at(2)->isType(kExprFunctionRef)); - ASSERT_STREQ(stmt->selectList->at(2)->getName(), "CUSTOM"); - ASSERT_NOTNULL(stmt->selectList->at(2)->exprList); - ASSERT_EQ(stmt->selectList->at(2)->exprList->size(), 2); - ASSERT(stmt->selectList->at(2)->exprList->at(0)->isType(kExprColumnRef)); - ASSERT_STREQ(stmt->selectList->at(2)->exprList->at(0)->getName(), "c"); - - ASSERT(stmt->selectList->at(2)->exprList->at(1)->isType(kExprFunctionRef)); - ASSERT_STREQ(stmt->selectList->at(2)->exprList->at(1)->getName(), "F"); - ASSERT_EQ(stmt->selectList->at(2)->exprList->at(1)->exprList->size(), 1); - ASSERT(stmt->selectList->at(2)->exprList->at(1)->exprList->at(0)->isType(kExprColumnRef)); - ASSERT_STREQ(stmt->selectList->at(2)->exprList->at(1)->exprList->at(0)->getName(), "un"); -} - - -TEST(SelectHavingTest) { - TEST_PARSE_SINGLE_SQL( - "SELECT city, AVG(grade) AS avg_grade FROM students GROUP BY city HAVING AVG(grade) < -2.0", - kStmtSelect, - SelectStatement, - result, - stmt); - - ASSERT_FALSE(stmt->selectDistinct); - - GroupByDescription* group = stmt->groupBy; - ASSERT_NOTNULL(group); - ASSERT_EQ(group->columns->size(), 1); - ASSERT_EQ(group->having->opType, kOpLess); - ASSERT(group->having->expr->isType(kExprFunctionRef)); - ASSERT(group->having->expr2->isType(kExprLiteralFloat)); - ASSERT_EQ(group->having->expr2->fval, -2.0); -} - - -TEST(SelectDistinctTest) { - TEST_PARSE_SINGLE_SQL( - "SELECT DISTINCT grade, city FROM students;", - kStmtSelect, - SelectStatement, - result, - stmt); - - ASSERT(stmt->selectDistinct); - ASSERT_NULL(stmt->whereClause); -} - -TEST(SelectGroupDistinctTest) { - TEST_PARSE_SINGLE_SQL( - "SELECT city, COUNT(name), COUNT(DISTINCT grade) FROM students GROUP BY city;", - kStmtSelect, - SelectStatement, - result, - stmt); - - ASSERT_FALSE(stmt->selectDistinct); - ASSERT_EQ(stmt->selectList->size(), 3); - ASSERT(!stmt->selectList->at(1)->distinct); - ASSERT(stmt->selectList->at(2)->distinct); -} - -TEST(OrderByTest) { - TEST_PARSE_SINGLE_SQL( - "SELECT grade, city FROM students ORDER BY grade, city DESC;", - kStmtSelect, - SelectStatement, - result, - stmt); - - ASSERT_NULL(stmt->whereClause); - ASSERT_NOTNULL(stmt->order); - - ASSERT_EQ(stmt->order->size(), 2); - ASSERT_EQ(stmt->order->at(0)->type, kOrderAsc); - ASSERT_STREQ(stmt->order->at(0)->expr->name, "grade"); - - ASSERT_EQ(stmt->order->at(1)->type, kOrderDesc); - ASSERT_STREQ(stmt->order->at(1)->expr->name, "city"); -} - -TEST(SelectBetweenTest) { - TEST_PARSE_SINGLE_SQL( - "SELECT grade, city FROM students WHERE grade BETWEEN -1 and c;", - kStmtSelect, - SelectStatement, - result, - stmt); - - - Expr* where = stmt->whereClause; - ASSERT_NOTNULL(where); - ASSERT(where->isType(kExprOperator)); - ASSERT_EQ(where->opType, kOpBetween); - - ASSERT_STREQ(where->expr->getName(), "grade"); - ASSERT(where->expr->isType(kExprColumnRef)); - - ASSERT_EQ(where->exprList->size(), 2); - ASSERT(where->exprList->at(0)->isType(kExprLiteralInt)); - ASSERT_EQ(where->exprList->at(0)->ival, -1); - ASSERT(where->exprList->at(1)->isType(kExprColumnRef)); - ASSERT_STREQ(where->exprList->at(1)->getName(), "c"); -} - -TEST(SelectConditionalSelectTest) { - TEST_PARSE_SINGLE_SQL( - "SELECT * FROM t WHERE a = (SELECT MIN(v) FROM tt) AND EXISTS (SELECT * FROM test WHERE x < a);", - kStmtSelect, - SelectStatement, - result, - stmt); - - Expr* where = stmt->whereClause; - ASSERT_NOTNULL(where); - ASSERT(where->isType(kExprOperator)); - ASSERT_EQ(where->opType, kOpAnd); - - // a = (SELECT ...) - Expr* cond1 = where->expr; - ASSERT_NOTNULL(cond1); - ASSERT_NOTNULL(cond1->expr); - ASSERT_EQ(cond1->opType, kOpEquals); - ASSERT_STREQ(cond1->expr->getName(), "a"); - ASSERT(cond1->expr->isType(kExprColumnRef)); - - ASSERT_NOTNULL(cond1->expr2); - ASSERT(cond1->expr2->isType(kExprSelect)); - - SelectStatement* select2 = cond1->expr2->select; - ASSERT_NOTNULL(select2); - ASSERT_STREQ(select2->fromTable->getName(), "tt"); - - - // EXISTS (SELECT ...) - Expr* cond2 = where->expr2; - ASSERT_EQ(cond2->opType, kOpExists); - ASSERT_NOTNULL(cond2->select); - - SelectStatement* ex_select = cond2->select; - ASSERT_STREQ(ex_select->fromTable->getName(), "test"); -} - -TEST(SelectCaseWhen) { - TEST_PARSE_SINGLE_SQL( - "SELECT MAX(CASE WHEN a = 'foo' THEN x ELSE 0 END) FROM test;", - kStmtSelect, - SelectStatement, - result, - stmt); - - ASSERT_EQ(stmt->selectList->size(), 1); - Expr* func = stmt->selectList->at(0); - - ASSERT_NOTNULL(func); - ASSERT(func->isType(kExprFunctionRef)); - ASSERT_EQ(func->exprList->size(), 1); - - Expr* caseExpr = func->exprList->at(0); - ASSERT_NOTNULL(caseExpr); - ASSERT(caseExpr->isType(kExprOperator)); - ASSERT_EQ(caseExpr->opType, kOpCase); - ASSERT(caseExpr->expr->isType(kExprOperator)); - ASSERT_EQ(caseExpr->expr->opType, kOpEquals); - ASSERT_EQ(caseExpr->exprList->size(), 2); -} - -TEST(SelectJoin) { - TEST_PARSE_SINGLE_SQL( - "SELECT City.name, Product.category, SUM(price) FROM fact\ - INNER JOIN City ON fact.city_id = City.id\ - OUTER JOIN Product ON fact.product_id = Product.id\ - GROUP BY City.name, Product.category;", - kStmtSelect, - SelectStatement, - result, - stmt); - - const TableRef* table = stmt->fromTable; - const JoinDefinition* outer_join = table->join; - ASSERT_EQ(table->type, kTableJoin); - ASSERT_EQ(outer_join->type, kJoinOuter); - - ASSERT_EQ(outer_join->right->type, kTableName); - ASSERT_STREQ(outer_join->right->name, "Product"); - ASSERT_EQ(outer_join->condition->opType, kOpEquals); - ASSERT_STREQ(outer_join->condition->expr->table, "fact"); - ASSERT_STREQ(outer_join->condition->expr->name, "product_id"); - ASSERT_STREQ(outer_join->condition->expr2->table, "Product"); - ASSERT_STREQ(outer_join->condition->expr2->name, "id"); - - // Joins are are left associative. - // So the second join should be on the left. - ASSERT_EQ(outer_join->left->type, kTableJoin); - - const JoinDefinition* inner_join = outer_join->left->join; - ASSERT_EQ(inner_join->type, kJoinInner); - ASSERT_EQ(inner_join->left->type, kTableName); - ASSERT_STREQ(inner_join->left->name, "fact"); - ASSERT_EQ(inner_join->right->type, kTableName); - ASSERT_STREQ(inner_join->right->name, "City"); - - ASSERT_EQ(inner_join->condition->opType, kOpEquals); - ASSERT_STREQ(inner_join->condition->expr->table, "fact"); - ASSERT_STREQ(inner_join->condition->expr->name, "city_id"); - ASSERT_STREQ(inner_join->condition->expr2->table, "City"); - ASSERT_STREQ(inner_join->condition->expr2->name, "id"); -} diff --git a/cpp/sql-parser/test/sql_asserts.h b/cpp/sql-parser/test/sql_asserts.h deleted file mode 100644 index 2ac60b446..000000000 --- a/cpp/sql-parser/test/sql_asserts.h +++ /dev/null @@ -1,23 +0,0 @@ -#ifndef __HELPER_H__ -#define __HELPER_H__ - - -#define TEST_PARSE_SQL_QUERY(query, result, numStatements) \ - hsql::SQLParserResult result; \ - hsql::SQLParser::parse(query, &result); \ - ASSERT(result.isValid()); \ - ASSERT_EQ(result.size(), numStatements); - - -#define TEST_PARSE_SINGLE_SQL(query, stmtType, stmtClass, result, outputVar) \ - TEST_PARSE_SQL_QUERY(query, result, 1); \ - ASSERT_EQ(result.getStatement(0)->type(), stmtType); \ - const stmtClass* outputVar = (const stmtClass*) result.getStatement(0); - - -#define TEST_CAST_STMT(result, stmt_index, stmtType, stmtClass, outputVar) \ - ASSERT_EQ(result.getStatement(stmt_index)->type(), stmtType); \ - const stmtClass* outputVar = (const stmtClass*) result.getStatement(stmt_index); - - -#endif diff --git a/cpp/sql-parser/test/sql_parser.cpp b/cpp/sql-parser/test/sql_parser.cpp deleted file mode 100644 index ed3c236c4..000000000 --- a/cpp/sql-parser/test/sql_parser.cpp +++ /dev/null @@ -1,44 +0,0 @@ -#include "thirdparty/microtest/microtest.h" - -#include -#include -#include - -#include "sql_asserts.h" -#include "SQLParser.h" -#include "parser/bison_parser.h" - -using namespace hsql; - -void test_tokens(const std::string& query, const std::vector& expected_tokens) { - std::vector tokens; - ASSERT(SQLParser::tokenize(query, &tokens)); - - ASSERT_EQ(expected_tokens.size(), tokens.size()); - - for (unsigned i = 0; i < expected_tokens.size(); ++i) { - ASSERT_EQ(expected_tokens[i], tokens[i]); - } -} - -TEST(SQLParserTokenizeTest) { - test_tokens("SELECT * FROM test;", { SQL_SELECT, '*', SQL_FROM, SQL_IDENTIFIER, ';' }); - test_tokens("SELECT a, 'b' FROM test WITH HINT;", { SQL_SELECT, SQL_IDENTIFIER, ',', SQL_STRING, SQL_FROM, SQL_IDENTIFIER, SQL_WITH, SQL_HINT, ';' }); -} - -TEST(SQLParserTokenizeStringifyTest) { - const std::string query = "SELECT * FROM test;"; - std::vector tokens; - ASSERT(SQLParser::tokenize(query, &tokens)); - - // Make u16string. - std::u16string token_string(tokens.cbegin(), tokens.cend()); - - // Check if u16 string is cacheable. - std::map cache; - cache[token_string] = query; - - ASSERT(query == cache[token_string]); - ASSERT(&query != &cache[token_string]); -} - diff --git a/cpp/sql-parser/test/sql_tests.cpp b/cpp/sql-parser/test/sql_tests.cpp deleted file mode 100644 index 9c9cc8217..000000000 --- a/cpp/sql-parser/test/sql_tests.cpp +++ /dev/null @@ -1,201 +0,0 @@ -/* - * sql_tests.cpp - */ - -#include "thirdparty/microtest/microtest.h" - -#include "SQLParser.h" -#include "util/sqlhelper.h" - -#include "sql_asserts.h" - -using namespace hsql; - - -TEST(DeleteStatementTest) { - SQLParserResult result; - SQLParser::parse("DELETE FROM students WHERE grade > 2.0;", &result); - - ASSERT(result.isValid()); - ASSERT_EQ(result.size(), 1); - ASSERT(result.getStatement(0)->type() == kStmtDelete); - - const DeleteStatement* stmt = (const DeleteStatement*) result.getStatement(0); - ASSERT_STREQ(stmt->tableName, "students"); - ASSERT_NOTNULL(stmt->expr); - ASSERT(stmt->expr->isType(kExprOperator)); - ASSERT_STREQ(stmt->expr->expr->name, "grade"); - ASSERT_EQ(stmt->expr->expr2->fval, 2.0); -} - -TEST(CreateStatementTest) { - SQLParserResult result; - SQLParser::parse("CREATE TABLE students (name TEXT, student_number INT, city INTEGER, grade DOUBLE)", &result); - - ASSERT(result.isValid()); - ASSERT_EQ(result.size(), 1); - ASSERT_EQ(result.getStatement(0)->type(), kStmtCreate); - - const CreateStatement* stmt = (const CreateStatement*) result.getStatement(0); - ASSERT_EQ(stmt->type, kCreateTable); - ASSERT_STREQ(stmt->tableName, "students"); - ASSERT_NOTNULL(stmt->columns); - ASSERT_EQ(stmt->columns->size(), 4); - ASSERT_STREQ(stmt->columns->at(0)->name, "name"); - ASSERT_STREQ(stmt->columns->at(1)->name, "student_number"); - ASSERT_STREQ(stmt->columns->at(2)->name, "city"); - ASSERT_STREQ(stmt->columns->at(3)->name, "grade"); - ASSERT_EQ(stmt->columns->at(0)->type, ColumnDefinition::TEXT); - ASSERT_EQ(stmt->columns->at(1)->type, ColumnDefinition::INT); - ASSERT_EQ(stmt->columns->at(2)->type, ColumnDefinition::INT); - ASSERT_EQ(stmt->columns->at(3)->type, ColumnDefinition::DOUBLE); -} - - -TEST(UpdateStatementTest) { - SQLParserResult result; - SQLParser::parse("UPDATE students SET grade = 5.0, name = 'test' WHERE name = 'Max Mustermann';", &result); - - ASSERT(result.isValid()); - ASSERT_EQ(result.size(), 1); - ASSERT_EQ(result.getStatement(0)->type(), kStmtUpdate); - - const UpdateStatement* stmt = (const UpdateStatement*) result.getStatement(0); - ASSERT_NOTNULL(stmt->table); - ASSERT_STREQ(stmt->table->name, "students"); - - ASSERT_NOTNULL(stmt->updates); - ASSERT_EQ(stmt->updates->size(), 2); - ASSERT_STREQ(stmt->updates->at(0)->column, "grade"); - ASSERT_STREQ(stmt->updates->at(1)->column, "name"); - ASSERT(stmt->updates->at(0)->value->isType(kExprLiteralFloat)); - ASSERT(stmt->updates->at(1)->value->isType(kExprLiteralString)); - ASSERT_EQ(stmt->updates->at(0)->value->fval, 5.0); - ASSERT_STREQ(stmt->updates->at(1)->value->name, "test"); - - ASSERT_NOTNULL(stmt->where); - ASSERT(stmt->where->isType(kExprOperator)); - ASSERT_EQ(stmt->where->opType, kOpEquals); - ASSERT_STREQ(stmt->where->expr->name, "name"); - ASSERT_STREQ(stmt->where->expr2->name, "Max Mustermann"); -} - - -TEST(InsertStatementTest) { - TEST_PARSE_SINGLE_SQL( - "INSERT INTO students VALUES ('Max Mustermann', 12345, 'Musterhausen', 2.0)", - kStmtInsert, - InsertStatement, - result, - stmt); - - ASSERT_EQ(stmt->values->size(), 4); - // TODO -} - - -TEST(DropTableStatementTest) { - TEST_PARSE_SINGLE_SQL( - "DROP TABLE students", - kStmtDrop, - DropStatement, - result, - stmt); - - ASSERT_EQ(stmt->type, kDropTable); - ASSERT_NOTNULL(stmt->name); - ASSERT_STREQ(stmt->name, "students"); -} - -TEST(ReleaseStatementTest) { - TEST_PARSE_SINGLE_SQL( - "SELECT * FROM students;", - kStmtSelect, - SelectStatement, - result, - stmt); - - ASSERT_EQ(1, result.size()); - ASSERT_NULL(stmt->whereClause); - - std::vector statements = result.releaseStatements(); - - ASSERT_EQ(0, result.size()); - - for (SQLStatement* stmt : statements) { - delete stmt; - } -} - -TEST(ShowTableStatementTest) { - TEST_PARSE_SINGLE_SQL( - "SHOW TABLES;", - kStmtShow, - ShowStatement, - result, - stmt); - - ASSERT_EQ(stmt->type, kShowTables); - ASSERT_NULL(stmt->name); -} - -TEST(ShowColumnsStatementTest) { - TEST_PARSE_SINGLE_SQL( - "SHOW COLUMNS students;", - kStmtShow, - ShowStatement, - result, - stmt); - - ASSERT_EQ(stmt->type, kShowColumns); - ASSERT_NOTNULL(stmt->name); - ASSERT_STREQ(stmt->name, "students"); -} - - -SQLParserResult parse_and_move(std::string query) { - hsql::SQLParserResult result; - hsql::SQLParser::parse(query, &result); - // Moves on return. - return result; -} - -SQLParserResult move_in_and_back(SQLParserResult res) { - // Moves on return. - return res; -} - -TEST(MoveSQLResultTest) { - SQLParserResult res = parse_and_move("SELECT * FROM test;"); - ASSERT(res.isValid()); - ASSERT_EQ(1, res.size()); - - // Moved around. - SQLParserResult new_res = move_in_and_back(std::move(res)); - - // Original object should be invalid. - ASSERT_FALSE(res.isValid()); - ASSERT_EQ(0, res.size()); - - ASSERT(new_res.isValid()); - ASSERT_EQ(1, new_res.size()); -} - -TEST(HintTest) { - TEST_PARSE_SINGLE_SQL( - "SELECT * FROM students WITH HINT(NO_CACHE, SAMPLE_RATE(10));", - kStmtSelect, - SelectStatement, - result, - stmt); - - - ASSERT_NOTNULL(stmt->hints); - ASSERT_EQ(2, stmt->hints->size()); - ASSERT_STREQ("NO_CACHE", stmt->hints->at(0)->name); - ASSERT_STREQ("SAMPLE_RATE", stmt->hints->at(1)->name); - ASSERT_EQ(1, stmt->hints->at(1)->exprList->size()); - ASSERT_EQ(10, stmt->hints->at(1)->exprList->at(0)->ival); -} - -TEST_MAIN(); diff --git a/cpp/sql-parser/test/test.sh b/cpp/sql-parser/test/test.sh deleted file mode 100755 index 5766a13d7..000000000 --- a/cpp/sql-parser/test/test.sh +++ /dev/null @@ -1,76 +0,0 @@ -#!/bin/bash -# Has to be executed from the root of the repository. -# Usually invoked by `make test`. -export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:./ - -# Colors -RED='\033[1;31m' -GREEN='\033[1;32m' -NC='\033[0m' -BOLD='\033[1;39m' - -RET=0 -SQL_TEST_RET=0 -MEM_LEAK_RET=0 -CONFLICT_RET=0 - -################################################# -# Running SQL parser tests. -printf "\n${GREEN}Running SQL parser tests...${NC}\n" -bin/tests -f "test/queries/queries-good.sql" -f "test/queries/queries-bad.sql" -SQL_TEST_RET=$? - -if [ $SQL_TEST_RET -eq 0 ]; then - printf "${GREEN}SQL parser tests succeeded!${NC}\n" -else - RET=1 - printf "${RED}SQL parser tests failed!${NC}\n" -fi - -################################################# -# Running memory leak checks. -printf "\n${GREEN}Running memory leak checks...${NC}\n" -valgrind --leak-check=full --error-exitcode=200 --log-fd=3 \ - bin/tests -f "test/queries/queries-good.sql" -f "test/queries/queries-bad.sql" \ - 3>&1 >/dev/null 2>/dev/null -MEM_LEAK_RET=$? - -if [ $MEM_LEAK_RET -ne 200 ]; then - printf "${GREEN}Memory leak check succeeded!${NC}\n" - MEM_LEAK_RET=0 -else - MEM_LEAK_RET=1 - RET=1 - printf "${RED}Memory leak check failed!${NC}\n" -fi - -################################################# -# Checking if the grammar is conflict free. -printf "\n${GREEN}Checking for conflicts in the grammer...${NC}\n" -printf "${RED}" -make -C src/parser/ test >>/dev/null -CONFLICT_RET=$? - -if [ $CONFLICT_RET -eq 0 ]; then - printf "${GREEN}Conflict check succeeded!${NC}\n" -else - RET=1 - printf "${RED}Conflict check failed!${NC}\n" -fi - -# Print a summary of the test results. -printf " ----------------------------------- -${BOLD}Summary:\n" -if [ $SQL_TEST_RET -eq 0 ]; then printf "SQL Tests: ${GREEN}Success${BOLD}\n"; -else printf "SQL Tests: ${RED}Failure${BOLD}\n"; fi -if [ $MEM_LEAK_RET -eq 0 ]; then printf "Memory Leak Check: ${GREEN}Success${BOLD}\n"; -else printf "Memory Leak Check: ${RED}Failure${BOLD}\n"; fi -if [ $CONFLICT_RET -eq 0 ]; then printf "Grammar Conflict Check: ${GREEN}Success${BOLD}\n"; -else printf "Grammar Conflict Check: ${RED}Failure${BOLD}\n"; fi - -if [ $RET -eq 0 ]; then printf "${GREEN}All tests passed!${NC}\n"; -else printf "${RED}Some tests failed!${NC}\n"; fi -printf "${NC}----------------------------------\n" - -exit $RET diff --git a/cpp/sql-parser/test/thirdparty/microtest/microtest.h b/cpp/sql-parser/test/thirdparty/microtest/microtest.h deleted file mode 100644 index b7c8392d1..000000000 --- a/cpp/sql-parser/test/thirdparty/microtest/microtest.h +++ /dev/null @@ -1,224 +0,0 @@ -// -// microtest.h -// -// URL: https://github.com/torpedro/microtest.h -// Author: Pedro Flemming (http://torpedro.com/) -// License: MIT License (https://github.com/torpedro/microtest.h/blob/master/LICENSE) -// Copyright (c) 2017 Pedro Flemming -// -// This is a small header-only C++ unit testing framework. -// It allows to define small unit tests with set of assertions available. -// -#ifndef __MICROTEST_H__ -#define __MICROTEST_H__ - -#include -#include -#include -#include - -//////////////// -// Assertions // -//////////////// - -#define ASSERT(cond)\ - ASSERT_TRUE(cond); - -#define ASSERT_TRUE(cond)\ - if (!(cond)) throw mt::AssertFailedException(#cond, __FILE__, __LINE__); - -#define ASSERT_FALSE(cond)\ - if (cond) throw mt::AssertFailedException(#cond, __FILE__, __LINE__); - -#define ASSERT_NULL(value)\ - ASSERT_TRUE(value == NULL); - -#define ASSERT_NOTNULL(value)\ - ASSERT_TRUE(value != NULL); - -#define ASSERT_STREQ(a, b)\ - if (std::string(a).compare(std::string(b)) != 0) {\ - printf("%s{ info} %s", mt::yellow(), mt::def());\ - std::cout << "Actual values: " << a << " != " << b << std::endl;\ - throw mt::AssertFailedException(#a " == " #b, __FILE__, __LINE__);\ - } - -#define ASSERT_STRNEQ(a, b)\ - if (std::string(a).compare(std::string(b)) !== 0) {\ - printf("%s{ info} %s", mt::yellow(), mt::def());\ - std::cout << "Actual values: " << a << " == " << b << std::endl;\ - throw mt::AssertFailedException(#a " != " #b, __FILE__, __LINE__);\ - } - -#define ASSERT_EQ(a, b)\ - if (a != b) {\ - printf("%s{ info} %s", mt::yellow(), mt::def());\ - std::cout << "Actual values: " << a << " != " << b << std::endl;\ - }\ - ASSERT(a == b); - -#define ASSERT_NEQ(a, b)\ - if (a == b) {\ - printf("%s{ info} %s", mt::yellow(), mt::def());\ - std::cout << "Actual values: " << a << " == " << b << std::endl;\ - }\ - ASSERT(a != b); - - -//////////////// -// Unit Tests // -//////////////// - -#define TEST(name) \ - void name();\ - namespace {\ - bool __##name = mt::TestsManager::AddTest(name, #name);\ - }\ - void name() - - -/////////////// -// Framework // -/////////////// - -namespace mt { - - inline const char* red() { - return "\033[1;31m"; - } - - inline const char* green() { - return "\033[0;32m"; - } - - inline const char* yellow() { - return "\033[0;33m"; - } - - inline const char* def() { - return "\033[0m"; - } - - inline void printRunning(const char* message, FILE* file = stdout) { - fprintf(file, "%s{ running}%s %s\n", green(), def(), message); - } - - inline void printOk(const char* message, FILE* file = stdout) { - fprintf(file, "%s{ ok}%s %s\n", green(), def(), message); - } - - inline void printFailed(const char* message, FILE* file = stdout) { - fprintf(file, "%s{ failed} %s%s\n", red(), message, def()); - } - - // Exception that is thrown when an assertion fails. - class AssertFailedException : public std::exception { - public: - AssertFailedException(std::string description, std::string filepath, int line) : - std::exception(), - description_(description), - filepath_(filepath), - line_(line) {}; - - virtual const char* what() const throw() { - return description_.c_str(); - } - - inline const char* getFilepath() { - return filepath_.c_str(); - } - - inline int getLine() { - return line_; - } - - protected: - std::string description_; - std::string filepath_; - int line_; - }; - - class TestsManager { - // Note: static initialization fiasco - // http://www.parashift.com/c++-faq-lite/static-init-order.html - // http://www.parashift.com/c++-faq-lite/static-init-order-on-first-use.html - public: - struct Test { - const char* name; - void (*fn)(void); - }; - - static std::vector& tests() { - static std::vector tests_; - return tests_; - } - - // Adds a new test to the current set of tests. - // Returns false if a test with the same name already exists. - inline static bool AddTest(void (*fn)(void), const char* name) { - tests().push_back({ name, fn }); - return true; - } - - // Run all tests that are registered. - // Returns the number of tests that failed. - inline static size_t RunAllTests(FILE* file = stdout) { - size_t num_failed = 0; - - for (const Test& test : tests()) { - // Run the test. - // If an AsserFailedException is thrown, the test has failed. - try { - printRunning(test.name, file); - - (*test.fn)(); - - printOk(test.name, file); - - } catch (AssertFailedException& e) { - printFailed(test.name, file); - fprintf(file, " %sAssertion failed: %s%s\n", - red(), e.what(), def()); - fprintf(file, " %s%s:%d%s\n", - red(), e.getFilepath(), e.getLine(), def()); - ++num_failed; - } - } - - int return_code = (num_failed > 0) ? 1 : 0; - return return_code; - } - }; - - // Class that will capture the arguments passed to the program. - class Runtime { - public: - static const std::vector& args(int argc = -1, char** argv = NULL) { - static std::vector args_; - if (argc >= 0) { - for (int i = 0; i < argc; ++i) { - args_.push_back(argv[i]); - } - } - return args_; - } - }; -} - - -#define TEST_MAIN() \ - int main(int argc, char *argv[]) {\ - mt::Runtime::args(argc, argv);\ - \ - size_t num_failed = mt::TestsManager::RunAllTests(stdout);\ - if (num_failed == 0) {\ - fprintf(stdout, "%s{ summary} All tests succeeded!%s\n", mt::green(), mt::def());\ - return 0;\ - } else {\ - double percentage = 100.0 * num_failed / mt::TestsManager::tests().size();\ - fprintf(stderr, "%s{ summary} %lu tests failed (%.2f%%)%s\n", mt::red(), num_failed, percentage, mt::def());\ - return -1;\ - }\ - } - -#endif // __MICROTEST_H__ \ No newline at end of file diff --git a/cpp/sql-parser/test/tpc_h_tests.cpp b/cpp/sql-parser/test/tpc_h_tests.cpp deleted file mode 100644 index 5d6143d44..000000000 --- a/cpp/sql-parser/test/tpc_h_tests.cpp +++ /dev/null @@ -1,124 +0,0 @@ -#include "thirdparty/microtest/microtest.h" - -#include "SQLParser.h" -#include "util/sqlhelper.h" - -#include "sql_asserts.h" - -#include -#include -#include -#include - -using namespace hsql; - -std::string readFileContents(std::string file_path) { - std::ifstream t(file_path.c_str()); - std::string text((std::istreambuf_iterator(t)), - std::istreambuf_iterator()); - return text; -} - -TEST(TPCHQueryGrammarTests) { - std::vector files = { - "test/queries/tpc-h-01.sql", - "test/queries/tpc-h-02.sql", - "test/queries/tpc-h-03.sql", - "test/queries/tpc-h-04.sql", - "test/queries/tpc-h-05.sql", - "test/queries/tpc-h-06.sql", - "test/queries/tpc-h-07.sql", - "test/queries/tpc-h-08.sql", - "test/queries/tpc-h-09.sql", - "test/queries/tpc-h-10.sql", - "test/queries/tpc-h-11.sql", - "test/queries/tpc-h-12.sql", - "test/queries/tpc-h-13.sql", - "test/queries/tpc-h-14.sql", - "test/queries/tpc-h-15.sql", - "test/queries/tpc-h-16.sql", - "test/queries/tpc-h-17.sql", - "test/queries/tpc-h-18.sql", - "test/queries/tpc-h-19.sql", - "test/queries/tpc-h-20.sql", - "test/queries/tpc-h-21.sql", - "test/queries/tpc-h-22.sql", - }; - - int testsFailed = 0; - std::string concatenated = ""; - for (const std::string& file_path : files) { - std::string query = readFileContents(file_path); - - concatenated += query; - if (concatenated.back() != ';') concatenated += ';'; - - SQLParserResult result; - SQLParser::parse(query.c_str(), &result); - if (!result.isValid()) { - mt::printFailed(file_path.c_str()); - printf("%s %s (L%d:%d)%s\n", mt::red(), result.errorMsg(), result.errorLine(), result.errorColumn(), mt::def()); - ++testsFailed; - } else { - mt::printOk(file_path.c_str()); - } - } - - SQLParserResult result; - SQLParser::parse(concatenated.c_str(), &result); - if (!result.isValid()) { - mt::printFailed("TPCHAllConcatenated"); - printf("%s %s (L%d:%d)%s\n", mt::red(), result.errorMsg(), result.errorLine(), result.errorColumn(), mt::def()); - ++testsFailed; - } else { - mt::printOk("TPCHAllConcatenated"); - } - - ASSERT_EQ(testsFailed, 0); -} - -TEST(TPCHQueryDetailTest) { - std::string query = readFileContents("test/queries/tpc-h-20.sql"); - - SQLParserResult result; - SQLParser::parse(query.c_str(), &result); - ASSERT(result.isValid()); - ASSERT_EQ(result.size(), 1); - - const SQLStatement* stmt20 = result.getStatement(0); - ASSERT_EQ(stmt20->type(), kStmtSelect); - - const SelectStatement* select20 = (const SelectStatement*) stmt20; - ASSERT_EQ(select20->selectList->size(), 2); - ASSERT_STREQ(select20->selectList->at(0)->getName(), "S_NAME"); - ASSERT_STREQ(select20->selectList->at(1)->getName(), "S_ADDRESS"); - - // Test WHERE Clause. - Expr* where = select20->whereClause; - ASSERT_NOTNULL(where); - ASSERT(where->isType(kExprOperator)); - ASSERT_EQ(where->opType, kOpAnd); - - Expr* andExpr2 = where->expr; - ASSERT_NOTNULL(andExpr2); - ASSERT(andExpr2->isType(kExprOperator)); - ASSERT_EQ(andExpr2->opType, kOpAnd); - - // Test IN expression. - Expr* inExpr = andExpr2->expr; - ASSERT_NOTNULL(inExpr); - ASSERT(inExpr->isType(kExprOperator)); - ASSERT_EQ(inExpr->opType, kOpIn); - - ASSERT_STREQ(inExpr->expr->getName(), "S_SUPPKEY"); - ASSERT_NOTNULL(inExpr->select); - ASSERT_EQ(inExpr->select->selectList->size(), 1); - ASSERT(inExpr->select->selectList->at(0)->isType(kExprColumnRef)); - ASSERT_STREQ(inExpr->select->selectList->at(0)->getName(), "PS_SUPPKEY"); - - // Test ORDER BY clause. - ASSERT_NOTNULL(select20->order); - ASSERT_EQ(select20->order->size(), 1); - ASSERT(select20->order->at(0)->expr->isType(kExprColumnRef)); - ASSERT_STREQ(select20->order->at(0)->expr->getName(), "S_NAME"); -} diff --git a/cpp/time_util.h b/cpp/time_util.h deleted file mode 100644 index a90734fc3..000000000 --- a/cpp/time_util.h +++ /dev/null @@ -1,23 +0,0 @@ -#ifndef _TIME_UTIL_H_ -#define _TIME_UTIL_H_ - -#include - -// Handle for timing. -typedef clock_t bench_timer_t; - -/** Starts the clock for a benchmark. */ -bench_timer_t time_start() { - bench_timer_t t = clock(); - return t; -} - -/** Stops the clock and returns time elapsed in seconds. - * Throws an error if time__start() was not called first. - * */ -double time_stop(bench_timer_t start) { - clock_t _end = clock(); - return ((double)(_end - start)) / CLOCKS_PER_SEC; -} - -#endif diff --git a/cpp/types.h b/cpp/types.h deleted file mode 100644 index 95773d31b..000000000 --- a/cpp/types.h +++ /dev/null @@ -1,9 +0,0 @@ -#ifndef _TYPES_H_ -#define _TYPES_H_ - -#include -#include - -using Row = std::vector; - -#endif diff --git a/cpp/util.h b/cpp/util.h deleted file mode 100644 index ca297cb3f..000000000 --- a/cpp/util.h +++ /dev/null @@ -1,34 +0,0 @@ -#ifndef _UTIL_H_ -#define _UTIL_H_ - -#include -#include - -#include "sql-parser/src/SQLParser.h" - -using std::equal; -using std::string; -using std::tolower; -using std::vector; - -bool ignore_case_pred(unsigned char a, unsigned char b) { - return tolower(a) == tolower(b); -} - -bool equals_ignorecase(string const& a, string const& b) { - if (a.length() == b.length()) { - return equal(b.begin(), b.end(), a.begin(), ignore_case_pred); - } else { - return false; - } -} - -vector get_attribute_cols(vector* attribute_cols) { - vector to_return; - for (auto it = attribute_cols->begin(); it != attribute_cols->end(); ++it) { - to_return.push_back((*it)->getName()); - } - return to_return; -} - -#endif