Skip to content
This repository has been archived by the owner on Feb 20, 2023. It is now read-only.

User-Defined Functions #1510

Open
wants to merge 155 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
155 commits
Select commit Hold shift + click to select a range
4fc8f26
open PR
turingcompl33t Mar 9, 2021
62940a0
Merge branch 'master' into feature-udfs
turingcompl33t Mar 12, 2021
8e50e24
Merge branch 'master' into feature-udfs
turingcompl33t Apr 1, 2021
ee57184
catalog port
turingcompl33t Apr 2, 2021
ddad51a
port tpl tests
turingcompl33t Apr 2, 2021
f8383ee
port network layer
turingcompl33t Apr 2, 2021
9ae19b2
port traffic cop, but dependencies on executors and refactor of execu…
turingcompl33t Apr 2, 2021
f18d617
port parser code, and run formatter
turingcompl33t Apr 2, 2021
731f2b9
pull in udf specific files in parser, ast, and code generation
turingcompl33t Apr 3, 2021
ff6be66
reorder
turingcompl33t Apr 3, 2021
75839c5
pull in ast for udfs, messy and unimplemented in some places because …
turingcompl33t Apr 3, 2021
421d873
integrate binder, builds successfully
turingcompl33t Apr 4, 2021
b8d458c
integrate execution exec
turingcompl33t Apr 4, 2021
c5fc040
integrate sema
turingcompl33t Apr 4, 2021
6b1ae59
integrate udf lambda parsing
turingcompl33t Apr 4, 2021
7fc02a7
pull in compiler additions, some places to revisit here
turingcompl33t Apr 4, 2021
98259fd
integrate vm and ddl executors
turingcompl33t Apr 4, 2021
ea585b6
fixed bug in udf codegen, but now libpg_query wont link...
turingcompl33t Apr 4, 2021
2059633
Merge branch 'master' into feature-udfs
turingcompl33t Apr 9, 2021
44e5f54
merge
turingcompl33t Apr 20, 2021
7c5f413
merge updates
Apr 20, 2021
f5f8cf7
able to push from dev10
turingcompl33t Apr 20, 2021
aa56dbd
fix linker error with libpg_query
turingcompl33t Apr 20, 2021
86427c6
remove old comments in libpg_query
turingcompl33t Apr 20, 2021
48112ce
remove old TODO in db_server.py
turingcompl33t Apr 23, 2021
1e211e4
cleanup in pipeline, remove dead code, add documentation
turingcompl33t Apr 23, 2021
d4278aa
implement CreateFunctionExecutor in traffic_cop
turingcompl33t Apr 23, 2021
3b29f88
starting to work on cleaning up udf_parser
turingcompl33t Apr 23, 2021
e7dd0d0
documentation for FunctionContext
turingcompl33t Apr 23, 2021
eb898d8
address some TODO in udf parser and AST context
turingcompl33t Apr 23, 2021
6ece761
wip on bytecode generation
turingcompl33t Apr 23, 2021
684ffbc
fix up loop builder in bytecode generation
turingcompl33t Apr 23, 2021
c63256d
misc fixes and cleanup, looking primarily at semantic analysis
turingcompl33t Apr 23, 2021
59e5d8a
address some issues in binder and sema
turingcompl33t Apr 23, 2021
b540f43
updates to udf codegen and executable query
turingcompl33t Apr 23, 2021
307393e
last big visitor in udf codegen
turingcompl33t Apr 23, 2021
9d67d8b
slowly working down the list
turingcompl33t Apr 24, 2021
5ea15c7
wip, editor crashed
turingcompl33t Apr 24, 2021
f997bb5
all major todos addressed, now time to start running tests
turingcompl33t Apr 24, 2021
5d19a1c
Merge branch 'master' into feature-udfs
turingcompl33t Apr 24, 2021
9d054c5
merge, still need to fix build
turingcompl33t May 14, 2021
eee35bb
fix build after merge
turingcompl33t May 24, 2021
02a9e48
merge master
turingcompl33t Jun 15, 2021
bb64f35
various updates to ast, ast tests, and translation from constant valu…
turingcompl33t Jun 17, 2021
e698b23
Merge branch 'master' into feature-udfs
turingcompl33t Jun 17, 2021
decb9d1
fixed error causing binder tests to fail, starting in on linting errors
turingcompl33t Jun 18, 2021
bc4a1e5
progress on linter errors, big refactor in udf parser
turingcompl33t Jun 18, 2021
cb909ff
lint passing
turingcompl33t Jun 18, 2021
6c20c68
now fighting clang-tidy, almost there but going to need a big refacto…
turingcompl33t Jun 18, 2021
3189deb
big refactor of UDF AST in progress
turingcompl33t Jun 18, 2021
9bad8e6
still a work in progress on refactoring UDF code generation and UDF ast
turingcompl33t Jun 18, 2021
8171dfb
linting and clang-tidy passing, I am sure we will still fail doxygen …
turingcompl33t Jun 18, 2021
230964b
Merge branch 'master' into feature-udfs
turingcompl33t Jun 21, 2021
a1b177b
make pointer explicit
turingcompl33t Jun 21, 2021
f36b19a
refactoring in UDF parsing and AST construction, add documentation fo…
turingcompl33t Jun 24, 2021
ea6f440
fix censored errors
turingcompl33t Jun 24, 2021
dc53b41
fix broken tpl test
turingcompl33t Jun 25, 2021
35f8302
revisiting tpl tests, crashing on basic usage of tpl lambdas
turingcompl33t Jun 25, 2021
3590422
fix broken benchmark runner
turingcompl33t Jun 25, 2021
bc6df12
fix FunctionBuilder that had unread private member
turingcompl33t Jun 25, 2021
8de24e8
add top-level command for CREATE FUNCTION feedback
turingcompl33t Jun 26, 2021
f675140
wip refactoring execution context to resolve lifetime management for …
turingcompl33t Jun 28, 2021
13ad865
still working on refactor
turingcompl33t Jun 29, 2021
7c22e78
building again after execution context refactor
turingcompl33t Jun 29, 2021
cff6bd0
fix access modifier in execution context
turingcompl33t Jun 29, 2021
4b069ee
refactoring again to account for the fact that we don't always know t…
turingcompl33t Jun 29, 2021
69a7004
builds, lints, and passes clang tidy after refactor
turingcompl33t Jun 29, 2021
c375a9b
fix doxygen failure
turingcompl33t Jul 2, 2021
45a17ef
refactor to separate execution context builder
turingcompl33t Jul 2, 2021
c6cb435
fix bad reference in query execution utility
turingcompl33t Jul 2, 2021
5f4189a
resolve memory corruption bug in TPL lambda code generation, still fa…
turingcompl33t Jul 8, 2021
2bb9944
update system_functions_test with new ExecutionContext API
turingcompl33t Jul 9, 2021
0fa39b0
refactor index_nested_loops_join_test to account for updated Executio…
turingcompl33t Jul 9, 2021
3e19098
some refactoring in lambda code generation, still working out the des…
turingcompl33t Jul 9, 2021
38c7b7c
merge master
turingcompl33t Jul 12, 2021
cb77a2c
tpl closures working on both VM and JIT
turingcompl33t Jul 12, 2021
a8031d6
add closures tpl tests, add documentation for the implementation of t…
turingcompl33t Jul 15, 2021
f64c718
minor tweaks, first end to end test of UDF definition and execution w…
turingcompl33t Jul 16, 2021
b2cd8e1
refactor udf code generator and udf ast context
turingcompl33t Jul 16, 2021
a1cb9e5
refactor udf parser to plpgsql parser
turingcompl33t Jul 16, 2021
4bd7b3c
some updates to GenerateTrace.java to handle integration tests for us…
turingcompl33t Jul 17, 2021
9343add
a little more refactoring for GenerateTrace.java, happy with it now
turingcompl33t Jul 17, 2021
635a6de
passing first integration test for UDFs
turingcompl33t Jul 17, 2021
da68ea7
fixed bug in CreateFunction DDL executor, another integration test pa…
turingcompl33t Jul 17, 2021
8a2caa1
update 20min timeout in SQL integration tests to 40 because I keep fa…
turingcompl33t Jul 19, 2021
b72aa95
fix bug in plpgsql parser that caused it to fail on integer variable …
turingcompl33t Jul 20, 2021
eb5ebc3
integration tests for conditionals and while loop iteration, found a …
turingcompl33t Jul 21, 2021
0f2154b
some refactoring of UDF AST context to make querying variables and re…
turingcompl33t Jul 22, 2021
72a0507
refactor to add support for integer for loop variant to parser, now n…
turingcompl33t Jul 22, 2021
66c222b
make clang tidy happy by removing else-if after throw
turingcompl33t Jul 22, 2021
d5fc469
refactor formal parameters for plpgsql parser to reflect types
turingcompl33t Jul 23, 2021
bf56e2a
small changes while trying to get iteration over query results to wor…
turingcompl33t Jul 23, 2021
7b2d2e7
more refactoring in udf code generation during attempts to resolve th…
turingcompl33t Jul 24, 2021
253a578
worked out the issue with embedded SQL, at least for certain SELECT q…
turingcompl33t Jul 26, 2021
6df7d14
minor tweaks in BindNodeVisitor logic for resolving ColumnValueExpres…
turingcompl33t Jul 27, 2021
30ecd1d
refactors across the binder and UDF code generation interface, attemp…
turingcompl33t Jul 28, 2021
24ce125
integration tests for binding multiple query results to udf variables
turingcompl33t Jul 28, 2021
964430d
refactor udf code generation for embedded queries to pull out logic c…
turingcompl33t Jul 29, 2021
c3e81bc
fix some clang tidy errors
turingcompl33t Jul 29, 2021
aa2dfb4
able to bind query results to scalars in both queries and query-varia…
turingcompl33t Jul 29, 2021
d1c0b66
update error handling to not crash the system on code generation fail…
turingcompl33t Jul 29, 2021
ec93afc
major refactor, primarily in pipeline implementation to account for d…
turingcompl33t Aug 2, 2021
1ed88d3
first draft of codegen design doc
turingcompl33t Aug 2, 2021
c8a9043
Merge branch 'feature-udfs' of github.com:turingcompl33t/terrier into…
turingcompl33t Aug 2, 2021
bb5b250
remove unnecessary code in pipeline code generation, lint and tidy, a…
turingcompl33t Aug 2, 2021
bc15102
some basic integration tests for embedded sql queries, need to cover …
turingcompl33t Aug 3, 2021
b6df721
add support for direct assignment of query results to scalar values, …
turingcompl33t Aug 5, 2021
964448d
add support for multiple embedded queries within UDF body, not partic…
turingcompl33t Aug 6, 2021
bc795ea
integration tests for query-fed for loop construct, passing
turingcompl33t Aug 6, 2021
41bd5a2
fig bug in modified translator identified by clang tidy
turingcompl33t Aug 7, 2021
4847199
fix implementation of function calls, going to refactor a few things …
turingcompl33t Aug 8, 2021
f347ffa
refactor execution result handling in udf code generation, slightly m…
turingcompl33t Aug 8, 2021
08327aa
more integration tests for function calls
turingcompl33t Aug 8, 2021
d28c284
finally figured out how to get type names from the postgres parser af…
turingcompl33t Aug 9, 2021
a403aa8
add DROP FUNCTION, some double-free bug when destroying the UDF proc …
turingcompl33t Aug 9, 2021
dc3ca9a
fix bug in PgProcImpl::DropProcedure, DROP FUNCTION now works
turingcompl33t Aug 10, 2021
43cef63
fix some bugs found by clang tidy
turingcompl33t Aug 10, 2021
5c8f21e
add required information for DROP FUNCTION IF EXISTS, just not tied t…
turingcompl33t Aug 10, 2021
6191c33
merge master
turingcompl33t Aug 11, 2021
9b982a5
clean up some of the incomplete type enumerations
turingcompl33t Aug 11, 2021
a592f37
add DROP FUNCTION to integration tests
turingcompl33t Aug 11, 2021
3bfb561
fix small bug in catalog test from refactor of DropProcedure
turingcompl33t Aug 11, 2021
8aa7ad3
make doxygen happy
turingcompl33t Aug 11, 2021
4a1b637
fix some compilation bugs that only show up in release
turingcompl33t Aug 12, 2021
c87f7a3
add some integration tests with character types
turingcompl33t Aug 12, 2021
49faf61
fighting weird function name collision bug that only manifests in CI...
turingcompl33t Aug 12, 2021
d77b17a
fix memory leak from bad merge resolution
turingcompl33t Aug 13, 2021
d5f194b
fix memory leak in libpg_query
turingcompl33t Aug 13, 2021
de6e801
remove old tpl tests, remove flag from debug compilation
turingcompl33t Aug 13, 2021
8dc0cff
remove old comment
turingcompl33t Aug 13, 2021
bce772a
Merge branch 'master' into feature-udfs
mbutrovich Aug 19, 2021
40d3c9b
Merge branch 'master' into feature-udfs
turingcompl33t Aug 20, 2021
6ef1e53
Merge branch 'feature-udfs' of https://github.com/turingcompl33t/terr…
turingcompl33t Aug 20, 2021
7279338
update installation script, add requirements.txt
turingcompl33t Sep 9, 2021
9d5a4a4
update postgresparser
turingcompl33t Sep 23, 2021
b42be3b
issues with types
turingcompl33t Sep 23, 2021
ddb1a39
updates and bugfixes in udf processing, able to compile and invoke pr…
turingcompl33t Sep 24, 2021
dceb128
working on fixing function call argument type resolution
turingcompl33t Sep 24, 2021
c9181e1
wip
turingcompl33t Sep 24, 2021
b4ea2c0
type resolution for call expressions, almost there
turingcompl33t Sep 24, 2021
f65453a
updates for procedures, promotion
turingcompl33t Sep 24, 2021
6a08cf4
going to punt on cast() for now
turingcompl33t Sep 25, 2021
a0ee099
add support for RANDOM
turingcompl33t Sep 25, 2021
f130ff2
actual pseudorandom support for RANDOM
turingcompl33t Sep 25, 2021
51310f5
compiling and invoking up through function 5
turingcompl33t Sep 25, 2021
c52fb13
add support for resolving functions with NULL actual parameters
turingcompl33t Sep 26, 2021
bcecad1
refactor function call type resolution
turingcompl33t Sep 26, 2021
02829ee
now able to invoke UDFs with untyped NULLs that are automatically res…
turingcompl33t Sep 26, 2021
e617369
fix argument resolution when a cast is required
turingcompl33t Sep 26, 2021
fb90d2c
remove print
turingcompl33t Sep 26, 2021
5206e08
fix issue that only manifests in release
turingcompl33t Sep 28, 2021
28b266a
test run with tpch runner
turingcompl33t Nov 18, 2021
eb4cc4b
setup for procbench runner
turingcompl33t Nov 19, 2021
d729006
slight modifications to table and schema readers, able to load all pr…
turingcompl33t Nov 19, 2021
0855600
got procbench running
turingcompl33t Dec 9, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ config/
configure
config-h.in
autom4te.cache
*Makefile.in
*Makefile
build/*Makefile.in
build/*Makefile
libtool
aclocal.m4
config.log
Expand Down
9 changes: 4 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -868,7 +868,7 @@ file(GLOB_RECURSE
function(add_test_util_lib TYPE)
string(TOLOWER ${TYPE} TYPE_LOWER)
add_library(noisepage_test_util_${TYPE_LOWER} ${TYPE} ${NOISEPAGE_TEST_UTIL_SRCS})
add_custom_command(TARGET noisepage_test_util_${TYPE_LOWER} DEPENDS gtest gtest_main gmock gmock_main)
add_custom_command(TARGET noisepage_test_util_${TYPE_LOWER} DEPENDS gtest gtest_main)
target_compile_options(noisepage_test_util_${TYPE_LOWER} PRIVATE "-Werror" "-Wall")
# Inject the source directory path into the translation units for test utility lib
target_compile_definitions(noisepage_test_util_${TYPE_LOWER} PRIVATE NOISEPAGE_BUILD_ROOT=${CMAKE_BINARY_DIR})
Expand All @@ -878,7 +878,7 @@ function(add_test_util_lib TYPE)
${CMAKE_BINARY_DIR}/_deps/src/googletest/googletest/include/
)
target_link_libraries(noisepage_test_util_${TYPE_LOWER} PUBLIC
${CMAKE_BINARY_DIR}/lib/libgtest.a ${CMAKE_BINARY_DIR}/lib/libgmock.a
${CMAKE_BINARY_DIR}/lib/libgtest.a
util_${TYPE_LOWER} pqxx)
set_target_properties(noisepage_test_util_${TYPE_LOWER} PROPERTIES CXX_EXTENSIONS OFF UNITY_BUILD ${NOISEPAGE_UNITY_BUILD})
endfunction()
Expand Down Expand Up @@ -917,7 +917,6 @@ function(add_noisepage_test
add_executable(${TEST_NAME} ${EXCLUDE_OPTION} ${TEST_SOURCES})

target_compile_options(${TEST_NAME} PRIVATE "-Werror" "-Wall" "-fvisibility=hidden")
target_link_libraries(${TEST_NAME} PRIVATE ${CMAKE_BINARY_DIR}/lib/libgmock_main.a)
if (${NOISEPAGE_ENABLE_SHARED})
target_link_libraries(${TEST_NAME} PRIVATE noisepage_test_util_shared)
else ()
Expand Down Expand Up @@ -1119,10 +1118,10 @@ file(GLOB_RECURSE
)

add_library(noisepage_benchmark_util STATIC ${NOISEPAGE_BENCHMARK_UTIL_SRCS})
add_custom_command(TARGET noisepage_benchmark_util DEPENDS gtest gtest_main gmock gmock_main)
add_custom_command(TARGET noisepage_benchmark_util DEPENDS gtest gtest_main)
target_compile_options(noisepage_benchmark_util PRIVATE "-Werror" "-Wall")
target_include_directories(noisepage_benchmark_util PUBLIC ${PROJECT_SOURCE_DIR}/benchmark/include)
target_link_libraries(noisepage_benchmark_util PUBLIC ${CMAKE_BINARY_DIR}/lib/libgmock_main.a noisepage_test_util_static benchmark)
target_link_libraries(noisepage_benchmark_util PUBLIC noisepage_test_util_static benchmark)
set_target_properties(noisepage_benchmark_util PROPERTIES CXX_EXTENSIONS OFF)

set(NOISEPAGE_BENCHMARKS "")
Expand Down
6 changes: 3 additions & 3 deletions Jenkinsfile-utils.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,13 @@ void stageTest(Boolean runPipelineMetrics, Map args = [:]) {

buildType = (args.cmake.toUpperCase().contains("CMAKE_BUILD_TYPE=RELEASE")) ? "release" : "debug"

sh script: "cd build && PYTHONPATH=.. timeout 20m python3 -m script.testing.junit --build-type=$buildType --query-mode=simple", label: 'UnitTest (Simple)'
sh script: "cd build && PYTHONPATH=.. timeout 40m python3 -m script.testing.junit --build-type=$buildType --query-mode=simple", label: 'UnitTest (Simple)'
sh script: "cd build && PYTHONPATH=.. timeout 60m python3 -m script.testing.junit --build-type=$buildType --query-mode=simple -a 'compiled_query_execution=True' -a 'bytecode_handlers_path=./bytecode_handlers_ir.bc'", label: 'UnitTest (Simple, Compiled Execution)'
sh script: "cd build && PYTHONPATH=.. timeout 20m python3 -m script.testing.junit --build-type=$buildType --query-mode=extended", label: 'UnitTest (Extended)'
sh script: "cd build && PYTHONPATH=.. timeout 40m python3 -m script.testing.junit --build-type=$buildType --query-mode=extended", label: 'UnitTest (Extended)'
sh script: "cd build && PYTHONPATH=.. timeout 60m python3 -m script.testing.junit --build-type=$buildType --query-mode=extended -a 'compiled_query_execution=True' -a 'bytecode_handlers_path=./bytecode_handlers_ir.bc'", label: 'UnitTest (Extended, Compiled Execution)'

if (runPipelineMetrics) {
sh script: "cd build && PYTHONPATH=.. timeout 20m python3 -m script.testing.junit --build-type=$buildType --query-mode=extended -a 'pipeline_metrics_enable=True' -a 'pipeline_metrics_sample_rate=100' -a 'counters_enable=True' -a 'query_trace_metrics_enable=True'", label: 'UnitTest (Extended with pipeline metrics, counters, and query trace metrics)'
sh script: "cd build && PYTHONPATH=.. timeout 40m python3 -m script.testing.junit --build-type=$buildType --query-mode=extended -a 'pipeline_metrics_enable=True' -a 'pipeline_metrics_sample_rate=100' -a 'counters_enable=True' -a 'query_trace_metrics_enable=True'", label: 'UnitTest (Extended with pipeline metrics, counters, and query trace metrics)'
sh script: "cd build && PYTHONPATH=.. timeout 60m python3 -m script.testing.junit --build-type=$buildType --query-mode=extended -a 'pipeline_metrics_enable=True' -a 'pipeline_metrics_sample_rate=100' -a 'counters_enable=True' -a 'query_trace_metrics_enable=True' -a 'compiled_query_execution=True' -a 'bytecode_handlers_path=./bytecode_handlers_ir.bc'", label: 'UnitTest (Extended, Compiled Execution with pipeline metrics, counters, and query trace metrics)'
}

Expand Down
20 changes: 20 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Makefile
# Some scripting shortcuts.

# Run all regression checks in all execution modes
check-regress: check-regress-interpreted check-regress-compiled

# Run all regression tests in interpreted mode
check-regress-interpreted:
cd build && PYTHONPATH=.. python -m script.testing.junit --build-type=debug --query-mode=simple

# Run all regression tests in compiled mode
check-regress-compiled:
PYTHONPATH=.. python -m script.testing.junit --build-type=debug --query-mode=simple -a 'compiled_query_execution=True' -a 'bytecode_handlers_path=./bytecode_handlers_ir.bc'

check-regress-udf:
cd build && PYTHONPATH=.. python -m script.testing.junit --build-type=debug --query-mode=simple --tracefile-test=udf.test

# Re-generate the trace file for UDF regression tests
generate-regress-udf:
cd script/testing/junit/ && ant generate-trace -Dpath=sql/udf.sql -Ddb-url=jdbc:postgresql://localhost/test -Ddb-user=postgres -Ddb-password=password -Doutput-name=udf.test
118 changes: 89 additions & 29 deletions benchmark/runner/execution_runners.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "common/scoped_timer.h"
#include "execution/compiler/compilation_context.h"
#include "execution/compiler/executable_query.h"
#include "execution/exec/execution_context_builder.h"
#include "execution/exec/execution_settings.h"
#include "execution/execution_util.h"
#include "execution/sql/ddl_executors.h"
Expand Down Expand Up @@ -448,9 +449,17 @@ class ExecutionRunners : public benchmark::Fixture {
exec_settings = *exec_settings_arg;
}

auto exec_ctx = std::make_unique<execution::exec::ExecutionContext>(
db_oid, common::ManagedPointer(txn), execution::exec::NoOpResultConsumer(), out_plan->GetOutputSchema().Get(),
common::ManagedPointer(accessor), exec_settings, metrics_manager_, DISABLED, DISABLED);
auto exec_ctx = execution::exec::ExecutionContextBuilder()
.WithDatabaseOID(db_oid)
.WithExecutionSettings(exec_settings)
.WithTxnContext(common::ManagedPointer{txn})
.WithOutputSchema(out_plan->GetOutputSchema())
.WithOutputCallback(execution::exec::NoOpResultConsumer{})
.WithCatalogAccessor(common::ManagedPointer{accessor})
.WithMetricsManager(metrics_manager_)
.WithReplicationManager(DISABLED)
.WithRecoveryManager(DISABLED)
.Build();

execution::compiler::ExecutableQuery::query_identifier.store(ExecutionRunners::query_id++);
auto exec_query = execution::compiler::CompilationContext::Compile(*out_plan, exec_settings, accessor.get(),
Expand Down Expand Up @@ -494,9 +503,18 @@ class ExecutionRunners : public benchmark::Fixture {
auto txn = txn_manager->BeginTransaction();
auto accessor = catalog->GetAccessor(common::ManagedPointer(txn), db_oid, DISABLED);
auto exec_settings = ExecutionRunners::GetExecutionSettings();
auto exec_ctx = std::make_unique<execution::exec::ExecutionContext>(
db_oid, common::ManagedPointer(txn), nullptr, nullptr, common::ManagedPointer(accessor), exec_settings,
metrics_manager_, DISABLED, DISABLED);

auto exec_ctx = execution::exec::ExecutionContextBuilder()
.WithDatabaseOID(db_oid)
.WithExecutionSettings(exec_settings)
.WithTxnContext(common::ManagedPointer{txn})
.WithOutputSchema(execution::exec::ExecutionContext::NULL_OUTPUT_SCHEMA)
.WithOutputCallback(execution::exec::ExecutionContext::NULL_OUTPUT_CALLBACK)
.WithCatalogAccessor(common::ManagedPointer{accessor})
.WithMetricsManager(metrics_manager_)
.WithReplicationManager(DISABLED)
.WithRecoveryManager(DISABLED)
.Build();

execution::sql::TableGenerator table_generator(exec_ctx.get(), block_store, accessor->GetDefaultNamespace());
if (is_build) {
Expand Down Expand Up @@ -529,12 +547,12 @@ class ExecutionRunners : public benchmark::Fixture {
}

void BenchmarkExecQuery(int64_t num_iters, execution::compiler::ExecutableQuery *exec_query,
planner::OutputSchema *out_schema, bool commit,
const planner::OutputSchema *out_schema, bool commit,
std::vector<std::vector<parser::ConstantValueExpression>> *params = &empty_params,
execution::exec::ExecutionSettings *exec_settings_arg = nullptr) {
transaction::TransactionContext *txn = nullptr;
std::unique_ptr<catalog::CatalogAccessor> accessor = nullptr;
std::vector<std::vector<parser::ConstantValueExpression>> param_ref = *params;
const auto &params_ref = *params;

execution::exec::NoOpResultConsumer consumer;
execution::exec::OutputCallback callback = consumer;
Expand All @@ -553,14 +571,23 @@ class ExecutionRunners : public benchmark::Fixture {
exec_settings = *exec_settings_arg;
}

auto exec_ctx = std::make_unique<execution::exec::ExecutionContext>(
db_oid, common::ManagedPointer(txn), callback, out_schema, common::ManagedPointer(accessor), exec_settings,
metrics_manager, DISABLED, DISABLED);

// Attach params to ExecutionContext
if (static_cast<size_t>(i) < param_ref.size()) {
exec_ctx->SetParams(common::ManagedPointer<const std::vector<parser::ConstantValueExpression>>(&param_ref[i]));
// TODO(Kyle): This makes an unnecessary copy of the query parameters
std::vector<parser::ConstantValueExpression> parameters{};
if (static_cast<std::size_t>(i) < params_ref.size()) {
std::copy(params_ref[i].cbegin(), params_ref[i].cend(), std::back_inserter(parameters));
}
auto exec_ctx = execution::exec::ExecutionContextBuilder()
.WithDatabaseOID(db_oid)
.WithQueryParametersFrom(parameters)
.WithExecutionSettings(exec_settings)
.WithTxnContext(common::ManagedPointer{txn})
.WithOutputSchema(common::ManagedPointer{out_schema})
.WithOutputCallback(callback)
.WithCatalogAccessor(common::ManagedPointer{accessor})
.WithMetricsManager(metrics_manager_)
.WithReplicationManager(DISABLED)
.WithRecoveryManager(DISABLED)
.Build();

exec_query->Run(common::ManagedPointer(exec_ctx), mode);

Expand All @@ -582,10 +609,17 @@ class ExecutionRunners : public benchmark::Fixture {
auto txn = txn_manager_->BeginTransaction();
auto accessor = catalog_->GetAccessor(common::ManagedPointer(txn), db_oid, DISABLED);
auto exec_settings = GetExecutionSettings();
auto exec_ctx = std::make_unique<execution::exec::ExecutionContext>(
db_oid, common::ManagedPointer(txn), nullptr, nullptr, common::ManagedPointer(accessor), exec_settings,
metrics_manager_, DISABLED, DISABLED);
exec_ctx->SetExecutionMode(static_cast<uint8_t>(mode));
auto exec_ctx = execution::exec::ExecutionContextBuilder()
.WithDatabaseOID(db_oid)
.WithExecutionSettings(exec_settings)
.WithTxnContext(common::ManagedPointer{txn})
.WithOutputSchema(execution::exec::ExecutionContext::NULL_OUTPUT_SCHEMA)
.WithOutputCallback(execution::exec::ExecutionContext::NULL_OUTPUT_CALLBACK)
.WithCatalogAccessor(common::ManagedPointer{accessor})
.WithMetricsManager(metrics_manager_)
.WithReplicationManager(DISABLED)
.WithRecoveryManager(DISABLED)
.Build();

selfdriving::PipelineOperatingUnits units;
selfdriving::ExecutionOperatingUnitFeatureVector pipe0_vec;
Expand Down Expand Up @@ -939,15 +973,24 @@ BENCHMARK_DEFINE_F(ExecutionRunners, SEQ0_OutputRunners)(benchmark::State &state

auto txn = txn_manager_->BeginTransaction();
auto accessor = catalog_->GetAccessor(common::ManagedPointer(txn), db_oid, DISABLED);
auto schema = std::make_unique<planner::OutputSchema>(std::move(cols));
auto schema = std::make_unique<const planner::OutputSchema>(std::move(cols));

auto exec_settings = GetExecutionSettings();
execution::compiler::ExecutableQuery::query_identifier.store(ExecutionRunners::query_id++);
execution::exec::NoOpResultConsumer consumer;
execution::exec::OutputCallback callback = consumer;
auto exec_ctx = std::make_unique<execution::exec::ExecutionContext>(
db_oid, common::ManagedPointer(txn), callback, schema.get(), common::ManagedPointer(accessor), exec_settings,
metrics_manager_, DISABLED, DISABLED);

auto exec_ctx = execution::exec::ExecutionContextBuilder()
.WithDatabaseOID(db_oid)
.WithExecutionSettings(exec_settings)
.WithTxnContext(common::ManagedPointer{txn})
.WithOutputSchema(common::ManagedPointer{schema})
.WithOutputCallback(callback)
.WithCatalogAccessor(common::ManagedPointer{accessor})
.WithMetricsManager(metrics_manager_)
.WithReplicationManager(DISABLED)
.WithRecoveryManager(DISABLED)
.Build();

auto exec_query = execution::compiler::ExecutableQuery(output.str(), common::ManagedPointer(exec_ctx), false, 16,
exec_settings, txn->StartTime());
Expand Down Expand Up @@ -1011,9 +1054,18 @@ void ExecutionRunners::ExecuteIndexOperation(benchmark::State *state, bool is_in
auto exec_settings = GetExecutionSettings();
execution::exec::NoOpResultConsumer consumer;
execution::exec::OutputCallback callback = consumer;
auto exec_ctx = std::make_unique<execution::exec::ExecutionContext>(
db_oid, common::ManagedPointer(txn), callback, nullptr, common::ManagedPointer(accessor), exec_settings,
metrics_manager, DISABLED, DISABLED);

auto exec_ctx = execution::exec::ExecutionContextBuilder()
.WithDatabaseOID(db_oid)
.WithExecutionSettings(exec_settings)
.WithTxnContext(common::ManagedPointer{txn})
.WithOutputSchema(execution::exec::ExecutionContext::NULL_OUTPUT_SCHEMA)
.WithOutputCallback(callback)
.WithCatalogAccessor(common::ManagedPointer{accessor})
.WithMetricsManager(metrics_manager_)
.WithReplicationManager(DISABLED)
.WithRecoveryManager(DISABLED)
.Build();

// A brief discussion of the features:
// NUM_ROWS: size of the index
Expand Down Expand Up @@ -2062,9 +2114,17 @@ void InitializeRunnersState() {
// Load the database
auto accessor = catalog->GetAccessor(common::ManagedPointer(txn), db_oid, DISABLED);
auto exec_settings = ExecutionRunners::GetExecutionSettings();
auto exec_ctx = std::make_unique<execution::exec::ExecutionContext>(
db_oid, common::ManagedPointer(txn), nullptr, nullptr, common::ManagedPointer(accessor), exec_settings,
db_main->GetMetricsManager(), DISABLED, DISABLED);
auto exec_ctx = execution::exec::ExecutionContextBuilder()
.WithDatabaseOID(db_oid)
.WithExecutionSettings(exec_settings)
.WithTxnContext(common::ManagedPointer{txn})
.WithOutputSchema(execution::exec::ExecutionContext::NULL_OUTPUT_SCHEMA)
.WithOutputCallback(execution::exec::ExecutionContext::NULL_OUTPUT_CALLBACK)
.WithCatalogAccessor(common::ManagedPointer{accessor})
.WithMetricsManager(db_main->GetMetricsManager())
.WithReplicationManager(DISABLED)
.WithRecoveryManager(DISABLED)
.Build();

execution::sql::TableGenerator table_gen(exec_ctx.get(), block_store, accessor->GetDefaultNamespace());
table_gen.GenerateExecutionRunnersData(settings, config);
Expand Down
Loading