Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ void CurrentQueryFunction(DataChunk &input, ExpressionState &state, Vector &resu

// current_schema
void CurrentSchemaFunction(DataChunk &input, ExpressionState &state, Vector &result) {
Value val(ClientData::Get(state.GetContext()).catalog_search_path->GetDefault().GetSchema());
Value val(ClientData::Get(state.GetContext()).catalog_search_path->GetDefault().GetSchemaName());
result.Reference(val, count_t(input.size()));
}

Expand Down Expand Up @@ -67,7 +67,7 @@ unique_ptr<FunctionData> CurrentSchemasBind(BindScalarFunctionInput &input) {
auto &catalog_search_path = ClientData::Get(context).catalog_search_path;
auto &search_path = implicit_schemas ? catalog_search_path->Get() : catalog_search_path->GetSetPaths();
std::transform(search_path.begin(), search_path.end(), std::back_inserter(schema_list),
[](const CatalogSearchEntry &s) -> Value { return Value(s.GetSchema()); });
[](const CatalogSearchEntry &s) -> Value { return Value(s.GetSchemaName()); });
result_val = Value::LIST(LogicalType::VARCHAR, schema_list);
}
return make_uniq<CurrentSchemasBindData>(std::move(result_val));
Expand Down
15 changes: 15 additions & 0 deletions src/duckdb/extension/icu/icu-timezone.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,16 @@ struct ICUFromNaiveTimestamp : public ICUDateFunc {
return timestamp_tz_ns_t(result);
}

static inline timestamp_tz_t Operation(Calendar *calendar, date_t naive) {
if (DUCKDB_UNLIKELY(naive == date_t::infinity())) {
return timestamp_tz_t::infinity();
}
if (DUCKDB_UNLIKELY(naive == date_t::ninfinity())) {
return timestamp_tz_t::ninfinity();
}
return Operation(calendar, Timestamp::FromDatetime(naive, dtime_t(0)));
}

template <class SRC, class DST>
static bool CastFromNaive(Vector &source, Vector &result, idx_t count, CastParameters &parameters) {
auto &cast_data = parameters.cast_data->Cast<CastData>();
Expand Down Expand Up @@ -706,6 +716,11 @@ struct ICUTimeZoneFunc : public ICUDateFunc {
.AddParameter("timestamp", LogicalType::TIMESTAMP_TZ_NS);
set.AddFunction(timetzns_fun);

ScalarFunction date_fun({}, LogicalType::TIMESTAMP_TZ, Execute<ICUFromNaiveTimestamp, date_t, timestamp_tz_t>,
Bind);
date_fun.GetSignature().AddParameter("timezone", LogicalType::VARCHAR).AddParameter("date", LogicalType::DATE);
set.AddFunction(date_fun);

set.ApplyToFunctions([](ScalarFunction &func) {
func.SetFallible();
func.SetStability(FunctionStability::CONSISTENT_WITHIN_QUERY);
Expand Down
33 changes: 32 additions & 1 deletion src/duckdb/extension/json/json_functions/json_create.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -614,6 +614,33 @@ static void CreateRawValues(yyjson_mut_doc *doc, yyjson_mut_val *vals[], const V
}
}

// DECIMAL(w, s) with w == s has no digits before the decimal point, so its VARCHAR form has no leading zero
// (e.g., ".5" or "-.5"). That is not a valid JSON number, so we add the zero before inserting it as a raw value.
static void CreateRawDecimalValues(yyjson_mut_doc *doc, yyjson_mut_val *vals[], const Vector &value_v, idx_t count) {
const auto values = value_v.Values<string_t>();
string buffer;
for (idx_t i = 0; i < count; i++) {
const auto entry = values[i];
if (!entry.IsValid()) {
vals[i] = yyjson_mut_null(doc);
continue;
}
const auto &str = entry.GetValue();
const auto data = str.GetData();
const auto size = str.GetSize();
const idx_t point_pos = (size > 0 && data[0] == '-') ? 1 : 0;
if (point_pos < size && data[point_pos] == '.') {
buffer.assign(data, point_pos);
buffer += '0';
buffer.append(data + point_pos, size - point_pos);
vals[i] = yyjson_mut_rawncpy(doc, buffer.c_str(), buffer.size());
} else {
vals[i] = yyjson_mut_rawncpy(doc, data, size);
}
D_ASSERT(vals[i] != nullptr);
}
}

static void CreateValuesStruct(const StructNames &names, yyjson_mut_doc *doc, yyjson_mut_val *vals[], Vector &value_v,
idx_t count, const JSONCopyFormatOptions &options) {
// Structs become values, therefore we initialize vals to JSON values
Expand Down Expand Up @@ -1057,7 +1084,11 @@ static void CreateValues(const StructNames &names, yyjson_mut_doc *doc, yyjson_m
if (DecimalType::GetWidth(type) > 15) {
Vector string_vector(LogicalTypeId::VARCHAR, count);
VectorOperations::DefaultCast(value_v, string_vector, count);
CreateRawValues(doc, vals, string_vector, count);
if (DecimalType::GetWidth(type) == DecimalType::GetScale(type)) {
CreateRawDecimalValues(doc, vals, string_vector, count);
} else {
CreateRawValues(doc, vals, string_vector, count);
}
} else {
Vector double_vector(LogicalType::DOUBLE, count);
VectorOperations::DefaultCast(value_v, double_vector, count);
Expand Down
4 changes: 2 additions & 2 deletions src/duckdb/extension/parquet/read_single_parquet_file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,14 +114,14 @@ static unique_ptr<FunctionData> ReadSingleParquetFileBind(ClientContext &context
result->file = TableFunctionFileBindInput::GetFile(input);

// the named parameters of this function are those of the multi-file parquet reader
ParquetMultiFileInfo interface;
ParquetMultiFileInfo file_info;
MultiFileOptions file_options;
if (file_input.multi_file_options) {
file_options = *file_input.multi_file_options;
}
ParquetFileReaderOptions options(context);
for (auto &kv : input.named_parameters) {
interface.ParseOption(context, kv.first, kv.second, file_options, options);
file_info.ParseOption(context, kv.first, kv.second, file_options, options);
}
result->options = std::move(options.options);

Expand Down
8 changes: 4 additions & 4 deletions src/duckdb/generated_extension_loader_package_build.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ int32_t duckdb_extension_core_functions_describe(duckdb_extension_descriptor *de
descriptor->version = 1;
descriptor->name = "core_functions";
descriptor->extension_version = EXT_VERSION_CORE_FUNCTIONS;
descriptor->api_version = "v2.0.1-alpha55482";
descriptor->api_version = "v2.0.1-alpha56370";
descriptor->entry_cpp = (void (*)(void))core_functions_duckdb_cpp_init;
return 0;
}
Expand Down Expand Up @@ -78,7 +78,7 @@ int32_t duckdb_extension_parquet_describe(duckdb_extension_descriptor *descripto
descriptor->version = 1;
descriptor->name = "parquet";
descriptor->extension_version = EXT_VERSION_PARQUET;
descriptor->api_version = "v2.0.1-alpha55482";
descriptor->api_version = "v2.0.1-alpha56370";
descriptor->entry_cpp = (void (*)(void))parquet_duckdb_cpp_init;
return 0;
}
Expand Down Expand Up @@ -111,7 +111,7 @@ int32_t duckdb_extension_icu_describe(duckdb_extension_descriptor *descriptor) {
descriptor->version = 1;
descriptor->name = "icu";
descriptor->extension_version = EXT_VERSION_ICU;
descriptor->api_version = "v2.0.1-alpha55482";
descriptor->api_version = "v2.0.1-alpha56370";
descriptor->entry_cpp = (void (*)(void))icu_duckdb_cpp_init;
return 0;
}
Expand Down Expand Up @@ -144,7 +144,7 @@ int32_t duckdb_extension_json_describe(duckdb_extension_descriptor *descriptor)
descriptor->version = 1;
descriptor->name = "json";
descriptor->extension_version = EXT_VERSION_JSON;
descriptor->api_version = "v2.0.1-alpha55482";
descriptor->api_version = "v2.0.1-alpha56370";
descriptor->entry_cpp = (void (*)(void))json_duckdb_cpp_init;
return 0;
}
Expand Down
42 changes: 37 additions & 5 deletions src/duckdb/src/catalog/catalog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,13 +127,36 @@ Catalog &Catalog::GetCatalog(ClientContext &context, const Identifier &catalog_n
// Schema
//===--------------------------------------------------------------------===//
optional_ptr<CatalogEntry> Catalog::CreateSchema(ClientContext &context, CreateSchemaInfo &info) {
CheckNestedSchemaSupport(info.GetQualifiedName(), CatalogType::SCHEMA_ENTRY);
auto supports_create_schema = SupportsCreateSchema(info);
if (supports_create_schema.HasError()) {
supports_create_schema.Throw();
}
return CreateSchema(GetCatalogTransaction(context), info);
}

void Catalog::CheckNestedSchemaSupport(const QualifiedName &name, CatalogType type) const {
if (SupportsNestedSchemas()) {
return;
}
auto &path = name.Path();
auto end = path.size();
if (type != CatalogType::SCHEMA_ENTRY && end > 0) {
end--;
}
idx_t schema_count = 0;
for (idx_t i = end > 1 ? 1 : 0; i < end; i++) {
if (!path[i].empty() && ++schema_count > 1) {
while (path[end - 1].empty()) {
end--;
}
auto schema_path =
QualifiedName::FromPath(vector<Identifier>(path.begin() + 1, path.begin() + NumericCast<int64_t>(end)));
throw BinderException("Catalog %s does not support nested schemas: %s", GetName(), schema_path.ToString());
}
}
}

CatalogTransaction Catalog::GetCatalogTransaction(ClientContext &context) {
return CatalogTransaction(*this, context);
}
Expand Down Expand Up @@ -438,6 +461,7 @@ struct CatalogLookup {
void Catalog::DropEntry(ClientContext &context, DropInfo &info) {
if (info.type == CatalogType::SCHEMA_ENTRY) {
// DROP SCHEMA
CheckNestedSchemaSupport(info.GetQualifiedName(), CatalogType::SCHEMA_ENTRY);
DropSchema(context, info);
return;
}
Expand Down Expand Up @@ -483,6 +507,7 @@ optional_ptr<SchemaCatalogEntry> Catalog::GetSchema(CatalogTransaction transacti

optional_ptr<SchemaCatalogEntry> Catalog::GetSchema(ClientContext &context, const EntryLookupInfo &schema_lookup,
OnEntryNotFound if_not_found) {
CheckNestedSchemaSupport(schema_lookup.GetQualifiedName(), CatalogType::SCHEMA_ENTRY);
return LookupSchema(GetCatalogTransaction(context), schema_lookup, if_not_found);
}

Expand Down Expand Up @@ -582,6 +607,7 @@ optional_ptr<SchemaCatalogEntry>
Catalog::LookupSchemaPath(CatalogTransaction transaction, const EntryLookupInfo &schema_lookup,
OnEntryNotFound if_not_found,
const std::function<optional_ptr<CatalogEntry>(const EntryLookupInfo &)> &lookup_root) {
CheckNestedSchemaSupport(schema_lookup.GetQualifiedName(), CatalogType::SCHEMA_ENTRY);
auto &path = schema_lookup.GetQualifiedName().Path();
optional_ptr<SchemaCatalogEntry> schema;
// Bound schema lookups lead with the catalog; bare lookups contain just the schema name.
Expand Down Expand Up @@ -643,6 +669,7 @@ SchemaCatalogEntry &Catalog::GetSchema(ClientContext &context, const Identifier
}

SchemaCatalogEntry &Catalog::GetSchema(CatalogTransaction transaction, const EntryLookupInfo &schema_lookup) {
CheckNestedSchemaSupport(schema_lookup.GetQualifiedName(), CatalogType::SCHEMA_ENTRY);
return *LookupSchema(transaction, schema_lookup, OnEntryNotFound::THROW_EXCEPTION);
}

Expand Down Expand Up @@ -1011,6 +1038,11 @@ CatalogException Catalog::CreateMissingEntryException(CatalogEntryRetriever &ret
return CatalogException::MissingEntry(lookup_info, did_you_mean);
}

CatalogEntryLookup Catalog::TryLookupEntry(CatalogTransaction transaction, const EntryLookupInfo &lookup_info) {
CheckNestedSchemaSupport(lookup_info.GetQualifiedName(), lookup_info.GetCatalogType());
return TryLookupEntryInternal(transaction, lookup_info);
}

CatalogEntryLookup Catalog::TryLookupEntryInternal(CatalogTransaction transaction, const EntryLookupInfo &lookup_info) {
if (lookup_info.GetAtClause() && !SupportsTimeTravel()) {
return {nullptr, nullptr, ErrorData(BinderException("Catalog type does not support time travel"))};
Expand Down Expand Up @@ -1043,7 +1075,7 @@ CatalogEntryLookup Catalog::TryLookupEntry(CatalogEntryRetriever &retriever, con
auto entries = GetCatalogEntries(retriever, GetName(), Identifier::InvalidSchema());
for (auto &entry : entries) {
auto transaction = GetCatalogTransaction(context);
auto result = TryLookupEntryInternal(
auto result = TryLookupEntry(
transaction,
EntryLookupInfo(lookup_info, QualifiedName::FromCatalogSchema(GetName(), entry.GetSchemaPath(),
lookup_info.GetEntryIdentifier())));
Expand All @@ -1056,7 +1088,7 @@ CatalogEntryLookup Catalog::TryLookupEntry(CatalogEntryRetriever &retriever, con
}
} else {
auto transaction = GetCatalogTransaction(context);
auto result = TryLookupEntryInternal(transaction, lookup_info);
auto result = TryLookupEntry(transaction, lookup_info);
if (result.Found()) {
return result;
}
Expand Down Expand Up @@ -1184,7 +1216,7 @@ CatalogEntryLookup Catalog::TryLookupEntry(CatalogEntryRetriever &retriever, con
CatalogEntryLookup result;
for (auto &lookup : lookups) {
auto transaction = lookup.catalog.GetCatalogTransaction(context);
result = lookup.catalog.TryLookupEntryInternal(transaction, lookup.lookup_info);
result = lookup.catalog.TryLookupEntry(transaction, lookup.lookup_info);
if (result.Found()) {
break;
}
Expand Down Expand Up @@ -1303,7 +1335,7 @@ CatalogEntryLookup Catalog::TryLookupDefaultTable(CatalogEntryRetriever &retriev

EntryLookupInfo info(CatalogType::TABLE_ENTRY,
QualifiedName(catalog_by_name->GetName(), table_schema, table_name), at_clause, context);
return catalog_by_name->TryLookupEntryInternal(transaction, info);
return catalog_by_name->TryLookupEntry(transaction, info);
}

return {nullptr, nullptr, ErrorData()};
Expand All @@ -1325,7 +1357,7 @@ CatalogEntryLookup Catalog::TryLookupDefaultSchema(CatalogEntryRetriever &retrie
auto transaction = catalog_entry->GetCatalogTransaction(retriever.GetContext());
EntryLookupInfo default_schema_lookup(
lookup_info, QualifiedName(catalog_entry->GetName(), *default_schema, lookup_info.GetEntryIdentifier()));
auto result = catalog_entry->TryLookupEntryInternal(transaction, default_schema_lookup);
auto result = catalog_entry->TryLookupEntry(transaction, default_schema_lookup);
if (result.Found() || result.error.HasError()) {
return result;
}
Expand Down
Loading
Loading