Skip to content

Commit eeb7e63

Browse files
committed
Snow 773928 CArrowChunkIterator Decimal Conversion Context (#1545)
1 parent 60e22d5 commit eeb7e63

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,18 @@ PyObject* DecimalFromDecimalConverter::toPyObject(int64_t rowIndex) const
8484
int64_t bytes_start = 16 * (m_array->array->offset + rowIndex);
8585
const char* ptr_start = m_array->buffer_views[1].data.as_char;
8686
PyObject* int128_bytes = PyBytes_FromStringAndSize(&(ptr_start[bytes_start]), 16);
87+
/**
88+
# Alternatively, the decimal conversion can be implemented using the ArrowDecimal related APIs in the following
89+
# code snippets, however, it's less performant than the direct memory manipulation.
90+
# The code snippets here is for context reference.
91+
92+
ArrowDecimal arrowDecimal;
93+
ArrowDecimalInit(&arrowDecimal, 128, precision, scale);
94+
ArrowArrayViewGetDecimalUnsafe(m_array, rowIndex, &arrowDecimal);
95+
uint8_t outBytes[16];
96+
ArrowDecimalGetBytes(&arrowDecimal, outBytes);
97+
PyObject* int128_bytes = PyBytes_FromStringAndSize(&outBytes, 16);
98+
*/
8799
return PyObject_CallMethod(m_context, "DECIMAL128_to_decimal", "Si", int128_bytes, m_scale);
88100
}
89101

0 commit comments

Comments
 (0)