Skip to content

Commit c2e4c79

Browse files
committed
fix ArrowStringView (#1659)
1 parent 4db7f96 commit c2e4c79

File tree

2 files changed

+27
-27
lines changed

2 files changed

+27
-27
lines changed

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

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ void CArrowChunkIterator::initColumnConverters()
118118

119119
ArrowArrayView* array = m_ipcArrowArrayViewVec[m_currentBatchIndex]->children[i];
120120

121-
ArrowStringView snowflakeLogicalType;
121+
struct ArrowStringView snowflakeLogicalType = ArrowCharView(nullptr);
122122
const char* metadata = m_ipcArrowSchema->children[i]->metadata;
123123
returnCode = ArrowMetadataGetValue(metadata, ArrowCharView("logicalType"), &snowflakeLogicalType);
124124
SF_CHECK_ARROW_RC(returnCode, "[Snowflake Exception] error getting 'logicalType' from Arrow metadata, error code: %d", returnCode);
@@ -131,17 +131,17 @@ void CArrowChunkIterator::initColumnConverters()
131131
{
132132
case SnowflakeType::Type::FIXED:
133133
{
134-
ArrowStringView scaleString;
135-
ArrowStringView precisionString;
134+
struct ArrowStringView scaleString = ArrowCharView(nullptr);
135+
struct ArrowStringView precisionString = ArrowCharView(nullptr);
136136
int scale = 0;
137137
int precision = 38;
138138
if(metadata != nullptr) {
139139
returnCode = ArrowMetadataGetValue(metadata, ArrowCharView("scale"), &scaleString);
140140
SF_CHECK_ARROW_RC(returnCode, "[Snowflake Exception] error getting 'scale' from Arrow metadata, error code: %d", returnCode);
141141
returnCode = ArrowMetadataGetValue(metadata, ArrowCharView("precision"), &precisionString);
142142
SF_CHECK_ARROW_RC(returnCode, "[Snowflake Exception] error getting 'precision' from Arrow metadata, error code: %d", returnCode);
143-
scale = std::stoi(scaleString.data);
144-
precision = std::stoi(precisionString.data);
143+
scale = std::stoi(std::string(scaleString.data, scaleString.size_bytes));
144+
precision = std::stoi(std::string(precisionString.data, precisionString.size_bytes));
145145
}
146146

147147
switch(columnSchemaView.type)
@@ -271,10 +271,10 @@ void CArrowChunkIterator::initColumnConverters()
271271
{
272272
int scale = 9;
273273
if(metadata != nullptr) {
274-
ArrowStringView scaleString;
274+
struct ArrowStringView scaleString = ArrowCharView(nullptr);
275275
returnCode = ArrowMetadataGetValue(metadata, ArrowCharView("scale"), &scaleString);
276276
SF_CHECK_ARROW_RC(returnCode, "[Snowflake Exception] error getting 'scale' from Arrow metadata, error code: %d", returnCode);
277-
scale = std::stoi(scaleString.data);
277+
scale = std::stoi(std::string(scaleString.data, scaleString.size_bytes));
278278
}
279279
switch (columnSchemaView.type)
280280
{
@@ -305,10 +305,10 @@ void CArrowChunkIterator::initColumnConverters()
305305
{
306306
int scale = 9;
307307
if(metadata != nullptr) {
308-
ArrowStringView scaleString;
308+
struct ArrowStringView scaleString = ArrowCharView(nullptr);
309309
returnCode = ArrowMetadataGetValue(metadata, ArrowCharView("scale"), &scaleString);
310310
SF_CHECK_ARROW_RC(returnCode, "[Snowflake Exception] error getting 'scale' from Arrow metadata, error code: %d", returnCode);
311-
scale = std::stoi(scaleString.data);
311+
scale = std::stoi(std::string(scaleString.data, scaleString.size_bytes));
312312
}
313313
switch (columnSchemaView.type)
314314
{
@@ -364,10 +364,10 @@ void CArrowChunkIterator::initColumnConverters()
364364
{
365365
int scale = 9;
366366
if(metadata != nullptr) {
367-
ArrowStringView scaleString;
367+
struct ArrowStringView scaleString = ArrowCharView(nullptr);
368368
returnCode = ArrowMetadataGetValue(metadata, ArrowCharView("scale"), &scaleString);
369369
SF_CHECK_ARROW_RC(returnCode, "[Snowflake Exception] error getting 'scale' from Arrow metadata, error code: %d", returnCode);
370-
scale = std::stoi(scaleString.data);
370+
scale = std::stoi(std::string(scaleString.data, scaleString.size_bytes));
371371
}
372372
switch (columnSchemaView.type)
373373
{
@@ -403,17 +403,17 @@ void CArrowChunkIterator::initColumnConverters()
403403

404404
case SnowflakeType::Type::TIMESTAMP_TZ:
405405
{
406-
ArrowStringView scaleString;
407-
ArrowStringView byteLengthString;
406+
struct ArrowStringView scaleString = ArrowCharView(nullptr);
407+
struct ArrowStringView byteLengthString = ArrowCharView(nullptr);
408408
int scale = 9;
409409
int byteLength = 16;
410410
if(metadata != nullptr) {
411411
returnCode = ArrowMetadataGetValue(metadata, ArrowCharView("scale"), &scaleString);
412412
SF_CHECK_ARROW_RC(returnCode, "[Snowflake Exception] error getting 'scale' from Arrow metadata, error code: %d", returnCode);
413413
returnCode = ArrowMetadataGetValue(metadata, ArrowCharView("byteLength"), &byteLengthString);
414414
SF_CHECK_ARROW_RC(returnCode, "[Snowflake Exception] error getting 'byteLength' from Arrow metadata, error code: %d", returnCode);
415-
scale = std::stoi(scaleString.data);
416-
byteLength = std::stoi(byteLengthString.data);
415+
scale = std::stoi(std::string(scaleString.data, scaleString.size_bytes));
416+
byteLength = std::stoi(std::string(byteLengthString.data, byteLengthString.size_bytes));
417417
}
418418
switch (byteLength)
419419
{

src/snowflake/connector/cpp/ArrowIterator/CArrowTableIterator.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,11 @@ void CArrowTableIterator::reconstructRecordBatches_nanoarrow()
7070
case SnowflakeType::Type::FIXED:
7171
{
7272
int scale = 0;
73-
ArrowStringView scaleString;
73+
struct ArrowStringView scaleString = ArrowCharView(nullptr);
7474
if(metadata != nullptr) {
7575
returnCode = ArrowMetadataGetValue(metadata, ArrowCharView("scale"), &scaleString);
7676
SF_CHECK_ARROW_RC(returnCode, "[Snowflake Exception] error getting 'scale' from Arrow metadata, error code: %d", returnCode);
77-
scale = std::stoi(scaleString.data);
77+
scale = std::stoi(std::string(scaleString.data, scaleString.size_bytes));
7878
}
7979
if (scale > 0 && columnSchemaView.type != ArrowType::NANOARROW_TYPE_DECIMAL128)
8080
{
@@ -110,10 +110,10 @@ void CArrowTableIterator::reconstructRecordBatches_nanoarrow()
110110
{
111111
int scale = 9;
112112
if(metadata != nullptr) {
113-
ArrowStringView scaleString;
113+
struct ArrowStringView scaleString = ArrowCharView(nullptr);
114114
returnCode = ArrowMetadataGetValue(metadata, ArrowCharView("scale"), &scaleString);
115115
SF_CHECK_ARROW_RC(returnCode, "[Snowflake Exception] error getting 'scale' from Arrow metadata, error code: %d", returnCode);
116-
scale = std::stoi(scaleString.data);
116+
scale = std::stoi(std::string(scaleString.data, scaleString.size_bytes));
117117
}
118118

119119
convertTimeColumn_nanoarrow(batchIdx, colIdx, &columnSchemaView, columnArray, scale);
@@ -124,10 +124,10 @@ void CArrowTableIterator::reconstructRecordBatches_nanoarrow()
124124
{
125125
int scale = 9;
126126
if(metadata != nullptr) {
127-
ArrowStringView scaleString;
127+
struct ArrowStringView scaleString = ArrowCharView(nullptr);
128128
returnCode = ArrowMetadataGetValue(metadata, ArrowCharView("scale"), &scaleString);
129129
SF_CHECK_ARROW_RC(returnCode, "[Snowflake Exception] error getting 'scale' from Arrow metadata, error code: %d", returnCode);
130-
scale = std::stoi(scaleString.data);
130+
scale = std::stoi(std::string(scaleString.data, scaleString.size_bytes));
131131
}
132132
convertTimestampColumn_nanoarrow(batchIdx, colIdx, &columnSchemaView, columnArray, scale);
133133
break;
@@ -137,10 +137,10 @@ void CArrowTableIterator::reconstructRecordBatches_nanoarrow()
137137
{
138138
int scale = 9;
139139
if(metadata != nullptr) {
140-
ArrowStringView scaleString;
140+
struct ArrowStringView scaleString = ArrowCharView(nullptr);
141141
returnCode = ArrowMetadataGetValue(metadata, ArrowCharView("scale"), &scaleString);
142142
SF_CHECK_ARROW_RC(returnCode, "[Snowflake Exception] error getting 'scale' from Arrow metadata, error code: %d", returnCode);
143-
scale = std::stoi(scaleString.data);
143+
scale = std::stoi(std::string(scaleString.data, scaleString.size_bytes));
144144
}
145145

146146
convertTimestampColumn_nanoarrow(batchIdx, colIdx, &columnSchemaView, columnArray, scale, m_timezone);
@@ -149,17 +149,17 @@ void CArrowTableIterator::reconstructRecordBatches_nanoarrow()
149149

150150
case SnowflakeType::Type::TIMESTAMP_TZ:
151151
{
152-
ArrowStringView scaleString;
153-
ArrowStringView byteLengthString;
152+
struct ArrowStringView scaleString = ArrowCharView(nullptr);
153+
struct ArrowStringView byteLengthString = ArrowCharView(nullptr);
154154
int scale = 9;
155155
int byteLength = 16;
156156
if(metadata != nullptr) {
157157
returnCode = ArrowMetadataGetValue(metadata, ArrowCharView("scale"), &scaleString);
158158
SF_CHECK_ARROW_RC(returnCode, "[Snowflake Exception] error getting 'scale' from Arrow metadata, error code: %d", returnCode);
159159
returnCode = ArrowMetadataGetValue(metadata, ArrowCharView("byteLength"), &byteLengthString);
160160
SF_CHECK_ARROW_RC(returnCode, "[Snowflake Exception] error getting 'byteLength' from Arrow metadata, error code: %d", returnCode);
161-
scale = std::stoi(scaleString.data);
162-
byteLength = std::stoi(byteLengthString.data);
161+
scale = std::stoi(std::string(scaleString.data, scaleString.size_bytes));
162+
byteLength = std::stoi(std::string(byteLengthString.data, byteLengthString.size_bytes));
163163
}
164164

165165
convertTimestampTZColumn_nanoarrow(batchIdx, colIdx, &columnSchemaView, columnArray, scale, byteLength, m_timezone);

0 commit comments

Comments
 (0)