Skip to content

Commit ce82b1d

Browse files
Update vendored DuckDB sources to 955c3a0
1 parent 955c3a0 commit ce82b1d

32 files changed

+14427
-14059
lines changed

src/duckdb/src/catalog/catalog.cpp

+25-5
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,9 @@ struct CatalogLookup {
328328
CatalogLookup(Catalog &catalog, CatalogType catalog_type, string schema_p, string name_p)
329329
: catalog(catalog), schema(std::move(schema_p)), name(std::move(name_p)), lookup_info(catalog_type, name) {
330330
}
331+
CatalogLookup(Catalog &catalog, string schema_p, const EntryLookupInfo &lookup_p)
332+
: catalog(catalog), schema(std::move(schema_p)), name(lookup_p.GetEntryName()), lookup_info(lookup_p, name) {
333+
}
331334

332335
Catalog &catalog;
333336
string schema;
@@ -757,11 +760,14 @@ CatalogException Catalog::CreateMissingEntryException(CatalogEntryRetriever &ret
757760
did_you_mean = StringUtil::Join(suggestions, " or ");
758761
}
759762

760-
return CatalogException::MissingEntry(type, entry_name, did_you_mean, lookup_info.GetErrorContext());
763+
return CatalogException::MissingEntry(lookup_info, did_you_mean);
761764
}
762765

763766
CatalogEntryLookup Catalog::TryLookupEntryInternal(CatalogTransaction transaction, const string &schema,
764767
const EntryLookupInfo &lookup_info) {
768+
if (lookup_info.GetAtClause() && !SupportsTimeTravel()) {
769+
return {nullptr, nullptr, ErrorData(BinderException("Catalog type does not support time travel"))};
770+
}
765771
auto schema_lookup = EntryLookupInfo::SchemaLookup(lookup_info, schema);
766772
auto schema_entry = LookupSchema(transaction, schema_lookup, OnEntryNotFound::RETURN_NULL);
767773
if (!schema_entry) {
@@ -833,6 +839,8 @@ CatalogEntryLookup Catalog::TryLookupEntry(CatalogEntryRetriever &retriever, con
833839
const EntryLookupInfo &lookup_info, OnEntryNotFound if_not_found) {
834840
auto &context = retriever.GetContext();
835841
reference_set_t<SchemaCatalogEntry> schemas;
842+
bool all_errors = true;
843+
ErrorData error_data;
836844
for (auto &lookup : lookups) {
837845
auto transaction = lookup.catalog.GetCatalogTransaction(context);
838846
auto result = lookup.catalog.TryLookupEntryInternal(transaction, lookup.schema, lookup.lookup_info);
@@ -842,6 +850,14 @@ CatalogEntryLookup Catalog::TryLookupEntry(CatalogEntryRetriever &retriever, con
842850
if (result.schema) {
843851
schemas.insert(*result.schema);
844852
}
853+
if (!result.error.HasError()) {
854+
all_errors = false;
855+
} else {
856+
error_data = std::move(result.error);
857+
}
858+
}
859+
if (all_errors && error_data.HasError()) {
860+
error_data.Throw();
845861
}
846862

847863
if (if_not_found == OnEntryNotFound::RETURN_NULL) {
@@ -916,11 +932,9 @@ CatalogEntryLookup Catalog::TryLookupEntry(CatalogEntryRetriever &retriever, con
916932
D_ASSERT(catalog_entry);
917933
auto lookup_behavior = catalog_entry->CatalogTypeLookupRule(lookup_info.GetCatalogType());
918934
if (lookup_behavior == CatalogLookupBehavior::STANDARD) {
919-
lookups.emplace_back(*catalog_entry, lookup_info.GetCatalogType(), entry.schema,
920-
lookup_info.GetEntryName());
935+
lookups.emplace_back(*catalog_entry, entry.schema, lookup_info);
921936
} else if (lookup_behavior == CatalogLookupBehavior::LOWER_PRIORITY) {
922-
final_lookups.emplace_back(*catalog_entry, lookup_info.GetCatalogType(), entry.schema,
923-
lookup_info.GetEntryName());
937+
final_lookups.emplace_back(*catalog_entry, entry.schema, lookup_info);
924938
}
925939
}
926940

@@ -955,6 +969,12 @@ CatalogEntry &Catalog::GetEntry(ClientContext &context, CatalogType catalog_type
955969
return GetEntry(context, catalog_name, schema_name, lookup_info);
956970
}
957971

972+
optional_ptr<CatalogEntry> Catalog::GetEntry(ClientContext &context, CatalogType catalog_type, const string &schema,
973+
const string &name, OnEntryNotFound if_not_found) {
974+
EntryLookupInfo lookup_info(catalog_type, name);
975+
return GetEntry(context, schema, lookup_info, if_not_found);
976+
}
977+
958978
CatalogEntry &Catalog::GetEntry(ClientContext &context, CatalogType catalog_type, const string &schema_name,
959979
const string &name) {
960980
EntryLookupInfo lookup_info(catalog_type, name);

src/duckdb/src/catalog/catalog_entry/table_catalog_entry.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,11 @@ string TableCatalogEntry::ToSQL() const {
203203
return create_info->ToString();
204204
}
205205

206+
TableFunction TableCatalogEntry::GetScanFunction(ClientContext &context, unique_ptr<FunctionData> &bind_data,
207+
const EntryLookupInfo &lookup_info) {
208+
return GetScanFunction(context, bind_data);
209+
}
210+
206211
const ColumnList &TableCatalogEntry::GetColumns() const {
207212
return columns;
208213
}

src/duckdb/src/catalog/catalog_entry/view_catalog_entry.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,10 @@ string ViewCatalogEntry::ToSQL() const {
100100
return result;
101101
}
102102

103+
const SelectStatement &ViewCatalogEntry::GetQuery() {
104+
return *query;
105+
}
106+
103107
unique_ptr<CatalogEntry> ViewCatalogEntry::Copy(ClientContext &context) const {
104108
D_ASSERT(!internal);
105109
auto create_info = GetInfo();

src/duckdb/src/catalog/catalog_entry_retriever.cpp

+11-1
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,9 @@ optional_ptr<CatalogEntry> CatalogEntryRetriever::GetEntry(const string &catalog
4040
}
4141

4242
optional_ptr<SchemaCatalogEntry> CatalogEntryRetriever::GetSchema(const string &catalog,
43-
const EntryLookupInfo &schema_lookup,
43+
const EntryLookupInfo &schema_lookup_p,
4444
OnEntryNotFound on_entry_not_found) {
45+
EntryLookupInfo schema_lookup(schema_lookup_p, at_clause);
4546
auto result = Catalog::GetSchema(*this, catalog, schema_lookup, on_entry_not_found);
4647
if (!result) {
4748
return result;
@@ -73,6 +74,7 @@ optional_ptr<CatalogEntry> CatalogEntryRetriever::ReturnAndCallback(optional_ptr
7374
void CatalogEntryRetriever::Inherit(const CatalogEntryRetriever &parent) {
7475
this->callback = parent.callback;
7576
this->search_path = parent.search_path;
77+
this->at_clause = parent.at_clause;
7678
}
7779

7880
const CatalogSearchPath &CatalogEntryRetriever::GetSearchPath() const {
@@ -107,6 +109,14 @@ void CatalogEntryRetriever::SetSearchPath(vector<CatalogSearchEntry> entries) {
107109
this->search_path = make_shared_ptr<CatalogSearchPath>(context, std::move(new_path));
108110
}
109111

112+
optional_ptr<BoundAtClause> CatalogEntryRetriever::GetAtClause() const {
113+
return at_clause;
114+
}
115+
116+
void CatalogEntryRetriever::SetAtClause(optional_ptr<BoundAtClause> at_clause_p) {
117+
at_clause = at_clause_p;
118+
}
119+
110120
void CatalogEntryRetriever::SetCallback(catalog_entry_callback_t callback) {
111121
this->callback = std::move(callback);
112122
}

src/duckdb/src/catalog/entry_lookup_info.cpp

+23
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,25 @@ EntryLookupInfo::EntryLookupInfo(CatalogType catalog_type_p, const string &name_
66
: catalog_type(catalog_type_p), name(name_p), error_context(error_context_p) {
77
}
88

9+
EntryLookupInfo::EntryLookupInfo(CatalogType catalog_type_p, const string &name_p,
10+
optional_ptr<BoundAtClause> at_clause_p, QueryErrorContext error_context_p)
11+
: catalog_type(catalog_type_p), name(name_p), at_clause(at_clause_p), error_context(error_context_p) {
12+
}
13+
14+
EntryLookupInfo::EntryLookupInfo(const EntryLookupInfo &parent, const string &name_p)
15+
: catalog_type(parent.catalog_type), name(name_p), at_clause(parent.at_clause),
16+
error_context(parent.error_context) {
17+
}
18+
19+
EntryLookupInfo::EntryLookupInfo(const EntryLookupInfo &parent, optional_ptr<BoundAtClause> at_clause)
20+
: EntryLookupInfo(parent.catalog_type, parent.name, parent.at_clause ? parent.at_clause : at_clause,
21+
parent.error_context) {
22+
}
23+
24+
EntryLookupInfo EntryLookupInfo::SchemaLookup(const EntryLookupInfo &parent, const string &schema_name) {
25+
return EntryLookupInfo(CatalogType::SCHEMA_ENTRY, schema_name, parent.at_clause, parent.error_context);
26+
}
27+
928
CatalogType EntryLookupInfo::GetCatalogType() const {
1029
return catalog_type;
1130
}
@@ -18,4 +37,8 @@ const QueryErrorContext &EntryLookupInfo::GetErrorContext() const {
1837
return error_context;
1938
}
2039

40+
const optional_ptr<BoundAtClause> EntryLookupInfo::GetAtClause() const {
41+
return at_clause;
42+
}
43+
2144
} // namespace duckdb

src/duckdb/src/common/exception/catalog_exception.cpp

+21-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#include "duckdb/common/exception/catalog_exception.hpp"
22
#include "duckdb/common/to_string.hpp"
33
#include "duckdb/common/string_util.hpp"
4+
#include "duckdb/catalog/entry_lookup_info.hpp"
5+
#include "duckdb/planner/tableref/bound_at_clause.hpp"
46

57
namespace duckdb {
68

@@ -11,12 +13,20 @@ CatalogException::CatalogException(const string &msg, const unordered_map<string
1113
: Exception(ExceptionType::CATALOG, msg, extra_info) {
1214
}
1315

14-
CatalogException CatalogException::MissingEntry(CatalogType type, const string &name, const string &suggestion,
15-
QueryErrorContext context) {
16+
CatalogException CatalogException::MissingEntry(const EntryLookupInfo &lookup_info, const string &suggestion) {
17+
auto type = lookup_info.GetCatalogType();
18+
auto context = lookup_info.GetErrorContext();
19+
auto &name = lookup_info.GetEntryName();
20+
auto at_clause = lookup_info.GetAtClause();
21+
1622
string did_you_mean;
1723
if (!suggestion.empty()) {
1824
did_you_mean = "\nDid you mean \"" + suggestion + "\"?";
1925
}
26+
string version_info;
27+
if (at_clause) {
28+
version_info += " at " + StringUtil::Lower(at_clause->Unit()) + " " + at_clause->GetValue().ToString();
29+
}
2030

2131
auto extra_info = Exception::InitializeExtraInfo("MISSING_ENTRY", context.query_location);
2232

@@ -25,9 +35,15 @@ CatalogException CatalogException::MissingEntry(CatalogType type, const string &
2535
if (!suggestion.empty()) {
2636
extra_info["candidates"] = suggestion;
2737
}
28-
return CatalogException(
29-
StringUtil::Format("%s with name %s does not exist!%s", CatalogTypeToString(type), name, did_you_mean),
30-
extra_info);
38+
return CatalogException(StringUtil::Format("%s with name %s does not exist%s!%s", CatalogTypeToString(type), name,
39+
version_info, did_you_mean),
40+
extra_info);
41+
}
42+
43+
CatalogException CatalogException::MissingEntry(CatalogType type, const string &name, const string &suggestion,
44+
QueryErrorContext context) {
45+
EntryLookupInfo lookup_info(type, name, context);
46+
return MissingEntry(lookup_info, suggestion);
3147
}
3248

3349
CatalogException CatalogException::MissingEntry(const string &type, const string &name,

src/duckdb/src/execution/physical_plan/plan_create_table.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ PhysicalOperator &DuckCatalog::PlanCreateTableAs(ClientContext &context, Physica
3737
PhysicalOperator &PhysicalPlanGenerator::CreatePlan(LogicalCreateTable &op) {
3838
const auto &create_info = op.info->base->Cast<CreateTableInfo>();
3939
auto &catalog = op.info->schema.catalog;
40-
auto existing_entry = catalog.GetEntry<TableCatalogEntry>(context, create_info.schema, create_info.table,
41-
OnEntryNotFound::RETURN_NULL);
40+
auto existing_entry = catalog.GetEntry(context, CatalogType::TABLE_ENTRY, create_info.schema, create_info.table,
41+
OnEntryNotFound::RETURN_NULL);
4242
bool replace = op.info->Base().on_conflict == OnCreateConflict::REPLACE_ON_CONFLICT;
4343
if ((!existing_entry || replace) && !op.children.empty()) {
4444
auto &plan = CreatePlan(*op.children[0]);

src/duckdb/src/function/table/version/pragma_version.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#ifndef DUCKDB_PATCH_VERSION
2-
#define DUCKDB_PATCH_VERSION "0-dev1710"
2+
#define DUCKDB_PATCH_VERSION "0-dev1738"
33
#endif
44
#ifndef DUCKDB_MINOR_VERSION
55
#define DUCKDB_MINOR_VERSION 3
@@ -8,10 +8,10 @@
88
#define DUCKDB_MAJOR_VERSION 1
99
#endif
1010
#ifndef DUCKDB_VERSION
11-
#define DUCKDB_VERSION "v1.3.0-dev1710"
11+
#define DUCKDB_VERSION "v1.3.0-dev1738"
1212
#endif
1313
#ifndef DUCKDB_SOURCE_ID
14-
#define DUCKDB_SOURCE_ID "43c5f34898"
14+
#define DUCKDB_SOURCE_ID "dc4bb03fd1"
1515
#endif
1616
#include "duckdb/function/table/system_functions.hpp"
1717
#include "duckdb/main/database.hpp"

src/duckdb/src/include/duckdb/catalog/catalog.hpp

+6
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,9 @@ class Catalog {
239239
//! Gets the "schema.name" entry of the specified type, if entry does not exist behavior depends on OnEntryNotFound
240240
DUCKDB_API optional_ptr<CatalogEntry> GetEntry(ClientContext &context, const string &schema,
241241
const EntryLookupInfo &lookup_info, OnEntryNotFound if_not_found);
242+
DUCKDB_API optional_ptr<CatalogEntry> GetEntry(ClientContext &context, CatalogType catalog_type,
243+
const string &schema, const string &name,
244+
OnEntryNotFound if_not_found);
242245
DUCKDB_API optional_ptr<CatalogEntry> GetEntry(CatalogEntryRetriever &retriever, const string &schema,
243246
const EntryLookupInfo &lookup_info, OnEntryNotFound if_not_found);
244247
DUCKDB_API CatalogEntry &GetEntry(ClientContext &context, const string &schema, const EntryLookupInfo &lookup_info);
@@ -308,6 +311,9 @@ class Catalog {
308311

309312
virtual bool InMemory() = 0;
310313
virtual string GetDBPath() = 0;
314+
virtual bool SupportsTimeTravel() const {
315+
return false;
316+
}
311317

312318
//! Whether or not this catalog should search a specific type with the standard priority
313319
DUCKDB_API virtual CatalogLookupBehavior CatalogTypeLookupRule(CatalogType type) const {

src/duckdb/src/include/duckdb/catalog/catalog_entry/table_catalog_entry.hpp

+3
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ struct BoundCreateTableInfo;
3838

3939
class TableFunction;
4040
struct FunctionData;
41+
struct EntryLookupInfo;
4142

4243
class Binder;
4344
struct ColumnSegmentInfo;
@@ -94,6 +95,8 @@ class TableCatalogEntry : public StandardEntry {
9495

9596
//! Returns the scan function that can be used to scan the given table
9697
virtual TableFunction GetScanFunction(ClientContext &context, unique_ptr<FunctionData> &bind_data) = 0;
98+
virtual TableFunction GetScanFunction(ClientContext &context, unique_ptr<FunctionData> &bind_data,
99+
const EntryLookupInfo &lookup_info);
97100

98101
virtual bool IsDuckTable() const {
99102
return false;

src/duckdb/src/include/duckdb/catalog/catalog_entry/view_catalog_entry.hpp

+7
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,13 @@ class ViewCatalogEntry : public StandardEntry {
4848

4949
unique_ptr<CatalogEntry> Copy(ClientContext &context) const override;
5050

51+
virtual const SelectStatement &GetQuery();
52+
53+
virtual bool HasTypes() const {
54+
// Whether or not the view has types/names defined
55+
return true;
56+
}
57+
5158
string ToSQL() const override;
5259

5360
private:

src/duckdb/src/include/duckdb/catalog/catalog_entry_retriever.hpp

+4
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ class CatalogEntryRetriever {
5959
void SetCallback(catalog_entry_callback_t callback);
6060
catalog_entry_callback_t GetCallback();
6161

62+
optional_ptr<BoundAtClause> GetAtClause() const;
63+
void SetAtClause(optional_ptr<BoundAtClause> at_clause);
64+
6265
private:
6366
optional_ptr<CatalogEntry> ReturnAndCallback(optional_ptr<CatalogEntry> result);
6467

@@ -67,6 +70,7 @@ class CatalogEntryRetriever {
6770
catalog_entry_callback_t callback = nullptr;
6871
ClientContext &context;
6972
shared_ptr<CatalogSearchPath> search_path;
73+
optional_ptr<BoundAtClause> at_clause;
7074
};
7175

7276
} // namespace duckdb

src/duckdb/src/include/duckdb/catalog/entry_lookup_info.hpp

+8-3
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,29 @@
1313
#include "duckdb/parser/query_error_context.hpp"
1414

1515
namespace duckdb {
16+
class BoundAtClause;
1617

1718
struct EntryLookupInfo {
1819
public:
1920
EntryLookupInfo(CatalogType catalog_type, const string &name,
2021
QueryErrorContext error_context = QueryErrorContext());
22+
EntryLookupInfo(CatalogType catalog_type, const string &name, optional_ptr<BoundAtClause> at_clause,
23+
QueryErrorContext error_context);
24+
EntryLookupInfo(const EntryLookupInfo &parent, const string &name);
25+
EntryLookupInfo(const EntryLookupInfo &parent, optional_ptr<BoundAtClause> at_clause);
2126

2227
public:
2328
CatalogType GetCatalogType() const;
2429
const string &GetEntryName() const;
2530
const QueryErrorContext &GetErrorContext() const;
31+
const optional_ptr<BoundAtClause> GetAtClause() const;
2632

27-
static EntryLookupInfo SchemaLookup(const EntryLookupInfo &parent, const string &schema_name) {
28-
return EntryLookupInfo(CatalogType::SCHEMA_ENTRY, schema_name, parent.error_context);
29-
}
33+
static EntryLookupInfo SchemaLookup(const EntryLookupInfo &parent, const string &schema_name);
3034

3135
private:
3236
CatalogType catalog_type;
3337
const string &name;
38+
optional_ptr<BoundAtClause> at_clause;
3439
QueryErrorContext error_context;
3540
};
3641

src/duckdb/src/include/duckdb/common/exception/catalog_exception.hpp

+2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "duckdb/common/unordered_map.hpp"
1515

1616
namespace duckdb {
17+
struct EntryLookupInfo;
1718

1819
class CatalogException : public Exception {
1920
public:
@@ -28,6 +29,7 @@ class CatalogException : public Exception {
2829
: CatalogException(ConstructMessage(msg, params...), Exception::InitializeExtraInfo(error_context)) {
2930
}
3031

32+
static CatalogException MissingEntry(const EntryLookupInfo &lookup_info, const string &suggestion);
3133
static CatalogException MissingEntry(CatalogType type, const string &name, const string &suggestion,
3234
QueryErrorContext context = QueryErrorContext());
3335
static CatalogException MissingEntry(const string &type, const string &name, const vector<string> &suggestions,

src/duckdb/src/include/duckdb/parser/tableref.hpp

+6-2
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,6 @@ class TableRef {
4141
public:
4242
//! Convert the object to a string
4343
virtual string ToString() const = 0;
44-
string BaseToString(string result) const;
45-
string BaseToString(string result, const vector<string> &column_name_alias) const;
4644
void Print();
4745

4846
virtual bool Equals(const TableRef &other) const;
@@ -72,5 +70,11 @@ class TableRef {
7270
}
7371
return reinterpret_cast<const TARGET &>(*this);
7472
}
73+
74+
protected:
75+
string BaseToString(string result) const;
76+
string BaseToString(string result, const vector<string> &column_name_alias) const;
77+
string AliasToString(const vector<string> &column_name_alias) const;
78+
string SampleToString() const;
7579
};
7680
} // namespace duckdb

0 commit comments

Comments
 (0)