Skip to content

Commit 849119d

Browse files
committed
more fixes
1 parent 5b9dbbf commit 849119d

10 files changed

Lines changed: 45 additions & 20 deletions

File tree

external/duckdb

Submodule duckdb updated 3086 files

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ cmake.build-type = "Debug"
122122
[[tool.scikit-build.overrides]]
123123
if.state = "editable"
124124
if.env.COVERAGE = false
125-
if.platform-system = "Darwin"
125+
if.platform-system = "(?i)darwin"
126126
inherit.cmake.define = "append"
127127
cmake.define.DISABLE_UNITY = "1"
128128

src/duckdb_py/arrow/pyarrow_filter_pushdown.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ struct PyArrowBackend : public FilterBackend {
189189

190190
py::object MakeColumnRef(const vector<Identifier> &path) override {
191191
vector<string> str_path;
192-
std::transform(path.begin(), path.end(), str_path.begin(),
192+
std::transform(path.begin(), path.end(), std::back_inserter(str_path),
193193
[](const Identifier &segment) { return segment.GetIdentifierName(); });
194194
return field_factory(py::tuple(py::cast(str_path)));
195195
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#pragma once
2+
#include "duckdb_python/pybind11/pybind_wrapper.hpp"
3+
#include "duckdb/common/identifier.hpp"
4+
5+
namespace py = pybind11;
6+
7+
namespace PYBIND11_NAMESPACE {
8+
namespace detail {
9+
template <>
10+
class type_caster<duckdb::Identifier> {
11+
PYBIND11_TYPE_CASTER(duckdb::Identifier, const_name("str"));
12+
13+
// Python str -> Identifier
14+
bool load(handle src, bool) {
15+
if (!PyUnicode_Check(src.ptr())) {
16+
return false;
17+
}
18+
value = duckdb::Identifier(src.cast<std::string>());
19+
return true;
20+
}
21+
22+
// Identifier -> Python str
23+
static handle cast(const duckdb::Identifier &id, return_value_policy, handle) {
24+
auto &str_value = id.GetIdentifierName();
25+
return PyUnicode_FromStringAndSize(str_value.data(), py::ssize_t(str_value.size()));
26+
}
27+
};
28+
} // namespace detail
29+
} // namespace PYBIND11_NAMESPACE

src/duckdb_py/include/duckdb_python/pybind11/pybind_wrapper.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <pybind11/pybind11.h>
1212
#include <pybind11/numpy.h>
1313
#include <pybind11/stl.h>
14+
#include "duckdb_python/pybind11/conversions/identifier.hpp"
1415
#include "duckdb/common/vector.hpp"
1516
#include "duckdb/common/assert.hpp"
1617
#include "duckdb/common/helper.hpp"

src/duckdb_py/include/duckdb_python/pyrelation.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ struct DuckDBPyRelation {
289289
bool executed;
290290
shared_ptr<Relation> rel;
291291
vector<LogicalType> types;
292-
vector<Identifier> names;
292+
vector<string> names;
293293
shared_ptr<DuckDBPyResult> result;
294294
std::string rendered_result;
295295
};

src/duckdb_py/include/duckdb_python/pyresult.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ struct DuckDBPyResult {
4848
duckdb::pyarrow::RecordBatchReader FetchRecordBatchReader(idx_t rows_per_batch = 1000000);
4949
py::object FetchArrowCapsule(idx_t rows_per_batch = 1000000);
5050

51-
static py::list GetDescription(const vector<Identifier> &names, const vector<LogicalType> &types);
51+
static py::list GetDescription(const vector<string> &names, const vector<LogicalType> &types);
5252

5353
void Close();
5454

src/duckdb_py/pyrelation.cpp

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ DuckDBPyRelation::DuckDBPyRelation(shared_ptr<Relation> rel_p) : rel(std::move(r
2929
this->executed = false;
3030
auto &columns = rel->Columns();
3131
for (auto &col : columns) {
32-
names.push_back(col.GetName());
32+
names.push_back(col.Name().GetIdentifierName());
3333
types.push_back(col.GetType());
3434
}
3535
}
@@ -69,9 +69,7 @@ DuckDBPyRelation::DuckDBPyRelation(shared_ptr<DuckDBPyResult> result_p) : rel(nu
6969
}
7070
this->executed = true;
7171
this->types = result->GetTypes();
72-
auto names_str = result->GetNames();
73-
std::transform(names_str.begin(), names_str.end(), this->names.begin(),
74-
[](const std::string &name) { return Identifier(name); });
72+
this->names = result->GetNames();
7573
}
7674

7775
unique_ptr<DuckDBPyRelation> DuckDBPyRelation::ProjectFromExpression(const string &expression) {
@@ -1026,9 +1024,6 @@ PolarsDataFrame DuckDBPyRelation::ToPolars(idx_t batch_size, bool lazy) {
10261024
ArrowSchema arrow_schema;
10271025
auto result_names = names;
10281026
QueryResult::DeduplicateColumns(result_names);
1029-
vector<std::string> string_names(result_names.size());
1030-
std::transform(result_names.begin(), result_names.end(), string_names.begin(),
1031-
[](const Identifier &name) { return name.GetIdentifierName(); });
10321027
ClientProperties client_properties;
10331028
if (rel) {
10341029
client_properties = rel->context->GetContext()->GetClientProperties();
@@ -1037,10 +1032,10 @@ PolarsDataFrame DuckDBPyRelation::ToPolars(idx_t batch_size, bool lazy) {
10371032
} else {
10381033
throw InternalException("DuckDBPyRelation To Polars must have a valid relation or result");
10391034
}
1040-
ArrowConverter::ToArrowSchema(&arrow_schema, types, string_names, client_properties);
1035+
ArrowConverter::ToArrowSchema(&arrow_schema, types, result_names, client_properties);
10411036
py::list batches;
10421037
// Now we create an empty arrow table
1043-
auto empty_table = pyarrow::ToArrowTable(types, string_names, batches, client_properties);
1038+
auto empty_table = pyarrow::ToArrowTable(types, result_names, batches, client_properties);
10441039

10451040
// And we extract the polars schema from the arrow table
10461041
auto polars_df = py::cast<PolarsDataFrame>(pybind11::module_::import("polars").attr("DataFrame")(empty_table));
@@ -1077,8 +1072,8 @@ void DuckDBPyRelation::Close() {
10771072
}
10781073

10791074
bool DuckDBPyRelation::ContainsColumnByName(const string &name) const {
1080-
return std::find_if(names.begin(), names.end(), [&](const Identifier &item) { return name == item; }) !=
1081-
names.end();
1075+
return std::find_if(names.begin(), names.end(),
1076+
[&](const string &item) { return StringUtil::CIEquals(name, item); }) != names.end();
10821077
}
10831078

10841079
void DuckDBPyRelation::SetConnectionOwner(py::object owner) {
@@ -1122,7 +1117,7 @@ unique_ptr<DuckDBPyRelation> DuckDBPyRelation::GetAttribute(const string &name)
11221117
// e.g 'rel['my_struct']['my_field']:
11231118
// first 'my_struct' is selected by the bottom condition
11241119
// then 'my_field' is accessed on the result of this
1125-
column_names.push_back(names[0]);
1120+
column_names.push_back(Identifier(names[0]));
11261121
column_names.push_back(Identifier(name));
11271122
} else if (ContainsColumnByName(name)) {
11281123
column_names.push_back(Identifier(name));

src/duckdb_py/pyresult.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -793,11 +793,11 @@ py::object DuckDBPyResult::FetchArrowCapsule(idx_t rows_per_batch) {
793793
return py::capsule(stream, "arrow_array_stream", ArrowArrayStreamPyCapsuleDestructor);
794794
}
795795

796-
py::list DuckDBPyResult::GetDescription(const vector<Identifier> &names, const vector<LogicalType> &types) {
796+
py::list DuckDBPyResult::GetDescription(const vector<string> &names, const vector<LogicalType> &types) {
797797
py::list desc;
798798

799799
for (idx_t col_idx = 0; col_idx < names.size(); col_idx++) {
800-
auto py_name = py::str(names[col_idx].GetIdentifierName());
800+
auto py_name = py::str(names[col_idx]);
801801
auto py_type = DuckDBPyType(types[col_idx]);
802802
desc.append(py::make_tuple(py_name, py_type, py::none(), py::none(), py::none(), py::none(), py::none()));
803803
}

src/duckdb_py/pystatement.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ py::set DuckDBPyStatement::NamedParameters() const {
3737
py::set result;
3838
auto &named_parameters = statement->named_param_map;
3939
for (auto &param : named_parameters) {
40-
result.add(param.first);
40+
result.add(param.first.GetIdentifierName());
4141
}
4242
return result;
4343
}

0 commit comments

Comments
 (0)