66#include " SnowflakeType.hpp"
77#include " Python/Common.hpp"
88#include " Util/time.hpp"
9- #include < iostream>
109#include < memory>
1110#include < string>
1211#include < vector>
@@ -37,22 +36,22 @@ void CArrowTableIterator::reconstructRecordBatches_nanoarrow()
3736 std::shared_ptr<arrow::Schema> schema = currentBatch->schema ();
3837
3938 // each record batch will have its own list of newly created array and schema
40- m_newArrays.push_back (std::vector<std::unique_ptr< nanoarrow::UniqueArray> >());
41- m_newSchemas.push_back (std::vector<std::unique_ptr< nanoarrow::UniqueSchema> >());
39+ m_newArrays.push_back (std::vector<nanoarrow::UniqueArray>());
40+ m_newSchemas.push_back (std::vector<nanoarrow::UniqueSchema>());
4241
4342 // These copies will be used if rebuilding the RecordBatch if necessary
44- std::unique_ptr< nanoarrow::UniqueSchema> arrowSchema = std::make_unique<nanoarrow::UniqueSchema>() ;
45- std::unique_ptr< nanoarrow::UniqueArray> arrowArray = std::make_unique<nanoarrow::UniqueArray>() ;
46- std::unique_ptr< nanoarrow::UniqueArrayView> arrowArrayView = std::make_unique<nanoarrow::UniqueArrayView>() ;
43+ nanoarrow::UniqueSchema arrowSchema;
44+ nanoarrow::UniqueArray arrowArray;
45+ nanoarrow::UniqueArrayView arrowArrayView;
4746
4847 // Recommended path
4948 // TODO: Export is not needed when using nanoarrow IPC to read schema
5049 arrow::Status exportBatchOk = arrow::ExportRecordBatch (
51- *currentBatch, arrowArray-> get (), arrowSchema-> get ());
50+ *currentBatch, arrowArray. get (), arrowSchema. get ());
5251
5352 ArrowError error;
5453 int returnCode = ArrowArrayViewInitFromSchema (
55- arrowArrayView-> get (), arrowSchema-> get (), &error);
54+ arrowArrayView. get (), arrowSchema. get (), &error);
5655 if (returnCode != NANOARROW_OK) {
5756 std::string errorInfo = Logger::formatString (
5857 " [Snowflake Exception] error initializing ArrowArrayView from schema : %s" ,
@@ -63,7 +62,7 @@ void CArrowTableIterator::reconstructRecordBatches_nanoarrow()
6362 }
6463
6564 returnCode = ArrowArrayViewSetArray (
66- arrowArrayView-> get (), arrowArray-> get (), &error);
65+ arrowArrayView. get (), arrowArray. get (), &error);
6766 if (returnCode != NANOARROW_OK) {
6867 std::string errorInfo = Logger::formatString (
6968 " [Snowflake Exception] error initializing ArrowArrayView from array : %s" ,
@@ -79,8 +78,8 @@ void CArrowTableIterator::reconstructRecordBatches_nanoarrow()
7978
8079 for (int colIdx = 0 ; colIdx < currentBatch->num_columns (); colIdx++)
8180 {
82- ArrowArrayView* columnArray = m_nanoarrowViews[batchIdx]->get ()-> children [colIdx];
83- ArrowSchema* columnSchema = m_nanoarrowSchemas[batchIdx]->get ()-> children [colIdx];
81+ ArrowArrayView* columnArray = m_nanoarrowViews[batchIdx]->children [colIdx];
82+ ArrowSchema* columnSchema = m_nanoarrowSchemas[batchIdx]->children [colIdx];
8483 ArrowSchemaView columnSchemaView;
8584
8685 returnCode = ArrowSchemaViewInit (
@@ -95,7 +94,7 @@ void CArrowTableIterator::reconstructRecordBatches_nanoarrow()
9594 }
9695
9796 ArrowStringView snowflakeLogicalType;
98- const char * metadata = m_nanoarrowSchemas[batchIdx]->get ()-> children [colIdx]->metadata ;
97+ const char * metadata = m_nanoarrowSchemas[batchIdx]->children [colIdx]->metadata ;
9998 ArrowMetadataGetValue (metadata, ArrowCharView (" logicalType" ), &snowflakeLogicalType);
10099 SnowflakeType::Type st = SnowflakeType::snowflakeTypeFromString (
101100 std::string (snowflakeLogicalType.data , snowflakeLogicalType.size_bytes )
@@ -305,10 +304,10 @@ void CArrowTableIterator::convertScaledFixedNumberColumnToDecimalColumn_nanoarro
305304)
306305{
307306 // Convert to arrow double/float64 column
308- std::unique_ptr< nanoarrow::UniqueSchema> newUniqueField = std::make_unique<nanoarrow::UniqueSchema>() ;
309- std::unique_ptr< nanoarrow::UniqueArray> newUniqueArray = std::make_unique<nanoarrow::UniqueArray>() ;
310- ArrowSchema* newSchema = newUniqueField-> get ();
311- ArrowArray* newArray = newUniqueArray-> get ();
307+ nanoarrow::UniqueSchema newUniqueField;
308+ nanoarrow::UniqueArray newUniqueArray;
309+ ArrowSchema* newSchema = newUniqueField. get ();
310+ ArrowArray* newArray = newUniqueArray. get ();
312311
313312 // create new schema
314313 ArrowSchemaInit (newSchema);
@@ -337,8 +336,8 @@ void CArrowTableIterator::convertScaledFixedNumberColumnToDecimalColumn_nanoarro
337336 }
338337 }
339338 ArrowArrayFinishBuildingDefault (newArray, &error);
340- m_nanoarrowTable [batchIdx]->get ()-> children [colIdx] = newArray ;
341- m_nanoarrowSchemas [batchIdx]->get ()-> children [colIdx] = newSchema ;
339+ ArrowSchemaMove (newSchema, m_nanoarrowSchemas [batchIdx]->children [colIdx]) ;
340+ ArrowArrayMove (newArray, m_nanoarrowTable [batchIdx]->children [colIdx]) ;
342341 m_newArrays[batchIdx].push_back (std::move (newUniqueArray));
343342 m_newSchemas[batchIdx].push_back (std::move (newUniqueField));
344343}
@@ -352,10 +351,10 @@ void CArrowTableIterator::convertScaledFixedNumberColumnToDoubleColumn_nanoarrow
352351)
353352{
354353 // Convert to arrow double/float64 column
355- std::unique_ptr< nanoarrow::UniqueSchema> newUniqueField = std::make_unique<nanoarrow::UniqueSchema>() ;
356- std::unique_ptr< nanoarrow::UniqueArray> newUniqueArray = std::make_unique<nanoarrow::UniqueArray>() ;
357- ArrowSchema* newSchema = newUniqueField-> get ();
358- ArrowArray* newArray = newUniqueArray-> get ();
354+ nanoarrow::UniqueSchema newUniqueField;
355+ nanoarrow::UniqueArray newUniqueArray;
356+ ArrowSchema* newSchema = newUniqueField. get ();
357+ ArrowArray* newArray = newUniqueArray. get ();
359358
360359 // create new schema
361360 ArrowSchemaInit (newSchema);
@@ -385,8 +384,8 @@ void CArrowTableIterator::convertScaledFixedNumberColumnToDoubleColumn_nanoarrow
385384 }
386385 }
387386 ArrowArrayFinishBuildingDefault (newArray, &error);
388- m_nanoarrowTable [batchIdx]->get ()-> children [colIdx] = newArray ;
389- m_nanoarrowSchemas [batchIdx]->get ()-> children [colIdx] = newSchema ;
387+ ArrowSchemaMove (newSchema, m_nanoarrowSchemas [batchIdx]->children [colIdx]) ;
388+ ArrowArrayMove (newArray, m_nanoarrowTable [batchIdx]->children [colIdx]) ;
390389 m_newArrays[batchIdx].push_back (std::move (newUniqueArray));
391390 m_newSchemas[batchIdx].push_back (std::move (newUniqueField));
392391}
@@ -399,10 +398,10 @@ void CArrowTableIterator::convertTimeColumn_nanoarrow(
399398 const int scale
400399)
401400{
402- std::unique_ptr< nanoarrow::UniqueSchema> newUniqueField = std::make_unique<nanoarrow::UniqueSchema>() ;
403- std::unique_ptr< nanoarrow::UniqueArray> newUniqueArray = std::make_unique<nanoarrow::UniqueArray>() ;
404- ArrowSchema* newSchema = newUniqueField-> get ();
405- ArrowArray* newArray = newUniqueArray-> get ();
401+ nanoarrow::UniqueSchema newUniqueField;
402+ nanoarrow::UniqueArray newUniqueArray;
403+ ArrowSchema* newSchema = newUniqueField. get ();
404+ ArrowArray* newArray = newUniqueArray. get ();
406405 ArrowError error;
407406
408407 // create new schema
@@ -458,8 +457,8 @@ void CArrowTableIterator::convertTimeColumn_nanoarrow(
458457 }
459458
460459 ArrowArrayFinishBuildingDefault (newArray, &error);
461- m_nanoarrowTable [batchIdx]->get ()-> children [colIdx] = newArray ;
462- m_nanoarrowSchemas [batchIdx]->get ()-> children [colIdx] = newSchema ;
460+ ArrowSchemaMove (newSchema, m_nanoarrowSchemas [batchIdx]->children [colIdx]) ;
461+ ArrowArrayMove (newArray, m_nanoarrowTable [batchIdx]->children [colIdx]) ;
463462 m_newArrays[batchIdx].push_back (std::move (newUniqueArray));
464463 m_newSchemas[batchIdx].push_back (std::move (newUniqueField));
465464}
@@ -473,10 +472,10 @@ void CArrowTableIterator::convertTimestampColumn_nanoarrow(
473472 const std::string timezone
474473)
475474{
476- std::unique_ptr< nanoarrow::UniqueSchema> newUniqueField = std::make_unique<nanoarrow::UniqueSchema>() ;
477- std::unique_ptr< nanoarrow::UniqueArray> newUniqueArray = std::make_unique<nanoarrow::UniqueArray>() ;
478- ArrowSchema* newSchema = newUniqueField-> get ();
479- ArrowArray* newArray = newUniqueArray-> get ();
475+ nanoarrow::UniqueSchema newUniqueField;
476+ nanoarrow::UniqueArray newUniqueArray;
477+ ArrowSchema* newSchema = newUniqueField. get ();
478+ ArrowArray* newArray = newUniqueArray. get ();
480479 ArrowError error;
481480
482481 ArrowSchemaInit (newSchema);
@@ -624,6 +623,7 @@ void CArrowTableIterator::convertTimestampColumn_nanoarrow(
624623 {
625624 val = epoch * sf::internal::powTenSB4[6 ] + fraction / 1000 ;
626625 }
626+ else
627627 {
628628 val = epoch * sf::internal::powTenSB4[9 ] + fraction;
629629 }
@@ -675,8 +675,8 @@ void CArrowTableIterator::convertTimestampColumn_nanoarrow(
675675 }
676676
677677 ArrowArrayFinishBuildingDefault (newArray, &error);
678- m_nanoarrowTable [batchIdx]->get ()-> children [colIdx] = newArray ;
679- m_nanoarrowSchemas [batchIdx]->get ()-> children [colIdx] = newSchema ;
678+ ArrowSchemaMove (newSchema, m_nanoarrowSchemas [batchIdx]->children [colIdx]) ;
679+ ArrowArrayMove (newArray, m_nanoarrowTable [batchIdx]->children [colIdx]) ;
680680 m_newArrays[batchIdx].push_back (std::move (newUniqueArray));
681681 m_newSchemas[batchIdx].push_back (std::move (newUniqueField));
682682}
@@ -691,10 +691,10 @@ void CArrowTableIterator::convertTimestampTZColumn_nanoarrow(
691691 const std::string timezone
692692)
693693{
694- std::unique_ptr< nanoarrow::UniqueSchema> newUniqueField = std::make_unique<nanoarrow::UniqueSchema>() ;
695- std::unique_ptr< nanoarrow::UniqueArray> newUniqueArray = std::make_unique<nanoarrow::UniqueArray>() ;
696- ArrowSchema* newSchema = newUniqueField-> get ();
697- ArrowArray* newArray = newUniqueArray-> get ();
694+ nanoarrow::UniqueSchema newUniqueField;
695+ nanoarrow::UniqueArray newUniqueArray;
696+ ArrowSchema* newSchema = newUniqueField. get ();
697+ ArrowArray* newArray = newUniqueArray. get ();
698698 ArrowError error;
699699 ArrowSchemaInit (newSchema);
700700 newSchema->flags &= (field->schema ->flags & ARROW_FLAG_NULLABLE); // map to nullable()
@@ -813,8 +813,8 @@ void CArrowTableIterator::convertTimestampTZColumn_nanoarrow(
813813 }
814814
815815 ArrowArrayFinishBuildingDefault (newArray, &error);
816- m_nanoarrowTable [batchIdx]->get ()-> children [colIdx] = newArray ;
817- m_nanoarrowSchemas [batchIdx]->get ()-> children [colIdx] = newSchema ;
816+ ArrowSchemaMove (newSchema, m_nanoarrowSchemas [batchIdx]->children [colIdx]) ;
817+ ArrowArrayMove (newArray, m_nanoarrowTable [batchIdx]->children [colIdx]) ;
818818 m_newArrays[batchIdx].push_back (std::move (newUniqueArray));
819819 m_newSchemas[batchIdx].push_back (std::move (newUniqueField));
820820}
@@ -833,15 +833,15 @@ bool CArrowTableIterator::convertRecordBatchesToTable_nanoarrow()
833833std::vector<uintptr_t > CArrowTableIterator::getArrowArrayPtrs () {
834834 std::vector<uintptr_t > ret;
835835 for (size_t i = 0 ; i < m_nanoarrowTable.size (); i++) {
836- ret.push_back ((uintptr_t )(void *)(m_nanoarrowTable[i]-> get ()));
836+ ret.push_back ((uintptr_t )(void *)(m_nanoarrowTable[i]. get ()));
837837 }
838838 return ret;
839839}
840840
841841std::vector<uintptr_t > CArrowTableIterator::getArrowSchemaPtrs () {
842842 std::vector<uintptr_t > ret;
843843 for (size_t i = 0 ; i < m_nanoarrowSchemas.size (); i++) {
844- ret.push_back ((uintptr_t )(void *)(m_nanoarrowSchemas[i]-> get ()));
844+ ret.push_back ((uintptr_t )(void *)(m_nanoarrowSchemas[i]. get ()));
845845 }
846846 return ret;
847847}
0 commit comments