Skip to content

Commit bdc43c8

Browse files
committed
release 3.0.2.1
1 parent 1ee15cf commit bdc43c8

File tree

85 files changed

+23132
-11887
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

85 files changed

+23132
-11887
lines changed

core/include/ConstantImp.h

Lines changed: 378 additions & 286 deletions
Large diffs are not rendered by default.

core/include/DdbPythonUtil.h

Lines changed: 1 addition & 196 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,8 @@
33
#include "DolphinDB.h"
44
#include "Concurrent.h"
55
#include "MultithreadedTableWriter.h"
6+
67
#include "pybind11/numpy.h"
7-
#include "pybind11/embed.h"
8-
#include "pybind11/stl.h"
9-
#include "Wrappers.h"
108

119
#ifdef _MSC_VER
1210
#ifdef _USRDLL
@@ -20,202 +18,9 @@
2018

2119
namespace dolphindb {
2220

23-
24-
25-
#define EXPARAM_DEFAULT INT_MIN
26-
27-
28-
struct HIDEVISIBILITY Preserved {
29-
// instantiation only once for frequently use
30-
bool np_above_1_20_;
31-
bool pd_above_2_0_;
32-
bool pd_above_1_2_;
33-
bool pyarrow_import_;
34-
bool has_arrow_;
35-
// modules and methods
36-
py::object numpy_; // module
37-
//static py::object isnan_; // func
38-
//static py::object sum_; // func
39-
py::object datetime64_; // type, equal to np.datetime64
40-
py::object nan_;
41-
py::object pandas_; // module
42-
py::object pyarrow_; // pyarrow
43-
44-
// pandas types (use py::isinstance)
45-
py::object pdseries_;
46-
py::object pddataframe_;
47-
py::object pdNaT_;
48-
py::object pdNA_;//np.nan=pd.NA
49-
py::object pdtimestamp_;
50-
py::object pdindex_;
51-
py::object pdextensiondtype_;
52-
53-
// pandas extension dtypes (use equal)
54-
py::object pdBooleanDtype_;
55-
py::object pdFloat32Dtype_;
56-
py::object pdFloat64Dtype_;
57-
py::object pdInt8Dtype_;
58-
py::object pdInt16Dtype_;
59-
py::object pdInt32Dtype_;
60-
py::object pdInt64Dtype_;
61-
py::object pdStringDtype_;
62-
63-
// numpy dtypes (instances of dtypes, use equal)
64-
py::object nparray_;
65-
py::object npmatrix_;
66-
py::object npbool_;
67-
py::object npint8_;
68-
py::object npint16_;
69-
py::object npint32_;
70-
py::object npint64_;
71-
py::object npfloat32_;
72-
py::object npfloat64_;
73-
//npstr has many format, like U4,U8..., they have same type
74-
py::object npstrType_;
75-
76-
py::object npdatetime64M_ins_;
77-
py::object npdatetime64D_ins_;
78-
py::object npdatetime64m_ins_;
79-
py::object npdatetime64s_ins_;
80-
py::object npdatetime64h_ins_;
81-
py::object npdatetime64ms_ins_;
82-
py::object npdatetime64us_ins_;
83-
py::object npdatetime64ns_ins_;
84-
py::object npdatetime64_ins_;
85-
86-
py::object npobject_;
87-
88-
py::object pynone_;
89-
py::object pybool_;
90-
py::object pyint_;
91-
py::object pyfloat_;
92-
py::object pystr_;
93-
py::object pybytes_;
94-
py::object pyset_;
95-
py::object pytuple_;
96-
py::object pylist_;
97-
py::object pydict_;
98-
99-
py::object m_decimal_;
100-
py::object decimal_;
101-
102-
// pyarrow types
103-
py::object pdarrowdtype_;
104-
py::object paboolean_;
105-
py::object paint8_;
106-
py::object paint16_;
107-
py::object paint32_;
108-
py::object paint64_;
109-
py::object padate32_;
110-
py::object patime32_ms_;
111-
py::object patime32_s_;
112-
py::object patime64_ns_;
113-
py::object patimestamp_ns_;
114-
py::object patimestamp_ms_;
115-
py::object patimestamp_s_;
116-
py::object pafloat32_;
117-
py::object pafloat64_;
118-
py::object padictionary_int32_utf8_;
119-
py::object paDictionaryType_;
120-
py::object pautf8_;
121-
py::object pafixed_size_binary_16_;
122-
py::object palarge_binary_;
123-
py::object padecimal128_;
124-
py::object palist_;
125-
py::object pachunkedarray_;
126-
127-
py::object npdatetime64M_(){
128-
if(np_above_1_20_) return npdatetime64M_ins_;
129-
else return name2dtype("datetime64[M]");
130-
}
131-
py::object npdatetime64D_(){
132-
if(np_above_1_20_) return npdatetime64D_ins_;
133-
else return name2dtype("datetime64[D]");
134-
}
135-
py::object npdatetime64m_(){
136-
if(np_above_1_20_) return npdatetime64m_ins_;
137-
else return name2dtype("datetime64[m]");
138-
}
139-
py::object npdatetime64s_(){
140-
if(np_above_1_20_) return npdatetime64s_ins_;
141-
else return name2dtype("datetime64[s]");
142-
}
143-
py::object npdatetime64h_(){
144-
if(np_above_1_20_) return npdatetime64h_ins_;
145-
else return name2dtype("datetime64[h]");
146-
}
147-
py::object npdatetime64ms_(){
148-
if(np_above_1_20_) return npdatetime64ms_ins_;
149-
else return name2dtype("datetime64[ms]");
150-
}
151-
py::object npdatetime64us_(){
152-
if(np_above_1_20_) return npdatetime64us_ins_;
153-
else return name2dtype("datetime64[us]");
154-
}
155-
py::object npdatetime64ns_(){
156-
if(np_above_1_20_) return npdatetime64ns_ins_;
157-
else return name2dtype("datetime64[ns]");
158-
}
159-
py::object npdatetime64_(){
160-
if(np_above_1_20_) return npdatetime64_ins_;
161-
else return name2dtype("datetime64");
162-
}
163-
164-
Preserved();
165-
166-
py::object name2dtype(const char *pname){
167-
py::object type = py::reinterpret_borrow<py::object>(numpy_.attr("dtype")(pname));
168-
// py::dtype type(pname);
169-
//py::object dtname=py::getattr(type, "name");
170-
//std::string name=py::str(dtname);
171-
//printf("DType: %s.",name.data());
172-
return type;
173-
}
174-
static py::object getType(py::object obj){
175-
//std::string text=py::str(obj.get_type());
176-
//printf("Type: %s.",text.data());
177-
return py::reinterpret_borrow<py::object>(obj.get_type());
178-
}
179-
};
180-
181-
enum CHILD_VECTOR_OPTION {
182-
DISABLE,
183-
ANY_VECTOR,
184-
ARRAY_VECTOR,
185-
};
186-
187-
struct TableVectorInfo {
188-
bool is_empty;
189-
std::string colName;
190-
};
191-
192-
class EXPORT_DECL TableChecker: public std::map<std::string, Type>{
193-
public:
194-
TableChecker() {}
195-
TableChecker(const py::object &pydict);
196-
};
197-
19821
class EXPORT_DECL DdbPythonUtil{
19922
public:
200-
struct ToPythonOption;
201-
struct ToPythonOption{
202-
bool table2List;//if object is table, false: convert to pandas, true: convert to list
203-
ToPythonOption(){
204-
table2List = false;
205-
}
206-
ToPythonOption(bool table2Lista){
207-
table2List = table2Lista;
208-
}
209-
};
210-
211-
static ConstantSP toDolphinDB(py::object obj, Type typeIndicator = {DT_UNK, EXPARAM_DEFAULT}, TableChecker checker = TableChecker());
212-
static py::object toPython(ConstantSP obj, bool tableFlag=false, ToPythonOption *poption = NULL);
213-
static ConstantSP toDolphinDB_Scalar(py::object obj, Type typeIndicator = {DT_UNK, EXPARAM_DEFAULT});
214-
static ConstantSP toDolphinDB_Vector(py::object obj, Type typeIndicator = {DT_UNK, EXPARAM_DEFAULT}, CHILD_VECTOR_OPTION option = CHILD_VECTOR_OPTION::DISABLE);
21523
static py::object loadPickleFile(const std::string &filepath);
216-
static void createPyVector(const ConstantSP &obj,py::object &pyObject,bool tableFlag,ToPythonOption *poption);
217-
static Preserved *preserved_;
218-
static void preservedinit() { if(preserved_ == nullptr) preserved_ = new Preserved(); }
21924

22025
protected:
22126
friend class PytoDdbRowPool;

core/include/DecimalHelper.h

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
#ifndef DECIMAL_HELPER_H_
2+
#define DECIMAL_HELPER_H_
3+
4+
5+
#include "ConstantImp.h"
6+
#include "TypeDefine.h"
7+
#include "Types.h"
8+
#include "Util.h"
9+
10+
11+
namespace _decimal_util {
12+
13+
using namespace dolphindb;
14+
using pybind_dolphindb::int128;
15+
using decimal_util::exp10_i128;
16+
17+
18+
inline bool isDecimalType(DATA_TYPE type) {
19+
if (type >= ARRAY_TYPE_BASE) {
20+
type = static_cast<DATA_TYPE>(type - ARRAY_TYPE_BASE);
21+
}
22+
return (Util::getCategory(type) == DENARY);
23+
}
24+
25+
inline int packDecimalTypeAndScale(DATA_TYPE type, int scale) {
26+
if (false == isDecimalType(type)) {
27+
return static_cast<int>(type);
28+
}
29+
/*
30+
* 31 16 0
31+
* +---+-----------+-------------+
32+
* | 1 | scale | data type |
33+
* +---+-----------+-------------+
34+
*/
35+
return ((scale << 16) | 0x80000000) | (type & 0xffff);
36+
}
37+
38+
inline std::pair<DATA_TYPE, int> unpackDecimalTypeAndScale(const int value) {
39+
DATA_TYPE type = static_cast<DATA_TYPE>(value);
40+
int scale = 0;
41+
if (value & 0x80000000) {
42+
/*
43+
* 31 16 0
44+
* +---+-----------+-------------+
45+
* | 1 | scale | data type |
46+
* +---+-----------+-------------+
47+
*/
48+
scale = (value & (~0x80000000)) >> 16;
49+
type = static_cast<DATA_TYPE>(value & 0xffff);
50+
if (type >= ARRAY_TYPE_BASE) {
51+
if (Util::getCategory(static_cast<DATA_TYPE>(static_cast<int>(type) - ARRAY_TYPE_BASE)) != DENARY) {
52+
type = DT_VOID;
53+
}
54+
} else {
55+
if (Util::getCategory(type) != DENARY) {
56+
type = DT_VOID;
57+
}
58+
}
59+
}
60+
return {type, scale};
61+
}
62+
63+
64+
} // namespace _decimal_util
65+
66+
67+
#endif // DECIMAL_HELPER_H_

core/include/DolphinDB.h

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,12 @@
3131
#include "Table.h"
3232
#include "pybind11/pybind11.h"
3333

34+
#include "TypeHelper.h"
35+
3436

3537
namespace py = pybind11;
3638

37-
#if defined(_MSC_VER)
38-
#include <BaseTsd.h>
39-
typedef SSIZE_T ssize_t;
40-
#endif
39+
4140

4241
#ifdef _MSC_VER
4342
#if defined(_Py_static_string_init) && defined(PY_MINOR_VERSION) && (PY_MINOR_VERSION >= 10)
@@ -68,7 +67,10 @@ typedef SmartPointer<DBConnection> DBConnectionSP;
6867
typedef SmartPointer<DBConnectionPool> DBConnectionPoolSP;
6968
typedef SmartPointer<PartitionedTableAppender> PartitionedTableAppenderSP;
7069

71-
typedef std::pair<DATA_TYPE, int> Type;
70+
using converter::PyObjs;
71+
using converter::Type;
72+
using converter::TableChecker;
73+
using converter::CHILD_VECTOR_OPTION;
7274

7375
class HIDEVISIBILITY ProtectGil{
7476
public:

core/include/DolphinDBImp.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class DBConnectionImpl {
3939
void setProtocol(PROTOCOL protocol) {
4040
protocol_ = protocol;
4141
if (protocol_ == PROTOCOL_ARROW) {
42-
if (!DdbPythonUtil::preserved_->has_arrow_) {
42+
if (!converter::PyObjs::cache_->has_arrow_) {
4343
throw RuntimeException("No module named 'pyarrow'");
4444
}
4545
}

core/include/IOBinding.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#ifndef IOBINDING_H_
2+
#define IOBINDING_H_
3+
4+
5+
#include <pybind11/pybind11.h>
6+
#include <pybind11/pytypes.h>
7+
8+
9+
namespace py = pybind11;
10+
11+
12+
namespace pybind_dolphindb {
13+
14+
void Init_Module_IO(py::module &m);
15+
16+
} // namespace pybind_dolphindb
17+
18+
19+
20+
21+
#endif // IOBINDING_H_

core/include/Matrix.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,24 @@ class EXPORT_DECL Matrix{
1111
void setRowLabel(const ConstantSP& label);
1212
void setColumnLabel(const ConstantSP& label);
1313
bool reshape(INDEX cols, INDEX rows);
14-
string getString() const;
15-
string getString(INDEX index) const ;
14+
std::string getString() const;
15+
std::string getString(INDEX index) const ;
1616
ConstantSP get(const ConstantSP& index) const ;
1717
bool set(const ConstantSP index, const ConstantSP& value);
18-
virtual string getString(int column, int row) const = 0;
18+
virtual std::string getString(int column, int row) const = 0;
1919
virtual ConstantSP getInstance(INDEX size) const = 0;
2020
virtual ConstantSP getColumn(INDEX index) const = 0;
2121
virtual bool setColumn(INDEX index, const ConstantSP& value)=0;
2222
virtual int asof(const ConstantSP& value) const {throw RuntimeException("asof not supported.");}
23+
24+
protected:
25+
void calculateInvalidLength(INDEX colStart, int colLength,INDEX rowStart, int rowLength, int& invalidLenBeginning, int& invalidLenEnding) const;
26+
2327
protected:
2428
int cols_;
2529
int rows_;
2630
ConstantSP rowLabel_;
2731
ConstantSP colLabel_;
2832
};
2933

30-
}
34+
}

core/include/MultithreadedTableWriter.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ class EXPORT_DECL MultithreadedTableWriter {
9494

9595
bool isExit(){ return hasError_; }
9696
const DATA_TYPE* getColType(){ return colTypes_.data(); }
97+
const int* getColExtra(){ return colExtras_.data(); }
9798
int getColSize(){ return colTypes_.size(); }
9899
private:
99100
bool insert(std::vector<ConstantSP> **records, int recordCount, ErrorCodeInfo &errorInfo);

0 commit comments

Comments
 (0)