CMU-Peleton——SQL功能模块笔记

Overview

Implement Details

Step #1 - Implement the String Functions

  • All of Peloton’s built-in SQL string functions are in the peloton::function::StringFunctions utility class.

  • Each of these static functions will take in an ExecutorContext object as its first argument. This object stores information about the query being executed and provides a memory pool for allocating memory if it is needed.

  • The functions will then have additional input arguments and different return types:

    For UPPER and LOWER, the input arguments are (1) a const char* for the string to be modified and (2) a const uint32_t for the string length. The return type should be a char*. You should check for NULL in the operator implementation, not the function.

    For CONCAT, the input arguments are (1) an array of strings to concatenate together (const char **concat_strs), (2) an array of the lengths of those strings (const uint32_t*), and (3) the number of strings in the array (const uint32_t). The return type must be a StringFunctions::StrWithLen struct, since the code that called your method does not know how long the string will be that you return.

    HINT: Use the PL_MEMCPY macro to copy memory between arrays as needed. You should not invoke memcpy or memset directly.

Step #2 - Register the Function in the Catalog

  • Modify Catalog::InitializeFunctions() to register the three new built-in SQL functions that you are adding. You will need to also add the new entries to the OperatorId enum.

Step #3 - Add the Function Proxy to the LLVM Engine

  • For UPPER and LOWER, you will need to create separate UnaryOperatorHandleNull structs in codegen/type/varchar_type.cpp. You will need to implement three methods:

    • SupportsType(): Returns true if the given input type is a VARCHAR.
    • ResultType(): Returns the VARCHAR type.
    • Impl(): Uses the StringFunctionsProxy object to invoke the real function in StringFunctions. You do not need to worry about NULL inputs. The UnaryOperatorHandleNull base class will handle that for you. The return type should be a codegen::Value object.
  • For CONCAT, we are already providing you with the BinaryOperator struct implementation in codegen/type/varchar_type.cpp. This is because the operator implementation for this function is more complicated that the previous two (e.g., you have to allocate memory on the stack). You will need to uncomment the code once you complete steps #1 and #2 above.

  • Make sure you also add the three new functions to the function look-up tables in codegen/type/varchar_type.cpp. Add new entries for UPPER and ==LOWER ==to kUnaryOperatorTable. Add a new entry for CONCAT to kBinaryOperatorTable.

  • You then need to connect your operator handlers to the catalog. You add entries for the three functions in both codegen/proxy/string_functions_proxy.cpp and include/codegen/proxy/string_functions_proxy.h. Use the DEFINE_METHOD macro like the other entries in these two files. It will take care everything for you.

Instructions

Building Peloton

- build Peloton by following [these installation instructions](https://github.com/cmu-db/peloton/wiki/Installation#build-peloton).

Testing

  1. Peloton Testing Framework : You can test the string functions by making use of the string functions test case. We will use a more comprehensive testing script to grade your assignment.
cd build
make string_functions_test
  1. PSQL Command-line Interface: We are also providing a SQL script for testing your implementation and also getting used to the Peloton’s command line interface. Follow these instructions to launch Peloton’s psql terminal, and then load in this SQL script to run it. You can cross check your output with the expected output.

Development Hints

  1. Here’s a short list of rules that you should follow while hacking on Peloton. For instance, use class UpperCaseCamelCase for type names/methods/functions, int lower_case_with_underscores for variable names. Always use descriptive names and comment generously.

    We use ClangFormat to ensure that everyone follows the same code formatting style. Before submitting your assignment, ensure that you follow these guidelines by running this command:

clang-format-3.6 --style=file ./src/function/string_functions.cpp | diff ./src/function/string_functions.cpp -

ClangFormat supports two ways to provide custom style options: directly specify the style configuration in the –style= command line option or use –style=file and put the style configuration file in the .clang-format file in the project directory. We follow the second approach. The style file is located here in the Peloton repository. To modify the source code file to adhere to the style file, you can use the following command as describe in the manpage:

clang-format-3.6 --style=file -i ./src/function/string_functions.cpp
  1. Instead of using printf statements for debugging, use the ==LOG_* == macros for logging information like this:
LOG_INFO("Nested loop join executor -- %d children", num_children);
LOG_DEBUG("Advance the right buffer iterator.");

To enable logging in peloton, you will need to reconfigure it like this :

cd build
cmake -DCMAKE_BUILD_TYPE=DEBUG ..
make

More information is available here. The different logging levels are defined in this [header file]. After enabling logging, the logging level defaults to LOG_LEVEL_INFO. So, any logging method with a logging level that equal to or higher than LOG_LEVEL_INFO, like LOG_INFO, LOG_WARN, and LOG_ERROR will emit logging information in the peloton debugging log file. The debugging log file is written to stdout.

Note: Our source validator pre-commit hook will throw an error if you try to push code that includes forbidden commands (e.g., printf, cout, cerr). See these instructions on how to set it up.

  1. To speed up compilation, you can use the -j command-line flag for make to tell it how many threads. For example, if you want to use four cores to build the system, you would execute make -j 4.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值