Skip to content

Commit

Permalink
Merge branch 'uhugeint' into hugeint_faster_math
Browse files Browse the repository at this point in the history
  • Loading branch information
nickgerrets committed Dec 6, 2023
2 parents 37244ee + 9dc2797 commit 2c1ad67
Show file tree
Hide file tree
Showing 43 changed files with 280 additions and 236 deletions.
19 changes: 19 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -698,6 +698,10 @@ function(build_loadable_extension_directory NAME OUTPUT_DIRECTORY PARAMETERS)
set_target_properties(${TARGET_NAME} PROPERTIES SUFFIX
".duckdb_extension")

if(EMSCRIPTEN)
set_target_properties(${TARGET_NAME} PROPERTIES SUFFIX ".duckdb_extension.wasm")
endif()

if(MSVC)
set_target_properties(
${TARGET_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY_DEBUG
Expand All @@ -706,6 +710,21 @@ function(build_loadable_extension_directory NAME OUTPUT_DIRECTORY PARAMETERS)
${TARGET_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY_RELEASE
"${CMAKE_BINARY_DIR}/${OUTPUT_DIRECTORY}")
endif()

if(EMSCRIPTEN)
# Copy file.duckdb_extension.wasm to file.duckdb_extension.wasm.lib
add_custom_command(
TARGET ${TARGET_NAME}
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:${TARGET_NAME}> $<TARGET_FILE:${TARGET_NAME}>.lib
)
# Compile the library into the actual wasm file
add_custom_command(
TARGET ${TARGET_NAME}
POST_BUILD
COMMAND emcc $<TARGET_FILE:${TARGET_NAME}>.lib -o $<TARGET_FILE:${TARGET_NAME}> -sSIDE_MODULE=1 -O3
)
endif()
endfunction()

function(build_loadable_extension NAME PARAMETERS)
Expand Down
9 changes: 3 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -269,20 +269,17 @@ release: ${EXTENSION_CONFIG_STEP}
wasm_mvp: ${EXTENSION_CONFIG_STEP}
mkdir -p ./build/wasm_mvp && \
emcmake cmake $(GENERATOR) -DWASM_LOADABLE_EXTENSIONS=1 -DBUILD_EXTENSIONS_ONLY=1 -Bbuild/wasm_mvp -DCMAKE_CXX_FLAGS="-DDUCKDB_CUSTOM_PLATFORM=wasm_mvp" && \
emmake make -j8 -Cbuild/wasm_mvp && \
cd build/wasm_mvp && bash ../../scripts/link-wasm-extensions.sh
emmake make -j8 -Cbuild/wasm_mvp

wasm_eh: ${EXTENSION_CONFIG_STEP}
mkdir -p ./build/wasm_eh && \
emcmake cmake $(GENERATOR) -DWASM_LOADABLE_EXTENSIONS=1 -DBUILD_EXTENSIONS_ONLY=1 -Bbuild/wasm_eh -DCMAKE_CXX_FLAGS="-fwasm-exceptions -DWEBDB_FAST_EXCEPTIONS=1 -DDUCKDB_CUSTOM_PLATFORM=wasm_eh" && \
emmake make -j8 -Cbuild/wasm_eh && \
cd build/wasm_eh && bash ../../scripts/link-wasm-extensions.sh
emmake make -j8 -Cbuild/wasm_eh

wasm_threads: ${EXTENSION_CONFIG_STEP}
mkdir -p ./build/wasm_threads && \
emcmake cmake $(GENERATOR) -DWASM_LOADABLE_EXTENSIONS=1 -DBUILD_EXTENSIONS_ONLY=1 -Bbuild/wasm_threads -DCMAKE_CXX_FLAGS="-fwasm-exceptions -DWEBDB_FAST_EXCEPTIONS=1 -DWITH_WASM_THREADS=1 -DWITH_WASM_SIMD=1 -DWITH_WASM_BULK_MEMORY=1 -DDUCKDB_CUSTOM_PLATFORM=wasm_threads" && \
emmake make -j8 -Cbuild/wasm_threads && \
cd build/wasm_threads && bash ../../scripts/link-wasm-extensions.sh
emmake make -j8 -Cbuild/wasm_threads

cldebug: ${EXTENSION_CONFIG_STEP}
mkdir -p ./build/cldebug && \
Expand Down
4 changes: 2 additions & 2 deletions extension/autocomplete/autocomplete_extension.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,15 @@ static vector<string> InitialKeywords() {
return vector<string> {"SELECT", "INSERT", "DELETE", "UPDATE", "CREATE", "DROP", "COPY",
"ALTER", "WITH", "EXPORT", "BEGIN", "VACUUM", "PREPARE", "EXECUTE",
"DEALLOCATE", "CALL", "ANALYZE", "EXPLAIN", "DESCRIBE", "SUMMARIZE", "LOAD",
"CHECKPOINT", "ROLLBACK", "COMMIT", "CALL"};
"CHECKPOINT", "ROLLBACK", "COMMIT", "CALL", "FROM"};
}

static vector<AutoCompleteCandidate> SuggestKeyword(ClientContext &context) {
auto keywords = InitialKeywords();
vector<AutoCompleteCandidate> result;
for (auto &kw : keywords) {
auto score = 0;
if (kw == "SELECT" || kw == "DELETE" || kw == "INSERT" || kw == "UPDATE") {
if (kw == "FROM" || kw == "SELECT" || kw == "DELETE" || kw == "INSERT" || kw == "UPDATE") {
score = 1;
}
result.emplace_back(kw + " ", score);
Expand Down
4 changes: 2 additions & 2 deletions extension/httpfs/include/s3fs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ class S3FileHandle : public HTTPFileHandle {
S3FileHandle(FileSystem &fs, string path_p, uint8_t flags, const HTTPParams &http_params,
const S3AuthParams &auth_params_p, const S3ConfigParams &config_params_p)
: HTTPFileHandle(fs, std::move(path_p), flags, http_params), auth_params(auth_params_p),
config_params(config_params_p) {

config_params(config_params_p), uploads_in_progress(0), parts_uploaded(0), upload_finalized(false),
uploader_has_error(false), upload_exception(nullptr) {
if (flags & FileFlags::FILE_FLAGS_WRITE && flags & FileFlags::FILE_FLAGS_READ) {
throw NotImplementedException("Cannot open an HTTP file for both reading and writing");
} else if (flags & FileFlags::FILE_FLAGS_APPEND) {
Expand Down
10 changes: 4 additions & 6 deletions extension/httpfs/s3fs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,9 @@ void S3FileHandle::Close() {
auto &s3fs = (S3FileSystem &)file_system;
if ((flags & FileFlags::FILE_FLAGS_WRITE) && !upload_finalized) {
s3fs.FlushAllBuffers(*this);
s3fs.FinalizeMultipartUpload(*this);
if (parts_uploaded) {
s3fs.FinalizeMultipartUpload(*this);
}
}
}

Expand Down Expand Up @@ -424,6 +426,7 @@ void S3FileSystem::FlushAllBuffers(S3FileHandle &file_handle) {

void S3FileSystem::FinalizeMultipartUpload(S3FileHandle &file_handle) {
auto &s3fs = (S3FileSystem &)file_handle.file_system;
file_handle.upload_finalized = true;

std::stringstream ss;
ss << "<CompleteMultipartUpload xmlns=\"http://s3.amazonaws.com/doc/2006-03-01/\">";
Expand Down Expand Up @@ -452,7 +455,6 @@ void S3FileSystem::FinalizeMultipartUpload(S3FileHandle &file_handle) {
if (open_tag_pos == string::npos) {
throw IOException("Unexpected response during S3 multipart upload finalization: %d\n\n%s", res->code, result);
}
file_handle.upload_finalized = true;
}

// Wrapper around the BufferManager::Allocate to that allows limiting the number of buffers that will be handed out
Expand Down Expand Up @@ -826,10 +828,6 @@ void S3FileHandle::Initialize(FileOpener *opener) {
D_ASSERT(part_size * max_part_count >= config_params.max_file_size);

multipart_upload_id = s3fs.InitializeMultipartUpload(*this);

uploads_in_progress = 0;
parts_uploaded = 0;
upload_finalized = false;
}
}

Expand Down
19 changes: 0 additions & 19 deletions scripts/link-wasm-extensions.sh

This file was deleted.

10 changes: 5 additions & 5 deletions src/execution/index/art/art.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -911,11 +911,11 @@ string ART::GenerateConstraintErrorMessage(VerifyExistenceType verify_type, cons
case VerifyExistenceType::APPEND: {
// APPEND to PK/UNIQUE table, but node/key already exists in PK/UNIQUE table
string type = IsPrimary() ? "primary key" : "unique";
return StringUtil::Format(
"Duplicate key \"%s\" violates %s constraint. "
"If this is an unexpected constraint violation please double "
"check with the known index limitations section in our documentation (docs - sql - indexes).",
key_name, type);
return StringUtil::Format("Duplicate key \"%s\" violates %s constraint. "
"If this is an unexpected constraint violation please double "
"check with the known index limitations section in our documentation "
"(https://duckdb.org/docs/sql/indexes).",
key_name, type);
}
case VerifyExistenceType::APPEND_FK: {
// APPEND_FK to FK table, node/key does not exist in PK/UNIQUE table
Expand Down
2 changes: 1 addition & 1 deletion src/execution/operator/persistent/physical_insert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ static void RegisterUpdatedRows(InsertLocalState &lstate, const Vector &row_ids,
auto result = updated_rows.insert(data[i]);
if (result.second == false) {
throw InvalidInputException(
"ON CONFLICT DO UPDATE can not update the same row twice in the same command, Ensure that no rows "
"ON CONFLICT DO UPDATE can not update the same row twice in the same command. Ensure that no rows "
"proposed for insertion within the same command have duplicate constrained values");
}
}
Expand Down
10 changes: 7 additions & 3 deletions src/main/database_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,12 @@ optional_ptr<AttachedDatabase> DatabaseManager::GetDatabaseFromPath(ClientContex

void DatabaseManager::CheckPathConflict(ClientContext &context, const string &path) {
// ensure that we did not already attach a database with the same path
if (db_paths.find(path) != db_paths.end()) {
bool path_exists;
{
lock_guard<mutex> path_lock(db_paths_lock);
path_exists = db_paths.find(path) != db_paths.end();
}
if (path_exists) {
// check that the database is actually still attached
auto entry = GetDatabaseFromPath(context, path);
if (entry) {
Expand All @@ -109,8 +114,8 @@ void DatabaseManager::InsertDatabasePath(ClientContext &context, const string &p
return;
}

lock_guard<mutex> path_lock(db_paths_lock);
CheckPathConflict(context, path);
lock_guard<mutex> path_lock(db_paths_lock);
db_paths.insert(path);
}

Expand Down Expand Up @@ -141,7 +146,6 @@ void DatabaseManager::GetDatabaseType(ClientContext &context, string &db_type, A

// try to extract database type from path
if (db_type.empty()) {
lock_guard<mutex> path_lock(db_paths_lock);
CheckPathConflict(context, info.path);

DBPathAndType::CheckMagicBytes(info.path, db_type, config);
Expand Down
4 changes: 3 additions & 1 deletion src/optimizer/filter_combiner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,9 @@ FilterResult FilterCombiner::AddBoundComparisonFilter(Expression &expr) {
// get the current bucket of constant values
D_ASSERT(constant_values.find(equivalence_set) != constant_values.end());
auto &info_list = constant_values.find(equivalence_set)->second;
D_ASSERT(node.return_type == info.constant.type());
if (node.return_type != info.constant.type()) {
return FilterResult::UNSUPPORTED;
}
// check the existing constant comparisons to see if we can do any pruning
auto ret = AddConstantComparison(info_list, info);

Expand Down
13 changes: 8 additions & 5 deletions src/optimizer/rule/move_constants.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,12 @@ MoveConstantsRule::MoveConstantsRule(ExpressionRewriter &rewriter) : Rule(rewrit
arithmetic->function = make_uniq<ManyFunctionMatcher>(unordered_set<string> {"+", "-", "*"});
// we match only on integral numeric types
arithmetic->type = make_uniq<IntegerTypeMatcher>();
arithmetic->matchers.push_back(make_uniq<ConstantExpressionMatcher>());
arithmetic->matchers.push_back(make_uniq<ExpressionMatcher>());
auto child_constant_matcher = make_uniq<ConstantExpressionMatcher>();
auto child_expression_matcher = make_uniq<ExpressionMatcher>();
child_constant_matcher->type = make_uniq<IntegerTypeMatcher>();
child_expression_matcher->type = make_uniq<IntegerTypeMatcher>();
arithmetic->matchers.push_back(std::move(child_constant_matcher));
arithmetic->matchers.push_back(std::move(child_expression_matcher));
arithmetic->policy = SetMatcher::Policy::SOME;
op->matchers.push_back(std::move(arithmetic));
root = std::move(op);
Expand All @@ -34,9 +38,8 @@ unique_ptr<Expression> MoveConstantsRule::Apply(LogicalOperator &op, vector<refe
auto &outer_constant = bindings[1].get().Cast<BoundConstantExpression>();
auto &arithmetic = bindings[2].get().Cast<BoundFunctionExpression>();
auto &inner_constant = bindings[3].get().Cast<BoundConstantExpression>();
if (!TypeIsIntegral(arithmetic.return_type.InternalType())) {
return nullptr;
}
D_ASSERT(arithmetic.return_type.IsIntegral());
D_ASSERT(arithmetic.children[0]->return_type.IsIntegral());
if (inner_constant.value.IsNull() || outer_constant.value.IsNull()) {
return make_uniq<BoundConstantExpression>(Value(comparison.return_type));
}
Expand Down
2 changes: 1 addition & 1 deletion src/optimizer/rule/regex_optimizations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,13 +143,13 @@ unique_ptr<Expression> RegexOptimizationRule::Apply(LogicalOperator &op, vector<

auto constant_value = ExpressionExecutor::EvaluateScalar(GetContext(), constant_expr);
D_ASSERT(constant_value.type() == constant_expr.return_type);
auto patt_str = StringValue::Get(constant_value);

duckdb_re2::RE2::Options parsed_options = regexp_bind_data.options;

if (constant_expr.value.IsNull()) {
return make_uniq<BoundConstantExpression>(Value(root.return_type));
}
auto patt_str = StringValue::Get(constant_value);

// the constant_expr is a scalar expression that we have to fold
if (!constant_expr.IsFoldable()) {
Expand Down
11 changes: 8 additions & 3 deletions test/api/adbc/test_adbc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,14 @@ TEST_CASE("Test Invalid Path", "[adbc]") {

REQUIRE(!SUCCESS(AdbcDatabaseInit(&adbc_database, &adbc_error)));

REQUIRE(std::strcmp(
adbc_error.message,
"IO Error: Cannot open file \"/this/path/is/imaginary/hopefully/\": No such file or directory") == 0);
if (!adbc_error.message) {
REQUIRE(false);
} else {
REQUIRE(std::strcmp(
adbc_error.message,
"IO Error: Cannot open file \"/this/path/is/imaginary/hopefully/\": No such file or directory") ==
0);
}
}

TEST_CASE("Error Release", "[adbc]") {
Expand Down
Binary file modified test/api/serialized_plans/serialized_plans.binary
Binary file not shown.
1 change: 1 addition & 0 deletions test/api/test_progress_bar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class TestProgressBar {
};

TEST_CASE("Test Progress Bar Fast", "[api]") {
return;
DuckDB db(nullptr);
Connection con(db);
REQUIRE_NOTHROW(con.context->GetQueryProgress());
Expand Down
4 changes: 2 additions & 2 deletions test/arrow/arrow_roundtrip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ TEST_CASE("Test arrow roundtrip", "[arrow]") {
// FIXME: there seems to be a bug in the enum arrow reader in this test when run with vsize=2
return;
#endif
TestArrowRoundtrip("SELECT * EXCLUDE(bit,time_tz,uhugeint) REPLACE "
"(interval (1) seconds AS interval, hugeint::DOUBLE as hugeint) "
TestArrowRoundtrip("SELECT * EXCLUDE(bit,time_tz) REPLACE "
"(interval (1) seconds AS interval, hugeint::DOUBLE as hugeint, uhugeint::DOUBLE as uhugeint) "
"FROM test_all_types()");
}

Expand Down
1 change: 0 additions & 1 deletion test/fuzzer/sqlsmith/window-rows-overflow.test
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ create table all_types as
small_enum,
medium_enum,
large_enum,
uhugeint
)
from test_all_types();

Expand Down
5 changes: 0 additions & 5 deletions test/sql/copy/s3/fully_qualified_s3_url.test
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,6 @@ require httpfs

require-env S3_TEST_SERVER_AVAILABLE 1

# FIXME - this test randomly fails in the CI
# # terminate called after throwing an instance of 'duckdb::IOException'
# what(): IO Error: Unexpected response during S3 multipart upload finalization: 403
mode skip

# Require that these environment variables are also set

require-env AWS_DEFAULT_REGION
Expand Down
2 changes: 1 addition & 1 deletion test/sql/copy/s3/upload_large_file.test_slow
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ set ignore_error_messages

# confirm we use a reasonable amount of memory
statement ok
SET memory_limit='2.2GB';
SET memory_limit='2.5GB';

statement ok
set http_timeout=120000;
Expand Down
Loading

0 comments on commit 2c1ad67

Please sign in to comment.