├── .clang-format ├── .gitignore ├── CMakeLists.txt ├── COPYING ├── README.md ├── client.sh ├── compression.sh ├── deps ├── CMakeLists.txt └── common │ ├── CMakeLists.txt │ ├── conf │ ├── ini.cpp │ └── ini.h │ ├── defs.h │ ├── io │ ├── io.cpp │ ├── io.h │ ├── roll_select_dir.cpp │ ├── roll_select_dir.h │ └── select_dir.h │ ├── lang │ ├── bitmap.cpp │ ├── bitmap.h │ ├── mutex.cpp │ ├── mutex.h │ ├── serializable.h │ ├── string.cpp │ └── string.h │ ├── log │ ├── log.cpp │ └── log.h │ ├── math │ ├── md5.cpp │ ├── md5.h │ ├── random_generator.cpp │ ├── random_generator.h │ ├── regex.cpp │ └── regex.h │ ├── metrics │ ├── console_reporter.cpp │ ├── console_reporter.h │ ├── histogram_snapshot.cpp │ ├── histogram_snapshot.h │ ├── log_reporter.cpp │ ├── log_reporter.h │ ├── metric.h │ ├── metrics.cpp │ ├── metrics.h │ ├── metrics_registry.cpp │ ├── metrics_registry.h │ ├── reporter.cpp │ ├── reporter.h │ ├── reservoir.cpp │ ├── reservoir.h │ ├── sampler.cpp │ ├── sampler.h │ ├── snapshot.h │ ├── timer_snapshot.cpp │ ├── timer_snapshot.h │ ├── uniform_reservoir.cpp │ └── uniform_reservoir.h │ ├── mm │ ├── debug_new.cpp.skip │ ├── debug_new.h │ ├── mem.cpp.skip │ ├── mem.h │ ├── mem_pool.cpp │ └── mem_pool.h │ ├── os │ ├── os.cpp │ ├── os.h │ ├── path.cpp │ ├── path.h │ ├── pidfile.cpp │ ├── pidfile.h │ ├── process.cpp │ ├── process.h │ ├── process_param.cpp │ ├── process_param.h │ ├── signal.cpp │ └── signal.h │ ├── seda │ ├── callback.cpp │ ├── callback.h │ ├── class_factory.h │ ├── event_dispatcher.cpp │ ├── event_dispatcher.h │ ├── example_stage.cpp │ ├── example_stage.h │ ├── init.cpp │ ├── init.h │ ├── kill_thread.cpp │ ├── kill_thread.h │ ├── metrics_report_event.cpp │ ├── metrics_report_event.h │ ├── metrics_stage.cpp │ ├── metrics_stage.h │ ├── seda_config.cpp │ ├── seda_config.h │ ├── seda_defs.h │ ├── stage.cpp │ ├── stage.h │ ├── stage_event.cpp │ ├── stage_event.h │ ├── stage_factory.h │ ├── thread_pool.cpp │ ├── thread_pool.h │ ├── timer_stage.cpp │ └── timer_stage.h │ ├── time │ ├── datetime.cpp │ ├── datetime.h │ ├── timeout_info.cpp │ └── timeout_info.h │ └── version.h ├── docs └── how_to_build.md ├── etc └── observer.ini ├── gdbserver.sh ├── lexandyacc.sh ├── load_test.sh ├── run_test.sh ├── server.sh ├── src ├── CMakeLists.txt ├── obclient │ ├── CMakeLists.txt │ └── client.cpp └── observer │ ├── CMakeLists.txt │ ├── event │ ├── execution_plan_event.cpp │ ├── execution_plan_event.h │ ├── session_event.cpp │ ├── session_event.h │ ├── sql_event.cpp │ ├── sql_event.h │ ├── storage_event.cpp │ └── storage_event.h │ ├── handler │ └── handler.h │ ├── ini_setting.h │ ├── init.cpp │ ├── init.h │ ├── main.cpp │ ├── net │ ├── connection_context.h │ ├── server.cpp │ ├── server.h │ └── server_param.h │ ├── rc.cpp │ ├── rc.h │ ├── session │ ├── session.cpp │ ├── session.h │ ├── session_stage.cpp │ └── session_stage.h │ ├── sql │ ├── executor │ │ ├── execute_stage.cpp │ │ ├── execute_stage.h │ │ ├── execution_node.cpp │ │ ├── execution_node.h │ │ ├── tuple.cpp │ │ ├── tuple.h │ │ ├── value.cpp │ │ └── value.h │ ├── optimizer │ │ ├── optimize_stage.cpp │ │ └── optimize_stage.h │ ├── parser │ │ ├── lex.yy.c │ │ ├── lex.yy.h │ │ ├── lex_sql.l │ │ ├── parse.cpp │ │ ├── parse.h │ │ ├── parse_defs.h │ │ ├── parse_stage.cpp │ │ ├── parse_stage.h │ │ ├── resolve_stage.cpp │ │ ├── resolve_stage.h │ │ ├── yacc_sql.tab.c │ │ ├── yacc_sql.tab.h │ │ └── yacc_sql.y │ ├── plan_cache │ │ ├── plan_cache_stage.cpp │ │ └── plan_cache_stage.h │ └── query_cache │ │ ├── query_cache_stage.cpp │ │ └── query_cache_stage.h │ └── storage │ ├── common │ ├── bplus_tree.cpp │ ├── bplus_tree.h │ ├── bplus_tree_index.cpp │ ├── bplus_tree_index.h │ ├── condition_filter.cpp │ ├── condition_filter.h │ ├── db.cpp │ ├── db.h │ ├── field_meta.cpp │ ├── field_meta.h │ ├── index.cpp │ ├── index.h │ ├── index_meta.cpp │ ├── index_meta.h │ ├── meta_util.cpp │ ├── meta_util.h │ ├── record_manager.cpp │ ├── record_manager.h │ ├── table.cpp │ ├── table.h │ ├── table_meta.cpp │ └── table_meta.h │ ├── default │ ├── default_handler.cpp │ ├── default_handler.h │ ├── default_storage_stage.cpp │ ├── default_storage_stage.h │ ├── disk_buffer_pool.cpp │ └── disk_buffer_pool.h │ ├── mem │ ├── mem_storage_stage.cpp │ └── mem_storage_stage.h │ └── trx │ ├── trx.cpp │ └── trx.h ├── test ├── case │ ├── README.md │ ├── case-scores.json │ ├── miniob_test.py │ ├── result │ │ ├── basic.result │ │ ├── primary-aggregation-func.result │ │ ├── primary-complex-sub-query.result │ │ ├── primary-date.result │ │ ├── primary-drop-table.result │ │ ├── primary-expression.result │ │ ├── primary-group-by.result │ │ ├── primary-insert.result │ │ ├── primary-join-tables.result │ │ ├── primary-multi-index.result │ │ ├── primary-null.result │ │ ├── primary-order-by.result │ │ ├── primary-select-meta.result │ │ ├── primary-select-tables.result │ │ ├── primary-simple-sub-query.result │ │ ├── primary-text.result │ │ ├── primary-unique.result │ │ └── primary-update.result │ └── test │ │ ├── .primary-update.test.swp │ │ ├── basic.test │ │ ├── primary-aggregation-func.test │ │ ├── primary-complex-sub-query.test │ │ ├── primary-date.test │ │ ├── primary-drop-table.test │ │ ├── primary-expression.test │ │ ├── primary-group-by.test │ │ ├── primary-insert.test │ │ ├── primary-join-tables.test │ │ ├── primary-multi-index.test │ │ ├── primary-null.test │ │ ├── primary-order-by.test │ │ ├── primary-select-meta.test │ │ ├── primary-select-tables.test │ │ ├── primary-simple-sub-query.test │ │ ├── primary-text.test │ │ ├── primary-unique.test │ │ └── primary-update.test ├── perf │ ├── CMakeLists.txt │ └── client_performance_test.cpp ├── test_ans │ ├── aggr │ │ ├── aggr_test_1 │ │ ├── aggr_test_2 │ │ └── aggr_test_3 │ ├── complex │ │ ├── case1 │ │ ├── case2 │ │ └── case3 │ ├── date │ │ ├── compare_date_1 │ │ ├── compare_date_2 │ │ ├── compare_date_3 │ │ ├── compare_date_4 │ │ ├── compare_date_5 │ │ ├── compare_date_6 │ │ ├── compare_date_index_1 │ │ ├── compare_date_index_2 │ │ └── delete_date_1 │ ├── drop_table │ │ ├── drop_table_1 │ │ ├── drop_table_2 │ │ ├── drop_table_3 │ │ └── drop_table_4 │ ├── expression │ │ ├── case1 │ │ ├── case2 │ │ └── case3 │ ├── group │ │ ├── group_case_1 │ │ ├── group_case_2 │ │ ├── group_case_3 │ │ └── group_case_4 │ ├── inner_join │ │ ├── case_1 │ │ ├── case_2 │ │ ├── case_3 │ │ └── case_4 │ ├── insert │ │ ├── case_1 │ │ ├── case_2 │ │ └── case_3 │ ├── metadata_verification │ │ ├── case_1 │ │ └── case_2 │ ├── multi_index │ │ ├── case_1 │ │ ├── case_2 │ │ ├── case_3 │ │ └── case_4 │ ├── multi_table │ │ ├── case_1 │ │ ├── case_2 │ │ └── case_3 │ ├── null │ │ ├── case_1 │ │ ├── case_2 │ │ ├── case_3 │ │ ├── case_4 │ │ └── case_5 │ ├── order │ │ ├── case_1 │ │ ├── case_2 │ │ ├── case_3 │ │ └── case_4 │ ├── sub-query │ │ ├── case1 │ │ └── case2 │ ├── unique_index │ │ ├── case_1 │ │ ├── case_2 │ │ └── case_3 │ └── update │ │ └── case_1 ├── test_case │ ├── aggr │ │ ├── aggr_test_1 │ │ ├── aggr_test_2 │ │ └── aggr_test_3 │ ├── complex │ │ ├── case1 │ │ ├── case2 │ │ └── case3 │ ├── date │ │ ├── compare_date_1 │ │ ├── compare_date_2 │ │ ├── compare_date_3 │ │ ├── compare_date_4 │ │ ├── compare_date_5 │ │ ├── compare_date_6 │ │ ├── compare_date_index_1 │ │ ├── compare_date_index_2 │ │ └── delete_date_1 │ ├── drop_table │ │ ├── drop_table_1 │ │ ├── drop_table_2 │ │ ├── drop_table_3 │ │ └── drop_table_4 │ ├── expression │ │ ├── case1 │ │ ├── case2 │ │ └── case3 │ ├── group │ │ ├── group_case_1 │ │ ├── group_case_2 │ │ ├── group_case_3 │ │ └── group_case_4 │ ├── inner_join │ │ ├── case_1 │ │ ├── case_2 │ │ ├── case_3 │ │ └── case_4 │ ├── insert │ │ ├── case_1 │ │ ├── case_2 │ │ └── case_3 │ ├── metadata_verification │ │ ├── case_1 │ │ └── case_2 │ ├── multi_index │ │ ├── case_1 │ │ ├── case_2 │ │ ├── case_3 │ │ └── case_4 │ ├── multi_table │ │ ├── case_1 │ │ ├── case_2 │ │ └── case_3 │ ├── null │ │ ├── case_1 │ │ ├── case_2 │ │ ├── case_3 │ │ ├── case_4 │ │ └── case_5 │ ├── order │ │ ├── case_1 │ │ ├── case_2 │ │ ├── case_3 │ │ └── case_4 │ ├── sub-query │ │ ├── case1 │ │ └── case2 │ ├── unique_index │ │ ├── case_1 │ │ ├── case_2 │ │ └── case_3 │ └── update │ │ └── case_1 ├── test_load │ ├── aggr │ ├── complex │ ├── date │ ├── date2 │ ├── expression │ ├── expression2 │ ├── expression3 │ ├── group │ ├── group2 │ ├── index │ ├── null │ ├── simple │ ├── sub-multi-query │ ├── sub-query │ ├── sub2 │ └── table_date └── test_out │ ├── aggr │ ├── aggr_test_1 │ ├── aggr_test_2 │ └── aggr_test_3 │ ├── complex │ ├── case1 │ ├── case2 │ └── case3 │ ├── date │ ├── compare_date_1 │ ├── compare_date_2 │ ├── compare_date_3 │ ├── compare_date_4 │ ├── compare_date_5 │ ├── compare_date_6 │ ├── compare_date_index_1 │ ├── compare_date_index_2 │ └── delete_date_1 │ ├── drop_table │ ├── drop_table_1 │ ├── drop_table_2 │ ├── drop_table_3 │ └── drop_table_4 │ ├── expression │ ├── case1 │ ├── case2 │ └── case3 │ ├── group │ ├── group_case_1 │ ├── group_case_2 │ ├── group_case_3 │ └── group_case_4 │ ├── inner_join │ ├── case_1 │ ├── case_2 │ ├── case_3 │ └── case_4 │ ├── insert │ ├── case_1 │ ├── case_2 │ └── case_3 │ ├── metadata_verification │ ├── case_1 │ └── case_2 │ ├── multi_index │ ├── case_1 │ ├── case_2 │ ├── case_3 │ └── case_4 │ ├── multi_table │ ├── case_1 │ ├── case_2 │ └── case_3 │ ├── null │ ├── case_1 │ ├── case_2 │ ├── case_3 │ ├── case_4 │ └── case_5 │ ├── order │ ├── case_1 │ ├── case_2 │ ├── case_3 │ └── case_4 │ ├── sub-query │ ├── case1 │ └── case2 │ ├── unique_index │ ├── case_1 │ ├── case_2 │ └── case_3 │ └── update │ └── case_1 └── unitest ├── CMakeLists.txt ├── bitmap_test.cpp ├── bp_manager_test.cpp ├── bplus_tree_test.cpp ├── log_test.cpp ├── log_test.h ├── md5_test.cpp ├── md5_test.h ├── mem_pool_test.cpp ├── path_test.cpp ├── pidfile_test.cpp ├── rc_test.cpp └── thread_test.h /.gitignore: -------------------------------------------------------------------------------- 1 | data/ 2 | ./deps/libevent/* 3 | ./deps/googletest/* 4 | ./deps/jsoncpp/* 5 | ./deps/common/* 6 | build/* 7 | cmake-build-*/* 8 | .vscode/* 9 | .DS_Store 10 | .idea 11 | compile_commands.json 12 | ./.name 13 | ./miniob.iml 14 | ./vcs.xml 15 | ./workspace.xml 16 | ./modules.xml 17 | *.output 18 | *.ans 19 | ./test/case/miniob_data_test/* 20 | ./test/case/result_tmp/* 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## Introduction 2 | 3 | [Oceanbase数据库大赛现场赛](https://open.oceanbase.com/competition/index) 第二名 324.877 4 | 5 | miniob设计的目标是让不熟悉数据库设计和实现的同学能够快速的了解与深入学习数据库内核,期望通过miniob相关训练之后,能够对各个数据库内核模块的功能与它们之间的关联有所了解,并能够在 6 | 使用时,设计出高效的SQL。面向的对象主要是在校学生,并且诸多模块做了简化,比如不考虑并发操作。 7 | 注意:此代码仅供学习使用,不考虑任何安全特性。 8 | 9 | # How to build 10 | please refer to docs/how_to_build.md 11 | 12 | # miniob 题目 13 | [miniob 题目](https://oceanbase-partner.github.io/lectures-on-dbms-implementation/miniob-topics) 14 | 15 | # miniob 实现解析 16 | 17 | [miniob-date 实现解析](https://oceanbase-partner.github.io/lectures-on-dbms-implementation/miniob-date-implementation.html) 18 | 19 | [miniob drop-table 实现解析](https://oceanbase-partner.github.io/lectures-on-dbms-implementation/miniob-drop-table-implementation.html) 20 | 21 | [miniob select-tables 实现解析](https://oceanbase-partner.github.io/lectures-on-dbms-implementation/miniob-select-tables-implementation.html) 22 | 23 | [miniob 调试篇](https://oceanbase-partner.github.io/lectures-on-dbms-implementation/miniob-how-to-debug.html) 24 | -------------------------------------------------------------------------------- /client.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | ./cmake-build-debug/bin/obclient 3 | -------------------------------------------------------------------------------- /compression.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | table_size="300w" 4 | 5 | if [ $# -eq 1 ]; then 6 | table_size="$1" 7 | fi 8 | 9 | echo "create table t1 (c1 int, c2 int, c3 int, v1 char, v2 char, v3 char, v4 char, v5 char, v6 char, v7 char, v8 char, v9 char);" | ./cmake-build-debug/bin/obclient 10 | echo "load data infile '$PWD/data/miniob-${table_size}-v2.table' into table t1;" | ./cmake-build-debug/bin/obclient -------------------------------------------------------------------------------- /deps/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | 3 | ADD_SUBDIRECTORY(common) 4 | -------------------------------------------------------------------------------- /deps/common/io/roll_select_dir.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2021 Xie Meiyi(xiemeiyi@hust.edu.cn) and OceanBase and/or its affiliates. All rights reserved. 2 | miniob is licensed under Mulan PSL v2. 3 | You can use this software according to the terms and conditions of the Mulan PSL v2. 4 | You may obtain a copy of Mulan PSL v2 at: 5 | http://license.coscl.org.cn/MulanPSL2 6 | THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, 7 | EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, 8 | MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. 9 | See the Mulan PSL v2 for more details. */ 10 | 11 | // 12 | // Created by Longda on 2010 13 | // 14 | 15 | #include "common/io/roll_select_dir.h" 16 | #include "common/io/io.h" 17 | #include "common/log/log.h" 18 | namespace common { 19 | 20 | void RollSelectDir::setBaseDir(std::string baseDir) 21 | { 22 | mBaseDir = baseDir; 23 | 24 | std::vector dirList; 25 | int rc = getDirList(dirList, mBaseDir, ""); 26 | if (rc) { 27 | LOG_ERROR("Failed to all subdir entry"); 28 | } 29 | 30 | if (dirList.size() == 0) { 31 | MUTEX_LOCK(&mMutex); 32 | 33 | mSubdirs.clear(); 34 | mSubdirs.push_back(mBaseDir); 35 | mPos = 0; 36 | MUTEX_UNLOCK(&mMutex); 37 | 38 | return; 39 | } 40 | 41 | MUTEX_LOCK(&mMutex); 42 | mSubdirs = dirList; 43 | mPos = 0; 44 | MUTEX_UNLOCK(&mMutex); 45 | return; 46 | } 47 | 48 | std::string RollSelectDir::select() 49 | { 50 | std::string ret; 51 | 52 | MUTEX_LOCK(&mMutex); 53 | ret = mSubdirs[mPos % mSubdirs.size()]; 54 | mPos++; 55 | MUTEX_UNLOCK(&mMutex); 56 | 57 | return ret; 58 | } 59 | 60 | } // namespace common -------------------------------------------------------------------------------- /deps/common/io/roll_select_dir.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2021 Xie Meiyi(xiemeiyi@hust.edu.cn) and OceanBase and/or its affiliates. All rights reserved. 2 | miniob is licensed under Mulan PSL v2. 3 | You can use this software according to the terms and conditions of the Mulan PSL v2. 4 | You may obtain a copy of Mulan PSL v2 at: 5 | http://license.coscl.org.cn/MulanPSL2 6 | THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, 7 | EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, 8 | MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. 9 | See the Mulan PSL v2 for more details. */ 10 | 11 | // 12 | // Created by Longda on 2010 13 | // 14 | 15 | #ifndef __COMMON_IO_ROLL_SELECT_DIR__ 16 | #define __COMMON_IO_ROLL_SELECT_DIR__ 17 | 18 | #include 19 | #include 20 | #include 21 | 22 | #include "common/defs.h" 23 | #include "common/io/select_dir.h" 24 | #include "common/lang/mutex.h" 25 | namespace common { 26 | 27 | class RollSelectDir : public SelectDir { 28 | public: 29 | RollSelectDir() 30 | { 31 | MUTEX_INIT(&mMutex, NULL); 32 | } 33 | ~RollSelectDir() 34 | { 35 | MUTEX_DESTROY(&mMutex); 36 | } 37 | 38 | public: 39 | /** 40 | * inherit from CSelectDir 41 | */ 42 | std::string select(); 43 | void setBaseDir(std::string baseDir); 44 | 45 | public: 46 | std::string mBaseDir; 47 | std::vector mSubdirs; 48 | pthread_mutex_t mMutex; 49 | u32_t mPos; 50 | }; 51 | 52 | } // namespace common 53 | #endif /* __COMMON_IO_ROLL_SELECT_DIR__ */ 54 | -------------------------------------------------------------------------------- /deps/common/io/select_dir.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2021 Xie Meiyi(xiemeiyi@hust.edu.cn) and OceanBase and/or its affiliates. All rights reserved. 2 | miniob is licensed under Mulan PSL v2. 3 | You can use this software according to the terms and conditions of the Mulan PSL v2. 4 | You may obtain a copy of Mulan PSL v2 at: 5 | http://license.coscl.org.cn/MulanPSL2 6 | THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, 7 | EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, 8 | MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. 9 | See the Mulan PSL v2 for more details. */ 10 | 11 | // 12 | // Created by Longda on 2010 13 | // 14 | 15 | #ifndef __COMMON_IO_SELECT_DIR_H__ 16 | #define __COMMON_IO_SELECT_DIR_H__ 17 | 18 | #include 19 | namespace common { 20 | 21 | class SelectDir { 22 | public: 23 | virtual std::string select() 24 | { 25 | return std::string(""); 26 | }; 27 | virtual void setBaseDir(std::string baseDir){}; 28 | }; 29 | 30 | } // namespace common 31 | #endif /* __COMMON_IO_SELECT_DIR_H__ */ 32 | -------------------------------------------------------------------------------- /deps/common/lang/bitmap.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2021 Xie Meiyi(xiemeiyi@hust.edu.cn) and OceanBase and/or its affiliates. All rights reserved. 2 | miniob is licensed under Mulan PSL v2. 3 | You can use this software according to the terms and conditions of the Mulan PSL v2. 4 | You may obtain a copy of Mulan PSL v2 at: 5 | http://license.coscl.org.cn/MulanPSL2 6 | THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, 7 | EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, 8 | MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. 9 | See the Mulan PSL v2 for more details. */ 10 | 11 | // 12 | // Created by wangyunlai on 2021/5/7. 13 | // 14 | 15 | #ifndef __COMMON_LANG_BITMAP_H__ 16 | #define __COMMON_LANG_BITMAP_H__ 17 | 18 | namespace common { 19 | 20 | class Bitmap { 21 | public: 22 | Bitmap(char *bitmap, int size); 23 | 24 | bool get_bit(int index); 25 | void set_bit(int index); 26 | void clear_bit(int index); 27 | 28 | int next_unsetted_bit(int start); 29 | int next_setted_bit(int start); 30 | 31 | private: 32 | char *bitmap_; 33 | int size_; 34 | }; 35 | 36 | } // namespace common 37 | 38 | #endif // __COMMON_LANG_BITMAP_H__ -------------------------------------------------------------------------------- /deps/common/math/random_generator.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2021 Xie Meiyi(xiemeiyi@hust.edu.cn) and OceanBase and/or its affiliates. All rights reserved. 2 | miniob is licensed under Mulan PSL v2. 3 | You can use this software according to the terms and conditions of the Mulan PSL v2. 4 | You may obtain a copy of Mulan PSL v2 at: 5 | http://license.coscl.org.cn/MulanPSL2 6 | THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, 7 | EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, 8 | MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. 9 | See the Mulan PSL v2 for more details. */ 10 | 11 | // 12 | // Created by Longda on 2021/4/20. 13 | // 14 | 15 | #include 16 | 17 | #include "common/math/random_generator.h" 18 | 19 | namespace common { 20 | 21 | RandomGenerator::RandomGenerator() : randomData(std::chrono::system_clock::now().time_since_epoch().count()) 22 | {} 23 | 24 | RandomGenerator::~RandomGenerator() 25 | {} 26 | 27 | unsigned int RandomGenerator::next() 28 | { 29 | 30 | return randomData(); 31 | } 32 | 33 | unsigned int RandomGenerator::next(unsigned int range) 34 | { 35 | if (range > 0) { 36 | return next() % range; 37 | } else { 38 | return 0; 39 | } 40 | } 41 | 42 | } // namespace common -------------------------------------------------------------------------------- /deps/common/math/random_generator.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2021 Xie Meiyi(xiemeiyi@hust.edu.cn) and OceanBase and/or its affiliates. All rights reserved. 2 | miniob is licensed under Mulan PSL v2. 3 | You can use this software according to the terms and conditions of the Mulan PSL v2. 4 | You may obtain a copy of Mulan PSL v2 at: 5 | http://license.coscl.org.cn/MulanPSL2 6 | THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, 7 | EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, 8 | MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. 9 | See the Mulan PSL v2 for more details. */ 10 | 11 | // 12 | // Created by Longda on 2021/4/20. 13 | // 14 | #ifndef __COMMON_MATH_RANDOM_GENERATOR_H_ 15 | #define __COMMON_MATH_RANDOM_GENERATOR_H_ 16 | 17 | #include 18 | #include 19 | namespace common { 20 | 21 | #define DEFAULT_RANDOM_BUFF_SIZE 512 22 | 23 | class RandomGenerator { 24 | 25 | public: 26 | RandomGenerator(); 27 | virtual ~RandomGenerator(); 28 | 29 | public: 30 | unsigned int next(); 31 | unsigned int next(unsigned int range); 32 | 33 | private: 34 | // The GUN Extended TLS Version 35 | std::mt19937 randomData; 36 | }; 37 | 38 | } // namespace common 39 | 40 | #endif /* __COMMON_MATH_RANDOM_GENERATOR_H_ */ 41 | -------------------------------------------------------------------------------- /deps/common/math/regex.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2021 Xie Meiyi(xiemeiyi@hust.edu.cn) and OceanBase and/or its affiliates. All rights reserved. 2 | miniob is licensed under Mulan PSL v2. 3 | You can use this software according to the terms and conditions of the Mulan PSL v2. 4 | You may obtain a copy of Mulan PSL v2 at: 5 | http://license.coscl.org.cn/MulanPSL2 6 | THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, 7 | EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, 8 | MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. 9 | See the Mulan PSL v2 for more details. */ 10 | 11 | // 12 | // Created by Longda on 2010 13 | // 14 | 15 | #include 16 | #include 17 | #include 18 | 19 | #include "common/math/regex.h" 20 | namespace common { 21 | 22 | int regex_match(const char *str_, const char *pat_) 23 | { 24 | regex_t reg; 25 | if (regcomp(®, pat_, REG_EXTENDED | REG_NOSUB)) 26 | return -1; 27 | 28 | int ret = regexec(®, str_, 0, NULL, 0); 29 | regfree(®); 30 | return ret; 31 | } 32 | 33 | } // namespace common -------------------------------------------------------------------------------- /deps/common/math/regex.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2021 Xie Meiyi(xiemeiyi@hust.edu.cn) and OceanBase and/or its affiliates. All rights reserved. 2 | miniob is licensed under Mulan PSL v2. 3 | You can use this software according to the terms and conditions of the Mulan PSL v2. 4 | You may obtain a copy of Mulan PSL v2 at: 5 | http://license.coscl.org.cn/MulanPSL2 6 | THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, 7 | EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, 8 | MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. 9 | See the Mulan PSL v2 for more details. */ 10 | 11 | // 12 | // Created by Longda on 2010 13 | // 14 | 15 | #ifndef __COMMON_MATH_REGEX_H__ 16 | #define __COMMON_MATH_REGEX_H__ 17 | namespace common { 18 | 19 | int regex_match(const char *str_, const char *pat_); 20 | 21 | } // namespace common 22 | #endif /* __COMMON_MATH_REGEX_H__ */ 23 | -------------------------------------------------------------------------------- /deps/common/metrics/console_reporter.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2021 Xie Meiyi(xiemeiyi@hust.edu.cn) and OceanBase and/or its affiliates. All rights reserved. 2 | miniob is licensed under Mulan PSL v2. 3 | You can use this software according to the terms and conditions of the Mulan PSL v2. 4 | You may obtain a copy of Mulan PSL v2 at: 5 | http://license.coscl.org.cn/MulanPSL2 6 | THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, 7 | EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, 8 | MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. 9 | See the Mulan PSL v2 for more details. */ 10 | 11 | // 12 | // Created by Longda on 2021/4/20. 13 | // 14 | 15 | #include "common/metrics/console_reporter.h" 16 | 17 | #include 18 | #include 19 | 20 | #include "common/metrics/metric.h" 21 | 22 | namespace common { 23 | 24 | ConsoleReporter *get_console_reporter() 25 | { 26 | static ConsoleReporter *instance = new ConsoleReporter(); 27 | 28 | return instance; 29 | } 30 | 31 | void ConsoleReporter::report(const std::string &tag, Metric *metric) 32 | { 33 | Snapshot *snapshot = metric->get_snapshot(); 34 | 35 | if (snapshot != NULL) { 36 | printf("%s:%s\n", tag.c_str(), snapshot->to_string().c_str()); 37 | } else { 38 | printf("There is no snapshot of %s metrics.", tag.c_str()); 39 | } 40 | } 41 | 42 | } // namespace common -------------------------------------------------------------------------------- /deps/common/metrics/console_reporter.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2021 Xie Meiyi(xiemeiyi@hust.edu.cn) and OceanBase and/or its affiliates. All rights reserved. 2 | miniob is licensed under Mulan PSL v2. 3 | You can use this software according to the terms and conditions of the Mulan PSL v2. 4 | You may obtain a copy of Mulan PSL v2 at: 5 | http://license.coscl.org.cn/MulanPSL2 6 | THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, 7 | EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, 8 | MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. 9 | See the Mulan PSL v2 for more details. */ 10 | 11 | // 12 | // Created by Longda on 2021/4/20. 13 | // 14 | 15 | #ifndef __COMMON_METRICS_CONSOLE_REPORTER_H__ 16 | #define __COMMON_METRICS_CONSOLE_REPORTER_H__ 17 | 18 | #include "common/metrics/reporter.h" 19 | 20 | namespace common { 21 | 22 | class ConsoleReporter : public Reporter { 23 | public: 24 | void report(const std::string &tag, Metric *metric); 25 | }; 26 | 27 | ConsoleReporter *get_console_reporter(); 28 | } // namespace common 29 | #endif //__COMMON_METRICS_CONSOLE_REPORTER_H__ 30 | -------------------------------------------------------------------------------- /deps/common/metrics/log_reporter.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2021 Xie Meiyi(xiemeiyi@hust.edu.cn) and OceanBase and/or its affiliates. All rights reserved. 2 | miniob is licensed under Mulan PSL v2. 3 | You can use this software according to the terms and conditions of the Mulan PSL v2. 4 | You may obtain a copy of Mulan PSL v2 at: 5 | http://license.coscl.org.cn/MulanPSL2 6 | THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, 7 | EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, 8 | MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. 9 | See the Mulan PSL v2 for more details. */ 10 | 11 | // 12 | // Created by Longda on 2021/4/20. 13 | // 14 | 15 | #include "common/metrics/log_reporter.h" 16 | 17 | #include 18 | 19 | #include "common/metrics/metric.h" 20 | #include "common/log/log.h" 21 | 22 | namespace common { 23 | 24 | LogReporter *get_log_reporter() 25 | { 26 | static LogReporter *instance = new LogReporter(); 27 | 28 | return instance; 29 | } 30 | 31 | void LogReporter::report(const std::string &tag, Metric *metric) 32 | { 33 | Snapshot *snapshot = metric->get_snapshot(); 34 | 35 | if (snapshot != NULL) { 36 | LOG_INFO("%s:%s", tag.c_str(), snapshot->to_string().c_str()); 37 | } else { 38 | LOG_WARN("There is no snapshot of %s metrics.", tag.c_str()); 39 | } 40 | } 41 | 42 | } // namespace common -------------------------------------------------------------------------------- /deps/common/metrics/log_reporter.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2021 Xie Meiyi(xiemeiyi@hust.edu.cn) and OceanBase and/or its affiliates. All rights reserved. 2 | miniob is licensed under Mulan PSL v2. 3 | You can use this software according to the terms and conditions of the Mulan PSL v2. 4 | You may obtain a copy of Mulan PSL v2 at: 5 | http://license.coscl.org.cn/MulanPSL2 6 | THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, 7 | EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, 8 | MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. 9 | See the Mulan PSL v2 for more details. */ 10 | 11 | // 12 | // Created by Longda on 2021/4/20. 13 | // 14 | 15 | #ifndef __COMMON_METRICS_LOG_REPORTER_H__ 16 | #define __COMMON_METRICS_LOG_REPORTER_H__ 17 | 18 | #include "common/metrics/reporter.h" 19 | 20 | namespace common { 21 | 22 | class LogReporter : public Reporter { 23 | public: 24 | void report(const std::string &tag, Metric *metric); 25 | }; 26 | 27 | LogReporter *get_log_reporter(); 28 | } // namespace common 29 | #endif //__COMMON_METRICS_LOG_REPORTER_H__ 30 | -------------------------------------------------------------------------------- /deps/common/metrics/metric.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2021 Xie Meiyi(xiemeiyi@hust.edu.cn) and OceanBase and/or its affiliates. All rights reserved. 2 | miniob is licensed under Mulan PSL v2. 3 | You can use this software according to the terms and conditions of the Mulan PSL v2. 4 | You may obtain a copy of Mulan PSL v2 at: 5 | http://license.coscl.org.cn/MulanPSL2 6 | THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, 7 | EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, 8 | MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. 9 | See the Mulan PSL v2 for more details. */ 10 | 11 | // 12 | // Created by Longda on 2021/4/20. 13 | // 14 | 15 | #ifndef __COMMON_METRICS_METRIC_H__ 16 | #define __COMMON_METRICS_METRIC_H__ 17 | 18 | #include "common/metrics/snapshot.h" 19 | 20 | namespace common { 21 | 22 | class Metric { 23 | public: 24 | virtual void snapshot() = 0; 25 | 26 | virtual Snapshot *get_snapshot() 27 | { 28 | return snapshot_value_; 29 | } 30 | 31 | protected: 32 | Snapshot *snapshot_value_; 33 | }; 34 | 35 | } // namespace common 36 | #endif //__COMMON_METRICS_METRIC_H__ 37 | -------------------------------------------------------------------------------- /deps/common/metrics/metrics_registry.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2021 Xie Meiyi(xiemeiyi@hust.edu.cn) and OceanBase and/or its affiliates. All rights reserved. 2 | miniob is licensed under Mulan PSL v2. 3 | You can use this software according to the terms and conditions of the Mulan PSL v2. 4 | You may obtain a copy of Mulan PSL v2 at: 5 | http://license.coscl.org.cn/MulanPSL2 6 | THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, 7 | EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, 8 | MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. 9 | See the Mulan PSL v2 for more details. */ 10 | 11 | // 12 | // Created by Longda on 2021/4/20. 13 | // 14 | 15 | #ifndef __COMMON_METRICS_METRICS_REGISTRY_H__ 16 | #define __COMMON_METRICS_METRICS_REGISTRY_H__ 17 | 18 | #include 19 | #include 20 | #include 21 | 22 | #include "common/metrics/metric.h" 23 | #include "common/metrics/reporter.h" 24 | 25 | namespace common { 26 | 27 | class MetricsRegistry { 28 | public: 29 | MetricsRegistry(){}; 30 | virtual ~MetricsRegistry(){}; 31 | 32 | void register_metric(const std::string &tag, Metric *metric); 33 | void unregister(const std::string &tag); 34 | 35 | void snapshot(); 36 | 37 | void report(); 38 | 39 | void add_reporter(Reporter *reporter) 40 | { 41 | reporters.push_back(reporter); 42 | } 43 | 44 | protected: 45 | std::map metrics; 46 | std::list reporters; 47 | }; 48 | 49 | MetricsRegistry &get_metrics_registry(); 50 | } // namespace common 51 | #endif //__COMMON_METRICS_METRICS_REGISTRY_H__ 52 | -------------------------------------------------------------------------------- /deps/common/metrics/reporter.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2021 Xie Meiyi(xiemeiyi@hust.edu.cn) and OceanBase and/or its affiliates. All rights reserved. 2 | miniob is licensed under Mulan PSL v2. 3 | You can use this software according to the terms and conditions of the Mulan PSL v2. 4 | You may obtain a copy of Mulan PSL v2 at: 5 | http://license.coscl.org.cn/MulanPSL2 6 | THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, 7 | EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, 8 | MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. 9 | See the Mulan PSL v2 for more details. */ 10 | 11 | // 12 | // Created by Longda on 2021/4/19. 13 | // 14 | 15 | #include "common/metrics/reporter.h" 16 | -------------------------------------------------------------------------------- /deps/common/metrics/reporter.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2021 Xie Meiyi(xiemeiyi@hust.edu.cn) and OceanBase and/or its affiliates. All rights reserved. 2 | miniob is licensed under Mulan PSL v2. 3 | You can use this software according to the terms and conditions of the Mulan PSL v2. 4 | You may obtain a copy of Mulan PSL v2 at: 5 | http://license.coscl.org.cn/MulanPSL2 6 | THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, 7 | EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, 8 | MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. 9 | See the Mulan PSL v2 for more details. */ 10 | 11 | // 12 | // Created by Longda on 2021/4/19. 13 | // 14 | 15 | #ifndef __COMMON_METRICS_REPORTER_H__ 16 | #define __COMMON_METRICS_REPORTER_H__ 17 | 18 | #include 19 | #include "common/metrics/metric.h" 20 | 21 | namespace common { 22 | 23 | class Reporter { 24 | public: 25 | virtual void report(const std::string &tag, Metric *metric) = 0; 26 | }; 27 | } // namespace common 28 | #endif //__COMMON_METRICS_REPORTER_H__ 29 | -------------------------------------------------------------------------------- /deps/common/metrics/reservoir.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2021 Xie Meiyi(xiemeiyi@hust.edu.cn) and OceanBase and/or its affiliates. All rights reserved. 2 | miniob is licensed under Mulan PSL v2. 3 | You can use this software according to the terms and conditions of the Mulan PSL v2. 4 | You may obtain a copy of Mulan PSL v2 at: 5 | http://license.coscl.org.cn/MulanPSL2 6 | THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, 7 | EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, 8 | MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. 9 | See the Mulan PSL v2 for more details. */ 10 | 11 | // 12 | // Created by Longda on 2021/4/20. 13 | // 14 | 15 | #include "reservoir.h" 16 | 17 | using namespace common; 18 | 19 | Reservoir::Reservoir(RandomGenerator &random) : random(random) 20 | {} 21 | 22 | Reservoir::~Reservoir() 23 | {} 24 | 25 | size_t Reservoir::next(size_t range) 26 | { 27 | return random.next(range); 28 | } 29 | -------------------------------------------------------------------------------- /deps/common/metrics/reservoir.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2021 Xie Meiyi(xiemeiyi@hust.edu.cn) and OceanBase and/or its affiliates. All rights reserved. 2 | miniob is licensed under Mulan PSL v2. 3 | You can use this software according to the terms and conditions of the Mulan PSL v2. 4 | You may obtain a copy of Mulan PSL v2 at: 5 | http://license.coscl.org.cn/MulanPSL2 6 | THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, 7 | EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, 8 | MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. 9 | See the Mulan PSL v2 for more details. */ 10 | 11 | // 12 | // Created by Longda on 2021/4/19. 13 | // 14 | 15 | #ifndef __COMMON_METRICS_RESERVOIR_H_ 16 | #define __COMMON_METRICS_RESERVOIR_H_ 17 | 18 | #include 19 | 20 | #include "common/math/random_generator.h" 21 | #include "common/metrics/metric.h" 22 | #include "common/metrics/snapshot.h" 23 | 24 | namespace common { 25 | 26 | class Reservoir : public Metric { 27 | public: 28 | Reservoir(RandomGenerator &random); 29 | virtual ~Reservoir(); 30 | 31 | public: 32 | virtual size_t size() = 0; 33 | virtual size_t get_count() = 0; 34 | 35 | virtual void update(double one) = 0; 36 | 37 | virtual void reset() = 0; 38 | 39 | protected: 40 | virtual size_t next(size_t range); 41 | 42 | private: 43 | RandomGenerator &random; 44 | }; 45 | 46 | } // namespace common 47 | 48 | #endif /* __COMMON_METRICS_RESERVOIR_H_ */ 49 | -------------------------------------------------------------------------------- /deps/common/metrics/sampler.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2021 Xie Meiyi(xiemeiyi@hust.edu.cn) and OceanBase and/or its affiliates. All rights reserved. 2 | miniob is licensed under Mulan PSL v2. 3 | You can use this software according to the terms and conditions of the Mulan PSL v2. 4 | You may obtain a copy of Mulan PSL v2 at: 5 | http://license.coscl.org.cn/MulanPSL2 6 | THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, 7 | EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, 8 | MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. 9 | See the Mulan PSL v2 for more details. */ 10 | 11 | // 12 | // Created by Longda on 2021/4/20. 13 | // 14 | 15 | #include "common/metrics/sampler.h" 16 | #include "common/log/log.h" 17 | 18 | #define RANGE_SIZE 100 19 | 20 | namespace common { 21 | 22 | Sampler *&get_sampler() 23 | { 24 | static Sampler *g_sampler = new Sampler(); 25 | 26 | return g_sampler; 27 | } 28 | 29 | Sampler::Sampler() : random_() 30 | {} 31 | 32 | Sampler::~Sampler() 33 | {} 34 | 35 | bool Sampler::sampling() 36 | { 37 | int v = random_.next(RANGE_SIZE); 38 | if (v <= ratio_num_) { 39 | return true; 40 | } else { 41 | return false; 42 | } 43 | } 44 | 45 | double Sampler::get_ratio() 46 | { 47 | return ratio_; 48 | } 49 | 50 | void Sampler::set_ratio(double ratio) 51 | { 52 | if (0 <= ratio && ratio <= 1) { 53 | this->ratio_ = ratio; 54 | ratio_num_ = ratio * RANGE_SIZE; 55 | } else { 56 | LOG_WARN("Invalid ratio :%lf", ratio); 57 | } 58 | } 59 | 60 | } // namespace common 61 | -------------------------------------------------------------------------------- /deps/common/metrics/sampler.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2021 Xie Meiyi(xiemeiyi@hust.edu.cn) and OceanBase and/or its affiliates. All rights reserved. 2 | miniob is licensed under Mulan PSL v2. 3 | You can use this software according to the terms and conditions of the Mulan PSL v2. 4 | You may obtain a copy of Mulan PSL v2 at: 5 | http://license.coscl.org.cn/MulanPSL2 6 | THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, 7 | EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, 8 | MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. 9 | See the Mulan PSL v2 for more details. */ 10 | 11 | // 12 | // Created by Longda on 2021/4/20. 13 | // 14 | 15 | #ifndef __COMMON_METRICS_SAMPLER_H__ 16 | #define __COMMON_METRICS_SAMPLER_H__ 17 | 18 | #include "common/math/random_generator.h" 19 | 20 | namespace common { 21 | 22 | /** 23 | * The most simple sample function 24 | */ 25 | class Sampler { 26 | public: 27 | Sampler(); 28 | virtual ~Sampler(); 29 | 30 | bool sampling(); 31 | 32 | void set_ratio(double ratio); 33 | double get_ratio(); 34 | 35 | private: 36 | double ratio_ = 1.0; 37 | int ratio_num_ = 1; 38 | RandomGenerator random_; 39 | }; 40 | 41 | Sampler *&get_sampler(); 42 | } // namespace common 43 | #endif //__COMMON_METRICS_SAMPLER_H__ 44 | -------------------------------------------------------------------------------- /deps/common/metrics/timer_snapshot.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2021 Xie Meiyi(xiemeiyi@hust.edu.cn) and OceanBase and/or its affiliates. All rights reserved. 2 | miniob is licensed under Mulan PSL v2. 3 | You can use this software according to the terms and conditions of the Mulan PSL v2. 4 | You may obtain a copy of Mulan PSL v2 at: 5 | http://license.coscl.org.cn/MulanPSL2 6 | THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, 7 | EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, 8 | MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. 9 | See the Mulan PSL v2 for more details. */ 10 | 11 | // 12 | // Created by Longda on 2021/4/20. 13 | // 14 | 15 | #include "common/metrics/timer_snapshot.h" 16 | #include 17 | 18 | namespace common { 19 | 20 | TimerSnapshot::TimerSnapshot() 21 | {} 22 | 23 | TimerSnapshot::~TimerSnapshot() 24 | {} 25 | 26 | double TimerSnapshot::get_tps() 27 | { 28 | return tps; 29 | } 30 | 31 | void TimerSnapshot::set_tps(double tps) 32 | { 33 | this->tps = tps; 34 | } 35 | 36 | std::string TimerSnapshot::to_string() 37 | { 38 | std::stringstream oss; 39 | 40 | oss << HistogramSnapShot::to_string() << ",tps:" << tps; 41 | 42 | return oss.str(); 43 | } 44 | } // namespace common -------------------------------------------------------------------------------- /deps/common/metrics/timer_snapshot.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2021 Xie Meiyi(xiemeiyi@hust.edu.cn) and OceanBase and/or its affiliates. All rights reserved. 2 | miniob is licensed under Mulan PSL v2. 3 | You can use this software according to the terms and conditions of the Mulan PSL v2. 4 | You may obtain a copy of Mulan PSL v2 at: 5 | http://license.coscl.org.cn/MulanPSL2 6 | THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, 7 | EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, 8 | MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. 9 | See the Mulan PSL v2 for more details. */ 10 | 11 | // 12 | // Created by Longda on 2021/4/20. 13 | // 14 | 15 | #ifndef __COMMON_METRICS_TIMER_SNAPSHOT_H__ 16 | #define __COMMON_METRICS_TIMER_SNAPSHOT_H__ 17 | 18 | #include "common/metrics/histogram_snapshot.h" 19 | 20 | namespace common { 21 | class TimerSnapshot : public HistogramSnapShot { 22 | public: 23 | TimerSnapshot(); 24 | virtual ~TimerSnapshot(); 25 | 26 | double get_tps(); 27 | void set_tps(double tps); 28 | 29 | std::string to_string(); 30 | 31 | protected: 32 | double tps = 1.0; 33 | }; 34 | } // namespace common 35 | #endif //__COMMON_METRICS_TIMER_SNAPSHOT_H__ 36 | -------------------------------------------------------------------------------- /deps/common/os/os.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2021 Xie Meiyi(xiemeiyi@hust.edu.cn) and OceanBase and/or its affiliates. All rights reserved. 2 | miniob is licensed under Mulan PSL v2. 3 | You can use this software according to the terms and conditions of the Mulan PSL v2. 4 | You may obtain a copy of Mulan PSL v2 at: 5 | http://license.coscl.org.cn/MulanPSL2 6 | THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, 7 | EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, 8 | MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. 9 | See the Mulan PSL v2 for more details. */ 10 | 11 | // 12 | // Created by Longda on 2010. 13 | // 14 | 15 | #include 16 | #include 17 | 18 | #include "common/defs.h" 19 | #include "common/os/os.h" 20 | #include "common/log/log.h" 21 | 22 | namespace common { 23 | // Don't care windows 24 | u32_t getCpuNum() 25 | { 26 | return std::thread::hardware_concurrency(); 27 | } 28 | 29 | #define MAX_STACK_SIZE 32 30 | 31 | void print_stacktrace() 32 | { 33 | int size = MAX_STACK_SIZE; 34 | void *array[MAX_STACK_SIZE]; 35 | int stack_num = backtrace(array, size); 36 | char **stacktrace = backtrace_symbols(array, stack_num); 37 | for (int i = 0; i < stack_num; ++i) { 38 | LOG_INFO("%d ----- %s\n", i, stacktrace[i]); 39 | } 40 | free(stacktrace); 41 | } 42 | 43 | } // namespace common -------------------------------------------------------------------------------- /deps/common/os/os.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2021 Xie Meiyi(xiemeiyi@hust.edu.cn) and OceanBase and/or its affiliates. All rights reserved. 2 | miniob is licensed under Mulan PSL v2. 3 | You can use this software according to the terms and conditions of the Mulan PSL v2. 4 | You may obtain a copy of Mulan PSL v2 at: 5 | http://license.coscl.org.cn/MulanPSL2 6 | THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, 7 | EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, 8 | MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. 9 | See the Mulan PSL v2 for more details. */ 10 | 11 | // 12 | // Created by Longda on 2010 13 | // 14 | 15 | #ifndef __COMMON_OS_OS_H__ 16 | #define __COMMON_OS_OS_H__ 17 | namespace common { 18 | 19 | u32_t getCpuNum(); 20 | 21 | void print_stacktrace(); 22 | 23 | } // namespace common 24 | #endif /* __COMMON_OS_OS_H__ */ 25 | -------------------------------------------------------------------------------- /deps/common/os/pidfile.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2021 Xie Meiyi(xiemeiyi@hust.edu.cn) and OceanBase and/or its affiliates. All rights reserved. 2 | miniob is licensed under Mulan PSL v2. 3 | You can use this software according to the terms and conditions of the Mulan PSL v2. 4 | You may obtain a copy of Mulan PSL v2 at: 5 | http://license.coscl.org.cn/MulanPSL2 6 | THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, 7 | EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, 8 | MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. 9 | See the Mulan PSL v2 for more details. */ 10 | 11 | // 12 | // Created by Longda on 2010 13 | // 14 | 15 | #ifndef __COMMON_OS_PIDFILE_H__ 16 | #define __COMMON_OS_PIDFILE_H__ 17 | namespace common { 18 | 19 | //! Generates a PID file for the current component 20 | /** 21 | * Gets the process ID (PID) of the calling process and writes a file 22 | * dervied from the input argument containing that value in a system 23 | * standard directory, e.g. /var/run/progName.pid 24 | * 25 | * @param[in] programName as basis for file to write 26 | * @return 0 for success, error otherwise 27 | */ 28 | int writePidFile(const char *progName); 29 | 30 | //! Cleanup PID file for the current component 31 | /** 32 | * Removes the PID file for the current component 33 | * 34 | */ 35 | void removePidFile(void); 36 | 37 | std::string &getPidPath(); 38 | 39 | } // namespace common 40 | #endif // __COMMON_OS_PIDFILE_H__ 41 | -------------------------------------------------------------------------------- /deps/common/os/process_param.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2021 Xie Meiyi(xiemeiyi@hust.edu.cn) and OceanBase and/or its affiliates. All rights reserved. 2 | miniob is licensed under Mulan PSL v2. 3 | You can use this software according to the terms and conditions of the Mulan PSL v2. 4 | You may obtain a copy of Mulan PSL v2 at: 5 | http://license.coscl.org.cn/MulanPSL2 6 | THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, 7 | EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, 8 | MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. 9 | See the Mulan PSL v2 for more details. */ 10 | 11 | // 12 | // Created by Longda on 2010 13 | // 14 | 15 | #include "process_param.h" 16 | #include 17 | namespace common { 18 | 19 | //! Global process config 20 | ProcessParam *&the_process_param() 21 | { 22 | static ProcessParam *process_cfg = new ProcessParam(); 23 | 24 | return process_cfg; 25 | } 26 | 27 | void ProcessParam::init_default(std::string &process_name) 28 | { 29 | assert(process_name.empty() == false); 30 | this->process_name_ = process_name; 31 | if (std_out_.empty()) { 32 | std_out_ = "../log/" + process_name + ".out"; 33 | } 34 | if (std_err_.empty()) { 35 | std_err_ = "../log/" + process_name + ".err"; 36 | } 37 | if (conf.empty()) { 38 | conf = "../etc/" + process_name + ".ini"; 39 | } 40 | 41 | demon = false; 42 | } 43 | 44 | } // namespace common -------------------------------------------------------------------------------- /deps/common/os/signal.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2021 Xie Meiyi(xiemeiyi@hust.edu.cn) and OceanBase and/or its affiliates. All rights reserved. 2 | miniob is licensed under Mulan PSL v2. 3 | You can use this software according to the terms and conditions of the Mulan PSL v2. 4 | You may obtain a copy of Mulan PSL v2 at: 5 | http://license.coscl.org.cn/MulanPSL2 6 | THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, 7 | EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, 8 | MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. 9 | See the Mulan PSL v2 for more details. */ 10 | 11 | // 12 | // Created by Longda on 2010 13 | // 14 | 15 | #ifndef __COMMON_OS_SIGNAL_H__ 16 | #define __COMMON_OS_SIGNAL_H__ 17 | 18 | #include 19 | 20 | namespace common { 21 | 22 | //! Default function that blocks signals. 23 | /** 24 | * Now it blocks SIGINT, SIGTERM, and SIGUSR1 25 | */ 26 | void blockDefaultSignals(sigset_t *signal_set, sigset_t *old_set); 27 | //! Default function that unblocks signals. 28 | /** 29 | * It unblocks SIGINT, SIGTERM,and SIGUSR1. 30 | */ 31 | void unBlockDefaultSignals(sigset_t *signal_set, sigset_t *old_set); 32 | 33 | void *waitForSignals(sigset_t *signal_set); 34 | void startWaitForSignals(sigset_t *signal_set); 35 | 36 | // Set signal handling function 37 | /** 38 | * handler function 39 | */ 40 | typedef void (*sighandler_t)(int); 41 | void setSignalHandler(sighandler_t func); 42 | void setSignalHandler(int sig, sighandler_t func); 43 | 44 | } // namespace common 45 | #endif /* __COMMON_OS_SIGNAL_H__ */ 46 | -------------------------------------------------------------------------------- /deps/common/seda/example_stage.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2021 Xie Meiyi(xiemeiyi@hust.edu.cn) and OceanBase and/or its affiliates. All rights reserved. 2 | miniob is licensed under Mulan PSL v2. 3 | You can use this software according to the terms and conditions of the Mulan PSL v2. 4 | You may obtain a copy of Mulan PSL v2 at: 5 | http://license.coscl.org.cn/MulanPSL2 6 | THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, 7 | EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, 8 | MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. 9 | See the Mulan PSL v2 for more details. */ 10 | 11 | // 12 | // Created by Longda on 2021/4/13. 13 | // 14 | 15 | #ifndef __COMMON_SEDA_EXAMPLE_STAGE_H__ 16 | #define __COMMON_SEDA_EXAMPLE_STAGE_H__ 17 | 18 | #include "common/seda/stage.h" 19 | 20 | namespace common { 21 | 22 | class ExampleStage : public Stage { 23 | public: 24 | ~ExampleStage(); 25 | static Stage *make_stage(const std::string &tag); 26 | 27 | protected: 28 | // common function 29 | ExampleStage(const char *tag); 30 | bool set_properties(); 31 | 32 | bool initialize(); 33 | void cleanup(); 34 | void handle_event(StageEvent *event); 35 | void callback_event(StageEvent *event, CallbackContext *context); 36 | }; 37 | } // namespace common 38 | #endif //__COMMON_SEDA_EXAMPLE_STAGE_H__ 39 | -------------------------------------------------------------------------------- /deps/common/seda/init.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2021 Xie Meiyi(xiemeiyi@hust.edu.cn) and OceanBase and/or its affiliates. All rights reserved. 2 | miniob is licensed under Mulan PSL v2. 3 | You can use this software according to the terms and conditions of the Mulan PSL v2. 4 | You may obtain a copy of Mulan PSL v2 at: 5 | http://license.coscl.org.cn/MulanPSL2 6 | THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, 7 | EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, 8 | MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. 9 | See the Mulan PSL v2 for more details. */ 10 | 11 | // 12 | // Created by Longda on 2010 13 | // 14 | 15 | #ifndef __COMMON_SEDA_INIT_H__ 16 | #define __COMMON_SEDA_INIT_H__ 17 | 18 | // Basic includes 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | #include "common/conf/ini.h" 28 | #include "common/defs.h" 29 | #include "common/os/process_param.h" 30 | namespace common { 31 | 32 | /** 33 | * start the seda process, do this will trigger all threads 34 | */ 35 | int init_seda(ProcessParam *process_cfg); 36 | 37 | void cleanup_seda(); 38 | 39 | } // namespace common 40 | #endif // __COMMON_SEDA_INIT_H__ 41 | -------------------------------------------------------------------------------- /deps/common/seda/kill_thread.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2021 Xie Meiyi(xiemeiyi@hust.edu.cn) and OceanBase and/or its affiliates. All rights reserved. 2 | miniob is licensed under Mulan PSL v2. 3 | You can use this software according to the terms and conditions of the Mulan PSL v2. 4 | You may obtain a copy of Mulan PSL v2 at: 5 | http://license.coscl.org.cn/MulanPSL2 6 | THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, 7 | EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, 8 | MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. 9 | See the Mulan PSL v2 for more details. */ 10 | 11 | // 12 | // Created by Longda on 2010 13 | // 14 | // Include Files 15 | #include "common/seda/kill_thread.h" 16 | 17 | #include 18 | 19 | #include "common/seda/thread_pool.h" 20 | namespace common { 21 | 22 | /** 23 | * Notify the pool and kill the thread 24 | * @param[in] event Pointer to event that must be handled. 25 | * 26 | * @post Call never returns. Thread is killed. Pool is notified. 27 | */ 28 | void KillThreadStage::handle_event(StageEvent *event) 29 | { 30 | get_pool()->thread_kill(); 31 | event->done(); 32 | this->release_event(); 33 | pthread_exit(0); 34 | } 35 | 36 | /** 37 | * Process properties of the classes 38 | * @pre class members are uninitialized 39 | * @post initializing the class members 40 | * @return the class object 41 | */ 42 | Stage *KillThreadStage::make_stage(const std::string &tag) 43 | { 44 | return new KillThreadStage(tag.c_str()); 45 | } 46 | 47 | bool KillThreadStage::set_properties() 48 | { 49 | // nothing to do 50 | return true; 51 | } 52 | 53 | } // namespace common -------------------------------------------------------------------------------- /deps/common/seda/metrics_report_event.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2021 Xie Meiyi(xiemeiyi@hust.edu.cn) and OceanBase and/or its affiliates. All rights reserved. 2 | miniob is licensed under Mulan PSL v2. 3 | You can use this software according to the terms and conditions of the Mulan PSL v2. 4 | You may obtain a copy of Mulan PSL v2 at: 5 | http://license.coscl.org.cn/MulanPSL2 6 | THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, 7 | EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, 8 | MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. 9 | See the Mulan PSL v2 for more details. */ 10 | 11 | // 12 | // Created by Longda on 2021/4/20. 13 | // 14 | 15 | #include "metrics_report_event.h" 16 | -------------------------------------------------------------------------------- /deps/common/seda/metrics_report_event.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2021 Xie Meiyi(xiemeiyi@hust.edu.cn) and OceanBase and/or its affiliates. All rights reserved. 2 | miniob is licensed under Mulan PSL v2. 3 | You can use this software according to the terms and conditions of the Mulan PSL v2. 4 | You may obtain a copy of Mulan PSL v2 at: 5 | http://license.coscl.org.cn/MulanPSL2 6 | THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, 7 | EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, 8 | MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. 9 | See the Mulan PSL v2 for more details. */ 10 | 11 | // 12 | // Created by Longda on 2021/4/20. 13 | // 14 | 15 | #ifndef __COMMON_SEDA_METRICS_REPORT_EVENT_H__ 16 | #define __COMMON_SEDA_METRICS_REPORT_EVENT_H__ 17 | 18 | #include "common/seda/stage_event.h" 19 | 20 | namespace common { 21 | class MetricsReportEvent : public StageEvent { 22 | public: 23 | MetricsReportEvent(){ 24 | 25 | }; 26 | 27 | ~MetricsReportEvent(){ 28 | 29 | }; 30 | }; 31 | } // namespace common 32 | #endif //__COMMON_SEDA_METRICS_REPORT_EVENT_H__ 33 | -------------------------------------------------------------------------------- /deps/common/seda/metrics_stage.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2021 Xie Meiyi(xiemeiyi@hust.edu.cn) and OceanBase and/or its affiliates. All rights reserved. 2 | miniob is licensed under Mulan PSL v2. 3 | You can use this software according to the terms and conditions of the Mulan PSL v2. 4 | You may obtain a copy of Mulan PSL v2 at: 5 | http://license.coscl.org.cn/MulanPSL2 6 | THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, 7 | EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, 8 | MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. 9 | See the Mulan PSL v2 for more details. */ 10 | 11 | // 12 | // Created by Longda on 2021/4/13. 13 | // 14 | 15 | #ifndef __COMMON_SEDA_METRICS_STAGE_H__ 16 | #define __COMMON_SEDA_METRICS_STAGE_H__ 17 | 18 | #include "common/seda/stage.h" 19 | 20 | namespace common { 21 | 22 | class MetricsStage : public Stage { 23 | public: 24 | ~MetricsStage(); 25 | static Stage *make_stage(const std::string &tag); 26 | 27 | protected: 28 | // common function 29 | MetricsStage(const char *tag); 30 | bool set_properties(); 31 | 32 | bool initialize(); 33 | void cleanup(); 34 | void handle_event(StageEvent *event); 35 | void callback_event(StageEvent *event, CallbackContext *context); 36 | 37 | protected: 38 | private: 39 | Stage *timer_stage_ = nullptr; 40 | // report metrics every @metric_report_interval_ seconds 41 | int metric_report_interval_ = 10; 42 | }; 43 | } // namespace common 44 | #endif //__COMMON_SEDA_METRICS_STAGE_H__ 45 | -------------------------------------------------------------------------------- /deps/common/seda/seda_defs.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2021 Xie Meiyi(xiemeiyi@hust.edu.cn) and OceanBase and/or its affiliates. All rights reserved. 2 | miniob is licensed under Mulan PSL v2. 3 | You can use this software according to the terms and conditions of the Mulan PSL v2. 4 | You may obtain a copy of Mulan PSL v2 at: 5 | http://license.coscl.org.cn/MulanPSL2 6 | THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, 7 | EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, 8 | MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. 9 | See the Mulan PSL v2 for more details. */ 10 | 11 | // 12 | // Created by Longda on 2021/4/21. 13 | // 14 | 15 | #ifndef __COMMON_SEDA_SEDA_DEFS_H__ 16 | #define __COMMON_SEDA_SEDA_DEFS_H__ 17 | 18 | #define SEDA_BASE_NAME "SEDA_BASE" 19 | #define THREAD_POOLS_NAME "ThreadPools" 20 | #define STAGES "STAGES" 21 | 22 | #define EVENT_HISTORY "EventHistory" 23 | #define MAX_EVENT_HISTORY_NUM "MaxEventHistoryNum" 24 | 25 | #define COUNT "count" 26 | 27 | #define THREAD_POOL_ID "ThreadId" 28 | 29 | #define NEXT_STAGES "NextStages" 30 | #define DEFAULT_THREAD_POOL "DefaultThreads" 31 | #define METRCS_REPORT_INTERVAL "MetricsReportInterval" 32 | 33 | #endif //__COMMON_SEDA_SEDA_DEFS_H__ 34 | -------------------------------------------------------------------------------- /deps/common/seda/stage_factory.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2021 Xie Meiyi(xiemeiyi@hust.edu.cn) and OceanBase and/or its affiliates. All rights reserved. 2 | miniob is licensed under Mulan PSL v2. 3 | You can use this software according to the terms and conditions of the Mulan PSL v2. 4 | You may obtain a copy of Mulan PSL v2 at: 5 | http://license.coscl.org.cn/MulanPSL2 6 | THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, 7 | EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, 8 | MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. 9 | See the Mulan PSL v2 for more details. */ 10 | 11 | // 12 | // Created by Longda on 2010 13 | // 14 | 15 | #ifndef __COMMON_SEDA_STAGE_FACTORY_H__ 16 | #define __COMMON_SEDA_STAGE_FACTORY_H__ 17 | 18 | #include "common/seda/class_factory.h" 19 | #include "common/seda/stage.h" 20 | namespace common { 21 | 22 | class Stage; 23 | 24 | typedef ClassFactory StageFactory; 25 | 26 | } // namespace common 27 | #endif // __COMMON_SEDA_STAGE_FACTORY_H__ 28 | -------------------------------------------------------------------------------- /deps/common/time/timeout_info.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2021 Xie Meiyi(xiemeiyi@hust.edu.cn) and OceanBase and/or its affiliates. All rights reserved. 2 | miniob is licensed under Mulan PSL v2. 3 | You can use this software according to the terms and conditions of the Mulan PSL v2. 4 | You may obtain a copy of Mulan PSL v2 at: 5 | http://license.coscl.org.cn/MulanPSL2 6 | THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, 7 | EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, 8 | MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. 9 | See the Mulan PSL v2 for more details. */ 10 | 11 | // 12 | // Created by Longda on 2010 13 | // 14 | 15 | #include "common/time/timeout_info.h" 16 | 17 | #include 18 | namespace common { 19 | 20 | TimeoutInfo::TimeoutInfo(time_t deadLine) : deadline_(deadLine), is_timed_out_(false), ref_cnt_(0) 21 | { 22 | MUTEX_INIT(&mutex_, NULL); 23 | } 24 | 25 | TimeoutInfo::~TimeoutInfo() 26 | { 27 | // unlock mutex_ as we locked it before 'delete this' 28 | MUTEX_UNLOCK(&mutex_); 29 | 30 | MUTEX_DESTROY(&mutex_); 31 | } 32 | 33 | void TimeoutInfo::attach() 34 | { 35 | MUTEX_LOCK(&mutex_); 36 | ref_cnt_++; 37 | MUTEX_UNLOCK(&mutex_); 38 | } 39 | 40 | void TimeoutInfo::detach() 41 | { 42 | MUTEX_LOCK(&mutex_); 43 | if (0 == --ref_cnt_) { 44 | delete this; 45 | return; 46 | } 47 | MUTEX_UNLOCK(&mutex_); 48 | } 49 | 50 | bool TimeoutInfo::has_timed_out() 51 | { 52 | MUTEX_LOCK(&mutex_); 53 | bool ret = is_timed_out_; 54 | if (!is_timed_out_) { 55 | struct timeval tv; 56 | gettimeofday(&tv, NULL); 57 | 58 | ret = is_timed_out_ = (tv.tv_sec >= deadline_); 59 | } 60 | MUTEX_UNLOCK(&mutex_); 61 | 62 | return ret; 63 | } 64 | 65 | } // namespace common -------------------------------------------------------------------------------- /deps/common/version.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2021 Xie Meiyi(xiemeiyi@hust.edu.cn) and OceanBase and/or its affiliates. All rights reserved. 2 | miniob is licensed under Mulan PSL v2. 3 | You can use this software according to the terms and conditions of the Mulan PSL v2. 4 | You may obtain a copy of Mulan PSL v2 at: 5 | http://license.coscl.org.cn/MulanPSL2 6 | THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, 7 | EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, 8 | MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. 9 | See the Mulan PSL v2 for more details. */ 10 | 11 | // 12 | // Created by Longda on 2010 13 | // 14 | 15 | #ifndef __COMMON_VERSION_H__ 16 | #define __COMMON_VERSION_H__ 17 | namespace common { 18 | 19 | #ifndef MAIJOR_VER 20 | #define MAIJOR_VER 1 21 | #endif 22 | 23 | #ifndef MINOR_VER 24 | #define MINOR_VER 0 25 | #endif 26 | 27 | #ifndef PATCH_VER 28 | #define PATCH_VER 0 29 | #endif 30 | 31 | #ifndef OTHER_VER 32 | #define OTHER_VER 1 33 | #endif 34 | 35 | #define STR1(R) #R 36 | #define STR2(R) STR1(R) 37 | 38 | #define VERSION_STR (STR2(MAIJOR_VER) "." STR2(MINOR_VER) "." STR2(PATCH_VER) "." STR2(OTHER_VER)) 39 | #define VERSION_NUM (MAIJOR_VER << 24 | MINOR_VER << 16 | PATCH_VER << 8 | OTHER_VER) 40 | 41 | } // namespace common 42 | #endif //__COMMON_VERSION_H__ 43 | -------------------------------------------------------------------------------- /docs/how_to_build.md: -------------------------------------------------------------------------------- 1 | # How to build 2 | 1. install cmake 3 | 4 | 5 | 6 | 2. build libevent 7 | 8 | ``` 9 | 10 | git submodule add https://github.com/libevent/libevent deps/libevent 11 | cd deps 12 | cd libevent 13 | git checkout release-2.1.12-stable 14 | mkdir build 15 | cd build 16 | cmake .. -DEVENT__DISABLE_OPENSSL=ON 17 | make 18 | sudo make install 19 | ``` 20 | 21 | 3. build google test 22 | ``` 23 | 24 | git submodule add https://github.com/google/googletest deps/googletest 25 | cd deps 26 | cd googletest 27 | mkdir build 28 | cd build 29 | cmake .. 30 | make 31 | sudo make install 32 | ``` 33 | 34 | 4. build jsoncpp 35 | ```shell 36 | 37 | git submodule add https://github.com/open-source-parsers/jsoncpp.git deps/jsoncpp 38 | cd deps 39 | cd jsoncpp 40 | mkdir build 41 | cd build 42 | cmake -DJSONCPP_WITH_TESTS=OFF -DJSONCPP_WITH_POST_BUILD_UNITTEST=OFF .. 43 | make 44 | sudo make install 45 | ``` 46 | 47 | 5. build miniob 48 | 49 | ```shell 50 | cd `project home` 51 | mkdir build 52 | cd build 53 | cmake .. 54 | make 55 | ``` 56 | -------------------------------------------------------------------------------- /gdbserver.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | gdb --args ./cmake-build-debug/bin/observer -f ./etc/observer.ini 3 | -------------------------------------------------------------------------------- /lexandyacc.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | cd src/observer/sql/parser && flex lex_sql.l && bison -d -b yacc_sql yacc_sql.y && cd ../../../../ && cd cmake-build-debug && cmake .. -DDEBUG=ON && make && cd ../ -------------------------------------------------------------------------------- /load_test.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | function load_data { 4 | desc_ret=$(echo "desc "$1";" | ./cmake-build-debug/bin/obclient) 5 | if [[ $desc_ret == *"No such table: $1"* ]]; then 6 | echo "table not exists" 7 | else 8 | echo "drop table "$1"; " | ./cmake-build-debug/bin/obclient 9 | fi 10 | input_file="test/test_load/$1" 11 | 12 | cat $input_file | ./cmake-build-debug/bin/obclient 13 | echo "" 14 | echo "load done!" 15 | } 16 | 17 | load_data "$1" 18 | ./cmake-build-debug/bin/obclient -------------------------------------------------------------------------------- /run_test.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | function run_single_test { 4 | input_file="test/test_case/$1/$2" 5 | output_file="test/test_out/$1/$2" 6 | ans="test/test_ans/$1/$2" 7 | diff_dir="diff" 8 | 9 | if [[ ! -d "test/test_out/$1" ]]; then 10 | echo "create dir out test/test_out/$1" 11 | mkdir -p "test/test_out/$1" 12 | fi 13 | 14 | cat $input_file | ./cmake-build-debug/bin/obclient > $output_file 15 | sed -i 's/^miniob\ >\ //' $output_file 16 | 17 | a=$(diff $output_file $ans) 18 | if [ $(echo $a | wc -w) -gt 0 ] 19 | then 20 | echo "$1/$2:FAILURE" 21 | cat $output_file > $1.$2.output 22 | cat $ans > $1.$2.ans 23 | else 24 | echo "$1/$2:SUCCESS" 25 | fi 26 | } 27 | 28 | function run_test { 29 | for file in ` ls test/test_case/$1 ` 30 | do 31 | run_single_test "$1" "$file" 32 | done 33 | } 34 | 35 | if [ $# -eq 1 ]; then 36 | if [[ "$1" == "all" ]]; then 37 | for dir in `ls test/test_case` 38 | do 39 | run_test "$dir" 40 | done 41 | else 42 | run_test "$1" 43 | fi 44 | else 45 | run_single_test "$1" "$2" 46 | fi 47 | -------------------------------------------------------------------------------- /server.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | if [[ "$1" == "gdb" ]]; then 3 | echo "running in debug mode $1" 4 | GDB="gdb --args" 5 | else 6 | GDB="" 7 | fi 8 | $GDB rm -rf miniob/db/sys/* 9 | $GDB ./cmake-build-debug/bin/observer -f ./etc/observer.ini 10 | -------------------------------------------------------------------------------- /src/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | PROJECT(miniob) 2 | MESSAGE("Begin to build " ${PROJECT_NAME}) 3 | MESSAGE(STATUS "This is PROJECT_BINARY_DIR dir " ${PROJECT_BINARY_DIR}) 4 | MESSAGE(STATUS "This is PROJECT_SOURCE_DIR dir " ${PROJECT_SOURCE_DIR}) 5 | 6 | 7 | ADD_SUBDIRECTORY(obclient) 8 | ADD_SUBDIRECTORY(observer) 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /src/obclient/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | PROJECT(obclient) 2 | MESSAGE("Begin to build " ${PROJECT_NAME}) 3 | MESSAGE(STATUS "This is PROJECT_BINARY_DIR dir " ${PROJECT_BINARY_DIR}) 4 | MESSAGE(STATUS "This is PROJECT_SOURCE_DIR dir " ${PROJECT_SOURCE_DIR}) 5 | 6 | 7 | #INCLUDE_DIRECTORIES([AFTER|BEFORE] [SYSTEM] dir1 dir2 ...) 8 | INCLUDE_DIRECTORIES(. ${PROJECT_SOURCE_DIR}/../../deps /usr/local/include SYSTEM) 9 | # 父cmake 设置的include_directories 和link_directories并不传导到子cmake里面 10 | #INCLUDE_DIRECTORIES(BEFORE ${CMAKE_INSTALL_PREFIX}/include) 11 | LINK_DIRECTORIES(/usr/local/lib ${PROJECT_BINARY_DIR}/../../lib) 12 | 13 | 14 | FILE(GLOB_RECURSE ALL_SRC *.cpp) 15 | FOREACH (F ${ALL_SRC}) 16 | 17 | SET(PRJ_SRC ${PRJ_SRC} ${F}) 18 | MESSAGE("Use " ${F}) 19 | 20 | ENDFOREACH (F) 21 | 22 | 23 | # 指定目标文件位置 24 | SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/../../bin) 25 | MESSAGE("Binary directory:" ${EXECUTABLE_OUTPUT_PATH}) 26 | ADD_EXECUTABLE(${PROJECT_NAME} ${PRJ_SRC}) 27 | TARGET_LINK_LIBRARIES(${PROJECT_NAME} common pthread dl) 28 | 29 | 30 | # Target 必须在定义 ADD_EXECUTABLE 之后, programs 不受这个限制 31 | # TARGETS和PROGRAMS 的默认权限是OWNER_EXECUTE, GROUP_EXECUTE, 和WORLD_EXECUTE,即755权限, programs 都是处理脚步类 32 | # 类型分为RUNTIME/LIBRARY/ARCHIVE, prog 33 | INSTALL(TARGETS ${PROJECT_NAME} RUNTIME DESTINATION bin) -------------------------------------------------------------------------------- /src/observer/event/execution_plan_event.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2021 Xie Meiyi(xiemeiyi@hust.edu.cn) and OceanBase and/or its affiliates. All rights reserved. 2 | miniob is licensed under Mulan PSL v2. 3 | You can use this software according to the terms and conditions of the Mulan PSL v2. 4 | You may obtain a copy of Mulan PSL v2 at: 5 | http://license.coscl.org.cn/MulanPSL2 6 | THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, 7 | EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, 8 | MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. 9 | See the Mulan PSL v2 for more details. */ 10 | 11 | // 12 | // Created by Wangyunlai on 2021/5/11. 13 | // 14 | 15 | #include "event/execution_plan_event.h" 16 | #include "event/sql_event.h" 17 | 18 | ExecutionPlanEvent::ExecutionPlanEvent(SQLStageEvent *sql_event, Query *sqls) : sql_event_(sql_event), sqls_(sqls) 19 | {} 20 | ExecutionPlanEvent::~ExecutionPlanEvent() 21 | { 22 | sql_event_ = nullptr; 23 | // if (sql_event_) { 24 | // sql_event_->doneImmediate(); 25 | // } 26 | 27 | query_destroy(sqls_); 28 | sqls_ = nullptr; 29 | } 30 | -------------------------------------------------------------------------------- /src/observer/event/execution_plan_event.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2021 Xie Meiyi(xiemeiyi@hust.edu.cn) and OceanBase and/or its affiliates. All rights reserved. 2 | miniob is licensed under Mulan PSL v2. 3 | You can use this software according to the terms and conditions of the Mulan PSL v2. 4 | You may obtain a copy of Mulan PSL v2 at: 5 | http://license.coscl.org.cn/MulanPSL2 6 | THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, 7 | EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, 8 | MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. 9 | See the Mulan PSL v2 for more details. */ 10 | 11 | // 12 | // Created by Wangyunlai on 2021/5/11. 13 | // 14 | 15 | #ifndef __OBSERVER_EVENT_EXECUTION_PLAN_EVENT_H__ 16 | #define __OBSERVER_EVENT_EXECUTION_PLAN_EVENT_H__ 17 | 18 | #include "common/seda/stage_event.h" 19 | #include "sql/parser/parse.h" 20 | 21 | class SQLStageEvent; 22 | 23 | class ExecutionPlanEvent : public common::StageEvent { 24 | public: 25 | ExecutionPlanEvent(SQLStageEvent *sql_event, Query *sqls); 26 | virtual ~ExecutionPlanEvent(); 27 | 28 | Query *sqls() const 29 | { 30 | return sqls_; 31 | } 32 | 33 | SQLStageEvent *sql_event() const 34 | { 35 | return sql_event_; 36 | } 37 | 38 | private: 39 | SQLStageEvent *sql_event_; 40 | Query *sqls_; 41 | }; 42 | 43 | #endif // __OBSERVER_EVENT_EXECUTION_PLAN_EVENT_H__ -------------------------------------------------------------------------------- /src/observer/event/session_event.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2021 Xie Meiyi(xiemeiyi@hust.edu.cn) and OceanBase and/or its affiliates. All rights reserved. 2 | miniob is licensed under Mulan PSL v2. 3 | You can use this software according to the terms and conditions of the Mulan PSL v2. 4 | You may obtain a copy of Mulan PSL v2 at: 5 | http://license.coscl.org.cn/MulanPSL2 6 | THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, 7 | EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, 8 | MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. 9 | See the Mulan PSL v2 for more details. */ 10 | 11 | // 12 | // Created by Longda on 2021/4/13. 13 | // 14 | 15 | #include "session_event.h" 16 | 17 | SessionEvent::SessionEvent(ConnectionContext *client) : client_(client) 18 | {} 19 | 20 | SessionEvent::~SessionEvent() 21 | {} 22 | 23 | ConnectionContext *SessionEvent::get_client() const 24 | { 25 | return client_; 26 | } 27 | 28 | const char *SessionEvent::get_response() const 29 | { 30 | return response_.c_str(); 31 | } 32 | 33 | void SessionEvent::set_response(const char *response) 34 | { 35 | set_response(response, strlen(response)); 36 | } 37 | 38 | void SessionEvent::set_response(const char *response, int len) 39 | { 40 | response_.assign(response, len); 41 | } 42 | 43 | void SessionEvent::set_response(std::string &&response) 44 | { 45 | response_ = std::move(response); 46 | } 47 | 48 | int SessionEvent::get_response_len() const 49 | { 50 | return response_.size(); 51 | } 52 | 53 | char *SessionEvent::get_request_buf() 54 | { 55 | return client_->buf; 56 | } 57 | 58 | int SessionEvent::get_request_buf_len() 59 | { 60 | return SOCKET_BUFFER_SIZE; 61 | } -------------------------------------------------------------------------------- /src/observer/event/session_event.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2021 Xie Meiyi(xiemeiyi@hust.edu.cn) and OceanBase and/or its affiliates. All rights reserved. 2 | miniob is licensed under Mulan PSL v2. 3 | You can use this software according to the terms and conditions of the Mulan PSL v2. 4 | You may obtain a copy of Mulan PSL v2 at: 5 | http://license.coscl.org.cn/MulanPSL2 6 | THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, 7 | EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, 8 | MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. 9 | See the Mulan PSL v2 for more details. */ 10 | 11 | // 12 | // Created by Longda on 2021/4/13. 13 | // 14 | 15 | #ifndef __OBSERVER_SESSION_SESSIONEVENT_H__ 16 | #define __OBSERVER_SESSION_SESSIONEVENT_H__ 17 | 18 | #include 19 | #include 20 | 21 | #include "common/seda/stage_event.h" 22 | #include "net/connection_context.h" 23 | 24 | class SessionEvent : public common::StageEvent { 25 | public: 26 | SessionEvent(ConnectionContext *client); 27 | virtual ~SessionEvent(); 28 | 29 | ConnectionContext *get_client() const; 30 | 31 | const char *get_response() const; 32 | void set_response(const char *response); 33 | void set_response(const char *response, int len); 34 | void set_response(std::string &&response); 35 | int get_response_len() const; 36 | char *get_request_buf(); 37 | int get_request_buf_len(); 38 | 39 | private: 40 | ConnectionContext *client_; 41 | 42 | std::string response_; 43 | }; 44 | 45 | #endif //__OBSERVER_SESSION_SESSIONEVENT_H__ 46 | -------------------------------------------------------------------------------- /src/observer/event/sql_event.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2021 Xie Meiyi(xiemeiyi@hust.edu.cn) and OceanBase and/or its affiliates. All rights reserved. 2 | miniob is licensed under Mulan PSL v2. 3 | You can use this software according to the terms and conditions of the Mulan PSL v2. 4 | You may obtain a copy of Mulan PSL v2 at: 5 | http://license.coscl.org.cn/MulanPSL2 6 | THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, 7 | EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, 8 | MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. 9 | See the Mulan PSL v2 for more details. */ 10 | 11 | // 12 | // Created by Longda on 2021/4/14. 13 | // 14 | 15 | #include "event/sql_event.h" 16 | #include "event/session_event.h" 17 | 18 | SQLStageEvent::SQLStageEvent(SessionEvent *event, std::string &sql) : session_event_(event), sql_(sql) 19 | {} 20 | 21 | SQLStageEvent::~SQLStageEvent() noexcept 22 | { 23 | if (session_event_ != nullptr) { 24 | session_event_ = nullptr; 25 | // SessionEvent *session_event = session_event_; 26 | // session_event_ = nullptr; 27 | // session_event->doneImmediate(); 28 | } 29 | } -------------------------------------------------------------------------------- /src/observer/event/sql_event.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2021 Xie Meiyi(xiemeiyi@hust.edu.cn) and OceanBase and/or its affiliates. All rights reserved. 2 | miniob is licensed under Mulan PSL v2. 3 | You can use this software according to the terms and conditions of the Mulan PSL v2. 4 | You may obtain a copy of Mulan PSL v2 at: 5 | http://license.coscl.org.cn/MulanPSL2 6 | THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, 7 | EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, 8 | MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. 9 | See the Mulan PSL v2 for more details. */ 10 | 11 | // 12 | // Created by Longda on 2021/4/14. 13 | // 14 | 15 | #ifndef __OBSERVER_SQL_EVENT_SQLEVENT_H__ 16 | #define __OBSERVER_SQL_EVENT_SQLEVENT_H__ 17 | 18 | #include "common/seda/stage_event.h" 19 | #include 20 | 21 | class SessionEvent; 22 | 23 | class SQLStageEvent : public common::StageEvent { 24 | public: 25 | SQLStageEvent(SessionEvent *event, std::string &sql); 26 | virtual ~SQLStageEvent() noexcept; 27 | 28 | const std::string &get_sql() const 29 | { 30 | return sql_; 31 | } 32 | 33 | SessionEvent *session_event() const 34 | { 35 | return session_event_; 36 | } 37 | 38 | private: 39 | SessionEvent *session_event_; 40 | std::string &sql_; 41 | // void *context_; 42 | }; 43 | 44 | #endif //__SRC_OBSERVER_SQL_EVENT_SQLEVENT_H__ 45 | -------------------------------------------------------------------------------- /src/observer/event/storage_event.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2021 Xie Meiyi(xiemeiyi@hust.edu.cn) and OceanBase and/or its affiliates. All rights reserved. 2 | miniob is licensed under Mulan PSL v2. 3 | You can use this software according to the terms and conditions of the Mulan PSL v2. 4 | You may obtain a copy of Mulan PSL v2 at: 5 | http://license.coscl.org.cn/MulanPSL2 6 | THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, 7 | EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, 8 | MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. 9 | See the Mulan PSL v2 for more details. */ 10 | 11 | // 12 | // Created by Longda on 2021/4/14. 13 | // 14 | 15 | #include "event/storage_event.h" 16 | #include "event/execution_plan_event.h" 17 | 18 | StorageEvent::StorageEvent(ExecutionPlanEvent *exe_event) : exe_event_(exe_event) 19 | {} 20 | 21 | StorageEvent::~StorageEvent() 22 | { 23 | exe_event_ = nullptr; 24 | // if (exe_event_ != nullptr) { 25 | // ExecutionPlanEvent *exe_event = exe_event_; 26 | // exe_event->doneImmediate(); 27 | // } 28 | } -------------------------------------------------------------------------------- /src/observer/event/storage_event.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2021 Xie Meiyi(xiemeiyi@hust.edu.cn) and OceanBase and/or its affiliates. All rights reserved. 2 | miniob is licensed under Mulan PSL v2. 3 | You can use this software according to the terms and conditions of the Mulan PSL v2. 4 | You may obtain a copy of Mulan PSL v2 at: 5 | http://license.coscl.org.cn/MulanPSL2 6 | THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, 7 | EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, 8 | MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. 9 | See the Mulan PSL v2 for more details. */ 10 | 11 | // 12 | // Created by Longda on 2021/4/14. 13 | // 14 | 15 | #ifndef __OBSERVER_SQL_EVENT_STORAGEEVENT_H__ 16 | #define __OBSERVER_SQL_EVENT_STORAGEEVENT_H__ 17 | 18 | #include "common/seda/stage_event.h" 19 | 20 | class ExecutionPlanEvent; 21 | 22 | class StorageEvent : public common::StageEvent { 23 | public: 24 | StorageEvent(ExecutionPlanEvent *exe_event); 25 | virtual ~StorageEvent(); 26 | 27 | ExecutionPlanEvent *exe_event() const 28 | { 29 | return exe_event_; 30 | } 31 | 32 | private: 33 | ExecutionPlanEvent *exe_event_; 34 | }; 35 | 36 | #endif //__OBSERVER_SQL_EVENT_STORAGEEVENT_H__ 37 | -------------------------------------------------------------------------------- /src/observer/ini_setting.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2021 Xie Meiyi(xiemeiyi@hust.edu.cn) and OceanBase and/or its affiliates. All rights reserved. 2 | miniob is licensed under Mulan PSL v2. 3 | You can use this software according to the terms and conditions of the Mulan PSL v2. 4 | You may obtain a copy of Mulan PSL v2 at: 5 | http://license.coscl.org.cn/MulanPSL2 6 | THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, 7 | EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, 8 | MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. 9 | See the Mulan PSL v2 for more details. */ 10 | 11 | // 12 | // Created by Longda on 2021/4/14. 13 | // 14 | 15 | #ifndef __SRC_OBSERVER_INI_SETTING_H__ 16 | #define __SRC_OBSERVER_INI_SETTING_H__ 17 | 18 | //! this document is used for ini setting 19 | 20 | #define CLIENT_ADDRESS "CLIENT_ADDRESS" 21 | #define MAX_CONNECTION_NUM "MAX_CONNECTION_NUM" 22 | #define MAX_CONNECTION_NUM_DEFAULT 8192 23 | #define PORT "PORT" 24 | #define PORT_DEFAULT 16880 25 | 26 | #define SOCKET_BUFFER_SIZE 8192 27 | 28 | #define SESSION_STAGE_NAME "SessionStage" 29 | #endif //__SRC_OBSERVER_INI_SETTING_H__ 30 | -------------------------------------------------------------------------------- /src/observer/init.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2021 Xie Meiyi(xiemeiyi@hust.edu.cn) and OceanBase and/or its affiliates. All rights reserved. 2 | miniob is licensed under Mulan PSL v2. 3 | You can use this software according to the terms and conditions of the Mulan PSL v2. 4 | You may obtain a copy of Mulan PSL v2 at: 5 | http://license.coscl.org.cn/MulanPSL2 6 | THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, 7 | EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, 8 | MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. 9 | See the Mulan PSL v2 for more details. */ 10 | 11 | // 12 | // Created by Longda on 2021/5/3. 13 | // 14 | 15 | #ifndef __OBSERVER_INIT_H__ 16 | #define __OBSERVER_INIT_H__ 17 | 18 | #include "common/os/process_param.h" 19 | #include "common/conf/ini.h" 20 | 21 | int init(common::ProcessParam *processParam); 22 | void cleanup(); 23 | 24 | #endif //__OBSERVER_INIT_H__ 25 | -------------------------------------------------------------------------------- /src/observer/net/connection_context.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2021 Xie Meiyi(xiemeiyi@hust.edu.cn) and OceanBase and/or its affiliates. All rights reserved. 2 | miniob is licensed under Mulan PSL v2. 3 | You can use this software according to the terms and conditions of the Mulan PSL v2. 4 | You may obtain a copy of Mulan PSL v2 at: 5 | http://license.coscl.org.cn/MulanPSL2 6 | THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, 7 | EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, 8 | MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. 9 | See the Mulan PSL v2 for more details. */ 10 | 11 | // 12 | // Created by Longda on 2021/4/13. 13 | // 14 | 15 | #ifndef __SRC_OBSERVER_NET_CONNECTION_CONTEXT_H__ 16 | #define __SRC_OBSERVER_NET_CONNECTION_CONTEXT_H__ 17 | 18 | #include 19 | #include 20 | 21 | class Session; 22 | 23 | typedef struct _ConnectionContext { 24 | Session *session; 25 | int fd; 26 | struct event read_event; 27 | pthread_mutex_t mutex; 28 | char addr[24]; 29 | char buf[SOCKET_BUFFER_SIZE]; 30 | } ConnectionContext; 31 | 32 | #endif //__SRC_OBSERVER_NET_CONNECTION_CONTEXT_H__ 33 | -------------------------------------------------------------------------------- /src/observer/net/server_param.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2021 Xie Meiyi(xiemeiyi@hust.edu.cn) and OceanBase and/or its affiliates. All rights reserved. 2 | miniob is licensed under Mulan PSL v2. 3 | You can use this software according to the terms and conditions of the Mulan PSL v2. 4 | You may obtain a copy of Mulan PSL v2 at: 5 | http://license.coscl.org.cn/MulanPSL2 6 | THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, 7 | EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, 8 | MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. 9 | See the Mulan PSL v2 for more details. */ 10 | 11 | // 12 | // Created by Longda on 2021/4/13. 13 | // 14 | 15 | #ifndef __SRC_OBSERVER_NET_SERVER_PARAM_H__ 16 | #define __SRC_OBSERVER_NET_SERVER_PARAM_H__ 17 | 18 | #include 19 | 20 | class ServerParam { 21 | public: 22 | ServerParam(); 23 | 24 | ServerParam(const ServerParam &other) = default; 25 | ~ServerParam() = default; 26 | 27 | public: 28 | // accpet client's address, default is INADDR_ANY, means accept every address 29 | long listen_addr; 30 | 31 | int max_connection_num; 32 | // server listing port 33 | int port; 34 | 35 | std::string unix_socket_path; 36 | 37 | // 如果使用标准输入输出作为通信条件,就不再监听端口 38 | bool use_unix_socket = false; 39 | }; 40 | 41 | #endif //__SRC_OBSERVER_NET_SERVER_PARAM_H__ 42 | -------------------------------------------------------------------------------- /src/observer/session/session.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2021 Xie Meiyi(xiemeiyi@hust.edu.cn) and OceanBase and/or its affiliates. All rights reserved. 2 | miniob is licensed under Mulan PSL v2. 3 | You can use this software according to the terms and conditions of the Mulan PSL v2. 4 | You may obtain a copy of Mulan PSL v2 at: 5 | http://license.coscl.org.cn/MulanPSL2 6 | THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, 7 | EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, 8 | MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. 9 | See the Mulan PSL v2 for more details. */ 10 | 11 | // 12 | // Created by Wangyunlai on 2021/5/12. 13 | // 14 | 15 | #include "session/session.h" 16 | #include "storage/trx/trx.h" 17 | 18 | Session &Session::default_session() 19 | { 20 | static Session session; 21 | return session; 22 | } 23 | 24 | Session::Session(const Session &other) : current_db_(other.current_db_) 25 | {} 26 | 27 | Session::~Session() 28 | { 29 | delete trx_; 30 | trx_ = nullptr; 31 | } 32 | 33 | const std::string &Session::get_current_db() const 34 | { 35 | return current_db_; 36 | } 37 | void Session::set_current_db(const std::string &dbname) 38 | { 39 | current_db_ = dbname; 40 | } 41 | 42 | void Session::set_trx_multi_operation_mode(bool multi_operation_mode) 43 | { 44 | trx_multi_operation_mode_ = multi_operation_mode; 45 | } 46 | 47 | bool Session::is_trx_multi_operation_mode() const 48 | { 49 | return trx_multi_operation_mode_; 50 | } 51 | 52 | Trx *Session::current_trx() 53 | { 54 | if (trx_ == nullptr) { 55 | trx_ = new Trx; 56 | } 57 | return trx_; 58 | } 59 | -------------------------------------------------------------------------------- /src/observer/session/session.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2021 Xie Meiyi(xiemeiyi@hust.edu.cn) and OceanBase and/or its affiliates. All rights reserved. 2 | miniob is licensed under Mulan PSL v2. 3 | You can use this software according to the terms and conditions of the Mulan PSL v2. 4 | You may obtain a copy of Mulan PSL v2 at: 5 | http://license.coscl.org.cn/MulanPSL2 6 | THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, 7 | EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, 8 | MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. 9 | See the Mulan PSL v2 for more details. */ 10 | 11 | // 12 | // Created by Wangyunlai on 2021/5/12. 13 | // 14 | 15 | #ifndef __OBSERVER_SESSION_SESSION_H__ 16 | #define __OBSERVER_SESSION_SESSION_H__ 17 | 18 | #include 19 | 20 | class Trx; 21 | 22 | class Session { 23 | public: 24 | // static Session ¤t(); 25 | static Session &default_session(); 26 | 27 | public: 28 | Session() = default; 29 | ~Session(); 30 | 31 | Session(const Session &other); 32 | void operator=(Session &) = delete; 33 | 34 | const std::string &get_current_db() const; 35 | void set_current_db(const std::string &dbname); 36 | 37 | void set_trx_multi_operation_mode(bool multi_operation_mode); 38 | bool is_trx_multi_operation_mode() const; 39 | 40 | Trx *current_trx(); 41 | 42 | private: 43 | std::string current_db_; 44 | Trx *trx_ = nullptr; 45 | bool trx_multi_operation_mode_ = false; // 当前事务的模式,是否多语句模式. 单语句模式自动提交 46 | }; 47 | 48 | #endif // __OBSERVER_SESSION_SESSION_H__ -------------------------------------------------------------------------------- /src/observer/sql/executor/execute_stage.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2021 Xie Meiyi(xiemeiyi@hust.edu.cn) and OceanBase and/or its affiliates. All rights reserved. 2 | miniob is licensed under Mulan PSL v2. 3 | You can use this software according to the terms and conditions of the Mulan PSL v2. 4 | You may obtain a copy of Mulan PSL v2 at: 5 | http://license.coscl.org.cn/MulanPSL2 6 | THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, 7 | EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, 8 | MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. 9 | See the Mulan PSL v2 for more details. */ 10 | 11 | // 12 | // Created by Longda on 2021/4/13. 13 | // 14 | 15 | #ifndef __OBSERVER_SQL_EXECUTE_STAGE_H__ 16 | #define __OBSERVER_SQL_EXECUTE_STAGE_H__ 17 | 18 | #include "common/seda/stage.h" 19 | #include "sql/parser/parse.h" 20 | #include "rc.h" 21 | 22 | class SessionEvent; 23 | 24 | class ExecuteStage : public common::Stage { 25 | public: 26 | ~ExecuteStage(); 27 | static Stage *make_stage(const std::string &tag); 28 | 29 | protected: 30 | // common function 31 | ExecuteStage(const char *tag); 32 | bool set_properties() override; 33 | 34 | bool initialize() override; 35 | void cleanup() override; 36 | void handle_event(common::StageEvent *event) override; 37 | void callback_event(common::StageEvent *event, common::CallbackContext *context) override; 38 | 39 | void handle_request(common::StageEvent *event); 40 | RC do_select(const char *db, Query *sql, SessionEvent *session_event); 41 | 42 | protected: 43 | private: 44 | Stage *default_storage_stage_ = nullptr; 45 | Stage *mem_storage_stage_ = nullptr; 46 | }; 47 | 48 | #endif //__OBSERVER_SQL_EXECUTE_STAGE_H__ 49 | -------------------------------------------------------------------------------- /src/observer/sql/executor/execution_node.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2021 Xie Meiyi(xiemeiyi@hust.edu.cn) and OceanBase and/or its affiliates. All rights reserved. 2 | miniob is licensed under Mulan PSL v2. 3 | You can use this software according to the terms and conditions of the Mulan PSL v2. 4 | You may obtain a copy of Mulan PSL v2 at: 5 | http://license.coscl.org.cn/MulanPSL2 6 | THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, 7 | EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, 8 | MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. 9 | See the Mulan PSL v2 for more details. */ 10 | 11 | // 12 | // Created by Meiyi & Wangyunlai on 2021/5/13. 13 | // 14 | 15 | #ifndef __OBSERVER_SQL_EXECUTOR_EXECUTION_NODE_H_ 16 | #define __OBSERVER_SQL_EXECUTOR_EXECUTION_NODE_H_ 17 | 18 | #include 19 | #include "storage/common/condition_filter.h" 20 | #include "sql/executor/tuple.h" 21 | 22 | class Table; 23 | class Trx; 24 | 25 | class ExecutionNode { 26 | public: 27 | ExecutionNode() = default; 28 | virtual ~ExecutionNode() = default; 29 | 30 | virtual RC execute(TupleSet &tuple_set) = 0; 31 | }; 32 | 33 | class SelectExeNode : public ExecutionNode { 34 | public: 35 | SelectExeNode(); 36 | virtual ~SelectExeNode(); 37 | 38 | RC init( 39 | Trx *trx, Table *table, TupleSchema &&tuple_schema, std::vector &&condition_filters); 40 | 41 | RC execute(TupleSet &tuple_set) override; 42 | 43 | private: 44 | Trx *trx_ = nullptr; 45 | Table *table_; 46 | TupleSchema tuple_schema_; 47 | std::vector condition_filters_; 48 | }; 49 | 50 | #endif //__OBSERVER_SQL_EXECUTOR_EXECUTION_NODE_H_ 51 | -------------------------------------------------------------------------------- /src/observer/sql/executor/value.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2021 Xie Meiyi(xiemeiyi@hust.edu.cn) and OceanBase and/or its affiliates. All rights reserved. 2 | miniob is licensed under Mulan PSL v2. 3 | You can use this software according to the terms and conditions of the Mulan PSL v2. 4 | You may obtain a copy of Mulan PSL v2 at: 5 | http://license.coscl.org.cn/MulanPSL2 6 | THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, 7 | EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, 8 | MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. 9 | See the Mulan PSL v2 for more details. */ 10 | -------------------------------------------------------------------------------- /src/observer/sql/optimizer/optimize_stage.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2021 Xie Meiyi(xiemeiyi@hust.edu.cn) and OceanBase and/or its affiliates. All rights reserved. 2 | miniob is licensed under Mulan PSL v2. 3 | You can use this software according to the terms and conditions of the Mulan PSL v2. 4 | You may obtain a copy of Mulan PSL v2 at: 5 | http://license.coscl.org.cn/MulanPSL2 6 | THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, 7 | EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, 8 | MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. 9 | See the Mulan PSL v2 for more details. */ 10 | 11 | // 12 | // Created by Longda on 2021/4/13. 13 | // 14 | 15 | #ifndef __OBSERVER_SQL_OPTIMIZE_STAGE_H__ 16 | #define __OBSERVER_SQL_OPTIMIZE_STAGE_H__ 17 | 18 | #include "common/seda/stage.h" 19 | 20 | class OptimizeStage : public common::Stage { 21 | public: 22 | ~OptimizeStage(); 23 | static Stage *make_stage(const std::string &tag); 24 | 25 | protected: 26 | // common function 27 | OptimizeStage(const char *tag); 28 | bool set_properties(); 29 | 30 | bool initialize(); 31 | void cleanup(); 32 | void handle_event(common::StageEvent *event); 33 | void callback_event(common::StageEvent *event, common::CallbackContext *context); 34 | 35 | protected: 36 | private: 37 | Stage *execute_stage = nullptr; 38 | }; 39 | 40 | #endif //__OBSERVER_SQL_OPTIMIZE_STAGE_H__ 41 | -------------------------------------------------------------------------------- /src/observer/sql/parser/parse.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2021 Xie Meiyi(xiemeiyi@hust.edu.cn) and OceanBase and/or its affiliates. All rights reserved. 2 | miniob is licensed under Mulan PSL v2. 3 | You can use this software according to the terms and conditions of the Mulan PSL v2. 4 | You may obtain a copy of Mulan PSL v2 at: 5 | http://license.coscl.org.cn/MulanPSL2 6 | THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, 7 | EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, 8 | MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. 9 | See the Mulan PSL v2 for more details. */ 10 | 11 | // 12 | // Created by Meiyi 13 | // 14 | 15 | #ifndef __OBSERVER_SQL_PARSER_PARSE_H__ 16 | #define __OBSERVER_SQL_PARSER_PARSE_H__ 17 | 18 | #include "rc.h" 19 | #include "sql/parser/parse_defs.h" 20 | 21 | RC parse(const char *st, Query *sqln); 22 | 23 | #endif //__OBSERVER_SQL_PARSER_PARSE_H__ 24 | -------------------------------------------------------------------------------- /src/observer/sql/parser/parse_stage.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2021 Xie Meiyi(xiemeiyi@hust.edu.cn) and OceanBase and/or its affiliates. All rights reserved. 2 | miniob is licensed under Mulan PSL v2. 3 | You can use this software according to the terms and conditions of the Mulan PSL v2. 4 | You may obtain a copy of Mulan PSL v2 at: 5 | http://license.coscl.org.cn/MulanPSL2 6 | THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, 7 | EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, 8 | MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. 9 | See the Mulan PSL v2 for more details. */ 10 | 11 | // 12 | // Created by Longda on 2021/4/13. 13 | // 14 | 15 | #ifndef __OBSERVER_SQL_PARSE_STAGE_H__ 16 | #define __OBSERVER_SQL_PARSE_STAGE_H__ 17 | 18 | #include "common/seda/stage.h" 19 | 20 | class ParseStage : public common::Stage { 21 | public: 22 | ~ParseStage(); 23 | static Stage *make_stage(const std::string &tag); 24 | 25 | protected: 26 | // common function 27 | ParseStage(const char *tag); 28 | bool set_properties(); 29 | 30 | bool initialize(); 31 | void cleanup(); 32 | void handle_event(common::StageEvent *event); 33 | void callback_event(common::StageEvent *event, common::CallbackContext *context); 34 | 35 | protected: 36 | common::StageEvent *handle_request(common::StageEvent *event); 37 | 38 | private: 39 | Stage *optimize_stage_ = nullptr; 40 | }; 41 | 42 | #endif //__OBSERVER_SQL_PARSE_STAGE_H__ 43 | -------------------------------------------------------------------------------- /src/observer/sql/parser/resolve_stage.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2021 Xie Meiyi(xiemeiyi@hust.edu.cn) and OceanBase and/or its affiliates. All rights reserved. 2 | miniob is licensed under Mulan PSL v2. 3 | You can use this software according to the terms and conditions of the Mulan PSL v2. 4 | You may obtain a copy of Mulan PSL v2 at: 5 | http://license.coscl.org.cn/MulanPSL2 6 | THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, 7 | EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, 8 | MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. 9 | See the Mulan PSL v2 for more details. */ 10 | 11 | // 12 | // Created by Longda on 2021/4/13. 13 | // 14 | 15 | #ifndef __OBSERVER_SQL_RESOLVE_STAGE_H__ 16 | #define __OBSERVER_SQL_RESOLVE_STAGE_H__ 17 | 18 | #include "common/seda/stage.h" 19 | 20 | class ResolveStage : public common::Stage { 21 | public: 22 | ~ResolveStage(); 23 | static Stage *make_stage(const std::string &tag); 24 | 25 | protected: 26 | // common function 27 | ResolveStage(const char *tag); 28 | bool set_properties(); 29 | 30 | bool initialize(); 31 | void cleanup(); 32 | void handle_event(common::StageEvent *event); 33 | void callback_event(common::StageEvent *event, common::CallbackContext *context); 34 | 35 | protected: 36 | private: 37 | Stage *query_cache_stage = nullptr; 38 | }; 39 | 40 | #endif //__OBSERVER_SQL_RESOLVE_STAGE_H__ 41 | -------------------------------------------------------------------------------- /src/observer/sql/plan_cache/plan_cache_stage.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2021 Xie Meiyi(xiemeiyi@hust.edu.cn) and OceanBase and/or its affiliates. All rights reserved. 2 | miniob is licensed under Mulan PSL v2. 3 | You can use this software according to the terms and conditions of the Mulan PSL v2. 4 | You may obtain a copy of Mulan PSL v2 at: 5 | http://license.coscl.org.cn/MulanPSL2 6 | THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, 7 | EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, 8 | MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. 9 | See the Mulan PSL v2 for more details. */ 10 | 11 | // 12 | // Created by Longda on 2021/4/13. 13 | // 14 | 15 | #ifndef __OBSERVER_SQL_PLAN_CACHE_STAGE_H__ 16 | #define __OBSERVER_SQL_PLAN_CACHE_STAGE_H__ 17 | 18 | #include "common/seda/stage.h" 19 | 20 | class PlanCacheStage : public common::Stage { 21 | public: 22 | ~PlanCacheStage(); 23 | static Stage *make_stage(const std::string &tag); 24 | 25 | protected: 26 | // common function 27 | PlanCacheStage(const char *tag); 28 | bool set_properties(); 29 | 30 | bool initialize(); 31 | void cleanup(); 32 | void handle_event(common::StageEvent *event); 33 | void callback_event(common::StageEvent *event, common::CallbackContext *context); 34 | 35 | protected: 36 | private: 37 | Stage *parse_stage = nullptr; 38 | Stage *execute_stage = nullptr; 39 | }; 40 | 41 | #endif //__OBSERVER_SQL_PLAN_CACHE_STAGE_H__ 42 | -------------------------------------------------------------------------------- /src/observer/sql/query_cache/query_cache_stage.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2021 Xie Meiyi(xiemeiyi@hust.edu.cn) and OceanBase and/or its affiliates. All rights reserved. 2 | miniob is licensed under Mulan PSL v2. 3 | You can use this software according to the terms and conditions of the Mulan PSL v2. 4 | You may obtain a copy of Mulan PSL v2 at: 5 | http://license.coscl.org.cn/MulanPSL2 6 | THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, 7 | EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, 8 | MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. 9 | See the Mulan PSL v2 for more details. */ 10 | 11 | // 12 | // Created by Longda on 2021/4/13. 13 | // 14 | 15 | #ifndef __OBSERVER_SQL_QUERY_CACHE_STAGE_H__ 16 | #define __OBSERVER_SQL_QUERY_CACHE_STAGE_H__ 17 | 18 | #include "common/seda/stage.h" 19 | 20 | class QueryCacheStage : public common::Stage { 21 | public: 22 | ~QueryCacheStage(); 23 | static Stage *make_stage(const std::string &tag); 24 | 25 | protected: 26 | // common function 27 | QueryCacheStage(const char *tag); 28 | bool set_properties(); 29 | 30 | bool initialize(); 31 | void cleanup(); 32 | void handle_event(common::StageEvent *event); 33 | void callback_event(common::StageEvent *event, common::CallbackContext *context); 34 | 35 | protected: 36 | private: 37 | Stage *plan_cache_stage = nullptr; 38 | }; 39 | 40 | #endif //__OBSERVER_SQL_QUERY_CACHE_STAGE_H__ 41 | -------------------------------------------------------------------------------- /src/observer/storage/common/db.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2021 Xie Meiyi(xiemeiyi@hust.edu.cn) and OceanBase and/or its affiliates. All rights reserved. 2 | miniob is licensed under Mulan PSL v2. 3 | You can use this software according to the terms and conditions of the Mulan PSL v2. 4 | You may obtain a copy of Mulan PSL v2 at: 5 | http://license.coscl.org.cn/MulanPSL2 6 | THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, 7 | EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, 8 | MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. 9 | See the Mulan PSL v2 for more details. */ 10 | 11 | // 12 | // Created by Meiyi & Longda & Wangyunlai on 2021/5/12. 13 | // 14 | 15 | #ifndef __OBSERVER_STORAGE_COMMON_DB_H__ 16 | #define __OBSERVER_STORAGE_COMMON_DB_H__ 17 | 18 | #include 19 | #include 20 | #include 21 | 22 | #include "rc.h" 23 | #include "sql/parser/parse_defs.h" 24 | 25 | class Table; 26 | 27 | class Db { 28 | public: 29 | Db() = default; 30 | ~Db(); 31 | 32 | RC init(const char *name, const char *dbpath); 33 | 34 | RC create_table(const char *table_name, int attribute_count, const AttrInfo *attributes); 35 | 36 | Table *find_table(const char *table_name) const; 37 | 38 | const char *name() const; 39 | 40 | void all_tables(std::vector &table_names) const; 41 | 42 | RC sync(); 43 | 44 | private: 45 | RC open_all_tables(); 46 | 47 | private: 48 | std::string name_; 49 | std::string path_; 50 | std::unordered_map opened_tables_; 51 | }; 52 | 53 | #endif // __OBSERVER_STORAGE_COMMON_DB_H__ -------------------------------------------------------------------------------- /src/observer/storage/common/index.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2021 Xie Meiyi(xiemeiyi@hust.edu.cn) and OceanBase and/or its affiliates. All rights reserved. 2 | miniob is licensed under Mulan PSL v2. 3 | You can use this software according to the terms and conditions of the Mulan PSL v2. 4 | You may obtain a copy of Mulan PSL v2 at: 5 | http://license.coscl.org.cn/MulanPSL2 6 | THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, 7 | EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, 8 | MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. 9 | See the Mulan PSL v2 for more details. */ 10 | 11 | // 12 | // Created by Meiyi & wangyunlai.wyl on 2021/5/19. 13 | // 14 | 15 | #include "storage/common/index.h" 16 | 17 | RC Index::init(const IndexMeta &index_meta, const FieldMeta &field_meta) 18 | { 19 | index_meta_ = index_meta; 20 | field_meta_ = field_meta; 21 | return RC::SUCCESS; 22 | } -------------------------------------------------------------------------------- /src/observer/storage/common/index_meta.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2021 Xie Meiyi(xiemeiyi@hust.edu.cn) and OceanBase and/or its affiliates. All rights reserved. 2 | miniob is licensed under Mulan PSL v2. 3 | You can use this software according to the terms and conditions of the Mulan PSL v2. 4 | You may obtain a copy of Mulan PSL v2 at: 5 | http://license.coscl.org.cn/MulanPSL2 6 | THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, 7 | EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, 8 | MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. 9 | See the Mulan PSL v2 for more details. */ 10 | 11 | // 12 | // Created by Meiyi & Wangyunlai on 2021/5/12. 13 | // 14 | 15 | #ifndef __OBSERVER_STORAGE_COMMON_INDEX_META_H__ 16 | #define __OBSERVER_STORAGE_COMMON_INDEX_META_H__ 17 | 18 | #include 19 | #include "rc.h" 20 | 21 | class TableMeta; 22 | class FieldMeta; 23 | 24 | namespace Json { 25 | class Value; 26 | } // namespace Json 27 | 28 | class IndexMeta { 29 | public: 30 | IndexMeta() = default; 31 | 32 | RC init(const char *name, const FieldMeta &field); 33 | 34 | public: 35 | const char *name() const; 36 | const char *field() const; 37 | 38 | void desc(std::ostream &os) const; 39 | 40 | public: 41 | void to_json(Json::Value &json_value) const; 42 | static RC from_json(const TableMeta &table, const Json::Value &json_value, IndexMeta &index); 43 | 44 | protected: 45 | std::string name_; // index's name 46 | std::string field_; // field's name 47 | }; 48 | #endif // __OBSERVER_STORAGE_COMMON_INDEX_META_H__ -------------------------------------------------------------------------------- /src/observer/storage/common/meta_util.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2021 Xie Meiyi(xiemeiyi@hust.edu.cn) and OceanBase and/or its affiliates. All rights reserved. 2 | miniob is licensed under Mulan PSL v2. 3 | You can use this software according to the terms and conditions of the Mulan PSL v2. 4 | You may obtain a copy of Mulan PSL v2 at: 5 | http://license.coscl.org.cn/MulanPSL2 6 | THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, 7 | EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, 8 | MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. 9 | See the Mulan PSL v2 for more details. */ 10 | 11 | // Created by Meiyi & wangyunlai.wyl on 2021/5/18. 12 | // 13 | 14 | #include "common/defs.h" 15 | #include "storage/common/meta_util.h" 16 | 17 | std::string table_meta_file(const char *base_dir, const char *table_name) 18 | { 19 | return std::string(base_dir) + common::FILE_PATH_SPLIT_STR + table_name + TABLE_META_SUFFIX; 20 | } 21 | std::string table_data_file(const char *base_dir, const char *table_name) 22 | { 23 | return std::string(base_dir) + common::FILE_PATH_SPLIT_STR + table_name + TABLE_DATA_SUFFIX; 24 | } 25 | 26 | std::string table_index_file(const char *base_dir, const char *table_name, const char *index_name) 27 | { 28 | return std::string(base_dir) + common::FILE_PATH_SPLIT_STR + table_name + "-" + index_name + TABLE_INDEX_SUFFIX; 29 | } 30 | -------------------------------------------------------------------------------- /src/observer/storage/common/meta_util.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2021 Xie Meiyi(xiemeiyi@hust.edu.cn) and OceanBase and/or its affiliates. All rights reserved. 2 | miniob is licensed under Mulan PSL v2. 3 | You can use this software according to the terms and conditions of the Mulan PSL v2. 4 | You may obtain a copy of Mulan PSL v2 at: 5 | http://license.coscl.org.cn/MulanPSL2 6 | THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, 7 | EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, 8 | MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. 9 | See the Mulan PSL v2 for more details. */ 10 | 11 | // Created by Meiyi & wangyunlai.wyl on 2021/5/18. 12 | // 13 | 14 | #ifndef __OBSERVER_STORAGE_COMMON_META_UTIL_H_ 15 | #define __OBSERVER_STORAGE_COMMON_META_UTIL_H_ 16 | 17 | #include 18 | 19 | static const char *TABLE_META_SUFFIX = ".table"; 20 | static const char *TABLE_META_FILE_PATTERN = ".*\\.table$"; 21 | static const char *TABLE_DATA_SUFFIX = ".data"; 22 | static const char *TABLE_INDEX_SUFFIX = ".index"; 23 | 24 | std::string table_meta_file(const char *base_dir, const char *table_name); 25 | std::string table_data_file(const char *base_dir, const char *table_name); 26 | std::string table_index_file(const char *base_dir, const char *table_name, const char *index_name); 27 | 28 | #endif //__OBSERVER_STORAGE_COMMON_META_UTIL_H_ 29 | -------------------------------------------------------------------------------- /src/observer/storage/default/default_storage_stage.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2021 Xie Meiyi(xiemeiyi@hust.edu.cn) and OceanBase and/or its affiliates. All rights reserved. 2 | miniob is licensed under Mulan PSL v2. 3 | You can use this software according to the terms and conditions of the Mulan PSL v2. 4 | You may obtain a copy of Mulan PSL v2 at: 5 | http://license.coscl.org.cn/MulanPSL2 6 | THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, 7 | EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, 8 | MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. 9 | See the Mulan PSL v2 for more details. */ 10 | 11 | // 12 | // Created by Meiyi & Longda on 2021/4/13. 13 | // 14 | 15 | #ifndef __OBSERVER_STORAGE_DEFAULT_STORAGE_STAGE_H__ 16 | #define __OBSERVER_STORAGE_DEFAULT_STORAGE_STAGE_H__ 17 | 18 | #include "common/seda/stage.h" 19 | #include "common/metrics/metrics.h" 20 | 21 | class DefaultHandler; 22 | 23 | class DefaultStorageStage : public common::Stage { 24 | public: 25 | ~DefaultStorageStage(); 26 | static Stage *make_stage(const std::string &tag); 27 | 28 | protected: 29 | // common function 30 | DefaultStorageStage(const char *tag); 31 | bool set_properties() override; 32 | 33 | bool initialize() override; 34 | void cleanup() override; 35 | void handle_event(common::StageEvent *event) override; 36 | void callback_event(common::StageEvent *event, common::CallbackContext *context) override; 37 | 38 | private: 39 | std::string load_data(const char *db_name, const char *table_name, const char *file_name); 40 | 41 | protected: 42 | common::SimpleTimer *query_metric_ = nullptr; 43 | static const std::string QUERY_METRIC_TAG; 44 | 45 | private: 46 | DefaultHandler *handler_; 47 | }; 48 | 49 | #endif //__OBSERVER_STORAGE_DEFAULT_STORAGE_STAGE_H__ 50 | -------------------------------------------------------------------------------- /src/observer/storage/mem/mem_storage_stage.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2021 Xie Meiyi(xiemeiyi@hust.edu.cn) and OceanBase and/or its affiliates. All rights reserved. 2 | miniob is licensed under Mulan PSL v2. 3 | You can use this software according to the terms and conditions of the Mulan PSL v2. 4 | You may obtain a copy of Mulan PSL v2 at: 5 | http://license.coscl.org.cn/MulanPSL2 6 | THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, 7 | EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, 8 | MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. 9 | See the Mulan PSL v2 for more details. */ 10 | 11 | // 12 | // Created by Longda on 2021/4/13. 13 | // 14 | 15 | #ifndef __OBSERVER_STORAGE_MEM_STORAGE_STAGE_H__ 16 | #define __OBSERVER_STORAGE_MEM_STORAGE_STAGE_H__ 17 | 18 | #include "common/seda/stage.h" 19 | #include "common/metrics/metrics.h" 20 | 21 | class MemStorageStage : public common::Stage { 22 | public: 23 | ~MemStorageStage(); 24 | static Stage *make_stage(const std::string &tag); 25 | 26 | protected: 27 | // common function 28 | MemStorageStage(const char *tag); 29 | bool set_properties(); 30 | 31 | bool initialize(); 32 | void cleanup(); 33 | void handle_event(common::StageEvent *event); 34 | void callback_event(common::StageEvent *event, common::CallbackContext *context); 35 | 36 | protected: 37 | common::SimpleTimer *queryMetric = nullptr; 38 | static const std::string QUERY_METRIC_TAG; 39 | 40 | private: 41 | }; 42 | 43 | #endif //__OBSERVER_STORAGE_MEM_STORAGE_STAGE_H__ 44 | -------------------------------------------------------------------------------- /test/case/README.md: -------------------------------------------------------------------------------- 1 | # miniob-test 2 | miniob自动化功能测试 3 | 使用方法参考 miniob_test.py 4 | 5 | -------------------------------------------------------------------------------- /test/case/case-scores.json: -------------------------------------------------------------------------------- 1 | { 2 | "basic":{"necessary":true, "score":10}, 3 | "primary-date":{"necessary":true, "score":10}, 4 | "primary-update":{"necessary":true, "score":10}, 5 | "primary-select-meta":{"necessary":true, "score":10}, 6 | "primary-select-tables":{"necessary":true, "score":10}, 7 | "primary-aggregation-func":{"necessary":true, "score":10}, 8 | "primary-drop-table":{"necessary":true, "score":10}, 9 | 10 | "primary-insert":{"necessary":false, "score":10}, 11 | "primary-join-tables":{"necessary":false, "score":20}, 12 | "primary-null":{"necessary":false, "score":10}, 13 | "primary-unique":{"necessary":false, "score":10}, 14 | "primary-simple-sub-query":{"necessary":false, "score":10}, 15 | "primary-multi-index":{"necessary":false, "score":20}, 16 | "primary-text":{"necessary":false, "score":20}, 17 | "primary-expression":{"necessary":false, "score":20}, 18 | "primary-complex-sub-query":{"necessary":false, "score":20}, 19 | "primary-order-by":{"necessary":false, "score":10}, 20 | "primary-group-by":{"necessary":false, "score":20} 21 | } 22 | -------------------------------------------------------------------------------- /test/case/result/primary-drop-table.result: -------------------------------------------------------------------------------- 1 | 1. DROP EMPTY TABLE 2 | CREATE TABLE Drop_table_1(id int, t_name char); 3 | SUCCESS 4 | DROP TABLE Drop_table_1; 5 | SUCCESS 6 | 7 | 2. DROP NON-EMPTY TABLE 8 | CREATE TABLE Drop_table_2(id int, t_name char); 9 | SUCCESS 10 | INSERT INTO Drop_table_2 VALUES (1,'OB'); 11 | SUCCESS 12 | DROP TABLE Drop_table_2; 13 | SUCCESS 14 | 15 | 3. CHECK THE ACCURACY OF DROPPING TABLE 16 | CREATE TABLE Drop_table_3(id int, t_name char); 17 | SUCCESS 18 | INSERT INTO Drop_table_3 VALUES (1,'OB'); 19 | SUCCESS 20 | SELECT * FROM Drop_table_3; 21 | 1 | OB 22 | ID | T_NAME 23 | DROP TABLE Drop_table_3; 24 | SUCCESS 25 | INSERT INTO Drop_table_3 VALUES (1,'OB'); 26 | FAILURE 27 | SELECT * FROM Drop_table_3; 28 | FAILURE 29 | DELETE FROM Drop_table_3 WHERE id = 3; 30 | FAILURE 31 | CREATE TABLE Drop_table_3(id int, t_name char); 32 | SUCCESS 33 | SELECT * FROM Drop_table_3; 34 | ID | T_NAME 35 | 36 | 4. DROP NON-EXISTENT TABLE 37 | CREATE TABLE Drop_table_4(id int, t_name char); 38 | SUCCESS 39 | DROP TABLE Drop_table_4; 40 | SUCCESS 41 | DROP TABLE Drop_table_4; 42 | FAILURE 43 | DROP TABLE Drop_table_4_1; 44 | FAILURE 45 | 46 | 5. CREATE A TABLE WHICH HAS DROPPED 47 | CREATE TABLE Drop_table_5(id int, t_name char); 48 | SUCCESS 49 | DROP TABLE Drop_table_5; 50 | SUCCESS 51 | CREATE TABLE Drop_table_5(id int, t_name char); 52 | SUCCESS 53 | SELECT * FROM Drop_table_5; 54 | ID | T_NAME 55 | 56 | 6. DROP A TABLE WITH INDEX 57 | CREATE TABLE Drop_table_6(id int, t_name char); 58 | SUCCESS 59 | CREATE INDEX index_id on Drop_table_6(id); 60 | SUCCESS 61 | INSERT INTO Drop_table_6 VALUES (1,'OB'); 62 | SUCCESS 63 | SELECT * FROM Drop_table_6; 64 | 1 | OB 65 | ID | T_NAME 66 | DROP TABLE Drop_table_6; 67 | SUCCESS 68 | SELECT * FROM Drop_table_6; 69 | FAILURE 70 | -------------------------------------------------------------------------------- /test/case/result/primary-insert.result: -------------------------------------------------------------------------------- 1 | INITIALIZATION 2 | CREATE TABLE insert_table(id int, t_name char, col1 int, col2 int); 3 | SUCCESS 4 | 5 | 1. INSERT 6 | INSERT INTO insert_table VALUES (1,'N1',1,1); 7 | SUCCESS 8 | INSERT INTO insert_table VALUES (2,'N2',1,1),(3,'N3',2,1); 9 | SUCCESS 10 | 11 | 2. ERROR 12 | INSERT INTO insert_table VALUES (4,'N4',1,1),(1,1,1); 13 | FAILURE 14 | INSERT INTO insert_table VALUES (4,'N4',1,1),(1,1,1,1); 15 | FAILURE 16 | 17 | 3. SELECT 18 | SELECT * FROM insert_table; 19 | 1 | N1 | 1 | 1 20 | 2 | N2 | 1 | 1 21 | 3 | N3 | 2 | 1 22 | ID | T_NAME | COL1 | COL2 23 | -------------------------------------------------------------------------------- /test/case/result/primary-select-meta.result: -------------------------------------------------------------------------------- 1 | INITIALIZATION 2 | CREATE TABLE Select_meta(id int, age int); 3 | SUCCESS 4 | 5 | 1. SELECT FROM A NON-EXISTENT TABLE 6 | select * from no_table; 7 | FAILURE 8 | 9 | 2. SELECT FROM A NON-EXISTENT COLUMN 10 | select home from Select_meta; 11 | FAILURE 12 | select * from Select_meta where home='001'; 13 | FAILURE 14 | -------------------------------------------------------------------------------- /test/case/result/primary-unique.result: -------------------------------------------------------------------------------- 1 | INITIALIZATION 2 | CREATE TABLE unique_table(id int, col1 int, col2 int); 3 | SUCCESS 4 | INSERT INTO unique_table VALUES (1,1,1); 5 | SUCCESS 6 | 7 | 1. UNIQUE TEST 8 | CREATE UNIQUE INDEX index_id on unique_table(id); 9 | SUCCESS 10 | INSERT INTO unique_table VALUES (2,1,1); 11 | SUCCESS 12 | CREATE UNIQUE INDEX index_id on unique_table(id); 13 | FAILURE 14 | INSERT INTO unique_table VALUES (3,2,1); 15 | SUCCESS 16 | INSERT INTO unique_table VALUES (1,2,1); 17 | FAILURE 18 | 19 | 2. SELECT 20 | SELECT * FROM unique_table; 21 | 1 | 1 | 1 22 | 2 | 1 | 1 23 | 3 | 2 | 1 24 | ID | COL1 | COL2 25 | -------------------------------------------------------------------------------- /test/case/test/.primary-update.test.swp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/obcontest/miniob_final/5722f31f846ba608d7ff264e045ee8ee59daa520/test/case/test/.primary-update.test.swp -------------------------------------------------------------------------------- /test/case/test/basic.test: -------------------------------------------------------------------------------- 1 | -- echo basic insert 2 | 3 | create table t_basic(id int, age int, name char, score float); 4 | insert into t_basic values(1,1, 'a', 1.0); 5 | insert into t_basic values(2,2, 'b', 2.0); 6 | insert into t_basic values(4,4, 'c', 3.0); 7 | insert into t_basic values(3,3, 'd', 4.0); 8 | insert into t_basic values(5,5, 'e', 5.5); 9 | insert into t_basic values(6,6, 'f', 6.6); 10 | insert into t_basic values(7,7, 'g', 7.7); 11 | 12 | --sort select * from t_basic; 13 | 14 | -- echo basic delete 15 | delete from t_basic where id=3; 16 | -- sort select * from t_basic; 17 | 18 | -- echo basic select 19 | select * from t_basic where id=1; 20 | 21 | -- sort select * from t_basic where id>=5; 22 | 23 | select * from t_basic where age>1 and age<3; 24 | 25 | select * from t_basic where t_basic.id=1 and t_basic.age=1; 26 | 27 | select * from t_basic where id=1 and age=1; 28 | 29 | -- sort select id, age, name, score from t_basic; 30 | 31 | -- sort select t_basic.id, t_basic.age, t_basic.name, t_basic.score from t_basic; 32 | 33 | -- sort select t_basic.id, t_basic.age, name from t_basic; 34 | 35 | -- echo create index 36 | create index i_id on t_basic (id); 37 | -- sort select * from t_basic; 38 | -------------------------------------------------------------------------------- /test/case/test/primary-date.test: -------------------------------------------------------------------------------- 1 | -- echo initialization 2 | CREATE TABLE date_table(id int, u_date date); 3 | CREATE INDEX index_id on date_table(u_date); 4 | 5 | -- echo 1. insert normal date data 6 | INSERT INTO date_table VALUES (1,'2020-01-21'); 7 | INSERT INTO date_table VALUES (2,'2020-10-21'); 8 | INSERT INTO date_table VALUES (3,'2020-1-01'); 9 | INSERT INTO date_table VALUES (4,'2020-01-1'); 10 | INSERT INTO date_table VALUES (5,'2019-12-21'); 11 | INSERT INTO date_table VALUES (6,'2016-2-29'); 12 | INSERT INTO date_table VALUES (7,'1970-1-1'); 13 | INSERT INTO date_table VALUES (8,'2000-01-01'); 14 | INSERT INTO date_table VALUES (9,'2038-1-19'); 15 | 16 | -- echo 2. compare date data 17 | -- sort SELECT * FROM date_table WHERE u_date>'2020-1-20'; 18 | -- sort SELECT * FROM date_table WHERE u_date<'2019-12-31'; 19 | -- sort SELECT * FROM date_table WHERE u_date='2020-1-1'; 20 | 21 | -- echo 3. delete data 22 | DELETE FROM date_table WHERE u_date>'2012-2-29'; 23 | -- sort SELECT * FROM date_table; 24 | 25 | -- echo 4. check invalid date data 26 | SELECT * FROM date_table WHERE u_date='2017-2-29'; 27 | SELECT * FROM date_table WHERE u_date='2017-21-29'; 28 | SELECT * FROM date_table WHERE u_date='2017-12-32'; 29 | SELECT * FROM date_table WHERE u_date='2017-11-31'; 30 | 31 | INSERT INTO date_table VALUES (10,'2017-2-29'); 32 | INSERT INTO date_table VALUES (11,'2017-21-29'); 33 | INSERT INTO date_table VALUES (12,'2017-12-32'); 34 | INSERT INTO date_table VALUES (13,'2017-11-31'); 35 | -------------------------------------------------------------------------------- /test/case/test/primary-drop-table.test: -------------------------------------------------------------------------------- 1 | -- echo 1. Drop empty table 2 | CREATE TABLE Drop_table_1(id int, t_name char); 3 | DROP TABLE Drop_table_1; 4 | 5 | -- echo 2. Drop non-empty table 6 | CREATE TABLE Drop_table_2(id int, t_name char); 7 | INSERT INTO Drop_table_2 VALUES (1,'OB'); 8 | DROP TABLE Drop_table_2; 9 | 10 | -- echo 3. Check the accuracy of dropping table 11 | CREATE TABLE Drop_table_3(id int, t_name char); 12 | INSERT INTO Drop_table_3 VALUES (1,'OB'); 13 | -- sort SELECT * FROM Drop_table_3; 14 | DROP TABLE Drop_table_3; 15 | INSERT INTO Drop_table_3 VALUES (1,'OB'); 16 | SELECT * FROM Drop_table_3; 17 | DELETE FROM Drop_table_3 WHERE id = 3; 18 | CREATE TABLE Drop_table_3(id int, t_name char); 19 | -- sort SELECT * FROM Drop_table_3; 20 | 21 | -- echo 4. Drop non-existent table 22 | CREATE TABLE Drop_table_4(id int, t_name char); 23 | DROP TABLE Drop_table_4; 24 | DROP TABLE Drop_table_4; 25 | DROP TABLE Drop_table_4_1; 26 | 27 | -- echo 5. Create a table which has dropped 28 | CREATE TABLE Drop_table_5(id int, t_name char); 29 | DROP TABLE Drop_table_5; 30 | CREATE TABLE Drop_table_5(id int, t_name char); 31 | SELECT * FROM Drop_table_5; 32 | 33 | -- echo 6. Drop a table with index 34 | CREATE TABLE Drop_table_6(id int, t_name char); 35 | CREATE INDEX index_id on Drop_table_6(id); 36 | INSERT INTO Drop_table_6 VALUES (1,'OB'); 37 | -- sort SELECT * FROM Drop_table_6; 38 | DROP TABLE Drop_table_6; 39 | SELECT * FROM Drop_table_6; 40 | -------------------------------------------------------------------------------- /test/case/test/primary-group-by.test: -------------------------------------------------------------------------------- 1 | -- echo 1. create table 2 | create table t_group_by (id int, score float, name char); 3 | create table t_group_by_2 (id int, age int); 4 | 5 | -- echo 2. insert records 6 | insert into t_group_by values(3, 1.0, 'a'); 7 | insert into t_group_by values(1, 2.0, 'b'); 8 | insert into t_group_by values(4, 3.0, 'c'); 9 | insert into t_group_by values(3, 2.0, 'c'); 10 | insert into t_group_by values(3, 4.0, 'c'); 11 | insert into t_group_by values(3, 3.0, 'd'); 12 | insert into t_group_by values(3, 2.0, 'f'); 13 | 14 | insert into t_group_by_2 values(1, 10); 15 | insert into t_group_by_2 values(2, 20); 16 | insert into t_group_by_2 values(3, 10); 17 | insert into t_group_by_2 values(3, 20); 18 | insert into t_group_by_2 values(3, 40); 19 | insert into t_group_by_2 values(4, 20); 20 | 21 | -- echo 3. primary group by 22 | -- sort select id, avg(score) from t_group_by group by id; 23 | 24 | -- sort select name, min(id), max(score) from t_group_by group by name; 25 | 26 | -- sort select id, name, avg(score) from t_group_by group by id, name; 27 | 28 | -- echo 4. with where condition 29 | -- sort select id, avg(score) from t_group_by where id>2 group by id; 30 | 31 | -- sort select name, count(id), max(score) from t_group_by where name > 'a' and id>=0 group by name; 32 | 33 | -- echo 5. multi table 34 | -- sort select t_group_by.id, t_group_by.name, avg(t_group_by.score), avg(t_group_by_2.age) from t_group_by, t_group_by_2 where t_group_by.id=t_group_by_2.id group by t_group_by.id, t_group_by.name; -------------------------------------------------------------------------------- /test/case/test/primary-insert.test: -------------------------------------------------------------------------------- 1 | -- echo initialization 2 | CREATE TABLE insert_table(id int, t_name char, col1 int, col2 int); 3 | 4 | -- echo 1. insert 5 | INSERT INTO insert_table VALUES (1,'N1',1,1); 6 | INSERT INTO insert_table VALUES (2,'N2',1,1),(3,'N3',2,1); 7 | 8 | -- echo 2. error 9 | INSERT INTO insert_table VALUES (4,'N4',1,1),(1,1,1); 10 | INSERT INTO insert_table VALUES (4,'N4',1,1),(1,1,1,1); 11 | 12 | -- echo 3. select 13 | -- sort SELECT * FROM insert_table; -------------------------------------------------------------------------------- /test/case/test/primary-order-by.test: -------------------------------------------------------------------------------- 1 | -- echo 1. create table 2 | create table t_order_by(id int, score float, name char); 3 | create table t_order_by_2(id int, age int); 4 | 5 | -- echo 2. insert records 6 | insert into t_order_by values(3, 1.0, 'a'); 7 | insert into t_order_by values(1, 2.0, 'b'); 8 | insert into t_order_by values(4, 3.0, 'c'); 9 | insert into t_order_by values(3, 2.0, 'c'); 10 | insert into t_order_by values(3, 4.0, 'c'); 11 | insert into t_order_by values(3, 3.0, 'd'); 12 | insert into t_order_by values(3, 2.0, 'f'); 13 | 14 | insert into t_order_by_2 values(1, 10); 15 | insert into t_order_by_2 values(2, 20); 16 | insert into t_order_by_2 values(3, 10); 17 | insert into t_order_by_2 values(3, 20); 18 | insert into t_order_by_2 values(3, 40); 19 | insert into t_order_by_2 values(4, 20); 20 | 21 | -- echo 3. primary order by 22 | -- sort select * from t_order_by order by id; 23 | 24 | -- sort select * from t_order_by order by id asc; 25 | 26 | -- sort select * from t_order_by order by id desc; 27 | 28 | -- sort select * from t_order_by order by score desc; 29 | 30 | -- sort select * from t_order_by order by name desc; 31 | 32 | -- echo 4. order by more than one fields 33 | select * from t_order_by order by id, score, name; 34 | 35 | select * from t_order_by order by id desc, score asc, name desc; 36 | 37 | -- echo 5. order by associate with where condition 38 | select * from t_order_by where id=3 and name>='a' order by score desc, name; 39 | 40 | -- echo 6. multi-table order by 41 | select * from t_order_by,t_order_by_2 order by t_order_by.id,t_order_by.score,t_order_by.name,t_order_by_2.id,t_order_by_2.age; 42 | 43 | select * from t_order_by, t_order_by_2 where t_order_by.id=t_order_by_2.id order by t_order_by.score desc, t_order_by_2.age asc, t_order_by.id asc, t_order_by.name; 44 | -------------------------------------------------------------------------------- /test/case/test/primary-select-meta.test: -------------------------------------------------------------------------------- 1 | -- echo initialization 2 | CREATE TABLE Select_meta(id int, age int); 3 | 4 | -- echo 1. select from a non-existent table 5 | select * from no_table; 6 | 7 | -- echo 2. select from a non-existent column 8 | select home from Select_meta; 9 | select * from Select_meta where home='001'; 10 | -------------------------------------------------------------------------------- /test/case/test/primary-unique.test: -------------------------------------------------------------------------------- 1 | -- echo initialization 2 | CREATE TABLE unique_table(id int, col1 int, col2 int); 3 | INSERT INTO unique_table VALUES (1,1,1); 4 | 5 | -- echo 1. unique test 6 | CREATE UNIQUE INDEX index_id on unique_table(id); 7 | INSERT INTO unique_table VALUES (2,1,1); 8 | CREATE UNIQUE INDEX index_id on unique_table(id); 9 | INSERT INTO unique_table VALUES (3,2,1); 10 | INSERT INTO unique_table VALUES (1,2,1); 11 | 12 | -- echo 2. select 13 | -- sort SELECT * FROM unique_table; -------------------------------------------------------------------------------- /test/case/test/primary-update.test: -------------------------------------------------------------------------------- 1 | -- echo initialization 2 | CREATE TABLE Update_table_1(id int, t_name char, col1 int, col2 int); 3 | CREATE INDEX index_id on Update_table_1(id); 4 | INSERT INTO Update_table_1 VALUES (1,'N1',1,1); 5 | INSERT INTO Update_table_1 VALUES (2,'N2',1,1); 6 | INSERT INTO Update_table_1 VALUES (3,'N3',2,1); 7 | 8 | -- echo 1. update a row 9 | UPDATE Update_table_1 SET t_name='N01' WHERE id=1; 10 | -- sort SELECT * FROM Update_table_1; 11 | 12 | -- echo 2. update rows 13 | UPDATE Update_table_1 SET col2=0 WHERE col1=1; 14 | -- sort SELECT * FROM Update_table_1; 15 | 16 | -- echo 3. update a index column 17 | UPDATE Update_table_1 SET id=4 WHERE t_name='N3'; 18 | -- sort SELECT * FROM Update_table_1; 19 | 20 | -- echo 4. update without conditions 21 | UPDATE Update_table_1 SET col1=0; 22 | -- sort SELECT * FROM Update_table_1; 23 | 24 | -- echo 5. update with conditions 25 | UPDATE Update_table_1 SET t_name='N02' WHERE col1=0 AND col2=0; 26 | -- sort SELECT * FROM Update_table_1; 27 | 28 | -- echo 6. update non-existent table 29 | UPDATE Update_table_2 SET t_name='N01' WHERE id=1; 30 | 31 | -- echo 7. update non-existent column 32 | UPDATE Update_table_1 SET t_name_false='N01' WHERE id=1; 33 | 34 | -- echo 8. update with invalid condition 35 | UPDATE Update_table_1 SET t_name='N01' WHERE id_false=1; 36 | 37 | -- echo 9. update in vain 38 | UPDATE Update_table_1 SET t_name='N01' WHERE id=100; 39 | -- sort SELECT * FROM Update_table_1; 40 | 41 | -- echo 10. update with invalid value 42 | UPDATE Update_table_1 SET col1='N01' WHERE id=1; -------------------------------------------------------------------------------- /test/perf/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | PROJECT(test) 2 | MESSAGE("Begin to build " ${PROJECT_NAME}) 3 | MESSAGE(STATUS "This is PROJECT_BINARY_DIR dir " ${PROJECT_BINARY_DIR}) 4 | MESSAGE(STATUS "This is PROJECT_SOURCE_DIR dir " ${PROJECT_SOURCE_DIR}) 5 | 6 | 7 | # 可以获取父cmake的变量 8 | MESSAGE("${CMAKE_COMMON_FLAGS}") 9 | 10 | 11 | #INCLUDE_DIRECTORIES([AFTER|BEFORE] [SYSTEM] dir1 dir2 ...) 12 | INCLUDE_DIRECTORIES(. ${PROJECT_SOURCE_DIR}/../../deps /usr/local/include SYSTEM) 13 | # 父cmake 设置的include_directories 和link_directories并不传导到子cmake里面 14 | #INCLUDE_DIRECTORIES(BEFORE ${CMAKE_INSTALL_PREFIX}/include) 15 | LINK_DIRECTORIES(/usr/local/lib ${PROJECT_BINARY_DIR}/../../lib) 16 | 17 | 18 | IF (DEFINED ENV{LD_LIBRARY_PATH}) 19 | SET(LD_LIBRARY_PATH_STR $ENV{LD_LIBRARY_PATH}) 20 | #separate_arguments(LD_LIBRARY_PATH_STR) #只能处理空行 21 | string(REPLACE ":" ";" LD_LIBRARY_PATH_LIST ${LD_LIBRARY_PATH_STR}) 22 | MESSAGE(" Add LD_LIBRARY_PATH to -L flags " ${LD_LIBRARY_PATH_LIST}) 23 | LINK_DIRECTORIES(${LD_LIBRARY_PATH_LIST}) 24 | ELSE () 25 | LINK_DIRECTORIES(/usr/local/lib) 26 | ENDIF () 27 | 28 | 29 | 30 | #get_filename_component( FileName 31 | # PATH|ABSOLUTE|NAME|EXT|NAME_WE|REALPATH 32 | # [CACHE]) 33 | FILE(GLOB_RECURSE ALL_SRC *.cpp) 34 | # AUX_SOURCE_DIRECTORY 类似功能 35 | FOREACH (F ${ALL_SRC}) 36 | get_filename_component(prjName ${F} NAME_WE) 37 | MESSAGE("Build ${prjName} according to ${F}") 38 | ADD_EXECUTABLE(${prjName} ${F}) 39 | TARGET_LINK_LIBRARIES(${prjName} common pthread dl observer_static) 40 | 41 | ENDFOREACH (F) 42 | 43 | -------------------------------------------------------------------------------- /test/test_ans/aggr/aggr_test_1: -------------------------------------------------------------------------------- 1 | SUCCESS 2 | SUCCESS 3 | SUCCESS 4 | SUCCESS 5 | SUCCESS 6 | SUCCESS 7 | SUCCESS 8 | SUCCESS 9 | id | age | name | score 10 | 1 | 1 | a | 1 11 | 2 | 2 | b | 2 12 | 4 | 4 | c | 3 13 | 3 | 3 | d | 4 14 | 5 | 5 | e | 5.5 15 | 6 | 6 | f | 6.6 16 | 7 | 7 | g | 7.7 17 | avg(id) | count(*) | max(id) | min(id) 18 | 4 | 7 | 7 | 1 19 | avg(t_basic_2.score) | count(*) | max(age) | min(score) 20 | 4.26 | 7 | 7 | 1 21 | avg(3) | count(1) 22 | 3 | 7 23 | avg(3.4) | max(1.1) | min(-1.1) 24 | 3.4 | 1.1 | -1.1 25 | max(3.456) | min(age) | avg(t_basic_2.age) 26 | 3.46 | 1 | 4 27 | count(4) | max(name) 28 | 7 | g 29 | FAILURE 30 | FAILURE 31 | FAILURE 32 | SUCCESS 33 | avg(id) | max(age) | min(name) | count(score) 34 | SUCCESS 35 | SUCCESS 36 | -------------------------------------------------------------------------------- /test/test_ans/aggr/aggr_test_2: -------------------------------------------------------------------------------- 1 | SUCCESS 2 | SUCCESS 3 | SUCCESS 4 | SUCCESS 5 | SUCCESS 6 | SUCCESS 7 | SUCCESS 8 | count(*) 9 | 6 10 | count(id) 11 | 6 12 | min(id) 13 | 1 14 | min(name) 15 | aa 16 | max(id) 17 | 6 18 | max(name) 19 | we 20 | avg(id) 21 | 3.5 22 | avg(price) 23 | -1.74 24 | avg(price) | max(id) | max(name) 25 | -1.74 | 6 | we 26 | FAILURE 27 | FAILURE 28 | FAILURE 29 | SUCCESS 30 | -------------------------------------------------------------------------------- /test/test_ans/aggr/aggr_test_3: -------------------------------------------------------------------------------- 1 | SUCCESS 2 | SUCCESS 3 | SUCCESS 4 | SUCCESS 5 | SUCCESS 6 | SUCCESS 7 | SUCCESS 8 | count(*) 9 | 6 10 | count(id) 11 | 6 12 | min(id) 13 | 1 14 | min(name) 15 | aa 16 | max(id) 17 | 6 18 | max(name) 19 | we 20 | avg(id) 21 | 3.5 22 | avg(price) 23 | -1.74 24 | avg(price) | max(id) | max(name) 25 | -1.74 | 6 | we 26 | FAILURE 27 | FAILURE 28 | FAILURE 29 | max(birthday) 30 | 2021-03-04 31 | min(t.birthday) 32 | 1987-10-18 33 | avg(price) | max(id) | max(name) | min(t.birthday) | max(birthday) 34 | -1.74 | 6 | we | 1987-10-18 | 2021-03-04 35 | SUCCESS 36 | -------------------------------------------------------------------------------- /test/test_ans/complex/case1: -------------------------------------------------------------------------------- 1 | SUCCESS 2 | SUCCESS 3 | SUCCESS 4 | SUCCESS 5 | SUCCESS 6 | SUCCESS 7 | SUCCESS 8 | SUCCESS 9 | SUCCESS 10 | SUCCESS 11 | SUCCESS 12 | SUCCESS 13 | SUCCESS 14 | id | col1 | feat1 15 | 1 | 4 | 11.2 16 | SUCCESS 17 | SUCCESS 18 | SUCCESS 19 | -------------------------------------------------------------------------------- /test/test_ans/complex/case2: -------------------------------------------------------------------------------- 1 | SUCCESS 2 | SUCCESS 3 | SUCCESS 4 | SUCCESS 5 | SUCCESS 6 | SUCCESS 7 | ID | COL1 | FEAT1 8 | 0 | 2 | 1 9 | 1 | 0 | 13 10 | 1 | 4 | 11.2 11 | 2 | 2 | 12 12 | 3 | 3 | 13.5 13 | SUCCESS 14 | SUCCESS 15 | SUCCESS 16 | -------------------------------------------------------------------------------- /test/test_ans/complex/case3: -------------------------------------------------------------------------------- 1 | SUCCESS 2 | SUCCESS 3 | SUCCESS 4 | SUCCESS 5 | SUCCESS 6 | SUCCESS 7 | SUCCESS 8 | SUCCESS 9 | SUCCESS 10 | SUCCESS 11 | SUCCESS 12 | SUCCESS 13 | ID | COL1 | FEAT1 14 | 1 | 4 | 11.2 15 | 3 | 3 | 13.5 16 | ID | COL1 | FEAT1 17 | ID | COL1 | FEAT1 18 | 1 | 4 | 11.2 19 | 2 | 2 | 12 20 | 3 | 3 | 13.5 21 | ID | COL1 | FEAT1 22 | 2 | 2 | 12 23 | ID | COL1 | FEAT1 24 | 1 | 4 | 11.2 25 | 2 | 2 | 12 26 | ID | COL3 | FEAT3 27 | SUCCESS 28 | SUCCESS 29 | SUCCESS 30 | -------------------------------------------------------------------------------- /test/test_ans/date/compare_date_1: -------------------------------------------------------------------------------- 1 | SUCCESS 2 | SUCCESS 3 | SUCCESS 4 | SUCCESS 5 | SUCCESS 6 | SUCCESS 7 | SUCCESS 8 | SUCCESS 9 | SUCCESS 10 | SUCCESS 11 | SUCCESS 12 | a | b 13 | 1 | 2020-01-03 14 | 2 | 2020-01-03 15 | 3 | 2020-01-03 16 | 4 | 2020-01-03 17 | 5 | 2020-02-03 18 | 6 | 2010-03-05 19 | 7 | 2000-03-05 20 | 8 | 1990-12-05 21 | 9 | 1980-02-05 22 | 10 | 1970-12-31 23 | a | b 24 | 1 | 2020-01-03 25 | 2 | 2020-01-03 26 | 3 | 2020-01-03 27 | 4 | 2020-01-03 28 | 5 | 2020-02-03 29 | 6 | 2010-03-05 30 | 7 | 2000-03-05 31 | 8 | 1990-12-05 32 | 9 | 1980-02-05 33 | 10 | 1970-12-31 34 | b 35 | 2020-01-03 36 | 2020-01-03 37 | 2020-01-03 38 | 2020-01-03 39 | 2020-02-03 40 | 2010-03-05 41 | 2000-03-05 42 | 1990-12-05 43 | 1980-02-05 44 | 1970-12-31 45 | a | b 46 | 7 | 2000-03-05 47 | 8 | 1990-12-05 48 | 9 | 1980-02-05 49 | 10 | 1970-12-31 50 | a | b 51 | 1 | 2020-01-03 52 | 2 | 2020-01-03 53 | 3 | 2020-01-03 54 | 4 | 2020-01-03 55 | 5 | 2020-02-03 56 | 6 | 2010-03-05 57 | a | b 58 | 1 | 2020-01-03 59 | 2 | 2020-01-03 60 | 3 | 2020-01-03 61 | 4 | 2020-01-03 62 | 5 | 2020-02-03 63 | 6 | 2010-03-05 64 | a | b 65 | a | b 66 | 7 | 2000-03-05 67 | FAILURE 68 | FAILURE 69 | SUCCESS 70 | a | b 71 | 1 | 2020-01-03 72 | 2 | 2020-01-03 73 | 3 | 2020-01-03 74 | 4 | 2020-01-03 75 | 5 | 2020-02-03 76 | 6 | 2010-03-05 77 | 7 | 2000-03-05 78 | 8 | 1990-12-05 79 | 9 | 1980-02-05 80 | a | b 81 | 1 | 2020-01-03 82 | 2 | 2020-01-03 83 | 3 | 2020-01-03 84 | 4 | 2020-01-03 85 | 5 | 2020-02-03 86 | 6 | 2010-03-05 87 | 7 | 2000-03-05 88 | 8 | 1990-12-05 89 | 9 | 1980-02-05 90 | a | b 91 | 1 | 2020-01-03 92 | 2 | 2020-01-03 93 | 3 | 2020-01-03 94 | 4 | 2020-01-03 95 | 5 | 2020-02-03 96 | 6 | 2010-03-05 97 | 7 | 2000-03-05 98 | 8 | 1990-12-05 99 | 9 | 1980-02-05 100 | SUCCESS 101 | -------------------------------------------------------------------------------- /test/test_ans/date/compare_date_3: -------------------------------------------------------------------------------- 1 | SUCCESS 2 | FAILURE 3 | FAILURE 4 | FAILURE 5 | FAILURE 6 | FAILURE 7 | FAILURE 8 | FAILURE 9 | FAILURE 10 | FAILURE 11 | FAILURE 12 | FAILURE 13 | FAILURE 14 | FAILURE 15 | FAILURE 16 | FAILURE 17 | FAILURE 18 | FAILURE 19 | FAILURE 20 | FAILURE 21 | FAILURE 22 | FAILURE 23 | FAILURE 24 | FAILURE 25 | FAILURE 26 | SUCCESS 27 | SUCCESS 28 | SUCCESS 29 | SUCCESS 30 | SUCCESS 31 | SUCCESS 32 | SUCCESS 33 | SUCCESS 34 | SUCCESS 35 | SUCCESS 36 | SUCCESS 37 | a | b | c 38 | 1 | 2020-01-03 | a 39 | 2 | 2020-01-03 | b 40 | 3 | 2020-01-03 | c 41 | 4 | 2020-01-03 | d 42 | 5 | 2020-02-03 | e 43 | 6 | 2008-02-29 | f 44 | 7 | 2021-02-28 | g 45 | 8 | 2021-12-28 | h 46 | 9 | 2021-06-17 | i 47 | 10 | 1970-12-31 | j 48 | 11 | 1970-12-31 | k 49 | SUCCESS 50 | a | b | c 51 | 1 | 2020-01-03 | a 52 | 2 | 2020-01-03 | b 53 | 3 | 2020-01-03 | c 54 | 4 | 2020-01-03 | d 55 | 5 | 2020-02-03 | e 56 | 6 | 2008-02-29 | f 57 | 7 | 2021-02-28 | g 58 | 8 | 2021-12-28 | h 59 | 9 | 2021-06-17 | i 60 | SUCCESS 61 | SUCCESS 62 | FAILURE 63 | a | b | c 64 | 1 | 2020-01-03 | a 65 | 2 | 2020-01-03 | b 66 | 3 | 2020-01-03 | c 67 | 4 | 2020-01-03 | d 68 | 5 | 2020-02-03 | e 69 | 6 | 2008-02-29 | f 70 | 7 | 2021-02-28 | g 71 | 8 | 2021-12-28 | h 72 | 9 | 2021-06-17 | i 73 | SUCCESS 74 | SUCCESS 75 | a | b | c 76 | 1 | 2020-01-03 | a 77 | 2 | 2020-01-03 | b 78 | 3 | 2020-01-03 | c 79 | 4 | 2020-01-03 | d 80 | 6 | 2008-02-29 | f 81 | 8 | 2021-12-28 | h 82 | 9 | 2021-06-17 | i 83 | SUCCESS 84 | -------------------------------------------------------------------------------- /test/test_ans/date/compare_date_4: -------------------------------------------------------------------------------- 1 | SUCCESS 2 | SUCCESS 3 | SUCCESS 4 | SUCCESS 5 | SUCCESS 6 | SUCCESS 7 | SUCCESS 8 | SUCCESS 9 | id | age | name | score 10 | 1 | 1 | a | 1 11 | 2 | 2 | b | 2 12 | 4 | 4 | c | 3 13 | 3 | 3 | d | 4 14 | 5 | 5 | e | 5.5 15 | 6 | 6 | f | 6.6 16 | 7 | 7 | g | 7.7 17 | SUCCESS 18 | id | age | name | score 19 | 1 | 1 | a | 1 20 | 2 | 2 | b | 2 21 | 4 | 4 | c | 3 22 | 5 | 5 | e | 5.5 23 | 6 | 6 | f | 6.6 24 | 7 | 7 | g | 7.7 25 | id | age | name | score 26 | 1 | 1 | a | 1 27 | id | age | name | score 28 | 5 | 5 | e | 5.5 29 | 6 | 6 | f | 6.6 30 | 7 | 7 | g | 7.7 31 | id | age | name | score 32 | 2 | 2 | b | 2 33 | FAILURE 34 | id | age | name | score 35 | 1 | 1 | a | 1 36 | id | age | name | score 37 | 1 | 1 | a | 1 38 | 2 | 2 | b | 2 39 | 4 | 4 | c | 3 40 | 5 | 5 | e | 5.5 41 | 6 | 6 | f | 6.6 42 | 7 | 7 | g | 7.7 43 | FAILURE 44 | FAILURE 45 | FAILURE 46 | id | age | name | score 47 | 1 | 1 | a | 1 48 | 2 | 2 | b | 2 49 | 4 | 4 | c | 3 50 | 5 | 5 | e | 5.5 51 | 6 | 6 | f | 6.6 52 | 7 | 7 | g | 7.7 53 | SUCCESS 54 | -------------------------------------------------------------------------------- /test/test_ans/date/compare_date_5: -------------------------------------------------------------------------------- 1 | FAILURE 2 | FAILURE 3 | FAILURE 4 | FAILURE 5 | FAILURE 6 | FAILURE 7 | FAILURE 8 | FAILURE 9 | FAILURE 10 | FAILURE 11 | FAILURE 12 | FAILURE 13 | FAILURE 14 | FAILURE 15 | FAILURE 16 | FAILURE 17 | FAILURE 18 | FAILURE 19 | FAILURE 20 | FAILURE 21 | FAILURE 22 | FAILURE 23 | -------------------------------------------------------------------------------- /test/test_ans/date/compare_date_6: -------------------------------------------------------------------------------- 1 | SUCCESS 2 | SUCCESS 3 | SUCCESS 4 | SUCCESS 5 | SUCCESS 6 | SUCCESS 7 | SUCCESS 8 | SUCCESS 9 | SUCCESS 10 | FAILURE 11 | FAILURE 12 | FAILURE 13 | FAILURE 14 | FAILURE 15 | FAILURE 16 | FAILURE 17 | FAILURE 18 | FAILURE 19 | FAILURE 20 | FAILURE 21 | FAILURE 22 | a | b | c | d 23 | 1 | 1.1 | a | 2020-01-03 24 | 2 | 1.2 | b | 2019-02-28 25 | 3 | 1.3 | c | 2018-03-30 26 | 4 | 1.4 | d | 2017-04-29 27 | 5 | 1.5 | e | 2016-05-30 28 | 6 | 1.6 | f | 2015-06-29 29 | 7 | -1.1 | g | 2014-07-28 30 | 8 | -2.2 | h | 2013-08-29 31 | FAILURE 32 | FAILURE 33 | FAILURE 34 | FAILURE 35 | FAILURE 36 | a 37 | 2 38 | 3 39 | 4 40 | 5 41 | 6 42 | 7 43 | 8 44 | a 45 | 4 46 | 5 47 | 6 48 | 7 49 | 8 50 | b 51 | 1.2 52 | a 53 | 1 54 | 2 55 | 3 56 | 5 57 | 6 58 | 7 59 | 8 60 | a | b | c | d 61 | 1 | 1.1 | a | 2020-01-03 62 | 2 | 1.2 | b | 2019-02-28 63 | 3 | 1.3 | c | 2018-03-30 64 | 4 | 1.4 | d | 2017-04-29 65 | 5 | 1.5 | e | 2016-05-30 66 | a | b | c | d 67 | 1 | 1.1 | a | 2020-01-03 68 | 2 | 1.2 | b | 2019-02-28 69 | 3 | 1.3 | c | 2018-03-30 70 | SUCCESS 71 | -------------------------------------------------------------------------------- /test/test_ans/date/compare_date_index_1: -------------------------------------------------------------------------------- 1 | SUCCESS 2 | SUCCESS 3 | SUCCESS 4 | SUCCESS 5 | SUCCESS 6 | SUCCESS 7 | SUCCESS 8 | SUCCESS 9 | SUCCESS 10 | SUCCESS 11 | FAILURE 12 | FAILURE 13 | FAILURE 14 | FAILURE 15 | FAILURE 16 | FAILURE 17 | FAILURE 18 | FAILURE 19 | FAILURE 20 | FAILURE 21 | FAILURE 22 | FAILURE 23 | a | b | c | d 24 | 1 | 1.1 | a | 2020-01-03 25 | 2 | 1.2 | b | 2019-02-28 26 | 3 | 1.3 | c | 2018-03-30 27 | 4 | 1.4 | d | 2017-04-29 28 | 5 | 1.5 | e | 2016-05-30 29 | 6 | 1.6 | f | 2015-06-29 30 | 7 | -1.1 | g | 2014-07-28 31 | 8 | -2.2 | h | 2013-08-29 32 | FAILURE 33 | FAILURE 34 | FAILURE 35 | FAILURE 36 | FAILURE 37 | a 38 | 2 39 | 3 40 | 4 41 | 5 42 | 6 43 | 7 44 | 8 45 | a 46 | 4 47 | 5 48 | 6 49 | 7 50 | 8 51 | a 52 | 1 53 | 2 54 | 3 55 | 4 56 | b 57 | 1.2 58 | a 59 | 1 60 | 2 61 | 3 62 | 5 63 | 6 64 | 7 65 | 8 66 | a | b | c | d 67 | 1 | 1.1 | a | 2020-01-03 68 | 2 | 1.2 | b | 2019-02-28 69 | 3 | 1.3 | c | 2018-03-30 70 | 4 | 1.4 | d | 2017-04-29 71 | 5 | 1.5 | e | 2016-05-30 72 | a | b | c | d 73 | 1 | 1.1 | a | 2020-01-03 74 | 2 | 1.2 | b | 2019-02-28 75 | 3 | 1.3 | c | 2018-03-30 76 | SUCCESS 77 | -------------------------------------------------------------------------------- /test/test_ans/date/compare_date_index_2: -------------------------------------------------------------------------------- 1 | SUCCESS 2 | SUCCESS 3 | SUCCESS 4 | SUCCESS 5 | SUCCESS 6 | SUCCESS 7 | a | b | c | d 8 | 2 | -1.1 | g | 2014-07-28 9 | 5 | 1.5 | e | 2016-05-30 10 | 8 | -2.2 | h | 2013-08-29 11 | SUCCESS 12 | -------------------------------------------------------------------------------- /test/test_ans/date/delete_date_1: -------------------------------------------------------------------------------- 1 | FAILURE 2 | FAILURE 3 | -------------------------------------------------------------------------------- /test/test_ans/drop_table/drop_table_1: -------------------------------------------------------------------------------- 1 | SUCCESS 2 | SUCCESS 3 | -------------------------------------------------------------------------------- /test/test_ans/drop_table/drop_table_2: -------------------------------------------------------------------------------- 1 | FAILURE 2 | -------------------------------------------------------------------------------- /test/test_ans/drop_table/drop_table_3: -------------------------------------------------------------------------------- 1 | SUCCESS 2 | SUCCESS 3 | FAILURE 4 | -------------------------------------------------------------------------------- /test/test_ans/drop_table/drop_table_4: -------------------------------------------------------------------------------- 1 | SUCCESS 2 | FAILURE 3 | SUCCESS 4 | SUCCESS 5 | SUCCESS 6 | -------------------------------------------------------------------------------- /test/test_ans/expression/case1: -------------------------------------------------------------------------------- 1 | SUCCESS 2 | SUCCESS 3 | SUCCESS 4 | SUCCESS 5 | SUCCESS 6 | SUCCESS 7 | SUCCESS 8 | SUCCESS 9 | SUCCESS 10 | SUCCESS 11 | SUCCESS 12 | SUCCESS 13 | t_expr1.col1+t_expr2.col2 14 | 12 15 | 11 16 | 12 17 | 13 18 | 11 19 | 12 20 | 13 21 | 14 22 | 10 23 | 11 24 | 12 25 | 13 26 | 14 27 | t_expr1.id | t_expr1.name | t_expr1.age | t_expr1.col1 | t_expr2.id | t_expr2.name | t_expr2.age | t_expr2.col2 28 | 5 | hu | 59 | 5 | 7 | hu | 39 | 7 29 | 3 | hu | 39 | 3 | 8 | hu | 29 | 8 30 | 4 | hu | 49 | 4 | 8 | hu | 29 | 8 31 | 5 | hu | 59 | 5 | 8 | hu | 29 | 8 32 | 2 | hu | 29 | 2 | 9 | hu | 19 | 9 33 | 3 | hu | 39 | 3 | 9 | hu | 19 | 9 34 | 4 | hu | 49 | 4 | 9 | hu | 19 | 9 35 | 5 | hu | 59 | 5 | 9 | hu | 19 | 9 36 | 1 | hu | 19 | 1 | 10 | hu | 9 | 9 37 | 2 | hu | 29 | 2 | 10 | hu | 9 | 9 38 | 3 | hu | 39 | 3 | 10 | hu | 9 | 9 39 | 4 | hu | 49 | 4 | 10 | hu | 9 | 9 40 | 5 | hu | 59 | 5 | 10 | hu | 9 | 9 41 | t_expr1.id 42 | 5 43 | 3 44 | 4 45 | 5 46 | 2 47 | 3 48 | 4 49 | 5 50 | 1 51 | 2 52 | 3 53 | 4 54 | 5 55 | SUCCESS 56 | SUCCESS 57 | -------------------------------------------------------------------------------- /test/test_ans/expression/case2: -------------------------------------------------------------------------------- 1 | SUCCESS 2 | SUCCESS 3 | SUCCESS 4 | ID | COL1 | COL2 | COL3 | COL4 5 | ID | COL1 | COL2 | COL3 | COL4 6 | 3 | 3 | 4 | 5 | 4 7 | ID | COL1 | COL2 | COL3 | COL4 8 | 2 | 2 | -2 | 5.5 | 1 9 | ID | COL1 | COL2 | COL3 | COL4 10 | 2 | 2 | -2 | 5.5 | 1 11 | SUCCESS 12 | -------------------------------------------------------------------------------- /test/test_ans/expression/case3: -------------------------------------------------------------------------------- 1 | SUCCESS 2 | SUCCESS 3 | ID | -(COL2*(-1)+1)+(COL4+2)*(COL1+COL3*2) | (4+COL2)*COL3/2 4 | 2 | 36 | 5.5 5 | 3 | 81 | 20 6 | ID | COL1 | COL2 | COL3 | COL4 | 6-(COL2*(1+COL1))+(COL4+2)/(1+COL1*4+COL3*2) 7 | 2 | 2 | -2 | 5.5 | 1 | 12.15 8 | ID | COL1 | COL2 | COL3 | COL4 | 3*COL1/(COL2+2) 9 | 3 | 3 | 4 | 5 | 4 | 1.5 10 | ID | 3*COL1/(COL2+2) 11 | ID | COL1 | COL2 | COL3 | COL4 12 | SUCCESS 13 | -------------------------------------------------------------------------------- /test/test_ans/group/group_case_1: -------------------------------------------------------------------------------- 1 | SUCCESS 2 | SUCCESS 3 | SUCCESS 4 | SUCCESS 5 | SUCCESS 6 | SUCCESS 7 | SUCCESS 8 | SUCCESS 9 | SUCCESS 10 | SUCCESS 11 | SUCCESS 12 | SUCCESS 13 | SUCCESS 14 | SUCCESS 15 | SUCCESS 16 | t_group_1.id | t_group_1.name | avg(t_group_1.score) | avg(t_group_2.age) 17 | 1 | hu | 90 | 18 18 | 2 | liu | 80 | 22 19 | 3 | li | 70 | 18 20 | 4 | we | 100 | 18 21 | 5 | li | 80 | 22 22 | 6 | we | 70 | 18 23 | t_group_1.id | max(t_group_1.name) | min(t_group_1.score) | count(t_group_1.age) | avg(t_group_1.age) 24 | 1 | hu | 90 | 1 | 18 25 | 2 | liu | 80 | 1 | 22 26 | 3 | li | 70 | 1 | 18 27 | 4 | we | 100 | 1 | 18 28 | 5 | li | 80 | 1 | 22 29 | 6 | we | 70 | 1 | 18 30 | id | avg(age) 31 | 1 | 18 32 | 2 | 22 33 | 3 | 18 34 | 4 | 18 35 | 5 | 22 36 | 6 | 18 37 | 7 | 18 38 | id | max(t_group_1.score) 39 | 7 | 60 40 | 1 | 90 41 | 3 | 80 42 | 2 | 80 43 | 4 | 100 44 | id | avg(score) 45 | 1 | 90 46 | 2 | 80 47 | 3 | 70 48 | 4 | 100 49 | 5 | 80 50 | 6 | 70 51 | 7 | 60 52 | id | avg(score) 53 | t_group_1.id | t_group_1.name | avg(t_group_1.score) | avg(t_group_2.age) 54 | max(id) | score 55 | 7 | 60 56 | 1 | 90 57 | 5 | 70 58 | 2 | 80 59 | 6 | 100 60 | SUCCESS 61 | SUCCESS 62 | -------------------------------------------------------------------------------- /test/test_ans/group/group_case_2: -------------------------------------------------------------------------------- 1 | SUCCESS 2 | SUCCESS 3 | SUCCESS 4 | SUCCESS 5 | SUCCESS 6 | SUCCESS 7 | SUCCESS 8 | SUCCESS 9 | SUCCESS 10 | id | avg(score) 11 | 1 | 2 12 | 3 | 2.4 13 | 4 | 3 14 | SUCCESS 15 | -------------------------------------------------------------------------------- /test/test_ans/group/group_case_3: -------------------------------------------------------------------------------- 1 | SUCCESS 2 | SUCCESS 3 | SUCCESS 4 | SUCCESS 5 | SUCCESS 6 | SUCCESS 7 | SUCCESS 8 | SUCCESS 9 | id | avg(score) 10 | 1 | 2 11 | 3 | 2.4 12 | 4 | 3 13 | SUCCESS 14 | -------------------------------------------------------------------------------- /test/test_ans/group/group_case_4: -------------------------------------------------------------------------------- 1 | SUCCESS 2 | SUCCESS 3 | SUCCESS 4 | SUCCESS 5 | SUCCESS 6 | SUCCESS 7 | SUCCESS 8 | SUCCESS 9 | SUCCESS 10 | SUCCESS 11 | SUCCESS 12 | SUCCESS 13 | SUCCESS 14 | SUCCESS 15 | SUCCESS 16 | T_GROUP_BY.ID | T_GROUP_BY.NAME | avg(T_GROUP_BY.SCORE) | avg(T_GROUP_BY_2.AGE) 17 | 1 | B | 2 | 10 18 | 3 | A | 1 | 23.33 19 | 3 | C | 3 | 23.33 20 | 3 | D | 3 | 23.33 21 | 3 | F | 2 | 23.33 22 | 4 | C | 3 | 20 23 | SUCCESS 24 | SUCCESS 25 | -------------------------------------------------------------------------------- /test/test_ans/inner_join/case_1: -------------------------------------------------------------------------------- 1 | SUCCESS 2 | SUCCESS 3 | SUCCESS 4 | SUCCESS 5 | SUCCESS 6 | t1.a | t2.b 7 | 1 | 1 8 | t2.b | t1.a 9 | 1 | 1 10 | t1.a | t2.b 11 | 2 | 1 12 | SUCCESS 13 | SUCCESS 14 | -------------------------------------------------------------------------------- /test/test_ans/inner_join/case_2: -------------------------------------------------------------------------------- 1 | SUCCESS 2 | SUCCESS 3 | SUCCESS 4 | SUCCESS 5 | SUCCESS 6 | SUCCESS 7 | SUCCESS 8 | t2.b | t1.a | t3.c 9 | 1 | 1 | a 10 | SUCCESS 11 | SUCCESS 12 | SUCCESS 13 | -------------------------------------------------------------------------------- /test/test_ans/inner_join/case_3: -------------------------------------------------------------------------------- 1 | SUCCESS 2 | SUCCESS 3 | SUCCESS 4 | SUCCESS 5 | SUCCESS 6 | SUCCESS 7 | avg(t1.a) | max(t2.b) 8 | 0.5 | 3 9 | SUCCESS 10 | max(t2.b) | avg(t1.a) 11 | 3 | 0.8 12 | SUCCESS 13 | SUCCESS 14 | -------------------------------------------------------------------------------- /test/test_ans/inner_join/case_4: -------------------------------------------------------------------------------- 1 | SUCCESS 2 | SUCCESS 3 | SUCCESS 4 | FAILURE 5 | SUCCESS 6 | SUCCESS 7 | SUCCESS 8 | -------------------------------------------------------------------------------- /test/test_ans/insert/case_1: -------------------------------------------------------------------------------- 1 | SUCCESS 2 | SUCCESS 3 | a | b 4 | 1 | 2 5 | 2 | 3 6 | SUCCESS 7 | -------------------------------------------------------------------------------- /test/test_ans/insert/case_2: -------------------------------------------------------------------------------- 1 | SUCCESS 2 | SUCCESS 3 | SUCCESS 4 | SUCCESS 5 | a | b 6 | 2000-01-29 | 2 7 | 2012-02-01 | 2 8 | SUCCESS 9 | -------------------------------------------------------------------------------- /test/test_ans/insert/case_3: -------------------------------------------------------------------------------- 1 | SUCCESS 2 | SUCCESS 3 | FAILURE 4 | a | b 5 | SUCCESS 6 | -------------------------------------------------------------------------------- /test/test_ans/metadata_verification/case_1: -------------------------------------------------------------------------------- 1 | SUCCESS 2 | FAILURE 3 | FAILURE 4 | FAILURE 5 | FAILURE 6 | FAILURE 7 | FAILURE 8 | SUCCESS 9 | -------------------------------------------------------------------------------- /test/test_ans/metadata_verification/case_2: -------------------------------------------------------------------------------- 1 | SUCCESS 2 | SUCCESS 3 | SUCCESS 4 | SUCCESS 5 | SUCCESS 6 | a 7 | 17.1 8 | 17.01 9 | 17 10 | 17.05 11 | SUCCESS 12 | -------------------------------------------------------------------------------- /test/test_ans/multi_index/case_1: -------------------------------------------------------------------------------- 1 | SUCCESS 2 | SUCCESS 3 | SUCCESS 4 | -------------------------------------------------------------------------------- /test/test_ans/multi_index/case_2: -------------------------------------------------------------------------------- 1 | SUCCESS 2 | SUCCESS 3 | SUCCESS 4 | SUCCESS 5 | SUCCESS 6 | -------------------------------------------------------------------------------- /test/test_ans/multi_index/case_3: -------------------------------------------------------------------------------- 1 | SUCCESS 2 | SUCCESS 3 | SUCCESS 4 | SUCCESS 5 | a | b 6 | 3 | b 7 | SUCCESS 8 | SUCCESS 9 | -------------------------------------------------------------------------------- /test/test_ans/multi_index/case_4: -------------------------------------------------------------------------------- 1 | SUCCESS 2 | SUCCESS 3 | SUCCESS 4 | SUCCESS 5 | SUCCESS 6 | ID | COL1 | COL2 | COL3 | COL4 | COL5 | COL6 7 | SUCCESS 8 | -------------------------------------------------------------------------------- /test/test_ans/multi_table/case_1: -------------------------------------------------------------------------------- 1 | SUCCESS 2 | SUCCESS 3 | t1.a | t2.b 4 | SUCCESS 5 | SUCCESS 6 | t1.a | t2.b 7 | 1 | 2 8 | SUCCESS 9 | SUCCESS 10 | -------------------------------------------------------------------------------- /test/test_ans/multi_table/case_2: -------------------------------------------------------------------------------- 1 | SUCCESS 2 | SUCCESS 3 | SUCCESS 4 | SUCCESS 5 | SUCCESS 6 | t1.a 7 | a 8 | t2.b | t1.a 9 | b | a 10 | SUCCESS 11 | SUCCESS 12 | -------------------------------------------------------------------------------- /test/test_ans/multi_table/case_3: -------------------------------------------------------------------------------- 1 | SUCCESS 2 | SUCCESS 3 | SUCCESS 4 | SUCCESS 5 | SUCCESS 6 | SUCCESS 7 | SUCCESS 8 | FAILURE 9 | SUCCESS 10 | t1.a | t3.d | t3.c | t2.b 11 | SUCCESS 12 | SUCCESS 13 | SUCCESS 14 | -------------------------------------------------------------------------------- /test/test_ans/null/case_1: -------------------------------------------------------------------------------- 1 | SUCCESS 2 | SUCCESS 3 | FAILURE 4 | a | b 5 | 1 | 1 6 | NULL | 2 7 | SUCCESS 8 | -------------------------------------------------------------------------------- /test/test_ans/null/case_2: -------------------------------------------------------------------------------- 1 | SUCCESS 2 | SUCCESS 3 | a | b | c | d 4 | 0 | 1 | NULL | NULL 5 | NULL | NULL | b | 2020-01-01 6 | 2 | 2 | c | NULL 7 | max(a) | avg(b) | min(c) | count(d) 8 | 2 | 1.5 | b | 1 9 | a 10 | a 11 | 2 12 | SUCCESS 13 | -------------------------------------------------------------------------------- /test/test_ans/null/case_3: -------------------------------------------------------------------------------- 1 | SUCCESS 2 | SUCCESS 3 | a | b 4 | NULL | 2 5 | a | b 6 | 1 | 1 7 | SUCCESS 8 | -------------------------------------------------------------------------------- /test/test_ans/null/case_4: -------------------------------------------------------------------------------- 1 | SUCCESS 2 | SUCCESS 3 | SUCCESS 4 | a | b 5 | NULL | 2 6 | a | b 7 | 1 | 1 8 | a | b 9 | 1 | 1 10 | a | b 11 | SUCCESS 12 | -------------------------------------------------------------------------------- /test/test_ans/null/case_5: -------------------------------------------------------------------------------- 1 | SUCCESS 2 | SUCCESS 3 | SUCCESS 4 | SUCCESS 5 | SUCCESS 6 | -------------------------------------------------------------------------------- /test/test_ans/order/case_1: -------------------------------------------------------------------------------- 1 | SUCCESS 2 | SUCCESS 3 | SUCCESS 4 | SUCCESS 5 | a 6 | a 7 | b 8 | c 9 | SUCCESS 10 | -------------------------------------------------------------------------------- /test/test_ans/order/case_2: -------------------------------------------------------------------------------- 1 | SUCCESS 2 | SUCCESS 3 | SUCCESS 4 | SUCCESS 5 | SUCCESS 6 | a | b 7 | 1 | c 8 | 1 | b 9 | 2 | d 10 | 3 | c 11 | SUCCESS 12 | -------------------------------------------------------------------------------- /test/test_ans/order/case_3: -------------------------------------------------------------------------------- 1 | SUCCESS 2 | SUCCESS 3 | SUCCESS 4 | SUCCESS 5 | SUCCESS 6 | SUCCESS 7 | t1.a | t2.b 8 | 1 | 2 9 | 1 | 4 10 | 3 | 4 11 | t2.b | t1.a 12 | 2 | 1 13 | 2 | 3 14 | 4 | 1 15 | 4 | 3 16 | FAILURE 17 | SUCCESS 18 | SUCCESS 19 | -------------------------------------------------------------------------------- /test/test_ans/order/case_4: -------------------------------------------------------------------------------- 1 | SUCCESS 2 | SUCCESS 3 | SUCCESS 4 | SUCCESS 5 | SUCCESS 6 | SUCCESS 7 | SUCCESS 8 | ID | SCORE | NAME 9 | 3 | 4 | C 10 | 3 | 3 | D 11 | 3 | 2 | C 12 | 3 | 2 | E 13 | 3 | 2 | F 14 | 3 | 1 | A 15 | SUCCESS 16 | -------------------------------------------------------------------------------- /test/test_ans/sub-query/case1: -------------------------------------------------------------------------------- 1 | SUCCESS 2 | SUCCESS 3 | SUCCESS 4 | SUCCESS 5 | SUCCESS 6 | SUCCESS 7 | SUCCESS 8 | SUCCESS 9 | SUCCESS 10 | name | age 11 | a | 20 12 | a | 50 13 | b | 60 14 | name | age 15 | b | 60 16 | name | age 17 | a | 50 18 | b | 60 19 | name | age 20 | c | 2 21 | SUCCESS 22 | SUCCESS 23 | -------------------------------------------------------------------------------- /test/test_ans/sub-query/case2: -------------------------------------------------------------------------------- 1 | SUCCESS 2 | SUCCESS 3 | SUCCESS 4 | SUCCESS 5 | SUCCESS 6 | SUCCESS 7 | SUCCESS 8 | SUCCESS 9 | ID | COL1 | FEAT1 10 | 1 | 4 | 11.2 11 | 2 | 2 | 12 12 | ID | COL1 | FEAT1 13 | 1 | 4 | 11.2 14 | 3 | 3 | 13.5 15 | ID | COL1 | FEAT1 16 | 2 | 2 | 12 17 | ID | COL1 | FEAT1 18 | 1 | 4 | 11.2 19 | 2 | 2 | 12 20 | 3 | 3 | 13.5 21 | ID | COL1 | FEAT1 22 | ID | COL1 | FEAT1 23 | ID | COL1 | FEAT1 24 | ID | COL1 | FEAT1 25 | 1 | 4 | 11.2 26 | 2 | 2 | 12 27 | 3 | 3 | 13.5 28 | ID | COL1 | FEAT1 29 | 3 | 3 | 13.5 30 | FAILURE 31 | FAILURE 32 | FAILURE 33 | FAILURE 34 | SUCCESS 35 | SUCCESS 36 | -------------------------------------------------------------------------------- /test/test_ans/unique_index/case_1: -------------------------------------------------------------------------------- 1 | SUCCESS 2 | SUCCESS 3 | SUCCESS 4 | FAILURE 5 | SUCCESS 6 | SUCCESS 7 | SUCCESS 8 | SUCCESS 9 | FAILURE 10 | FAILURE 11 | SUCCESS 12 | SUCCESS 13 | -------------------------------------------------------------------------------- /test/test_ans/unique_index/case_2: -------------------------------------------------------------------------------- 1 | SUCCESS 2 | SUCCESS 3 | SUCCESS 4 | FAILURE 5 | SUCCESS 6 | SUCCESS 7 | SUCCESS 8 | SUCCESS 9 | FAILURE 10 | FAILURE 11 | SUCCESS 12 | SUCCESS 13 | -------------------------------------------------------------------------------- /test/test_ans/unique_index/case_3: -------------------------------------------------------------------------------- 1 | SUCCESS 2 | SUCCESS 3 | SUCCESS 4 | FAILURE 5 | SUCCESS 6 | SUCCESS 7 | SUCCESS 8 | SUCCESS 9 | FAILURE 10 | FAILURE 11 | SUCCESS 12 | a 13 | 2020-01-01 14 | 2020-01-03 15 | SUCCESS 16 | -------------------------------------------------------------------------------- /test/test_ans/update/case_1: -------------------------------------------------------------------------------- 1 | SUCCESS 2 | SUCCESS 3 | SUCCESS 4 | SUCCESS 5 | a | b 6 | 3 | 2 7 | 2 | 3 8 | FAILURE 9 | FAILURE 10 | FAILURE 11 | FAILURE 12 | FAILURE 13 | a | b 14 | 3 | 2 15 | 2 | 3 16 | SUCCESS 17 | -------------------------------------------------------------------------------- /test/test_case/aggr/aggr_test_1: -------------------------------------------------------------------------------- 1 | create table t_basic_2(id int, age int, name char, score float); 2 | insert into t_basic_2 values(1,1, 'a', 1.0); 3 | insert into t_basic_2 values(2,2, 'b', 2.0); 4 | insert into t_basic_2 values(4,4, 'c', 3.0); 5 | insert into t_basic_2 values(3,3, 'd', 4.0); 6 | insert into t_basic_2 values(5,5, 'e', 5.5); 7 | insert into t_basic_2 values(6,6, 'f', 6.6); 8 | insert into t_basic_2 values(7,7, 'g', 7.7); 9 | select * from t_basic_2; 10 | select avg(id),count(*),max(id),min(id) from t_basic_2; 11 | select avg(t_basic_2.score),count(*),max(age),min(score) from t_basic_2; 12 | select avg(3),count(1) from t_basic_2; 13 | select avg(3.4),max(1.1),min(-1.1) from t_basic_2; 14 | select max(3.456),min(age),avg(t_basic_2.age) from t_basic_2; 15 | select count(4),max(name) from t_basic_2; 16 | select count(*,id) from t_basic_2; 17 | select count() from t_basic_2; 18 | select count(b) from t_basic_2; 19 | create table t_basic_3(id int, age int, name char, score float); 20 | select avg(id),max(age),min(name),count(score) from t_basic_3; 21 | drop table t_basic_2; 22 | drop table t_basic_3; -------------------------------------------------------------------------------- /test/test_case/aggr/aggr_test_2: -------------------------------------------------------------------------------- 1 | create table t(id int, name char, price float); 2 | insert into t values(1,'hu',2.2); 3 | insert into t values(2,'ni',3.333); 4 | insert into t values(3,'li',1.1); 5 | insert into t values(4,'we',3.155); 6 | insert into t values(5,'ti',1.0); 7 | insert into t values(6,'aa',-21.244); 8 | select count(*) from t; 9 | select count(id) from t; 10 | select min(id) from t; 11 | select min(name) from t; 12 | select max(id) from t; 13 | select max(name) from t; 14 | select avg(id) from t; 15 | select avg(price) from t; 16 | select avg(price), max(id), max(name) from t; 17 | select count(*,id) from t; 18 | select count() from t; 19 | select count(a) from t; 20 | drop table t; -------------------------------------------------------------------------------- /test/test_case/aggr/aggr_test_3: -------------------------------------------------------------------------------- 1 | create table t(id int, name char, price float,birthday date); 2 | insert into t values(1,'hu',2.2,'2021-3-4'); 3 | insert into t values(2,'ni',3.333,'2020-12-21'); 4 | insert into t values(3,'li',1.1,'2019-3-4'); 5 | insert into t values(4,'we',3.155,'1999-12-4'); 6 | insert into t values(5,'ti',1.0,'1988-2-1'); 7 | insert into t values(6,'aa',-21.244,'1987-10-18'); 8 | select count(*) from t; 9 | select count(id) from t; 10 | select min(id) from t; 11 | select min(name) from t; 12 | select max(id) from t; 13 | select max(name) from t; 14 | select avg(id) from t; 15 | select avg(price) from t; 16 | select avg(price), max(id), max(name) from t; 17 | select count(*,id) from t; 18 | select count() from t; 19 | select count(a) from t; 20 | select max(birthday) from t; 21 | select min(t.birthday) from t; 22 | select avg(price), max(id), max(name),min(t.birthday),max(birthday) from t; 23 | drop table t; -------------------------------------------------------------------------------- /test/test_case/complex/case1: -------------------------------------------------------------------------------- 1 | CREATE TABLE csq_1(id int, col1 int, feat1 float); 2 | CREATE TABLE csq_2(id int, col2 int, feat2 float); 3 | CREATE TABLE csq_3(id int, col3 int, feat3 float); 4 | CREATE TABLE csq_4(id int, col4 int, feat4 float); 5 | INSERT INTO csq_1 VALUES (1, 4, 11.2); 6 | INSERT INTO csq_1 VALUES (2, 2, 12.0); 7 | INSERT INTO csq_1 VALUES (3, 3, 13.5); 8 | INSERT INTO csq_2 VALUES (1, 2, 13.0); 9 | INSERT INTO csq_2 VALUES (2, 7, 10.5); 10 | INSERT INTO csq_2 VALUES (5, 3, 12.6); 11 | INSERT INTO csq_3 VALUES (1, 2, 11.0); 12 | INSERT INTO csq_3 VALUES (3, 6, 16.5); 13 | INSERT INTO csq_3 VALUES (5, 5, 14.6); 14 | SELECT * FROM csq_1 WHERE id IN (SELECT csq_2.id FROM csq_2 WHERE csq_2.id IN (SELECT csq_3.id FROM csq_3)); 15 | drop table csq_1; 16 | drop table csq_2; 17 | drop table csq_3; 18 | -------------------------------------------------------------------------------- /test/test_case/complex/case2: -------------------------------------------------------------------------------- 1 | create table CSQ_1(ID int, COL1 int, FEAT1 float); 2 | create table CSQ_2(ID int, COL2 int, FEAT2 float); 3 | create table CSQ_3(ID int, COL3 int, FEAT3 float); 4 | insert into CSQ_1 values (0,2,1.0),(1,0,13.0), (1,4,11.2), (2,2,12.0), (3,3,13.5); 5 | insert into CSQ_2 values (0,2,14.0),(1,2,2.0); 6 | insert into CSQ_3 values (0,-2, 0.5),(1,2,2.0); 7 | SELECT * FROM CSQ_1 WHERE (SELECT MAX(CSQ_2.FEAT2) FROM CSQ_2) > FEAT1 AND COL1 > (SELECT MIN(CSQ_3.COL3) FROM CSQ_3); 8 | drop table CSQ_1; 9 | drop table CSQ_2; 10 | drop table CSQ_3; -------------------------------------------------------------------------------- /test/test_case/complex/case3: -------------------------------------------------------------------------------- 1 | create table CSQ_1(ID int, COL1 int , FEAT1 float); 2 | create table CSQ_2(ID int , COL2 int, FEAT2 float); 3 | create table CSQ_3(ID int , COL3 int, FEAT3 float); 4 | INSERT INTO CSQ_1 VALUES (1, 4, 11.2); 5 | INSERT INTO CSQ_1 VALUES (2, 2, 12.0); 6 | INSERT INTO CSQ_1 VALUES (3, 3, 13.5); 7 | INSERT INTO CSQ_2 VALUES (1, 2, 13.0); 8 | INSERT INTO CSQ_2 VALUES (2, 7, 10.5); 9 | INSERT INTO CSQ_2 VALUES (5, 3, 12.6); 10 | INSERT INTO CSQ_3 VALUES (1, 2, 11.0); 11 | INSERT INTO CSQ_3 VALUES (3, 6, 16.5); 12 | INSERT INTO CSQ_3 VALUES (5, 5, 14.6); 13 | SELECT * FROM CSQ_1 WHERE COL1 > (SELECT AVG(CSQ_2.COL2) FROM CSQ_2 WHERE CSQ_2.FEAT2 >= (SELECT MIN(CSQ_3.FEAT3) FROM CSQ_3)); 14 | SELECT * FROM CSQ_1 WHERE (SELECT AVG(CSQ_2.COL2) FROM CSQ_2 WHERE CSQ_2.FEAT2 > (SELECT MIN(CSQ_3.FEAT3) FROM CSQ_3)) = COL1; 15 | SELECT * FROM CSQ_1 WHERE (SELECT AVG(CSQ_2.COL2) FROM CSQ_2) <> (SELECT AVG(CSQ_3.FEAT3) FROM CSQ_3); 16 | SELECT * FROM CSQ_1 WHERE FEAT1 > (SELECT MIN(CSQ_2.FEAT2) FROM CSQ_2) AND COL1 <= (SELECT MIN(CSQ_3.COL3) FROM CSQ_3); 17 | SELECT * FROM CSQ_1 WHERE FEAT1 <> (SELECT AVG(CSQ_2.FEAT2) FROM CSQ_2 WHERE CSQ_2.FEAT2 > CSQ_1.FEAT1); 18 | SELECT * FROM CSQ_3 WHERE FEAT3 < (SELECT MAX(CSQ_2.FEAT2) FROM CSQ_2 WHERE CSQ_2.ID NOT IN (SELECT CSQ_3.ID FROM CSQ_3 ) AND 1=0); 19 | drop table CSQ_1; 20 | drop table CSQ_2; 21 | DROP TABLE CSQ_3; -------------------------------------------------------------------------------- /test/test_case/date/compare_date_1: -------------------------------------------------------------------------------- 1 | create table t1 (a int, b date); 2 | insert into t1 values(1,'2020-1-3'); 3 | insert into t1 values(2,'2020-01-3'); 4 | insert into t1 values(3,'2020-1-03'); 5 | insert into t1 values(4,'2020-01-03'); 6 | insert into t1 values(5,'2020-02-3'); 7 | insert into t1 values(6, '2010-3-5'); 8 | insert into t1 values(7, '2000-3-5'); 9 | insert into t1 values(8, '1990-12-5'); 10 | insert into t1 values(9, '1980-2-5'); 11 | insert into t1 values(10, '1970-12-31'); 12 | select * from t1; 13 | select * from t1 where b < '2020-3-4'; 14 | select b from t1 where b < '2020-3-4'; 15 | select * from t1 where b <= '2008-2-29'; 16 | select * from t1 where b > '2008-2-29'; 17 | select * from t1 where b >= '2008-2-29'; 18 | select * from t1 where b = '2008-2-29'; 19 | select * from t1 where b = '2000-3-5'; 20 | select b from t1 where b < '2021-2-29'; 21 | select b from t1 where b >= '2020-12-32'; 22 | delete from t1 where b = '1970-12-31'; 23 | select * from t1; 24 | select * from t1; 25 | select * from t1; 26 | drop table t1; -------------------------------------------------------------------------------- /test/test_case/date/compare_date_2: -------------------------------------------------------------------------------- 1 | create table t3 (a int, b date); 2 | insert into t3 values(1,'2020-1-3'); 3 | insert into t3 values(2,'2020-01-3'); 4 | insert into t3 values(3,'2020-1-03'); 5 | insert into t3 values(4,'2020-01-03'); 6 | insert into t3 values(5,'2020-02-3'); 7 | insert into t3 values(6, '2010-3-5'); 8 | insert into t3 values(7, '2000-3-5'); 9 | insert into t3 values(8, '1990-12-5'); 10 | insert into t3 values(9, '1980-2-5'); 11 | insert into t3 values(10, '1970-12-31'); 12 | select * from t3; 13 | select * from t3 where b < '2020-3-4'; 14 | select b from t3 where b < '2020-3-4'; 15 | select * from t3 where b <= '2008-2-29'; 16 | select * from t3 where b > '2008-2-29'; 17 | select * from t3 where b >= '2008-2-29'; 18 | select * from t3 where b = '2008-2-29'; 19 | select * from t3 where b = '2000-3-5'; 20 | select b from t3 where b < '2021-2-29'; 21 | select b from t3 where b >= '2020-12-32'; 22 | select * from t3 where '2010-1-1' >= b; 23 | select * from t3 where '2000-3-5' >= b; 24 | select * from t3 where '2000-3-5' > b; 25 | select * from t3 where '2000-3-5' < b; 26 | select * from t3 where '2000-3-5' <= b; 27 | select * from t3 where '2021-2-29' < b; 28 | select * from t3 where '2010-2-28' < b; 29 | drop table t3; 30 | -------------------------------------------------------------------------------- /test/test_case/date/compare_date_4: -------------------------------------------------------------------------------- 1 | create table t_basic(id int, age int, name char, score float); 2 | insert into t_basic values(1,1, 'a', 1.0); 3 | insert into t_basic values(2,2, 'b', 2.0); 4 | insert into t_basic values(4,4, 'c', 3.0); 5 | insert into t_basic values(3,3, 'd', 4.0); 6 | insert into t_basic values(5,5, 'e', 5.5); 7 | insert into t_basic values(6,6, 'f', 6.6); 8 | insert into t_basic values(7,7, 'g', 7.7); 9 | select * from t_basic; 10 | delete from t_basic where id=3; 11 | select * from t_basic; 12 | select * from t_basic where id=1; 13 | select * from t_basic where id>=5; 14 | select * from t_basic where age>1 and age<3; 15 | select * from tbasic where tbasic.id=1 and t_basic.age=1; 16 | select * from t_basic where id=1 and age=1; 17 | select id, age, name, score from t_basic; 18 | select tbasic.id, tbasic.age, tbasic.name, tbasic.score from t_basic; 19 | select tbasic.id, tbasic.age, name from t_basic; 20 | create index iid on tbasic (id); 21 | select * from t_basic; 22 | drop table t_basic; -------------------------------------------------------------------------------- /test/test_case/date/compare_date_5: -------------------------------------------------------------------------------- 1 | Select * from t1 where d > '2039-2-10'; 2 | Select * from t1 where d > '2040-5-3'; 3 | Select * from t1 where d <= '1969-12-31'; 4 | Select * from t1 where d < '1950-1-31'; 5 | Select * from t1 where d <> '2010-13-21'; 6 | Select * from t1 where d = '2010-15-2'; 7 | Select * from t1 where d <> '2010-0-21'; 8 | Select * from t1 where d = '2010-0-2'; 9 | Select * from t1 where d < '2021-1-32'; 10 | Select * from t1 where d > '2021-2-29'; 11 | Select * from t1 where d = '2021-3-32'; 12 | Select * from t1 where d <= '2021-4-31'; 13 | Select * from t1 where d <= '2021-5-32'; 14 | Select * from t1 where d >= '2021-6-31'; 15 | Select * from t1 where d < '2021-7-32'; 16 | Select * from t1 where d <> '2021-8-32'; 17 | Select * from t1 where d < '2021-9-31'; 18 | Select * from t1 where d <> '2021-10-32'; 19 | Select * from t1 where d <> '2021-11-31'; 20 | Select * from t1 where d = '2021-12-32'; 21 | Select * from t1 where d = '2021-1-0'; 22 | Select * from t1 where d = '2021-0-0'; -------------------------------------------------------------------------------- /test/test_case/date/compare_date_6: -------------------------------------------------------------------------------- 1 | create table t3 (a int, b float, c char, d date); 2 | insert into t3 values(1,1.1,'a','2020-1-3'); 3 | insert into t3 values(2,1.2,'b','2019-2-28'); 4 | insert into t3 values(3,1.3,'c','2018-3-30'); 5 | insert into t3 values(4,1.4,'d','2017-4-29'); 6 | insert into t3 values(5,1.5,'e','2016-5-30'); 7 | insert into t3 values(6,1.6,'f','2015-6-29'); 8 | insert into t3 values(7,-1.1,'g','2014-7-28'); 9 | insert into t3 values(8,-2.2,'h','2013-8-29'); 10 | Select * from t3 where d <> '2010-13-21'; 11 | Select * from t3 where d = '2010-15-2'; 12 | Select * from t3 where d <> '2010-0-21'; 13 | Select * from t3 where d = '2010-0-2'; 14 | Select * from t3 where d < '2021-1-32'; 15 | Select * from t3 where d > '2021-2-29'; 16 | Select * from t3 where d = '2021-3-32'; 17 | Select * from t3 where d <= '2021-4-31'; 18 | Select * from t3 where d <= '2021-5-32'; 19 | Select * from t3 where d >= '2021-6-31'; 20 | Select * from t3 where d < '2021-7-32'; 21 | Select * from t3 where d <> '2021-8-32'; 22 | Select * from t3 where d < '2021-9-30'; 23 | Select * from t3 where d <> '2021-10-32'; 24 | Select * from t3 where d <> '2021-11-31'; 25 | Select * from t3 where d = '2021-12-32'; 26 | Select * from t3 where d = '2021-1-0'; 27 | Select * from t3 where d = '2021-0-0'; 28 | Select a from t3 where d <= '2019-2-28'; 29 | Select a from t3 where '2018-2-28' > d; 30 | Select b from t3 where '2019-2-28' = d; 31 | Select a from t3 where '2017-4-29' <> d; 32 | Select * from t3 where '2015-6-30' <= d; 33 | Select * from t3 where d > '2018-2-27'; 34 | drop table t3; -------------------------------------------------------------------------------- /test/test_case/date/compare_date_index_1: -------------------------------------------------------------------------------- 1 | create table t7 (a int, b float, c char, d date); 2 | create index c_id on t7 (c); 3 | insert into t7 values(1,1.1,'a','2020-1-3'); 4 | insert into t7 values(2,1.2,'b','2019-2-28'); 5 | insert into t7 values(3,1.3,'c','2018-3-30'); 6 | insert into t7 values(4,1.4,'d','2017-4-29'); 7 | insert into t7 values(5,1.5,'e','2016-5-30'); 8 | insert into t7 values(6,1.6,'f','2015-6-29'); 9 | insert into t7 values(7,-1.1,'g','2014-7-28'); 10 | insert into t7 values(8,-2.2,'h','2013-8-29'); 11 | Select * from t7 where d <> '2010-13-21'; 12 | Select * from t7 where d = '2010-15-2'; 13 | Select * from t7 where d <> '2010-0-21'; 14 | Select * from t7 where d = '2010-0-2'; 15 | Select * from t7 where d < '2021-1-32'; 16 | Select * from t7 where d > '2021-2-29'; 17 | Select * from t7 where d = '2021-3-32'; 18 | Select * from t7 where d <= '2021-4-31'; 19 | Select * from t7 where d <= '2021-5-32'; 20 | Select * from t7 where d >= '2021-6-31'; 21 | Select * from t7 where d < '2021-7-32'; 22 | Select * from t7 where d <> '2021-8-32'; 23 | Select * from t7 where d < '2021-9-30'; 24 | Select * from t7 where d <> '2021-10-32'; 25 | Select * from t7 where d <> '2021-11-31'; 26 | Select * from t7 where d = '2021-12-32'; 27 | Select * from t7 where d = '2021-1-0'; 28 | Select * from t7 where d = '2021-0-0'; 29 | Select a from t7 where d <= '2019-2-28'; 30 | Select a from t7 where '2018-2-28' > d; 31 | Select a from t7 where '2017-4-29' <= d; 32 | Select b from t7 where '2019-2-28' = d; 33 | Select a from t7 where '2017-4-29' <> d; 34 | Select * from t7 where d >= '2015-6-30'; 35 | Select * from t7 where d > '2018-2-27'; 36 | drop table t7; -------------------------------------------------------------------------------- /test/test_case/date/compare_date_index_2: -------------------------------------------------------------------------------- 1 | create table t4 (a int, b float, c char, d date); 2 | create index a_id on t4 (a); 3 | insert into t4 values(8,-2.2,'h','2013-8-29'); 4 | insert into t4 values(2,-1.1,'g','2014-7-28'); 5 | insert into t4 values(6,1.6,'f','2015-6-29'); 6 | insert into t4 values(5,1.5,'e','2016-5-30'); 7 | select * from t4 where a <> 6; 8 | drop table t4; -------------------------------------------------------------------------------- /test/test_case/date/delete_date_1: -------------------------------------------------------------------------------- 1 | create table t1 (a int, b date, c chars); 2 | delete from t1 where b='2020-02-30'; -------------------------------------------------------------------------------- /test/test_case/drop_table/drop_table_1: -------------------------------------------------------------------------------- 1 | create table t (a int); 2 | drop table t; 3 | -------------------------------------------------------------------------------- /test/test_case/drop_table/drop_table_2: -------------------------------------------------------------------------------- 1 | drop table t; 2 | -------------------------------------------------------------------------------- /test/test_case/drop_table/drop_table_3: -------------------------------------------------------------------------------- 1 | create table t (a int); 2 | drop table t; 3 | drop table t; 4 | -------------------------------------------------------------------------------- /test/test_case/drop_table/drop_table_4: -------------------------------------------------------------------------------- 1 | create table t(id int, age int); 2 | create table t(id int, name char); 3 | drop table t; 4 | create table t(id int, name char); 5 | drop table t; 6 | -------------------------------------------------------------------------------- /test/test_case/expression/case1: -------------------------------------------------------------------------------- 1 | create table t_expr1 (id int, name char, age int, col1 int); 2 | create table t_expr2 (id int, name char, age int, col2 int); 3 | insert into t_expr1 values(1,'hu',19, 1); 4 | insert into t_expr1 values(2,'hu',29, 2); 5 | insert into t_expr1 values(3,'hu',39, 3); 6 | insert into t_expr1 values(4,'hu',49, 4); 7 | insert into t_expr1 values(5,'hu',59, 5); 8 | insert into t_expr2 values(6,'hu',49, 6); 9 | insert into t_expr2 values(7,'hu',39, 7); 10 | insert into t_expr2 values(8,'hu',29, 8); 11 | insert into t_expr2 values(9,'hu',19, 9); 12 | insert into t_expr2 values(10,'hu',9, 9); 13 | select t_expr1.col1+t_expr2.col2 from t_expr1,t_expr2 where t_expr1.age +10 > t_expr2.age *2 + 3-(t_expr1.age +10)/3; 14 | select * from t_expr1,t_expr2 where t_expr1.age +10 > t_expr2.age *2 + 3-(t_expr1.age +10)/3; 15 | select t_expr1.id from t_expr1,t_expr2 where t_expr1.age +10 > t_expr2.age *2 + 3-(t_expr1.age +10)/3; 16 | drop table t_expr1; 17 | drop table t_expr2; -------------------------------------------------------------------------------- /test/test_case/expression/case2: -------------------------------------------------------------------------------- 1 | create table EXP_TABLE (ID int, COL1 int, COL2 int, COL3 float, COL4 int); 2 | insert into EXP_TABLE values(3,3,4,5.0,4); 3 | insert into EXP_TABLE values(2,2,-2,5.5,1); 4 | SELECT * FROM EXP_TABLE WHERE 1 = 5/4; 5 | SELECT * FROM EXP_TABLE WHERE COL1-2 > 0; 6 | SELECT * FROM EXP_TABLE WHERE 2+COL2 < 1; 7 | SELECT * FROM EXP_TABLE WHERE COL1*COL2 < 0; 8 | drop table EXP_TABLE; -------------------------------------------------------------------------------- /test/test_case/expression/case3: -------------------------------------------------------------------------------- 1 | create table EXP_TABLE (ID int, COL1 int, COL2 int, COL3 float, COL4 int); 2 | insert into EXP_TABLE values(2,2,-2,5.5,1),(3,3,4,5.0,4); 3 | SELECT ID,-(COL2*(-1)+1)+(COL4+2)*(COL1+COL3*2),(4+COL2)*COL3/2 FROM EXP_TABLE WHERE -(COL2*(-1)+1)+(COL4+2)*(COL1+COL3*2) > (4+COL2)*COL3/2; 4 | select ID,COL1,COL2,COL3,COL4,6-(COL2*(1+COL1))+(COL4+2)/(1+COL1*4+COL3*2) from EXP_TABLE where 6-(COL2*(1+COL1))+(COL4+2)/(1+COL1*4+COL3*2) > 5; 5 | select ID,COL1,COL2,COL3,COL4,3*COL1/(COL2+2) from EXP_TABLE where 3*COL1/(COL2+2) > 1; 6 | select ID,3*COL1/(COL2+2) from EXP_TABLE where 3*COL1/(COL2+2)+1/0 > 1; 7 | select * from EXP_TABLE where 1/0 = 1/0; 8 | drop table EXP_TABLE; -------------------------------------------------------------------------------- /test/test_case/group/group_case_1: -------------------------------------------------------------------------------- 1 | create table t_group_1(id int, name char, score float, age int); 2 | create table t_group_2(id int, name char, score float, age int); 3 | insert into t_group_1 values(1, 'hu', 90.0, 18); 4 | insert into t_group_1 values(2, 'liu', 80.0, 22); 5 | insert into t_group_1 values(3, 'li', 70.0, 18); 6 | insert into t_group_1 values(4, 'we', 100.0, 18); 7 | insert into t_group_1 values(5, 'li', 80.0, 22); 8 | insert into t_group_1 values(6, 'we', 70.0, 18); 9 | insert into t_group_1 values(7, 'aa', 60.0, 18); 10 | insert into t_group_2 values(1, 'hu', 90.0, 18); 11 | insert into t_group_2 values(2, 'liu', 80.0, 22); 12 | insert into t_group_2 values(3, 'li', 70.0, 18); 13 | insert into t_group_2 values(4, 'we', 100.0, 18); 14 | insert into t_group_2 values(5, 'li', 80.0, 22); 15 | insert into t_group_2 values(6, 'we', 70.0, 18); 16 | select t_group_1.id, t_group_1.name, avg(t_group_1.score), avg(t_group_2.age) from t_group_1,t_group_2 where t_group_1.id=t_group_2.id group by t_group_1.id,t_group_1.name; 17 | select t_group_1.id, max(t_group_1.name),min(t_group_1.score),count(t_group_1.age),avg(t_group_1.age) from t_group_1,t_group_2 where t_group_1.id=t_group_2.id group by t_group_1.id; 18 | select id, avg(age) from t_group_1 group by id,score; 19 | select t_group_1.id, max(t_group_1.score) from t_group_1 group by t_group_1.name; 20 | select id, avg(score) from t_group_1 group by id; 21 | select id, avg(score) from t_group_1 where id = 10 group by id; 22 | select t_group_1.id, t_group_1.name, avg(t_group_1.score), avg(t_group_2.age) from t_group_1,t_group_2 where t_group_1.id=10 group by t_group_1.id,t_group_1.name; 23 | select max(id), score from t_group_1 group by name; 24 | drop table t_group_1; 25 | drop table t_group_2; -------------------------------------------------------------------------------- /test/test_case/group/group_case_2: -------------------------------------------------------------------------------- 1 | create table t_group_by(id char, score float); 2 | create index t_id on t_group_by(id); 3 | insert into t_group_by values('1',2.0); 4 | insert into t_group_by values('1',2.0); 5 | insert into t_group_by values('3',2.4); 6 | insert into t_group_by values('3',2.4); 7 | insert into t_group_by values('4',3.0); 8 | insert into t_group_by values('4',3.0); 9 | insert into t_group_by values('4',3.0); 10 | SELECT id, AVG(score) FROM t_group_by GROUP BY id; 11 | drop table t_group_by; -------------------------------------------------------------------------------- /test/test_case/group/group_case_3: -------------------------------------------------------------------------------- 1 | create table t_group_by (id int, score float, name char); 2 | insert into t_group_by values(3, 1.0, 'a'); 3 | insert into t_group_by values(1, 2.0, 'b'); 4 | insert into t_group_by values(4, 3.0, 'c'); 5 | insert into t_group_by values(3, 2.0, 'c'); 6 | insert into t_group_by values(3, 4.0, 'c'); 7 | insert into t_group_by values(3, 3.0, 'd'); 8 | insert into t_group_by values(3, 2.0, 'f'); 9 | SELECT id, avg(score) FROM t_group_by GROUP BY id; 10 | drop table t_group_by; -------------------------------------------------------------------------------- /test/test_case/group/group_case_4: -------------------------------------------------------------------------------- 1 | create table T_GROUP_BY (ID int, NAME char, SCORE int); 2 | create table T_GROUP_BY_2 (ID int, NAME char, AGE float); 3 | insert into T_GROUP_BY values(1, 'B', 2); 4 | insert into T_GROUP_BY values(1, 'B', 2); 5 | insert into T_GROUP_BY_2 values(1, 'B', 10.0); 6 | insert into T_GROUP_BY_2 values(1, 'B', 10.0); 7 | insert into T_GROUP_BY values(3, 'A', 1); 8 | insert into T_GROUP_BY values(3, 'C', 3); 9 | insert into T_GROUP_BY values(3, 'D', 3); 10 | insert into T_GROUP_BY values(3, 'F', 2); 11 | insert into T_GROUP_BY_2 values(3,'A', 23.33); 12 | insert into T_GROUP_BY_2 values(3,'C', 23.33); 13 | insert into T_GROUP_BY_2 values(3,'D', 23.33); 14 | insert into T_GROUP_BY values(4, 'C', 3); 15 | insert into T_GROUP_BY_2 values(4,'C', 20.0); 16 | SELECT T_GROUP_BY.ID, T_GROUP_BY.NAME, AVG(T_GROUP_BY.SCORE), AVG(T_GROUP_BY_2.AGE) FROM T_GROUP_BY, T_GROUP_BY_2 WHERE T_GROUP_BY.ID=T_GROUP_BY_2.ID GROUP BY T_GROUP_BY.ID, T_GROUP_BY.NAME; 17 | drop table T_GROUP_BY; 18 | drop table T_GROUP_BY_2; -------------------------------------------------------------------------------- /test/test_case/inner_join/case_1: -------------------------------------------------------------------------------- 1 | create table t1 (a int); 2 | create table t2 (b int); 3 | insert into t1 values(1); 4 | insert into t1 values(2); 5 | insert into t2 values(1); 6 | select t1.a,t2.b from t1 inner join t2 on t1.a=t2.b; 7 | select t2.b,t1.a from t1 inner join t2 on t1.a=t2.b; 8 | select * from t1 inner join t2 on t1.a>t2.b; 9 | drop table t1; 10 | drop table t2; -------------------------------------------------------------------------------- /test/test_case/inner_join/case_2: -------------------------------------------------------------------------------- 1 | create table t1 (a int); 2 | create table t2 (b int); 3 | create table t3 (c char,d int); 4 | insert into t1 values(1); 5 | insert into t1 values(2); 6 | insert into t2 values(1); 7 | insert into t3 values('a',2); 8 | select t2.b,t1.a,t3.c from t1 inner join t2 on t1.a=t2.b inner join t3 on t3.d>t2.b and t3.d>t1.a; 9 | drop table t1; 10 | drop table t2; 11 | drop table t3; -------------------------------------------------------------------------------- /test/test_case/inner_join/case_3: -------------------------------------------------------------------------------- 1 | create table t1 (a int); 2 | create table t2 (b int); 3 | insert into t1 values(1); 4 | insert into t2 values(2); 5 | insert into t2 values(3); 6 | insert into t1 values(0); 7 | select avg(t1.a),max(t2.b) from t1 inner join t2 on t2.b > t1.a; 8 | insert into t1 values(2); 9 | select max(t2.b),avg(t1.a) from t1 inner join t2 on t2.b > t1.a; 10 | drop table t1; 11 | drop table t2; -------------------------------------------------------------------------------- /test/test_case/inner_join/case_4: -------------------------------------------------------------------------------- 1 | create table t1(a int); 2 | create table t2(b int); 3 | create table t3(c int); 4 | select * from t1, t2, inner join t1 on t1.a=t2.b, t3; 5 | drop table t1; 6 | drop table t2; 7 | drop table t3; -------------------------------------------------------------------------------- /test/test_case/insert/case_1: -------------------------------------------------------------------------------- 1 | create table t (a int, b int); 2 | insert into t values(1,2),(2,3); 3 | select * from t; 4 | drop table t; 5 | -------------------------------------------------------------------------------- /test/test_case/insert/case_2: -------------------------------------------------------------------------------- 1 | create table t (a date,b int); 2 | create index t1 on t(a); 3 | insert into t values ('2020-1-1',1),('2000-1-29',2),('2012-2-1',2); 4 | delete from t where a>'2012-2-29'; 5 | select * from t; 6 | drop table t; 7 | -------------------------------------------------------------------------------- /test/test_case/insert/case_3: -------------------------------------------------------------------------------- 1 | create table t (a date,b int); 2 | create index t1 on t(a); 3 | insert into t values ('2020-1-1',1),('2000-1-39',2),('2012-2-1',2); 4 | select * from t; 5 | drop table t; 6 | -------------------------------------------------------------------------------- /test/test_case/metadata_verification/case_1: -------------------------------------------------------------------------------- 1 | create table t(id int, age int); 2 | select * from t where name='a'; 3 | select address from t where id=1; 4 | select * from t_1000; 5 | insert into t_1000 values(1); 6 | select id, name from t; 7 | select name, id from t; 8 | drop table t; 9 | -------------------------------------------------------------------------------- /test/test_case/metadata_verification/case_2: -------------------------------------------------------------------------------- 1 | create table t (a float); 2 | insert into t values(17.10); 3 | insert into t values(17.01); 4 | insert into t values(17.001); 5 | insert into t values(17.045); 6 | select * from t; 7 | drop table t; 8 | -------------------------------------------------------------------------------- /test/test_case/multi_index/case_1: -------------------------------------------------------------------------------- 1 | create table t (a int,b int); 2 | create index t1 on t(a,b); 3 | drop table t; -------------------------------------------------------------------------------- /test/test_case/multi_index/case_2: -------------------------------------------------------------------------------- 1 | create table t (a int,b char); 2 | create index t1 on t (a,b); 3 | create index t2 on t (b,a); 4 | create index t3 on t (a); 5 | drop table t; -------------------------------------------------------------------------------- /test/test_case/multi_index/case_3: -------------------------------------------------------------------------------- 1 | create table t (a int, b char); 2 | create index t1 on t(a,b); 3 | insert into t values (3,'b'),(2,'c'),(1,'a'); 4 | delete from t where a = 2; 5 | select * from t where a >= 2; 6 | delete from t where a = 2; 7 | drop table t; -------------------------------------------------------------------------------- /test/test_case/multi_index/case_4: -------------------------------------------------------------------------------- 1 | CREATE TABLE MULTI_INDEX(ID INT, COL1 INT, COL2 FLOAT, COL3 CHAR, COL4 DATE, COL5 INT, COL6 INT); 2 | CREATE INDEX I_1_12 ON MULTI_INDEX(COL1,COL2); 3 | CREATE INDEX I_1_345 ON MULTI_INDEX(COL3, COL4, COL5); 4 | CREATE INDEX I_1_56 ON MULTI_INDEX(COL5, COL6); 5 | CREATE INDEX I_1_456 ON MULTI_INDEX(COL4, COL5, COL6); 6 | SELECT * FROM MULTI_INDEX; 7 | DROP TABLE MULTI_INDEX; -------------------------------------------------------------------------------- /test/test_case/multi_table/case_1: -------------------------------------------------------------------------------- 1 | create table t1 (a int); 2 | create table t2 (b int); 3 | select * from t1,t2; 4 | insert into t1 values(1); 5 | insert into t2 values(2); 6 | select * from t1,t2; 7 | drop table t1; 8 | drop table t2; -------------------------------------------------------------------------------- /test/test_case/multi_table/case_2: -------------------------------------------------------------------------------- 1 | create table t1 (a char); 2 | create table t2 (b char); 3 | insert into t1 values('a'); 4 | insert into t2 values('b'); 5 | insert into t2 values('a'); 6 | select t1.a from t1,t2 where t1.a=t2.b; 7 | select t2.*,t1.* from t1,t2 where t1.a 1.0; 7 | drop table t; -------------------------------------------------------------------------------- /test/test_case/null/case_3: -------------------------------------------------------------------------------- 1 | create table t (a int nullable, b float); 2 | insert into t values(1,1.0),(null,2.0); 3 | select * from t where a is null; 4 | select * from t where a is not null; 5 | drop table t; -------------------------------------------------------------------------------- /test/test_case/null/case_4: -------------------------------------------------------------------------------- 1 | create table t (a int nullable, b float); 2 | insert into t values(1,1.0),(null,2.0); 3 | create index t1 on t(a); 4 | select * from t where a is null; 5 | select * from t where a is not null; 6 | select * from t where a > 0; 7 | select * from t where null is not null; 8 | drop table t; -------------------------------------------------------------------------------- /test/test_case/null/case_5: -------------------------------------------------------------------------------- 1 | CREATE TABLE NULL_TABLE(ID INT, NUM INT NULLABLE, PRICE FLOAT NOT NULL, BIRTHDAY DATE NULLABLE); 2 | CREATE TABLE NULL_TABLE2(ID INT, NUM INT NULLABLE, PRICE FLOAT NOT NULL, BIRTHDAY DATE NULLABLE); 3 | CREATE INDEX INDEX_NUM ON NULL_TABLE(NUM); 4 | DROP TABLE NULL_TABLE; 5 | DROP TABLE NULL_TABLE2; -------------------------------------------------------------------------------- /test/test_case/order/case_1: -------------------------------------------------------------------------------- 1 | create table t (a char); 2 | insert into t values('b'); 3 | insert into t values('c'); 4 | insert into t values('a'); 5 | select * from t order by a; 6 | drop table t; -------------------------------------------------------------------------------- /test/test_case/order/case_2: -------------------------------------------------------------------------------- 1 | create table t (a int, b char); 2 | insert into t values(1,'b'); 3 | insert into t values(1,'c'); 4 | insert into t values(3,'c'); 5 | insert into t values(2,'d'); 6 | select a,b from t order by a, b desc; 7 | drop table t; -------------------------------------------------------------------------------- /test/test_case/order/case_3: -------------------------------------------------------------------------------- 1 | create table t1 (a int); 2 | create table t2 (b int); 3 | insert into t1 values(1); 4 | insert into t1 values(3); 5 | insert into t2 values(2); 6 | insert into t2 values(4); 7 | select * from t1,t2 where t1.a < t2.b order by t2.b,t1.a; 8 | select * from t2,t1 order by t2.b; 9 | select * from t2,t1 order by b; 10 | drop table t1; 11 | drop table t2; -------------------------------------------------------------------------------- /test/test_case/order/case_4: -------------------------------------------------------------------------------- 1 | create table t_orderby (ID int, SCORE int, NAME char); 2 | insert into t_orderby values(3, 1, 'A'); 3 | insert into t_orderby values(3, 2, 'F'); 4 | insert into t_orderby values(3, 2, 'C'); 5 | insert into t_orderby values(3, 3, 'D'); 6 | insert into t_orderby values(3, 4, 'C'); 7 | insert into t_orderby values(3, 2, 'E'); 8 | SELECT * FROM t_orderby WHERE ID=3 AND NAME>='A' ORDER BY SCORE DESC, NAME; 9 | drop table t_orderby; -------------------------------------------------------------------------------- /test/test_case/sub-query/case1: -------------------------------------------------------------------------------- 1 | create table t_query_1(name char, age int); 2 | create table t_query_2(name char, age int); 3 | insert into t_query_1 values('a', 20); 4 | insert into t_query_1 values('a', 50); 5 | insert into t_query_1 values('b', 60); 6 | insert into t_query_1 values('c', 2); 7 | insert into t_query_2 values('a', 50); 8 | insert into t_query_2 values('a', 10); 9 | insert into t_query_2 values('b', 30); 10 | select * from t_query_1 where name in(select name from t_query_2); 11 | select * from t_query_1 where t_query_1.age >(select max(t_query_2.age) from t_query_2); 12 | select * from t_query_1 where t_query_1.age > (select avg(t_query_2.age) from t_query_2) and t_query_1.age > 20.0; 13 | select * from t_query_1 where name not in(select name from t_query_2); 14 | drop table t_query_1; 15 | drop table t_query_2; -------------------------------------------------------------------------------- /test/test_case/sub-query/case2: -------------------------------------------------------------------------------- 1 | create table SSQ_1 (ID int, COL1 int, FEAT1 float); 2 | create table SSQ_2 (ID int, COL2 int, FEAT2 float); 3 | insert into SSQ_1 values(1, 4, 11.2); 4 | insert into SSQ_1 values(2, 2, 12.0); 5 | insert into SSQ_1 values(3, 3, 13.5); 6 | insert into SSQ_2 values(2, 2, 12.0); 7 | insert into SSQ_2 values(1, 2, 12.0); 8 | insert into SSQ_2 values(1, 2, 11.0); 9 | SELECT * FROM SSQ_1 WHERE ID IN (SELECT SSQ_2.ID FROM SSQ_2); 10 | SELECT * FROM SSQ_1 WHERE COL1 NOT IN (SELECT SSQ_2.COL2 FROM SSQ_2); 11 | SELECT * FROM SSQ_1 WHERE (SELECT AVG(SSQ_2.COL2) FROM SSQ_2) = COL1; 12 | SELECT * FROM SSQ_1 WHERE (SELECT MIN(SSQ_2.FEAT2) FROM SSQ_2) <= FEAT1; 13 | SELECT * FROM SSQ_1 WHERE FEAT1 < (SELECT MAX(SSQ_2.FEAT2) FROM SSQ_2 WHERE 1=0); 14 | SELECT * FROM SSQ_1 WHERE FEAT1 < (SELECT MAX(SSQ_2.FEAT2) FROM SSQ_2 WHERE 1=0); 15 | SELECT * FROM SSQ_1 WHERE ID IN (SELECT SSQ_2.ID FROM SSQ_2 WHERE 1=0); 16 | SELECT * FROM SSQ_1 WHERE ID NOT IN (SELECT SSQ_2.ID FROM SSQ_2 WHERE 1=0); 17 | SELECT * FROM SSQ_1 WHERE ID > (SELECT SSQ_2.ID FROM SSQ_2 WHERE SSQ_2.ID >= 2); 18 | SELECT * FROM SSQ_1 WHERE COL1 = (SELECT SSQ_2.COL2 FROM SSQ_2); 19 | SELECT * FROM SSQ_1 WHERE COL1 = (SELECT * FROM SSQ_2); 20 | SELECT * FROM SSQ_1 WHERE COL1 IN (SELECT * FROM SSQ_2); 21 | SELECT * from SSQ_1 where COL1 NOT IN (SELECT * FROM SSQ_2); 22 | drop table SSQ_1; 23 | drop table SSQ_2; -------------------------------------------------------------------------------- /test/test_case/unique_index/case_1: -------------------------------------------------------------------------------- 1 | create table t(a int); 2 | insert into t values(1); 3 | insert into t values(1); 4 | create unique index t1 on t(a); 5 | delete from t; 6 | insert into t values(1); 7 | create unique index t1 on t(a); 8 | insert into t values(2); 9 | insert into t values(1); 10 | update t set a=1 where a=2; 11 | update t set a=3 where a=2; 12 | drop table t; 13 | -------------------------------------------------------------------------------- /test/test_case/unique_index/case_2: -------------------------------------------------------------------------------- 1 | create table t(a date); 2 | insert into t values('2020-01-1'); 3 | insert into t values('2020-1-01'); 4 | create unique index t1 on t(a); 5 | delete from t; 6 | insert into t values('2020-1-1'); 7 | create unique index t1 on t(a); 8 | insert into t values('2020-1-2'); 9 | insert into t values('2020-1-1'); 10 | update t set a='2020-1-1' where a='2020-1-2'; 11 | update t set a='2020-1-3' where a='2020-1-2'; 12 | drop table t; -------------------------------------------------------------------------------- /test/test_case/unique_index/case_3: -------------------------------------------------------------------------------- 1 | create table t(a date); 2 | insert into t values('2020-01-1'); 3 | insert into t values('2020-1-01'); 4 | create unique index t1 on t(a); 5 | delete from t; 6 | insert into t values('2020-1-1'); 7 | create unique index t1 on t(a); 8 | insert into t values('2020-1-2'); 9 | insert into t values('2020-1-1'); 10 | update t set a='2020-1-1' where a='2020-1-2'; 11 | update t set a='2020-1-3' where a='2020-1-2'; 12 | select * from t where '2019-12-01' < a; 13 | drop table t; -------------------------------------------------------------------------------- /test/test_case/update/case_1: -------------------------------------------------------------------------------- 1 | create table t (a int, b int); 2 | insert into t values(1,2); 3 | insert into t values(2,3); 4 | update t set a=3 where b=2; 5 | select * from t; 6 | update t set a='a'; 7 | update t set c=1; 8 | update t set a=1 where c=1; 9 | update b set a=1; 10 | update set a=1; 11 | select * from t; 12 | drop table t; 13 | -------------------------------------------------------------------------------- /test/test_load/aggr: -------------------------------------------------------------------------------- 1 | create table t_basic_2(id int, age int, name char, score float); 2 | insert into t_basic_2 values(1,1, 'a', 1.0); 3 | insert into t_basic_2 values(2,2, 'b', 2.0); 4 | insert into t_basic_2 values(4,4, 'c', 3.0); 5 | insert into t_basic_2 values(3,3, 'd', 4.0); 6 | insert into t_basic_2 values(5,5, 'e', 5.5); 7 | insert into t_basic_2 values(6,6, 'f', 6.6); 8 | insert into t_basic_2 values(7,7, 'g', 7.7); -------------------------------------------------------------------------------- /test/test_load/complex: -------------------------------------------------------------------------------- 1 | create table CSQ_1(ID int, COL1 int, FEAT1 float); 2 | create table CSQ_2(ID int, COL2 int, FEAT2 float); 3 | create table CSQ_3(ID int, COL3 int, FEAT3 float); 4 | insert into CSQ_1 values (0,2,1.0),(1,0,13.0), (1,4,11.2), (2,2,12.0), (3,3,13.5); 5 | insert into CSQ_2 values (0,2,14.0),(1,2,2.0); 6 | insert into CSQ_3 values (0,-2, 0.5),(1,2,2.0); -------------------------------------------------------------------------------- /test/test_load/date: -------------------------------------------------------------------------------- 1 | create table t1 (a int, b date); 2 | insert into t1 values(1,'2020-1-3'); 3 | insert into t1 values(2,'2020-01-3'); 4 | insert into t1 values(3,'2020-1-03'); 5 | insert into t1 values(4,'2020-01-03'); 6 | insert into t1 values(5,'2020-02-3'); 7 | insert into t1 values(6, '2010-3-5'); 8 | insert into t1 values(7, '2000-3-5'); 9 | insert into t1 values(8, '1990-12-5'); 10 | insert into t1 values(9, '1980-2-5'); 11 | insert into t1 values(10, '1970-12-31'); -------------------------------------------------------------------------------- /test/test_load/date2: -------------------------------------------------------------------------------- 1 | create table t_basic(id int, age int, name char, score float); 2 | insert into t_basic values(1,1, 'a', 1.0); 3 | insert into t_basic values(2,2, 'b', 2.0); 4 | insert into t_basic values(4,4, 'c', 3.0); 5 | insert into t_basic values(3,3, 'd', 4.0); 6 | insert into t_basic values(5,5, 'e', 5.5); 7 | insert into t_basic values(6,6, 'f', 6.6); 8 | insert into t_basic values(7,7, 'g', 7.7); 9 | select * from t_basic; 10 | select * from t_basic; 11 | select * from t_basic where id=1; 12 | select * from t_basic where id>=5; 13 | select * from t_basic where age>1 and age<3; 14 | select * from tbasic where tbasic.id=1 and t_basic.age=1; 15 | select * from t_basic where id=1 and age=1; 16 | select id, age, name, score from t_basic; 17 | select tbasic.id, tbasic.age, tbasic.name, tbasic.score from t_basic; 18 | select tbasic.id, tbasic.age, name from t_basic; 19 | create index iid on tbasic (id); 20 | select * from t_basic; 21 | drop table t_basic; -------------------------------------------------------------------------------- /test/test_load/expression: -------------------------------------------------------------------------------- 1 | create table t_expr1 (id int, name char, age int, col1 int); 2 | create table t_expr2 (id int, name char, age int, col2 int); 3 | insert into t_expr1 values(1,'hu',19, 1); 4 | insert into t_expr1 values(2,'hu',29, 2); 5 | insert into t_expr1 values(3,'hu',39, 3); 6 | insert into t_expr1 values(4,'hu',49, 4); 7 | insert into t_expr1 values(5,'hu',59, 5); 8 | insert into t_expr2 values(6,'hu',49, 6); 9 | insert into t_expr2 values(7,'hu',39, 7); 10 | insert into t_expr2 values(8,'hu',29, 8); 11 | insert into t_expr2 values(9,'hu',19, 9); 12 | insert into t_expr2 values(10,'hu',9, 9); -------------------------------------------------------------------------------- /test/test_load/expression2: -------------------------------------------------------------------------------- 1 | create table EXP_TABLE (ID int, COL1 int, COL2 int, COL3 float, COL4 int); 2 | insert into EXP_TABLE values(3,3,4,5.0,4); 3 | insert into EXP_TABLE values(2,2,-2,5.5,1); -------------------------------------------------------------------------------- /test/test_load/expression3: -------------------------------------------------------------------------------- 1 | create table EXP_TABLE (ID int, COL1 int, COL2 int, COL3 float, COL4 int); 2 | insert into EXP_TABLE values(2,2,-2,5.5,1),(3,3,4,5.0,4); -------------------------------------------------------------------------------- /test/test_load/group: -------------------------------------------------------------------------------- 1 | create table t_group_1(id int, name char, score float, age int); 2 | create table t_group_2(id int, name char, score float, age int); 3 | insert into t_group_1 values(1, 'hu', 90.0, 18); 4 | insert into t_group_1 values(2, 'liu', 80.0, 22); 5 | insert into t_group_1 values(3, 'li', 70.0, 18); 6 | insert into t_group_1 values(4, 'we', 100.0, 18); 7 | insert into t_group_1 values(5, 'li', 80.0, 22); 8 | insert into t_group_1 values(6, 'we', 70.0, 18); 9 | insert into t_group_1 values(7, 'aa', 60.0, 18); 10 | insert into t_group_2 values(1, 'hu', 90.0, 18); 11 | insert into t_group_2 values(2, 'liu', 80.0, 22); 12 | insert into t_group_2 values(3, 'li', 70.0, 18); 13 | insert into t_group_2 values(4, 'we', 100.0, 18); 14 | insert into t_group_2 values(5, 'li', 80.0, 22); 15 | insert into t_group_2 values(6, 'we', 70.0, 18); 16 | -------------------------------------------------------------------------------- /test/test_load/group2: -------------------------------------------------------------------------------- 1 | create table T_GROUP_BY (ID int, NAME char, SCORE int); 2 | create table T_GROUP_BY_2 (ID int, NAME char, AGE float); 3 | insert into T_GROUP_BY values(1, 'B', 2); 4 | insert into T_GROUP_BY values(1, 'B', 2); 5 | insert into T_GROUP_BY_2 values(1, 'B', 10.0); 6 | insert into T_GROUP_BY_2 values(1, 'B', 10.0); 7 | insert into T_GROUP_BY values(3, 'A', 1); 8 | insert into T_GROUP_BY values(3, 'C', 3); 9 | insert into T_GROUP_BY values(3, 'D', 3); 10 | insert into T_GROUP_BY values(3, 'F', 2); 11 | insert into T_GROUP_BY_2 values(3,'A', 23.33); 12 | insert into T_GROUP_BY_2 values(3,'C', 23.33); 13 | insert into T_GROUP_BY_2 values(3,'D', 23.33); 14 | insert into T_GROUP_BY values(4, 'C', 3); 15 | insert into T_GROUP_BY_2 values(4,'C', 20.0); -------------------------------------------------------------------------------- /test/test_load/index: -------------------------------------------------------------------------------- 1 | create table t3 (a int, b float, c char, d date); 2 | insert into t3 values(1,1.1,'a','2020-1-3'); 3 | insert into t3 values(2,1.2,'b','2019-2-28'); 4 | insert into t3 values(3,1.3,'c','2018-3-30'); 5 | insert into t3 values(4,1.4,'d','2017-4-29'); 6 | insert into t3 values(5,1.5,'e','2016-5-30'); 7 | insert into t3 values(6,1.6,'f','2015-6-29'); 8 | insert into t3 values(7,-1.1,'g','2014-7-28'); 9 | insert into t3 values(8,-2.2,'h','2013-8-29'); -------------------------------------------------------------------------------- /test/test_load/null: -------------------------------------------------------------------------------- 1 | create table NULL_TABLE(id int nullable, num int nullable, price int nullable, BIRTHDAY date nullable); 2 | desc NULL_TABLE; 3 | insert into NULL_TABLE values(1,18,10,'2020-01-01'),(2,null,20,'2010-01-11'),(4,15,30,'2021-01-31'); -------------------------------------------------------------------------------- /test/test_load/simple: -------------------------------------------------------------------------------- 1 | create table simple(a int); 2 | insert into simple values (1); 3 | insert into simple values (2); 4 | insert into simple values (3); -------------------------------------------------------------------------------- /test/test_load/sub-multi-query: -------------------------------------------------------------------------------- 1 | CREATE TABLE csq_1(id int, col1 int, feat1 float); 2 | CREATE TABLE csq_2(id int, col2 int, feat2 float); 3 | CREATE TABLE csq_3(id int, col3 int, feat3 float); 4 | CREATE TABLE csq_4(id int, col4 int, feat4 float); 5 | INSERT INTO csq_1 VALUES (1, 4, 11.2); 6 | INSERT INTO csq_1 VALUES (2, 2, 12.0); 7 | INSERT INTO csq_1 VALUES (3, 3, 13.5); 8 | INSERT INTO csq_2 VALUES (1, 2, 13.0); 9 | INSERT INTO csq_2 VALUES (2, 7, 10.5); 10 | INSERT INTO csq_2 VALUES (5, 3, 12.6); 11 | INSERT INTO csq_3 VALUES (1, 2, 11.0); 12 | INSERT INTO csq_3 VALUES (3, 6, 16.5); 13 | INSERT INTO csq_3 VALUES (5, 5, 14.6); 14 | -- SELECT * FROM csq_1 WHERE (SELECT MAX(csq_2.feat2) FROM csq_2) > feat1 AND col1 > (SELECT MIN(csq_3.col3) FROM csq_3); -------------------------------------------------------------------------------- /test/test_load/sub-query: -------------------------------------------------------------------------------- 1 | create table SSQ_1 (ID int, COL1 int, FEAT1 float); 2 | create table SSQ_2 (ID int, COL2 int, FEAT2 float); 3 | insert into SSQ_1 values(1, 4, 11.2); 4 | insert into SSQ_1 values(2, 2, 12.0); 5 | insert into SSQ_1 values(3, 3, 13.5); 6 | insert into SSQ_2 values(2, 2, 12.0); 7 | insert into SSQ_2 values(1, 2, 12.0); 8 | insert into SSQ_2 values(1, 2, 11.0); -------------------------------------------------------------------------------- /test/test_load/sub2: -------------------------------------------------------------------------------- 1 | create table CSQ_1(ID int, COL1 int , FEAT1 float); 2 | create table CSQ_2(ID int , COL2 int, FEAT2 float); 3 | create table CSQ_3(ID int , COL3 int, FEAT3 float); 4 | INSERT INTO CSQ_1 VALUES (1, 4, 11.2); 5 | INSERT INTO CSQ_1 VALUES (2, 2, 12.0); 6 | INSERT INTO CSQ_1 VALUES (3, 3, 13.5); 7 | INSERT INTO CSQ_2 VALUES (1, 2, 13.0); 8 | INSERT INTO CSQ_2 VALUES (2, 7, 10.5); 9 | INSERT INTO CSQ_2 VALUES (5, 3, 12.6); 10 | INSERT INTO CSQ_3 VALUES (1, 2, 11.0); 11 | INSERT INTO CSQ_3 VALUES (3, 6, 16.5); 12 | INSERT INTO CSQ_3 VALUES (5, 5, 14.6); -------------------------------------------------------------------------------- /test/test_load/table_date: -------------------------------------------------------------------------------- 1 | create table t1 (a int, b float, c char, d date); 2 | insert into t1 values(1,1.1,'a','2020-1-3'); 3 | insert into t1 values(2,1.2,'b','2019-2-28'); 4 | insert into t1 values(3,1.3,'c','2018-3-30'); 5 | insert into t1 values(4,1.4,'d','2017-4-29'); 6 | insert into t1 values(5,1.5,'e','2016-5-30'); 7 | insert into t1 values(6,1.6,'f','2015-6-29'); 8 | insert into t1 values(7,-1.1,'g','2014-7-28'); 9 | insert into t1 values(8,-2.2,'h','2013-8-29'); -------------------------------------------------------------------------------- /test/test_out/aggr/aggr_test_1: -------------------------------------------------------------------------------- 1 | create table t_basic_2(id int, age int, name char, score float); 2 | SUCCESS 3 | insert into t_basic_2 values(1,1, 'a', 1.0); 4 | SUCCESS 5 | insert into t_basic_2 values(2,2, 'b', 2.0); 6 | SUCCESS 7 | insert into t_basic_2 values(4,4, 'c', 3.0); 8 | SUCCESS 9 | insert into t_basic_2 values(3,3, 'd', 4.0); 10 | SUCCESS 11 | insert into t_basic_2 values(5,5, 'e', 5.5); 12 | SUCCESS 13 | insert into t_basic_2 values(6,6, 'f', 6.6); 14 | SUCCESS 15 | insert into t_basic_2 values(7,7, 'g', 7.7); 16 | SUCCESS 17 | select * from t_basic_2; 18 | id | age | name | score 19 | 1 | 1 | a | 1 20 | 2 | 2 | b | 2 21 | 4 | 4 | c | 3 22 | 3 | 3 | d | 4 23 | 5 | 5 | e | 5.5 24 | 6 | 6 | f | 6.6 25 | 7 | 7 | g | 7.7 26 | select avg(id),count(*),max(id),min(id) from t_basic_2; 27 | Connection has been closed 28 | -------------------------------------------------------------------------------- /test/test_out/aggr/aggr_test_2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/obcontest/miniob_final/5722f31f846ba608d7ff264e045ee8ee59daa520/test/test_out/aggr/aggr_test_2 -------------------------------------------------------------------------------- /test/test_out/aggr/aggr_test_3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/obcontest/miniob_final/5722f31f846ba608d7ff264e045ee8ee59daa520/test/test_out/aggr/aggr_test_3 -------------------------------------------------------------------------------- /test/test_out/complex/case1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/obcontest/miniob_final/5722f31f846ba608d7ff264e045ee8ee59daa520/test/test_out/complex/case1 -------------------------------------------------------------------------------- /test/test_out/complex/case2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/obcontest/miniob_final/5722f31f846ba608d7ff264e045ee8ee59daa520/test/test_out/complex/case2 -------------------------------------------------------------------------------- /test/test_out/complex/case3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/obcontest/miniob_final/5722f31f846ba608d7ff264e045ee8ee59daa520/test/test_out/complex/case3 -------------------------------------------------------------------------------- /test/test_out/date/compare_date_1: -------------------------------------------------------------------------------- 1 | create table t1 (a int, b date); 2 | Failed to parse sql: create table t1 (a int, b date);, error msg: Unknown error 3 | insert into t1 values(1,'2020-1-3'); 4 | FAILURE 5 | insert into t1 values(2,'2020-01-3'); 6 | FAILURE 7 | insert into t1 values(3,'2020-1-03'); 8 | FAILURE 9 | insert into t1 values(4,'2020-01-03'); 10 | FAILURE 11 | insert into t1 values(5,'2020-02-3'); 12 | FAILURE 13 | insert into t1 values(6, '2010-3-5'); 14 | FAILURE 15 | insert into t1 values(7, '2000-3-5'); 16 | FAILURE 17 | insert into t1 values(8, '1990-12-5'); 18 | FAILURE 19 | insert into t1 values(9, '1980-2-5'); 20 | FAILURE 21 | insert into t1 values(10, '1970-12-31'); 22 | FAILURE 23 | select * from t1; 24 | No data 25 | select * from t1 where b < '2020-3-4'; 26 | No data 27 | select b from t1 where b < '2020-3-4'; 28 | No data 29 | select * from t1 where b <= '2008-2-29'; 30 | No data 31 | select * from t1 where b > '2008-2-29'; 32 | No data 33 | select * from t1 where b >= '2008-2-29'; 34 | No data 35 | select * from t1 where b = '2008-2-29'; 36 | No data 37 | select * from t1 where b = '2000-3-5'; 38 | No data 39 | select b from t1 where b < '2021-2-29'; 40 | No data 41 | select b from t1 where b >= '2020-12-32'; 42 | No data 43 | delete from t1 where b = '1970-12-31'; 44 | FAILURE 45 | select * from t1; 46 | No data 47 | select * from t1; 48 | No data 49 | select * from t1; 50 | No data 51 | drop table t1; 52 | Unsupported sql: 6 53 | -------------------------------------------------------------------------------- /test/test_out/date/compare_date_2: -------------------------------------------------------------------------------- 1 | create table t3 (a int, b date); 2 | Failed to parse sql: create table t3 (a int, b date);, error msg: Unknown error 3 | insert into t3 values(1,'2020-1-3'); 4 | FAILURE 5 | insert into t3 values(2,'2020-01-3'); 6 | FAILURE 7 | insert into t3 values(3,'2020-1-03'); 8 | FAILURE 9 | insert into t3 values(4,'2020-01-03'); 10 | FAILURE 11 | insert into t3 values(5,'2020-02-3'); 12 | FAILURE 13 | insert into t3 values(6, '2010-3-5'); 14 | FAILURE 15 | insert into t3 values(7, '2000-3-5'); 16 | FAILURE 17 | insert into t3 values(8, '1990-12-5'); 18 | FAILURE 19 | insert into t3 values(9, '1980-2-5'); 20 | FAILURE 21 | insert into t3 values(10, '1970-12-31'); 22 | FAILURE 23 | select * from t3; 24 | No data 25 | select * from t3 where b < '2020-3-4'; 26 | No data 27 | select b from t3 where b < '2020-3-4'; 28 | No data 29 | select * from t3 where b <= '2008-2-29'; 30 | No data 31 | select * from t3 where b > '2008-2-29'; 32 | No data 33 | select * from t3 where b >= '2008-2-29'; 34 | No data 35 | select * from t3 where b = '2008-2-29'; 36 | No data 37 | select * from t3 where b = '2000-3-5'; 38 | No data 39 | select b from t3 where b < '2021-2-29'; 40 | No data 41 | select b from t3 where b >= '2020-12-32'; 42 | No data 43 | select * from t3 where '2010-1-1' >= b; 44 | No data 45 | select * from t3 where '2000-3-5' >= b; 46 | No data 47 | select * from t3 where '2000-3-5' > b; 48 | No data 49 | select * from t3 where '2000-3-5' < b; 50 | No data 51 | select * from t3 where '2000-3-5' <= b; 52 | No data 53 | select * from t3 where '2021-2-29' < b; 54 | No data 55 | select * from t3 where '2010-2-28' < b; 56 | No data 57 | drop table t3; 58 | Unsupported sql: 6 59 | -------------------------------------------------------------------------------- /test/test_out/date/compare_date_5: -------------------------------------------------------------------------------- 1 | Select * from t1 where d > '2039-2-10'; 2 | No data 3 | Select * from t1 where d > '2040-5-3'; 4 | No data 5 | Select * from t1 where d <= '1969-12-31'; 6 | No data 7 | Select * from t1 where d < '1950-1-31'; 8 | No data 9 | Select * from t1 where d <> '2010-13-21'; 10 | No data 11 | Select * from t1 where d = '2010-15-2'; 12 | No data 13 | Select * from t1 where d <> '2010-0-21'; 14 | No data 15 | Select * from t1 where d = '2010-0-2'; 16 | No data 17 | Select * from t1 where d < '2021-1-32'; 18 | No data 19 | Select * from t1 where d > '2021-2-29'; 20 | No data 21 | Select * from t1 where d = '2021-3-32'; 22 | No data 23 | Select * from t1 where d <= '2021-4-31'; 24 | No data 25 | Select * from t1 where d <= '2021-5-32'; 26 | No data 27 | Select * from t1 where d >= '2021-6-31'; 28 | No data 29 | Select * from t1 where d < '2021-7-32'; 30 | No data 31 | Select * from t1 where d <> '2021-8-32'; 32 | No data 33 | Select * from t1 where d < '2021-9-31'; 34 | No data 35 | Select * from t1 where d <> '2021-10-32'; 36 | No data 37 | Select * from t1 where d <> '2021-11-31'; 38 | No data 39 | Select * from t1 where d = '2021-12-32'; 40 | No data 41 | Select * from t1 where d = '2021-1-0'; 42 | No data 43 | Select * from t1 where d = '2021-0-0'; 44 | No data 45 | -------------------------------------------------------------------------------- /test/test_out/date/compare_date_index_2: -------------------------------------------------------------------------------- 1 | create table t4 (a int, b float, c char, d date); 2 | Failed to parse sql: create table t4 (a int, b float, c char, d date);, error msg: Unknown error 3 | create index a_id on t4 (a); 4 | FAILURE 5 | insert into t4 values(8,-2.2,'h','2013-8-29'); 6 | FAILURE 7 | insert into t4 values(2,-1.1,'g','2014-7-28'); 8 | FAILURE 9 | insert into t4 values(6,1.6,'f','2015-6-29'); 10 | FAILURE 11 | insert into t4 values(5,1.5,'e','2016-5-30'); 12 | FAILURE 13 | select * from t4 where a <> 6; 14 | No data 15 | drop table t4; 16 | Unsupported sql: 6 17 | -------------------------------------------------------------------------------- /test/test_out/date/delete_date_1: -------------------------------------------------------------------------------- 1 | create table t1 (a int, b date, c chars); 2 | Failed to parse sql: create table t1 (a int, b date, c chars);, error msg: Unknown error 3 | delete from t1 where b='2020-02-30'; 4 | FAILURE 5 | -------------------------------------------------------------------------------- /test/test_out/drop_table/drop_table_1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/obcontest/miniob_final/5722f31f846ba608d7ff264e045ee8ee59daa520/test/test_out/drop_table/drop_table_1 -------------------------------------------------------------------------------- /test/test_out/drop_table/drop_table_2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/obcontest/miniob_final/5722f31f846ba608d7ff264e045ee8ee59daa520/test/test_out/drop_table/drop_table_2 -------------------------------------------------------------------------------- /test/test_out/drop_table/drop_table_3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/obcontest/miniob_final/5722f31f846ba608d7ff264e045ee8ee59daa520/test/test_out/drop_table/drop_table_3 -------------------------------------------------------------------------------- /test/test_out/drop_table/drop_table_4: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/obcontest/miniob_final/5722f31f846ba608d7ff264e045ee8ee59daa520/test/test_out/drop_table/drop_table_4 -------------------------------------------------------------------------------- /test/test_out/expression/case1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/obcontest/miniob_final/5722f31f846ba608d7ff264e045ee8ee59daa520/test/test_out/expression/case1 -------------------------------------------------------------------------------- /test/test_out/expression/case2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/obcontest/miniob_final/5722f31f846ba608d7ff264e045ee8ee59daa520/test/test_out/expression/case2 -------------------------------------------------------------------------------- /test/test_out/expression/case3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/obcontest/miniob_final/5722f31f846ba608d7ff264e045ee8ee59daa520/test/test_out/expression/case3 -------------------------------------------------------------------------------- /test/test_out/group/group_case_1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/obcontest/miniob_final/5722f31f846ba608d7ff264e045ee8ee59daa520/test/test_out/group/group_case_1 -------------------------------------------------------------------------------- /test/test_out/group/group_case_2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/obcontest/miniob_final/5722f31f846ba608d7ff264e045ee8ee59daa520/test/test_out/group/group_case_2 -------------------------------------------------------------------------------- /test/test_out/group/group_case_3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/obcontest/miniob_final/5722f31f846ba608d7ff264e045ee8ee59daa520/test/test_out/group/group_case_3 -------------------------------------------------------------------------------- /test/test_out/group/group_case_4: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/obcontest/miniob_final/5722f31f846ba608d7ff264e045ee8ee59daa520/test/test_out/group/group_case_4 -------------------------------------------------------------------------------- /test/test_out/inner_join/case_1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/obcontest/miniob_final/5722f31f846ba608d7ff264e045ee8ee59daa520/test/test_out/inner_join/case_1 -------------------------------------------------------------------------------- /test/test_out/inner_join/case_2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/obcontest/miniob_final/5722f31f846ba608d7ff264e045ee8ee59daa520/test/test_out/inner_join/case_2 -------------------------------------------------------------------------------- /test/test_out/inner_join/case_3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/obcontest/miniob_final/5722f31f846ba608d7ff264e045ee8ee59daa520/test/test_out/inner_join/case_3 -------------------------------------------------------------------------------- /test/test_out/inner_join/case_4: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/obcontest/miniob_final/5722f31f846ba608d7ff264e045ee8ee59daa520/test/test_out/inner_join/case_4 -------------------------------------------------------------------------------- /test/test_out/insert/case_1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/obcontest/miniob_final/5722f31f846ba608d7ff264e045ee8ee59daa520/test/test_out/insert/case_1 -------------------------------------------------------------------------------- /test/test_out/insert/case_2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/obcontest/miniob_final/5722f31f846ba608d7ff264e045ee8ee59daa520/test/test_out/insert/case_2 -------------------------------------------------------------------------------- /test/test_out/insert/case_3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/obcontest/miniob_final/5722f31f846ba608d7ff264e045ee8ee59daa520/test/test_out/insert/case_3 -------------------------------------------------------------------------------- /test/test_out/metadata_verification/case_1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/obcontest/miniob_final/5722f31f846ba608d7ff264e045ee8ee59daa520/test/test_out/metadata_verification/case_1 -------------------------------------------------------------------------------- /test/test_out/metadata_verification/case_2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/obcontest/miniob_final/5722f31f846ba608d7ff264e045ee8ee59daa520/test/test_out/metadata_verification/case_2 -------------------------------------------------------------------------------- /test/test_out/multi_index/case_1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/obcontest/miniob_final/5722f31f846ba608d7ff264e045ee8ee59daa520/test/test_out/multi_index/case_1 -------------------------------------------------------------------------------- /test/test_out/multi_index/case_2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/obcontest/miniob_final/5722f31f846ba608d7ff264e045ee8ee59daa520/test/test_out/multi_index/case_2 -------------------------------------------------------------------------------- /test/test_out/multi_index/case_3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/obcontest/miniob_final/5722f31f846ba608d7ff264e045ee8ee59daa520/test/test_out/multi_index/case_3 -------------------------------------------------------------------------------- /test/test_out/multi_index/case_4: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/obcontest/miniob_final/5722f31f846ba608d7ff264e045ee8ee59daa520/test/test_out/multi_index/case_4 -------------------------------------------------------------------------------- /test/test_out/multi_table/case_1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/obcontest/miniob_final/5722f31f846ba608d7ff264e045ee8ee59daa520/test/test_out/multi_table/case_1 -------------------------------------------------------------------------------- /test/test_out/multi_table/case_2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/obcontest/miniob_final/5722f31f846ba608d7ff264e045ee8ee59daa520/test/test_out/multi_table/case_2 -------------------------------------------------------------------------------- /test/test_out/multi_table/case_3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/obcontest/miniob_final/5722f31f846ba608d7ff264e045ee8ee59daa520/test/test_out/multi_table/case_3 -------------------------------------------------------------------------------- /test/test_out/null/case_1: -------------------------------------------------------------------------------- 1 | create table t (a int nullable, b float not null); 2 | Failed to parse sql: create table t (a int nullable, b float not null);, error msg: Unknown error 3 | insert into t values(1,1.0),(null,2.0); 4 | Failed to parse sql: insert into t values(1,1.0),(null,2.0);, error msg: Unknown error 5 | insert into t values(1,null); 6 | Failed to parse sql: insert into t values(1,null);, error msg: Unknown error 7 | select * from t; 8 | No data 9 | drop table t; 10 | Unsupported sql: 6 11 | -------------------------------------------------------------------------------- /test/test_out/null/case_2: -------------------------------------------------------------------------------- 1 | create table t (a int nullable, b float nullable,c char nullable, d date nullable); 2 | Failed to parse sql: create table t (a int nullable, b float nullable,c char nullable, d date nullable);, error msg: Unknown error 3 | insert into t values(0,1.0,null,null),(null,null,'b','2020-1-1'),(2,2.0,'c',null); 4 | Failed to parse sql: insert into t values(0,1.0,null,null),(null,null,'b','2020-1-1'),(2,2.0,'c',null);, error msg: Unknown error 5 | select * from t where null is null; 6 | Connection has been closed 7 | -------------------------------------------------------------------------------- /test/test_out/null/case_3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/obcontest/miniob_final/5722f31f846ba608d7ff264e045ee8ee59daa520/test/test_out/null/case_3 -------------------------------------------------------------------------------- /test/test_out/null/case_4: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/obcontest/miniob_final/5722f31f846ba608d7ff264e045ee8ee59daa520/test/test_out/null/case_4 -------------------------------------------------------------------------------- /test/test_out/null/case_5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/obcontest/miniob_final/5722f31f846ba608d7ff264e045ee8ee59daa520/test/test_out/null/case_5 -------------------------------------------------------------------------------- /test/test_out/order/case_1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/obcontest/miniob_final/5722f31f846ba608d7ff264e045ee8ee59daa520/test/test_out/order/case_1 -------------------------------------------------------------------------------- /test/test_out/order/case_2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/obcontest/miniob_final/5722f31f846ba608d7ff264e045ee8ee59daa520/test/test_out/order/case_2 -------------------------------------------------------------------------------- /test/test_out/order/case_3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/obcontest/miniob_final/5722f31f846ba608d7ff264e045ee8ee59daa520/test/test_out/order/case_3 -------------------------------------------------------------------------------- /test/test_out/order/case_4: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/obcontest/miniob_final/5722f31f846ba608d7ff264e045ee8ee59daa520/test/test_out/order/case_4 -------------------------------------------------------------------------------- /test/test_out/sub-query/case1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/obcontest/miniob_final/5722f31f846ba608d7ff264e045ee8ee59daa520/test/test_out/sub-query/case1 -------------------------------------------------------------------------------- /test/test_out/sub-query/case2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/obcontest/miniob_final/5722f31f846ba608d7ff264e045ee8ee59daa520/test/test_out/sub-query/case2 -------------------------------------------------------------------------------- /test/test_out/unique_index/case_1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/obcontest/miniob_final/5722f31f846ba608d7ff264e045ee8ee59daa520/test/test_out/unique_index/case_1 -------------------------------------------------------------------------------- /test/test_out/unique_index/case_2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/obcontest/miniob_final/5722f31f846ba608d7ff264e045ee8ee59daa520/test/test_out/unique_index/case_2 -------------------------------------------------------------------------------- /test/test_out/unique_index/case_3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/obcontest/miniob_final/5722f31f846ba608d7ff264e045ee8ee59daa520/test/test_out/unique_index/case_3 -------------------------------------------------------------------------------- /test/test_out/update/case_1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/obcontest/miniob_final/5722f31f846ba608d7ff264e045ee8ee59daa520/test/test_out/update/case_1 -------------------------------------------------------------------------------- /unitest/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | PROJECT(unitest) 2 | MESSAGE("Begin to build " ${PROJECT_NAME}) 3 | MESSAGE(STATUS "This is PROJECT_BINARY_DIR dir " ${PROJECT_BINARY_DIR}) 4 | MESSAGE(STATUS "This is PROJECT_SOURCE_DIR dir " ${PROJECT_SOURCE_DIR}) 5 | 6 | 7 | # 可以获取父cmake的变量 8 | MESSAGE("${CMAKE_COMMON_FLAGS}") 9 | 10 | 11 | #INCLUDE_DIRECTORIES([AFTER|BEFORE] [SYSTEM] dir1 dir2 ...) 12 | INCLUDE_DIRECTORIES(. ${PROJECT_SOURCE_DIR}/../deps ${PROJECT_SOURCE_DIR}/../src/observer /usr/local/include SYSTEM) 13 | # 父cmake 设置的include_directories 和link_directories并不传导到子cmake里面 14 | #INCLUDE_DIRECTORIES(BEFORE ${CMAKE_INSTALL_PREFIX}/include) 15 | LINK_DIRECTORIES(/usr/local/lib /usr/local/lib64 ${PROJECT_BINARY_DIR}/../lib) 16 | 17 | 18 | IF (DEFINED ENV{LD_LIBRARY_PATH}) 19 | SET(LD_LIBRARY_PATH_STR $ENV{LD_LIBRARY_PATH}) 20 | #separate_arguments(LD_LIBRARY_PATH_STR) #只能处理空行 21 | string(REPLACE ":" ";" LD_LIBRARY_PATH_LIST ${LD_LIBRARY_PATH_STR}) 22 | MESSAGE(" Add LD_LIBRARY_PATH to -L flags " ${LD_LIBRARY_PATH_LIST}) 23 | LINK_DIRECTORIES(${LD_LIBRARY_PATH_LIST}) 24 | ELSE () 25 | LINK_DIRECTORIES(/usr/local/lib) 26 | ENDIF () 27 | 28 | 29 | find_package(GTest CONFIG REQUIRED) 30 | 31 | 32 | enable_testing() 33 | include(GoogleTest) 34 | #get_filename_component( FileName 35 | # PATH|ABSOLUTE|NAME|EXT|NAME_WE|REALPATH 36 | # [CACHE]) 37 | FILE(GLOB_RECURSE ALL_SRC *.cpp) 38 | # AUX_SOURCE_DIRECTORY 类似功能 39 | FOREACH (F ${ALL_SRC}) 40 | get_filename_component(prjName ${F} NAME_WE) 41 | MESSAGE("Build ${prjName} according to ${F}") 42 | ADD_EXECUTABLE(${prjName} ${F}) 43 | # 不是所有的单测都需要链接observer_static 44 | TARGET_LINK_LIBRARIES(${prjName} common pthread dl gtest gtest_main observer_static) 45 | gtest_discover_tests(${prjName}) 46 | ENDFOREACH (F) 47 | 48 | -------------------------------------------------------------------------------- /unitest/log_test.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2021 Xie Meiyi(xiemeiyi@hust.edu.cn) and OceanBase and/or its affiliates. All rights reserved. 2 | miniob is licensed under Mulan PSL v2. 3 | You can use this software according to the terms and conditions of the Mulan PSL v2. 4 | You may obtain a copy of Mulan PSL v2 at: 5 | http://license.coscl.org.cn/MulanPSL2 6 | THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, 7 | EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, 8 | MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. 9 | See the Mulan PSL v2 for more details. */ 10 | 11 | // 12 | // Created by Longda on 2021 13 | // 14 | 15 | #ifndef CTESTLOG_H_ 16 | #define CTESTLOG_H_ 17 | 18 | #include 19 | 20 | /* 21 | * 22 | */ 23 | class LogTest { 24 | public: 25 | LogTest(); 26 | virtual ~LogTest(); 27 | 28 | int init(const std::string &logFile = "test.log"); 29 | 30 | void *log_loop(void *param); 31 | }; 32 | 33 | #endif /* CTESTLOG_H_ */ 34 | -------------------------------------------------------------------------------- /unitest/md5_test.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2021 Xie Meiyi(xiemeiyi@hust.edu.cn) and OceanBase and/or its affiliates. All rights reserved. 2 | miniob is licensed under Mulan PSL v2. 3 | You can use this software according to the terms and conditions of the Mulan PSL v2. 4 | You may obtain a copy of Mulan PSL v2 at: 5 | http://license.coscl.org.cn/MulanPSL2 6 | THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, 7 | EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, 8 | MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. 9 | See the Mulan PSL v2 for more details. */ 10 | 11 | // 12 | // Created by Longda on 2021 13 | // 14 | 15 | #include 16 | 17 | #include "common/math/md5.h" 18 | #include "md5_test.h" 19 | 20 | using namespace common; 21 | 22 | Md5Test::Md5Test() 23 | { 24 | // Auto-generated constructor stub 25 | } 26 | 27 | Md5Test::~Md5Test() 28 | { 29 | // Auto-generated destructor stub 30 | } 31 | 32 | void Md5Test::string() 33 | { 34 | char buf[512] = "/home/fastdfs/longda"; 35 | unsigned char digest[16] = {0}; 36 | MD5String(buf, digest); 37 | for (int i = 0; i < 16; i++) { 38 | printf("%d: %02x %d\n", i, digest[i], digest[i]); 39 | } 40 | } 41 | 42 | int main(int argc, char **argv) 43 | { 44 | Md5Test test; 45 | test.string(); 46 | 47 | return 0; 48 | } 49 | -------------------------------------------------------------------------------- /unitest/md5_test.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2021 Xie Meiyi(xiemeiyi@hust.edu.cn) and OceanBase and/or its affiliates. All rights reserved. 2 | miniob is licensed under Mulan PSL v2. 3 | You can use this software according to the terms and conditions of the Mulan PSL v2. 4 | You may obtain a copy of Mulan PSL v2 at: 5 | http://license.coscl.org.cn/MulanPSL2 6 | THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, 7 | EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, 8 | MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. 9 | See the Mulan PSL v2 for more details. */ 10 | 11 | // 12 | // Created by Longda on 2021 13 | // 14 | 15 | #ifndef CTESTMD5_H_ 16 | #define CTESTMD5_H_ 17 | 18 | /* 19 | * 20 | */ 21 | class Md5Test { 22 | public: 23 | Md5Test(); 24 | virtual ~Md5Test(); 25 | 26 | void string(); 27 | }; 28 | 29 | #endif /* CTESTMD5_H_ */ 30 | -------------------------------------------------------------------------------- /unitest/path_test.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2021 Xie Meiyi(xiemeiyi@hust.edu.cn) and OceanBase and/or its affiliates. All rights reserved. 2 | miniob is licensed under Mulan PSL v2. 3 | You can use this software according to the terms and conditions of the Mulan PSL v2. 4 | You may obtain a copy of Mulan PSL v2 at: 5 | http://license.coscl.org.cn/MulanPSL2 6 | THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, 7 | EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, 8 | MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. 9 | See the Mulan PSL v2 for more details. */ 10 | 11 | // 12 | // Created by Longda on 2021 13 | // 14 | 15 | int main(int argc, char **argv) 16 | { 17 | return 0; 18 | } -------------------------------------------------------------------------------- /unitest/pidfile_test.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2021 Xie Meiyi(xiemeiyi@hust.edu.cn) and OceanBase and/or its affiliates. All rights reserved. 2 | miniob is licensed under Mulan PSL v2. 3 | You can use this software according to the terms and conditions of the Mulan PSL v2. 4 | You may obtain a copy of Mulan PSL v2 at: 5 | http://license.coscl.org.cn/MulanPSL2 6 | THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, 7 | EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, 8 | MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. 9 | See the Mulan PSL v2 for more details. */ 10 | 11 | // 12 | // Created by Longda on 2021/4/16. 13 | // 14 | #include 15 | 16 | #include "gtest/gtest.h" 17 | 18 | #include "common/os/pidfile.h" 19 | #include "common/io/io.h" 20 | #include "common/lang/string.h" 21 | 22 | using namespace common; 23 | 24 | int main() 25 | { 26 | long long pid = (long long)getpid(); 27 | 28 | const char *programName = "test"; 29 | writePidFile(programName); 30 | 31 | std::string pidFile = getPidPath(); 32 | 33 | char buf[1024] = {0}; 34 | char *p = buf; 35 | size_t size = 0; 36 | readFromFile(pidFile, p, size); 37 | 38 | std::string temp(p); 39 | long long target = 0; 40 | str_to_val(temp, target); 41 | 42 | EXPECT_EQ(pid, target); 43 | } -------------------------------------------------------------------------------- /unitest/rc_test.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2021 Xie Meiyi(xiemeiyi@hust.edu.cn) and OceanBase and/or its affiliates. All rights reserved. 2 | miniob is licensed under Mulan PSL v2. 3 | You can use this software according to the terms and conditions of the Mulan PSL v2. 4 | You may obtain a copy of Mulan PSL v2 at: 5 | http://license.coscl.org.cn/MulanPSL2 6 | THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, 7 | EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, 8 | MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. 9 | See the Mulan PSL v2 for more details. */ 10 | 11 | // 12 | // Created by Longda on 2021/5/3. 13 | // 14 | #include "rc.h" 15 | #include 16 | 17 | int main(int argc, char **argv) 18 | { 19 | 20 | std::cout << rc2SimpleStr(status) << std::endl; 21 | } -------------------------------------------------------------------------------- /unitest/thread_test.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2021 Xie Meiyi(xiemeiyi@hust.edu.cn) and OceanBase and/or its affiliates. All rights reserved. 2 | miniob is licensed under Mulan PSL v2. 3 | You can use this software according to the terms and conditions of the Mulan PSL v2. 4 | You may obtain a copy of Mulan PSL v2 at: 5 | http://license.coscl.org.cn/MulanPSL2 6 | THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, 7 | EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, 8 | MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. 9 | See the Mulan PSL v2 for more details. */ 10 | 11 | // 12 | // Created by Longda on 2021 13 | // 14 | 15 | #ifndef CTESTTHREAD_H_ 16 | #define CTESTTHREAD_H_ 17 | 18 | #include "common/lang/mutex.h" 19 | 20 | /* 21 | * 22 | */ 23 | class ThreadTest { 24 | public: 25 | ThreadTest(); 26 | virtual ~ThreadTest(); 27 | 28 | int create(); 29 | 30 | int startTestCond(); 31 | int startTestDeadLock(); 32 | 33 | static void *testCond(void *param); 34 | static void *testDeadLock(void *param); 35 | 36 | private: 37 | int param[10]; 38 | 39 | pthread_mutex_t mutex; 40 | pthread_cond_t cond; 41 | 42 | pthread_mutex_t dead_mutex1; 43 | pthread_mutex_t dead_mutex2; 44 | }; 45 | 46 | #endif /* CTESTTHREAD_H_ */ 47 | --------------------------------------------------------------------------------