Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ inline RowStatus MoveSingleCellToBinaryBuffer(ColumnBinding* binding, BinaryArra
value_offset = -1;
}

if (binding->strlen_buffer) {
binding->strlen_buffer[i] = static_cast<ssize_t>(remaining_length);
if (binding->str_len_buffer) {
binding->str_len_buffer[i] = static_cast<ssize_t>(remaining_length);
}

return result;
Expand All @@ -72,15 +72,15 @@ BinaryArrayFlightSqlAccessor<TARGET_TYPE>::BinaryArrayFlightSqlAccessor(Array* a

template <>
RowStatus
BinaryArrayFlightSqlAccessor<odbcabstraction::CDataType_BINARY>::MoveSingleCell_impl(
BinaryArrayFlightSqlAccessor<odbcabstraction::CDataType_BINARY>::MoveSingleCellImpl(
ColumnBinding* binding, int64_t arrow_row, int64_t i, int64_t& value_offset,
bool update_value_offset, odbcabstraction::Diagnostics& diagnostics) {
return MoveSingleCellToBinaryBuffer(binding, this->GetArray(), arrow_row, i,
value_offset, update_value_offset, diagnostics);
}

template <CDataType TARGET_TYPE>
size_t BinaryArrayFlightSqlAccessor<TARGET_TYPE>::GetCellLength_impl(
size_t BinaryArrayFlightSqlAccessor<TARGET_TYPE>::GetCellLengthImpl(
ColumnBinding* binding) const {
return binding->buffer_length;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ class BinaryArrayFlightSqlAccessor
public:
explicit BinaryArrayFlightSqlAccessor(Array* array);

RowStatus MoveSingleCell_impl(ColumnBinding* binding, int64_t arrow_row, int64_t i,
int64_t& value_offset, bool update_value_offset,
odbcabstraction::Diagnostics& diagnostics);
RowStatus MoveSingleCellImpl(ColumnBinding* binding, int64_t arrow_row, int64_t i,
int64_t& value_offset, bool update_value_offset,
odbcabstraction::Diagnostics& diagnostics);

size_t GetCellLength_impl(ColumnBinding* binding) const;
size_t GetCellLengthImpl(ColumnBinding* binding) const;
};

} // namespace flight_sql
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ TEST(BinaryArrayAccessor, Test_CDataType_BINARY_Basic) {

BinaryArrayFlightSqlAccessor<odbcabstraction::CDataType_BINARY> accessor(array.get());

size_t max_strlen = 64;
std::vector<char> buffer(values.size() * max_strlen);
std::vector<ssize_t> strlen_buffer(values.size());
size_t max_str_len = 64;
std::vector<char> buffer(values.size() * max_str_len);
std::vector<ssize_t> str_len_buffer(values.size());

ColumnBinding binding(odbcabstraction::CDataType_BINARY, 0, 0, buffer.data(),
max_strlen, strlen_buffer.data());
max_str_len, str_len_buffer.data());

int64_t value_offset = 0;
odbcabstraction::Diagnostics diagnostics("Foo", "Foo", OdbcVersion::V_3);
Expand All @@ -49,12 +49,13 @@ TEST(BinaryArrayAccessor, Test_CDataType_BINARY_Basic) {
diagnostics, nullptr));

for (int i = 0; i < values.size(); ++i) {
ASSERT_EQ(values[i].length(), strlen_buffer[i]);
ASSERT_EQ(values[i].length(), str_len_buffer[i]);
// Beware that CDataType_BINARY values are not null terminated.
// It's safe to create a std::string from this data because we know it's
// ASCII, this doesn't work with arbitrary binary data.
ASSERT_EQ(values[i], std::string(buffer.data() + i * max_strlen,
buffer.data() + i * max_strlen + strlen_buffer[i]));
ASSERT_EQ(values[i],
std::string(buffer.data() + i * max_str_len,
buffer.data() + i * max_str_len + str_len_buffer[i]));
}
}

Expand All @@ -65,12 +66,12 @@ TEST(BinaryArrayAccessor, Test_CDataType_BINARY_Truncation) {

BinaryArrayFlightSqlAccessor<odbcabstraction::CDataType_BINARY> accessor(array.get());

size_t max_strlen = 8;
std::vector<char> buffer(values.size() * max_strlen);
std::vector<ssize_t> strlen_buffer(values.size());
size_t max_str_len = 8;
std::vector<char> buffer(values.size() * max_str_len);
std::vector<ssize_t> str_len_buffer(values.size());

ColumnBinding binding(odbcabstraction::CDataType_BINARY, 0, 0, buffer.data(),
max_strlen, strlen_buffer.data());
max_str_len, str_len_buffer.data());

std::stringstream ss;
int64_t value_offset = 0;
Expand All @@ -83,13 +84,13 @@ TEST(BinaryArrayAccessor, Test_CDataType_BINARY_Truncation) {
int64_t original_value_offset = value_offset;
ASSERT_EQ(1, accessor.GetColumnarData(&binding, 0, 1, value_offset, true, diagnostics,
nullptr));
ASSERT_EQ(values[0].length() - original_value_offset, strlen_buffer[0]);
ASSERT_EQ(values[0].length() - original_value_offset, str_len_buffer[0]);

int64_t chunk_length = 0;
if (value_offset == -1) {
chunk_length = strlen_buffer[0];
chunk_length = str_len_buffer[0];
} else {
chunk_length = max_strlen;
chunk_length = max_str_len;
}

// Beware that CDataType_BINARY values are not null terminated.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ BooleanArrayFlightSqlAccessor<TARGET_TYPE>::BooleanArrayFlightSqlAccessor(Array*
BooleanArrayFlightSqlAccessor<TARGET_TYPE>>(array) {}

template <CDataType TARGET_TYPE>
RowStatus BooleanArrayFlightSqlAccessor<TARGET_TYPE>::MoveSingleCell_impl(
RowStatus BooleanArrayFlightSqlAccessor<TARGET_TYPE>::MoveSingleCellImpl(
ColumnBinding* binding, int64_t arrow_row, int64_t i, int64_t& value_offset,
bool update_value_offset, odbcabstraction::Diagnostics& diagnostics) {
typedef unsigned char c_type;
Expand All @@ -38,15 +38,15 @@ RowStatus BooleanArrayFlightSqlAccessor<TARGET_TYPE>::MoveSingleCell_impl(
auto* buffer = static_cast<c_type*>(binding->buffer);
buffer[i] = value ? 1 : 0;

if (binding->strlen_buffer) {
binding->strlen_buffer[i] = static_cast<ssize_t>(GetCellLength_impl(binding));
if (binding->str_len_buffer) {
binding->str_len_buffer[i] = static_cast<ssize_t>(GetCellLengthImpl(binding));
}

return odbcabstraction::RowStatus_SUCCESS;
}

template <CDataType TARGET_TYPE>
size_t BooleanArrayFlightSqlAccessor<TARGET_TYPE>::GetCellLength_impl(
size_t BooleanArrayFlightSqlAccessor<TARGET_TYPE>::GetCellLengthImpl(
ColumnBinding* binding) const {
return sizeof(unsigned char);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ class BooleanArrayFlightSqlAccessor
public:
explicit BooleanArrayFlightSqlAccessor(Array* array);

RowStatus MoveSingleCell_impl(ColumnBinding* binding, int64_t arrow_row, int64_t i,
int64_t& value_offset, bool update_value_offset,
odbcabstraction::Diagnostics& diagnostics);
RowStatus MoveSingleCellImpl(ColumnBinding* binding, int64_t arrow_row, int64_t i,
int64_t& value_offset, bool update_value_offset,
odbcabstraction::Diagnostics& diagnostics);

size_t GetCellLength_impl(ColumnBinding* binding) const;
size_t GetCellLengthImpl(ColumnBinding* binding) const;
};

} // namespace flight_sql
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ TEST(BooleanArrayFlightSqlAccessor, Test_BooleanArray_CDataType_BIT) {
BooleanArrayFlightSqlAccessor<odbcabstraction::CDataType_BIT> accessor(array.get());

std::vector<char> buffer(values.size());
std::vector<ssize_t> strlen_buffer(values.size());
std::vector<ssize_t> str_len_buffer(values.size());

ColumnBinding binding(odbcabstraction::CDataType_BIT, 0, 0, buffer.data(), 0,
strlen_buffer.data());
str_len_buffer.data());

int64_t value_offset = 0;
odbcabstraction::Diagnostics diagnostics("Foo", "Foo", OdbcVersion::V_3);
Expand All @@ -47,7 +47,7 @@ TEST(BooleanArrayFlightSqlAccessor, Test_BooleanArray_CDataType_BIT) {
diagnostics, nullptr));

for (int i = 0; i < values.size(); ++i) {
ASSERT_EQ(sizeof(unsigned char), strlen_buffer[i]);
ASSERT_EQ(sizeof(unsigned char), str_len_buffer[i]);
ASSERT_EQ(values[i] ? 1 : 0, buffer[i]);
}
}
Expand Down
6 changes: 3 additions & 3 deletions cpp/src/arrow/flight/sql/odbc/flight_sql/accessors/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ inline size_t CopyFromArrayValuesToBinding(ARRAY_TYPE* array, ColumnBinding* bin
int64_t starting_row, int64_t cells) {
constexpr ssize_t element_size = sizeof(typename ARRAY_TYPE::value_type);

if (binding->strlen_buffer) {
if (binding->str_len_buffer) {
for (int64_t i = 0; i < cells; ++i) {
int64_t current_row = starting_row + i;
if (array->IsNull(current_row)) {
binding->strlen_buffer[i] = odbcabstraction::NULL_DATA;
binding->str_len_buffer[i] = odbcabstraction::NULL_DATA;
} else {
binding->strlen_buffer[i] = element_size;
binding->str_len_buffer[i] = element_size;
}
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ DateArrayFlightSqlAccessor<TARGET_TYPE, ARROW_ARRAY>::DateArrayFlightSqlAccessor
DateArrayFlightSqlAccessor<TARGET_TYPE, ARROW_ARRAY>>(array) {}

template <CDataType TARGET_TYPE, typename ARROW_ARRAY>
RowStatus DateArrayFlightSqlAccessor<TARGET_TYPE, ARROW_ARRAY>::MoveSingleCell_impl(
RowStatus DateArrayFlightSqlAccessor<TARGET_TYPE, ARROW_ARRAY>::MoveSingleCellImpl(
ColumnBinding* binding, int64_t arrow_row, int64_t cell_counter,
int64_t& value_offset, bool update_value_offset,
odbcabstraction::Diagnostics& diagnostics) {
Expand All @@ -74,16 +74,16 @@ RowStatus DateArrayFlightSqlAccessor<TARGET_TYPE, ARROW_ARRAY>::MoveSingleCell_i
buffer[cell_counter].month = date.tm_mon + 1;
buffer[cell_counter].day = date.tm_mday;

if (binding->strlen_buffer) {
binding->strlen_buffer[cell_counter] =
static_cast<ssize_t>(GetCellLength_impl(binding));
if (binding->str_len_buffer) {
binding->str_len_buffer[cell_counter] =
static_cast<ssize_t>(GetCellLengthImpl(binding));
}

return odbcabstraction::RowStatus_SUCCESS;
}

template <CDataType TARGET_TYPE, typename ARROW_ARRAY>
size_t DateArrayFlightSqlAccessor<TARGET_TYPE, ARROW_ARRAY>::GetCellLength_impl(
size_t DateArrayFlightSqlAccessor<TARGET_TYPE, ARROW_ARRAY>::GetCellLengthImpl(
ColumnBinding* binding) const {
return sizeof(DATE_STRUCT);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ class DateArrayFlightSqlAccessor
public:
explicit DateArrayFlightSqlAccessor(Array* array);

RowStatus MoveSingleCell_impl(ColumnBinding* binding, int64_t arrow_row,
int64_t cell_counter, int64_t& value_offset,
bool update_value_offset,
odbcabstraction::Diagnostics& diagnostics);
RowStatus MoveSingleCellImpl(ColumnBinding* binding, int64_t arrow_row,
int64_t cell_counter, int64_t& value_offset,
bool update_value_offset,
odbcabstraction::Diagnostics& diagnostics);

size_t GetCellLength_impl(ColumnBinding* binding) const;
size_t GetCellLengthImpl(ColumnBinding* binding) const;
};

} // namespace flight_sql
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ TEST(DateArrayAccessor, Test_Date32Array_CDataType_DATE) {
dynamic_cast<NumericArray<Date32Type>*>(array.get()));

std::vector<tagDATE_STRUCT> buffer(values.size());
std::vector<ssize_t> strlen_buffer(values.size());
std::vector<ssize_t> str_len_buffer(values.size());

ColumnBinding binding(odbcabstraction::CDataType_DATE, 0, 0, buffer.data(), 0,
strlen_buffer.data());
str_len_buffer.data());

int64_t value_offset = 0;
odbcabstraction::Diagnostics diagnostics("Foo", "Foo", OdbcVersion::V_3);
Expand All @@ -63,7 +63,7 @@ TEST(DateArrayAccessor, Test_Date32Array_CDataType_DATE) {
diagnostics, nullptr));

for (size_t i = 0; i < values.size(); ++i) {
ASSERT_EQ(sizeof(DATE_STRUCT), strlen_buffer[i]);
ASSERT_EQ(sizeof(DATE_STRUCT), str_len_buffer[i]);

ASSERT_EQ(expected[i].year, buffer[i].year);
ASSERT_EQ(expected[i].month, buffer[i].month);
Expand All @@ -89,10 +89,10 @@ TEST(DateArrayAccessor, Test_Date64Array_CDataType_DATE) {
dynamic_cast<NumericArray<Date64Type>*>(array.get()));

std::vector<tagDATE_STRUCT> buffer(values.size());
std::vector<ssize_t> strlen_buffer(values.size());
std::vector<ssize_t> str_len_buffer(values.size());

ColumnBinding binding(odbcabstraction::CDataType_DATE, 0, 0, buffer.data(), 0,
strlen_buffer.data());
str_len_buffer.data());

int64_t value_offset = 0;
odbcabstraction::Diagnostics diagnostics("Foo", "Foo", OdbcVersion::V_3);
Expand All @@ -101,7 +101,7 @@ TEST(DateArrayAccessor, Test_Date64Array_CDataType_DATE) {
diagnostics, nullptr));

for (size_t i = 0; i < values.size(); ++i) {
ASSERT_EQ(sizeof(DATE_STRUCT), strlen_buffer[i]);
ASSERT_EQ(sizeof(DATE_STRUCT), str_len_buffer[i]);
ASSERT_EQ(expected[i].year, buffer[i].year);
ASSERT_EQ(expected[i].month, buffer[i].month);
ASSERT_EQ(expected[i].day, buffer[i].day);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ DecimalArrayFlightSqlAccessor<ARROW_ARRAY, TARGET_TYPE>::DecimalArrayFlightSqlAc
template <>
RowStatus
DecimalArrayFlightSqlAccessor<Decimal128Array, odbcabstraction::CDataType_NUMERIC>::
MoveSingleCell_impl(ColumnBinding* binding, int64_t arrow_row, int64_t i,
int64_t& value_offset, bool update_value_offset,
odbcabstraction::Diagnostics& diagnostics) {
MoveSingleCellImpl(ColumnBinding* binding, int64_t arrow_row, int64_t i,
int64_t& value_offset, bool update_value_offset,
odbcabstraction::Diagnostics& diagnostics) {
auto result = &(static_cast<NUMERIC_STRUCT*>(binding->buffer)[i]);
int32_t original_scale = data_type_->scale();

Expand Down Expand Up @@ -74,15 +74,15 @@ DecimalArrayFlightSqlAccessor<Decimal128Array, odbcabstraction::CDataType_NUMERI

result->precision = data_type_->precision();

if (binding->strlen_buffer) {
binding->strlen_buffer[i] = static_cast<ssize_t>(GetCellLength_impl(binding));
if (binding->str_len_buffer) {
binding->str_len_buffer[i] = static_cast<ssize_t>(GetCellLengthImpl(binding));
}

return odbcabstraction::RowStatus_SUCCESS;
}

template <typename ARROW_ARRAY, CDataType TARGET_TYPE>
size_t DecimalArrayFlightSqlAccessor<ARROW_ARRAY, TARGET_TYPE>::GetCellLength_impl(
size_t DecimalArrayFlightSqlAccessor<ARROW_ARRAY, TARGET_TYPE>::GetCellLengthImpl(
ColumnBinding* binding) const {
return sizeof(NUMERIC_STRUCT);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ class DecimalArrayFlightSqlAccessor
public:
explicit DecimalArrayFlightSqlAccessor(Array* array);

RowStatus MoveSingleCell_impl(ColumnBinding* binding, int64_t arrow_row, int64_t i,
int64_t& value_offset, bool update_value_offset,
odbcabstraction::Diagnostics& diagnostics);
RowStatus MoveSingleCellImpl(ColumnBinding* binding, int64_t arrow_row, int64_t i,
int64_t& value_offset, bool update_value_offset,
odbcabstraction::Diagnostics& diagnostics);

size_t GetCellLength_impl(ColumnBinding* binding) const;
size_t GetCellLengthImpl(ColumnBinding* binding) const;

private:
Decimal128Type* data_type_;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,10 @@ void AssertNumericOutput(int input_precision, int input_scale,
accessor(array.get());

std::vector<NUMERIC_STRUCT> buffer(values.size());
std::vector<ssize_t> strlen_buffer(values.size());
std::vector<ssize_t> str_len_buffer(values.size());

ColumnBinding binding(odbcabstraction::CDataType_NUMERIC, output_precision,
output_scale, buffer.data(), 0, strlen_buffer.data());
output_scale, buffer.data(), 0, str_len_buffer.data());

int64_t value_offset = 0;
odbcabstraction::Diagnostics diagnostics("Foo", "Foo", OdbcVersion::V_3);
Expand All @@ -96,7 +96,7 @@ void AssertNumericOutput(int input_precision, int input_scale,
diagnostics, nullptr));

for (int i = 0; i < values.size(); ++i) {
ASSERT_EQ(sizeof(NUMERIC_STRUCT), strlen_buffer[i]);
ASSERT_EQ(sizeof(NUMERIC_STRUCT), str_len_buffer[i]);

ASSERT_EQ(output_precision, buffer[i].precision);
ASSERT_EQ(output_scale, buffer[i].scale);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ PrimitiveArrayFlightSqlAccessor<
array) {}

template <typename ARROW_ARRAY, CDataType TARGET_TYPE>
size_t PrimitiveArrayFlightSqlAccessor<ARROW_ARRAY, TARGET_TYPE>::GetColumnarData_impl(
size_t PrimitiveArrayFlightSqlAccessor<ARROW_ARRAY, TARGET_TYPE>::GetColumnarDataImpl(
ColumnBinding* binding, int64_t starting_row, int64_t cells, int64_t& value_offset,
bool update_value_offset, odbcabstraction::Diagnostics& diagnostics,
uint16_t* row_status_array) {
Expand All @@ -48,7 +48,7 @@ size_t PrimitiveArrayFlightSqlAccessor<ARROW_ARRAY, TARGET_TYPE>::GetColumnarDat
}

template <typename ARROW_ARRAY, CDataType TARGET_TYPE>
size_t PrimitiveArrayFlightSqlAccessor<ARROW_ARRAY, TARGET_TYPE>::GetCellLength_impl(
size_t PrimitiveArrayFlightSqlAccessor<ARROW_ARRAY, TARGET_TYPE>::GetCellLengthImpl(
ColumnBinding* binding) const {
return sizeof(typename ARROW_ARRAY::TypeClass::c_type);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ class PrimitiveArrayFlightSqlAccessor
public:
explicit PrimitiveArrayFlightSqlAccessor(Array* array);

size_t GetColumnarData_impl(ColumnBinding* binding, int64_t starting_row, int64_t cells,
int64_t& value_offset, bool update_value_offset,
odbcabstraction::Diagnostics& diagnostics,
uint16_t* row_status_array);
size_t GetColumnarDataImpl(ColumnBinding* binding, int64_t starting_row, int64_t cells,
int64_t& value_offset, bool update_value_offset,
odbcabstraction::Diagnostics& diagnostics,
uint16_t* row_status_array);

size_t GetCellLength_impl(ColumnBinding* binding) const;
size_t GetCellLengthImpl(ColumnBinding* binding) const;
};

} // namespace flight_sql
Expand Down
Loading
Loading