Skip to content

Commit a0f9f88

Browse files
committed
code cleanup
1 parent ed253b0 commit a0f9f88

14 files changed

+109
-309
lines changed

src/snowflake/connector/cpp/ArrowIterator/BinaryConverter.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77

88
#include "IColumnConverter.hpp"
99
#include "logging.hpp"
10-
#include <memory>
1110
#include "nanoarrow.h"
11+
#include <memory>
1212

1313
namespace sf
1414
{

src/snowflake/connector/cpp/ArrowIterator/BooleanConverter.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
#define PC_BOOLEANCONVERTER_HPP
77

88
#include "IColumnConverter.hpp"
9-
#include <memory>
109
#include "nanoarrow.h"
10+
#include <memory>
1111

1212
namespace sf
1313
{

src/snowflake/connector/cpp/ArrowIterator/CArrowChunkIterator.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -226,13 +226,13 @@ void CArrowChunkIterator::initColumnConverters()
226226
if (m_useNumpy)\
227227
{\
228228
m_currentBatchConverters.push_back(std::make_shared<\
229-
sf::NumpyDecimalConverter<ArrowArrayView>>(\
229+
sf::NumpyDecimalConverter>(\
230230
array, precision, scale, m_context));\
231231
}\
232232
else\
233233
{\
234234
m_currentBatchConverters.push_back(std::make_shared<\
235-
sf::DecimalFromIntConverter<ArrowArrayView>>(\
235+
sf::DecimalFromIntConverter>(\
236236
array, precision, scale));\
237237
}\
238238
}\
@@ -241,13 +241,13 @@ void CArrowChunkIterator::initColumnConverters()
241241
if (m_useNumpy)\
242242
{\
243243
m_currentBatchConverters.push_back(\
244-
std::make_shared<sf::NumpyIntConverter<ArrowArrayView>>(\
244+
std::make_shared<sf::NumpyIntConverter>(\
245245
array, m_context));\
246246
}\
247247
else\
248248
{\
249249
m_currentBatchConverters.push_back(\
250-
std::make_shared<sf::IntConverter<ArrowArrayView>>(\
250+
std::make_shared<sf::IntConverter>(\
251251
array));\
252252
}\
253253
}\
@@ -353,7 +353,7 @@ void CArrowChunkIterator::initColumnConverters()
353353
case NANOARROW_TYPE_INT64:
354354
{
355355
m_currentBatchConverters.push_back(
356-
std::make_shared<sf::TimeConverter<ArrowArrayView>>(
356+
std::make_shared<sf::TimeConverter>(
357357
array, scale));
358358
break;
359359
}

src/snowflake/connector/cpp/ArrowIterator/CArrowChunkIterator.hpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88
#include "CArrowIterator.hpp"
99
#include "IColumnConverter.hpp"
1010
#include "Python/Common.hpp"
11-
#include <memory>
12-
#include <vector>
1311
#include "nanoarrow.h"
1412
#include "nanoarrow.hpp"
13+
#include <memory>
14+
#include <vector>
1515

1616
namespace sf
1717
{
@@ -50,8 +50,6 @@ class CArrowChunkIterator : public CArrowIterator
5050

5151
/** list of column converters*/
5252
std::vector<std::shared_ptr<sf::IColumnConverter>> m_currentBatchConverters;
53-
//std::vector<std::shared_ptr<ArrowArray>> m_arrays;
54-
std::vector<std::shared_ptr<ArrowArrayView>> m_arrayViews;
5553
/** row index inside current record batch (start from 0) */
5654
int m_rowIndexInBatch;
5755

src/snowflake/connector/cpp/ArrowIterator/DecimalConverter.cpp

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,43 @@ py::UniqueRef& DecimalBaseConverter::initPyDecimalConstructor()
3030
return pyDecimalConstructor;
3131
}
3232

33+
DecimalFromIntConverter::DecimalFromIntConverter(ArrowArrayView* array,
34+
int precision, int scale)
35+
: m_array(array),
36+
m_precision(precision),
37+
m_scale(scale)
38+
{
39+
}
40+
41+
PyObject* DecimalFromIntConverter::toPyObject(int64_t rowIndex) const
42+
{
43+
if(ArrowArrayViewIsNull(m_array, rowIndex)) {
44+
Py_RETURN_NONE;
45+
}
46+
int64_t val = ArrowArrayViewGetIntUnsafe(m_array, rowIndex);
47+
py::UniqueRef decimal(
48+
PyObject_CallFunction(m_pyDecimalConstructor.get(), "L", val));
49+
return PyObject_CallMethod(decimal.get(), "scaleb", "i", -m_scale);
50+
}
51+
52+
NumpyDecimalConverter::NumpyDecimalConverter(ArrowArrayView* array,
53+
int precision, int scale, PyObject * context)
54+
: m_array(array),
55+
m_precision(precision),
56+
m_scale(scale),
57+
m_context(context)
58+
{
59+
}
60+
61+
PyObject* NumpyDecimalConverter::toPyObject(int64_t rowIndex) const
62+
{
63+
if(ArrowArrayViewIsNull(m_array, rowIndex)) {
64+
Py_RETURN_NONE;
65+
}
66+
int64_t val = ArrowArrayViewGetIntUnsafe(m_array, rowIndex);
67+
return PyObject_CallMethod(m_context, "FIXED_to_numpy_float64", "Li", val, m_scale);
68+
}
69+
3370
DecimalFromDecimalConverter::DecimalFromDecimalConverter(
3471
PyObject* context,
3572
ArrowArrayView* array, int scale)

src/snowflake/connector/cpp/ArrowIterator/DecimalConverter.hpp

Lines changed: 3 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@ class DecimalBaseConverter : public IColumnConverter
2929
class DecimalFromDecimalConverter : public DecimalBaseConverter
3030
{
3131
public:
32-
explicit DecimalFromDecimalConverter(PyObject* context, ArrowArrayView* array,
33-
int scale);
32+
explicit DecimalFromDecimalConverter(PyObject* context, ArrowArrayView* array, int scale);
3433

3534
PyObject* toPyObject(int64_t rowIndex) const override;
3635

@@ -41,17 +40,10 @@ class DecimalFromDecimalConverter : public DecimalBaseConverter
4140
/** no need for this converter to store precision*/
4241
};
4342

44-
template <typename T>
4543
class DecimalFromIntConverter : public DecimalBaseConverter
4644
{
4745
public:
48-
explicit DecimalFromIntConverter(ArrowArrayView* array,
49-
int precision, int scale)
50-
: m_array(array),
51-
m_precision(precision),
52-
m_scale(scale)
53-
{
54-
}
46+
explicit DecimalFromIntConverter(ArrowArrayView* array, int precision, int scale);
5547

5648
PyObject* toPyObject(int64_t rowIndex) const override;
5749

@@ -63,31 +55,11 @@ class DecimalFromIntConverter : public DecimalBaseConverter
6355
int m_scale;
6456
};
6557

66-
template <typename T>
67-
PyObject* DecimalFromIntConverter<T>::toPyObject(int64_t rowIndex) const
68-
{
69-
if(ArrowArrayViewIsNull(m_array, rowIndex)) {
70-
Py_RETURN_NONE;
71-
}
72-
int64_t val = ArrowArrayViewGetIntUnsafe(m_array, rowIndex);
73-
py::UniqueRef decimal(
74-
PyObject_CallFunction(m_pyDecimalConstructor.get(), "L", val));
75-
return PyObject_CallMethod(decimal.get(), "scaleb", "i", -m_scale);
76-
}
77-
7858

79-
template <typename T>
8059
class NumpyDecimalConverter : public IColumnConverter
8160
{
8261
public:
83-
explicit NumpyDecimalConverter(ArrowArrayView* array,
84-
int precision, int scale, PyObject * context)
85-
: m_array(array),
86-
m_precision(precision),
87-
m_scale(scale),
88-
m_context(context)
89-
{
90-
}
62+
explicit NumpyDecimalConverter(ArrowArrayView* array, int precision, int scale, PyObject * context);
9163

9264
PyObject* toPyObject(int64_t rowIndex) const override;
9365

@@ -101,17 +73,6 @@ class NumpyDecimalConverter : public IColumnConverter
10173
PyObject * m_context;
10274
};
10375

104-
template <typename T>
105-
PyObject* NumpyDecimalConverter<T>::toPyObject(int64_t rowIndex) const
106-
{
107-
if(ArrowArrayViewIsNull(m_array, rowIndex)) {
108-
Py_RETURN_NONE;
109-
}
110-
int64_t val = ArrowArrayViewGetIntUnsafe(m_array, rowIndex);
111-
return PyObject_CallMethod(m_context, "FIXED_to_numpy_float64", "Li", val, m_scale);
112-
}
113-
114-
11576
} // namespace sf
11677

11778
#endif // PC_DECIMALCONVERTER_HPP

src/snowflake/connector/cpp/ArrowIterator/FloatConverter.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
#define PC_FLOATCONVERTER_HPP
77

88
#include "IColumnConverter.hpp"
9-
#include <memory>
109
#include "nanoarrow.h"
10+
#include <memory>
1111

1212
namespace sf
1313
{

src/snowflake/connector/cpp/ArrowIterator/IntConverter.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,23 @@ namespace sf
88
{
99
/** this file is here for future use and if this is useless at the end, it will
1010
* be removed */
11+
12+
PyObject* IntConverter::toPyObject(int64_t rowIndex) const
13+
{
14+
if(ArrowArrayViewIsNull(m_array, rowIndex)) {
15+
Py_RETURN_NONE;
16+
}
17+
int64_t val = ArrowArrayViewGetIntUnsafe(m_array, rowIndex);
18+
return pyLongForward(val);
19+
}
20+
21+
PyObject* NumpyIntConverter::toPyObject(int64_t rowIndex) const
22+
{
23+
if(ArrowArrayViewIsNull(m_array, rowIndex)) {
24+
Py_RETURN_NONE;
25+
}
26+
int64_t val = ArrowArrayViewGetIntUnsafe(m_array, rowIndex);
27+
return PyObject_CallMethod(m_context, "FIXED_to_numpy_int64", "L", val);
28+
}
29+
1130
} // namespace sf

src/snowflake/connector/cpp/ArrowIterator/IntConverter.hpp

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
namespace sf
1414
{
1515

16-
template <typename T>
1716
class IntConverter : public IColumnConverter
1817
{
1918
public:
@@ -38,17 +37,6 @@ class IntConverter : public IColumnConverter
3837
ArrowArrayView* m_array;
3938
};
4039

41-
template <typename T>
42-
PyObject* IntConverter<T>::toPyObject(int64_t rowIndex) const
43-
{
44-
if(ArrowArrayViewIsNull(m_array, rowIndex)) {
45-
Py_RETURN_NONE;
46-
}
47-
int64_t val = ArrowArrayViewGetIntUnsafe(m_array, rowIndex);
48-
return pyLongForward(val);
49-
}
50-
51-
template <typename T>
5240
class NumpyIntConverter : public IColumnConverter
5341
{
5442
public:
@@ -66,16 +54,6 @@ class NumpyIntConverter : public IColumnConverter
6654
PyObject * m_context;
6755
};
6856

69-
template <typename T>
70-
PyObject* NumpyIntConverter<T>::toPyObject(int64_t rowIndex) const
71-
{
72-
if(ArrowArrayViewIsNull(m_array, rowIndex)) {
73-
Py_RETURN_NONE;
74-
}
75-
int64_t val = ArrowArrayViewGetIntUnsafe(m_array, rowIndex);
76-
return PyObject_CallMethod(m_context, "FIXED_to_numpy_int64", "L", val);
77-
}
78-
7957
} // namespace sf
8058

8159
#endif // PC_INTCONVERTER_HPP

src/snowflake/connector/cpp/ArrowIterator/StringConverter.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77

88
#include "IColumnConverter.hpp"
99
#include "logging.hpp"
10-
#include <memory>
1110
#include "nanoarrow.h"
1211
#include "nanoarrow.hpp"
12+
#include <memory>
1313

1414
namespace sf
1515
{

0 commit comments

Comments
 (0)