开源 企业版 高校版 私有云 模力方舟 AI 队友
代码拉取完成,页面将自动刷新
加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
已有帐号? 立即登录
文件
main
分支 (256)
标签 (40)
main
feature
braintrustdata-json-dot-syntax
master
bump-postgres-scanner
bump-sqlite
tiledb
hannesmuehleisen-patch-2
hannesmuehleisen-patch-1
optimizeextract
statistics
node-15-builds
projectsource
nodejs
tpchlicense
benchmarks
rightouterjoin
updateparameters
insertdeletefix
fixglobinternal
v0.10.0
v0.9.2
v0.9.1
v0.9.0
v0.8.1
v0.8.0
v0.7.1
v0.7.0
v0.6.1
v0.6.0
v0.5.1
v0.5.0
v0.4.0
v0.3.4
v0.3.3
v0.3.2
v0.3.1
v0.3.0
v0.2.9
v0.2.8
main
分支 (256)
标签 (40)
main
feature
braintrustdata-json-dot-syntax
master
bump-postgres-scanner
bump-sqlite
tiledb
hannesmuehleisen-patch-2
hannesmuehleisen-patch-1
optimizeextract
statistics
node-15-builds
projectsource
nodejs
tpchlicense
benchmarks
rightouterjoin
updateparameters
insertdeletefix
fixglobinternal
v0.10.0
v0.9.2
v0.9.1
v0.9.0
v0.8.1
v0.8.0
v0.7.1
v0.7.0
v0.6.1
v0.6.0
v0.5.1
v0.5.0
v0.4.0
v0.3.4
v0.3.3
v0.3.2
v0.3.1
v0.3.0
v0.2.9
v0.2.8
克隆/下载
克隆/下载
提示
下载代码请复制以下命令到终端执行
为确保你提交的代码身份被 Gitee 正确识别,请执行以下命令完成配置
初次使用 SSH 协议进行代码克隆、推送等操作时,需按下述提示完成 SSH 配置
1 生成 RSA 密钥
2 获取 RSA 公钥内容,并配置到 SSH公钥
在 Gitee 上使用 SVN,请访问 使用指南
使用 HTTPS 协议时,命令行会出现如下账号密码验证步骤。基于安全考虑,Gitee 建议 配置并使用私人令牌 替代登录密码进行克隆、推送等操作
Username for 'https://gitee.com': userName
Password for 'https://userName@gitee.com': # 私人令牌
main
分支 (256)
标签 (40)
main
feature
braintrustdata-json-dot-syntax
master
bump-postgres-scanner
bump-sqlite
tiledb
hannesmuehleisen-patch-2
hannesmuehleisen-patch-1
optimizeextract
statistics
node-15-builds
projectsource
nodejs
tpchlicense
benchmarks
rightouterjoin
updateparameters
insertdeletefix
fixglobinternal
v0.10.0
v0.9.2
v0.9.1
v0.9.0
v0.8.1
v0.8.0
v0.7.1
v0.7.0
v0.6.1
v0.6.0
v0.5.1
v0.5.0
v0.4.0
v0.3.4
v0.3.3
v0.3.2
v0.3.1
v0.3.0
v0.2.9
v0.2.8
duckdb
/
tools
/
pythonpkg
/
duckdb_python.cpp
duckdb
/
tools
/
pythonpkg
/
duckdb_python.cpp
duckdb_python.cpp 20.72 KB
一键复制 编辑 原始数据 按行查看 历史
Max Gabrielsson 提交于 2024年02月28日 03:03 +08:00 . split list and array type
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336
#include "duckdb_python/pybind11/pybind_wrapper.hpp"
#include "duckdb/common/atomic.hpp"
#include "duckdb/common/vector.hpp"
#include "duckdb/parser/parser.hpp"
#include "duckdb_python/python_objects.hpp"
#include "duckdb_python/pyconnection/pyconnection.hpp"
#include "duckdb_python/pyrelation.hpp"
#include "duckdb_python/expression/pyexpression.hpp"
#include "duckdb_python/pyresult.hpp"
#include "duckdb_python/pybind11/exceptions.hpp"
#include "duckdb_python/typing.hpp"
#include "duckdb_python/functional.hpp"
#include "duckdb_python/connection_wrapper.hpp"
#include "duckdb_python/pybind11/conversions/pyconnection_default.hpp"
#include "duckdb/common/box_renderer.hpp"
#include "duckdb/function/function.hpp"
#include "duckdb_python/pybind11/conversions/exception_handling_enum.hpp"
#include "duckdb_python/pybind11/conversions/python_udf_type_enum.hpp"
#include "duckdb.hpp"
#ifndef DUCKDB_PYTHON_LIB_NAME
#define DUCKDB_PYTHON_LIB_NAME duckdb
#endif
namespace py = pybind11;
namespace duckdb {
enum PySQLTokenType {
PY_SQL_TOKEN_IDENTIFIER = 0,
PY_SQL_TOKEN_NUMERIC_CONSTANT,
PY_SQL_TOKEN_STRING_CONSTANT,
PY_SQL_TOKEN_OPERATOR,
PY_SQL_TOKEN_KEYWORD,
PY_SQL_TOKEN_COMMENT
};
static py::list PyTokenize(const string &query) {
auto tokens = Parser::Tokenize(query);
py::list result;
for (auto &token : tokens) {
auto tuple = py::tuple(2);
tuple[0] = token.start;
switch (token.type) {
case SimplifiedTokenType::SIMPLIFIED_TOKEN_IDENTIFIER:
tuple[1] = PY_SQL_TOKEN_IDENTIFIER;
break;
case SimplifiedTokenType::SIMPLIFIED_TOKEN_NUMERIC_CONSTANT:
tuple[1] = PY_SQL_TOKEN_NUMERIC_CONSTANT;
break;
case SimplifiedTokenType::SIMPLIFIED_TOKEN_STRING_CONSTANT:
tuple[1] = PY_SQL_TOKEN_STRING_CONSTANT;
break;
case SimplifiedTokenType::SIMPLIFIED_TOKEN_OPERATOR:
tuple[1] = PY_SQL_TOKEN_OPERATOR;
break;
case SimplifiedTokenType::SIMPLIFIED_TOKEN_KEYWORD:
tuple[1] = PY_SQL_TOKEN_KEYWORD;
break;
case SimplifiedTokenType::SIMPLIFIED_TOKEN_COMMENT:
tuple[1] = PY_SQL_TOKEN_COMMENT;
break;
}
result.append(tuple);
}
return result;
}
static void InitializeConnectionMethods(py::module_ &m) {
m.def("cursor", &PyConnectionWrapper::Cursor, "Create a duplicate of the current connection",
py::arg("connection") = py::none())
.def("duplicate", &PyConnectionWrapper::Cursor, "Create a duplicate of the current connection",
py::arg("connection") = py::none());
m.def("create_function", &PyConnectionWrapper::RegisterScalarUDF,
"Create a DuckDB function out of the passing in python function so it can be used in queries",
py::arg("name"), py::arg("function"), py::arg("return_type") = py::none(), py::arg("parameters") = py::none(),
py::kw_only(), py::arg("type") = PythonUDFType::NATIVE, py::arg("null_handling") = 0,
py::arg("exception_handling") = 0, py::arg("side_effects") = false, py::arg("connection") = py::none());
m.def("remove_function", &PyConnectionWrapper::UnregisterUDF, "Remove a previously created function",
py::arg("name"), py::arg("connection") = py::none());
DefineMethod({"sqltype", "dtype", "type"}, m, &PyConnectionWrapper::Type, "Create a type object from 'type_str'",
py::arg("type_str"), py::arg("connection") = py::none());
DefineMethod({"struct_type", "row_type"}, m, &PyConnectionWrapper::StructType,
"Create a struct type object from 'fields'", py::arg("fields"), py::arg("connection") = py::none());
m.def("union_type", &PyConnectionWrapper::UnionType, "Create a union type object from 'members'",
py::arg("members").none(false), py::arg("connection") = py::none())
.def("string_type", &PyConnectionWrapper::StringType, "Create a string type with an optional collation",
py::arg("collation") = string(), py::arg("connection") = py::none())
.def("enum_type", &PyConnectionWrapper::EnumType,
"Create an enum type of underlying 'type', consisting of the list of 'values'", py::arg("name"),
py::arg("type"), py::arg("values"), py::arg("connection") = py::none())
.def("decimal_type", &PyConnectionWrapper::DecimalType, "Create a decimal type with 'width' and 'scale'",
py::arg("width"), py::arg("scale"), py::arg("connection") = py::none());
m.def("array_type", &PyConnectionWrapper::ArrayType, "Create an array type object of 'type'",
py::arg("type").none(false), py::arg("size").none(false), py::arg("connection") = py::none());
m.def("list_type", &PyConnectionWrapper::ListType, "Create a list type object of 'type'",
py::arg("type").none(false), py::arg("connection") = py::none());
m.def("map_type", &PyConnectionWrapper::MapType, "Create a map type object from 'key_type' and 'value_type'",
py::arg("key").none(false), py::arg("value").none(false), py::arg("connection") = py::none())
.def("execute", &PyConnectionWrapper::Execute,
"Execute the given SQL query, optionally using prepared statements with parameters set", py::arg("query"),
py::arg("parameters") = py::none(), py::arg("multiple_parameter_sets") = false,
py::arg("connection") = py::none())
.def("executemany", &PyConnectionWrapper::ExecuteMany,
"Execute the given prepared statement multiple times using the list of parameter sets in parameters",
py::arg("query"), py::arg("parameters") = py::none(), py::arg("connection") = py::none())
.def("close", &PyConnectionWrapper::Close, "Close the connection", py::arg("connection") = py::none())
.def("interrupt", &PyConnectionWrapper::Interrupt, "Interrupt pending operations",
py::arg("connection") = py::none())
.def("fetchone", &PyConnectionWrapper::FetchOne, "Fetch a single row from a result following execute",
py::arg("connection") = py::none())
.def("fetchmany", &PyConnectionWrapper::FetchMany, "Fetch the next set of rows from a result following execute",
py::arg("size") = 1, py::arg("connection") = py::none())
.def("fetchall", &PyConnectionWrapper::FetchAll, "Fetch all rows from a result following execute",
py::arg("connection") = py::none())
.def("fetchnumpy", &PyConnectionWrapper::FetchNumpy, "Fetch a result as list of NumPy arrays following execute",
py::arg("connection") = py::none())
.def("fetchdf", &PyConnectionWrapper::FetchDF, "Fetch a result as DataFrame following execute()", py::kw_only(),
py::arg("date_as_object") = false, py::arg("connection") = py::none())
.def("fetch_df", &PyConnectionWrapper::FetchDF, "Fetch a result as DataFrame following execute()",
py::kw_only(), py::arg("date_as_object") = false, py::arg("connection") = py::none())
.def("fetch_df_chunk", &PyConnectionWrapper::FetchDFChunk,
"Fetch a chunk of the result as DataFrame following execute()", py::arg("vectors_per_chunk") = 1,
py::kw_only(), py::arg("date_as_object") = false, py::arg("connection") = py::none())
.def("df", &PyConnectionWrapper::FetchDF, "Fetch a result as DataFrame following execute()", py::kw_only(),
py::arg("date_as_object") = false, py::arg("connection") = py::none())
.def("fetch_arrow_table", &PyConnectionWrapper::FetchArrow, "Fetch a result as Arrow table following execute()",
py::arg("rows_per_batch") = 1000000, py::arg("connection") = py::none())
.def("torch", &PyConnectionWrapper::FetchPyTorch,
"Fetch a result as dict of PyTorch Tensors following execute()", py::arg("connection") = py::none())
.def("tf", &PyConnectionWrapper::FetchTF, "Fetch a result as dict of TensorFlow Tensors following execute()",
py::arg("connection") = py::none())
.def("fetch_record_batch", &PyConnectionWrapper::FetchRecordBatchReader,
"Fetch an Arrow RecordBatchReader following execute()", py::arg("rows_per_batch") = 1000000,
py::arg("connection") = py::none())
.def("arrow", &PyConnectionWrapper::FetchArrow, "Fetch a result as Arrow table following execute()",
py::arg("rows_per_batch") = 1000000, py::arg("connection") = py::none())
.def("pl", &PyConnectionWrapper::FetchPolars, "Fetch a result as Polars DataFrame following execute()",
py::arg("rows_per_batch") = 1000000, py::arg("connection") = py::none())
.def("begin", &PyConnectionWrapper::Begin, "Start a new transaction", py::arg("connection") = py::none())
.def("commit", &PyConnectionWrapper::Commit, "Commit changes performed within a transaction",
py::arg("connection") = py::none())
.def("rollback", &PyConnectionWrapper::Rollback, "Roll back changes performed within a transaction",
py::arg("connection") = py::none())
.def("read_json", &PyConnectionWrapper::ReadJSON, "Create a relation object from the JSON file in 'name'",
py::arg("name"), py::arg("connection") = py::none(), py::arg("columns") = py::none(),
py::arg("sample_size") = py::none(), py::arg("maximum_depth") = py::none(),
py::arg("records") = py::none(), py::arg("format") = py::none());
m.def("values", &PyConnectionWrapper::Values, "Create a relation object from the passed values", py::arg("values"),
py::arg("connection") = py::none());
m.def("from_substrait", &PyConnectionWrapper::FromSubstrait, "Creates a query object from the substrait plan",
py::arg("proto"), py::arg("connection") = py::none());
m.def("get_substrait", &PyConnectionWrapper::GetSubstrait, "Serialize a query object to protobuf", py::arg("query"),
py::arg("connection") = py::none(), py::kw_only(), py::arg("enable_optimizer") = true);
m.def("get_substrait_json", &PyConnectionWrapper::GetSubstraitJSON, "Serialize a query object to protobuf",
py::arg("query"), py::arg("connection") = py::none(), py::kw_only(), py::arg("enable_optimizer") = true);
m.def("from_substrait_json", &PyConnectionWrapper::FromSubstraitJSON, "Serialize a query object to protobuf",
py::arg("json"), py::arg("connection") = py::none());
m.def("df", &PyConnectionWrapper::FromDF, "Create a relation object from the DataFrame df", py::arg("df"),
py::arg("connection") = py::none());
m.def("from_df", &PyConnectionWrapper::FromDF, "Create a relation object from the DataFrame df", py::arg("df"),
py::arg("connection") = py::none());
m.def("from_arrow", &PyConnectionWrapper::FromArrow, "Create a relation object from an Arrow object",
py::arg("arrow_object"), py::arg("connection") = py::none());
m.def("arrow", &PyConnectionWrapper::FromArrow, "Create a relation object from an Arrow object",
py::arg("arrow_object"), py::arg("connection") = py::none());
m.def("filter", &PyConnectionWrapper::FilterDf, "Filter the DataFrame df by the filter in filter_expr",
py::arg("df"), py::arg("filter_expr"), py::arg("connection") = py::none());
m.def("project", &PyConnectionWrapper::ProjectDf, "Project the DataFrame df by the projection in project_expr",
py::arg("df"), py::arg("project_expr"), py::arg("connection") = py::none());
m.def("alias", &PyConnectionWrapper::AliasDF, "Create a relation from DataFrame df with the passed alias",
py::arg("df"), py::arg("alias"), py::arg("connection") = py::none());
m.def("order", &PyConnectionWrapper::OrderDf, "Reorder the DataFrame df by order_expr", py::arg("df"),
py::arg("order_expr"), py::arg("connection") = py::none());
m.def("aggregate", &PyConnectionWrapper::AggregateDF,
"Compute the aggregate aggr_expr by the optional groups group_expr on DataFrame df", py::arg("df"),
py::arg("aggr_expr"), py::arg("group_expr") = "", py::arg("connection") = py::none());
m.def("distinct", &PyConnectionWrapper::DistinctDF, "Compute the distinct rows from DataFrame df ", py::arg("df"),
py::arg("connection") = py::none());
m.def("limit", &PyConnectionWrapper::LimitDF, "Retrieve the first n rows from the DataFrame df", py::arg("df"),
py::arg("n"), py::arg("connection") = py::none());
m.def("query_df", &PyConnectionWrapper::QueryDF,
"Run the given SQL query in sql_query on the view named virtual_table_name that contains the content of "
"DataFrame df",
py::arg("df"), py::arg("virtual_table_name"), py::arg("sql_query"), py::arg("connection") = py::none());
m.def("write_csv", &PyConnectionWrapper::WriteCsvDF, "Write the DataFrame df to a CSV file in file_name",
py::arg("df"), py::arg("file_name"), py::arg("connection") = py::none());
DefineMethod(
{"read_csv", "from_csv_auto"}, m, &PyConnectionWrapper::ReadCSV,
"Create a relation object from the CSV file in 'name'", py::arg("name"), py::arg("connection") = py::none(),
py::arg("header") = py::none(), py::arg("compression") = py::none(), py::arg("sep") = py::none(),
py::arg("delimiter") = py::none(), py::arg("dtype") = py::none(), py::arg("na_values") = py::none(),
py::arg("skiprows") = py::none(), py::arg("quotechar") = py::none(), py::arg("escapechar") = py::none(),
py::arg("encoding") = py::none(), py::arg("parallel") = py::none(), py::arg("date_format") = py::none(),
py::arg("timestamp_format") = py::none(), py::arg("sample_size") = py::none(),
py::arg("all_varchar") = py::none(), py::arg("normalize_names") = py::none(), py::arg("filename") = py::none(),
py::arg("null_padding") = py::none(), py::arg("names") = py::none());
m.def("append", &PyConnectionWrapper::Append, "Append the passed DataFrame to the named table",
py::arg("table_name"), py::arg("df"), py::kw_only(), py::arg("by_name") = false,
py::arg("connection") = py::none())
.def("register", &PyConnectionWrapper::RegisterPythonObject,
"Register the passed Python Object value for querying with a view", py::arg("view_name"),
py::arg("python_object"), py::arg("connection") = py::none())
.def("unregister", &PyConnectionWrapper::UnregisterPythonObject, "Unregister the view name",
py::arg("view_name"), py::arg("connection") = py::none())
.def("table", &PyConnectionWrapper::Table, "Create a relation object for the name'd table",
py::arg("table_name"), py::arg("connection") = py::none())
.def("view", &PyConnectionWrapper::View, "Create a relation object for the name'd view", py::arg("view_name"),
py::arg("connection") = py::none())
.def("values", &PyConnectionWrapper::Values, "Create a relation object from the passed values",
py::arg("values"), py::arg("connection") = py::none())
.def("table_function", &PyConnectionWrapper::TableFunction,
"Create a relation object from the name'd table function with given parameters", py::arg("name"),
py::arg("parameters") = py::none(), py::arg("connection") = py::none());
DefineMethod({"sql", "query", "from_query"}, m, &PyConnectionWrapper::RunQuery,
"Run a SQL query. If it is a SELECT statement, create a relation object from the given SQL query, "
"otherwise run the query as-is.",
py::arg("query"), py::arg("alias") = "", py::arg("connection") = py::none());
DefineMethod({"from_parquet", "read_parquet"}, m, &PyConnectionWrapper::FromParquet,
"Create a relation object from the Parquet files in file_glob", py::arg("file_glob"),
py::arg("binary_as_string") = false, py::kw_only(), py::arg("file_row_number") = false,
py::arg("filename") = false, py::arg("hive_partitioning") = false, py::arg("union_by_name") = false,
py::arg("compression") = py::none(), py::arg("connection") = py::none());
DefineMethod({"from_parquet", "read_parquet"}, m, &PyConnectionWrapper::FromParquets,
"Create a relation object from the Parquet files in file_globs", py::arg("file_globs"),
py::arg("binary_as_string") = false, py::kw_only(), py::arg("file_row_number") = false,
py::arg("filename") = false, py::arg("hive_partitioning") = false, py::arg("union_by_name") = false,
py::arg("compression") = py::none(), py::arg("connection") = py::none());
m.def("from_substrait", &PyConnectionWrapper::FromSubstrait, "Create a query object from protobuf plan",
py::arg("proto"), py::arg("connection") = py::none())
.def("get_substrait", &PyConnectionWrapper::GetSubstrait, "Serialize a query to protobuf", py::arg("query"),
py::arg("connection") = py::none(), py::kw_only(), py::arg("enable_optimizer") = true)
.def("get_substrait_json", &PyConnectionWrapper::GetSubstraitJSON,
"Serialize a query to protobuf on the JSON format", py::arg("query"), py::arg("connection") = py::none(),
py::kw_only(), py::arg("enable_optimizer") = true)
.def("get_table_names", &PyConnectionWrapper::GetTableNames, "Extract the required table names from a query",
py::arg("query"), py::arg("connection") = py::none())
.def("description", &PyConnectionWrapper::GetDescription, "Get result set attributes, mainly column names",
py::arg("connection") = py::none())
.def("rowcount", &PyConnectionWrapper::GetRowcount, "Get result set row count",
py::arg("connection") = py::none())
.def("install_extension", &PyConnectionWrapper::InstallExtension, "Install an extension by name",
py::arg("extension"), py::kw_only(), py::arg("force_install") = false, py::arg("connection") = py::none())
.def("load_extension", &PyConnectionWrapper::LoadExtension, "Load an installed extension", py::arg("extension"),
py::arg("connection") = py::none())
.def("register_filesystem", &PyConnectionWrapper::RegisterFilesystem, "Register a fsspec compliant filesystem",
py::arg("filesystem"), py::arg("connection") = py::none())
.def("unregister_filesystem", &PyConnectionWrapper::UnregisterFilesystem, "Unregister a filesystem",
py::arg("name"), py::arg("connection") = py::none())
.def("list_filesystems", &PyConnectionWrapper::ListFilesystems,
"List registered filesystems, including builtin ones", py::arg("connection") = py::none())
.def("filesystem_is_registered", &PyConnectionWrapper::FileSystemIsRegistered,
"Check if a filesystem with the provided name is currently registered", py::arg("name"),
py::arg("connection") = py::none());
}
PYBIND11_MODULE(DUCKDB_PYTHON_LIB_NAME, m) { // NOLINT
py::enum_<duckdb::ExplainType>(m, "ExplainType")
.value("STANDARD", duckdb::ExplainType::EXPLAIN_STANDARD)
.value("ANALYZE", duckdb::ExplainType::EXPLAIN_ANALYZE)
.export_values();
py::enum_<duckdb::PythonExceptionHandling>(m, "PythonExceptionHandling")
.value("DEFAULT", duckdb::PythonExceptionHandling::FORWARD_ERROR)
.value("RETURN_NULL", duckdb::PythonExceptionHandling::RETURN_NULL)
.export_values();
py::enum_<duckdb::RenderMode>(m, "RenderMode")
.value("ROWS", duckdb::RenderMode::ROWS)
.value("COLUMNS", duckdb::RenderMode::COLUMNS)
.export_values();
DuckDBPyTyping::Initialize(m);
DuckDBPyFunctional::Initialize(m);
DuckDBPyExpression::Initialize(m);
DuckDBPyRelation::Initialize(m);
DuckDBPyConnection::Initialize(m);
PythonObject::Initialize();
py::options pybind_opts;
m.doc() = "DuckDB is an embeddable SQL OLAP Database Management System";
m.attr("__package__") = "duckdb";
m.attr("__version__") = std::string(DuckDB::LibraryVersion()).substr(1);
m.attr("__standard_vector_size__") = DuckDB::StandardVectorSize();
m.attr("__git_revision__") = DuckDB::SourceID();
m.attr("__interactive__") = DuckDBPyConnection::DetectAndGetEnvironment();
m.attr("__jupyter__") = DuckDBPyConnection::IsJupyter();
m.attr("default_connection") = DuckDBPyConnection::DefaultConnection();
m.attr("apilevel") = "2.0";
m.attr("threadsafety") = 1;
m.attr("paramstyle") = "qmark";
InitializeConnectionMethods(m);
RegisterExceptions(m);
m.def("connect", &DuckDBPyConnection::Connect,
"Create a DuckDB database instance. Can take a database file name to read/write persistent data and a "
"read_only flag if no changes are desired",
py::arg("database") = ":memory:", py::arg("read_only") = false, py::arg_v("config", py::dict(), "None"));
m.def("tokenize", PyTokenize,
"Tokenizes a SQL string, returning a list of (position, type) tuples that can be "
"used for e.g. syntax highlighting",
py::arg("query"));
py::enum_<PySQLTokenType>(m, "token_type", py::module_local())
.value("identifier", PySQLTokenType::PY_SQL_TOKEN_IDENTIFIER)
.value("numeric_const", PySQLTokenType::PY_SQL_TOKEN_NUMERIC_CONSTANT)
.value("string_const", PySQLTokenType::PY_SQL_TOKEN_STRING_CONSTANT)
.value("operator", PySQLTokenType::PY_SQL_TOKEN_OPERATOR)
.value("keyword", PySQLTokenType::PY_SQL_TOKEN_KEYWORD)
.value("comment", PySQLTokenType::PY_SQL_TOKEN_COMMENT)
.export_values();
// we need this because otherwise we try to remove registered_dfs on shutdown when python is already dead
auto clean_default_connection = []() {
DuckDBPyConnection::Cleanup();
};
m.add_object("_clean_default_connection", py::capsule(clean_default_connection));
}
} // namespace duckdb
Loading...
举报
举报成功
我们将于2个工作日内通过站内信反馈结果给你!
请认真填写举报原因,尽可能描述详细。
请选择举报类型
取消
发送
误判申诉

此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。

如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。

取消
提交

简介

DuckDB,是一个可嵌入的 SQL OLAP 数据库管理系统
取消

发行版

暂无发行版

贡献者

全部

近期动态

不能加载更多了
编辑仓库简介
简介内容
主页
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/mobnet/duckdb.git
git@gitee.com:mobnet/duckdb.git
mobnet
duckdb
duckdb
main
点此查找更多帮助

搜索帮助

评论
仓库举报
回到顶部
登录提示
该操作需登录 Gitee 帐号,请先登录后再操作。
立即登录
没有帐号,去注册

AltStyle によって変換されたページ (->オリジナル) /