Skip to content

Commit

Permalink
chore: Update vendored sources to duckdb/duckdb@2414840
Browse files Browse the repository at this point in the history
Merge pull request duckdb/duckdb#10005 from Tishj/python3_7_optional_issue
Merge pull request duckdb/duckdb#9974 from taniabogatsch/duplicate-lambda-parameters
Merge pull request duckdb/duckdb#9999 from Mytherin/parallelcheckpoint
Merge pull request duckdb/duckdb#9973 from xuke-hat/refine-iejoin
Merge pull request duckdb/duckdb#9984 from hawkfish/tsns-time
Merge pull request duckdb/duckdb#9977 from atacan/swift-readme
  • Loading branch information
krlmlr committed Dec 15, 2023
1 parent e0f233f commit 1284057
Show file tree
Hide file tree
Showing 26 changed files with 489 additions and 175 deletions.
6 changes: 3 additions & 3 deletions src/duckdb/src/catalog/default/default_functions.cpp
Expand Up @@ -105,14 +105,14 @@ static DefaultMacro internal_macros[] = {
{DEFAULT_SCHEMA, "array_reverse", {"l", nullptr}, "list_reverse(l)"},

// FIXME implement as actual function if we encounter a lot of performance issues. Complexity now: n * m, with hashing possibly n + m
{DEFAULT_SCHEMA, "list_intersect", {"l1", "l2", nullptr}, "list_filter(list_distinct(l1), (x) -> list_contains(l2, x))"},
{DEFAULT_SCHEMA, "list_intersect", {"l1", "l2", nullptr}, "list_filter(list_distinct(l1), (variable_intersect) -> list_contains(l2, variable_intersect))"},
{DEFAULT_SCHEMA, "array_intersect", {"l1", "l2", nullptr}, "list_intersect(l1, l2)"},

{DEFAULT_SCHEMA, "list_has_any", {"l1", "l2", nullptr}, "CASE WHEN l1 IS NULL THEN NULL WHEN l2 IS NULL THEN NULL WHEN len(list_filter(l1, (x) -> list_contains(l2, x))) > 0 THEN true ELSE false END"},
{DEFAULT_SCHEMA, "list_has_any", {"l1", "l2", nullptr}, "CASE WHEN l1 IS NULL THEN NULL WHEN l2 IS NULL THEN NULL WHEN len(list_filter(l1, (variable_has_any) -> list_contains(l2, variable_has_any))) > 0 THEN true ELSE false END"},
{DEFAULT_SCHEMA, "array_has_any", {"l1", "l2", nullptr}, "list_has_any(l1, l2)" },
{DEFAULT_SCHEMA, "&&", {"l1", "l2", nullptr}, "list_has_any(l1, l2)" }, // "&&" is the operator for "list_has_any

{DEFAULT_SCHEMA, "list_has_all", {"l1", "l2", nullptr}, "CASE WHEN l1 IS NULL THEN NULL WHEN l2 IS NULL THEN NULL WHEN len(list_filter(l2, (x) -> list_contains(l1, x))) = len(list_filter(l2, x -> x IS NOT NULL)) THEN true ELSE false END"},
{DEFAULT_SCHEMA, "list_has_all", {"l1", "l2", nullptr}, "CASE WHEN l1 IS NULL THEN NULL WHEN l2 IS NULL THEN NULL WHEN len(list_filter(l2, (variable_has_all) -> list_contains(l1, variable_has_all))) = len(list_filter(l2, variable_has_all -> variable_has_all IS NOT NULL)) THEN true ELSE false END"},
{DEFAULT_SCHEMA, "array_has_all", {"l1", "l2", nullptr}, "list_has_all(l1, l2)" },
{DEFAULT_SCHEMA, "@>", {"l1", "l2", nullptr}, "list_has_all(l1, l2)" }, // "@>" is the operator for "list_has_all
{DEFAULT_SCHEMA, "<@", {"l1", "l2", nullptr}, "list_has_all(l2, l1)" }, // "<@" is the operator for "list_has_all
Expand Down
17 changes: 17 additions & 0 deletions src/duckdb/src/common/operator/cast_operators.cpp
Expand Up @@ -1489,6 +1489,11 @@ date_t CastTimestampMsToDate::Operation(timestamp_t input) {
return Timestamp::GetDate(Timestamp::FromEpochMs(input.value));
}

template <>
dtime_t CastTimestampMsToTime::Operation(timestamp_t input) {
return Timestamp::GetTime(Timestamp::FromEpochMs(input.value));
}

template <>
timestamp_t CastTimestampMsToNs::Operation(timestamp_t input) {
auto us = CastTimestampMsToUs::Operation<timestamp_t, timestamp_t>(input);
Expand All @@ -1506,6 +1511,12 @@ date_t CastTimestampNsToDate::Operation(timestamp_t input) {
return Timestamp::GetDate(us);
}

template <>
dtime_t CastTimestampNsToTime::Operation(timestamp_t input) {
const auto us = CastTimestampNsToUs::Operation<timestamp_t, timestamp_t>(input);
return Timestamp::GetTime(us);
}

template <>
timestamp_t CastTimestampSecToMs::Operation(timestamp_t input) {
auto us = CastTimestampSecToUs::Operation<timestamp_t, timestamp_t>(input);
Expand All @@ -1529,6 +1540,12 @@ date_t CastTimestampSecToDate::Operation(timestamp_t input) {
return Timestamp::GetDate(us);
}

template <>
dtime_t CastTimestampSecToTime::Operation(timestamp_t input) {
const auto us = CastTimestampSecToUs::Operation<timestamp_t, timestamp_t>(input);
return Timestamp::GetTime(us);
}

//===--------------------------------------------------------------------===//
// Cast To Timestamp
//===--------------------------------------------------------------------===//
Expand Down
33 changes: 15 additions & 18 deletions src/duckdb/src/execution/operator/join/physical_iejoin.cpp
Expand Up @@ -24,8 +24,6 @@ PhysicalIEJoin::PhysicalIEJoin(LogicalComparisonJoin &op, unique_ptr<PhysicalOpe

// 1. let L1 (resp. L2) be the array of column X (resp. Y)
D_ASSERT(conditions.size() >= 2);
lhs_orders.resize(2);
rhs_orders.resize(2);
for (idx_t i = 0; i < 2; ++i) {
auto &cond = conditions[i];
D_ASSERT(cond.left->return_type == cond.right->return_type);
Expand All @@ -52,8 +50,8 @@ PhysicalIEJoin::PhysicalIEJoin(LogicalComparisonJoin &op, unique_ptr<PhysicalOpe
default:
throw NotImplementedException("Unimplemented join type for IEJoin");
}
lhs_orders[i].emplace_back(BoundOrderByNode(sense, OrderByNullType::NULLS_LAST, std::move(left)));
rhs_orders[i].emplace_back(BoundOrderByNode(sense, OrderByNullType::NULLS_LAST, std::move(right)));
lhs_orders.emplace_back(sense, OrderByNullType::NULLS_LAST, std::move(left));
rhs_orders.emplace_back(sense, OrderByNullType::NULLS_LAST, std::move(right));
}

for (idx_t i = 2; i < conditions.size(); ++i) {
Expand Down Expand Up @@ -88,13 +86,13 @@ class IEJoinGlobalState : public GlobalSinkState {
RowLayout lhs_layout;
lhs_layout.Initialize(op.children[0]->types);
vector<BoundOrderByNode> lhs_order;
lhs_order.emplace_back(op.lhs_orders[0][0].Copy());
lhs_order.emplace_back(op.lhs_orders[0].Copy());
tables[0] = make_uniq<GlobalSortedTable>(context, lhs_order, lhs_layout);

RowLayout rhs_layout;
rhs_layout.Initialize(op.children[1]->types);
vector<BoundOrderByNode> rhs_order;
rhs_order.emplace_back(op.rhs_orders[0][0].Copy());
rhs_order.emplace_back(op.rhs_orders[0].Copy());
tables[1] = make_uniq<GlobalSortedTable>(context, rhs_order, rhs_layout);
}

Expand Down Expand Up @@ -369,8 +367,8 @@ IEJoinUnion::IEJoinUnion(ClientContext &context, const PhysicalIEJoin &op, Sorte
}

// 1. let L1 (resp. L2) be the array of column X (resp. Y )
const auto &order1 = op.lhs_orders[0][0];
const auto &order2 = op.lhs_orders[1][0];
const auto &order1 = op.lhs_orders[0];
const auto &order2 = op.lhs_orders[1];

// 2. if (op1 ∈ {>, ≥}) sort L1 in descending order
// 3. else if (op1 ∈ {<, ≤}) sort L1 in ascending order
Expand Down Expand Up @@ -399,8 +397,8 @@ IEJoinUnion::IEJoinUnion(ClientContext &context, const PhysicalIEJoin &op, Sorte

// RHS has negative rids
ExpressionExecutor r_executor(context);
r_executor.AddExpression(*op.rhs_orders[0][0].expression);
r_executor.AddExpression(*op.rhs_orders[1][0].expression);
r_executor.AddExpression(*op.rhs_orders[0].expression);
r_executor.AddExpression(*op.rhs_orders[1].expression);
AppendKey(t2, r_executor, *l1, -1, -1, b2);

if (l1->global_sort_state.sorted_blocks.empty()) {
Expand Down Expand Up @@ -616,15 +614,14 @@ idx_t IEJoinUnion::JoinComplexBlocks(SelectionVector &lsel, SelectionVector &rse
const auto rrid = li[j];
++j;

D_ASSERT(lrid > 0 && rrid < 0);
// 15. add tuples w.r.t. (L1[j], L1[i]) to join result
if (lrid > 0 && rrid < 0) {
lsel.set_index(result_count, sel_t(+lrid - 1));
rsel.set_index(result_count, sel_t(-rrid - 1));
++result_count;
if (result_count == STANDARD_VECTOR_SIZE) {
// out of space!
return result_count;
}
lsel.set_index(result_count, sel_t(+lrid - 1));
rsel.set_index(result_count, sel_t(-rrid - 1));
++result_count;
if (result_count == STANDARD_VECTOR_SIZE) {
// out of space!
return result_count;
}
}
++i;
Expand Down
Expand Up @@ -112,15 +112,16 @@ class BatchInsertGlobalState : public GlobalSinkState {
static constexpr const idx_t BATCH_FLUSH_THRESHOLD = LocalStorage::MERGE_THRESHOLD * 3;

public:
explicit BatchInsertGlobalState(DuckTableEntry &table) : table(table), insert_count(0) {
explicit BatchInsertGlobalState(DuckTableEntry &table)
: table(table), insert_count(0), optimistically_written(false) {
}

mutex lock;
DuckTableEntry &table;
idx_t insert_count;
vector<RowGroupBatchEntry> collections;
idx_t next_start = 0;
bool optimistically_written = false;
atomic<bool> optimistically_written;

void FindMergeCollections(idx_t min_batch_index, optional_idx &merged_batch_index,
vector<unique_ptr<RowGroupCollection>> &result) {
Expand Down
12 changes: 12 additions & 0 deletions src/duckdb/src/function/cast/time_casts.cpp
Expand Up @@ -117,6 +117,10 @@ BoundCastInfo DefaultCasts::TimestampNsCastSwitch(BindCastInput &input, const Lo
case LogicalTypeId::DATE:
// timestamp (ns) to date
return BoundCastInfo(&VectorCastHelpers::TemplatedCastLoop<timestamp_t, date_t, duckdb::CastTimestampNsToDate>);
case LogicalTypeId::TIME:
// timestamp (ns) to time
return BoundCastInfo(
&VectorCastHelpers::TemplatedCastLoop<timestamp_t, dtime_t, duckdb::CastTimestampNsToTime>);
case LogicalTypeId::TIMESTAMP:
// timestamp (ns) to timestamp (us)
return BoundCastInfo(
Expand All @@ -136,6 +140,10 @@ BoundCastInfo DefaultCasts::TimestampMsCastSwitch(BindCastInput &input, const Lo
case LogicalTypeId::DATE:
// timestamp (ms) to date
return BoundCastInfo(&VectorCastHelpers::TemplatedCastLoop<timestamp_t, date_t, duckdb::CastTimestampMsToDate>);
case LogicalTypeId::TIME:
// timestamp (ms) to time
return BoundCastInfo(
&VectorCastHelpers::TemplatedCastLoop<timestamp_t, dtime_t, duckdb::CastTimestampMsToTime>);
case LogicalTypeId::TIMESTAMP:
// timestamp (ms) to timestamp (us)
return BoundCastInfo(
Expand All @@ -160,6 +168,10 @@ BoundCastInfo DefaultCasts::TimestampSecCastSwitch(BindCastInput &input, const L
// timestamp (s) to date
return BoundCastInfo(
&VectorCastHelpers::TemplatedCastLoop<timestamp_t, date_t, duckdb::CastTimestampSecToDate>);
case LogicalTypeId::TIME:
// timestamp (s) to time
return BoundCastInfo(
&VectorCastHelpers::TemplatedCastLoop<timestamp_t, dtime_t, duckdb::CastTimestampSecToTime>);
case LogicalTypeId::TIMESTAMP_MS:
// timestamp (s) to timestamp (ms)
return BoundCastInfo(
Expand Down
4 changes: 2 additions & 2 deletions src/duckdb/src/function/table/version/pragma_version.cpp
@@ -1,8 +1,8 @@
#ifndef DUCKDB_VERSION
#define DUCKDB_VERSION "v0.9.3-dev1538"
#define DUCKDB_VERSION "v0.9.3-dev1565"
#endif
#ifndef DUCKDB_SOURCE_ID
#define DUCKDB_SOURCE_ID "d51e1b06fa"
#define DUCKDB_SOURCE_ID "2414840843"
#endif
#include "duckdb/function/table/system_functions.hpp"
#include "duckdb/main/database.hpp"
Expand Down
25 changes: 25 additions & 0 deletions src/duckdb/src/include/duckdb/common/operator/cast_operators.hpp
Expand Up @@ -632,6 +632,13 @@ struct CastTimestampMsToDate {
}
};

struct CastTimestampMsToTime {
template <class SRC, class DST>
static inline DST Operation(SRC input) {
throw duckdb::NotImplementedException("Cast to TIME could not be performed!");
}
};

struct CastTimestampMsToUs {
template <class SRC, class DST>
static inline DST Operation(SRC input) {
Expand All @@ -652,6 +659,12 @@ struct CastTimestampNsToDate {
throw duckdb::NotImplementedException("Cast to DATE could not be performed!");
}
};
struct CastTimestampNsToTime {
template <class SRC, class DST>
static inline DST Operation(SRC input) {
throw duckdb::NotImplementedException("Cast to TIME could not be performed!");
}
};
struct CastTimestampNsToUs {
template <class SRC, class DST>
static inline DST Operation(SRC input) {
Expand All @@ -665,6 +678,12 @@ struct CastTimestampSecToDate {
throw duckdb::NotImplementedException("Cast to DATE could not be performed!");
}
};
struct CastTimestampSecToTime {
template <class SRC, class DST>
static inline DST Operation(SRC input) {
throw duckdb::NotImplementedException("Cast to TIME could not be performed!");
}
};
struct CastTimestampSecToMs {
template <class SRC, class DST>
static inline DST Operation(SRC input) {
Expand Down Expand Up @@ -695,16 +714,22 @@ duckdb::timestamp_t CastTimestampUsToNs::Operation(duckdb::timestamp_t input);
template <>
duckdb::date_t CastTimestampMsToDate::Operation(duckdb::timestamp_t input);
template <>
duckdb::dtime_t CastTimestampMsToTime::Operation(duckdb::timestamp_t input);
template <>
duckdb::timestamp_t CastTimestampMsToUs::Operation(duckdb::timestamp_t input);
template <>
duckdb::timestamp_t CastTimestampMsToNs::Operation(duckdb::timestamp_t input);
template <>
duckdb::date_t CastTimestampNsToDate::Operation(duckdb::timestamp_t input);
template <>
duckdb::dtime_t CastTimestampNsToTime::Operation(duckdb::timestamp_t input);
template <>
duckdb::timestamp_t CastTimestampNsToUs::Operation(duckdb::timestamp_t input);
template <>
duckdb::date_t CastTimestampSecToDate::Operation(duckdb::timestamp_t input);
template <>
duckdb::dtime_t CastTimestampSecToTime::Operation(duckdb::timestamp_t input);
template <>
duckdb::timestamp_t CastTimestampSecToMs::Operation(duckdb::timestamp_t input);
template <>
duckdb::timestamp_t CastTimestampSecToUs::Operation(duckdb::timestamp_t input);
Expand Down
6 changes: 3 additions & 3 deletions src/duckdb/src/include/duckdb/execution/executor.hpp
Expand Up @@ -14,6 +14,7 @@
#include "duckdb/common/pair.hpp"
#include "duckdb/common/reference_map.hpp"
#include "duckdb/parallel/pipeline.hpp"
#include "duckdb/execution/task_error_manager.hpp"

namespace duckdb {
class ClientContext;
Expand Down Expand Up @@ -123,7 +124,6 @@ class Executor {
unique_ptr<PhysicalOperator> owned_plan;

mutex executor_lock;
mutex error_lock;
//! All pipelines of the query plan
vector<shared_ptr<Pipeline>> pipelines;
//! The root pipelines of the query
Expand All @@ -138,12 +138,12 @@ class Executor {
idx_t root_pipeline_idx;
//! The producer of this query
unique_ptr<ProducerToken> producer;
//! Exceptions that occurred during the execution of the current query
vector<PreservedError> exceptions;
//! List of events
vector<shared_ptr<Event>> events;
//! The query profiler
shared_ptr<QueryProfiler> profiler;
//! Task error manager
TaskErrorManager error_manager;

//! The amount of completed pipelines of the query
atomic<idx_t> completed_pipelines;
Expand Down
Expand Up @@ -24,8 +24,8 @@ class PhysicalIEJoin : public PhysicalRangeJoin {
vector<JoinCondition> cond, JoinType join_type, idx_t estimated_cardinality);

vector<LogicalType> join_key_types;
vector<vector<BoundOrderByNode>> lhs_orders;
vector<vector<BoundOrderByNode>> rhs_orders;
vector<BoundOrderByNode> lhs_orders;
vector<BoundOrderByNode> rhs_orders;

public:
// CachingOperator Interface
Expand Down
46 changes: 46 additions & 0 deletions src/duckdb/src/include/duckdb/execution/task_error_manager.hpp
@@ -0,0 +1,46 @@
//===----------------------------------------------------------------------===//
// DuckDB
//
// duckdb/execution/task_error_manager.hpp
//
//
//===----------------------------------------------------------------------===//

#pragma once

#include "duckdb/common/preserved_error.hpp"
#include "duckdb/common/mutex.hpp"
#include "duckdb/common/vector.hpp"

namespace duckdb {

class TaskErrorManager {
public:
void PushError(PreservedError error) {
lock_guard<mutex> elock(error_lock);
this->exceptions.push_back(std::move(error));
}

bool HasError() {
lock_guard<mutex> elock(error_lock);
return !exceptions.empty();
}

void ThrowException() {
lock_guard<mutex> elock(error_lock);
D_ASSERT(!exceptions.empty());
auto &entry = exceptions[0];
entry.Throw();
}

void Reset() {
lock_guard<mutex> elock(error_lock);
exceptions.clear();
}

private:
mutex error_lock;
//! Exceptions that occurred during the execution of the current query
vector<PreservedError> exceptions;
};
} // namespace duckdb
Expand Up @@ -34,9 +34,6 @@ class RowGroupWriter {

virtual MetadataWriter &GetPayloadWriter() = 0;

void RegisterPartialBlock(PartialBlockAllocation &&allocation);
PartialBlockAllocation GetBlockAllocation(uint32_t segment_size);

PartialBlockManager &GetPartialBlockManager() {
return partial_block_manager;
}
Expand Down
Expand Up @@ -36,6 +36,8 @@ class TableDataWriter {

virtual void AddRowGroup(RowGroupPointer &&row_group_pointer, unique_ptr<RowGroupWriter> &&writer);

TaskScheduler &GetScheduler();

protected:
DuckTableEntry &table;
//! Pointers to the start of each row group.
Expand Down

0 comments on commit 1284057

Please sign in to comment.