Skip to content

Commit ebef445

Browse files
committed
upgrade to 0.3.4
Change-Id: Ifacbe328c99f96fd42e8e87b492da0c0aeb7a26d
1 parent 567f4c2 commit ebef445

File tree

6 files changed

+89
-74
lines changed

6 files changed

+89
-74
lines changed

.github/workflows/rust.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ jobs:
3737
- run: cargo fmt --all -- --check
3838
- name: Download DuckDB
3939
run: |
40-
wget https://github.com/duckdb/duckdb/releases/download/v0.3.3/libduckdb-linux-amd64.zip -O libduckdb.zip
40+
wget https://github.com/duckdb/duckdb/releases/download/v0.3.4/libduckdb-linux-amd64.zip -O libduckdb.zip
4141
unzip libduckdb.zip -d libduckdb
4242
# - run: cargo clippy --all-targets --workspace --features bundled --features modern-full -- -D warnings -A clippy::redundant-closure
4343
- run: cargo clippy --all-targets --workspace --features buildtime_bindgen --features modern-full -- -D warnings -A clippy::redundant-closure

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "duckdb"
3-
version = "0.3.3"
3+
version = "0.3.4"
44
authors = ["wangfenjin <[email protected]>"]
55
edition = "2021"
66
description = "Ergonomic wrapper for DuckDB"
@@ -69,7 +69,7 @@ tempdir = "0.3.7"
6969

7070
[dependencies.libduckdb-sys]
7171
path = "libduckdb-sys"
72-
version = "0.3.3"
72+
version = "0.3.4"
7373

7474
[package.metadata.docs.rs]
7575
features = []

libduckdb-sys/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "libduckdb-sys"
3-
version = "0.3.3"
3+
version = "0.3.4"
44
authors = ["wangfenjin <[email protected]>"]
55
edition = "2021"
66
build = "build.rs"

libduckdb-sys/duckdb/duckdb.cpp

Lines changed: 58 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -3484,6 +3484,9 @@ string IndexCatalogEntry::ToSQL() {
34843484
if (sql.empty()) {
34853485
throw InternalException("Cannot convert INDEX to SQL because it was not created with a SQL statement");
34863486
}
3487+
if (sql[sql.size() - 1] != ';') {
3488+
sql += ";";
3489+
}
34873490
return sql;
34883491
}
34893492

@@ -63943,6 +63946,7 @@ void PhysicalIEJoin::GetData(ExecutionContext &context, DataChunk &result, Globa
6394363946
const idx_t count = ie_lstate.SelectOuterRows(ie_lstate.right_matches);
6394463947
if (!count) {
6394563948
ie_gstate.GetNextPair(context.client, ie_sink, ie_lstate);
63949+
continue;
6394663950
}
6394763951

6394863952
SliceSortedPayload(result, ie_sink.tables[1]->global_sort_state, ie_lstate.right_base, ie_lstate.true_sel,
@@ -72020,12 +72024,12 @@ void PartitionableHashTable::Partition() {
7202072024
D_ASSERT(radix_partitioned_hts.size() == 0);
7202172025
D_ASSERT(partition_info.n_partitions > 1);
7202272026

72023-
vector<GroupedAggregateHashTable *> partition_hts;
72027+
vector<GroupedAggregateHashTable *> partition_hts(partition_info.n_partitions);
7202472028
for (auto &unpartitioned_ht : unpartitioned_hts) {
7202572029
for (idx_t r = 0; r < partition_info.n_partitions; r++) {
7202672030
radix_partitioned_hts[r].push_back(make_unique<GroupedAggregateHashTable>(
7202772031
buffer_manager, group_types, payload_types, bindings, HtEntryType::HT_WIDTH_32));
72028-
partition_hts.push_back(radix_partitioned_hts[r].back().get());
72032+
partition_hts[r] = radix_partitioned_hts[r].back().get();
7202972033
}
7203072034
unpartitioned_ht->Partition(partition_hts, partition_info.radix_mask, partition_info.RADIX_SHIFT);
7203172035
unpartitioned_ht.reset();
@@ -72504,6 +72508,8 @@ template <>
7250472508
bool TrySubtractOperator::Operation(int32_t left, int32_t right, int32_t &result);
7250572509
template <>
7250672510
bool TrySubtractOperator::Operation(int64_t left, int64_t right, int64_t &result);
72511+
template <>
72512+
bool TrySubtractOperator::Operation(hugeint_t left, hugeint_t right, hugeint_t &result);
7250772513

7250872514
struct SubtractOperatorOverflowCheck {
7250972515
template <class TA, class TB, class TR>
@@ -83750,6 +83756,9 @@ void HistogramFun::RegisterFunction(BuiltinFunctions &set) {
8375083756
fun.AddFunction(GetHistogramFunction<int64_t>(LogicalType::TIMESTAMP_S));
8375183757
fun.AddFunction(GetHistogramFunction<int64_t>(LogicalType::TIMESTAMP_MS));
8375283758
fun.AddFunction(GetHistogramFunction<int64_t>(LogicalType::TIMESTAMP_NS));
83759+
fun.AddFunction(GetHistogramFunction<int64_t>(LogicalType::TIME));
83760+
fun.AddFunction(GetHistogramFunction<int64_t>(LogicalType::TIME_TZ));
83761+
fun.AddFunction(GetHistogramFunction<int32_t>(LogicalType::DATE));
8375383762
set.AddFunction(fun);
8375483763
}
8375583764

@@ -91556,6 +91565,10 @@ static void TemplatedContainsOrPosition(DataChunk &args, ExpressionState &state,
9155691565
VectorData value_data;
9155791566
value_vector.Orrify(count, value_data);
9155891567

91568+
// not required for a comparison of nested types
91569+
auto child_value = FlatVector::GetData<CHILD_TYPE>(child_vector);
91570+
auto values = FlatVector::GetData<CHILD_TYPE>(value_vector);
91571+
9155991572
for (idx_t i = 0; i < count; i++) {
9156091573
auto list_index = list_data.sel->get_index(i);
9156191574
auto value_index = value_data.sel->get_index(i);
@@ -91566,31 +91579,26 @@ static void TemplatedContainsOrPosition(DataChunk &args, ExpressionState &state,
9156691579
}
9156791580

9156891581
const auto &list_entry = list_entries[list_index];
91569-
auto source_idx = child_data.sel->get_index(list_entry.offset);
9157091582

91571-
// not required for a comparison of nested types
91572-
auto child_value = FlatVector::GetData<CHILD_TYPE>(child_vector);
91573-
auto values = FlatVector::GetData<CHILD_TYPE>(value_vector);
91574-
91575-
result_entries[list_index] = OP::Initialize();
91583+
result_entries[i] = OP::Initialize();
9157691584
for (idx_t child_idx = 0; child_idx < list_entry.length; child_idx++) {
91577-
auto child_value_idx = source_idx + child_idx;
9157891585

91586+
auto child_value_idx = child_data.sel->get_index(list_entry.offset + child_idx);
9157991587
if (!child_data.validity.RowIsValid(child_value_idx)) {
9158091588
continue;
9158191589
}
9158291590

9158391591
if (!is_nested) {
9158491592
if (ValueEqualsOrNot<CHILD_TYPE>(child_value[child_value_idx], values[value_index])) {
91585-
result_entries[list_index] = OP::UpdateResultEntries(child_idx);
91593+
result_entries[i] = OP::UpdateResultEntries(child_idx);
9158691594
break; // Found value in list, no need to look further
9158791595
}
9158891596
} else {
9158991597
// FIXME: using Value is less efficient than modifying the vector comparison code
9159091598
// to more efficiently compare nested types
9159191599
if (ValueEqualsOrNot<Value>(child_vector.GetValue(child_value_idx),
9159291600
value_vector.GetValue(value_index))) {
91593-
result_entries[list_index] = OP::UpdateResultEntries(child_idx);
91601+
result_entries[i] = OP::UpdateResultEntries(child_idx);
9159491602
break; // Found value in list, no need to look further
9159591603
}
9159691604
}
@@ -92009,10 +92017,7 @@ static void ListAggregateFunction(DataChunk &args, ExpressionState &state, Vecto
9200992017
continue;
9201092018
}
9201192019

92012-
auto source_idx = child_data.sel->get_index(list_entry.offset);
92013-
idx_t child_idx = 0;
92014-
92015-
while (child_idx < list_entry.length) {
92020+
for (idx_t child_idx = 0; child_idx < list_entry.length; child_idx++) {
9201692021

9201792022
// states vector is full, update
9201892023
if (states_idx == STANDARD_VECTOR_SIZE) {
@@ -92025,10 +92030,10 @@ static void ListAggregateFunction(DataChunk &args, ExpressionState &state, Vecto
9202592030
states_idx = 0;
9202692031
}
9202792032

92028-
sel_vector.set_index(states_idx, source_idx + child_idx);
92033+
auto source_idx = child_data.sel->get_index(list_entry.offset + child_idx);
92034+
sel_vector.set_index(states_idx, source_idx);
9202992035
states_update[states_idx] = state_ptr;
9203092036
states_idx++;
92031-
child_idx++;
9203292037
}
9203392038
}
9203492039

@@ -92065,7 +92070,7 @@ static unique_ptr<FunctionData> ListAggregateBind(ClientContext &context, Scalar
9206592070

9206692071
// get the function name
9206792072
Value function_value = ExpressionExecutor::EvaluateScalar(*arguments[1]);
92068-
auto function_name = StringValue::Get(function_value);
92073+
auto function_name = function_value.ToString();
9206992074

9207092075
vector<LogicalType> types;
9207192076
types.push_back(list_child_type);
@@ -96177,6 +96182,12 @@ bool TrySubtractOperator::Operation(int64_t left, int64_t right, int64_t &result
9617796182
return true;
9617896183
}
9617996184

96185+
template <>
96186+
bool TrySubtractOperator::Operation(hugeint_t left, hugeint_t right, hugeint_t &result) {
96187+
result = left;
96188+
return Hugeint::SubtractInPlace(result, right);
96189+
}
96190+
9618096191
//===--------------------------------------------------------------------===//
9618196192
// subtract decimal with overflow check
9618296193
//===--------------------------------------------------------------------===//
@@ -133896,51 +133907,37 @@ unique_ptr<BaseStatistics> StatisticsPropagator::PropagateExpression(BoundAggreg
133896133907

133897133908
namespace duckdb {
133898133909

133899-
unique_ptr<Expression> CastHugeintToSmallestType(unique_ptr<Expression> expr, NumericStatistics &num_stats) {
133900-
// Compute range
133901-
if (num_stats.min.IsNull() || num_stats.max.IsNull()) {
133902-
return expr;
133903-
}
133904-
133905-
auto min_val = num_stats.min.GetValue<hugeint_t>();
133906-
auto max_val = num_stats.max.GetValue<hugeint_t>();
133907-
if (max_val < min_val) {
133908-
return expr;
133909-
}
133910+
template <class T>
133911+
bool GetCastType(T signed_range, LogicalType &cast_type) {
133912+
auto range = static_cast<typename std::make_unsigned<decltype(signed_range)>::type>(signed_range);
133910133913

133911-
// Prevent overflow
133912-
if (min_val < NumericLimits<int64_t>().Minimum() && max_val > NumericLimits<int64_t>().Maximum()) {
133913-
return expr;
133914+
// Check if this range fits in a smaller type
133915+
if (range < NumericLimits<uint8_t>::Maximum()) {
133916+
cast_type = LogicalType::UTINYINT;
133917+
} else if (sizeof(T) > sizeof(uint16_t) && range < NumericLimits<uint16_t>::Maximum()) {
133918+
cast_type = LogicalType::USMALLINT;
133919+
} else if (sizeof(T) > sizeof(uint32_t) && range < NumericLimits<uint32_t>::Maximum()) {
133920+
cast_type = LogicalType::UINTEGER;
133921+
} else {
133922+
return false;
133914133923
}
133924+
return true;
133925+
}
133915133926

133916-
// Compute range
133917-
auto range = max_val - min_val;
133918-
133919-
// Check if this range fits in a smaller type
133920-
LogicalType cast_type;
133927+
template <>
133928+
bool GetCastType(hugeint_t range, LogicalType &cast_type) {
133921133929
if (range < NumericLimits<uint8_t>().Maximum()) {
133922133930
cast_type = LogicalType::UTINYINT;
133923133931
} else if (range < NumericLimits<uint16_t>().Maximum()) {
133924133932
cast_type = LogicalType::USMALLINT;
133925133933
} else if (range < NumericLimits<uint32_t>().Maximum()) {
133926133934
cast_type = LogicalType::UINTEGER;
133927133935
} else if (range < NumericLimits<uint64_t>().Maximum()) {
133928-
cast_type = LogicalTypeId::UBIGINT;
133936+
cast_type = LogicalType::UBIGINT;
133929133937
} else {
133930-
return expr;
133938+
return false;
133931133939
}
133932-
133933-
// Create expression to map to a smaller range
133934-
auto input_type = expr->return_type;
133935-
auto minimum_expr = make_unique<BoundConstantExpression>(Value::CreateValue(min_val));
133936-
vector<unique_ptr<Expression>> arguments;
133937-
arguments.push_back(move(expr));
133938-
arguments.push_back(move(minimum_expr));
133939-
auto minus_expr = make_unique<BoundFunctionExpression>(input_type, SubtractFun::GetFunction(input_type, input_type),
133940-
move(arguments), nullptr, true);
133941-
133942-
// Cast to smaller type
133943-
return make_unique<BoundCastExpression>(move(minus_expr), cast_type);
133940+
return true;
133944133941
}
133945133942

133946133943
template <class T>
@@ -133958,21 +133955,14 @@ unique_ptr<Expression> TemplatedCastToSmallestType(unique_ptr<Expression> expr,
133958133955

133959133956
// Compute range, cast to unsigned to prevent comparing signed with unsigned
133960133957
T signed_range;
133961-
if (!TrySubtractOperator::Operation(signed_min_val, signed_max_val, signed_range)) {
133958+
if (!TrySubtractOperator::Operation(signed_max_val, signed_min_val, signed_range)) {
133962133959
// overflow in subtraction: cannot do any simplification
133963133960
return expr;
133964133961
}
133965-
auto range = static_cast<typename std::make_unsigned<decltype(signed_range)>::type>(signed_range);
133966133962

133967133963
// Check if this range fits in a smaller type
133968133964
LogicalType cast_type;
133969-
if (range < NumericLimits<uint8_t>::Maximum()) {
133970-
cast_type = LogicalType::UTINYINT;
133971-
} else if (sizeof(T) > sizeof(uint16_t) && range < NumericLimits<uint16_t>::Maximum()) {
133972-
cast_type = LogicalType::USMALLINT;
133973-
} else if (sizeof(T) > sizeof(uint32_t) && range < NumericLimits<uint32_t>::Maximum()) {
133974-
cast_type = LogicalType::UINTEGER;
133975-
} else {
133965+
if (!GetCastType(signed_range, cast_type)) {
133976133966
return expr;
133977133967
}
133978133968

@@ -134008,7 +133998,7 @@ unique_ptr<Expression> CastToSmallestType(unique_ptr<Expression> expr, NumericSt
134008133998
case PhysicalType::INT64:
134009133999
return TemplatedCastToSmallestType<int64_t>(move(expr), num_stats);
134010134000
case PhysicalType::INT128:
134011-
return CastHugeintToSmallestType(move(expr), num_stats);
134001+
return TemplatedCastToSmallestType<hugeint_t>(move(expr), num_stats);
134012134002
default:
134013134003
throw NotImplementedException("Unknown integer type!");
134014134004
}
@@ -134976,6 +134966,8 @@ void StatisticsPropagator::PropagateStatistics(LogicalComparisonJoin &join, uniq
134976134966
if (join.conditions.size() > 1) {
134977134967
// there are multiple conditions: erase this condition
134978134968
join.conditions.erase(join.conditions.begin() + i);
134969+
// remove the corresponding statistics
134970+
join.join_stats.clear();
134979134971
i--;
134980134972
continue;
134981134973
} else {
@@ -160505,8 +160497,7 @@ BoundStatement Binder::BindCopyTo(CopyStatement &stmt) {
160505160497
auto copy = make_unique<LogicalCopyToFile>(copy_function->function, move(function_data));
160506160498
copy->file_path = stmt.info->file_path;
160507160499
copy->use_tmp_file = use_tmp_file;
160508-
LocalFileSystem fs;
160509-
copy->is_file_and_exists = fs.FileExists(copy->file_path);
160500+
copy->is_file_and_exists = config.file_system->FileExists(copy->file_path);
160510160501

160511160502
copy->AddChild(move(select_node.plan));
160512160503

@@ -175021,6 +175012,10 @@ DataTable::DataTable(ClientContext &context, DataTable &parent, idx_t removed_co
175021175012
D_ASSERT(removed_column < column_definitions.size());
175022175013
column_definitions.erase(column_definitions.begin() + removed_column);
175023175014

175015+
for (idx_t i = 0; i < column_definitions.size(); i++) {
175016+
column_definitions[i].oid = i;
175017+
}
175018+
175024175019
// alter the row_groups and remove the column from each of them
175025175020
this->row_groups = make_shared<SegmentTree>();
175026175021
auto current_row_group = (RowGroup *)parent.row_groups->GetRootSegment();

libduckdb-sys/duckdb/duckdb.hpp

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
1010

1111
#pragma once
1212
#define DUCKDB_AMALGAMATION 1
13-
#define DUCKDB_SOURCE_ID "fe9ba8003"
14-
#define DUCKDB_VERSION "v0.3.3"
13+
#define DUCKDB_SOURCE_ID "662041e2b"
14+
#define DUCKDB_VERSION "v0.3.4"
1515
//===----------------------------------------------------------------------===//
1616
// DuckDB
1717
//
@@ -2472,6 +2472,13 @@ struct TemplatedValidityMask {
24722472
entry_idx = row_idx / BITS_PER_VALUE;
24732473
idx_in_entry = row_idx % BITS_PER_VALUE;
24742474
}
2475+
//! Get an entry that has first-n bits set as valid and rest set as invalid
2476+
static inline V EntryWithValidBits(idx_t n) {
2477+
if (n == 0) {
2478+
return V(0);
2479+
}
2480+
return ValidityBuffer::MAX_ENTRY >> (BITS_PER_VALUE - n);
2481+
}
24752482

24762483
//! RowIsValidUnsafe should only be used if AllValid() is false: it achieves the same as RowIsValid but skips a
24772484
//! not-null check
@@ -2547,20 +2554,33 @@ struct TemplatedValidityMask {
25472554
}
25482555
}
25492556

2550-
//! Marks "count" entries in the validity mask as invalid (null)
2557+
//! Marks exactly "count" bits in the validity mask as invalid (null)
25512558
inline void SetAllInvalid(idx_t count) {
25522559
EnsureWritable();
2553-
for (idx_t i = 0; i < ValidityBuffer::EntryCount(count); i++) {
2560+
if (count == 0) {
2561+
return;
2562+
}
2563+
auto last_entry_index = ValidityBuffer::EntryCount(count) - 1;
2564+
for (idx_t i = 0; i < last_entry_index; i++) {
25542565
validity_mask[i] = 0;
25552566
}
2567+
auto last_entry_bits = count % static_cast<idx_t>(BITS_PER_VALUE);
2568+
validity_mask[last_entry_index] = (last_entry_bits == 0) ? 0 : (ValidityBuffer::MAX_ENTRY << (last_entry_bits));
25562569
}
25572570

2558-
//! Marks "count" entries in the validity mask as valid (not null)
2571+
//! Marks exactly "count" bits in the validity mask as valid (not null)
25592572
inline void SetAllValid(idx_t count) {
25602573
EnsureWritable();
2561-
for (idx_t i = 0; i < ValidityBuffer::EntryCount(count); i++) {
2574+
if (count == 0) {
2575+
return;
2576+
}
2577+
auto last_entry_index = ValidityBuffer::EntryCount(count) - 1;
2578+
for (idx_t i = 0; i < last_entry_index; i++) {
25622579
validity_mask[i] = ValidityBuffer::MAX_ENTRY;
25632580
}
2581+
auto last_entry_bits = count % static_cast<idx_t>(BITS_PER_VALUE);
2582+
validity_mask[last_entry_index] |=
2583+
(last_entry_bits == 0) ? ValidityBuffer::MAX_ENTRY : ~(ValidityBuffer::MAX_ENTRY << (last_entry_bits));
25642584
}
25652585

25662586
inline bool IsMaskSet() const {

libduckdb-sys/upgrade.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export DUCKDB_LIB_DIR="$SCRIPT_DIR/duckdb"
1010
export DU_INCLUDE_DIR="$DUCKDB_LIB_DIR"
1111

1212
# Download and extract amalgamation
13-
DUCKDB_VERSION=v0.3.3
13+
DUCKDB_VERSION=v0.3.4
1414
wget -T 20 "https://github.com/duckdb/duckdb/releases/download/$DUCKDB_VERSION/libduckdb-src.zip"
1515
unzip -o libduckdb-src.zip -d duckdb
1616
rm -f libduckdb-src.zip

0 commit comments

Comments
 (0)