Skip to content

Commit

Permalink
chore: Update vendored sources to duckdb/duckdb@1c832c2
Browse files Browse the repository at this point in the history
Merge pull request duckdb/duckdb#12081 from Maxxen/type-metadata-redux
Merge pull request duckdb/duckdb#11914 from cpcloud/run-pyodide-tests
  • Loading branch information
krlmlr committed May 17, 2024
1 parent 584f351 commit c688bb8
Show file tree
Hide file tree
Showing 19 changed files with 421 additions and 127 deletions.
15 changes: 0 additions & 15 deletions src/duckdb/src/catalog/catalog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -826,21 +826,6 @@ optional_ptr<SchemaCatalogEntry> Catalog::GetSchema(ClientContext &context, cons
return nullptr;
}

LogicalType Catalog::GetType(ClientContext &context, const string &schema, const string &name,
OnEntryNotFound if_not_found) {
auto type_entry = GetEntry<TypeCatalogEntry>(context, schema, name, if_not_found);
if (!type_entry) {
return LogicalType::INVALID;
}
return type_entry->user_type;
}

LogicalType Catalog::GetType(ClientContext &context, const string &catalog_name, const string &schema,
const string &name) {
auto &type_entry = Catalog::GetEntry<TypeCatalogEntry>(context, catalog_name, schema, name);
return type_entry.user_type;
}

vector<reference<SchemaCatalogEntry>> Catalog::GetSchemas(ClientContext &context) {
vector<reference<SchemaCatalogEntry>> schemas;
ScanSchemas(context, [&](SchemaCatalogEntry &entry) { schemas.push_back(entry); });
Expand Down
4 changes: 3 additions & 1 deletion src/duckdb/src/catalog/catalog_entry/type_catalog_entry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
namespace duckdb {

TypeCatalogEntry::TypeCatalogEntry(Catalog &catalog, SchemaCatalogEntry &schema, CreateTypeInfo &info)
: StandardEntry(CatalogType::TYPE_ENTRY, schema, catalog, info.name), user_type(info.type) {
: StandardEntry(CatalogType::TYPE_ENTRY, schema, catalog, info.name), user_type(info.type),
bind_modifiers(info.bind_modifiers) {
this->temporary = info.temporary;
this->internal = info.internal;
this->dependencies = info.dependencies;
Expand All @@ -34,6 +35,7 @@ unique_ptr<CreateInfo> TypeCatalogEntry::GetInfo() const {
result->dependencies = dependencies;
result->comment = comment;
result->tags = tags;
result->bind_modifiers = bind_modifiers;
return std::move(result);
}

Expand Down
3 changes: 3 additions & 0 deletions src/duckdb/src/common/box_renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ void BoxRenderer::RenderValue(std::ostream &ss, const string &value, idx_t colum
}

string BoxRenderer::RenderType(const LogicalType &type) {
if (type.HasAlias()) {
return StringUtil::Lower(type.ToString());
}
switch (type.id()) {
case LogicalTypeId::TINYINT:
return "int8";
Expand Down
86 changes: 82 additions & 4 deletions src/duckdb/src/common/extra_type_info.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,28 @@ ExtraTypeInfo::ExtraTypeInfo(ExtraTypeInfoType type, string alias) : type(type),
}
ExtraTypeInfo::~ExtraTypeInfo() {
}
shared_ptr<ExtraTypeInfo> ExtraTypeInfo::Copy() const {
return make_shared_ptr<ExtraTypeInfo>(*this);
}

static bool CompareModifiers(const vector<Value> &left, const vector<Value> &right) {
// Check if the common prefix of the properties is the same for both types
auto common_props = MinValue(left.size(), right.size());
for (idx_t i = 0; i < common_props; i++) {
if (left[i].type() != right[i].type()) {
return false;
}
// Special case for nulls:
// For type modifiers, NULL is equivalent to ANY
if (left[i].IsNull() || right[i].IsNull()) {
continue;
}
if (left[i] != right[i]) {
return false;
}
}
return true;
}

bool ExtraTypeInfo::Equals(ExtraTypeInfo *other_p) const {
if (type == ExtraTypeInfoType::INVALID_TYPE_INFO || type == ExtraTypeInfoType::STRING_TYPE_INFO ||
Expand All @@ -31,6 +53,9 @@ bool ExtraTypeInfo::Equals(ExtraTypeInfo *other_p) const {
if (alias != other_p->alias) {
return false;
}
if (!CompareModifiers(modifiers, other_p->modifiers)) {
return false;
}
return true;
}
if (!other_p) {
Expand All @@ -39,7 +64,13 @@ bool ExtraTypeInfo::Equals(ExtraTypeInfo *other_p) const {
if (type != other_p->type) {
return false;
}
return alias == other_p->alias && EqualsInternal(other_p);
if (alias != other_p->alias) {
return false;
}
if (!CompareModifiers(modifiers, other_p->modifiers)) {
return false;
}
return EqualsInternal(other_p);
}

bool ExtraTypeInfo::EqualsInternal(ExtraTypeInfo *other_p) const {
Expand All @@ -63,6 +94,10 @@ bool DecimalTypeInfo::EqualsInternal(ExtraTypeInfo *other_p) const {
return width == other.width && scale == other.scale;
}

shared_ptr<ExtraTypeInfo> DecimalTypeInfo::Copy() const {
return make_shared_ptr<DecimalTypeInfo>(*this);
}

//===--------------------------------------------------------------------===//
// String Type Info
//===--------------------------------------------------------------------===//
Expand All @@ -78,6 +113,10 @@ bool StringTypeInfo::EqualsInternal(ExtraTypeInfo *other_p) const {
return true;
}

shared_ptr<ExtraTypeInfo> StringTypeInfo::Copy() const {
return make_shared_ptr<StringTypeInfo>(*this);
}

//===--------------------------------------------------------------------===//
// List Type Info
//===--------------------------------------------------------------------===//
Expand All @@ -93,6 +132,10 @@ bool ListTypeInfo::EqualsInternal(ExtraTypeInfo *other_p) const {
return child_type == other.child_type;
}

shared_ptr<ExtraTypeInfo> ListTypeInfo::Copy() const {
return make_shared_ptr<ListTypeInfo>(*this);
}

//===--------------------------------------------------------------------===//
// Struct Type Info
//===--------------------------------------------------------------------===//
Expand All @@ -108,6 +151,10 @@ bool StructTypeInfo::EqualsInternal(ExtraTypeInfo *other_p) const {
return child_types == other.child_types;
}

shared_ptr<ExtraTypeInfo> StructTypeInfo::Copy() const {
return make_shared_ptr<StructTypeInfo>(*this);
}

//===--------------------------------------------------------------------===//
// Aggregate State Type Info
//===--------------------------------------------------------------------===//
Expand All @@ -125,6 +172,10 @@ bool AggregateStateTypeInfo::EqualsInternal(ExtraTypeInfo *other_p) const {
state_type.bound_argument_types == other.state_type.bound_argument_types;
}

shared_ptr<ExtraTypeInfo> AggregateStateTypeInfo::Copy() const {
return make_shared_ptr<AggregateStateTypeInfo>(*this);
}

//===--------------------------------------------------------------------===//
// User Type Info
//===--------------------------------------------------------------------===//
Expand All @@ -135,16 +186,25 @@ UserTypeInfo::UserTypeInfo(string name_p)
: ExtraTypeInfo(ExtraTypeInfoType::USER_TYPE_INFO), user_type_name(std::move(name_p)) {
}

UserTypeInfo::UserTypeInfo(string catalog_p, string schema_p, string name_p)
UserTypeInfo::UserTypeInfo(string name_p, vector<Value> modifiers_p)
: ExtraTypeInfo(ExtraTypeInfoType::USER_TYPE_INFO), user_type_name(std::move(name_p)),
user_type_modifiers(std::move(modifiers_p)) {
}

UserTypeInfo::UserTypeInfo(string catalog_p, string schema_p, string name_p, vector<Value> modifiers_p)
: ExtraTypeInfo(ExtraTypeInfoType::USER_TYPE_INFO), catalog(std::move(catalog_p)), schema(std::move(schema_p)),
user_type_name(std::move(name_p)) {
user_type_name(std::move(name_p)), user_type_modifiers(std::move(modifiers_p)) {
}

bool UserTypeInfo::EqualsInternal(ExtraTypeInfo *other_p) const {
auto &other = other_p->Cast<UserTypeInfo>();
return other.user_type_name == user_type_name;
}

shared_ptr<ExtraTypeInfo> UserTypeInfo::Copy() const {
return make_shared_ptr<UserTypeInfo>(*this);
}

//===--------------------------------------------------------------------===//
// Enum Type Info
//===--------------------------------------------------------------------===//
Expand Down Expand Up @@ -318,6 +378,12 @@ void EnumTypeInfo::Serialize(Serializer &serializer) const {
[&](Serializer::List &list, idx_t i) { list.WriteElement(strings[i]); });
}

shared_ptr<ExtraTypeInfo> EnumTypeInfo::Copy() const {
Vector values_insert_order_copy(LogicalType::VARCHAR, false, false, 0);
values_insert_order_copy.Reference(values_insert_order);
return make_shared_ptr<EnumTypeInfo>(values_insert_order_copy, dict_size);
}

//===--------------------------------------------------------------------===//
// ArrayTypeInfo
//===--------------------------------------------------------------------===//
Expand All @@ -331,6 +397,10 @@ bool ArrayTypeInfo::EqualsInternal(ExtraTypeInfo *other_p) const {
return child_type == other.child_type && size == other.size;
}

shared_ptr<ExtraTypeInfo> ArrayTypeInfo::Copy() const {
return make_shared_ptr<ArrayTypeInfo>(*this);
}

//===--------------------------------------------------------------------===//
// Any Type Info
//===--------------------------------------------------------------------===//
Expand All @@ -346,8 +416,12 @@ bool AnyTypeInfo::EqualsInternal(ExtraTypeInfo *other_p) const {
return target_type == other.target_type && cast_score == other.cast_score;
}

shared_ptr<ExtraTypeInfo> AnyTypeInfo::Copy() const {
return make_shared_ptr<AnyTypeInfo>(*this);
}

//===--------------------------------------------------------------------===//
// Any Type Info
// Integer Literal Type Info
//===--------------------------------------------------------------------===//
IntegerLiteralTypeInfo::IntegerLiteralTypeInfo() : ExtraTypeInfo(ExtraTypeInfoType::INTEGER_LITERAL_TYPE_INFO) {
}
Expand All @@ -361,4 +435,8 @@ bool IntegerLiteralTypeInfo::EqualsInternal(ExtraTypeInfo *other_p) const {
return constant_value == other.constant_value;
}

shared_ptr<ExtraTypeInfo> IntegerLiteralTypeInfo::Copy() const {
return make_shared_ptr<IntegerLiteralTypeInfo>(*this);
}

} // namespace duckdb
109 changes: 106 additions & 3 deletions src/duckdb/src/common/types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,18 @@ string LogicalType::ToString() const {
if (id_ != LogicalTypeId::USER) {
auto alias = GetAlias();
if (!alias.empty()) {
auto mods_ptr = GetModifiers();
if (mods_ptr && !mods_ptr->empty()) {
auto &mods = *mods_ptr;
alias += "(";
for (idx_t i = 0; i < mods.size(); i++) {
alias += mods[i].ToString();
if (i < mods.size() - 1) {
alias += ", ";
}
}
alias += ")";
}
return alias;
}
}
Expand Down Expand Up @@ -457,6 +469,7 @@ string LogicalType::ToString() const {
auto &catalog = UserType::GetCatalog(*this);
auto &schema = UserType::GetSchema(*this);
auto &type = UserType::GetTypeName(*this);
auto &mods = UserType::GetTypeModifiers(*this);

if (!catalog.empty()) {
result = KeywordHelper::WriteOptionallyQuoted(catalog);
Expand All @@ -471,6 +484,18 @@ string LogicalType::ToString() const {
result += ".";
}
result += KeywordHelper::WriteOptionallyQuoted(type);

if (!mods.empty()) {
result += "(";
for (idx_t i = 0; i < mods.size(); i++) {
result += mods[i].ToString();
if (i < mods.size() - 1) {
result += ", ";
}
}
result += ")";
}

return result;
}
case LogicalTypeId::AGGREGATE_STATE: {
Expand Down Expand Up @@ -504,7 +529,9 @@ LogicalType TransformStringToLogicalType(const string &str) {

LogicalType GetUserTypeRecursive(const LogicalType &type, ClientContext &context) {
if (type.id() == LogicalTypeId::USER && type.HasAlias()) {
return Catalog::GetType(context, INVALID_CATALOG, INVALID_SCHEMA, type.GetAlias());
auto &type_entry =
Catalog::GetEntry<TypeCatalogEntry>(context, INVALID_CATALOG, INVALID_SCHEMA, type.GetAlias());
return type_entry.user_type;
}
// Look for LogicalTypeId::USER in nested types
if (type.id() == LogicalTypeId::STRUCT) {
Expand Down Expand Up @@ -1131,6 +1158,15 @@ bool ApproxEqual(double ldecimal, double rdecimal) {
//===--------------------------------------------------------------------===//
// Extra Type Info
//===--------------------------------------------------------------------===//

LogicalType LogicalType::DeepCopy() const {
LogicalType copy = *this;
if (type_info_) {
copy.type_info_ = type_info_->Copy();
}
return copy;
}

void LogicalType::SetAlias(string alias) {
if (!type_info_) {
type_info_ = make_shared_ptr<ExtraTypeInfo>(ExtraTypeInfoType::GENERIC_TYPE_INFO, std::move(alias));
Expand Down Expand Up @@ -1159,6 +1195,53 @@ bool LogicalType::HasAlias() const {
return false;
}

void LogicalType::SetModifiers(vector<Value> modifiers) {
if (!type_info_ && !modifiers.empty()) {
type_info_ = make_shared_ptr<ExtraTypeInfo>(ExtraTypeInfoType::GENERIC_TYPE_INFO);
}
type_info_->modifiers = std::move(modifiers);
}

bool LogicalType::HasModifiers() const {
if (id() == LogicalTypeId::USER) {
return !UserType::GetTypeModifiers(*this).empty();
}
if (type_info_) {
return !type_info_->modifiers.empty();
}
return false;
}

vector<Value> LogicalType::GetModifiersCopy() const {
if (id() == LogicalTypeId::USER) {
return UserType::GetTypeModifiers(*this);
}
if (type_info_) {
return type_info_->modifiers;
}
return {};
}

optional_ptr<vector<Value>> LogicalType::GetModifiers() {
if (id() == LogicalTypeId::USER) {
return UserType::GetTypeModifiers(*this);
}
if (type_info_) {
return type_info_->modifiers;
}
return nullptr;
}

optional_ptr<const vector<Value>> LogicalType::GetModifiers() const {
if (id() == LogicalTypeId::USER) {
return UserType::GetTypeModifiers(*this);
}
if (type_info_) {
return type_info_->modifiers;
}
return nullptr;
}

//===--------------------------------------------------------------------===//
// Decimal Type
//===--------------------------------------------------------------------===//
Expand Down Expand Up @@ -1402,13 +1485,33 @@ const string &UserType::GetTypeName(const LogicalType &type) {
return info->Cast<UserTypeInfo>().user_type_name;
}

const vector<Value> &UserType::GetTypeModifiers(const LogicalType &type) {
D_ASSERT(type.id() == LogicalTypeId::USER);
auto info = type.AuxInfo();
D_ASSERT(info);
return info->Cast<UserTypeInfo>().user_type_modifiers;
}

vector<Value> &UserType::GetTypeModifiers(LogicalType &type) {
D_ASSERT(type.id() == LogicalTypeId::USER);
auto info = type.GetAuxInfoShrPtr();
D_ASSERT(info);
return info->Cast<UserTypeInfo>().user_type_modifiers;
}

LogicalType LogicalType::USER(const string &user_type_name) {
auto info = make_shared_ptr<UserTypeInfo>(user_type_name);
return LogicalType(LogicalTypeId::USER, std::move(info));
}

LogicalType LogicalType::USER(string catalog, string schema, string name) {
auto info = make_shared_ptr<UserTypeInfo>(std::move(catalog), std::move(schema), std::move(name));
LogicalType LogicalType::USER(const string &user_type_name, const vector<Value> &user_type_mods) {
auto info = make_shared_ptr<UserTypeInfo>(user_type_name, user_type_mods);
return LogicalType(LogicalTypeId::USER, std::move(info));
}

LogicalType LogicalType::USER(string catalog, string schema, string name, vector<Value> user_type_mods) {
auto info = make_shared_ptr<UserTypeInfo>(std::move(catalog), std::move(schema), std::move(name),
std::move(user_type_mods));
return LogicalType(LogicalTypeId::USER, std::move(info));
}

Expand Down

0 comments on commit c688bb8

Please sign in to comment.