1212#include " DateConverter.hpp"
1313#include " TimeStampConverter.hpp"
1414#include " TimeConverter.hpp"
15- #include " logging.hpp "
15+ #include < string >
1616
1717namespace sf
1818{
@@ -50,6 +50,10 @@ PyObject* CArrowChunkIterator::nextRow()
5050 if (m_rowIndexInBatch < m_rowCountInBatch)
5151 {
5252 this ->currentRowAsTuple ();
53+ if (py::checkPyError ())
54+ {
55+ return nullptr ;
56+ }
5357 return m_latestReturnedRow.get ();
5458 }
5559 else
@@ -60,11 +64,19 @@ PyObject* CArrowChunkIterator::nextRow()
6064 m_rowIndexInBatch = 0 ;
6165 m_rowCountInBatch = m_cRecordBatches[m_currentBatchIndex]->num_rows ();
6266 this ->initColumnConverters ();
67+ if (py::checkPyError ())
68+ {
69+ return nullptr ;
70+ }
6371
6472 logger.info (" Current batch index: %d, rows in current batch: %d" ,
6573 m_currentBatchIndex, m_rowCountInBatch);
6674
6775 this ->currentRowAsTuple ();
76+ if (py::checkPyError ())
77+ {
78+ return nullptr ;
79+ }
6880 return m_latestReturnedRow.get ();
6981 }
7082 }
@@ -189,15 +201,22 @@ void CArrowChunkIterator::initColumnConverters()
189201
190202 default :
191203 {
192- /* * TODO: how to throw an exception will be decided later */
193- logger.error (" unknown arrow internal data type(%d) for FIXED data" ,
194- dt->id ());
195- break ;
204+ std::string errorInfo = Logger::formatString (
205+ " [Snowflake Exception] unknown arrow internal data type(%d) "
206+ " for FIXED data" ,
207+ dt->id ());
208+ logger.error (errorInfo.c_str ());
209+ PyErr_SetString (PyExc_Exception, errorInfo.c_str ());
210+ return ;
196211 }
197212 }
198213 break ;
199214 }
200215
216+ case SnowflakeType::Type::ANY:
217+ case SnowflakeType::Type::CHAR:
218+ case SnowflakeType::Type::OBJECT:
219+ case SnowflakeType::Type::VARIANT:
201220 case SnowflakeType::Type::TEXT:
202221 {
203222 m_currentBatchConverters.push_back (
@@ -258,10 +277,13 @@ void CArrowChunkIterator::initColumnConverters()
258277
259278 default :
260279 {
261- /* * TODO: how to throw an exception will be decided later */
262- logger.error (" unknown arrow internal data type(%d) for TIME data" ,
263- dt->id ());
264- break ;
280+ std::string errorInfo = Logger::formatString (
281+ " [Snowflake Exception] unknown arrow internal data type(%d) "
282+ " for TIME data" ,
283+ dt->id ());
284+ logger.error (errorInfo.c_str ());
285+ PyErr_SetString (PyExc_Exception, errorInfo.c_str ());
286+ return ;
265287 }
266288 }
267289 break ;
@@ -292,11 +314,13 @@ void CArrowChunkIterator::initColumnConverters()
292314
293315 default :
294316 {
295- /* * TODO: how to throw an exception will be decided later */
296- logger. error (
297- " unknown arrow internal data type(%d) for TIMESTAMP_NTZ data" ,
317+ std::string errorInfo = Logger::formatString (
318+ " [Snowflake Exception] unknown arrow internal data type(%d) "
319+ " for TIMESTAMP_NTZ data" ,
298320 dt->id ());
299- break ;
321+ logger.error (errorInfo.c_str ());
322+ PyErr_SetString (PyExc_Exception, errorInfo.c_str ());
323+ return ;
300324 }
301325 }
302326 break ;
@@ -327,11 +351,13 @@ void CArrowChunkIterator::initColumnConverters()
327351
328352 default :
329353 {
330- /* * TODO: how to throw an exception will be decided later */
331- logger. error (
332- " unknown arrow internal data type(%d) for TIMESTAMP_LTZ data" ,
354+ std::string errorInfo = Logger::formatString (
355+ " [Snowflake Exception] unknown arrow internal data type(%d) "
356+ " for TIMESTAMP_LTZ data" ,
333357 dt->id ());
334- break ;
358+ logger.error (errorInfo.c_str ());
359+ PyErr_SetString (PyExc_Exception, errorInfo.c_str ());
360+ return ;
335361 }
336362 }
337363 break ;
@@ -366,11 +392,13 @@ void CArrowChunkIterator::initColumnConverters()
366392
367393 default :
368394 {
369- /* * TODO: how to throw an exception will be decided later */
370- logger. error (
371- " unknown arrow internal data type(%d) for TIMESTAMP_TZ data" ,
395+ std::string errorInfo = Logger::formatString (
396+ " [Snowflake Exception] unknown arrow internal data type(%d) "
397+ " for TIMESTAMP_TZ data" ,
372398 dt->id ());
373- break ;
399+ logger.error (errorInfo.c_str ());
400+ PyErr_SetString (PyExc_Exception, errorInfo.c_str ());
401+ return ;
374402 }
375403 }
376404
@@ -379,10 +407,12 @@ void CArrowChunkIterator::initColumnConverters()
379407
380408 default :
381409 {
382- /* * TODO: how to throw an exception will be decided later */
383- logger.error (" unknown snowflake data type : %d" ,
384- metaData->value (metaData->FindKey (" logicalType" )));
385- break ;
410+ std::string errorInfo = Logger::formatString (
411+ " [Snowflake Exception] unknown snowflake data type : %d" ,
412+ metaData->value (metaData->FindKey (" logicalType" )));
413+ logger.error (errorInfo.c_str ());
414+ PyErr_SetString (PyExc_Exception, errorInfo.c_str ());
415+ return ;
386416 }
387417 }
388418 }
0 commit comments