From 8a6996040fbe7bd6a20f2a04548d6672b8a06407 Mon Sep 17 00:00:00 2001 From: Aleksandr Golubov Date: Tue, 15 Oct 2024 14:03:11 +0500 Subject: [PATCH] Updated up to DuckDB 1.1.2 bugfix release --- c_src/duckdb/duckdb.cpp | 2117 ++++++++++++++------------------------- c_src/duckdb/duckdb.hpp | 920 ++++++++++++++++- mix.exs | 4 +- 3 files changed, 1656 insertions(+), 1385 deletions(-) diff --git a/c_src/duckdb/duckdb.cpp b/c_src/duckdb/duckdb.cpp index 5c5ff20..be0a7e5 100644 --- a/c_src/duckdb/duckdb.cpp +++ b/c_src/duckdb/duckdb.cpp @@ -2637,6 +2637,7 @@ static constexpr ExtensionEntry EXTENSION_SETTINGS[] = { {"binary_as_string", "parquet"}, {"ca_cert_file", "httpfs"}, {"calendar", "icu"}, + {"enable_geoparquet_conversion", "parquet"}, {"enable_server_cert_verification", "httpfs"}, {"force_download", "httpfs"}, {"hf_max_per_page", "httpfs"}, @@ -7842,6 +7843,7 @@ class SegmentTree { } SegmentNode node; segment->index = nodes.size(); + segment->next = nullptr; node.row_start = segment->start; node.node = std::move(segment); nodes.push_back(std::move(node)); @@ -10260,7 +10262,8 @@ struct CreateSecretInput { case_insensitive_map_t options; }; -typedef unique_ptr (*secret_deserializer_t)(Deserializer &deserializer, BaseSecret base_secret); +typedef unique_ptr (*secret_deserializer_t)(Deserializer &deserializer, BaseSecret base_secret, + const named_parameter_type_map_t &options); typedef unique_ptr (*create_secret_function_t)(ClientContext &context, CreateSecretInput &input); //! A CreateSecretFunction is a function adds a provider for a secret type. @@ -10403,14 +10406,30 @@ class KeyValueSecret : public BaseSecret { // FIXME: use serialization scripts template - static unique_ptr Deserialize(Deserializer &deserializer, BaseSecret base_secret) { + static unique_ptr Deserialize(Deserializer &deserializer, BaseSecret base_secret, + const named_parameter_type_map_t &options) { auto result = make_uniq(base_secret); Value secret_map_value; deserializer.ReadProperty(201, "secret_map", secret_map_value); for (const auto &entry : ListValue::GetChildren(secret_map_value)) { auto kv_struct = StructValue::GetChildren(entry); - result->secret_map[kv_struct[0].ToString()] = kv_struct[1].ToString(); + auto key = kv_struct[0].ToString(); + auto raw_value = kv_struct[1].ToString(); + + auto it = options.find(key); + if (it == options.end()) { + throw IOException("Failed to deserialize secret '%s', it contains an unexpected key: '%s'", + base_secret.GetName(), key); + } + auto &logical_type = it->second; + Value value; + if (logical_type.id() == LogicalTypeId::VARCHAR) { + value = Value(raw_value); + } else { + value = Value(raw_value).DefaultCastAs(logical_type); + } + result->secret_map[key] = value; } Value redact_set_value; @@ -13540,6 +13559,13 @@ optional_ptr DuckSchemaEntry::AddEntryInternal(CatalogTransaction // first find the set for this entry auto &set = GetCatalogSet(entry_type); dependencies.AddDependency(*this); + if (on_conflict == OnCreateConflict::IGNORE_ON_CONFLICT) { + auto old_entry = set.GetEntry(transaction, entry_name); + if (old_entry) { + return nullptr; + } + } + if (on_conflict == OnCreateConflict::REPLACE_ON_CONFLICT) { // CREATE OR REPLACE: first try to drop the entry auto old_entry = set.GetEntry(transaction, entry_name); @@ -13736,7 +13762,7 @@ void DuckSchemaEntry::DropEntry(ClientContext &context, DropInfo &info) { throw InternalException("Failed to drop entry \"%s\" - entry could not be found", info.name); } if (existing_entry->type != info.type) { - throw CatalogException("Existing object %s is of type %s, trying to replace with type %s", info.name, + throw CatalogException("Existing object %s is of type %s, trying to drop type %s", info.name, CatalogTypeToString(existing_entry->type), CatalogTypeToString(info.type)); } @@ -25556,7 +25582,7 @@ namespace duckdb { static const DefaultMacro internal_macros[] = { {DEFAULT_SCHEMA, "current_role", {nullptr}, {{nullptr, nullptr}}, "'duckdb'"}, // user name of current execution context {DEFAULT_SCHEMA, "current_user", {nullptr}, {{nullptr, nullptr}}, "'duckdb'"}, // user name of current execution context - {DEFAULT_SCHEMA, "current_catalog", {nullptr}, {{nullptr, nullptr}}, "current_database()"}, // name of current database (called "catalog" in the SQL standard) + {DEFAULT_SCHEMA, "current_catalog", {nullptr}, {{nullptr, nullptr}}, "main.current_database()"}, // name of current database (called "catalog" in the SQL standard) {DEFAULT_SCHEMA, "user", {nullptr}, {{nullptr, nullptr}}, "current_user"}, // equivalent to current_user {DEFAULT_SCHEMA, "session_user", {nullptr}, {{nullptr, nullptr}}, "'duckdb'"}, // session user name {"pg_catalog", "inet_client_addr", {nullptr}, {{nullptr, nullptr}}, "NULL"}, // address of the remote connection @@ -25571,10 +25597,10 @@ static const DefaultMacro internal_macros[] = { {"pg_catalog", "pg_typeof", {"expression", nullptr}, {{nullptr, nullptr}}, "lower(typeof(expression))"}, // get the data type of any value - {"pg_catalog", "current_database", {nullptr}, {{nullptr, nullptr}}, "current_database()"}, // name of current database (called "catalog" in the SQL standard) - {"pg_catalog", "current_query", {nullptr}, {{nullptr, nullptr}}, "current_query()"}, // the currently executing query (NULL if not inside a plpgsql function) - {"pg_catalog", "current_schema", {nullptr}, {{nullptr, nullptr}}, "current_schema()"}, // name of current schema - {"pg_catalog", "current_schemas", {"include_implicit"}, {{nullptr, nullptr}}, "current_schemas(include_implicit)"}, // names of schemas in search path + {"pg_catalog", "current_database", {nullptr}, {{nullptr, nullptr}}, "main.current_database()"}, // name of current database (called "catalog" in the SQL standard) + {"pg_catalog", "current_query", {nullptr}, {{nullptr, nullptr}}, "main.current_query()"}, // the currently executing query (NULL if not inside a plpgsql function) + {"pg_catalog", "current_schema", {nullptr}, {{nullptr, nullptr}}, "main.current_schema()"}, // name of current schema + {"pg_catalog", "current_schemas", {"include_implicit"}, {{nullptr, nullptr}}, "main.current_schemas(include_implicit)"}, // names of schemas in search path // privilege functions {"pg_catalog", "has_any_column_privilege", {"table", "privilege", nullptr}, {{nullptr, nullptr}}, "true"}, //boolean //does current user have privilege for any column of table @@ -34286,6 +34312,7 @@ static void InitializeFunctionPointers(ArrowAppendData &append_data, const Logic break; case LogicalTypeId::BLOB: case LogicalTypeId::BIT: + case LogicalTypeId::VARINT: if (append_data.options.arrow_offset_size == ArrowOffsetSize::LARGE) { InitializeAppenderForType>(append_data); } else { @@ -34384,85 +34411,88 @@ void ArrowAppender::AddChildren(ArrowAppendData &data, const idx_t count) { namespace duckdb { +using bitstring_t = duckdb::string_t; + //! The Bit class is a static class that holds helper functions for the BIT type. class Bit { public: //! Returns the number of bits in the bit string - DUCKDB_API static idx_t BitLength(string_t bits); + DUCKDB_API static idx_t BitLength(bitstring_t bits); //! Returns the number of set bits in the bit string - DUCKDB_API static idx_t BitCount(string_t bits); + DUCKDB_API static idx_t BitCount(bitstring_t bits); //! Returns the number of bytes in the bit string - DUCKDB_API static idx_t OctetLength(string_t bits); + DUCKDB_API static idx_t OctetLength(bitstring_t bits); //! Extracts the nth bit from bit string; the first (leftmost) bit is indexed 0 - DUCKDB_API static idx_t GetBit(string_t bit_string, idx_t n); + DUCKDB_API static idx_t GetBit(bitstring_t bit_string, idx_t n); //! Sets the nth bit in bit string to newvalue; the first (leftmost) bit is indexed 0 - DUCKDB_API static void SetBit(string_t &bit_string, idx_t n, idx_t new_value); + DUCKDB_API static void SetBit(bitstring_t &bit_string, idx_t n, idx_t new_value); //! Returns first starting index of the specified substring within bits, or zero if it's not present. - DUCKDB_API static idx_t BitPosition(string_t substring, string_t bits); + DUCKDB_API static idx_t BitPosition(bitstring_t substring, bitstring_t bits); //! Converts bits to a string, writing the output to the designated output string. //! The string needs to have space for at least GetStringSize(bits) bytes. - DUCKDB_API static void ToString(string_t bits, char *output); - DUCKDB_API static string ToString(string_t str); + DUCKDB_API static void ToString(bitstring_t bits, char *output); + DUCKDB_API static string ToString(bitstring_t bits); //! Returns the bit size of a string -> bit conversion DUCKDB_API static bool TryGetBitStringSize(string_t str, idx_t &result_size, string *error_message); //! Convert a string to a bit. This function should ONLY be called after calling GetBitSize, since it does NOT //! perform data validation. - DUCKDB_API static void ToBit(string_t str, string_t &output); + DUCKDB_API static void ToBit(string_t str, bitstring_t &output); DUCKDB_API static string ToBit(string_t str); //! output needs to have enough space allocated before calling this function (blob size + 1) - DUCKDB_API static void BlobToBit(string_t blob, string_t &output); + DUCKDB_API static void BlobToBit(string_t blob, bitstring_t &output); DUCKDB_API static string BlobToBit(string_t blob); //! output_str needs to have enough space allocated before calling this function (sizeof(T) + 1) template - static void NumericToBit(T numeric, string_t &output_str); + static void NumericToBit(T numeric, bitstring_t &output_str); template static string NumericToBit(T numeric); //! bit is expected to fit inside of output num (bit size <= sizeof(T) + 1) template - static void BitToNumeric(string_t bit, T &output_num); + static void BitToNumeric(bitstring_t bit, T &output_num); template - static T BitToNumeric(string_t bit); + static T BitToNumeric(bitstring_t bit); //! bit is expected to fit inside of output_blob (bit size = output_blob + 1) - static void BitToBlob(string_t bit, string_t &output_blob); + static void BitToBlob(bitstring_t bit, string_t &output_blob); - static string BitToBlob(string_t bit); + static string BitToBlob(bitstring_t bit); //! Creates a new bitstring of determined length - DUCKDB_API static void BitString(const string_t &input, const idx_t &len, string_t &result); - DUCKDB_API static void SetEmptyBitString(string_t &target, string_t &input); - DUCKDB_API static void SetEmptyBitString(string_t &target, idx_t len); + DUCKDB_API static void BitString(const string_t &input, idx_t len, bitstring_t &result); + DUCKDB_API static void ExtendBitString(const bitstring_t &input, idx_t bit_length, bitstring_t &result); + DUCKDB_API static void SetEmptyBitString(bitstring_t &target, string_t &input); + DUCKDB_API static void SetEmptyBitString(bitstring_t &target, idx_t len); DUCKDB_API static idx_t ComputeBitstringLen(idx_t len); - DUCKDB_API static void RightShift(const string_t &bit_string, const idx_t &shif, string_t &result); - DUCKDB_API static void LeftShift(const string_t &bit_string, const idx_t &shift, string_t &result); - DUCKDB_API static void BitwiseAnd(const string_t &rhs, const string_t &lhs, string_t &result); - DUCKDB_API static void BitwiseOr(const string_t &rhs, const string_t &lhs, string_t &result); - DUCKDB_API static void BitwiseXor(const string_t &rhs, const string_t &lhs, string_t &result); - DUCKDB_API static void BitwiseNot(const string_t &rhs, string_t &result); + DUCKDB_API static void RightShift(const bitstring_t &bit_string, idx_t shift, bitstring_t &result); + DUCKDB_API static void LeftShift(const bitstring_t &bit_string, idx_t shift, bitstring_t &result); + DUCKDB_API static void BitwiseAnd(const bitstring_t &rhs, const bitstring_t &lhs, bitstring_t &result); + DUCKDB_API static void BitwiseOr(const bitstring_t &rhs, const bitstring_t &lhs, bitstring_t &result); + DUCKDB_API static void BitwiseXor(const bitstring_t &rhs, const bitstring_t &lhs, bitstring_t &result); + DUCKDB_API static void BitwiseNot(const bitstring_t &rhs, bitstring_t &result); - DUCKDB_API static void Verify(const string_t &input); + DUCKDB_API static void Verify(const bitstring_t &input); private: - static void Finalize(string_t &str); - static idx_t GetBitInternal(string_t bit_string, idx_t n); - static void SetBitInternal(string_t &bit_string, idx_t n, idx_t new_value); + static void Finalize(bitstring_t &str); + static idx_t GetBitInternal(bitstring_t bit_string, idx_t n); + static void SetBitInternal(bitstring_t &bit_string, idx_t n, idx_t new_value); static idx_t GetBitIndex(idx_t n); - static uint8_t GetFirstByte(const string_t &str); + static uint8_t GetFirstByte(const bitstring_t &str); }; //===--------------------------------------------------------------------===// // Bit Template definitions //===--------------------------------------------------------------------===// template -void Bit::NumericToBit(T numeric, string_t &output_str) { +void Bit::NumericToBit(T numeric, bitstring_t &output_str) { D_ASSERT(output_str.GetSize() >= sizeof(T) + 1); auto output = output_str.GetDataWriteable(); @@ -34480,20 +34510,20 @@ template string Bit::NumericToBit(T numeric) { auto bit_len = sizeof(T) + 1; auto buffer = make_unsafe_uniq_array_uninitialized(bit_len); - string_t output_str(buffer.get(), UnsafeNumericCast(bit_len)); + bitstring_t output_str(buffer.get(), UnsafeNumericCast(bit_len)); Bit::NumericToBit(numeric, output_str); return output_str.GetString(); } template -T Bit::BitToNumeric(string_t bit) { +T Bit::BitToNumeric(bitstring_t bit) { T output; Bit::BitToNumeric(bit, output); return (output); } template -void Bit::BitToNumeric(string_t bit, T &output_num) { +void Bit::BitToNumeric(bitstring_t bit, T &output_num) { D_ASSERT(bit.GetSize() <= sizeof(T) + 1); output_num = 0; @@ -34554,18 +34584,20 @@ namespace duckdb { class Allocator; class Vector; -//! The VectorCache holds cached data that allows for re-use of the same memory by vectors +//! The VectorCache holds cached vector data. +//! It enables re-using the same memory for different vectors. class VectorCache { public: - //! Instantiate a vector cache with the given type and capacity - DUCKDB_API explicit VectorCache(Allocator &allocator, const LogicalType &type, - idx_t capacity = STANDARD_VECTOR_SIZE); + //! Instantiate an empty vector cache. + DUCKDB_API VectorCache(); + //! Instantiate a vector cache with the given type and capacity. + DUCKDB_API VectorCache(Allocator &allocator, const LogicalType &type, const idx_t capacity = STANDARD_VECTOR_SIZE); +public: buffer_ptr buffer; public: void ResetFromCache(Vector &result) const; - const LogicalType &GetType() const; }; @@ -34792,6 +34824,17 @@ void SetArrowFormat(DuckDBArrowSchemaHolder &root_holder, ArrowSchema &child, co child.metadata = root_holder.metadata_info.back().get(); break; } + case LogicalTypeId::VARINT: { + if (options.arrow_offset_size == ArrowOffsetSize::LARGE) { + child.format = "Z"; + } else { + child.format = "z"; + } + auto schema_metadata = ArrowSchemaMetadata::MetadataFromName("duckdb.varint"); + root_holder.metadata_info.emplace_back(schema_metadata.SerializeMetadata()); + child.metadata = root_holder.metadata_info.back().get(); + break; + } case LogicalTypeId::DOUBLE: child.format = "g"; break; @@ -35600,7 +35643,10 @@ class OperatorProfiler { public: DUCKDB_API explicit OperatorProfiler(ClientContext &context); + ~OperatorProfiler() { + } +public: DUCKDB_API void StartOperator(optional_ptr phys_op); DUCKDB_API void EndOperator(optional_ptr chunk); @@ -35608,20 +35654,14 @@ class OperatorProfiler { DUCKDB_API void Flush(const PhysicalOperator &phys_op); DUCKDB_API OperatorInformation &GetOperatorInfo(const PhysicalOperator &phys_op); - ~OperatorProfiler() { - } - +public: ClientContext &context; - bool HasOperatorSetting(const MetricsType &metric) const { - return operator_settings.find(metric) != operator_settings.end(); - } - private: //! Whether or not the profiler is enabled bool enabled; //! Sub-settings for the operator profiler - profiler_settings_t operator_settings; + profiler_settings_t settings; //! The timer used to time the execution time of the individual Physical Operators Profiler op; @@ -35649,7 +35689,8 @@ class QueryProfiler { using TreeMap = reference_map_t>; private: - unique_ptr CreateTree(const PhysicalOperator &root, profiler_settings_t settings, idx_t depth = 0); + unique_ptr CreateTree(const PhysicalOperator &root, const profiler_settings_t &settings, + const idx_t depth = 0); void Render(const ProfilingNode &node, std::ostream &str) const; public: @@ -36706,7 +36747,12 @@ void ArrowSchemaMetadata::AddOption(const string &key, const string &value) { metadata_map[key] = value; } string ArrowSchemaMetadata::GetOption(const string &key) const { - return metadata_map.at(key); + auto it = metadata_map.find(key); + if (it != metadata_map.end()) { + return it->second; + } else { + return ""; + } } string ArrowSchemaMetadata::GetExtensionName() const { @@ -36721,9 +36767,6 @@ ArrowSchemaMetadata ArrowSchemaMetadata::MetadataFromName(const string &extensio } bool ArrowSchemaMetadata::HasExtension() { - if (metadata_map.find(ARROW_EXTENSION_NAME) == metadata_map.end()) { - return false; - } auto arrow_extension = GetOption(ArrowSchemaMetadata::ARROW_EXTENSION_NAME); // FIXME: We are currently ignoring the ogc extensions return !arrow_extension.empty() && !StringUtil::StartsWith(arrow_extension, "ogc"); @@ -37954,7 +37997,8 @@ DUCKDB_API string ConvertToString::Operation(string_t input); // //===----------------------------------------------------------------------===// - +// Do not add a header inclusion guard to this file. Otherwise these Win32 macros +// may get defined and stomp on DuckDB symbols #ifdef WIN32 @@ -50777,6 +50821,10 @@ const char* EnumUtil::ToChars(MetricsType value) { return "OPERATOR_ROWS_SCANNED"; case MetricsType::OPERATOR_TIMING: return "OPERATOR_TIMING"; + case MetricsType::LATENCY: + return "LATENCY"; + case MetricsType::ROWS_RETURNED: + return "ROWS_RETURNED"; case MetricsType::RESULT_SET_SIZE: return "RESULT_SET_SIZE"; case MetricsType::ALL_OPTIMIZERS: @@ -50878,6 +50926,12 @@ MetricsType EnumUtil::FromString(const char *value) { if (StringUtil::Equals(value, "OPERATOR_TIMING")) { return MetricsType::OPERATOR_TIMING; } + if (StringUtil::Equals(value, "LATENCY")) { + return MetricsType::LATENCY; + } + if (StringUtil::Equals(value, "ROWS_RETURNED")) { + return MetricsType::ROWS_RETURNED; + } if (StringUtil::Equals(value, "RESULT_SET_SIZE")) { return MetricsType::RESULT_SET_SIZE; } @@ -56801,6 +56855,9 @@ PermissionException::PermissionException(const string &msg) : Exception(Exceptio SyntaxException::SyntaxException(const string &msg) : Exception(ExceptionType::SYNTAX, msg) { } +ExecutorException::ExecutorException(const string &msg) : Exception(ExceptionType::EXECUTOR, msg) { +} + ConstraintException::ConstraintException(const string &msg) : Exception(ExceptionType::CONSTRAINT, msg) { } @@ -57871,7 +57928,6 @@ string ExceptionFormatValue::Format(const string &msg, std::vector; } // namespace duckdb +namespace duckdb { + +template +struct EnumTypeInfoTemplated : public EnumTypeInfo { + explicit EnumTypeInfoTemplated(Vector &values_insert_order_p, idx_t size_p) + : EnumTypeInfo(values_insert_order_p, size_p) { + D_ASSERT(values_insert_order_p.GetType().InternalType() == PhysicalType::VARCHAR); + + UnifiedVectorFormat vdata; + values_insert_order.ToUnifiedFormat(size_p, vdata); + + auto data = UnifiedVectorFormat::GetData(vdata); + for (idx_t i = 0; i < size_p; i++) { + auto idx = vdata.sel->get_index(i); + if (!vdata.validity.RowIsValid(idx)) { + throw InternalException("Attempted to create ENUM type with NULL value"); + } + if (values.count(data[idx]) > 0) { + throw InvalidInputException("Attempted to create ENUM type with duplicate value %s", + data[idx].GetString()); + } + values[data[idx]] = UnsafeNumericCast(i); + } + } + + static shared_ptr Deserialize(Deserializer &deserializer, uint32_t size) { + Vector values_insert_order(LogicalType::VARCHAR, size); + auto strings = FlatVector::GetData(values_insert_order); + + deserializer.ReadList(201, "values", [&](Deserializer::List &list, idx_t i) { + strings[i] = StringVector::AddStringOrBlob(values_insert_order, list.ReadElement()); + }); + return make_shared_ptr(values_insert_order, size); + } + + const string_map_t &GetValues() const { + return values; + } + + EnumTypeInfoTemplated(const EnumTypeInfoTemplated &) = delete; + EnumTypeInfoTemplated &operator=(const EnumTypeInfoTemplated &) = delete; + +private: + string_map_t values; +}; + +} // namespace duckdb + + + + + + + + namespace duckdb { //===--------------------------------------------------------------------===// @@ -58124,50 +58235,6 @@ PhysicalType EnumTypeInfo::DictType(idx_t size) { } } -template -struct EnumTypeInfoTemplated : public EnumTypeInfo { - explicit EnumTypeInfoTemplated(Vector &values_insert_order_p, idx_t size_p) - : EnumTypeInfo(values_insert_order_p, size_p) { - D_ASSERT(values_insert_order_p.GetType().InternalType() == PhysicalType::VARCHAR); - - UnifiedVectorFormat vdata; - values_insert_order.ToUnifiedFormat(size_p, vdata); - - auto data = UnifiedVectorFormat::GetData(vdata); - for (idx_t i = 0; i < size_p; i++) { - auto idx = vdata.sel->get_index(i); - if (!vdata.validity.RowIsValid(idx)) { - throw InternalException("Attempted to create ENUM type with NULL value"); - } - if (values.count(data[idx]) > 0) { - throw InvalidInputException("Attempted to create ENUM type with duplicate value %s", - data[idx].GetString()); - } - values[data[idx]] = UnsafeNumericCast(i); - } - } - - static shared_ptr Deserialize(Deserializer &deserializer, uint32_t size) { - Vector values_insert_order(LogicalType::VARCHAR, size); - auto strings = FlatVector::GetData(values_insert_order); - - deserializer.ReadList(201, "values", [&](Deserializer::List &list, idx_t i) { - strings[i] = StringVector::AddStringOrBlob(values_insert_order, list.ReadElement()); - }); - return make_shared_ptr(values_insert_order, size); - } - - const string_map_t &GetValues() const { - return values; - } - - EnumTypeInfoTemplated(const EnumTypeInfoTemplated &) = delete; - EnumTypeInfoTemplated &operator=(const EnumTypeInfoTemplated &) = delete; - -private: - string_map_t values; -}; - EnumTypeInfo::EnumTypeInfo(Vector &values_insert_order_p, idx_t dict_size_p) : ExtraTypeInfo(ExtraTypeInfoType::ENUM_TYPE_INFO), values_insert_order(values_insert_order_p), dict_type(EnumDictType::VECTOR_DICT), dict_size(dict_size_p) { @@ -78608,7 +78675,7 @@ static unique_ptr CreateNode(const PipelineRenderNode &op) { static unique_ptr CreateNode(const ProfilingNode &op) { auto &info = op.GetProfilingInfo(); InsertionOrderPreservingMap extra_info; - if (info.Enabled(MetricsType::EXTRA_INFO)) { + if (info.Enabled(info.settings, MetricsType::EXTRA_INFO)) { extra_info = op.GetProfilingInfo().extra_info; } @@ -78618,11 +78685,13 @@ static unique_ptr CreateNode(const ProfilingNode &op) { } auto result = make_uniq(node_name, extra_info); - if (info.Enabled(MetricsType::OPERATOR_CARDINALITY)) { - result->extra_text[RenderTreeNode::CARDINALITY] = info.GetMetricAsString(MetricsType::OPERATOR_CARDINALITY); + if (info.Enabled(info.settings, MetricsType::OPERATOR_CARDINALITY)) { + auto cardinality = info.GetMetricAsString(MetricsType::OPERATOR_CARDINALITY); + result->extra_text[RenderTreeNode::CARDINALITY] = cardinality; } - if (info.Enabled(MetricsType::OPERATOR_TIMING)) { - string timing = StringUtil::Format("%.2f", info.metrics.at(MetricsType::OPERATOR_TIMING).GetValue()); + if (info.Enabled(info.settings, MetricsType::OPERATOR_TIMING)) { + auto value = info.metrics.at(MetricsType::OPERATOR_TIMING).GetValue(); + string timing = StringUtil::Format("%.2f", value); result->extra_text[RenderTreeNode::TIMING] = timing + "s"; } return result; @@ -97845,7 +97914,7 @@ idx_t Bit::ComputeBitstringLen(idx_t len) { return result; } -static inline idx_t GetBitPadding(const string_t &bit_string) { +static inline idx_t GetBitPadding(const bitstring_t &bit_string) { auto data = const_data_ptr_cast(bit_string.GetData()); D_ASSERT(idx_t(data[0]) <= 8); return data[0]; @@ -97860,14 +97929,14 @@ static inline idx_t GetBitSize(const string_t &str) { return str_len; } -uint8_t Bit::GetFirstByte(const string_t &str) { +uint8_t Bit::GetFirstByte(const bitstring_t &str) { D_ASSERT(str.GetSize() > 1); auto data = const_data_ptr_cast(str.GetData()); return data[1] & ((1 << (8 - data[0])) - 1); } -void Bit::Finalize(string_t &str) { +void Bit::Finalize(bitstring_t &str) { // bit strings require all padding bits to be set to 1 // this method sets all padding bits to 1 auto padding = GetBitPadding(str); @@ -97878,7 +97947,7 @@ void Bit::Finalize(string_t &str) { Bit::Verify(str); } -void Bit::SetEmptyBitString(string_t &target, string_t &input) { +void Bit::SetEmptyBitString(bitstring_t &target, string_t &input) { char *res_buf = target.GetDataWriteable(); const char *buf = input.GetData(); memset(res_buf, 0, input.GetSize()); @@ -97886,7 +97955,7 @@ void Bit::SetEmptyBitString(string_t &target, string_t &input) { Bit::Finalize(target); } -void Bit::SetEmptyBitString(string_t &target, idx_t len) { +void Bit::SetEmptyBitString(bitstring_t &target, idx_t len) { char *res_buf = target.GetDataWriteable(); memset(res_buf, 0, target.GetSize()); res_buf[0] = ComputePadding(len); @@ -97894,7 +97963,7 @@ void Bit::SetEmptyBitString(string_t &target, idx_t len) { } // **** casting functions **** -void Bit::ToString(string_t bits, char *output) { +void Bit::ToString(bitstring_t bits, char *output) { auto data = const_data_ptr_cast(bits.GetData()); auto len = bits.GetSize(); @@ -97910,7 +97979,7 @@ void Bit::ToString(string_t bits, char *output) { } } -string Bit::ToString(string_t str) { +string Bit::ToString(bitstring_t str) { auto len = BitLength(str); auto buffer = make_unsafe_uniq_array_uninitialized(len); ToString(str, buffer.get()); @@ -97940,7 +98009,7 @@ bool Bit::TryGetBitStringSize(string_t str, idx_t &str_len, string *error_messag return true; } -void Bit::ToBit(string_t str, string_t &output_str) { +void Bit::ToBit(string_t str, bitstring_t &output_str) { auto data = const_data_ptr_cast(str.GetData()); auto len = str.GetSize(); auto output = output_str.GetDataWriteable(); @@ -97974,12 +98043,12 @@ void Bit::ToBit(string_t str, string_t &output_str) { string Bit::ToBit(string_t str) { auto bit_len = GetBitSize(str); auto buffer = make_unsafe_uniq_array_uninitialized(bit_len); - string_t output_str(buffer.get(), UnsafeNumericCast(bit_len)); + bitstring_t output_str(buffer.get(), UnsafeNumericCast(bit_len)); Bit::ToBit(str, output_str); return output_str.GetString(); } -void Bit::BlobToBit(string_t blob, string_t &output_str) { +void Bit::BlobToBit(string_t blob, bitstring_t &output_str) { auto data = const_data_ptr_cast(blob.GetData()); auto output = output_str.GetDataWriteable(); idx_t size = blob.GetSize(); @@ -97990,12 +98059,12 @@ void Bit::BlobToBit(string_t blob, string_t &output_str) { string Bit::BlobToBit(string_t blob) { auto buffer = make_unsafe_uniq_array_uninitialized(blob.GetSize() + 1); - string_t output_str(buffer.get(), UnsafeNumericCast(blob.GetSize() + 1)); + bitstring_t output_str(buffer.get(), UnsafeNumericCast(blob.GetSize() + 1)); Bit::BlobToBit(blob, output_str); return output_str.GetString(); } -void Bit::BitToBlob(string_t bit, string_t &output_blob) { +void Bit::BitToBlob(bitstring_t bit, string_t &output_blob) { D_ASSERT(bit.GetSize() == output_blob.GetSize() + 1); auto data = const_data_ptr_cast(bit.GetData()); @@ -98012,7 +98081,7 @@ void Bit::BitToBlob(string_t bit, string_t &output_blob) { } } -string Bit::BitToBlob(string_t bit) { +string Bit::BitToBlob(bitstring_t bit) { D_ASSERT(bit.GetSize() > 1); auto buffer = make_unsafe_uniq_array_uninitialized(bit.GetSize() - 1); @@ -98022,32 +98091,53 @@ string Bit::BitToBlob(string_t bit) { } // **** scalar functions **** -void Bit::BitString(const string_t &input, const idx_t &bit_length, string_t &result) { +void Bit::BitString(const string_t &input, idx_t bit_length, bitstring_t &result) { char *res_buf = result.GetDataWriteable(); const char *buf = input.GetData(); auto padding = ComputePadding(bit_length); res_buf[0] = padding; + auto padding_len = UnsafeNumericCast(padding); for (idx_t i = 0; i < bit_length; i++) { if (i < bit_length - input.GetSize()) { - Bit::SetBit(result, i, 0); + Bit::SetBitInternal(result, i + padding_len, 0); } else { idx_t bit = buf[i - (bit_length - input.GetSize())] == '1' ? 1 : 0; + Bit::SetBitInternal(result, i + padding_len, bit); + } + } + Bit::Finalize(result); +} + +void Bit::ExtendBitString(const bitstring_t &input, idx_t bit_length, bitstring_t &result) { + uint8_t *res_buf = reinterpret_cast(result.GetDataWriteable()); + + auto padding = ComputePadding(bit_length); + res_buf[0] = static_cast(padding); + + idx_t original_length = Bit::BitLength(input); + D_ASSERT(bit_length >= original_length); + idx_t shift = bit_length - original_length; + for (idx_t i = 0; i < bit_length; i++) { + if (i < shift) { + Bit::SetBit(result, i, 0); + } else { + idx_t bit = Bit::GetBit(input, i - shift); Bit::SetBit(result, i, bit); } } Bit::Finalize(result); } -idx_t Bit::BitLength(string_t bits) { +idx_t Bit::BitLength(bitstring_t bits) { return ((bits.GetSize() - 1) * 8) - GetBitPadding(bits); } -idx_t Bit::OctetLength(string_t bits) { +idx_t Bit::OctetLength(bitstring_t bits) { return bits.GetSize() - 1; } -idx_t Bit::BitCount(string_t bits) { +idx_t Bit::BitCount(bitstring_t bits) { idx_t count = 0; const char *buf = bits.GetData(); for (idx_t byte_idx = 1; byte_idx < OctetLength(bits) + 1; byte_idx++) { @@ -98058,7 +98148,7 @@ idx_t Bit::BitCount(string_t bits) { return count - GetBitPadding(bits); } -idx_t Bit::BitPosition(string_t substring, string_t bits) { +idx_t Bit::BitPosition(bitstring_t substring, bitstring_t bits) { const char *buf = bits.GetData(); auto len = bits.GetSize(); auto substr_len = BitLength(substring); @@ -98092,7 +98182,7 @@ idx_t Bit::BitPosition(string_t substring, string_t bits) { return 0; } -idx_t Bit::GetBit(string_t bit_string, idx_t n) { +idx_t Bit::GetBit(bitstring_t bit_string, idx_t n) { return Bit::GetBitInternal(bit_string, n + GetBitPadding(bit_string)); } @@ -98100,7 +98190,7 @@ idx_t Bit::GetBitIndex(idx_t n) { return n / 8 + 1; } -idx_t Bit::GetBitInternal(string_t bit_string, idx_t n) { +idx_t Bit::GetBitInternal(bitstring_t bit_string, idx_t n) { const char *buf = bit_string.GetData(); auto idx = Bit::GetBitIndex(n); D_ASSERT(idx < bit_string.GetSize()); @@ -98108,12 +98198,12 @@ idx_t Bit::GetBitInternal(string_t bit_string, idx_t n) { return (byte & 1 ? 1 : 0); } -void Bit::SetBit(string_t &bit_string, idx_t n, idx_t new_value) { +void Bit::SetBit(bitstring_t &bit_string, idx_t n, idx_t new_value) { SetBitInternal(bit_string, n + GetBitPadding(bit_string), new_value); Bit::Finalize(bit_string); } -void Bit::SetBitInternal(string_t &bit_string, idx_t n, idx_t new_value) { +void Bit::SetBitInternal(bitstring_t &bit_string, idx_t n, idx_t new_value) { uint8_t *buf = reinterpret_cast(bit_string.GetDataWriteable()); auto idx = Bit::GetBitIndex(n); @@ -98128,39 +98218,41 @@ void Bit::SetBitInternal(string_t &bit_string, idx_t n, idx_t new_value) { } // **** BITWISE operators **** -void Bit::RightShift(const string_t &bit_string, const idx_t &shift, string_t &result) { +void Bit::RightShift(const bitstring_t &bit_string, idx_t shift, bitstring_t &result) { uint8_t *res_buf = reinterpret_cast(result.GetDataWriteable()); const uint8_t *buf = reinterpret_cast(bit_string.GetData()); res_buf[0] = buf[0]; + auto padding = GetBitPadding(result); for (idx_t i = 0; i < Bit::BitLength(result); i++) { if (i < shift) { - Bit::SetBit(result, i, 0); + Bit::SetBitInternal(result, i + padding, 0); } else { idx_t bit = Bit::GetBit(bit_string, i - shift); - Bit::SetBit(result, i, bit); + Bit::SetBitInternal(result, i + padding, bit); } } Bit::Finalize(result); } -void Bit::LeftShift(const string_t &bit_string, const idx_t &shift, string_t &result) { +void Bit::LeftShift(const bitstring_t &bit_string, idx_t shift, bitstring_t &result) { uint8_t *res_buf = reinterpret_cast(result.GetDataWriteable()); const uint8_t *buf = reinterpret_cast(bit_string.GetData()); res_buf[0] = buf[0]; + auto padding = GetBitPadding(result); for (idx_t i = 0; i < Bit::BitLength(bit_string); i++) { if (i < (Bit::BitLength(bit_string) - shift)) { idx_t bit = Bit::GetBit(bit_string, shift + i); - Bit::SetBit(result, i, bit); + Bit::SetBitInternal(result, i + padding, bit); } else { - Bit::SetBit(result, i, 0); + Bit::SetBitInternal(result, i + padding, 0); } } Bit::Finalize(result); } -void Bit::BitwiseAnd(const string_t &rhs, const string_t &lhs, string_t &result) { +void Bit::BitwiseAnd(const bitstring_t &rhs, const bitstring_t &lhs, bitstring_t &result) { if (Bit::BitLength(lhs) != Bit::BitLength(rhs)) { throw InvalidInputException("Cannot AND bit strings of different sizes"); } @@ -98176,7 +98268,7 @@ void Bit::BitwiseAnd(const string_t &rhs, const string_t &lhs, string_t &result) Bit::Finalize(result); } -void Bit::BitwiseOr(const string_t &rhs, const string_t &lhs, string_t &result) { +void Bit::BitwiseOr(const bitstring_t &rhs, const bitstring_t &lhs, bitstring_t &result) { if (Bit::BitLength(lhs) != Bit::BitLength(rhs)) { throw InvalidInputException("Cannot OR bit strings of different sizes"); } @@ -98192,7 +98284,7 @@ void Bit::BitwiseOr(const string_t &rhs, const string_t &lhs, string_t &result) Bit::Finalize(result); } -void Bit::BitwiseXor(const string_t &rhs, const string_t &lhs, string_t &result) { +void Bit::BitwiseXor(const bitstring_t &rhs, const bitstring_t &lhs, bitstring_t &result) { if (Bit::BitLength(lhs) != Bit::BitLength(rhs)) { throw InvalidInputException("Cannot XOR bit strings of different sizes"); } @@ -98208,7 +98300,7 @@ void Bit::BitwiseXor(const string_t &rhs, const string_t &lhs, string_t &result) Bit::Finalize(result); } -void Bit::BitwiseNot(const string_t &input, string_t &result) { +void Bit::BitwiseNot(const bitstring_t &input, bitstring_t &result) { uint8_t *result_buf = reinterpret_cast(result.GetDataWriteable()); const uint8_t *buf = reinterpret_cast(input.GetData()); @@ -98219,7 +98311,7 @@ void Bit::BitwiseNot(const string_t &input, string_t &result) { Bit::Finalize(result); } -void Bit::Verify(const string_t &input) { +void Bit::Verify(const bitstring_t &input) { #ifdef DEBUG // bit strings require all padding bits to be set to 1 auto padding = GetBitPadding(input); @@ -101255,50 +101347,53 @@ DataChunk::~DataChunk() { } void DataChunk::InitializeEmpty(const vector &types) { - InitializeEmpty(types.begin(), types.end()); -} - -void DataChunk::Initialize(Allocator &allocator, const vector &types, idx_t capacity_p) { - Initialize(allocator, types.begin(), types.end(), capacity_p); + D_ASSERT(data.empty()); + capacity = STANDARD_VECTOR_SIZE; + for (idx_t i = 0; i < types.size(); i++) { + data.emplace_back(types[i], nullptr); + } } void DataChunk::Initialize(ClientContext &context, const vector &types, idx_t capacity_p) { Initialize(Allocator::Get(context), types, capacity_p); } -idx_t DataChunk::GetAllocationSize() const { - idx_t total_size = 0; - auto cardinality = size(); - for (auto &vec : data) { - total_size += vec.GetAllocationSize(cardinality); - } - return total_size; +void DataChunk::Initialize(Allocator &allocator, const vector &types, idx_t capacity_p) { + auto initialize = vector(types.size(), true); + Initialize(allocator, types, initialize, capacity_p); } -void DataChunk::Initialize(Allocator &allocator, vector::const_iterator begin, - vector::const_iterator end, idx_t capacity_p) { - D_ASSERT(data.empty()); // can only be initialized once - D_ASSERT(std::distance(begin, end) != 0); // empty chunk not allowed +void DataChunk::Initialize(ClientContext &context, const vector &types, const vector &initialize, + idx_t capacity_p) { + Initialize(Allocator::Get(context), types, initialize, capacity_p); +} + +void DataChunk::Initialize(Allocator &allocator, const vector &types, const vector &initialize, + idx_t capacity_p) { + D_ASSERT(types.size() == initialize.size()); + D_ASSERT(data.empty()); + capacity = capacity_p; - for (; begin != end; begin++) { - VectorCache cache(allocator, *begin, capacity); + for (idx_t i = 0; i < types.size(); i++) { + if (!initialize[i]) { + data.emplace_back(types[i], nullptr); + vector_caches.emplace_back(); + continue; + } + + VectorCache cache(allocator, types[i], capacity); data.emplace_back(cache); vector_caches.push_back(std::move(cache)); } } -void DataChunk::Initialize(ClientContext &context, vector::const_iterator begin, - vector::const_iterator end, idx_t capacity_p) { - Initialize(Allocator::Get(context), begin, end, capacity_p); -} - -void DataChunk::InitializeEmpty(vector::const_iterator begin, vector::const_iterator end) { - capacity = STANDARD_VECTOR_SIZE; - D_ASSERT(data.empty()); // can only be initialized once - D_ASSERT(std::distance(begin, end) != 0); // empty chunk not allowed - for (; begin != end; begin++) { - data.emplace_back(*begin, nullptr); +idx_t DataChunk::GetAllocationSize() const { + idx_t total_size = 0; + auto cardinality = size(); + for (auto &vec : data) { + total_size += vec.GetAllocationSize(cardinality); } + return total_size; } void DataChunk::Reset() { @@ -117029,19 +117124,25 @@ class VectorCacheBuffer : public VectorBuffer { idx_t capacity; }; -VectorCache::VectorCache(Allocator &allocator, const LogicalType &type_p, idx_t capacity_p) { +VectorCache::VectorCache() : buffer(nullptr) { +} + +VectorCache::VectorCache(Allocator &allocator, const LogicalType &type_p, const idx_t capacity_p) { buffer = make_buffer(allocator, type_p, capacity_p); } void VectorCache::ResetFromCache(Vector &result) const { - D_ASSERT(buffer); - auto &vcache = buffer->Cast(); - vcache.ResetFromCache(result, buffer); + if (!buffer) { + return; + } + auto &vector_cache = buffer->Cast(); + vector_cache.ResetFromCache(result, buffer); } const LogicalType &VectorCache::GetType() const { - auto &vcache = buffer->Cast(); - return vcache.GetType(); + D_ASSERT(buffer); + auto &vector_cache = buffer->Cast(); + return vector_cache.GetType(); } } // namespace duckdb @@ -119558,6 +119659,10 @@ static void NestedComparisonExecutor(Vector &left, Vector &right, Vector &result if (!leftv.validity.AllValid() || !rightv.validity.AllValid()) { ComparesNotNull(leftv, rightv, result_validity, count); } + ValidityMask original_mask; + original_mask.SetAllValid(count); + original_mask.Copy(result_validity, count); + SelectionVector true_sel(count); SelectionVector false_sel(count); idx_t match_count = @@ -119566,12 +119671,19 @@ static void NestedComparisonExecutor(Vector &left, Vector &right, Vector &result for (idx_t i = 0; i < match_count; ++i) { const auto idx = true_sel.get_index(i); result_data[idx] = true; + // if the row was valid during the null check, set it to valid here as well + if (original_mask.RowIsValid(idx)) { + result_validity.SetValid(idx); + } } const idx_t no_match_count = count - match_count; for (idx_t i = 0; i < no_match_count; ++i) { const auto idx = false_sel.get_index(i); result_data[idx] = false; + if (original_mask.RowIsValid(idx)) { + result_validity.SetValid(idx); + } } } @@ -126204,8 +126316,8 @@ static AggregateFunction GetMinMaxOperator(const LogicalType &type) { auto internal_type = type.InternalType(); switch (internal_type) { case PhysicalType::VARCHAR: - return AggregateFunction::UnaryAggregateDestructor(type.id(), - type.id()); + return AggregateFunction::UnaryAggregateDestructor(type, + type); case PhysicalType::LIST: case PhysicalType::STRUCT: case PhysicalType::ARRAY: @@ -136680,7 +136792,7 @@ struct BitStringFun { static constexpr const char *Description = "Pads the bitstring until the specified length"; static constexpr const char *Example = "bitstring('1010'::BIT, 7)"; - static ScalarFunction GetFunction(); + static ScalarFunctionSet GetFunctions(); }; } // namespace duckdb @@ -137789,12 +137901,6 @@ struct ListNegativeDotProductFun { static constexpr const char *Name = "list_negative_dot_product"; }; -struct ListNegativeInnerProductFunAlias { - using ALIAS = ListNegativeInnerProductFun; - - static constexpr const char *Name = "<#>"; -}; - struct UnpivotListFun { static constexpr const char *Name = "unpivot_list"; static constexpr const char *Parameters = "any,..."; @@ -139351,7 +139457,6 @@ static const StaticFunctionDefinition internal_functions[] = { DUCKDB_SCALAR_FUNCTION_SET(BitwiseAndFun), DUCKDB_SCALAR_FUNCTION_ALIAS(ListHasAnyFunAlias), DUCKDB_SCALAR_FUNCTION(PowOperatorFun), - DUCKDB_SCALAR_FUNCTION_SET_ALIAS(ListNegativeInnerProductFunAlias), DUCKDB_SCALAR_FUNCTION_SET_ALIAS(ListDistanceFunAlias), DUCKDB_SCALAR_FUNCTION_SET(LeftShiftFun), DUCKDB_SCALAR_FUNCTION_SET_ALIAS(ListCosineDistanceFunAlias), @@ -139416,7 +139521,7 @@ static const StaticFunctionDefinition internal_functions[] = { DUCKDB_AGGREGATE_FUNCTION_SET(BitOrFun), DUCKDB_SCALAR_FUNCTION(BitPositionFun), DUCKDB_AGGREGATE_FUNCTION_SET(BitXorFun), - DUCKDB_SCALAR_FUNCTION(BitStringFun), + DUCKDB_SCALAR_FUNCTION_SET(BitStringFun), DUCKDB_AGGREGATE_FUNCTION_SET(BitstringAggFun), DUCKDB_AGGREGATE_FUNCTION(BoolAndFun), DUCKDB_AGGREGATE_FUNCTION(BoolOrFun), @@ -140902,28 +141007,46 @@ namespace duckdb { //===--------------------------------------------------------------------===// // BitStringFunction //===--------------------------------------------------------------------===// +template static void BitStringFunction(DataChunk &args, ExpressionState &state, Vector &result) { BinaryExecutor::Execute( args.data[0], args.data[1], result, args.size(), [&](string_t input, int32_t n) { if (n < 0) { throw InvalidInputException("The bitstring length cannot be negative"); } - if (idx_t(n) < input.GetSize()) { + idx_t input_length; + if (FROM_STRING) { + input_length = input.GetSize(); + } else { + input_length = Bit::BitLength(input); + } + if (idx_t(n) < input_length) { throw InvalidInputException("Length must be equal or larger than input string"); } idx_t len; - Bit::TryGetBitStringSize(input, len, nullptr); // string verification + if (FROM_STRING) { + Bit::TryGetBitStringSize(input, len, nullptr); // string verification + } len = Bit::ComputeBitstringLen(UnsafeNumericCast(n)); string_t target = StringVector::EmptyString(result, len); - Bit::BitString(input, UnsafeNumericCast(n), target); + if (FROM_STRING) { + Bit::BitString(input, UnsafeNumericCast(n), target); + } else { + Bit::ExtendBitString(input, UnsafeNumericCast(n), target); + } target.Finalize(); return target; }); } -ScalarFunction BitStringFun::GetFunction() { - return ScalarFunction({LogicalType::VARCHAR, LogicalType::INTEGER}, LogicalType::BIT, BitStringFunction); +ScalarFunctionSet BitStringFun::GetFunctions() { + ScalarFunctionSet bitstring; + bitstring.AddFunction( + ScalarFunction({LogicalType::VARCHAR, LogicalType::INTEGER}, LogicalType::BIT, BitStringFunction)); + bitstring.AddFunction( + ScalarFunction({LogicalType::BIT, LogicalType::INTEGER}, LogicalType::BIT, BitStringFunction)); + return bitstring; } //===--------------------------------------------------------------------===// @@ -142182,6 +142305,14 @@ struct DateDiff { }); } + // We need to truncate down, not towards 0 + static inline int64_t Truncate(int64_t value, int64_t units) { + return (value + (value < 0)) / units - (value < 0); + } + static inline int64_t Diff(int64_t start, int64_t end, int64_t units) { + return Truncate(end, units) - Truncate(start, units); + } + struct YearOperator { template static inline TR Operation(TA startdate, TB enddate) { @@ -142358,30 +142489,28 @@ template <> int64_t DateDiff::MillisecondsOperator::Operation(timestamp_t startdate, timestamp_t enddate) { D_ASSERT(Timestamp::IsFinite(startdate)); D_ASSERT(Timestamp::IsFinite(enddate)); - return Timestamp::GetEpochMs(enddate) - Timestamp::GetEpochMs(startdate); + return Diff(startdate.value, enddate.value, Interval::MICROS_PER_MSEC); } template <> int64_t DateDiff::SecondsOperator::Operation(timestamp_t startdate, timestamp_t enddate) { D_ASSERT(Timestamp::IsFinite(startdate)); D_ASSERT(Timestamp::IsFinite(enddate)); - return Timestamp::GetEpochSeconds(enddate) - Timestamp::GetEpochSeconds(startdate); + return Diff(startdate.value, enddate.value, Interval::MICROS_PER_SEC); } template <> int64_t DateDiff::MinutesOperator::Operation(timestamp_t startdate, timestamp_t enddate) { D_ASSERT(Timestamp::IsFinite(startdate)); D_ASSERT(Timestamp::IsFinite(enddate)); - return Timestamp::GetEpochSeconds(enddate) / Interval::SECS_PER_MINUTE - - Timestamp::GetEpochSeconds(startdate) / Interval::SECS_PER_MINUTE; + return Diff(startdate.value, enddate.value, Interval::MICROS_PER_MINUTE); } template <> int64_t DateDiff::HoursOperator::Operation(timestamp_t startdate, timestamp_t enddate) { D_ASSERT(Timestamp::IsFinite(startdate)); D_ASSERT(Timestamp::IsFinite(enddate)); - return Timestamp::GetEpochSeconds(enddate) / Interval::SECS_PER_HOUR - - Timestamp::GetEpochSeconds(startdate) / Interval::SECS_PER_HOUR; + return Diff(startdate.value, enddate.value, Interval::MICROS_PER_HOUR); } // TIME specialisations @@ -158760,10 +158889,10 @@ namespace duckdb { */ struct ht_entry_t { // NOLINT public: - //! Upper 16 bits are salt - static constexpr const hash_t SALT_MASK = 0xFFFF000000000000; - //! Lower 48 bits are the pointer - static constexpr const hash_t POINTER_MASK = 0x0000FFFFFFFFFFFF; + //! Upper 12 bits are salt + static constexpr const hash_t SALT_MASK = 0xFFF0000000000000; + //! Lower 52 bits are the pointer + static constexpr const hash_t POINTER_MASK = 0x000FFFFFFFFFFFFF; explicit inline ht_entry_t(hash_t value_p) noexcept : value(value_p) { } @@ -160398,9 +160527,10 @@ static idx_t BetweenLoopTypeSwitch(Vector &input, Vector &lower, Vector &upper, unique_ptr ExpressionExecutor::InitializeState(const BoundBetweenExpression &expr, ExpressionExecutorState &root) { auto result = make_uniq(expr, root); - result->AddChild(expr.input.get()); - result->AddChild(expr.lower.get()); - result->AddChild(expr.upper.get()); + result->AddChild(*expr.input); + result->AddChild(*expr.lower); + result->AddChild(*expr.upper); + result->Finalize(); return result; } @@ -160528,10 +160658,11 @@ unique_ptr ExpressionExecutor::InitializeState(const BoundCaseE ExpressionExecutorState &root) { auto result = make_uniq(expr, root); for (auto &case_check : expr.case_checks) { - result->AddChild(case_check.when_expr.get()); - result->AddChild(case_check.then_expr.get()); + result->AddChild(*case_check.when_expr); + result->AddChild(*case_check.then_expr); } - result->AddChild(expr.else_expr.get()); + result->AddChild(*expr.else_expr); + result->Finalize(); return std::move(result); } @@ -160743,8 +160874,9 @@ namespace duckdb { unique_ptr ExpressionExecutor::InitializeState(const BoundCastExpression &expr, ExpressionExecutorState &root) { auto result = make_uniq(expr, root); - result->AddChild(expr.child.get()); + result->AddChild(*expr.child); result->Finalize(); + if (expr.bound_cast.init_local_state) { CastLocalStateParameters parameters(root.executor->GetContext(), expr.bound_cast.cast_data); result->local_state = expr.bound_cast.init_local_state(parameters); @@ -160792,8 +160924,9 @@ namespace duckdb { unique_ptr ExpressionExecutor::InitializeState(const BoundComparisonExpression &expr, ExpressionExecutorState &root) { auto result = make_uniq(expr, root); - result->AddChild(expr.left.get()); - result->AddChild(expr.right.get()); + result->AddChild(*expr.left); + result->AddChild(*expr.right); + result->Finalize(); return result; } @@ -161179,8 +161312,9 @@ unique_ptr ExpressionExecutor::InitializeState(const BoundConju ExpressionExecutorState &root) { auto result = make_uniq(expr, root); for (auto &child : expr.children) { - result->AddChild(child.get()); + result->AddChild(*child); } + result->Finalize(); return std::move(result); } @@ -161334,8 +161468,9 @@ unique_ptr ExpressionExecutor::InitializeState(const BoundFunct ExpressionExecutorState &root) { auto result = make_uniq(expr, root); for (auto &child : expr.children) { - result->AddChild(child.get()); + result->AddChild(*child); } + result->Finalize(); if (expr.function.init_local_state) { result->local_state = expr.function.init_local_state(*result, expr, expr.bind_info.get()); @@ -161446,8 +161581,9 @@ unique_ptr ExpressionExecutor::InitializeState(const BoundOpera ExpressionExecutorState &root) { auto result = make_uniq(expr, root); for (auto &child : expr.children) { - result->AddChild(child.get()); + result->AddChild(*child); } + result->Finalize(); return result; } @@ -161604,7 +161740,7 @@ namespace duckdb { unique_ptr ExpressionExecutor::InitializeState(const BoundReferenceExpression &expr, ExpressionExecutorState &root) { auto result = make_uniq(expr, root); - result->Finalize(true); + result->Finalize(); return result; } @@ -162090,10 +162226,16 @@ unique_ptr ExpressionExecutor::InitializeState(const Expression void ExpressionExecutor::Execute(const Expression &expr, ExpressionState *state, const SelectionVector *sel, idx_t count, Vector &result) { #ifdef DEBUG - // the result vector has to be used for the first time or has to be reset - // otherwise, the validity mask might contain previous (now incorrect) data + // The result vector must be used for the first time, or must be reset. + // Otherwise, the validity mask can contain previous (now incorrect) data. if (result.GetVectorType() == VectorType::FLAT_VECTOR) { - D_ASSERT(FlatVector::Validity(result).CheckAllValid(count)); + + // We do not initialize vector caches for these expressions. + if (expr.GetExpressionClass() != ExpressionClass::BOUND_REF && + expr.GetExpressionClass() != ExpressionClass::BOUND_CONSTANT && + expr.GetExpressionClass() != ExpressionClass::BOUND_PARAMETER) { + D_ASSERT(FlatVector::Validity(result).CheckAllValid(count)); + } } #endif @@ -162237,20 +162379,22 @@ vector> &ExpressionExecutor::GetStates() { namespace duckdb { -void ExpressionState::AddChild(Expression *expr) { - types.push_back(expr->return_type); - child_states.push_back(ExpressionExecutor::InitializeState(*expr, root)); +void ExpressionState::AddChild(Expression &child_expr) { + types.push_back(child_expr.return_type); + auto child_state = ExpressionExecutor::InitializeState(child_expr, root); + child_states.push_back(std::move(child_state)); + + auto expr_class = child_expr.GetExpressionClass(); + auto initialize_child = expr_class != ExpressionClass::BOUND_REF && expr_class != ExpressionClass::BOUND_CONSTANT && + expr_class != ExpressionClass::BOUND_PARAMETER; + initialize.push_back(initialize_child); } -void ExpressionState::Finalize(bool empty) { +void ExpressionState::Finalize() { if (types.empty()) { return; } - if (empty) { - intermediate_chunk.InitializeEmpty(types); - } else { - intermediate_chunk.Initialize(GetAllocator(), types); - } + intermediate_chunk.Initialize(GetAllocator(), types, initialize); } Allocator &ExpressionState::GetAllocator() { @@ -171566,15 +171710,17 @@ void PhysicalHashAggregate::SinkDistinctGrouping(ExecutionContext &context, Data for (idx_t group_idx = 0; group_idx < grouped_aggregate_data.groups.size(); group_idx++) { auto &group = grouped_aggregate_data.groups[group_idx]; auto &bound_ref = group->Cast(); - filtered_input.data[bound_ref.index].Reference(chunk.data[bound_ref.index]); + auto &col = filtered_input.data[bound_ref.index]; + col.Reference(chunk.data[bound_ref.index]); + col.Slice(sel_vec, count); } for (idx_t child_idx = 0; child_idx < aggregate.children.size(); child_idx++) { auto &child = aggregate.children[child_idx]; auto &bound_ref = child->Cast(); - - filtered_input.data[bound_ref.index].Reference(chunk.data[bound_ref.index]); + auto &col = filtered_input.data[bound_ref.index]; + col.Reference(chunk.data[bound_ref.index]); + col.Slice(sel_vec, count); } - filtered_input.Slice(sel_vec, count); filtered_input.SetCardinality(count); radix_table.Sink(context, filtered_input, sink_input, empty_chunk, empty_filter); @@ -179966,10 +180112,6 @@ void StringValueScanner::SetStart() { } return; } - if (state_machine->options.IgnoreErrors()) { - // If we are ignoring errors we don't really need to figure out a line. - return; - } // The result size of the data after skipping the row is one line // We have to look for a new line that fits our schema // 1. We walk until the next new line @@ -180139,7 +180281,7 @@ void MatchAndReplace(CSVOption &original, CSVOption &sniffed, const string // We verify that the user input matches the sniffed value if (original != sniffed) { error += "CSV Sniffer: Sniffer detected value different than the user input for the " + name; - error += " options \n Set: " + original.FormatValue() + " Sniffed: " + sniffed.FormatValue() + "\n"; + error += " options \n Set: " + original.FormatValue() + ", Sniffed: " + sniffed.FormatValue() + "\n"; } } else { // We replace the value of original with the sniffed value @@ -180326,8 +180468,8 @@ SnifferResult CSVSniffer::SniffCSV(bool force_match) { if (set_names.size() == names.size()) { for (idx_t i = 0; i < set_columns.Size(); i++) { if (set_names[i] != names[i]) { - header_error += "Column at position: " + to_string(i) + " Set name: " + set_names[i] + - " Sniffed Name: " + names[i] + "\n"; + header_error += "Column at position: " + to_string(i) + ", Set name: " + set_names[i] + + ", Sniffed Name: " + names[i] + "\n"; match = false; } } @@ -180715,7 +180857,7 @@ void CSVSniffer::AnalyzeDialectCandidate(unique_ptr scanner, (single_column_before || (more_values && !require_more_padding) || (more_than_one_column && require_less_padding)) && !invalid_padding && comments_are_acceptable) { - if (!candidates.empty() && set_columns.IsSet() && max_columns_found == candidates.size()) { + if (!candidates.empty() && set_columns.IsSet() && max_columns_found == set_columns.Size()) { // We have a candidate that fits our requirements better return; } @@ -181017,9 +181159,9 @@ bool CSVSniffer::DetectHeaderWithSetColumn(ClientContext &context, vector
MAX_BUILD_SIZE) { return; } - if (NumericStats::Min(stats_build) <= NumericStats::Min(stats_probe) && - NumericStats::Max(stats_probe) <= NumericStats::Max(stats_build)) { - join_state.is_probe_in_domain = true; - } join_state.is_build_small = true; return; } @@ -210336,7 +210472,7 @@ unique_ptr ReservoirSample::GetChunk() { for (idx_t i = samples_remaining; i < collected_sample_count; i++) { sel.set_index(i - samples_remaining, i); } - ret->Initialize(allocator, reservoir_types.begin(), reservoir_types.end(), STANDARD_VECTOR_SIZE); + ret->Initialize(allocator, reservoir_types); ret->Slice(*reservoir_data_chunk, sel, STANDARD_VECTOR_SIZE); ret->SetCardinality(STANDARD_VECTOR_SIZE); // reduce capacity and cardinality of the sample data chunk @@ -232326,6 +232462,19 @@ static unique_ptr GetArrowExtensionType(const ArrowSchemaMetadata &ex auto type_info = make_uniq(ArrowVariableSizeType::SUPER_SIZE); return make_uniq(LogicalType::BIT, std::move(type_info)); + } else if (arrow_extension == "duckdb.varint") { + if (format != "z" && format != "Z") { + std::ostringstream error; + error << "duckdb.bit must be a blob (i.e., \'z\'). It is incorrectly defined as:" << format; + return make_uniq(error.str()); + } + unique_ptr type_info; + if (format == "z") { + type_info = make_uniq(ArrowVariableSizeType::NORMAL); + } else { + type_info = make_uniq(ArrowVariableSizeType::SUPER_SIZE); + } + return make_uniq(LogicalType::VARINT, std::move(type_info)); } else { std::ostringstream error; error << "Arrow Type with extension name: " << arrow_extension << " and format: " << format @@ -233847,7 +233996,8 @@ static void ColumnArrowToDuckDB(Vector &vector, ArrowArray &array, ArrowArraySca break; } case LogicalTypeId::BLOB: - case LogicalTypeId::BIT: { + case LogicalTypeId::BIT: + case LogicalTypeId::VARINT: { ArrowToDuckDBBlob(vector, array, scan_state, size, arrow_type, nested_offset, NumericCast(parent_offset)); break; @@ -235835,7 +235985,6 @@ void ReadCSVTableFunction::ReadCSVAddNamedParameters(TableFunction &table_functi table_function.named_parameters["types"] = LogicalType::ANY; table_function.named_parameters["names"] = LogicalType::LIST(LogicalType::VARCHAR); table_function.named_parameters["column_names"] = LogicalType::LIST(LogicalType::VARCHAR); - table_function.named_parameters["parallel"] = LogicalType::BOOLEAN; table_function.named_parameters["comment"] = LogicalType::VARCHAR; MultiFileReader::AddParameters(table_function); @@ -239115,13 +239264,21 @@ void DuckDBSecretsFunction(ClientContext &context, TableFunctionInput &data_p, D const auto &secret = *secret_entry.secret; - output.SetValue(0, count, secret.GetName()); - output.SetValue(1, count, Value(secret.GetType())); - output.SetValue(2, count, Value(secret.GetProvider())); - output.SetValue(3, count, Value(secret_entry.persist_type == SecretPersistType::PERSISTENT)); - output.SetValue(4, count, Value(secret_entry.storage_mode)); - output.SetValue(5, count, Value::LIST(LogicalType::VARCHAR, scope_value)); - output.SetValue(6, count, secret.ToString(bind_data.redact)); + idx_t i = 0; + // name + output.SetValue(i++, count, secret.GetName()); + // type + output.SetValue(i++, count, Value(secret.GetType())); + // provider + output.SetValue(i++, count, Value(secret.GetProvider())); + // persistent + output.SetValue(i++, count, Value(secret_entry.persist_type == SecretPersistType::PERSISTENT)); + // storage + output.SetValue(i++, count, Value(secret_entry.storage_mode)); + // scope + output.SetValue(i++, count, Value::LIST(LogicalType::VARCHAR, scope_value)); + // secret_string + output.SetValue(i++, count, secret.ToString(bind_data.redact)); data.offset++; count++; @@ -242544,6 +242701,9 @@ Appender::Appender(Connection &con, const string &schema_name, const string &tab } vector> defaults; for (auto &column : description->columns) { + if (column.Generated()) { + continue; + } types.push_back(column.Type()); defaults.push_back(column.HasDefaultValue() ? &column.DefaultValue() : nullptr); } @@ -247415,7 +247575,7 @@ duckdb_value duckdb_profiling_info_get_value(duckdb_profiling_info info, const c auto &node = *reinterpret_cast(info); auto &profiling_info = node.GetProfilingInfo(); auto key_enum = EnumUtil::FromString(duckdb::StringUtil::Upper(key)); - if (!profiling_info.Enabled(key_enum)) { + if (!profiling_info.Enabled(profiling_info.settings, key_enum)) { return nullptr; } @@ -247431,10 +247591,13 @@ duckdb_value duckdb_profiling_info_get_metrics(duckdb_profiling_info info) { auto &node = *reinterpret_cast(info); auto &profiling_info = node.GetProfilingInfo(); - // FIXME: filter between operator metrics and query node metrics. duckdb::unordered_map metrics_map; for (const auto &metric : profiling_info.metrics) { auto key = EnumUtil::ToString(metric.first); + if (!profiling_info.Enabled(profiling_info.settings, metric.first)) { + continue; + } + if (key == EnumUtil::ToString(MetricsType::OPERATOR_TYPE)) { auto type = duckdb::PhysicalOperatorType(metric.second.GetValue()); metrics_map[key] = EnumUtil::ToString(type); @@ -251225,13 +251388,19 @@ void ClientContext::Append(TableDescription &description, ColumnDataCollection & auto &table_entry = Catalog::GetEntry(*this, INVALID_CATALOG, description.schema, description.table); // verify that the table columns and types match up - if (description.columns.size() != table_entry.GetColumns().PhysicalColumnCount()) { + if (description.PhysicalColumnCount() != table_entry.GetColumns().PhysicalColumnCount()) { throw InvalidInputException("Failed to append: table entry has different number of columns!"); } + idx_t table_entry_col_idx = 0; for (idx_t i = 0; i < description.columns.size(); i++) { - if (description.columns[i].Type() != table_entry.GetColumns().GetColumn(PhysicalIndex(i)).Type()) { + auto &column = description.columns[i]; + if (column.Generated()) { + continue; + } + if (column.Type() != table_entry.GetColumns().GetColumn(PhysicalIndex(table_entry_col_idx)).Type()) { throw InvalidInputException("Failed to append: table entry has different number of columns!"); } + table_entry_col_idx++; } auto binder = Binder::CreateBinder(*this); auto bound_constraints = binder->BindConstraints(table_entry); @@ -253497,6 +253666,7 @@ class StandardBufferManager : public BufferManager { + #ifndef DUCKDB_NO_THREADS #endif @@ -253527,6 +253697,7 @@ DBConfig::~DBConfig() { DatabaseInstance::DatabaseInstance() { config.is_user_config = false; + create_api_v0 = nullptr; } DatabaseInstance::~DatabaseInstance() { @@ -253729,6 +253900,10 @@ void DatabaseInstance::LoadExtensionSettings() { } } +static duckdb_ext_api_v0 CreateAPIv0Wrapper() { + return CreateAPIv0(); +} + void DatabaseInstance::Initialize(const char *database_path, DBConfig *user_config) { DBConfig default_config; DBConfig *config_ptr = &default_config; @@ -253738,6 +253913,8 @@ void DatabaseInstance::Initialize(const char *database_path, DBConfig *user_conf Configure(*config_ptr, database_path); + create_api_v0 = CreateAPIv0Wrapper; + if (user_config && !user_config->options.use_temporary_directory) { // temporary directories explicitly disabled config.options.temporary_directory = string(); @@ -253975,6 +254152,11 @@ ValidChecker &DatabaseInstance::GetValidChecker() { return db_validity; } +const duckdb_ext_api_v0 DatabaseInstance::GetExtensionAPIV0() { + D_ASSERT(create_api_v0); + return create_api_v0(); +} + ValidChecker &ValidChecker::Get(DatabaseInstance &db) { return db.GetValidChecker(); } @@ -265552,815 +265734,6 @@ inline std::string GetDLError(void) { -//===--------------------------------------------------------------------===// -// Function pointer struct -//===--------------------------------------------------------------------===// -typedef struct { - // v0.0.1 - duckdb_state (*duckdb_open)(const char *path, duckdb_database *out_database); - duckdb_state (*duckdb_open_ext)(const char *path, duckdb_database *out_database, duckdb_config config, - char **out_error); - void (*duckdb_close)(duckdb_database *database); - duckdb_state (*duckdb_connect)(duckdb_database database, duckdb_connection *out_connection); - void (*duckdb_interrupt)(duckdb_connection connection); - duckdb_query_progress_type (*duckdb_query_progress)(duckdb_connection connection); - void (*duckdb_disconnect)(duckdb_connection *connection); - const char *(*duckdb_library_version)(); - duckdb_state (*duckdb_create_config)(duckdb_config *out_config); - size_t (*duckdb_config_count)(); - duckdb_state (*duckdb_get_config_flag)(size_t index, const char **out_name, const char **out_description); - duckdb_state (*duckdb_set_config)(duckdb_config config, const char *name, const char *option); - void (*duckdb_destroy_config)(duckdb_config *config); - duckdb_state (*duckdb_query)(duckdb_connection connection, const char *query, duckdb_result *out_result); - void (*duckdb_destroy_result)(duckdb_result *result); - const char *(*duckdb_column_name)(duckdb_result *result, idx_t col); - duckdb_type (*duckdb_column_type)(duckdb_result *result, idx_t col); - duckdb_statement_type (*duckdb_result_statement_type)(duckdb_result result); - duckdb_logical_type (*duckdb_column_logical_type)(duckdb_result *result, idx_t col); - idx_t (*duckdb_column_count)(duckdb_result *result); - idx_t (*duckdb_rows_changed)(duckdb_result *result); - const char *(*duckdb_result_error)(duckdb_result *result); - void *(*duckdb_malloc)(size_t size); - void (*duckdb_free)(void *ptr); - idx_t (*duckdb_vector_size)(); - bool (*duckdb_string_is_inlined)(duckdb_string_t string); - duckdb_date_struct (*duckdb_from_date)(duckdb_date date); - duckdb_date (*duckdb_to_date)(duckdb_date_struct date); - bool (*duckdb_is_finite_date)(duckdb_date date); - duckdb_time_struct (*duckdb_from_time)(duckdb_time time); - duckdb_time_tz (*duckdb_create_time_tz)(int64_t micros, int32_t offset); - duckdb_time_tz_struct (*duckdb_from_time_tz)(duckdb_time_tz micros); - duckdb_time (*duckdb_to_time)(duckdb_time_struct time); - duckdb_timestamp_struct (*duckdb_from_timestamp)(duckdb_timestamp ts); - duckdb_timestamp (*duckdb_to_timestamp)(duckdb_timestamp_struct ts); - bool (*duckdb_is_finite_timestamp)(duckdb_timestamp ts); - double (*duckdb_hugeint_to_double)(duckdb_hugeint val); - duckdb_hugeint (*duckdb_double_to_hugeint)(double val); - double (*duckdb_uhugeint_to_double)(duckdb_uhugeint val); - duckdb_uhugeint (*duckdb_double_to_uhugeint)(double val); - duckdb_decimal (*duckdb_double_to_decimal)(double val, uint8_t width, uint8_t scale); - double (*duckdb_decimal_to_double)(duckdb_decimal val); - duckdb_state (*duckdb_prepare)(duckdb_connection connection, const char *query, - duckdb_prepared_statement *out_prepared_statement); - void (*duckdb_destroy_prepare)(duckdb_prepared_statement *prepared_statement); - const char *(*duckdb_prepare_error)(duckdb_prepared_statement prepared_statement); - idx_t (*duckdb_nparams)(duckdb_prepared_statement prepared_statement); - const char *(*duckdb_parameter_name)(duckdb_prepared_statement prepared_statement, idx_t index); - duckdb_type (*duckdb_param_type)(duckdb_prepared_statement prepared_statement, idx_t param_idx); - duckdb_state (*duckdb_clear_bindings)(duckdb_prepared_statement prepared_statement); - duckdb_statement_type (*duckdb_prepared_statement_type)(duckdb_prepared_statement statement); - duckdb_state (*duckdb_bind_value)(duckdb_prepared_statement prepared_statement, idx_t param_idx, duckdb_value val); - duckdb_state (*duckdb_bind_parameter_index)(duckdb_prepared_statement prepared_statement, idx_t *param_idx_out, - const char *name); - duckdb_state (*duckdb_bind_boolean)(duckdb_prepared_statement prepared_statement, idx_t param_idx, bool val); - duckdb_state (*duckdb_bind_int8)(duckdb_prepared_statement prepared_statement, idx_t param_idx, int8_t val); - duckdb_state (*duckdb_bind_int16)(duckdb_prepared_statement prepared_statement, idx_t param_idx, int16_t val); - duckdb_state (*duckdb_bind_int32)(duckdb_prepared_statement prepared_statement, idx_t param_idx, int32_t val); - duckdb_state (*duckdb_bind_int64)(duckdb_prepared_statement prepared_statement, idx_t param_idx, int64_t val); - duckdb_state (*duckdb_bind_hugeint)(duckdb_prepared_statement prepared_statement, idx_t param_idx, - duckdb_hugeint val); - duckdb_state (*duckdb_bind_uhugeint)(duckdb_prepared_statement prepared_statement, idx_t param_idx, - duckdb_uhugeint val); - duckdb_state (*duckdb_bind_decimal)(duckdb_prepared_statement prepared_statement, idx_t param_idx, - duckdb_decimal val); - duckdb_state (*duckdb_bind_uint8)(duckdb_prepared_statement prepared_statement, idx_t param_idx, uint8_t val); - duckdb_state (*duckdb_bind_uint16)(duckdb_prepared_statement prepared_statement, idx_t param_idx, uint16_t val); - duckdb_state (*duckdb_bind_uint32)(duckdb_prepared_statement prepared_statement, idx_t param_idx, uint32_t val); - duckdb_state (*duckdb_bind_uint64)(duckdb_prepared_statement prepared_statement, idx_t param_idx, uint64_t val); - duckdb_state (*duckdb_bind_float)(duckdb_prepared_statement prepared_statement, idx_t param_idx, float val); - duckdb_state (*duckdb_bind_double)(duckdb_prepared_statement prepared_statement, idx_t param_idx, double val); - duckdb_state (*duckdb_bind_date)(duckdb_prepared_statement prepared_statement, idx_t param_idx, duckdb_date val); - duckdb_state (*duckdb_bind_time)(duckdb_prepared_statement prepared_statement, idx_t param_idx, duckdb_time val); - duckdb_state (*duckdb_bind_timestamp)(duckdb_prepared_statement prepared_statement, idx_t param_idx, - duckdb_timestamp val); - duckdb_state (*duckdb_bind_timestamp_tz)(duckdb_prepared_statement prepared_statement, idx_t param_idx, - duckdb_timestamp val); - duckdb_state (*duckdb_bind_interval)(duckdb_prepared_statement prepared_statement, idx_t param_idx, - duckdb_interval val); - duckdb_state (*duckdb_bind_varchar)(duckdb_prepared_statement prepared_statement, idx_t param_idx, const char *val); - duckdb_state (*duckdb_bind_varchar_length)(duckdb_prepared_statement prepared_statement, idx_t param_idx, - const char *val, idx_t length); - duckdb_state (*duckdb_bind_blob)(duckdb_prepared_statement prepared_statement, idx_t param_idx, const void *data, - idx_t length); - duckdb_state (*duckdb_bind_null)(duckdb_prepared_statement prepared_statement, idx_t param_idx); - duckdb_state (*duckdb_execute_prepared)(duckdb_prepared_statement prepared_statement, duckdb_result *out_result); - idx_t (*duckdb_extract_statements)(duckdb_connection connection, const char *query, - duckdb_extracted_statements *out_extracted_statements); - duckdb_state (*duckdb_prepare_extracted_statement)(duckdb_connection connection, - duckdb_extracted_statements extracted_statements, idx_t index, - duckdb_prepared_statement *out_prepared_statement); - const char *(*duckdb_extract_statements_error)(duckdb_extracted_statements extracted_statements); - void (*duckdb_destroy_extracted)(duckdb_extracted_statements *extracted_statements); - duckdb_state (*duckdb_pending_prepared)(duckdb_prepared_statement prepared_statement, - duckdb_pending_result *out_result); - void (*duckdb_destroy_pending)(duckdb_pending_result *pending_result); - const char *(*duckdb_pending_error)(duckdb_pending_result pending_result); - duckdb_pending_state (*duckdb_pending_execute_task)(duckdb_pending_result pending_result); - duckdb_pending_state (*duckdb_pending_execute_check_state)(duckdb_pending_result pending_result); - duckdb_state (*duckdb_execute_pending)(duckdb_pending_result pending_result, duckdb_result *out_result); - bool (*duckdb_pending_execution_is_finished)(duckdb_pending_state pending_state); - void (*duckdb_destroy_value)(duckdb_value *value); - duckdb_value (*duckdb_create_varchar)(const char *text); - duckdb_value (*duckdb_create_varchar_length)(const char *text, idx_t length); - duckdb_value (*duckdb_create_int64)(int64_t val); - duckdb_value (*duckdb_create_struct_value)(duckdb_logical_type type, duckdb_value *values); - duckdb_value (*duckdb_create_list_value)(duckdb_logical_type type, duckdb_value *values, idx_t value_count); - duckdb_value (*duckdb_create_array_value)(duckdb_logical_type type, duckdb_value *values, idx_t value_count); - char *(*duckdb_get_varchar)(duckdb_value value); - int64_t (*duckdb_get_int64)(duckdb_value val); - duckdb_logical_type (*duckdb_create_logical_type)(duckdb_type type); - char *(*duckdb_logical_type_get_alias)(duckdb_logical_type type); - duckdb_logical_type (*duckdb_create_list_type)(duckdb_logical_type type); - duckdb_logical_type (*duckdb_create_array_type)(duckdb_logical_type type, idx_t array_size); - duckdb_logical_type (*duckdb_create_map_type)(duckdb_logical_type key_type, duckdb_logical_type value_type); - duckdb_logical_type (*duckdb_create_union_type)(duckdb_logical_type *member_types, const char **member_names, - idx_t member_count); - duckdb_logical_type (*duckdb_create_struct_type)(duckdb_logical_type *member_types, const char **member_names, - idx_t member_count); - duckdb_logical_type (*duckdb_create_enum_type)(const char **member_names, idx_t member_count); - duckdb_logical_type (*duckdb_create_decimal_type)(uint8_t width, uint8_t scale); - duckdb_type (*duckdb_get_type_id)(duckdb_logical_type type); - uint8_t (*duckdb_decimal_width)(duckdb_logical_type type); - uint8_t (*duckdb_decimal_scale)(duckdb_logical_type type); - duckdb_type (*duckdb_decimal_internal_type)(duckdb_logical_type type); - duckdb_type (*duckdb_enum_internal_type)(duckdb_logical_type type); - uint32_t (*duckdb_enum_dictionary_size)(duckdb_logical_type type); - char *(*duckdb_enum_dictionary_value)(duckdb_logical_type type, idx_t index); - duckdb_logical_type (*duckdb_list_type_child_type)(duckdb_logical_type type); - duckdb_logical_type (*duckdb_array_type_child_type)(duckdb_logical_type type); - idx_t (*duckdb_array_type_array_size)(duckdb_logical_type type); - duckdb_logical_type (*duckdb_map_type_key_type)(duckdb_logical_type type); - duckdb_logical_type (*duckdb_map_type_value_type)(duckdb_logical_type type); - idx_t (*duckdb_struct_type_child_count)(duckdb_logical_type type); - char *(*duckdb_struct_type_child_name)(duckdb_logical_type type, idx_t index); - duckdb_logical_type (*duckdb_struct_type_child_type)(duckdb_logical_type type, idx_t index); - idx_t (*duckdb_union_type_member_count)(duckdb_logical_type type); - char *(*duckdb_union_type_member_name)(duckdb_logical_type type, idx_t index); - duckdb_logical_type (*duckdb_union_type_member_type)(duckdb_logical_type type, idx_t index); - void (*duckdb_destroy_logical_type)(duckdb_logical_type *type); - duckdb_data_chunk (*duckdb_fetch_chunk)(duckdb_result result); - duckdb_data_chunk (*duckdb_create_data_chunk)(duckdb_logical_type *types, idx_t column_count); - void (*duckdb_destroy_data_chunk)(duckdb_data_chunk *chunk); - void (*duckdb_data_chunk_reset)(duckdb_data_chunk chunk); - idx_t (*duckdb_data_chunk_get_column_count)(duckdb_data_chunk chunk); - duckdb_vector (*duckdb_data_chunk_get_vector)(duckdb_data_chunk chunk, idx_t col_idx); - idx_t (*duckdb_data_chunk_get_size)(duckdb_data_chunk chunk); - void (*duckdb_data_chunk_set_size)(duckdb_data_chunk chunk, idx_t size); - duckdb_logical_type (*duckdb_vector_get_column_type)(duckdb_vector vector); - void *(*duckdb_vector_get_data)(duckdb_vector vector); - uint64_t *(*duckdb_vector_get_validity)(duckdb_vector vector); - void (*duckdb_vector_ensure_validity_writable)(duckdb_vector vector); - void (*duckdb_vector_assign_string_element)(duckdb_vector vector, idx_t index, const char *str); - void (*duckdb_vector_assign_string_element_len)(duckdb_vector vector, idx_t index, const char *str, idx_t str_len); - duckdb_vector (*duckdb_list_vector_get_child)(duckdb_vector vector); - idx_t (*duckdb_list_vector_get_size)(duckdb_vector vector); - duckdb_state (*duckdb_list_vector_set_size)(duckdb_vector vector, idx_t size); - duckdb_state (*duckdb_list_vector_reserve)(duckdb_vector vector, idx_t required_capacity); - duckdb_vector (*duckdb_struct_vector_get_child)(duckdb_vector vector, idx_t index); - duckdb_vector (*duckdb_array_vector_get_child)(duckdb_vector vector); - bool (*duckdb_validity_row_is_valid)(uint64_t *validity, idx_t row); - void (*duckdb_validity_set_row_validity)(uint64_t *validity, idx_t row, bool valid); - void (*duckdb_validity_set_row_invalid)(uint64_t *validity, idx_t row); - void (*duckdb_validity_set_row_valid)(uint64_t *validity, idx_t row); - duckdb_scalar_function (*duckdb_create_scalar_function)(); - void (*duckdb_destroy_scalar_function)(duckdb_scalar_function *scalar_function); - void (*duckdb_scalar_function_set_name)(duckdb_scalar_function scalar_function, const char *name); - void (*duckdb_scalar_function_add_parameter)(duckdb_scalar_function scalar_function, duckdb_logical_type type); - void (*duckdb_scalar_function_set_return_type)(duckdb_scalar_function scalar_function, duckdb_logical_type type); - void (*duckdb_scalar_function_set_extra_info)(duckdb_scalar_function scalar_function, void *extra_info, - duckdb_delete_callback_t destroy); - void (*duckdb_scalar_function_set_function)(duckdb_scalar_function scalar_function, - duckdb_scalar_function_t function); - duckdb_state (*duckdb_register_scalar_function)(duckdb_connection con, duckdb_scalar_function scalar_function); - duckdb_table_function (*duckdb_create_table_function)(); - void (*duckdb_destroy_table_function)(duckdb_table_function *table_function); - void (*duckdb_table_function_set_name)(duckdb_table_function table_function, const char *name); - void (*duckdb_table_function_add_parameter)(duckdb_table_function table_function, duckdb_logical_type type); - void (*duckdb_table_function_add_named_parameter)(duckdb_table_function table_function, const char *name, - duckdb_logical_type type); - void (*duckdb_table_function_set_extra_info)(duckdb_table_function table_function, void *extra_info, - duckdb_delete_callback_t destroy); - void (*duckdb_table_function_set_bind)(duckdb_table_function table_function, duckdb_table_function_bind_t bind); - void (*duckdb_table_function_set_init)(duckdb_table_function table_function, duckdb_table_function_init_t init); - void (*duckdb_table_function_set_local_init)(duckdb_table_function table_function, - duckdb_table_function_init_t init); - void (*duckdb_table_function_set_function)(duckdb_table_function table_function, duckdb_table_function_t function); - void (*duckdb_table_function_supports_projection_pushdown)(duckdb_table_function table_function, bool pushdown); - duckdb_state (*duckdb_register_table_function)(duckdb_connection con, duckdb_table_function function); - void *(*duckdb_bind_get_extra_info)(duckdb_bind_info info); - void (*duckdb_bind_add_result_column)(duckdb_bind_info info, const char *name, duckdb_logical_type type); - idx_t (*duckdb_bind_get_parameter_count)(duckdb_bind_info info); - duckdb_value (*duckdb_bind_get_parameter)(duckdb_bind_info info, idx_t index); - duckdb_value (*duckdb_bind_get_named_parameter)(duckdb_bind_info info, const char *name); - void (*duckdb_bind_set_bind_data)(duckdb_bind_info info, void *bind_data, duckdb_delete_callback_t destroy); - void (*duckdb_bind_set_cardinality)(duckdb_bind_info info, idx_t cardinality, bool is_exact); - void (*duckdb_bind_set_error)(duckdb_bind_info info, const char *error); - void *(*duckdb_init_get_extra_info)(duckdb_init_info info); - void *(*duckdb_init_get_bind_data)(duckdb_init_info info); - void (*duckdb_init_set_init_data)(duckdb_init_info info, void *init_data, duckdb_delete_callback_t destroy); - idx_t (*duckdb_init_get_column_count)(duckdb_init_info info); - idx_t (*duckdb_init_get_column_index)(duckdb_init_info info, idx_t column_index); - void (*duckdb_init_set_max_threads)(duckdb_init_info info, idx_t max_threads); - void (*duckdb_init_set_error)(duckdb_init_info info, const char *error); - void *(*duckdb_function_get_extra_info)(duckdb_function_info info); - void *(*duckdb_function_get_bind_data)(duckdb_function_info info); - void *(*duckdb_function_get_init_data)(duckdb_function_info info); - void *(*duckdb_function_get_local_init_data)(duckdb_function_info info); - void (*duckdb_function_set_error)(duckdb_function_info info, const char *error); - void (*duckdb_add_replacement_scan)(duckdb_database db, duckdb_replacement_callback_t replacement, void *extra_data, - duckdb_delete_callback_t delete_callback); - void (*duckdb_replacement_scan_set_function_name)(duckdb_replacement_scan_info info, const char *function_name); - void (*duckdb_replacement_scan_add_parameter)(duckdb_replacement_scan_info info, duckdb_value parameter); - void (*duckdb_replacement_scan_set_error)(duckdb_replacement_scan_info info, const char *error); - duckdb_state (*duckdb_appender_create)(duckdb_connection connection, const char *schema, const char *table, - duckdb_appender *out_appender); - idx_t (*duckdb_appender_column_count)(duckdb_appender appender); - duckdb_logical_type (*duckdb_appender_column_type)(duckdb_appender appender, idx_t col_idx); - const char *(*duckdb_appender_error)(duckdb_appender appender); - duckdb_state (*duckdb_appender_flush)(duckdb_appender appender); - duckdb_state (*duckdb_appender_close)(duckdb_appender appender); - duckdb_state (*duckdb_appender_destroy)(duckdb_appender *appender); - duckdb_state (*duckdb_appender_begin_row)(duckdb_appender appender); - duckdb_state (*duckdb_appender_end_row)(duckdb_appender appender); - duckdb_state (*duckdb_append_default)(duckdb_appender appender); - duckdb_state (*duckdb_append_bool)(duckdb_appender appender, bool value); - duckdb_state (*duckdb_append_int8)(duckdb_appender appender, int8_t value); - duckdb_state (*duckdb_append_int16)(duckdb_appender appender, int16_t value); - duckdb_state (*duckdb_append_int32)(duckdb_appender appender, int32_t value); - duckdb_state (*duckdb_append_int64)(duckdb_appender appender, int64_t value); - duckdb_state (*duckdb_append_hugeint)(duckdb_appender appender, duckdb_hugeint value); - duckdb_state (*duckdb_append_uint8)(duckdb_appender appender, uint8_t value); - duckdb_state (*duckdb_append_uint16)(duckdb_appender appender, uint16_t value); - duckdb_state (*duckdb_append_uint32)(duckdb_appender appender, uint32_t value); - duckdb_state (*duckdb_append_uint64)(duckdb_appender appender, uint64_t value); - duckdb_state (*duckdb_append_uhugeint)(duckdb_appender appender, duckdb_uhugeint value); - duckdb_state (*duckdb_append_float)(duckdb_appender appender, float value); - duckdb_state (*duckdb_append_double)(duckdb_appender appender, double value); - duckdb_state (*duckdb_append_date)(duckdb_appender appender, duckdb_date value); - duckdb_state (*duckdb_append_time)(duckdb_appender appender, duckdb_time value); - duckdb_state (*duckdb_append_timestamp)(duckdb_appender appender, duckdb_timestamp value); - duckdb_state (*duckdb_append_interval)(duckdb_appender appender, duckdb_interval value); - duckdb_state (*duckdb_append_varchar)(duckdb_appender appender, const char *val); - duckdb_state (*duckdb_append_varchar_length)(duckdb_appender appender, const char *val, idx_t length); - duckdb_state (*duckdb_append_blob)(duckdb_appender appender, const void *data, idx_t length); - duckdb_state (*duckdb_append_null)(duckdb_appender appender); - duckdb_state (*duckdb_append_data_chunk)(duckdb_appender appender, duckdb_data_chunk chunk); - void (*duckdb_execute_tasks)(duckdb_database database, idx_t max_tasks); - duckdb_task_state (*duckdb_create_task_state)(duckdb_database database); - void (*duckdb_execute_tasks_state)(duckdb_task_state state); - idx_t (*duckdb_execute_n_tasks_state)(duckdb_task_state state, idx_t max_tasks); - void (*duckdb_finish_execution)(duckdb_task_state state); - bool (*duckdb_task_state_is_finished)(duckdb_task_state state); - void (*duckdb_destroy_task_state)(duckdb_task_state state); - bool (*duckdb_execution_is_finished)(duckdb_connection con); - duckdb_profiling_info (*duckdb_get_profiling_info)(duckdb_connection connection); - duckdb_value (*duckdb_profiling_info_get_value)(duckdb_profiling_info info, const char *key); - idx_t (*duckdb_profiling_info_get_child_count)(duckdb_profiling_info info); - duckdb_profiling_info (*duckdb_profiling_info_get_child)(duckdb_profiling_info info, idx_t index); - duckdb_value (*duckdb_profiling_info_get_metrics)(duckdb_profiling_info info); - void (*duckdb_scalar_function_set_varargs)(duckdb_scalar_function scalar_function, duckdb_logical_type type); - void (*duckdb_scalar_function_set_special_handling)(duckdb_scalar_function scalar_function); - void (*duckdb_scalar_function_set_volatile)(duckdb_scalar_function scalar_function); - void *(*duckdb_scalar_function_get_extra_info)(duckdb_function_info info); - void (*duckdb_scalar_function_set_error)(duckdb_function_info info, const char *error); - duckdb_state (*duckdb_table_description_create)(duckdb_connection connection, const char *schema, const char *table, - duckdb_table_description *out); - void (*duckdb_table_description_destroy)(duckdb_table_description *table_description); - const char *(*duckdb_table_description_error)(duckdb_table_description table_description); - duckdb_error_type (*duckdb_result_error_type)(duckdb_result *result); - uint32_t (*duckdb_string_t_length)(duckdb_string_t string); - const char *(*duckdb_string_t_data)(duckdb_string_t *string); - duckdb_value (*duckdb_create_bool)(bool input); - duckdb_value (*duckdb_create_int8)(int8_t input); - duckdb_value (*duckdb_create_uint8)(uint8_t input); - duckdb_value (*duckdb_create_int16)(int16_t input); - duckdb_value (*duckdb_create_uint16)(uint16_t input); - duckdb_value (*duckdb_create_int32)(int32_t input); - duckdb_value (*duckdb_create_uint32)(uint32_t input); - duckdb_value (*duckdb_create_uint64)(uint64_t input); - duckdb_value (*duckdb_create_hugeint)(duckdb_hugeint input); - duckdb_value (*duckdb_create_uhugeint)(duckdb_uhugeint input); - duckdb_value (*duckdb_create_float)(float input); - duckdb_value (*duckdb_create_double)(double input); - duckdb_value (*duckdb_create_date)(duckdb_date input); - duckdb_value (*duckdb_create_time)(duckdb_time input); - duckdb_value (*duckdb_create_time_tz_value)(duckdb_time_tz value); - duckdb_value (*duckdb_create_timestamp)(duckdb_timestamp input); - duckdb_value (*duckdb_create_interval)(duckdb_interval input); - duckdb_value (*duckdb_create_blob)(const uint8_t *data, idx_t length); - bool (*duckdb_get_bool)(duckdb_value val); - int8_t (*duckdb_get_int8)(duckdb_value val); - uint8_t (*duckdb_get_uint8)(duckdb_value val); - int16_t (*duckdb_get_int16)(duckdb_value val); - uint16_t (*duckdb_get_uint16)(duckdb_value val); - int32_t (*duckdb_get_int32)(duckdb_value val); - uint32_t (*duckdb_get_uint32)(duckdb_value val); - uint64_t (*duckdb_get_uint64)(duckdb_value val); - duckdb_hugeint (*duckdb_get_hugeint)(duckdb_value val); - duckdb_uhugeint (*duckdb_get_uhugeint)(duckdb_value val); - float (*duckdb_get_float)(duckdb_value val); - double (*duckdb_get_double)(duckdb_value val); - duckdb_date (*duckdb_get_date)(duckdb_value val); - duckdb_time (*duckdb_get_time)(duckdb_value val); - duckdb_time_tz (*duckdb_get_time_tz)(duckdb_value val); - duckdb_timestamp (*duckdb_get_timestamp)(duckdb_value val); - duckdb_interval (*duckdb_get_interval)(duckdb_value val); - duckdb_logical_type (*duckdb_get_value_type)(duckdb_value val); - duckdb_blob (*duckdb_get_blob)(duckdb_value val); - duckdb_scalar_function_set (*duckdb_create_scalar_function_set)(const char *name); - void (*duckdb_destroy_scalar_function_set)(duckdb_scalar_function_set *scalar_function_set); - duckdb_state (*duckdb_add_scalar_function_to_set)(duckdb_scalar_function_set set, duckdb_scalar_function function); - duckdb_state (*duckdb_register_scalar_function_set)(duckdb_connection con, duckdb_scalar_function_set set); - duckdb_aggregate_function_set (*duckdb_create_aggregate_function_set)(const char *name); - void (*duckdb_destroy_aggregate_function_set)(duckdb_aggregate_function_set *aggregate_function_set); - duckdb_state (*duckdb_add_aggregate_function_to_set)(duckdb_aggregate_function_set set, - duckdb_aggregate_function function); - duckdb_state (*duckdb_register_aggregate_function_set)(duckdb_connection con, duckdb_aggregate_function_set set); - idx_t (*duckdb_get_map_size)(duckdb_value value); - duckdb_value (*duckdb_get_map_key)(duckdb_value value, idx_t index); - duckdb_value (*duckdb_get_map_value)(duckdb_value value, idx_t index); - duckdb_aggregate_function (*duckdb_create_aggregate_function)(); - void (*duckdb_destroy_aggregate_function)(duckdb_aggregate_function *aggregate_function); - void (*duckdb_aggregate_function_set_name)(duckdb_aggregate_function aggregate_function, const char *name); - void (*duckdb_aggregate_function_add_parameter)(duckdb_aggregate_function aggregate_function, - duckdb_logical_type type); - void (*duckdb_aggregate_function_set_return_type)(duckdb_aggregate_function aggregate_function, - duckdb_logical_type type); - void (*duckdb_aggregate_function_set_functions)(duckdb_aggregate_function aggregate_function, - duckdb_aggregate_state_size state_size, - duckdb_aggregate_init_t state_init, - duckdb_aggregate_update_t update, - duckdb_aggregate_combine_t combine, - duckdb_aggregate_finalize_t finalize); - void (*duckdb_aggregate_function_set_destructor)(duckdb_aggregate_function aggregate_function, - duckdb_aggregate_destroy_t destroy); - duckdb_state (*duckdb_register_aggregate_function)(duckdb_connection con, - duckdb_aggregate_function aggregate_function); - void (*duckdb_aggregate_function_set_special_handling)(duckdb_aggregate_function aggregate_function); - void (*duckdb_aggregate_function_set_extra_info)(duckdb_aggregate_function aggregate_function, void *extra_info, - duckdb_delete_callback_t destroy); - void *(*duckdb_aggregate_function_get_extra_info)(duckdb_function_info info); - void (*duckdb_aggregate_function_set_error)(duckdb_function_info info, const char *error); - void (*duckdb_logical_type_set_alias)(duckdb_logical_type type, const char *alias); - duckdb_state (*duckdb_register_logical_type)(duckdb_connection con, duckdb_logical_type type, - duckdb_create_type_info info); - duckdb_cast_function (*duckdb_create_cast_function)(); - void (*duckdb_cast_function_set_source_type)(duckdb_cast_function cast_function, duckdb_logical_type source_type); - void (*duckdb_cast_function_set_target_type)(duckdb_cast_function cast_function, duckdb_logical_type target_type); - void (*duckdb_cast_function_set_implicit_cast_cost)(duckdb_cast_function cast_function, int64_t cost); - void (*duckdb_cast_function_set_function)(duckdb_cast_function cast_function, duckdb_cast_function_t function); - void (*duckdb_cast_function_set_extra_info)(duckdb_cast_function cast_function, void *extra_info, - duckdb_delete_callback_t destroy); - void *(*duckdb_cast_function_get_extra_info)(duckdb_function_info info); - duckdb_cast_mode (*duckdb_cast_function_get_cast_mode)(duckdb_function_info info); - void (*duckdb_cast_function_set_error)(duckdb_function_info info, const char *error); - void (*duckdb_cast_function_set_row_error)(duckdb_function_info info, const char *error, idx_t row, - duckdb_vector output); - duckdb_state (*duckdb_register_cast_function)(duckdb_connection con, duckdb_cast_function cast_function); - void (*duckdb_destroy_cast_function)(duckdb_cast_function *cast_function); - idx_t (*duckdb_row_count)(duckdb_result *result); - void *(*duckdb_column_data)(duckdb_result *result, idx_t col); - bool *(*duckdb_nullmask_data)(duckdb_result *result, idx_t col); - duckdb_data_chunk (*duckdb_result_get_chunk)(duckdb_result result, idx_t chunk_index); - bool (*duckdb_result_is_streaming)(duckdb_result result); - idx_t (*duckdb_result_chunk_count)(duckdb_result result); - duckdb_result_type (*duckdb_result_return_type)(duckdb_result result); - bool (*duckdb_value_boolean)(duckdb_result *result, idx_t col, idx_t row); - int8_t (*duckdb_value_int8)(duckdb_result *result, idx_t col, idx_t row); - int16_t (*duckdb_value_int16)(duckdb_result *result, idx_t col, idx_t row); - int32_t (*duckdb_value_int32)(duckdb_result *result, idx_t col, idx_t row); - int64_t (*duckdb_value_int64)(duckdb_result *result, idx_t col, idx_t row); - duckdb_hugeint (*duckdb_value_hugeint)(duckdb_result *result, idx_t col, idx_t row); - duckdb_uhugeint (*duckdb_value_uhugeint)(duckdb_result *result, idx_t col, idx_t row); - duckdb_decimal (*duckdb_value_decimal)(duckdb_result *result, idx_t col, idx_t row); - uint8_t (*duckdb_value_uint8)(duckdb_result *result, idx_t col, idx_t row); - uint16_t (*duckdb_value_uint16)(duckdb_result *result, idx_t col, idx_t row); - uint32_t (*duckdb_value_uint32)(duckdb_result *result, idx_t col, idx_t row); - uint64_t (*duckdb_value_uint64)(duckdb_result *result, idx_t col, idx_t row); - float (*duckdb_value_float)(duckdb_result *result, idx_t col, idx_t row); - double (*duckdb_value_double)(duckdb_result *result, idx_t col, idx_t row); - duckdb_date (*duckdb_value_date)(duckdb_result *result, idx_t col, idx_t row); - duckdb_time (*duckdb_value_time)(duckdb_result *result, idx_t col, idx_t row); - duckdb_timestamp (*duckdb_value_timestamp)(duckdb_result *result, idx_t col, idx_t row); - duckdb_interval (*duckdb_value_interval)(duckdb_result *result, idx_t col, idx_t row); - char *(*duckdb_value_varchar)(duckdb_result *result, idx_t col, idx_t row); - duckdb_string (*duckdb_value_string)(duckdb_result *result, idx_t col, idx_t row); - char *(*duckdb_value_varchar_internal)(duckdb_result *result, idx_t col, idx_t row); - duckdb_string (*duckdb_value_string_internal)(duckdb_result *result, idx_t col, idx_t row); - duckdb_blob (*duckdb_value_blob)(duckdb_result *result, idx_t col, idx_t row); - bool (*duckdb_value_is_null)(duckdb_result *result, idx_t col, idx_t row); - duckdb_state (*duckdb_execute_prepared_streaming)(duckdb_prepared_statement prepared_statement, - duckdb_result *out_result); - duckdb_state (*duckdb_pending_prepared_streaming)(duckdb_prepared_statement prepared_statement, - duckdb_pending_result *out_result); - duckdb_state (*duckdb_column_has_default)(duckdb_table_description table_description, idx_t index, bool *out); - duckdb_state (*duckdb_query_arrow)(duckdb_connection connection, const char *query, duckdb_arrow *out_result); - duckdb_state (*duckdb_query_arrow_schema)(duckdb_arrow result, duckdb_arrow_schema *out_schema); - duckdb_state (*duckdb_prepared_arrow_schema)(duckdb_prepared_statement prepared, duckdb_arrow_schema *out_schema); - void (*duckdb_result_arrow_array)(duckdb_result result, duckdb_data_chunk chunk, duckdb_arrow_array *out_array); - duckdb_state (*duckdb_query_arrow_array)(duckdb_arrow result, duckdb_arrow_array *out_array); - idx_t (*duckdb_arrow_column_count)(duckdb_arrow result); - idx_t (*duckdb_arrow_row_count)(duckdb_arrow result); - idx_t (*duckdb_arrow_rows_changed)(duckdb_arrow result); - const char *(*duckdb_query_arrow_error)(duckdb_arrow result); - void (*duckdb_destroy_arrow)(duckdb_arrow *result); - void (*duckdb_destroy_arrow_stream)(duckdb_arrow_stream *stream_p); - duckdb_state (*duckdb_execute_prepared_arrow)(duckdb_prepared_statement prepared_statement, - duckdb_arrow *out_result); - duckdb_state (*duckdb_arrow_scan)(duckdb_connection connection, const char *table_name, duckdb_arrow_stream arrow); - duckdb_state (*duckdb_arrow_array_scan)(duckdb_connection connection, const char *table_name, - duckdb_arrow_schema arrow_schema, duckdb_arrow_array arrow_array, - duckdb_arrow_stream *out_stream); - duckdb_data_chunk (*duckdb_stream_fetch_chunk)(duckdb_result result); -} duckdb_ext_api_v0; - -//===--------------------------------------------------------------------===// -// Struct Create Method -//===--------------------------------------------------------------------===// -inline duckdb_ext_api_v0 CreateAPIv0() { - duckdb_ext_api_v0 result; - result.duckdb_open = duckdb_open; - result.duckdb_open_ext = duckdb_open_ext; - result.duckdb_close = duckdb_close; - result.duckdb_connect = duckdb_connect; - result.duckdb_interrupt = duckdb_interrupt; - result.duckdb_query_progress = duckdb_query_progress; - result.duckdb_disconnect = duckdb_disconnect; - result.duckdb_library_version = duckdb_library_version; - result.duckdb_create_config = duckdb_create_config; - result.duckdb_config_count = duckdb_config_count; - result.duckdb_get_config_flag = duckdb_get_config_flag; - result.duckdb_set_config = duckdb_set_config; - result.duckdb_destroy_config = duckdb_destroy_config; - result.duckdb_query = duckdb_query; - result.duckdb_destroy_result = duckdb_destroy_result; - result.duckdb_column_name = duckdb_column_name; - result.duckdb_column_type = duckdb_column_type; - result.duckdb_result_statement_type = duckdb_result_statement_type; - result.duckdb_column_logical_type = duckdb_column_logical_type; - result.duckdb_column_count = duckdb_column_count; - result.duckdb_rows_changed = duckdb_rows_changed; - result.duckdb_result_error = duckdb_result_error; - result.duckdb_malloc = duckdb_malloc; - result.duckdb_free = duckdb_free; - result.duckdb_vector_size = duckdb_vector_size; - result.duckdb_string_is_inlined = duckdb_string_is_inlined; - result.duckdb_from_date = duckdb_from_date; - result.duckdb_to_date = duckdb_to_date; - result.duckdb_is_finite_date = duckdb_is_finite_date; - result.duckdb_from_time = duckdb_from_time; - result.duckdb_create_time_tz = duckdb_create_time_tz; - result.duckdb_from_time_tz = duckdb_from_time_tz; - result.duckdb_to_time = duckdb_to_time; - result.duckdb_from_timestamp = duckdb_from_timestamp; - result.duckdb_to_timestamp = duckdb_to_timestamp; - result.duckdb_is_finite_timestamp = duckdb_is_finite_timestamp; - result.duckdb_hugeint_to_double = duckdb_hugeint_to_double; - result.duckdb_double_to_hugeint = duckdb_double_to_hugeint; - result.duckdb_uhugeint_to_double = duckdb_uhugeint_to_double; - result.duckdb_double_to_uhugeint = duckdb_double_to_uhugeint; - result.duckdb_double_to_decimal = duckdb_double_to_decimal; - result.duckdb_decimal_to_double = duckdb_decimal_to_double; - result.duckdb_prepare = duckdb_prepare; - result.duckdb_destroy_prepare = duckdb_destroy_prepare; - result.duckdb_prepare_error = duckdb_prepare_error; - result.duckdb_nparams = duckdb_nparams; - result.duckdb_parameter_name = duckdb_parameter_name; - result.duckdb_param_type = duckdb_param_type; - result.duckdb_clear_bindings = duckdb_clear_bindings; - result.duckdb_prepared_statement_type = duckdb_prepared_statement_type; - result.duckdb_bind_value = duckdb_bind_value; - result.duckdb_bind_parameter_index = duckdb_bind_parameter_index; - result.duckdb_bind_boolean = duckdb_bind_boolean; - result.duckdb_bind_int8 = duckdb_bind_int8; - result.duckdb_bind_int16 = duckdb_bind_int16; - result.duckdb_bind_int32 = duckdb_bind_int32; - result.duckdb_bind_int64 = duckdb_bind_int64; - result.duckdb_bind_hugeint = duckdb_bind_hugeint; - result.duckdb_bind_uhugeint = duckdb_bind_uhugeint; - result.duckdb_bind_decimal = duckdb_bind_decimal; - result.duckdb_bind_uint8 = duckdb_bind_uint8; - result.duckdb_bind_uint16 = duckdb_bind_uint16; - result.duckdb_bind_uint32 = duckdb_bind_uint32; - result.duckdb_bind_uint64 = duckdb_bind_uint64; - result.duckdb_bind_float = duckdb_bind_float; - result.duckdb_bind_double = duckdb_bind_double; - result.duckdb_bind_date = duckdb_bind_date; - result.duckdb_bind_time = duckdb_bind_time; - result.duckdb_bind_timestamp = duckdb_bind_timestamp; - result.duckdb_bind_timestamp_tz = duckdb_bind_timestamp_tz; - result.duckdb_bind_interval = duckdb_bind_interval; - result.duckdb_bind_varchar = duckdb_bind_varchar; - result.duckdb_bind_varchar_length = duckdb_bind_varchar_length; - result.duckdb_bind_blob = duckdb_bind_blob; - result.duckdb_bind_null = duckdb_bind_null; - result.duckdb_execute_prepared = duckdb_execute_prepared; - result.duckdb_extract_statements = duckdb_extract_statements; - result.duckdb_prepare_extracted_statement = duckdb_prepare_extracted_statement; - result.duckdb_extract_statements_error = duckdb_extract_statements_error; - result.duckdb_destroy_extracted = duckdb_destroy_extracted; - result.duckdb_pending_prepared = duckdb_pending_prepared; - result.duckdb_destroy_pending = duckdb_destroy_pending; - result.duckdb_pending_error = duckdb_pending_error; - result.duckdb_pending_execute_task = duckdb_pending_execute_task; - result.duckdb_pending_execute_check_state = duckdb_pending_execute_check_state; - result.duckdb_execute_pending = duckdb_execute_pending; - result.duckdb_pending_execution_is_finished = duckdb_pending_execution_is_finished; - result.duckdb_destroy_value = duckdb_destroy_value; - result.duckdb_create_varchar = duckdb_create_varchar; - result.duckdb_create_varchar_length = duckdb_create_varchar_length; - result.duckdb_create_int64 = duckdb_create_int64; - result.duckdb_create_struct_value = duckdb_create_struct_value; - result.duckdb_create_list_value = duckdb_create_list_value; - result.duckdb_create_array_value = duckdb_create_array_value; - result.duckdb_get_varchar = duckdb_get_varchar; - result.duckdb_get_int64 = duckdb_get_int64; - result.duckdb_create_logical_type = duckdb_create_logical_type; - result.duckdb_logical_type_get_alias = duckdb_logical_type_get_alias; - result.duckdb_create_list_type = duckdb_create_list_type; - result.duckdb_create_array_type = duckdb_create_array_type; - result.duckdb_create_map_type = duckdb_create_map_type; - result.duckdb_create_union_type = duckdb_create_union_type; - result.duckdb_create_struct_type = duckdb_create_struct_type; - result.duckdb_create_enum_type = duckdb_create_enum_type; - result.duckdb_create_decimal_type = duckdb_create_decimal_type; - result.duckdb_get_type_id = duckdb_get_type_id; - result.duckdb_decimal_width = duckdb_decimal_width; - result.duckdb_decimal_scale = duckdb_decimal_scale; - result.duckdb_decimal_internal_type = duckdb_decimal_internal_type; - result.duckdb_enum_internal_type = duckdb_enum_internal_type; - result.duckdb_enum_dictionary_size = duckdb_enum_dictionary_size; - result.duckdb_enum_dictionary_value = duckdb_enum_dictionary_value; - result.duckdb_list_type_child_type = duckdb_list_type_child_type; - result.duckdb_array_type_child_type = duckdb_array_type_child_type; - result.duckdb_array_type_array_size = duckdb_array_type_array_size; - result.duckdb_map_type_key_type = duckdb_map_type_key_type; - result.duckdb_map_type_value_type = duckdb_map_type_value_type; - result.duckdb_struct_type_child_count = duckdb_struct_type_child_count; - result.duckdb_struct_type_child_name = duckdb_struct_type_child_name; - result.duckdb_struct_type_child_type = duckdb_struct_type_child_type; - result.duckdb_union_type_member_count = duckdb_union_type_member_count; - result.duckdb_union_type_member_name = duckdb_union_type_member_name; - result.duckdb_union_type_member_type = duckdb_union_type_member_type; - result.duckdb_destroy_logical_type = duckdb_destroy_logical_type; - result.duckdb_fetch_chunk = duckdb_fetch_chunk; - result.duckdb_create_data_chunk = duckdb_create_data_chunk; - result.duckdb_destroy_data_chunk = duckdb_destroy_data_chunk; - result.duckdb_data_chunk_reset = duckdb_data_chunk_reset; - result.duckdb_data_chunk_get_column_count = duckdb_data_chunk_get_column_count; - result.duckdb_data_chunk_get_vector = duckdb_data_chunk_get_vector; - result.duckdb_data_chunk_get_size = duckdb_data_chunk_get_size; - result.duckdb_data_chunk_set_size = duckdb_data_chunk_set_size; - result.duckdb_vector_get_column_type = duckdb_vector_get_column_type; - result.duckdb_vector_get_data = duckdb_vector_get_data; - result.duckdb_vector_get_validity = duckdb_vector_get_validity; - result.duckdb_vector_ensure_validity_writable = duckdb_vector_ensure_validity_writable; - result.duckdb_vector_assign_string_element = duckdb_vector_assign_string_element; - result.duckdb_vector_assign_string_element_len = duckdb_vector_assign_string_element_len; - result.duckdb_list_vector_get_child = duckdb_list_vector_get_child; - result.duckdb_list_vector_get_size = duckdb_list_vector_get_size; - result.duckdb_list_vector_set_size = duckdb_list_vector_set_size; - result.duckdb_list_vector_reserve = duckdb_list_vector_reserve; - result.duckdb_struct_vector_get_child = duckdb_struct_vector_get_child; - result.duckdb_array_vector_get_child = duckdb_array_vector_get_child; - result.duckdb_validity_row_is_valid = duckdb_validity_row_is_valid; - result.duckdb_validity_set_row_validity = duckdb_validity_set_row_validity; - result.duckdb_validity_set_row_invalid = duckdb_validity_set_row_invalid; - result.duckdb_validity_set_row_valid = duckdb_validity_set_row_valid; - result.duckdb_create_scalar_function = duckdb_create_scalar_function; - result.duckdb_destroy_scalar_function = duckdb_destroy_scalar_function; - result.duckdb_scalar_function_set_name = duckdb_scalar_function_set_name; - result.duckdb_scalar_function_add_parameter = duckdb_scalar_function_add_parameter; - result.duckdb_scalar_function_set_return_type = duckdb_scalar_function_set_return_type; - result.duckdb_scalar_function_set_extra_info = duckdb_scalar_function_set_extra_info; - result.duckdb_scalar_function_set_function = duckdb_scalar_function_set_function; - result.duckdb_register_scalar_function = duckdb_register_scalar_function; - result.duckdb_create_table_function = duckdb_create_table_function; - result.duckdb_destroy_table_function = duckdb_destroy_table_function; - result.duckdb_table_function_set_name = duckdb_table_function_set_name; - result.duckdb_table_function_add_parameter = duckdb_table_function_add_parameter; - result.duckdb_table_function_add_named_parameter = duckdb_table_function_add_named_parameter; - result.duckdb_table_function_set_extra_info = duckdb_table_function_set_extra_info; - result.duckdb_table_function_set_bind = duckdb_table_function_set_bind; - result.duckdb_table_function_set_init = duckdb_table_function_set_init; - result.duckdb_table_function_set_local_init = duckdb_table_function_set_local_init; - result.duckdb_table_function_set_function = duckdb_table_function_set_function; - result.duckdb_table_function_supports_projection_pushdown = duckdb_table_function_supports_projection_pushdown; - result.duckdb_register_table_function = duckdb_register_table_function; - result.duckdb_bind_get_extra_info = duckdb_bind_get_extra_info; - result.duckdb_bind_add_result_column = duckdb_bind_add_result_column; - result.duckdb_bind_get_parameter_count = duckdb_bind_get_parameter_count; - result.duckdb_bind_get_parameter = duckdb_bind_get_parameter; - result.duckdb_bind_get_named_parameter = duckdb_bind_get_named_parameter; - result.duckdb_bind_set_bind_data = duckdb_bind_set_bind_data; - result.duckdb_bind_set_cardinality = duckdb_bind_set_cardinality; - result.duckdb_bind_set_error = duckdb_bind_set_error; - result.duckdb_init_get_extra_info = duckdb_init_get_extra_info; - result.duckdb_init_get_bind_data = duckdb_init_get_bind_data; - result.duckdb_init_set_init_data = duckdb_init_set_init_data; - result.duckdb_init_get_column_count = duckdb_init_get_column_count; - result.duckdb_init_get_column_index = duckdb_init_get_column_index; - result.duckdb_init_set_max_threads = duckdb_init_set_max_threads; - result.duckdb_init_set_error = duckdb_init_set_error; - result.duckdb_function_get_extra_info = duckdb_function_get_extra_info; - result.duckdb_function_get_bind_data = duckdb_function_get_bind_data; - result.duckdb_function_get_init_data = duckdb_function_get_init_data; - result.duckdb_function_get_local_init_data = duckdb_function_get_local_init_data; - result.duckdb_function_set_error = duckdb_function_set_error; - result.duckdb_add_replacement_scan = duckdb_add_replacement_scan; - result.duckdb_replacement_scan_set_function_name = duckdb_replacement_scan_set_function_name; - result.duckdb_replacement_scan_add_parameter = duckdb_replacement_scan_add_parameter; - result.duckdb_replacement_scan_set_error = duckdb_replacement_scan_set_error; - result.duckdb_appender_create = duckdb_appender_create; - result.duckdb_appender_column_count = duckdb_appender_column_count; - result.duckdb_appender_column_type = duckdb_appender_column_type; - result.duckdb_appender_error = duckdb_appender_error; - result.duckdb_appender_flush = duckdb_appender_flush; - result.duckdb_appender_close = duckdb_appender_close; - result.duckdb_appender_destroy = duckdb_appender_destroy; - result.duckdb_appender_begin_row = duckdb_appender_begin_row; - result.duckdb_appender_end_row = duckdb_appender_end_row; - result.duckdb_append_default = duckdb_append_default; - result.duckdb_append_bool = duckdb_append_bool; - result.duckdb_append_int8 = duckdb_append_int8; - result.duckdb_append_int16 = duckdb_append_int16; - result.duckdb_append_int32 = duckdb_append_int32; - result.duckdb_append_int64 = duckdb_append_int64; - result.duckdb_append_hugeint = duckdb_append_hugeint; - result.duckdb_append_uint8 = duckdb_append_uint8; - result.duckdb_append_uint16 = duckdb_append_uint16; - result.duckdb_append_uint32 = duckdb_append_uint32; - result.duckdb_append_uint64 = duckdb_append_uint64; - result.duckdb_append_uhugeint = duckdb_append_uhugeint; - result.duckdb_append_float = duckdb_append_float; - result.duckdb_append_double = duckdb_append_double; - result.duckdb_append_date = duckdb_append_date; - result.duckdb_append_time = duckdb_append_time; - result.duckdb_append_timestamp = duckdb_append_timestamp; - result.duckdb_append_interval = duckdb_append_interval; - result.duckdb_append_varchar = duckdb_append_varchar; - result.duckdb_append_varchar_length = duckdb_append_varchar_length; - result.duckdb_append_blob = duckdb_append_blob; - result.duckdb_append_null = duckdb_append_null; - result.duckdb_append_data_chunk = duckdb_append_data_chunk; - result.duckdb_execute_tasks = duckdb_execute_tasks; - result.duckdb_create_task_state = duckdb_create_task_state; - result.duckdb_execute_tasks_state = duckdb_execute_tasks_state; - result.duckdb_execute_n_tasks_state = duckdb_execute_n_tasks_state; - result.duckdb_finish_execution = duckdb_finish_execution; - result.duckdb_task_state_is_finished = duckdb_task_state_is_finished; - result.duckdb_destroy_task_state = duckdb_destroy_task_state; - result.duckdb_execution_is_finished = duckdb_execution_is_finished; - result.duckdb_get_profiling_info = duckdb_get_profiling_info; - result.duckdb_profiling_info_get_value = duckdb_profiling_info_get_value; - result.duckdb_profiling_info_get_child_count = duckdb_profiling_info_get_child_count; - result.duckdb_profiling_info_get_child = duckdb_profiling_info_get_child; - result.duckdb_profiling_info_get_metrics = duckdb_profiling_info_get_metrics; - result.duckdb_scalar_function_set_varargs = duckdb_scalar_function_set_varargs; - result.duckdb_scalar_function_set_special_handling = duckdb_scalar_function_set_special_handling; - result.duckdb_scalar_function_set_volatile = duckdb_scalar_function_set_volatile; - result.duckdb_scalar_function_get_extra_info = duckdb_scalar_function_get_extra_info; - result.duckdb_scalar_function_set_error = duckdb_scalar_function_set_error; - result.duckdb_table_description_create = duckdb_table_description_create; - result.duckdb_table_description_destroy = duckdb_table_description_destroy; - result.duckdb_table_description_error = duckdb_table_description_error; - result.duckdb_result_error_type = duckdb_result_error_type; - result.duckdb_string_t_length = duckdb_string_t_length; - result.duckdb_string_t_data = duckdb_string_t_data; - result.duckdb_create_bool = duckdb_create_bool; - result.duckdb_create_int8 = duckdb_create_int8; - result.duckdb_create_uint8 = duckdb_create_uint8; - result.duckdb_create_int16 = duckdb_create_int16; - result.duckdb_create_uint16 = duckdb_create_uint16; - result.duckdb_create_int32 = duckdb_create_int32; - result.duckdb_create_uint32 = duckdb_create_uint32; - result.duckdb_create_uint64 = duckdb_create_uint64; - result.duckdb_create_hugeint = duckdb_create_hugeint; - result.duckdb_create_uhugeint = duckdb_create_uhugeint; - result.duckdb_create_float = duckdb_create_float; - result.duckdb_create_double = duckdb_create_double; - result.duckdb_create_date = duckdb_create_date; - result.duckdb_create_time = duckdb_create_time; - result.duckdb_create_time_tz_value = duckdb_create_time_tz_value; - result.duckdb_create_timestamp = duckdb_create_timestamp; - result.duckdb_create_interval = duckdb_create_interval; - result.duckdb_create_blob = duckdb_create_blob; - result.duckdb_get_bool = duckdb_get_bool; - result.duckdb_get_int8 = duckdb_get_int8; - result.duckdb_get_uint8 = duckdb_get_uint8; - result.duckdb_get_int16 = duckdb_get_int16; - result.duckdb_get_uint16 = duckdb_get_uint16; - result.duckdb_get_int32 = duckdb_get_int32; - result.duckdb_get_uint32 = duckdb_get_uint32; - result.duckdb_get_uint64 = duckdb_get_uint64; - result.duckdb_get_hugeint = duckdb_get_hugeint; - result.duckdb_get_uhugeint = duckdb_get_uhugeint; - result.duckdb_get_float = duckdb_get_float; - result.duckdb_get_double = duckdb_get_double; - result.duckdb_get_date = duckdb_get_date; - result.duckdb_get_time = duckdb_get_time; - result.duckdb_get_time_tz = duckdb_get_time_tz; - result.duckdb_get_timestamp = duckdb_get_timestamp; - result.duckdb_get_interval = duckdb_get_interval; - result.duckdb_get_value_type = duckdb_get_value_type; - result.duckdb_get_blob = duckdb_get_blob; - result.duckdb_create_scalar_function_set = duckdb_create_scalar_function_set; - result.duckdb_destroy_scalar_function_set = duckdb_destroy_scalar_function_set; - result.duckdb_add_scalar_function_to_set = duckdb_add_scalar_function_to_set; - result.duckdb_register_scalar_function_set = duckdb_register_scalar_function_set; - result.duckdb_create_aggregate_function_set = duckdb_create_aggregate_function_set; - result.duckdb_destroy_aggregate_function_set = duckdb_destroy_aggregate_function_set; - result.duckdb_add_aggregate_function_to_set = duckdb_add_aggregate_function_to_set; - result.duckdb_register_aggregate_function_set = duckdb_register_aggregate_function_set; - result.duckdb_get_map_size = duckdb_get_map_size; - result.duckdb_get_map_key = duckdb_get_map_key; - result.duckdb_get_map_value = duckdb_get_map_value; - result.duckdb_create_aggregate_function = duckdb_create_aggregate_function; - result.duckdb_destroy_aggregate_function = duckdb_destroy_aggregate_function; - result.duckdb_aggregate_function_set_name = duckdb_aggregate_function_set_name; - result.duckdb_aggregate_function_add_parameter = duckdb_aggregate_function_add_parameter; - result.duckdb_aggregate_function_set_return_type = duckdb_aggregate_function_set_return_type; - result.duckdb_aggregate_function_set_functions = duckdb_aggregate_function_set_functions; - result.duckdb_aggregate_function_set_destructor = duckdb_aggregate_function_set_destructor; - result.duckdb_register_aggregate_function = duckdb_register_aggregate_function; - result.duckdb_aggregate_function_set_special_handling = duckdb_aggregate_function_set_special_handling; - result.duckdb_aggregate_function_set_extra_info = duckdb_aggregate_function_set_extra_info; - result.duckdb_aggregate_function_get_extra_info = duckdb_aggregate_function_get_extra_info; - result.duckdb_aggregate_function_set_error = duckdb_aggregate_function_set_error; - result.duckdb_logical_type_set_alias = duckdb_logical_type_set_alias; - result.duckdb_register_logical_type = duckdb_register_logical_type; - result.duckdb_create_cast_function = duckdb_create_cast_function; - result.duckdb_cast_function_set_source_type = duckdb_cast_function_set_source_type; - result.duckdb_cast_function_set_target_type = duckdb_cast_function_set_target_type; - result.duckdb_cast_function_set_implicit_cast_cost = duckdb_cast_function_set_implicit_cast_cost; - result.duckdb_cast_function_set_function = duckdb_cast_function_set_function; - result.duckdb_cast_function_set_extra_info = duckdb_cast_function_set_extra_info; - result.duckdb_cast_function_get_extra_info = duckdb_cast_function_get_extra_info; - result.duckdb_cast_function_get_cast_mode = duckdb_cast_function_get_cast_mode; - result.duckdb_cast_function_set_error = duckdb_cast_function_set_error; - result.duckdb_cast_function_set_row_error = duckdb_cast_function_set_row_error; - result.duckdb_register_cast_function = duckdb_register_cast_function; - result.duckdb_destroy_cast_function = duckdb_destroy_cast_function; - result.duckdb_row_count = duckdb_row_count; - result.duckdb_column_data = duckdb_column_data; - result.duckdb_nullmask_data = duckdb_nullmask_data; - result.duckdb_result_get_chunk = duckdb_result_get_chunk; - result.duckdb_result_is_streaming = duckdb_result_is_streaming; - result.duckdb_result_chunk_count = duckdb_result_chunk_count; - result.duckdb_result_return_type = duckdb_result_return_type; - result.duckdb_value_boolean = duckdb_value_boolean; - result.duckdb_value_int8 = duckdb_value_int8; - result.duckdb_value_int16 = duckdb_value_int16; - result.duckdb_value_int32 = duckdb_value_int32; - result.duckdb_value_int64 = duckdb_value_int64; - result.duckdb_value_hugeint = duckdb_value_hugeint; - result.duckdb_value_uhugeint = duckdb_value_uhugeint; - result.duckdb_value_decimal = duckdb_value_decimal; - result.duckdb_value_uint8 = duckdb_value_uint8; - result.duckdb_value_uint16 = duckdb_value_uint16; - result.duckdb_value_uint32 = duckdb_value_uint32; - result.duckdb_value_uint64 = duckdb_value_uint64; - result.duckdb_value_float = duckdb_value_float; - result.duckdb_value_double = duckdb_value_double; - result.duckdb_value_date = duckdb_value_date; - result.duckdb_value_time = duckdb_value_time; - result.duckdb_value_timestamp = duckdb_value_timestamp; - result.duckdb_value_interval = duckdb_value_interval; - result.duckdb_value_varchar = duckdb_value_varchar; - result.duckdb_value_string = duckdb_value_string; - result.duckdb_value_varchar_internal = duckdb_value_varchar_internal; - result.duckdb_value_string_internal = duckdb_value_string_internal; - result.duckdb_value_blob = duckdb_value_blob; - result.duckdb_value_is_null = duckdb_value_is_null; - result.duckdb_execute_prepared_streaming = duckdb_execute_prepared_streaming; - result.duckdb_pending_prepared_streaming = duckdb_pending_prepared_streaming; - result.duckdb_column_has_default = duckdb_column_has_default; - result.duckdb_query_arrow = duckdb_query_arrow; - result.duckdb_query_arrow_schema = duckdb_query_arrow_schema; - result.duckdb_prepared_arrow_schema = duckdb_prepared_arrow_schema; - result.duckdb_result_arrow_array = duckdb_result_arrow_array; - result.duckdb_query_arrow_array = duckdb_query_arrow_array; - result.duckdb_arrow_column_count = duckdb_arrow_column_count; - result.duckdb_arrow_row_count = duckdb_arrow_row_count; - result.duckdb_arrow_rows_changed = duckdb_arrow_rows_changed; - result.duckdb_query_arrow_error = duckdb_query_arrow_error; - result.duckdb_destroy_arrow = duckdb_destroy_arrow; - result.duckdb_destroy_arrow_stream = duckdb_destroy_arrow_stream; - result.duckdb_execute_prepared_arrow = duckdb_execute_prepared_arrow; - result.duckdb_arrow_scan = duckdb_arrow_scan; - result.duckdb_arrow_array_scan = duckdb_arrow_array_scan; - result.duckdb_stream_fetch_chunk = duckdb_stream_fetch_chunk; - return result; -} - -#define DUCKDB_EXTENSION_API_VERSION_MAJOR 0 -#define DUCKDB_EXTENSION_API_VERSION_MINOR 0 -#define DUCKDB_EXTENSION_API_VERSION_PATCH 1 -#define DUCKDB_EXTENSION_API_VERSION_STRING "v0.0.1" - - - - #ifndef DUCKDB_NO_THREADS #include @@ -266444,7 +265817,7 @@ struct ExtensionAccess { } //! Called by the extension get a pointer the correctly versioned extension C API struct. - static void *GetAPI(duckdb_extension_info info, const char *version) { + static const void *GetAPI(duckdb_extension_info info, const char *version) { string version_string = version; idx_t major, minor, patch; @@ -266459,7 +265832,8 @@ struct ExtensionAccess { "Unsupported C CAPI version detected during extension initialization: " + string(version)); return nullptr; } - load_state.api_struct = CreateAPIv0(); + + load_state.api_struct = load_state.db.GetExtensionAPIV0(); return &load_state.api_struct; } }; @@ -267912,44 +267286,53 @@ using namespace duckdb_yyjson; // NOLINT namespace duckdb { +ProfilingInfo::ProfilingInfo(const profiler_settings_t &n_settings, const idx_t depth) : settings(n_settings) { + // Expand. + if (depth == 0) { + settings.insert(MetricsType::QUERY_NAME); + } else { + settings.insert(MetricsType::OPERATOR_TYPE); + } + for (const auto &metric : settings) { + Expand(expanded_settings, metric); + } + + // Reduce. + if (depth == 0) { + auto op_metrics = DefaultOperatorSettings(); + for (const auto metric : op_metrics) { + settings.erase(metric); + } + } else { + auto root_metrics = DefaultRootSettings(); + for (const auto metric : root_metrics) { + settings.erase(metric); + } + } + ResetMetrics(); +} + profiler_settings_t ProfilingInfo::DefaultSettings() { return {MetricsType::QUERY_NAME, MetricsType::BLOCKED_THREAD_TIME, MetricsType::CPU_TIME, MetricsType::EXTRA_INFO, MetricsType::CUMULATIVE_CARDINALITY, MetricsType::OPERATOR_TYPE, MetricsType::OPERATOR_CARDINALITY, MetricsType::CUMULATIVE_ROWS_SCANNED, MetricsType::OPERATOR_ROWS_SCANNED, - MetricsType::OPERATOR_TIMING, MetricsType::RESULT_SET_SIZE}; + MetricsType::OPERATOR_TIMING, MetricsType::RESULT_SET_SIZE, MetricsType::LATENCY, + MetricsType::ROWS_RETURNED}; } -profiler_settings_t ProfilingInfo::DefaultOperatorSettings() { - return {MetricsType::OPERATOR_CARDINALITY, MetricsType::OPERATOR_ROWS_SCANNED, MetricsType::OPERATOR_TIMING, - MetricsType::RESULT_SET_SIZE}; +profiler_settings_t ProfilingInfo::DefaultRootSettings() { + return {MetricsType::QUERY_NAME, MetricsType::BLOCKED_THREAD_TIME, MetricsType::LATENCY, + MetricsType::ROWS_RETURNED}; } -profiler_settings_t ProfilingInfo::AllSettings() { - auto all_settings = DefaultSettings(); - auto optimizer_settings = MetricsUtils::GetOptimizerMetrics(); - auto phase_timings = MetricsUtils::GetPhaseTimingMetrics(); - - for (auto &setting : optimizer_settings) { - all_settings.insert(setting); - } - - for (auto &setting : phase_timings) { - all_settings.insert(setting); - } - - return all_settings; +profiler_settings_t ProfilingInfo::DefaultOperatorSettings() { + return {MetricsType::OPERATOR_CARDINALITY, MetricsType::OPERATOR_ROWS_SCANNED, MetricsType::OPERATOR_TIMING, + MetricsType::OPERATOR_TYPE}; } void ProfilingInfo::ResetMetrics() { metrics.clear(); - - auto all_settings = AllSettings(); - - for (auto &metric : all_settings) { - if (!Enabled(metric)) { - continue; - } - + for (auto &metric : expanded_settings) { if (MetricsUtils::IsOptimizerMetric(metric) || MetricsUtils::IsPhaseTimingMetric(metric)) { metrics[metric] = Value::CreateValue(0.0); continue; @@ -267957,24 +267340,25 @@ void ProfilingInfo::ResetMetrics() { switch (metric) { case MetricsType::QUERY_NAME: + metrics[metric] = Value::CreateValue(""); + break; + case MetricsType::LATENCY: case MetricsType::BLOCKED_THREAD_TIME: case MetricsType::CPU_TIME: - case MetricsType::OPERATOR_TIMING: { + case MetricsType::OPERATOR_TIMING: metrics[metric] = Value::CreateValue(0.0); break; - } - case MetricsType::OPERATOR_TYPE: { + case MetricsType::OPERATOR_TYPE: metrics[metric] = Value::CreateValue(0); break; - } + case MetricsType::ROWS_RETURNED: case MetricsType::RESULT_SET_SIZE: case MetricsType::CUMULATIVE_CARDINALITY: case MetricsType::OPERATOR_CARDINALITY: case MetricsType::CUMULATIVE_ROWS_SCANNED: - case MetricsType::OPERATOR_ROWS_SCANNED: { + case MetricsType::OPERATOR_ROWS_SCANNED: metrics[metric] = Value::CreateValue(0); break; - } case MetricsType::EXTRA_INFO: break; default: @@ -267983,35 +267367,45 @@ void ProfilingInfo::ResetMetrics() { } } -bool ProfilingInfo::Enabled(const MetricsType setting) const { - if (settings.find(setting) != settings.end()) { +bool ProfilingInfo::Enabled(const profiler_settings_t &settings, const MetricsType metric) { + if (settings.find(metric) != settings.end()) { return true; } + return false; +} - switch (setting) { - case MetricsType::OPERATOR_TIMING: - return Enabled(MetricsType::CPU_TIME); - case MetricsType::OPERATOR_CARDINALITY: - return Enabled(MetricsType::CUMULATIVE_CARDINALITY); - case MetricsType::OPERATOR_ROWS_SCANNED: - return Enabled(MetricsType::CUMULATIVE_ROWS_SCANNED); - default: - break; - } +void ProfilingInfo::Expand(profiler_settings_t &settings, const MetricsType metric) { + settings.insert(metric); - if (MetricsUtils::IsOptimizerMetric(setting)) { - return Enabled(MetricsType::CUMULATIVE_OPTIMIZER_TIMING); + switch (metric) { + case MetricsType::CPU_TIME: + settings.insert(MetricsType::OPERATOR_TIMING); + return; + case MetricsType::CUMULATIVE_CARDINALITY: + settings.insert(MetricsType::OPERATOR_CARDINALITY); + return; + case MetricsType::CUMULATIVE_ROWS_SCANNED: + settings.insert(MetricsType::OPERATOR_ROWS_SCANNED); + return; + case MetricsType::CUMULATIVE_OPTIMIZER_TIMING: + case MetricsType::ALL_OPTIMIZERS: { + auto optimizer_metrics = MetricsUtils::GetOptimizerMetrics(); + for (const auto optimizer_metric : optimizer_metrics) { + settings.insert(optimizer_metric); + } + return; + } + default: + return; } - - return false; } -string ProfilingInfo::GetMetricAsString(MetricsType setting) const { - if (!Enabled(setting)) { - throw InternalException("Metric %s not enabled", EnumUtil::ToString(setting)); +string ProfilingInfo::GetMetricAsString(const MetricsType metric) const { + if (!Enabled(settings, metric)) { + throw InternalException("Metric %s not enabled", EnumUtil::ToString(metric)); } - if (setting == MetricsType::EXTRA_INFO) { + if (metric == MetricsType::EXTRA_INFO) { string result; for (auto &it : extra_info) { if (!result.empty()) { @@ -268023,14 +267417,12 @@ string ProfilingInfo::GetMetricAsString(MetricsType setting) const { } // The metric cannot be NULL and must be initialized. - D_ASSERT(!metrics.at(setting).IsNull()); - - if (setting == MetricsType::OPERATOR_TYPE) { - auto type = PhysicalOperatorType(metrics.at(setting).GetValue()); + D_ASSERT(!metrics.at(metric).IsNull()); + if (metric == MetricsType::OPERATOR_TYPE) { + auto type = PhysicalOperatorType(metrics.at(metric).GetValue()); return EnumUtil::ToString(type); } - - return metrics.at(setting).ToString(); + return metrics.at(metric).ToString(); } void ProfilingInfo::WriteMetricsToJSON(yyjson_mut_doc *doc, yyjson_mut_val *dest) { @@ -268072,6 +267464,7 @@ void ProfilingInfo::WriteMetricsToJSON(yyjson_mut_doc *doc, yyjson_mut_val *dest case MetricsType::QUERY_NAME: yyjson_mut_obj_add_strcpy(doc, dest, key_ptr, metrics[metric].GetValue().c_str()); break; + case MetricsType::LATENCY: case MetricsType::BLOCKED_THREAD_TIME: case MetricsType::CPU_TIME: case MetricsType::OPERATOR_TIMING: { @@ -268082,6 +267475,7 @@ void ProfilingInfo::WriteMetricsToJSON(yyjson_mut_doc *doc, yyjson_mut_val *dest yyjson_mut_obj_add_strcpy(doc, dest, key_ptr, GetMetricAsString(metric).c_str()); break; } + case MetricsType::ROWS_RETURNED: case MetricsType::RESULT_SET_SIZE: case MetricsType::CUMULATIVE_CARDINALITY: case MetricsType::OPERATOR_CARDINALITY: @@ -268220,6 +267614,7 @@ bool QueryProfiler::OperatorRequiresProfiling(PhysicalOperatorType op_type) { case PhysicalOperatorType::UNION: case PhysicalOperatorType::RECURSIVE_CTE: case PhysicalOperatorType::EMPTY_RESULT: + case PhysicalOperatorType::EXTENSION: return true; default: return false; @@ -268233,9 +267628,12 @@ void QueryProfiler::Finalize(ProfilingNode &node) { auto &info = node.GetProfilingInfo(); auto type = PhysicalOperatorType(info.GetMetricValue(MetricsType::OPERATOR_TYPE)); - if (type == PhysicalOperatorType::UNION && info.Enabled(MetricsType::OPERATOR_CARDINALITY)) { - info.AddToMetric(MetricsType::OPERATOR_CARDINALITY, - child->GetProfilingInfo().metrics[MetricsType::OPERATOR_CARDINALITY].GetValue()); + if (type == PhysicalOperatorType::UNION && + info.Enabled(info.expanded_settings, MetricsType::OPERATOR_CARDINALITY)) { + + auto &child_info = child->GetProfilingInfo(); + auto value = child_info.metrics[MetricsType::OPERATOR_CARDINALITY].GetValue(); + info.AddToMetric(MetricsType::OPERATOR_CARDINALITY, value); } } } @@ -268246,12 +267644,14 @@ void QueryProfiler::StartExplainAnalyze() { template static void GetCumulativeMetric(ProfilingNode &node, MetricsType cumulative_metric, MetricsType child_metric) { - node.GetProfilingInfo().metrics[cumulative_metric] = node.GetProfilingInfo().metrics[child_metric]; + auto &info = node.GetProfilingInfo(); + info.metrics[cumulative_metric] = info.metrics[child_metric]; + for (idx_t i = 0; i < node.GetChildCount(); i++) { auto child = node.GetChild(i); GetCumulativeMetric(*child, cumulative_metric, child_metric); - node.GetProfilingInfo().AddToMetric( - cumulative_metric, child->GetProfilingInfo().metrics[cumulative_metric].GetValue()); + auto value = child->GetProfilingInfo().metrics[cumulative_metric].GetValue(); + info.AddToMetric(cumulative_metric, value); } } @@ -268273,51 +267673,52 @@ void QueryProfiler::EndQuery() { } main_query.End(); - if (root && root->GetProfilingInfo().Enabled(MetricsType::OPERATOR_CARDINALITY)) { - Finalize(*root->GetChild(0)); + if (root) { + auto &info = root->GetProfilingInfo(); + if (info.Enabled(info.expanded_settings, MetricsType::OPERATOR_CARDINALITY)) { + Finalize(*root->GetChild(0)); + } } running = false; // Print or output the query profiling after query termination. // EXPLAIN ANALYZE output is not written by the profiler. if (IsEnabled() && !is_explain_analyze) { - // Expand the query info. if (root) { auto &info = root->GetProfilingInfo(); info = ProfilingInfo(ClientConfig::GetConfig(context).profiler_settings); + auto &child_info = root->children[0]->GetProfilingInfo(); info.metrics[MetricsType::QUERY_NAME] = query_info.query_name; - if (info.Enabled(MetricsType::BLOCKED_THREAD_TIME)) { + auto &settings = info.expanded_settings; + if (info.Enabled(settings, MetricsType::BLOCKED_THREAD_TIME)) { info.metrics[MetricsType::BLOCKED_THREAD_TIME] = query_info.blocked_thread_time; } - if (info.Enabled(MetricsType::OPERATOR_TIMING)) { - info.metrics[MetricsType::OPERATOR_TIMING] = main_query.Elapsed(); + if (info.Enabled(settings, MetricsType::LATENCY)) { + info.metrics[MetricsType::LATENCY] = main_query.Elapsed(); } - if (info.Enabled(MetricsType::CPU_TIME)) { + if (info.Enabled(settings, MetricsType::ROWS_RETURNED)) { + info.metrics[MetricsType::ROWS_RETURNED] = child_info.metrics[MetricsType::OPERATOR_CARDINALITY]; + } + if (info.Enabled(settings, MetricsType::CPU_TIME)) { GetCumulativeMetric(*root, MetricsType::CPU_TIME, MetricsType::OPERATOR_TIMING); } - if (info.Enabled(MetricsType::CUMULATIVE_CARDINALITY)) { + if (info.Enabled(settings, MetricsType::CUMULATIVE_CARDINALITY)) { GetCumulativeMetric(*root, MetricsType::CUMULATIVE_CARDINALITY, MetricsType::OPERATOR_CARDINALITY); } - if (info.Enabled(MetricsType::CUMULATIVE_ROWS_SCANNED)) { + if (info.Enabled(settings, MetricsType::CUMULATIVE_ROWS_SCANNED)) { GetCumulativeMetric(*root, MetricsType::CUMULATIVE_ROWS_SCANNED, MetricsType::OPERATOR_ROWS_SCANNED); } + if (info.Enabled(settings, MetricsType::RESULT_SET_SIZE)) { + info.metrics[MetricsType::RESULT_SET_SIZE] = child_info.metrics[MetricsType::RESULT_SET_SIZE]; + } MoveOptimizerPhasesToRoot(); - if (info.Enabled(MetricsType::CUMULATIVE_OPTIMIZER_TIMING)) { + if (info.Enabled(settings, MetricsType::CUMULATIVE_OPTIMIZER_TIMING)) { info.metrics.at(MetricsType::CUMULATIVE_OPTIMIZER_TIMING) = GetCumulativeOptimizers(*root); } - - if (info.Enabled(MetricsType::OPERATOR_TYPE)) { - info.settings.erase(MetricsType::OPERATOR_TYPE); - } - - if (info.Enabled(MetricsType::RESULT_SET_SIZE)) { - info.metrics[MetricsType::RESULT_SET_SIZE] = - root->children[0]->GetProfilingInfo().metrics[MetricsType::RESULT_SET_SIZE]; - } } string tree = ToString(); @@ -268382,34 +267783,20 @@ void QueryProfiler::EndPhase() { } } -bool SettingIsEnabled(const profiler_settings_t &settings, MetricsType metric) { - if (settings.find(metric) != settings.end()) { - return true; - } - - switch (metric) { - case MetricsType::OPERATOR_TIMING: - return SettingIsEnabled(settings, MetricsType::CPU_TIME); - case MetricsType::OPERATOR_CARDINALITY: - return SettingIsEnabled(settings, MetricsType::CUMULATIVE_CARDINALITY); - case MetricsType::OPERATOR_ROWS_SCANNED: - return SettingIsEnabled(settings, MetricsType::CUMULATIVE_ROWS_SCANNED); - default: - break; - } - - return false; -} - OperatorProfiler::OperatorProfiler(ClientContext &context) : context(context) { enabled = QueryProfiler::Get(context).IsEnabled(); - auto &settings = ClientConfig::GetConfig(context).profiler_settings; + auto &context_metrics = ClientConfig::GetConfig(context).profiler_settings; - profiler_settings_t op_metrics = ProfilingInfo::DefaultOperatorSettings(); - for (auto &metric : op_metrics) { - if (SettingIsEnabled(settings, metric)) { - operator_settings.insert(metric); - } + // Expand. + for (const auto metric : context_metrics) { + settings.insert(metric); + ProfilingInfo::Expand(settings, metric); + } + + // Reduce. + auto root_metrics = ProfilingInfo::DefaultRootSettings(); + for (const auto metric : root_metrics) { + settings.erase(metric); } } @@ -268417,15 +267804,13 @@ void OperatorProfiler::StartOperator(optional_ptr phys_o if (!enabled) { return; } - if (active_operator) { throw InternalException("OperatorProfiler: Attempting to call StartOperator while another operator is active"); } - active_operator = phys_op; - // start timing for current element - if (HasOperatorSetting(MetricsType::OPERATOR_TIMING)) { + // Start the timing of the current operator. + if (ProfilingInfo::Enabled(settings, MetricsType::OPERATOR_TIMING)) { op.Start(); } } @@ -268434,26 +267819,22 @@ void OperatorProfiler::EndOperator(optional_ptr chunk) { if (!enabled) { return; } - if (!active_operator) { throw InternalException("OperatorProfiler: Attempting to call EndOperator while another operator is active"); } - if (!operator_settings.empty()) { - // get the operator info for the current element - auto &curr_operator_info = GetOperatorInfo(*active_operator); - - // finish timing for the current element - if (HasOperatorSetting(MetricsType::OPERATOR_TIMING)) { + if (!settings.empty()) { + auto &info = GetOperatorInfo(*active_operator); + if (ProfilingInfo::Enabled(settings, MetricsType::OPERATOR_TIMING)) { op.End(); - curr_operator_info.AddTime(op.Elapsed()); + info.AddTime(op.Elapsed()); } - if (HasOperatorSetting(MetricsType::OPERATOR_CARDINALITY) && chunk) { - curr_operator_info.AddReturnedElements(chunk->size()); + if (ProfilingInfo::Enabled(settings, MetricsType::OPERATOR_CARDINALITY) && chunk) { + info.AddReturnedElements(chunk->size()); } - if (HasOperatorSetting(MetricsType::RESULT_SET_SIZE) && chunk) { - idx_t result_set_size = chunk->GetAllocationSize(); - curr_operator_info.AddResultSetSize(result_set_size); + if (ProfilingInfo::Enabled(settings, MetricsType::RESULT_SET_SIZE) && chunk) { + auto result_set_size = chunk->GetAllocationSize(); + info.AddResultSetSize(result_set_size); } } active_operator = nullptr; @@ -268463,11 +267844,10 @@ OperatorInformation &OperatorProfiler::GetOperatorInfo(const PhysicalOperator &p auto entry = timings.find(phys_op); if (entry != timings.end()) { return entry->second; - } else { - // add new entry - timings[phys_op] = OperatorInformation(); - return timings[phys_op]; } + // Add a new entry. + timings[phys_op] = OperatorInformation(); + return timings[phys_op]; } void OperatorProfiler::Flush(const PhysicalOperator &phys_op) { @@ -268488,30 +267868,31 @@ void QueryProfiler::Flush(OperatorProfiler &profiler) { auto &op = node.first.get(); auto entry = tree_map.find(op); D_ASSERT(entry != tree_map.end()); + auto &tree_node = entry->second.get(); + auto &info = tree_node.GetProfilingInfo(); - if (profiler.HasOperatorSetting(MetricsType::OPERATOR_TIMING)) { - tree_node.GetProfilingInfo().AddToMetric(MetricsType::OPERATOR_TIMING, node.second.time); + if (ProfilingInfo::Enabled(profiler.settings, MetricsType::OPERATOR_TIMING)) { + info.AddToMetric(MetricsType::OPERATOR_TIMING, node.second.time); } - if (profiler.HasOperatorSetting(MetricsType::OPERATOR_CARDINALITY)) { - tree_node.GetProfilingInfo().AddToMetric(MetricsType::OPERATOR_CARDINALITY, - node.second.elements_returned); + if (ProfilingInfo::Enabled(profiler.settings, MetricsType::OPERATOR_CARDINALITY)) { + info.AddToMetric(MetricsType::OPERATOR_CARDINALITY, node.second.elements_returned); } - if (profiler.HasOperatorSetting(MetricsType::OPERATOR_ROWS_SCANNED)) { + if (ProfilingInfo::Enabled(profiler.settings, MetricsType::OPERATOR_ROWS_SCANNED)) { if (op.type == PhysicalOperatorType::TABLE_SCAN) { auto &scan_op = op.Cast(); auto &bind_data = scan_op.bind_data; + if (bind_data && scan_op.function.cardinality) { auto cardinality = scan_op.function.cardinality(context, &(*bind_data)); if (cardinality && cardinality->has_estimated_cardinality) { - tree_node.GetProfilingInfo().AddToMetric(MetricsType::OPERATOR_ROWS_SCANNED, - cardinality->estimated_cardinality); + info.AddToMetric(MetricsType::OPERATOR_ROWS_SCANNED, cardinality->estimated_cardinality); } } } } - if (profiler.HasOperatorSetting(MetricsType::RESULT_SET_SIZE)) { - tree_node.GetProfilingInfo().AddToMetric(MetricsType::RESULT_SET_SIZE, node.second.result_set_size); + if (ProfilingInfo::Enabled(profiler.settings, MetricsType::RESULT_SET_SIZE)) { + info.AddToMetric(MetricsType::RESULT_SET_SIZE, node.second.result_set_size); } } profiler.timings.clear(); @@ -268519,10 +267900,15 @@ void QueryProfiler::Flush(OperatorProfiler &profiler) { void QueryProfiler::SetInfo(const double &blocked_thread_time) { lock_guard guard(flush_lock); - if (!IsEnabled() || !running || !root->GetProfilingInfo().Enabled(MetricsType::BLOCKED_THREAD_TIME)) { + if (!IsEnabled() || !running) { return; } + auto &info = root->GetProfilingInfo(); + auto metric_enabled = info.Enabled(info.expanded_settings, MetricsType::BLOCKED_THREAD_TIME); + if (!metric_enabled) { + return; + } query_info.blocked_thread_time = blocked_thread_time; } @@ -268800,8 +268186,8 @@ profiler_settings_t EraseQueryRootSettings(profiler_settings_t settings) { return settings; } -unique_ptr QueryProfiler::CreateTree(const PhysicalOperator &root_p, profiler_settings_t settings, - idx_t depth) { +unique_ptr QueryProfiler::CreateTree(const PhysicalOperator &root_p, const profiler_settings_t &settings, + const idx_t depth) { if (OperatorRequiresProfiling(root_p.type)) { query_requires_profiling = true; } @@ -268817,11 +268203,8 @@ unique_ptr QueryProfiler::CreateTree(const PhysicalOperator &root if (depth != 0) { info.AddToMetric(MetricsType::OPERATOR_TYPE, static_cast(root_p.type)); - if (info.Enabled(MetricsType::QUERY_NAME)) { - info.settings.erase(MetricsType::QUERY_NAME); - } } - if (info.Enabled(MetricsType::EXTRA_INFO)) { + if (info.Enabled(info.settings, MetricsType::EXTRA_INFO)) { info.extra_info = root_p.ParamsToString(); } @@ -268868,10 +268251,11 @@ void QueryProfiler::Print() { void QueryProfiler::MoveOptimizerPhasesToRoot() { auto &root_info = root->GetProfilingInfo(); auto &root_metrics = root_info.metrics; + for (auto &entry : phase_timings) { auto &phase = entry.first; auto &timing = entry.second; - if (root_info.Enabled(phase)) { + if (root_info.Enabled(root_info.expanded_settings, phase)) { root_metrics[phase] = Value::CreateValue(timing); } } @@ -272860,7 +272244,15 @@ unique_ptr SecretManager::DeserializeSecret(Deserializer &deserializ "Attempted to deserialize secret type '%s' which does not have a deserialization method", type); } - return deserialized_type.deserializer(deserializer, {scope, type, provider, name}); + auto function_entry = LookupFunctionInternal(type, provider); + if (!function_entry) { + throw IOException("Attempted to deserialize secret (type: '%s', provider: '%s', path: '%s') which does not " + "have any functions registered", + type, provider, secret_path); + } + + return deserialized_type.deserializer(deserializer, {scope, type, provider, name}, + function_entry->named_parameters); } void SecretManager::RegisterSecretType(SecretType &type) { @@ -278372,13 +277764,6 @@ unique_ptr Deliminator::Optimize(unique_ptr op if (candidate.joins.size() == candidate.delim_get_count && all_removed) { delim_join.type = LogicalOperatorType::LOGICAL_COMPARISON_JOIN; delim_join.duplicate_eliminated_columns.clear(); - if (all_equality_conditions) { - for (auto &cond : delim_join.conditions) { - if (IsEqualityJoinCondition(cond)) { - cond.comparison = ExpressionType::COMPARE_NOT_DISTINCT_FROM; - } - } - } } // Only DelimJoins are ever created as SINGLE joins, @@ -280899,10 +280284,17 @@ class InClauseRewriter : public LogicalOperatorVisitor { + namespace duckdb { unique_ptr InClauseRewriter::Rewrite(unique_ptr op) { if (op->children.size() == 1) { + if (op->children[0]->type == LogicalOperatorType::LOGICAL_GET) { + auto &get = op->children[0]->Cast(); + if (get.function.to_string && get.function.to_string(get.bind_data.get()) == "REMOTE") { + return op; + } + } root = std::move(op->children[0]); VisitOperatorExpressions(*op); op->children[0] = std::move(root); @@ -299067,8 +298459,13 @@ idx_t TaskScheduler::GetEstimatedCPUId() { #elif defined(_GNU_SOURCE) auto cpu = sched_getcpu(); if (cpu < 0) { +#ifndef DUCKDB_NO_THREADS // fallback to thread id return (idx_t)std::hash()(std::this_thread::get_id()); +#else + + return 0; +#endif } return (idx_t)cpu; #elif defined(__aarch64__) && defined(__APPLE__) @@ -299077,8 +298474,12 @@ idx_t TaskScheduler::GetEstimatedCPUId() { asm volatile("mrs %x0, tpidrro_el0" : "=r"(c)::"memory"); return (idx_t)(c & (1 << 3) - 1); #else +#ifndef DUCKDB_NO_THREADS // fallback to thread id return (idx_t)std::hash()(std::this_thread::get_id()); +#else + return 0; +#endif #endif #endif } @@ -309355,6 +308756,8 @@ class Transformer { //! Transform a range var into a (schema) qualified name QualifiedName TransformQualifiedName(duckdb_libpgquery::PGRangeVar &root); + //! Transform a Postgres TypeName string into a LogicalType (non-LIST types) + LogicalType TransformTypeNameInternal(duckdb_libpgquery::PGTypeName &name); //! Transform a Postgres TypeName string into a LogicalType LogicalType TransformTypeName(duckdb_libpgquery::PGTypeName &name); @@ -311474,8 +310877,10 @@ string InsertStatement::ToString() const { auto values_list = GetValuesList(); if (values_list) { D_ASSERT(!default_values); + auto saved_alias = values_list->alias; values_list->alias = string(); result += values_list->ToString(); + values_list->alias = saved_alias; } else if (select_statement) { D_ASSERT(!default_values); result += select_statement->ToString(); @@ -316127,12 +315532,7 @@ vector Transformer::TransformTypeModifiers(duckdb_libpgquery::PGTypeName return type_mods; } -LogicalType Transformer::TransformTypeName(duckdb_libpgquery::PGTypeName &type_name) { - if (type_name.type != duckdb_libpgquery::T_PGTypeName) { - throw ParserException("Expected a type"); - } - auto stack_checker = StackCheck(); - +LogicalType Transformer::TransformTypeNameInternal(duckdb_libpgquery::PGTypeName &type_name) { if (type_name.names->length > 1) { // qualified typename vector names; @@ -316141,24 +315541,27 @@ LogicalType Transformer::TransformTypeName(duckdb_libpgquery::PGTypeName &type_n } vector type_mods = TransformTypeModifiers(type_name); switch (type_name.names->length) { - case 2: + case 2: { return LogicalType::USER(INVALID_CATALOG, std::move(names[0]), std::move(names[1]), std::move(type_mods)); - case 3: + } + case 3: { return LogicalType::USER(std::move(names[0]), std::move(names[1]), std::move(names[2]), std::move(type_mods)); + } default: throw ParserException( "Too many qualifications for type name - expected [catalog.schema.name] or [schema.name]"); } } + auto name = PGPointerCast(type_name.names->tail->data.ptr_value)->val.str; // transform it to the SQL type LogicalTypeId base_type = TransformStringToLogicalTypeId(name); - LogicalType result_type; if (base_type == LogicalTypeId::LIST) { throw ParserException("LIST is not valid as a stand-alone type"); - } else if (base_type == LogicalTypeId::ENUM) { + } + if (base_type == LogicalTypeId::ENUM) { if (!type_name.typmods || type_name.typmods->length == 0) { throw ParserException("Enum needs a set of entries"); } @@ -316174,7 +315577,8 @@ LogicalType Transformer::TransformTypeName(duckdb_libpgquery::PGTypeName &type_n string_data[pos++] = StringVector::AddString(enum_vector, constant_value->val.val.str); } return LogicalType::ENUM(enum_vector, NumericCast(type_name.typmods->length)); - } else if (base_type == LogicalTypeId::STRUCT) { + } + if (base_type == LogicalTypeId::STRUCT) { if (!type_name.typmods || type_name.typmods->length == 0) { throw ParserException("Struct needs a name and entries"); } @@ -316204,9 +315608,9 @@ LogicalType Transformer::TransformTypeName(duckdb_libpgquery::PGTypeName &type_n children.push_back(make_pair(entry_name, entry_type)); } D_ASSERT(!children.empty()); - result_type = LogicalType::STRUCT(children); - - } else if (base_type == LogicalTypeId::MAP) { + return LogicalType::STRUCT(children); + } + if (base_type == LogicalTypeId::MAP) { if (!type_name.typmods || type_name.typmods->length != 2) { throw ParserException("Map type needs exactly two entries, key and value type"); } @@ -316215,8 +315619,9 @@ LogicalType Transformer::TransformTypeName(duckdb_libpgquery::PGTypeName &type_n auto value_type = TransformTypeName(*PGPointerCast(type_name.typmods->tail->data.ptr_value)); - result_type = LogicalType::MAP(std::move(key_type), std::move(value_type)); - } else if (base_type == LogicalTypeId::UNION) { + return LogicalType::MAP(std::move(key_type), std::move(value_type)); + } + if (base_type == LogicalTypeId::UNION) { if (!type_name.typmods || type_name.typmods->length == 0) { throw ParserException("Union type needs at least one member"); } @@ -316251,81 +315656,83 @@ LogicalType Transformer::TransformTypeName(duckdb_libpgquery::PGTypeName &type_n children.push_back(make_pair(entry_name, entry_type)); } D_ASSERT(!children.empty()); - result_type = LogicalType::UNION(std::move(children)); - } else if (base_type == LogicalTypeId::USER) { + return LogicalType::UNION(std::move(children)); + } + if (base_type == LogicalTypeId::USER) { string user_type_name {name}; vector type_mods = TransformTypeModifiers(type_name); - result_type = LogicalType::USER(user_type_name, type_mods); - } else { - SizeModifiers modifiers = GetSizeModifiers(type_name, base_type); - switch (base_type) { - case LogicalTypeId::VARCHAR: - if (modifiers.count > 1) { - throw ParserException("VARCHAR only supports a single modifier"); - } - // FIXME: create CHECK constraint based on varchar width - modifiers.width = 0; - result_type = LogicalType::VARCHAR; - break; - case LogicalTypeId::DECIMAL: - if (modifiers.count > 2) { - throw ParserException("DECIMAL only supports a maximum of two modifiers"); - } - if (modifiers.count == 1) { - // only width is provided: set scale to 0 - modifiers.scale = 0; - } - if (modifiers.width <= 0 || modifiers.width > Decimal::MAX_WIDTH_DECIMAL) { - throw ParserException("Width must be between 1 and %d!", (int)Decimal::MAX_WIDTH_DECIMAL); - } - if (modifiers.scale > modifiers.width) { - throw ParserException("Scale cannot be bigger than width"); - } - result_type = - LogicalType::DECIMAL(NumericCast(modifiers.width), NumericCast(modifiers.scale)); - break; - case LogicalTypeId::INTERVAL: - if (modifiers.count > 1) { - throw ParserException("INTERVAL only supports a single modifier"); - } - modifiers.width = 0; - result_type = LogicalType::INTERVAL; - break; - case LogicalTypeId::BIT: - if (!modifiers.width && type_name.typmods) { - throw ParserException("Type %s does not support any modifiers!", LogicalType(base_type).ToString()); - } - result_type = LogicalType(base_type); - break; - case LogicalTypeId::TIMESTAMP: - if (modifiers.count == 0) { - result_type = LogicalType::TIMESTAMP; - } else { - if (modifiers.count > 1) { - throw ParserException("TIMESTAMP only supports a single modifier"); - } - if (modifiers.width > 10) { - throw ParserException("TIMESTAMP only supports until nano-second precision (9)"); - } - if (modifiers.width == 0) { - result_type = LogicalType::TIMESTAMP_S; - } else if (modifiers.width <= 3) { - result_type = LogicalType::TIMESTAMP_MS; - } else if (modifiers.width <= 6) { - result_type = LogicalType::TIMESTAMP; - } else { - result_type = LogicalType::TIMESTAMP_NS; - } - } - break; - default: - if (modifiers.count > 0) { - throw ParserException("Type %s does not support any modifiers!", LogicalType(base_type).ToString()); - } - result_type = LogicalType(base_type); - break; + return LogicalType::USER(user_type_name, type_mods); + } + + SizeModifiers modifiers = GetSizeModifiers(type_name, base_type); + switch (base_type) { + case LogicalTypeId::VARCHAR: + if (modifiers.count > 1) { + throw ParserException("VARCHAR only supports a single modifier"); + } + // FIXME: create CHECK constraint based on varchar width + modifiers.width = 0; + return LogicalType::VARCHAR; + case LogicalTypeId::DECIMAL: + if (modifiers.count > 2) { + throw ParserException("DECIMAL only supports a maximum of two modifiers"); + } + if (modifiers.count == 1) { + // only width is provided: set scale to 0 + modifiers.scale = 0; } + if (modifiers.width <= 0 || modifiers.width > Decimal::MAX_WIDTH_DECIMAL) { + throw ParserException("Width must be between 1 and %d!", (int)Decimal::MAX_WIDTH_DECIMAL); + } + if (modifiers.scale > modifiers.width) { + throw ParserException("Scale cannot be bigger than width"); + } + return LogicalType::DECIMAL(NumericCast(modifiers.width), NumericCast(modifiers.scale)); + case LogicalTypeId::INTERVAL: + if (modifiers.count > 1) { + throw ParserException("INTERVAL only supports a single modifier"); + } + modifiers.width = 0; + return LogicalType::INTERVAL; + case LogicalTypeId::BIT: + if (!modifiers.width && type_name.typmods) { + throw ParserException("Type %s does not support any modifiers!", LogicalType(base_type).ToString()); + } + return LogicalType(base_type); + case LogicalTypeId::TIMESTAMP: + if (modifiers.count == 0) { + return LogicalType::TIMESTAMP; + } + if (modifiers.count > 1) { + throw ParserException("TIMESTAMP only supports a single modifier"); + } + if (modifiers.width > 10) { + throw ParserException("TIMESTAMP only supports until nano-second precision (9)"); + } + if (modifiers.width == 0) { + return LogicalType::TIMESTAMP_S; + } + if (modifiers.width <= 3) { + return LogicalType::TIMESTAMP_MS; + } + if (modifiers.width <= 6) { + return LogicalType::TIMESTAMP; + } + return LogicalType::TIMESTAMP_NS; + default: + if (modifiers.count > 0) { + throw ParserException("Type %s does not support any modifiers!", LogicalType(base_type).ToString()); + } + return LogicalType(base_type); } +} + +LogicalType Transformer::TransformTypeName(duckdb_libpgquery::PGTypeName &type_name) { + if (type_name.type != duckdb_libpgquery::T_PGTypeName) { + throw ParserException("Expected a type"); + } + auto stack_checker = StackCheck(); + auto result_type = TransformTypeNameInternal(type_name); if (type_name.arrayBounds) { // array bounds: turn the type into a list idx_t extra_stack = 0; @@ -324243,6 +323650,9 @@ class OrderBinder { unique_ptr CreateExtraReference(unique_ptr expr); + //! Sets the query component, for error messages + void SetQueryComponent(string component = string()); + private: unique_ptr CreateProjectionReference(ParsedExpression &expr, const idx_t index); unique_ptr BindConstant(ParsedExpression &expr); @@ -324252,6 +323662,7 @@ class OrderBinder { vector> binders; optional_ptr>> extra_list; SelectBindState &bind_state; + string query_component = "ORDER BY"; }; } // namespace duckdb @@ -324401,6 +323812,7 @@ void Binder::PrepareModifiers(OrderBinder &order_binder, QueryNode &statement, B make_uniq(Value::INTEGER(UnsafeNumericCast(1 + i)))); } } + order_binder.SetQueryComponent("DISTINCT ON"); for (auto &distinct_on_target : distinct.distinct_on_targets) { auto expr = BindOrderExpression(order_binder, std::move(distinct_on_target)); if (!expr) { @@ -324408,10 +323820,13 @@ void Binder::PrepareModifiers(OrderBinder &order_binder, QueryNode &statement, B } bound_distinct->target_distincts.push_back(std::move(expr)); } + order_binder.SetQueryComponent(); + bound_modifier = std::move(bound_distinct); break; } case ResultModifierType::ORDER_MODIFIER: { + auto &order = mod->Cast(); auto bound_order = make_uniq(); auto &config = DBConfig::GetConfig(context); @@ -328138,7 +327553,10 @@ void Binder::BindGeneratedColumns(BoundCreateTableInfo &info) { auto bound_expression = expr_binder.Bind(expression); D_ASSERT(bound_expression); - D_ASSERT(!bound_expression->HasSubquery()); + if (bound_expression->HasSubquery()) { + throw BinderException("Failed to bind generated column '%s' because the expression contains a subquery", + col.Name()); + } if (col.Type().id() == LogicalTypeId::ANY) { // Do this before changing the type, so we know it's the first time the type is set col.ChangeGeneratedExpressionType(bound_expression->return_type); @@ -336790,8 +336208,10 @@ optional_idx OrderBinder::TryGetProjectionReference(ParsedExpression &expr) cons // this is disabled by default (matching Postgres) - but we can control this with a setting auto &config = ClientConfig::GetConfig(binders[0].get().context); if (!config.order_by_non_integer_literal) { - throw BinderException(expr, "ORDER BY non-integer literal has no effect.\n* SET " - "order_by_non_integer_literal=true to allow this behavior."); + throw BinderException(expr, + "%s non-integer literal has no effect.\n* SET " + "order_by_non_integer_literal=true to allow this behavior.", + query_component); } break; } @@ -336823,6 +336243,14 @@ optional_idx OrderBinder::TryGetProjectionReference(ParsedExpression &expr) cons return optional_idx(); } +void OrderBinder::SetQueryComponent(string component) { + if (component.empty()) { + query_component = "ORDER BY"; + } else { + query_component = std::move(component); + } +} + unique_ptr OrderBinder::BindConstant(ParsedExpression &expr) { auto index = TryGetProjectionReference(expr); if (!index.IsValid()) { @@ -336859,7 +336287,7 @@ unique_ptr OrderBinder::Bind(unique_ptr expr) { break; } case ExpressionClass::PARAMETER: { - throw ParameterNotAllowedException("Parameter not supported in ORDER BY clause"); + throw ParameterNotAllowedException("Parameter not supported in %s clause", query_component); } case ExpressionClass::COLLATE: { auto &collation = expr->Cast(); @@ -342376,7 +341804,7 @@ DynamicTableFilterSet::GetFinalTableFilters(const PhysicalTableScan &scan, auto result = make_uniq(); if (existing_filters) { for (auto &entry : existing_filters->filters) { - result->filters[entry.first] = entry.second->Copy(); + result->PushFilter(entry.first, entry.second->Copy()); } } for (auto &entry : filters) { @@ -342385,7 +341813,7 @@ DynamicTableFilterSet::GetFinalTableFilters(const PhysicalTableScan &scan, // skip row id filters continue; } - result->filters[filter.first] = filter.second->Copy(); + result->PushFilter(filter.first, filter.second->Copy()); } } if (result->filters.empty()) { @@ -346405,16 +345833,15 @@ class BitpackingPrimitives { } } else { idx_t misaligned_count = count % BITPACKING_ALGORITHM_GROUP_SIZE; - T tmp_buffer[BITPACKING_ALGORITHM_GROUP_SIZE]; // TODO maybe faster on the heap? - count -= misaligned_count; - for (idx_t i = 0; i < count; i += BITPACKING_ALGORITHM_GROUP_SIZE) { PackGroup(dst + (i * width) / 8, src + i, width); } - // Input was not aligned to BITPACKING_ALGORITHM_GROUP_SIZE, we need a copy + // The input is not aligned to BITPACKING_ALGORITHM_GROUP_SIZE. + // Copy the unaligned count into a zero-initialized temporary group, and pack it. if (misaligned_count) { + T tmp_buffer[BITPACKING_ALGORITHM_GROUP_SIZE] = {0}; memcpy(tmp_buffer, src + count, misaligned_count * sizeof(T)); PackGroup(dst + (count * width) / 8, tmp_buffer, width); } @@ -350042,10 +349469,14 @@ struct BitpackingState { delta_required_bitwidth, static_cast(minimum_delta), delta_offset, compression_buffer, compression_buffer_idx, data_ptr); + // FOR (frame of reference). + total_size += sizeof(T); + // Aligned bitpacking width. + total_size += AlignValue(sizeof(bitpacking_width_t)); + // Delta offset. + total_size += sizeof(T); + // Compressed data size. total_size += BitpackingPrimitives::GetRequiredSize(compression_buffer_idx, delta_required_bitwidth); - total_size += sizeof(T); // FOR value - total_size += sizeof(T); // Delta offset value - total_size += AlignValue(sizeof(bitpacking_width_t)); // FOR value return true; } @@ -367147,13 +366578,13 @@ static const StorageVersionInfo storage_version_info[] = { {"v0.3.0", 25}, {"v0.3.1", 27}, {"v0.3.2", 31}, {"v0.3.3", 33}, {"v0.3.4", 33}, {"v0.3.5", 33}, {"v0.4.0", 33}, {"v0.5.0", 38}, {"v0.5.1", 38}, {"v0.6.0", 39}, {"v0.6.1", 39}, {"v0.7.0", 43}, {"v0.7.1", 43}, {"v0.8.0", 51}, {"v0.8.1", 51}, {"v0.9.0", 64}, {"v0.9.1", 64}, {"v0.9.2", 64}, {"v0.10.0", 64}, {"v0.10.1", 64}, {"v0.10.2", 64}, - {"v0.10.3", 64}, {"v1.0.0", 64}, {"v1.1.0", 64}, {nullptr, 0}}; + {"v0.10.3", 64}, {"v1.0.0", 64}, {"v1.1.0", 64}, {"v1.1.1", 64}, {nullptr, 0}}; // END OF STORAGE VERSION INFO // START OF SERIALIZATION VERSION INFO static const SerializationVersionInfo serialization_version_info[] = {{"v0.10.0", 1}, {"v0.10.1", 1}, {"v0.10.2", 1}, {"v0.10.3", 2}, {"v1.0.0", 2}, {"v1.1.0", 3}, - {"latest", 3}, {nullptr, 0}}; + {"v1.1.1", 3}, {"latest", 3}, {nullptr, 0}}; // END OF SERIALIZATION VERSION INFO optional_idx GetStorageVersion(const char *version_string) { @@ -373202,8 +372633,8 @@ unique_ptr RowGroupCollection::GetCheckpointTask(CollectionCheck } void RowGroupCollection::Checkpoint(TableDataWriter &writer, TableStatistics &global_stats) { - auto segments = row_groups->MoveSegments(); auto l = row_groups->Lock(); + auto segments = row_groups->MoveSegments(l); CollectionCheckpointState checkpoint_state(*this, writer, segments, global_stats); @@ -373564,11 +372995,15 @@ void RowVersionManager::CleanupAppend(transaction_t lowest_active_transaction, i for (idx_t vector_idx = start_vector_idx; vector_idx <= end_vector_idx; vector_idx++) { idx_t vcount = vector_idx == end_vector_idx ? row_group_end - end_vector_idx * STANDARD_VECTOR_SIZE : STANDARD_VECTOR_SIZE; - auto &info = *vector_info[vector_idx]; if (vcount != STANDARD_VECTOR_SIZE) { // not written fully - skip continue; } + if (!vector_info[vector_idx]) { + // already vacuumed - skip + continue; + } + auto &info = *vector_info[vector_idx]; // if we wrote the entire chunk info try to compress it unique_ptr new_info; auto cleanup = info.Cleanup(lowest_active_transaction, new_info); diff --git a/c_src/duckdb/duckdb.hpp b/c_src/duckdb/duckdb.hpp index bfeb111..b11ba7b 100644 --- a/c_src/duckdb/duckdb.hpp +++ b/c_src/duckdb/duckdb.hpp @@ -10,11 +10,11 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI #pragma once #define DUCKDB_AMALGAMATION 1 -#define DUCKDB_SOURCE_ID "af39bd0dcf" -#define DUCKDB_VERSION "v1.1.1" +#define DUCKDB_SOURCE_ID "f680b7d08f" +#define DUCKDB_VERSION "v1.1.2" #define DUCKDB_MAJOR_VERSION 1 #define DUCKDB_MINOR_VERSION 1 -#define DUCKDB_PATCH_VERSION "1" +#define DUCKDB_PATCH_VERSION "2" //===----------------------------------------------------------------------===// // DuckDB // @@ -746,6 +746,16 @@ class InvalidInputException : public Exception { } }; +class ExecutorException : public Exception { +public: + DUCKDB_API explicit ExecutorException(const string &msg); + + template + explicit ExecutorException(const string &msg, ARGS... params) + : ExecutorException(ConstructMessage(msg, params...)) { + } +}; + class InvalidConfigurationException : public Exception { public: DUCKDB_API explicit InvalidConfigurationException(const string &msg); @@ -8864,22 +8874,19 @@ class DataChunk { //! Set the DataChunk to own the data of data chunk, destroying the other chunk in the process DUCKDB_API void Move(DataChunk &chunk); - //! Initializes the DataChunk with the specified types to an empty DataChunk - //! This will create one vector of the specified type for each LogicalType in the - //! types list. The vector will be referencing vector to the data owned by - //! the DataChunk. + //! Initializes a DataChunk with the given types and without any vector data allocation. + DUCKDB_API void InitializeEmpty(const vector &types); + + //! Initializes a DataChunk with the given types. Then, if the corresponding boolean in the initialize-vector is + //! true, it initializes the vector for that data type. + DUCKDB_API void Initialize(ClientContext &context, const vector &types, + idx_t capacity = STANDARD_VECTOR_SIZE); DUCKDB_API void Initialize(Allocator &allocator, const vector &types, idx_t capacity = STANDARD_VECTOR_SIZE); - DUCKDB_API void Initialize(ClientContext &context, const vector &types, + DUCKDB_API void Initialize(ClientContext &context, const vector &types, const vector &initialize, + idx_t capacity = STANDARD_VECTOR_SIZE); + DUCKDB_API void Initialize(Allocator &allocator, const vector &types, const vector &initialize, idx_t capacity = STANDARD_VECTOR_SIZE); - //! Initializes an empty DataChunk with the given types. The vectors will *not* have any data allocated for them. - DUCKDB_API void InitializeEmpty(const vector &types); - - DUCKDB_API void InitializeEmpty(vector::const_iterator begin, vector::const_iterator end); - DUCKDB_API void Initialize(Allocator &allocator, vector::const_iterator begin, - vector::const_iterator end, idx_t capacity = STANDARD_VECTOR_SIZE); - DUCKDB_API void Initialize(ClientContext &context, vector::const_iterator begin, - vector::const_iterator end, idx_t capacity = STANDARD_VECTOR_SIZE); //! Append the other DataChunk to this one. The column count and types of //! the two DataChunks have to match exactly. Throws an exception if there @@ -11203,10 +11210,11 @@ struct ExpressionState { vector> child_states; vector types; DataChunk intermediate_chunk; + vector initialize; public: - void AddChild(Expression *expr); - void Finalize(bool empty = false); + void AddChild(Expression &child_expr); + void Finalize(); Allocator &GetAllocator(); bool HasContext(); DUCKDB_API ClientContext &GetContext(); @@ -21862,7 +21870,7 @@ class TableFunction : public SimpleNamedParameterFunction { // NOLINT: work-arou //! The returned FunctionData object should be constant and should not be changed during execution. table_function_bind_t bind; //! (Optional) Bind replace function - //! This function is called before the regular bind function. It allows returning a TableRef will be used to + //! This function is called before the regular bind function. It allows returning a TableRef that will be used to //! to generate a logical plan that replaces the LogicalGet of a regularly bound TableFunction. The BindReplace can //! also return a nullptr to indicate a regular bind needs to be performed instead. table_function_bind_replace_t bind_replace; @@ -23658,7 +23666,7 @@ struct duckdb_extension_access { //! Fetch the database from duckdb to register extensions to duckdb_database *(*get_database)(duckdb_extension_info info); //! Fetch the API - void *(*get_api)(duckdb_extension_info info, const char *version); + const void *(*get_api)(duckdb_extension_info info, const char *version); }; //===--------------------------------------------------------------------===// @@ -27446,6 +27454,8 @@ enum class MetricsType : uint8_t { CUMULATIVE_ROWS_SCANNED, OPERATOR_ROWS_SCANNED, OPERATOR_TIMING, + LATENCY, + ROWS_RETURNED, RESULT_SET_SIZE, ALL_OPTIMIZERS, CUMULATIVE_OPTIMIZER_TIMING, @@ -27513,38 +27523,36 @@ namespace duckdb { class ProfilingInfo { public: - // Enabling a metric adds it to this set. + //! Enabling a metric adds it to this set. profiler_settings_t settings; - // Contains all enabled metrics. + //! This set contains the expanded to-be-collected metrics, which can differ from 'settings'. + profiler_settings_t expanded_settings; + //! Contains all enabled metrics. profiler_metrics_t metrics; - // Additional metrics. + //! Additional metrics. // FIXME: move to metrics. InsertionOrderPreservingMap extra_info; public: ProfilingInfo() = default; - explicit ProfilingInfo(profiler_settings_t &n_settings, idx_t depth = 0) : settings(n_settings) { - if (depth == 0) { - settings.insert(MetricsType::QUERY_NAME); - } else { - settings.insert(MetricsType::OPERATOR_TYPE); - } - ResetMetrics(); - } + explicit ProfilingInfo(const profiler_settings_t &n_settings, const idx_t depth = 0); ProfilingInfo(ProfilingInfo &) = default; ProfilingInfo &operator=(ProfilingInfo const &) = default; public: static profiler_settings_t DefaultSettings(); + static profiler_settings_t DefaultRootSettings(); static profiler_settings_t DefaultOperatorSettings(); - static profiler_settings_t AllSettings(); public: void ResetMetrics(); - bool Enabled(const MetricsType setting) const; + //! Returns true, if the query profiler must collect this metric. + static bool Enabled(const profiler_settings_t &settings, const MetricsType metric); + //! Expand metrics depending on the collection of other metrics. + static void Expand(profiler_settings_t &settings, const MetricsType metric); public: - string GetMetricAsString(MetricsType setting) const; + string GetMetricAsString(const MetricsType metric) const; void WriteMetricsToJSON(duckdb_yyjson::yyjson_mut_doc *doc, duckdb_yyjson::yyjson_mut_val *destination); public: @@ -27555,20 +27563,20 @@ class ProfilingInfo { } template - void AddToMetric(const MetricsType setting, const Value &value) { - D_ASSERT(!metrics[setting].IsNull()); - if (metrics.find(setting) == metrics.end()) { - metrics[setting] = value; + void AddToMetric(const MetricsType type, const Value &value) { + D_ASSERT(!metrics[type].IsNull()); + if (metrics.find(type) == metrics.end()) { + metrics[type] = value; return; } - auto new_value = metrics[setting].GetValue() + value.GetValue(); - metrics[setting] = Value::CreateValue(new_value); + auto new_value = metrics[type].GetValue() + value.GetValue(); + metrics[type] = Value::CreateValue(new_value); } template - void AddToMetric(const MetricsType setting, const METRIC_TYPE &value) { + void AddToMetric(const MetricsType type, const METRIC_TYPE &value) { auto new_value = Value::CreateValue(value); - return AddToMetric(setting, new_value); + return AddToMetric(type, new_value); } }; } // namespace duckdb @@ -31802,12 +31810,26 @@ class StreamQueryResult : public QueryResult { namespace duckdb { struct TableDescription { +public: //! The schema of the table string schema; //! The table name of the table string table; //! The columns of the table vector columns; + +public: + idx_t PhysicalColumnCount() const { + idx_t count = 0; + for (auto &column : columns) { + if (column.Generated()) { + continue; + } + count++; + } + D_ASSERT(count != 0); + return count; + } }; } // namespace duckdb @@ -32773,6 +32795,816 @@ struct VersioningUtils { } // namespace duckdb + + + + +//===--------------------------------------------------------------------===// +// Function pointer struct +//===--------------------------------------------------------------------===// +typedef struct { + // v0.0.1 + duckdb_state (*duckdb_open)(const char *path, duckdb_database *out_database); + duckdb_state (*duckdb_open_ext)(const char *path, duckdb_database *out_database, duckdb_config config, + char **out_error); + void (*duckdb_close)(duckdb_database *database); + duckdb_state (*duckdb_connect)(duckdb_database database, duckdb_connection *out_connection); + void (*duckdb_interrupt)(duckdb_connection connection); + duckdb_query_progress_type (*duckdb_query_progress)(duckdb_connection connection); + void (*duckdb_disconnect)(duckdb_connection *connection); + const char *(*duckdb_library_version)(); + duckdb_state (*duckdb_create_config)(duckdb_config *out_config); + size_t (*duckdb_config_count)(); + duckdb_state (*duckdb_get_config_flag)(size_t index, const char **out_name, const char **out_description); + duckdb_state (*duckdb_set_config)(duckdb_config config, const char *name, const char *option); + void (*duckdb_destroy_config)(duckdb_config *config); + duckdb_state (*duckdb_query)(duckdb_connection connection, const char *query, duckdb_result *out_result); + void (*duckdb_destroy_result)(duckdb_result *result); + const char *(*duckdb_column_name)(duckdb_result *result, idx_t col); + duckdb_type (*duckdb_column_type)(duckdb_result *result, idx_t col); + duckdb_statement_type (*duckdb_result_statement_type)(duckdb_result result); + duckdb_logical_type (*duckdb_column_logical_type)(duckdb_result *result, idx_t col); + idx_t (*duckdb_column_count)(duckdb_result *result); + idx_t (*duckdb_rows_changed)(duckdb_result *result); + const char *(*duckdb_result_error)(duckdb_result *result); + void *(*duckdb_malloc)(size_t size); + void (*duckdb_free)(void *ptr); + idx_t (*duckdb_vector_size)(); + bool (*duckdb_string_is_inlined)(duckdb_string_t string); + duckdb_date_struct (*duckdb_from_date)(duckdb_date date); + duckdb_date (*duckdb_to_date)(duckdb_date_struct date); + bool (*duckdb_is_finite_date)(duckdb_date date); + duckdb_time_struct (*duckdb_from_time)(duckdb_time time); + duckdb_time_tz (*duckdb_create_time_tz)(int64_t micros, int32_t offset); + duckdb_time_tz_struct (*duckdb_from_time_tz)(duckdb_time_tz micros); + duckdb_time (*duckdb_to_time)(duckdb_time_struct time); + duckdb_timestamp_struct (*duckdb_from_timestamp)(duckdb_timestamp ts); + duckdb_timestamp (*duckdb_to_timestamp)(duckdb_timestamp_struct ts); + bool (*duckdb_is_finite_timestamp)(duckdb_timestamp ts); + double (*duckdb_hugeint_to_double)(duckdb_hugeint val); + duckdb_hugeint (*duckdb_double_to_hugeint)(double val); + double (*duckdb_uhugeint_to_double)(duckdb_uhugeint val); + duckdb_uhugeint (*duckdb_double_to_uhugeint)(double val); + duckdb_decimal (*duckdb_double_to_decimal)(double val, uint8_t width, uint8_t scale); + double (*duckdb_decimal_to_double)(duckdb_decimal val); + duckdb_state (*duckdb_prepare)(duckdb_connection connection, const char *query, + duckdb_prepared_statement *out_prepared_statement); + void (*duckdb_destroy_prepare)(duckdb_prepared_statement *prepared_statement); + const char *(*duckdb_prepare_error)(duckdb_prepared_statement prepared_statement); + idx_t (*duckdb_nparams)(duckdb_prepared_statement prepared_statement); + const char *(*duckdb_parameter_name)(duckdb_prepared_statement prepared_statement, idx_t index); + duckdb_type (*duckdb_param_type)(duckdb_prepared_statement prepared_statement, idx_t param_idx); + duckdb_state (*duckdb_clear_bindings)(duckdb_prepared_statement prepared_statement); + duckdb_statement_type (*duckdb_prepared_statement_type)(duckdb_prepared_statement statement); + duckdb_state (*duckdb_bind_value)(duckdb_prepared_statement prepared_statement, idx_t param_idx, duckdb_value val); + duckdb_state (*duckdb_bind_parameter_index)(duckdb_prepared_statement prepared_statement, idx_t *param_idx_out, + const char *name); + duckdb_state (*duckdb_bind_boolean)(duckdb_prepared_statement prepared_statement, idx_t param_idx, bool val); + duckdb_state (*duckdb_bind_int8)(duckdb_prepared_statement prepared_statement, idx_t param_idx, int8_t val); + duckdb_state (*duckdb_bind_int16)(duckdb_prepared_statement prepared_statement, idx_t param_idx, int16_t val); + duckdb_state (*duckdb_bind_int32)(duckdb_prepared_statement prepared_statement, idx_t param_idx, int32_t val); + duckdb_state (*duckdb_bind_int64)(duckdb_prepared_statement prepared_statement, idx_t param_idx, int64_t val); + duckdb_state (*duckdb_bind_hugeint)(duckdb_prepared_statement prepared_statement, idx_t param_idx, + duckdb_hugeint val); + duckdb_state (*duckdb_bind_uhugeint)(duckdb_prepared_statement prepared_statement, idx_t param_idx, + duckdb_uhugeint val); + duckdb_state (*duckdb_bind_decimal)(duckdb_prepared_statement prepared_statement, idx_t param_idx, + duckdb_decimal val); + duckdb_state (*duckdb_bind_uint8)(duckdb_prepared_statement prepared_statement, idx_t param_idx, uint8_t val); + duckdb_state (*duckdb_bind_uint16)(duckdb_prepared_statement prepared_statement, idx_t param_idx, uint16_t val); + duckdb_state (*duckdb_bind_uint32)(duckdb_prepared_statement prepared_statement, idx_t param_idx, uint32_t val); + duckdb_state (*duckdb_bind_uint64)(duckdb_prepared_statement prepared_statement, idx_t param_idx, uint64_t val); + duckdb_state (*duckdb_bind_float)(duckdb_prepared_statement prepared_statement, idx_t param_idx, float val); + duckdb_state (*duckdb_bind_double)(duckdb_prepared_statement prepared_statement, idx_t param_idx, double val); + duckdb_state (*duckdb_bind_date)(duckdb_prepared_statement prepared_statement, idx_t param_idx, duckdb_date val); + duckdb_state (*duckdb_bind_time)(duckdb_prepared_statement prepared_statement, idx_t param_idx, duckdb_time val); + duckdb_state (*duckdb_bind_timestamp)(duckdb_prepared_statement prepared_statement, idx_t param_idx, + duckdb_timestamp val); + duckdb_state (*duckdb_bind_timestamp_tz)(duckdb_prepared_statement prepared_statement, idx_t param_idx, + duckdb_timestamp val); + duckdb_state (*duckdb_bind_interval)(duckdb_prepared_statement prepared_statement, idx_t param_idx, + duckdb_interval val); + duckdb_state (*duckdb_bind_varchar)(duckdb_prepared_statement prepared_statement, idx_t param_idx, const char *val); + duckdb_state (*duckdb_bind_varchar_length)(duckdb_prepared_statement prepared_statement, idx_t param_idx, + const char *val, idx_t length); + duckdb_state (*duckdb_bind_blob)(duckdb_prepared_statement prepared_statement, idx_t param_idx, const void *data, + idx_t length); + duckdb_state (*duckdb_bind_null)(duckdb_prepared_statement prepared_statement, idx_t param_idx); + duckdb_state (*duckdb_execute_prepared)(duckdb_prepared_statement prepared_statement, duckdb_result *out_result); + idx_t (*duckdb_extract_statements)(duckdb_connection connection, const char *query, + duckdb_extracted_statements *out_extracted_statements); + duckdb_state (*duckdb_prepare_extracted_statement)(duckdb_connection connection, + duckdb_extracted_statements extracted_statements, idx_t index, + duckdb_prepared_statement *out_prepared_statement); + const char *(*duckdb_extract_statements_error)(duckdb_extracted_statements extracted_statements); + void (*duckdb_destroy_extracted)(duckdb_extracted_statements *extracted_statements); + duckdb_state (*duckdb_pending_prepared)(duckdb_prepared_statement prepared_statement, + duckdb_pending_result *out_result); + void (*duckdb_destroy_pending)(duckdb_pending_result *pending_result); + const char *(*duckdb_pending_error)(duckdb_pending_result pending_result); + duckdb_pending_state (*duckdb_pending_execute_task)(duckdb_pending_result pending_result); + duckdb_pending_state (*duckdb_pending_execute_check_state)(duckdb_pending_result pending_result); + duckdb_state (*duckdb_execute_pending)(duckdb_pending_result pending_result, duckdb_result *out_result); + bool (*duckdb_pending_execution_is_finished)(duckdb_pending_state pending_state); + void (*duckdb_destroy_value)(duckdb_value *value); + duckdb_value (*duckdb_create_varchar)(const char *text); + duckdb_value (*duckdb_create_varchar_length)(const char *text, idx_t length); + duckdb_value (*duckdb_create_int64)(int64_t val); + duckdb_value (*duckdb_create_struct_value)(duckdb_logical_type type, duckdb_value *values); + duckdb_value (*duckdb_create_list_value)(duckdb_logical_type type, duckdb_value *values, idx_t value_count); + duckdb_value (*duckdb_create_array_value)(duckdb_logical_type type, duckdb_value *values, idx_t value_count); + char *(*duckdb_get_varchar)(duckdb_value value); + int64_t (*duckdb_get_int64)(duckdb_value val); + duckdb_logical_type (*duckdb_create_logical_type)(duckdb_type type); + char *(*duckdb_logical_type_get_alias)(duckdb_logical_type type); + duckdb_logical_type (*duckdb_create_list_type)(duckdb_logical_type type); + duckdb_logical_type (*duckdb_create_array_type)(duckdb_logical_type type, idx_t array_size); + duckdb_logical_type (*duckdb_create_map_type)(duckdb_logical_type key_type, duckdb_logical_type value_type); + duckdb_logical_type (*duckdb_create_union_type)(duckdb_logical_type *member_types, const char **member_names, + idx_t member_count); + duckdb_logical_type (*duckdb_create_struct_type)(duckdb_logical_type *member_types, const char **member_names, + idx_t member_count); + duckdb_logical_type (*duckdb_create_enum_type)(const char **member_names, idx_t member_count); + duckdb_logical_type (*duckdb_create_decimal_type)(uint8_t width, uint8_t scale); + duckdb_type (*duckdb_get_type_id)(duckdb_logical_type type); + uint8_t (*duckdb_decimal_width)(duckdb_logical_type type); + uint8_t (*duckdb_decimal_scale)(duckdb_logical_type type); + duckdb_type (*duckdb_decimal_internal_type)(duckdb_logical_type type); + duckdb_type (*duckdb_enum_internal_type)(duckdb_logical_type type); + uint32_t (*duckdb_enum_dictionary_size)(duckdb_logical_type type); + char *(*duckdb_enum_dictionary_value)(duckdb_logical_type type, idx_t index); + duckdb_logical_type (*duckdb_list_type_child_type)(duckdb_logical_type type); + duckdb_logical_type (*duckdb_array_type_child_type)(duckdb_logical_type type); + idx_t (*duckdb_array_type_array_size)(duckdb_logical_type type); + duckdb_logical_type (*duckdb_map_type_key_type)(duckdb_logical_type type); + duckdb_logical_type (*duckdb_map_type_value_type)(duckdb_logical_type type); + idx_t (*duckdb_struct_type_child_count)(duckdb_logical_type type); + char *(*duckdb_struct_type_child_name)(duckdb_logical_type type, idx_t index); + duckdb_logical_type (*duckdb_struct_type_child_type)(duckdb_logical_type type, idx_t index); + idx_t (*duckdb_union_type_member_count)(duckdb_logical_type type); + char *(*duckdb_union_type_member_name)(duckdb_logical_type type, idx_t index); + duckdb_logical_type (*duckdb_union_type_member_type)(duckdb_logical_type type, idx_t index); + void (*duckdb_destroy_logical_type)(duckdb_logical_type *type); + duckdb_data_chunk (*duckdb_fetch_chunk)(duckdb_result result); + duckdb_data_chunk (*duckdb_create_data_chunk)(duckdb_logical_type *types, idx_t column_count); + void (*duckdb_destroy_data_chunk)(duckdb_data_chunk *chunk); + void (*duckdb_data_chunk_reset)(duckdb_data_chunk chunk); + idx_t (*duckdb_data_chunk_get_column_count)(duckdb_data_chunk chunk); + duckdb_vector (*duckdb_data_chunk_get_vector)(duckdb_data_chunk chunk, idx_t col_idx); + idx_t (*duckdb_data_chunk_get_size)(duckdb_data_chunk chunk); + void (*duckdb_data_chunk_set_size)(duckdb_data_chunk chunk, idx_t size); + duckdb_logical_type (*duckdb_vector_get_column_type)(duckdb_vector vector); + void *(*duckdb_vector_get_data)(duckdb_vector vector); + uint64_t *(*duckdb_vector_get_validity)(duckdb_vector vector); + void (*duckdb_vector_ensure_validity_writable)(duckdb_vector vector); + void (*duckdb_vector_assign_string_element)(duckdb_vector vector, idx_t index, const char *str); + void (*duckdb_vector_assign_string_element_len)(duckdb_vector vector, idx_t index, const char *str, idx_t str_len); + duckdb_vector (*duckdb_list_vector_get_child)(duckdb_vector vector); + idx_t (*duckdb_list_vector_get_size)(duckdb_vector vector); + duckdb_state (*duckdb_list_vector_set_size)(duckdb_vector vector, idx_t size); + duckdb_state (*duckdb_list_vector_reserve)(duckdb_vector vector, idx_t required_capacity); + duckdb_vector (*duckdb_struct_vector_get_child)(duckdb_vector vector, idx_t index); + duckdb_vector (*duckdb_array_vector_get_child)(duckdb_vector vector); + bool (*duckdb_validity_row_is_valid)(uint64_t *validity, idx_t row); + void (*duckdb_validity_set_row_validity)(uint64_t *validity, idx_t row, bool valid); + void (*duckdb_validity_set_row_invalid)(uint64_t *validity, idx_t row); + void (*duckdb_validity_set_row_valid)(uint64_t *validity, idx_t row); + duckdb_scalar_function (*duckdb_create_scalar_function)(); + void (*duckdb_destroy_scalar_function)(duckdb_scalar_function *scalar_function); + void (*duckdb_scalar_function_set_name)(duckdb_scalar_function scalar_function, const char *name); + void (*duckdb_scalar_function_add_parameter)(duckdb_scalar_function scalar_function, duckdb_logical_type type); + void (*duckdb_scalar_function_set_return_type)(duckdb_scalar_function scalar_function, duckdb_logical_type type); + void (*duckdb_scalar_function_set_extra_info)(duckdb_scalar_function scalar_function, void *extra_info, + duckdb_delete_callback_t destroy); + void (*duckdb_scalar_function_set_function)(duckdb_scalar_function scalar_function, + duckdb_scalar_function_t function); + duckdb_state (*duckdb_register_scalar_function)(duckdb_connection con, duckdb_scalar_function scalar_function); + duckdb_table_function (*duckdb_create_table_function)(); + void (*duckdb_destroy_table_function)(duckdb_table_function *table_function); + void (*duckdb_table_function_set_name)(duckdb_table_function table_function, const char *name); + void (*duckdb_table_function_add_parameter)(duckdb_table_function table_function, duckdb_logical_type type); + void (*duckdb_table_function_add_named_parameter)(duckdb_table_function table_function, const char *name, + duckdb_logical_type type); + void (*duckdb_table_function_set_extra_info)(duckdb_table_function table_function, void *extra_info, + duckdb_delete_callback_t destroy); + void (*duckdb_table_function_set_bind)(duckdb_table_function table_function, duckdb_table_function_bind_t bind); + void (*duckdb_table_function_set_init)(duckdb_table_function table_function, duckdb_table_function_init_t init); + void (*duckdb_table_function_set_local_init)(duckdb_table_function table_function, + duckdb_table_function_init_t init); + void (*duckdb_table_function_set_function)(duckdb_table_function table_function, duckdb_table_function_t function); + void (*duckdb_table_function_supports_projection_pushdown)(duckdb_table_function table_function, bool pushdown); + duckdb_state (*duckdb_register_table_function)(duckdb_connection con, duckdb_table_function function); + void *(*duckdb_bind_get_extra_info)(duckdb_bind_info info); + void (*duckdb_bind_add_result_column)(duckdb_bind_info info, const char *name, duckdb_logical_type type); + idx_t (*duckdb_bind_get_parameter_count)(duckdb_bind_info info); + duckdb_value (*duckdb_bind_get_parameter)(duckdb_bind_info info, idx_t index); + duckdb_value (*duckdb_bind_get_named_parameter)(duckdb_bind_info info, const char *name); + void (*duckdb_bind_set_bind_data)(duckdb_bind_info info, void *bind_data, duckdb_delete_callback_t destroy); + void (*duckdb_bind_set_cardinality)(duckdb_bind_info info, idx_t cardinality, bool is_exact); + void (*duckdb_bind_set_error)(duckdb_bind_info info, const char *error); + void *(*duckdb_init_get_extra_info)(duckdb_init_info info); + void *(*duckdb_init_get_bind_data)(duckdb_init_info info); + void (*duckdb_init_set_init_data)(duckdb_init_info info, void *init_data, duckdb_delete_callback_t destroy); + idx_t (*duckdb_init_get_column_count)(duckdb_init_info info); + idx_t (*duckdb_init_get_column_index)(duckdb_init_info info, idx_t column_index); + void (*duckdb_init_set_max_threads)(duckdb_init_info info, idx_t max_threads); + void (*duckdb_init_set_error)(duckdb_init_info info, const char *error); + void *(*duckdb_function_get_extra_info)(duckdb_function_info info); + void *(*duckdb_function_get_bind_data)(duckdb_function_info info); + void *(*duckdb_function_get_init_data)(duckdb_function_info info); + void *(*duckdb_function_get_local_init_data)(duckdb_function_info info); + void (*duckdb_function_set_error)(duckdb_function_info info, const char *error); + void (*duckdb_add_replacement_scan)(duckdb_database db, duckdb_replacement_callback_t replacement, void *extra_data, + duckdb_delete_callback_t delete_callback); + void (*duckdb_replacement_scan_set_function_name)(duckdb_replacement_scan_info info, const char *function_name); + void (*duckdb_replacement_scan_add_parameter)(duckdb_replacement_scan_info info, duckdb_value parameter); + void (*duckdb_replacement_scan_set_error)(duckdb_replacement_scan_info info, const char *error); + duckdb_state (*duckdb_appender_create)(duckdb_connection connection, const char *schema, const char *table, + duckdb_appender *out_appender); + idx_t (*duckdb_appender_column_count)(duckdb_appender appender); + duckdb_logical_type (*duckdb_appender_column_type)(duckdb_appender appender, idx_t col_idx); + const char *(*duckdb_appender_error)(duckdb_appender appender); + duckdb_state (*duckdb_appender_flush)(duckdb_appender appender); + duckdb_state (*duckdb_appender_close)(duckdb_appender appender); + duckdb_state (*duckdb_appender_destroy)(duckdb_appender *appender); + duckdb_state (*duckdb_appender_begin_row)(duckdb_appender appender); + duckdb_state (*duckdb_appender_end_row)(duckdb_appender appender); + duckdb_state (*duckdb_append_default)(duckdb_appender appender); + duckdb_state (*duckdb_append_bool)(duckdb_appender appender, bool value); + duckdb_state (*duckdb_append_int8)(duckdb_appender appender, int8_t value); + duckdb_state (*duckdb_append_int16)(duckdb_appender appender, int16_t value); + duckdb_state (*duckdb_append_int32)(duckdb_appender appender, int32_t value); + duckdb_state (*duckdb_append_int64)(duckdb_appender appender, int64_t value); + duckdb_state (*duckdb_append_hugeint)(duckdb_appender appender, duckdb_hugeint value); + duckdb_state (*duckdb_append_uint8)(duckdb_appender appender, uint8_t value); + duckdb_state (*duckdb_append_uint16)(duckdb_appender appender, uint16_t value); + duckdb_state (*duckdb_append_uint32)(duckdb_appender appender, uint32_t value); + duckdb_state (*duckdb_append_uint64)(duckdb_appender appender, uint64_t value); + duckdb_state (*duckdb_append_uhugeint)(duckdb_appender appender, duckdb_uhugeint value); + duckdb_state (*duckdb_append_float)(duckdb_appender appender, float value); + duckdb_state (*duckdb_append_double)(duckdb_appender appender, double value); + duckdb_state (*duckdb_append_date)(duckdb_appender appender, duckdb_date value); + duckdb_state (*duckdb_append_time)(duckdb_appender appender, duckdb_time value); + duckdb_state (*duckdb_append_timestamp)(duckdb_appender appender, duckdb_timestamp value); + duckdb_state (*duckdb_append_interval)(duckdb_appender appender, duckdb_interval value); + duckdb_state (*duckdb_append_varchar)(duckdb_appender appender, const char *val); + duckdb_state (*duckdb_append_varchar_length)(duckdb_appender appender, const char *val, idx_t length); + duckdb_state (*duckdb_append_blob)(duckdb_appender appender, const void *data, idx_t length); + duckdb_state (*duckdb_append_null)(duckdb_appender appender); + duckdb_state (*duckdb_append_data_chunk)(duckdb_appender appender, duckdb_data_chunk chunk); + void (*duckdb_execute_tasks)(duckdb_database database, idx_t max_tasks); + duckdb_task_state (*duckdb_create_task_state)(duckdb_database database); + void (*duckdb_execute_tasks_state)(duckdb_task_state state); + idx_t (*duckdb_execute_n_tasks_state)(duckdb_task_state state, idx_t max_tasks); + void (*duckdb_finish_execution)(duckdb_task_state state); + bool (*duckdb_task_state_is_finished)(duckdb_task_state state); + void (*duckdb_destroy_task_state)(duckdb_task_state state); + bool (*duckdb_execution_is_finished)(duckdb_connection con); + duckdb_profiling_info (*duckdb_get_profiling_info)(duckdb_connection connection); + duckdb_value (*duckdb_profiling_info_get_value)(duckdb_profiling_info info, const char *key); + idx_t (*duckdb_profiling_info_get_child_count)(duckdb_profiling_info info); + duckdb_profiling_info (*duckdb_profiling_info_get_child)(duckdb_profiling_info info, idx_t index); + duckdb_value (*duckdb_profiling_info_get_metrics)(duckdb_profiling_info info); + void (*duckdb_scalar_function_set_varargs)(duckdb_scalar_function scalar_function, duckdb_logical_type type); + void (*duckdb_scalar_function_set_special_handling)(duckdb_scalar_function scalar_function); + void (*duckdb_scalar_function_set_volatile)(duckdb_scalar_function scalar_function); + void *(*duckdb_scalar_function_get_extra_info)(duckdb_function_info info); + void (*duckdb_scalar_function_set_error)(duckdb_function_info info, const char *error); + duckdb_state (*duckdb_table_description_create)(duckdb_connection connection, const char *schema, const char *table, + duckdb_table_description *out); + void (*duckdb_table_description_destroy)(duckdb_table_description *table_description); + const char *(*duckdb_table_description_error)(duckdb_table_description table_description); + duckdb_error_type (*duckdb_result_error_type)(duckdb_result *result); + uint32_t (*duckdb_string_t_length)(duckdb_string_t string); + const char *(*duckdb_string_t_data)(duckdb_string_t *string); + duckdb_value (*duckdb_create_bool)(bool input); + duckdb_value (*duckdb_create_int8)(int8_t input); + duckdb_value (*duckdb_create_uint8)(uint8_t input); + duckdb_value (*duckdb_create_int16)(int16_t input); + duckdb_value (*duckdb_create_uint16)(uint16_t input); + duckdb_value (*duckdb_create_int32)(int32_t input); + duckdb_value (*duckdb_create_uint32)(uint32_t input); + duckdb_value (*duckdb_create_uint64)(uint64_t input); + duckdb_value (*duckdb_create_hugeint)(duckdb_hugeint input); + duckdb_value (*duckdb_create_uhugeint)(duckdb_uhugeint input); + duckdb_value (*duckdb_create_float)(float input); + duckdb_value (*duckdb_create_double)(double input); + duckdb_value (*duckdb_create_date)(duckdb_date input); + duckdb_value (*duckdb_create_time)(duckdb_time input); + duckdb_value (*duckdb_create_time_tz_value)(duckdb_time_tz value); + duckdb_value (*duckdb_create_timestamp)(duckdb_timestamp input); + duckdb_value (*duckdb_create_interval)(duckdb_interval input); + duckdb_value (*duckdb_create_blob)(const uint8_t *data, idx_t length); + bool (*duckdb_get_bool)(duckdb_value val); + int8_t (*duckdb_get_int8)(duckdb_value val); + uint8_t (*duckdb_get_uint8)(duckdb_value val); + int16_t (*duckdb_get_int16)(duckdb_value val); + uint16_t (*duckdb_get_uint16)(duckdb_value val); + int32_t (*duckdb_get_int32)(duckdb_value val); + uint32_t (*duckdb_get_uint32)(duckdb_value val); + uint64_t (*duckdb_get_uint64)(duckdb_value val); + duckdb_hugeint (*duckdb_get_hugeint)(duckdb_value val); + duckdb_uhugeint (*duckdb_get_uhugeint)(duckdb_value val); + float (*duckdb_get_float)(duckdb_value val); + double (*duckdb_get_double)(duckdb_value val); + duckdb_date (*duckdb_get_date)(duckdb_value val); + duckdb_time (*duckdb_get_time)(duckdb_value val); + duckdb_time_tz (*duckdb_get_time_tz)(duckdb_value val); + duckdb_timestamp (*duckdb_get_timestamp)(duckdb_value val); + duckdb_interval (*duckdb_get_interval)(duckdb_value val); + duckdb_logical_type (*duckdb_get_value_type)(duckdb_value val); + duckdb_blob (*duckdb_get_blob)(duckdb_value val); + duckdb_scalar_function_set (*duckdb_create_scalar_function_set)(const char *name); + void (*duckdb_destroy_scalar_function_set)(duckdb_scalar_function_set *scalar_function_set); + duckdb_state (*duckdb_add_scalar_function_to_set)(duckdb_scalar_function_set set, duckdb_scalar_function function); + duckdb_state (*duckdb_register_scalar_function_set)(duckdb_connection con, duckdb_scalar_function_set set); + duckdb_aggregate_function_set (*duckdb_create_aggregate_function_set)(const char *name); + void (*duckdb_destroy_aggregate_function_set)(duckdb_aggregate_function_set *aggregate_function_set); + duckdb_state (*duckdb_add_aggregate_function_to_set)(duckdb_aggregate_function_set set, + duckdb_aggregate_function function); + duckdb_state (*duckdb_register_aggregate_function_set)(duckdb_connection con, duckdb_aggregate_function_set set); + idx_t (*duckdb_get_map_size)(duckdb_value value); + duckdb_value (*duckdb_get_map_key)(duckdb_value value, idx_t index); + duckdb_value (*duckdb_get_map_value)(duckdb_value value, idx_t index); + duckdb_aggregate_function (*duckdb_create_aggregate_function)(); + void (*duckdb_destroy_aggregate_function)(duckdb_aggregate_function *aggregate_function); + void (*duckdb_aggregate_function_set_name)(duckdb_aggregate_function aggregate_function, const char *name); + void (*duckdb_aggregate_function_add_parameter)(duckdb_aggregate_function aggregate_function, + duckdb_logical_type type); + void (*duckdb_aggregate_function_set_return_type)(duckdb_aggregate_function aggregate_function, + duckdb_logical_type type); + void (*duckdb_aggregate_function_set_functions)(duckdb_aggregate_function aggregate_function, + duckdb_aggregate_state_size state_size, + duckdb_aggregate_init_t state_init, + duckdb_aggregate_update_t update, + duckdb_aggregate_combine_t combine, + duckdb_aggregate_finalize_t finalize); + void (*duckdb_aggregate_function_set_destructor)(duckdb_aggregate_function aggregate_function, + duckdb_aggregate_destroy_t destroy); + duckdb_state (*duckdb_register_aggregate_function)(duckdb_connection con, + duckdb_aggregate_function aggregate_function); + void (*duckdb_aggregate_function_set_special_handling)(duckdb_aggregate_function aggregate_function); + void (*duckdb_aggregate_function_set_extra_info)(duckdb_aggregate_function aggregate_function, void *extra_info, + duckdb_delete_callback_t destroy); + void *(*duckdb_aggregate_function_get_extra_info)(duckdb_function_info info); + void (*duckdb_aggregate_function_set_error)(duckdb_function_info info, const char *error); + void (*duckdb_logical_type_set_alias)(duckdb_logical_type type, const char *alias); + duckdb_state (*duckdb_register_logical_type)(duckdb_connection con, duckdb_logical_type type, + duckdb_create_type_info info); + duckdb_cast_function (*duckdb_create_cast_function)(); + void (*duckdb_cast_function_set_source_type)(duckdb_cast_function cast_function, duckdb_logical_type source_type); + void (*duckdb_cast_function_set_target_type)(duckdb_cast_function cast_function, duckdb_logical_type target_type); + void (*duckdb_cast_function_set_implicit_cast_cost)(duckdb_cast_function cast_function, int64_t cost); + void (*duckdb_cast_function_set_function)(duckdb_cast_function cast_function, duckdb_cast_function_t function); + void (*duckdb_cast_function_set_extra_info)(duckdb_cast_function cast_function, void *extra_info, + duckdb_delete_callback_t destroy); + void *(*duckdb_cast_function_get_extra_info)(duckdb_function_info info); + duckdb_cast_mode (*duckdb_cast_function_get_cast_mode)(duckdb_function_info info); + void (*duckdb_cast_function_set_error)(duckdb_function_info info, const char *error); + void (*duckdb_cast_function_set_row_error)(duckdb_function_info info, const char *error, idx_t row, + duckdb_vector output); + duckdb_state (*duckdb_register_cast_function)(duckdb_connection con, duckdb_cast_function cast_function); + void (*duckdb_destroy_cast_function)(duckdb_cast_function *cast_function); + idx_t (*duckdb_row_count)(duckdb_result *result); + void *(*duckdb_column_data)(duckdb_result *result, idx_t col); + bool *(*duckdb_nullmask_data)(duckdb_result *result, idx_t col); + duckdb_data_chunk (*duckdb_result_get_chunk)(duckdb_result result, idx_t chunk_index); + bool (*duckdb_result_is_streaming)(duckdb_result result); + idx_t (*duckdb_result_chunk_count)(duckdb_result result); + duckdb_result_type (*duckdb_result_return_type)(duckdb_result result); + bool (*duckdb_value_boolean)(duckdb_result *result, idx_t col, idx_t row); + int8_t (*duckdb_value_int8)(duckdb_result *result, idx_t col, idx_t row); + int16_t (*duckdb_value_int16)(duckdb_result *result, idx_t col, idx_t row); + int32_t (*duckdb_value_int32)(duckdb_result *result, idx_t col, idx_t row); + int64_t (*duckdb_value_int64)(duckdb_result *result, idx_t col, idx_t row); + duckdb_hugeint (*duckdb_value_hugeint)(duckdb_result *result, idx_t col, idx_t row); + duckdb_uhugeint (*duckdb_value_uhugeint)(duckdb_result *result, idx_t col, idx_t row); + duckdb_decimal (*duckdb_value_decimal)(duckdb_result *result, idx_t col, idx_t row); + uint8_t (*duckdb_value_uint8)(duckdb_result *result, idx_t col, idx_t row); + uint16_t (*duckdb_value_uint16)(duckdb_result *result, idx_t col, idx_t row); + uint32_t (*duckdb_value_uint32)(duckdb_result *result, idx_t col, idx_t row); + uint64_t (*duckdb_value_uint64)(duckdb_result *result, idx_t col, idx_t row); + float (*duckdb_value_float)(duckdb_result *result, idx_t col, idx_t row); + double (*duckdb_value_double)(duckdb_result *result, idx_t col, idx_t row); + duckdb_date (*duckdb_value_date)(duckdb_result *result, idx_t col, idx_t row); + duckdb_time (*duckdb_value_time)(duckdb_result *result, idx_t col, idx_t row); + duckdb_timestamp (*duckdb_value_timestamp)(duckdb_result *result, idx_t col, idx_t row); + duckdb_interval (*duckdb_value_interval)(duckdb_result *result, idx_t col, idx_t row); + char *(*duckdb_value_varchar)(duckdb_result *result, idx_t col, idx_t row); + duckdb_string (*duckdb_value_string)(duckdb_result *result, idx_t col, idx_t row); + char *(*duckdb_value_varchar_internal)(duckdb_result *result, idx_t col, idx_t row); + duckdb_string (*duckdb_value_string_internal)(duckdb_result *result, idx_t col, idx_t row); + duckdb_blob (*duckdb_value_blob)(duckdb_result *result, idx_t col, idx_t row); + bool (*duckdb_value_is_null)(duckdb_result *result, idx_t col, idx_t row); + duckdb_state (*duckdb_execute_prepared_streaming)(duckdb_prepared_statement prepared_statement, + duckdb_result *out_result); + duckdb_state (*duckdb_pending_prepared_streaming)(duckdb_prepared_statement prepared_statement, + duckdb_pending_result *out_result); + duckdb_state (*duckdb_column_has_default)(duckdb_table_description table_description, idx_t index, bool *out); + duckdb_state (*duckdb_query_arrow)(duckdb_connection connection, const char *query, duckdb_arrow *out_result); + duckdb_state (*duckdb_query_arrow_schema)(duckdb_arrow result, duckdb_arrow_schema *out_schema); + duckdb_state (*duckdb_prepared_arrow_schema)(duckdb_prepared_statement prepared, duckdb_arrow_schema *out_schema); + void (*duckdb_result_arrow_array)(duckdb_result result, duckdb_data_chunk chunk, duckdb_arrow_array *out_array); + duckdb_state (*duckdb_query_arrow_array)(duckdb_arrow result, duckdb_arrow_array *out_array); + idx_t (*duckdb_arrow_column_count)(duckdb_arrow result); + idx_t (*duckdb_arrow_row_count)(duckdb_arrow result); + idx_t (*duckdb_arrow_rows_changed)(duckdb_arrow result); + const char *(*duckdb_query_arrow_error)(duckdb_arrow result); + void (*duckdb_destroy_arrow)(duckdb_arrow *result); + void (*duckdb_destroy_arrow_stream)(duckdb_arrow_stream *stream_p); + duckdb_state (*duckdb_execute_prepared_arrow)(duckdb_prepared_statement prepared_statement, + duckdb_arrow *out_result); + duckdb_state (*duckdb_arrow_scan)(duckdb_connection connection, const char *table_name, duckdb_arrow_stream arrow); + duckdb_state (*duckdb_arrow_array_scan)(duckdb_connection connection, const char *table_name, + duckdb_arrow_schema arrow_schema, duckdb_arrow_array arrow_array, + duckdb_arrow_stream *out_stream); + duckdb_data_chunk (*duckdb_stream_fetch_chunk)(duckdb_result result); +} duckdb_ext_api_v0; + +//===--------------------------------------------------------------------===// +// Struct Create Method +//===--------------------------------------------------------------------===// +inline duckdb_ext_api_v0 CreateAPIv0() { + duckdb_ext_api_v0 result; + result.duckdb_open = duckdb_open; + result.duckdb_open_ext = duckdb_open_ext; + result.duckdb_close = duckdb_close; + result.duckdb_connect = duckdb_connect; + result.duckdb_interrupt = duckdb_interrupt; + result.duckdb_query_progress = duckdb_query_progress; + result.duckdb_disconnect = duckdb_disconnect; + result.duckdb_library_version = duckdb_library_version; + result.duckdb_create_config = duckdb_create_config; + result.duckdb_config_count = duckdb_config_count; + result.duckdb_get_config_flag = duckdb_get_config_flag; + result.duckdb_set_config = duckdb_set_config; + result.duckdb_destroy_config = duckdb_destroy_config; + result.duckdb_query = duckdb_query; + result.duckdb_destroy_result = duckdb_destroy_result; + result.duckdb_column_name = duckdb_column_name; + result.duckdb_column_type = duckdb_column_type; + result.duckdb_result_statement_type = duckdb_result_statement_type; + result.duckdb_column_logical_type = duckdb_column_logical_type; + result.duckdb_column_count = duckdb_column_count; + result.duckdb_rows_changed = duckdb_rows_changed; + result.duckdb_result_error = duckdb_result_error; + result.duckdb_malloc = duckdb_malloc; + result.duckdb_free = duckdb_free; + result.duckdb_vector_size = duckdb_vector_size; + result.duckdb_string_is_inlined = duckdb_string_is_inlined; + result.duckdb_from_date = duckdb_from_date; + result.duckdb_to_date = duckdb_to_date; + result.duckdb_is_finite_date = duckdb_is_finite_date; + result.duckdb_from_time = duckdb_from_time; + result.duckdb_create_time_tz = duckdb_create_time_tz; + result.duckdb_from_time_tz = duckdb_from_time_tz; + result.duckdb_to_time = duckdb_to_time; + result.duckdb_from_timestamp = duckdb_from_timestamp; + result.duckdb_to_timestamp = duckdb_to_timestamp; + result.duckdb_is_finite_timestamp = duckdb_is_finite_timestamp; + result.duckdb_hugeint_to_double = duckdb_hugeint_to_double; + result.duckdb_double_to_hugeint = duckdb_double_to_hugeint; + result.duckdb_uhugeint_to_double = duckdb_uhugeint_to_double; + result.duckdb_double_to_uhugeint = duckdb_double_to_uhugeint; + result.duckdb_double_to_decimal = duckdb_double_to_decimal; + result.duckdb_decimal_to_double = duckdb_decimal_to_double; + result.duckdb_prepare = duckdb_prepare; + result.duckdb_destroy_prepare = duckdb_destroy_prepare; + result.duckdb_prepare_error = duckdb_prepare_error; + result.duckdb_nparams = duckdb_nparams; + result.duckdb_parameter_name = duckdb_parameter_name; + result.duckdb_param_type = duckdb_param_type; + result.duckdb_clear_bindings = duckdb_clear_bindings; + result.duckdb_prepared_statement_type = duckdb_prepared_statement_type; + result.duckdb_bind_value = duckdb_bind_value; + result.duckdb_bind_parameter_index = duckdb_bind_parameter_index; + result.duckdb_bind_boolean = duckdb_bind_boolean; + result.duckdb_bind_int8 = duckdb_bind_int8; + result.duckdb_bind_int16 = duckdb_bind_int16; + result.duckdb_bind_int32 = duckdb_bind_int32; + result.duckdb_bind_int64 = duckdb_bind_int64; + result.duckdb_bind_hugeint = duckdb_bind_hugeint; + result.duckdb_bind_uhugeint = duckdb_bind_uhugeint; + result.duckdb_bind_decimal = duckdb_bind_decimal; + result.duckdb_bind_uint8 = duckdb_bind_uint8; + result.duckdb_bind_uint16 = duckdb_bind_uint16; + result.duckdb_bind_uint32 = duckdb_bind_uint32; + result.duckdb_bind_uint64 = duckdb_bind_uint64; + result.duckdb_bind_float = duckdb_bind_float; + result.duckdb_bind_double = duckdb_bind_double; + result.duckdb_bind_date = duckdb_bind_date; + result.duckdb_bind_time = duckdb_bind_time; + result.duckdb_bind_timestamp = duckdb_bind_timestamp; + result.duckdb_bind_timestamp_tz = duckdb_bind_timestamp_tz; + result.duckdb_bind_interval = duckdb_bind_interval; + result.duckdb_bind_varchar = duckdb_bind_varchar; + result.duckdb_bind_varchar_length = duckdb_bind_varchar_length; + result.duckdb_bind_blob = duckdb_bind_blob; + result.duckdb_bind_null = duckdb_bind_null; + result.duckdb_execute_prepared = duckdb_execute_prepared; + result.duckdb_extract_statements = duckdb_extract_statements; + result.duckdb_prepare_extracted_statement = duckdb_prepare_extracted_statement; + result.duckdb_extract_statements_error = duckdb_extract_statements_error; + result.duckdb_destroy_extracted = duckdb_destroy_extracted; + result.duckdb_pending_prepared = duckdb_pending_prepared; + result.duckdb_destroy_pending = duckdb_destroy_pending; + result.duckdb_pending_error = duckdb_pending_error; + result.duckdb_pending_execute_task = duckdb_pending_execute_task; + result.duckdb_pending_execute_check_state = duckdb_pending_execute_check_state; + result.duckdb_execute_pending = duckdb_execute_pending; + result.duckdb_pending_execution_is_finished = duckdb_pending_execution_is_finished; + result.duckdb_destroy_value = duckdb_destroy_value; + result.duckdb_create_varchar = duckdb_create_varchar; + result.duckdb_create_varchar_length = duckdb_create_varchar_length; + result.duckdb_create_int64 = duckdb_create_int64; + result.duckdb_create_struct_value = duckdb_create_struct_value; + result.duckdb_create_list_value = duckdb_create_list_value; + result.duckdb_create_array_value = duckdb_create_array_value; + result.duckdb_get_varchar = duckdb_get_varchar; + result.duckdb_get_int64 = duckdb_get_int64; + result.duckdb_create_logical_type = duckdb_create_logical_type; + result.duckdb_logical_type_get_alias = duckdb_logical_type_get_alias; + result.duckdb_create_list_type = duckdb_create_list_type; + result.duckdb_create_array_type = duckdb_create_array_type; + result.duckdb_create_map_type = duckdb_create_map_type; + result.duckdb_create_union_type = duckdb_create_union_type; + result.duckdb_create_struct_type = duckdb_create_struct_type; + result.duckdb_create_enum_type = duckdb_create_enum_type; + result.duckdb_create_decimal_type = duckdb_create_decimal_type; + result.duckdb_get_type_id = duckdb_get_type_id; + result.duckdb_decimal_width = duckdb_decimal_width; + result.duckdb_decimal_scale = duckdb_decimal_scale; + result.duckdb_decimal_internal_type = duckdb_decimal_internal_type; + result.duckdb_enum_internal_type = duckdb_enum_internal_type; + result.duckdb_enum_dictionary_size = duckdb_enum_dictionary_size; + result.duckdb_enum_dictionary_value = duckdb_enum_dictionary_value; + result.duckdb_list_type_child_type = duckdb_list_type_child_type; + result.duckdb_array_type_child_type = duckdb_array_type_child_type; + result.duckdb_array_type_array_size = duckdb_array_type_array_size; + result.duckdb_map_type_key_type = duckdb_map_type_key_type; + result.duckdb_map_type_value_type = duckdb_map_type_value_type; + result.duckdb_struct_type_child_count = duckdb_struct_type_child_count; + result.duckdb_struct_type_child_name = duckdb_struct_type_child_name; + result.duckdb_struct_type_child_type = duckdb_struct_type_child_type; + result.duckdb_union_type_member_count = duckdb_union_type_member_count; + result.duckdb_union_type_member_name = duckdb_union_type_member_name; + result.duckdb_union_type_member_type = duckdb_union_type_member_type; + result.duckdb_destroy_logical_type = duckdb_destroy_logical_type; + result.duckdb_fetch_chunk = duckdb_fetch_chunk; + result.duckdb_create_data_chunk = duckdb_create_data_chunk; + result.duckdb_destroy_data_chunk = duckdb_destroy_data_chunk; + result.duckdb_data_chunk_reset = duckdb_data_chunk_reset; + result.duckdb_data_chunk_get_column_count = duckdb_data_chunk_get_column_count; + result.duckdb_data_chunk_get_vector = duckdb_data_chunk_get_vector; + result.duckdb_data_chunk_get_size = duckdb_data_chunk_get_size; + result.duckdb_data_chunk_set_size = duckdb_data_chunk_set_size; + result.duckdb_vector_get_column_type = duckdb_vector_get_column_type; + result.duckdb_vector_get_data = duckdb_vector_get_data; + result.duckdb_vector_get_validity = duckdb_vector_get_validity; + result.duckdb_vector_ensure_validity_writable = duckdb_vector_ensure_validity_writable; + result.duckdb_vector_assign_string_element = duckdb_vector_assign_string_element; + result.duckdb_vector_assign_string_element_len = duckdb_vector_assign_string_element_len; + result.duckdb_list_vector_get_child = duckdb_list_vector_get_child; + result.duckdb_list_vector_get_size = duckdb_list_vector_get_size; + result.duckdb_list_vector_set_size = duckdb_list_vector_set_size; + result.duckdb_list_vector_reserve = duckdb_list_vector_reserve; + result.duckdb_struct_vector_get_child = duckdb_struct_vector_get_child; + result.duckdb_array_vector_get_child = duckdb_array_vector_get_child; + result.duckdb_validity_row_is_valid = duckdb_validity_row_is_valid; + result.duckdb_validity_set_row_validity = duckdb_validity_set_row_validity; + result.duckdb_validity_set_row_invalid = duckdb_validity_set_row_invalid; + result.duckdb_validity_set_row_valid = duckdb_validity_set_row_valid; + result.duckdb_create_scalar_function = duckdb_create_scalar_function; + result.duckdb_destroy_scalar_function = duckdb_destroy_scalar_function; + result.duckdb_scalar_function_set_name = duckdb_scalar_function_set_name; + result.duckdb_scalar_function_add_parameter = duckdb_scalar_function_add_parameter; + result.duckdb_scalar_function_set_return_type = duckdb_scalar_function_set_return_type; + result.duckdb_scalar_function_set_extra_info = duckdb_scalar_function_set_extra_info; + result.duckdb_scalar_function_set_function = duckdb_scalar_function_set_function; + result.duckdb_register_scalar_function = duckdb_register_scalar_function; + result.duckdb_create_table_function = duckdb_create_table_function; + result.duckdb_destroy_table_function = duckdb_destroy_table_function; + result.duckdb_table_function_set_name = duckdb_table_function_set_name; + result.duckdb_table_function_add_parameter = duckdb_table_function_add_parameter; + result.duckdb_table_function_add_named_parameter = duckdb_table_function_add_named_parameter; + result.duckdb_table_function_set_extra_info = duckdb_table_function_set_extra_info; + result.duckdb_table_function_set_bind = duckdb_table_function_set_bind; + result.duckdb_table_function_set_init = duckdb_table_function_set_init; + result.duckdb_table_function_set_local_init = duckdb_table_function_set_local_init; + result.duckdb_table_function_set_function = duckdb_table_function_set_function; + result.duckdb_table_function_supports_projection_pushdown = duckdb_table_function_supports_projection_pushdown; + result.duckdb_register_table_function = duckdb_register_table_function; + result.duckdb_bind_get_extra_info = duckdb_bind_get_extra_info; + result.duckdb_bind_add_result_column = duckdb_bind_add_result_column; + result.duckdb_bind_get_parameter_count = duckdb_bind_get_parameter_count; + result.duckdb_bind_get_parameter = duckdb_bind_get_parameter; + result.duckdb_bind_get_named_parameter = duckdb_bind_get_named_parameter; + result.duckdb_bind_set_bind_data = duckdb_bind_set_bind_data; + result.duckdb_bind_set_cardinality = duckdb_bind_set_cardinality; + result.duckdb_bind_set_error = duckdb_bind_set_error; + result.duckdb_init_get_extra_info = duckdb_init_get_extra_info; + result.duckdb_init_get_bind_data = duckdb_init_get_bind_data; + result.duckdb_init_set_init_data = duckdb_init_set_init_data; + result.duckdb_init_get_column_count = duckdb_init_get_column_count; + result.duckdb_init_get_column_index = duckdb_init_get_column_index; + result.duckdb_init_set_max_threads = duckdb_init_set_max_threads; + result.duckdb_init_set_error = duckdb_init_set_error; + result.duckdb_function_get_extra_info = duckdb_function_get_extra_info; + result.duckdb_function_get_bind_data = duckdb_function_get_bind_data; + result.duckdb_function_get_init_data = duckdb_function_get_init_data; + result.duckdb_function_get_local_init_data = duckdb_function_get_local_init_data; + result.duckdb_function_set_error = duckdb_function_set_error; + result.duckdb_add_replacement_scan = duckdb_add_replacement_scan; + result.duckdb_replacement_scan_set_function_name = duckdb_replacement_scan_set_function_name; + result.duckdb_replacement_scan_add_parameter = duckdb_replacement_scan_add_parameter; + result.duckdb_replacement_scan_set_error = duckdb_replacement_scan_set_error; + result.duckdb_appender_create = duckdb_appender_create; + result.duckdb_appender_column_count = duckdb_appender_column_count; + result.duckdb_appender_column_type = duckdb_appender_column_type; + result.duckdb_appender_error = duckdb_appender_error; + result.duckdb_appender_flush = duckdb_appender_flush; + result.duckdb_appender_close = duckdb_appender_close; + result.duckdb_appender_destroy = duckdb_appender_destroy; + result.duckdb_appender_begin_row = duckdb_appender_begin_row; + result.duckdb_appender_end_row = duckdb_appender_end_row; + result.duckdb_append_default = duckdb_append_default; + result.duckdb_append_bool = duckdb_append_bool; + result.duckdb_append_int8 = duckdb_append_int8; + result.duckdb_append_int16 = duckdb_append_int16; + result.duckdb_append_int32 = duckdb_append_int32; + result.duckdb_append_int64 = duckdb_append_int64; + result.duckdb_append_hugeint = duckdb_append_hugeint; + result.duckdb_append_uint8 = duckdb_append_uint8; + result.duckdb_append_uint16 = duckdb_append_uint16; + result.duckdb_append_uint32 = duckdb_append_uint32; + result.duckdb_append_uint64 = duckdb_append_uint64; + result.duckdb_append_uhugeint = duckdb_append_uhugeint; + result.duckdb_append_float = duckdb_append_float; + result.duckdb_append_double = duckdb_append_double; + result.duckdb_append_date = duckdb_append_date; + result.duckdb_append_time = duckdb_append_time; + result.duckdb_append_timestamp = duckdb_append_timestamp; + result.duckdb_append_interval = duckdb_append_interval; + result.duckdb_append_varchar = duckdb_append_varchar; + result.duckdb_append_varchar_length = duckdb_append_varchar_length; + result.duckdb_append_blob = duckdb_append_blob; + result.duckdb_append_null = duckdb_append_null; + result.duckdb_append_data_chunk = duckdb_append_data_chunk; + result.duckdb_execute_tasks = duckdb_execute_tasks; + result.duckdb_create_task_state = duckdb_create_task_state; + result.duckdb_execute_tasks_state = duckdb_execute_tasks_state; + result.duckdb_execute_n_tasks_state = duckdb_execute_n_tasks_state; + result.duckdb_finish_execution = duckdb_finish_execution; + result.duckdb_task_state_is_finished = duckdb_task_state_is_finished; + result.duckdb_destroy_task_state = duckdb_destroy_task_state; + result.duckdb_execution_is_finished = duckdb_execution_is_finished; + result.duckdb_get_profiling_info = duckdb_get_profiling_info; + result.duckdb_profiling_info_get_value = duckdb_profiling_info_get_value; + result.duckdb_profiling_info_get_child_count = duckdb_profiling_info_get_child_count; + result.duckdb_profiling_info_get_child = duckdb_profiling_info_get_child; + result.duckdb_profiling_info_get_metrics = duckdb_profiling_info_get_metrics; + result.duckdb_scalar_function_set_varargs = duckdb_scalar_function_set_varargs; + result.duckdb_scalar_function_set_special_handling = duckdb_scalar_function_set_special_handling; + result.duckdb_scalar_function_set_volatile = duckdb_scalar_function_set_volatile; + result.duckdb_scalar_function_get_extra_info = duckdb_scalar_function_get_extra_info; + result.duckdb_scalar_function_set_error = duckdb_scalar_function_set_error; + result.duckdb_table_description_create = duckdb_table_description_create; + result.duckdb_table_description_destroy = duckdb_table_description_destroy; + result.duckdb_table_description_error = duckdb_table_description_error; + result.duckdb_result_error_type = duckdb_result_error_type; + result.duckdb_string_t_length = duckdb_string_t_length; + result.duckdb_string_t_data = duckdb_string_t_data; + result.duckdb_create_bool = duckdb_create_bool; + result.duckdb_create_int8 = duckdb_create_int8; + result.duckdb_create_uint8 = duckdb_create_uint8; + result.duckdb_create_int16 = duckdb_create_int16; + result.duckdb_create_uint16 = duckdb_create_uint16; + result.duckdb_create_int32 = duckdb_create_int32; + result.duckdb_create_uint32 = duckdb_create_uint32; + result.duckdb_create_uint64 = duckdb_create_uint64; + result.duckdb_create_hugeint = duckdb_create_hugeint; + result.duckdb_create_uhugeint = duckdb_create_uhugeint; + result.duckdb_create_float = duckdb_create_float; + result.duckdb_create_double = duckdb_create_double; + result.duckdb_create_date = duckdb_create_date; + result.duckdb_create_time = duckdb_create_time; + result.duckdb_create_time_tz_value = duckdb_create_time_tz_value; + result.duckdb_create_timestamp = duckdb_create_timestamp; + result.duckdb_create_interval = duckdb_create_interval; + result.duckdb_create_blob = duckdb_create_blob; + result.duckdb_get_bool = duckdb_get_bool; + result.duckdb_get_int8 = duckdb_get_int8; + result.duckdb_get_uint8 = duckdb_get_uint8; + result.duckdb_get_int16 = duckdb_get_int16; + result.duckdb_get_uint16 = duckdb_get_uint16; + result.duckdb_get_int32 = duckdb_get_int32; + result.duckdb_get_uint32 = duckdb_get_uint32; + result.duckdb_get_uint64 = duckdb_get_uint64; + result.duckdb_get_hugeint = duckdb_get_hugeint; + result.duckdb_get_uhugeint = duckdb_get_uhugeint; + result.duckdb_get_float = duckdb_get_float; + result.duckdb_get_double = duckdb_get_double; + result.duckdb_get_date = duckdb_get_date; + result.duckdb_get_time = duckdb_get_time; + result.duckdb_get_time_tz = duckdb_get_time_tz; + result.duckdb_get_timestamp = duckdb_get_timestamp; + result.duckdb_get_interval = duckdb_get_interval; + result.duckdb_get_value_type = duckdb_get_value_type; + result.duckdb_get_blob = duckdb_get_blob; + result.duckdb_create_scalar_function_set = duckdb_create_scalar_function_set; + result.duckdb_destroy_scalar_function_set = duckdb_destroy_scalar_function_set; + result.duckdb_add_scalar_function_to_set = duckdb_add_scalar_function_to_set; + result.duckdb_register_scalar_function_set = duckdb_register_scalar_function_set; + result.duckdb_create_aggregate_function_set = duckdb_create_aggregate_function_set; + result.duckdb_destroy_aggregate_function_set = duckdb_destroy_aggregate_function_set; + result.duckdb_add_aggregate_function_to_set = duckdb_add_aggregate_function_to_set; + result.duckdb_register_aggregate_function_set = duckdb_register_aggregate_function_set; + result.duckdb_get_map_size = duckdb_get_map_size; + result.duckdb_get_map_key = duckdb_get_map_key; + result.duckdb_get_map_value = duckdb_get_map_value; + result.duckdb_create_aggregate_function = duckdb_create_aggregate_function; + result.duckdb_destroy_aggregate_function = duckdb_destroy_aggregate_function; + result.duckdb_aggregate_function_set_name = duckdb_aggregate_function_set_name; + result.duckdb_aggregate_function_add_parameter = duckdb_aggregate_function_add_parameter; + result.duckdb_aggregate_function_set_return_type = duckdb_aggregate_function_set_return_type; + result.duckdb_aggregate_function_set_functions = duckdb_aggregate_function_set_functions; + result.duckdb_aggregate_function_set_destructor = duckdb_aggregate_function_set_destructor; + result.duckdb_register_aggregate_function = duckdb_register_aggregate_function; + result.duckdb_aggregate_function_set_special_handling = duckdb_aggregate_function_set_special_handling; + result.duckdb_aggregate_function_set_extra_info = duckdb_aggregate_function_set_extra_info; + result.duckdb_aggregate_function_get_extra_info = duckdb_aggregate_function_get_extra_info; + result.duckdb_aggregate_function_set_error = duckdb_aggregate_function_set_error; + result.duckdb_logical_type_set_alias = duckdb_logical_type_set_alias; + result.duckdb_register_logical_type = duckdb_register_logical_type; + result.duckdb_create_cast_function = duckdb_create_cast_function; + result.duckdb_cast_function_set_source_type = duckdb_cast_function_set_source_type; + result.duckdb_cast_function_set_target_type = duckdb_cast_function_set_target_type; + result.duckdb_cast_function_set_implicit_cast_cost = duckdb_cast_function_set_implicit_cast_cost; + result.duckdb_cast_function_set_function = duckdb_cast_function_set_function; + result.duckdb_cast_function_set_extra_info = duckdb_cast_function_set_extra_info; + result.duckdb_cast_function_get_extra_info = duckdb_cast_function_get_extra_info; + result.duckdb_cast_function_get_cast_mode = duckdb_cast_function_get_cast_mode; + result.duckdb_cast_function_set_error = duckdb_cast_function_set_error; + result.duckdb_cast_function_set_row_error = duckdb_cast_function_set_row_error; + result.duckdb_register_cast_function = duckdb_register_cast_function; + result.duckdb_destroy_cast_function = duckdb_destroy_cast_function; + result.duckdb_row_count = duckdb_row_count; + result.duckdb_column_data = duckdb_column_data; + result.duckdb_nullmask_data = duckdb_nullmask_data; + result.duckdb_result_get_chunk = duckdb_result_get_chunk; + result.duckdb_result_is_streaming = duckdb_result_is_streaming; + result.duckdb_result_chunk_count = duckdb_result_chunk_count; + result.duckdb_result_return_type = duckdb_result_return_type; + result.duckdb_value_boolean = duckdb_value_boolean; + result.duckdb_value_int8 = duckdb_value_int8; + result.duckdb_value_int16 = duckdb_value_int16; + result.duckdb_value_int32 = duckdb_value_int32; + result.duckdb_value_int64 = duckdb_value_int64; + result.duckdb_value_hugeint = duckdb_value_hugeint; + result.duckdb_value_uhugeint = duckdb_value_uhugeint; + result.duckdb_value_decimal = duckdb_value_decimal; + result.duckdb_value_uint8 = duckdb_value_uint8; + result.duckdb_value_uint16 = duckdb_value_uint16; + result.duckdb_value_uint32 = duckdb_value_uint32; + result.duckdb_value_uint64 = duckdb_value_uint64; + result.duckdb_value_float = duckdb_value_float; + result.duckdb_value_double = duckdb_value_double; + result.duckdb_value_date = duckdb_value_date; + result.duckdb_value_time = duckdb_value_time; + result.duckdb_value_timestamp = duckdb_value_timestamp; + result.duckdb_value_interval = duckdb_value_interval; + result.duckdb_value_varchar = duckdb_value_varchar; + result.duckdb_value_string = duckdb_value_string; + result.duckdb_value_varchar_internal = duckdb_value_varchar_internal; + result.duckdb_value_string_internal = duckdb_value_string_internal; + result.duckdb_value_blob = duckdb_value_blob; + result.duckdb_value_is_null = duckdb_value_is_null; + result.duckdb_execute_prepared_streaming = duckdb_execute_prepared_streaming; + result.duckdb_pending_prepared_streaming = duckdb_pending_prepared_streaming; + result.duckdb_column_has_default = duckdb_column_has_default; + result.duckdb_query_arrow = duckdb_query_arrow; + result.duckdb_query_arrow_schema = duckdb_query_arrow_schema; + result.duckdb_prepared_arrow_schema = duckdb_prepared_arrow_schema; + result.duckdb_result_arrow_array = duckdb_result_arrow_array; + result.duckdb_query_arrow_array = duckdb_query_arrow_array; + result.duckdb_arrow_column_count = duckdb_arrow_column_count; + result.duckdb_arrow_row_count = duckdb_arrow_row_count; + result.duckdb_arrow_rows_changed = duckdb_arrow_rows_changed; + result.duckdb_query_arrow_error = duckdb_query_arrow_error; + result.duckdb_destroy_arrow = duckdb_destroy_arrow; + result.duckdb_destroy_arrow_stream = duckdb_destroy_arrow_stream; + result.duckdb_execute_prepared_arrow = duckdb_execute_prepared_arrow; + result.duckdb_arrow_scan = duckdb_arrow_scan; + result.duckdb_arrow_array_scan = duckdb_arrow_array_scan; + result.duckdb_stream_fetch_chunk = duckdb_stream_fetch_chunk; + return result; +} + +#define DUCKDB_EXTENSION_API_VERSION_MAJOR 0 +#define DUCKDB_EXTENSION_API_VERSION_MINOR 0 +#define DUCKDB_EXTENSION_API_VERSION_PATCH 1 +#define DUCKDB_EXTENSION_API_VERSION_STRING "v0.0.1" + //===----------------------------------------------------------------------===// // DuckDB // @@ -32914,6 +33746,8 @@ class DatabaseInstance : public enable_shared_from_this { DUCKDB_API ValidChecker &GetValidChecker(); DUCKDB_API void SetExtensionLoaded(const string &extension_name, ExtensionInstallInfo &install_info); + DUCKDB_API const duckdb_ext_api_v0 GetExtensionAPIV0(); + idx_t NumberOfThreads(); DUCKDB_API static DatabaseInstance &GetDatabase(ClientContext &context); @@ -32947,6 +33781,8 @@ class DatabaseInstance : public enable_shared_from_this { ValidChecker db_validity; unique_ptr db_file_system; shared_ptr db_cache_entry; + + duckdb_ext_api_v0 (*create_api_v0)(); }; //! The database object. This object holds the catalog and all the diff --git a/mix.exs b/mix.exs index d3db66f..9925e36 100644 --- a/mix.exs +++ b/mix.exs @@ -1,8 +1,8 @@ defmodule Duckdbex.MixProject do use Mix.Project - @version "0.3.5" - @duckdb_version "1.1.1" + @version "0.3.6" + @duckdb_version "1.1.2" def project do [