Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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 @@ -115,7 +115,10 @@ Result<std::shared_ptr<RecordBatch>> Transform_inner(
odbcabstraction::SqlDataType data_type_v3 =
GetDataTypeFromArrowField_V3(field, metadata_settings.use_wide_char_);

ColumnMetadata metadata(field->metadata());
const auto& metadata_map = field->metadata();
std::shared_ptr<const arrow::KeyValueMetadata> empty_metadata_map(
new arrow::KeyValueMetadata);
ColumnMetadata metadata(metadata_map ? metadata_map : empty_metadata_map);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's change the ColumnMetadata object itself to handle NULL safely and internally create an empty owned map (since it's easy for this to occur elsewhere)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yea that makes sense, I have updated the code to change ColumnMetadata.

There is an API Field::HasMetadata in arrow that checks if metadata is null, but seems it's not as commonly used.

arrow/cpp/src/arrow/type.cc

Lines 304 to 306 in a6bc579

bool Field::HasMetadata() const {
return (metadata_ != nullptr) && (metadata_->size() > 0);
}


data.table_cat = table_catalog;
data.table_schem = table_schema;
Expand All @@ -125,8 +128,8 @@ Result<std::shared_ptr<RecordBatch>> Transform_inner(
? data_type_v3
: ConvertSqlDataTypeFromV3ToV2(data_type_v3);

// TODO: Use `metadata.GetTypeName()` when ARROW-16064 is merged.
const auto& type_name_result = field->metadata()->Get("ARROW:FLIGHT:SQL:TYPE_NAME");
const auto& type_name_result = metadata.GetTypeName();

data.type_name = type_name_result.ok() ? type_name_result.ValueOrDie()
: GetTypeNameFromSqlDataType(data_type_v3);

Expand Down
2 changes: 1 addition & 1 deletion cpp/src/arrow/flight/sql/odbc/odbc_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -962,14 +962,14 @@ SQLRETURN SQLFetch(SQLHSTMT stmt) {

using ODBC::ODBCDescriptor;
using ODBC::ODBCStatement;

return ODBCStatement::ExecuteWithDiagnostics(stmt, SQL_ERROR, [=]() {
ODBCStatement* statement = reinterpret_cast<ODBCStatement*>(stmt);

// The SQL_ATTR_ROW_ARRAY_SIZE statement attribute specifies the number of rows in the
// rowset.
ODBCDescriptor* ard = statement->GetARD();
size_t rows = static_cast<size_t>(ard->GetArraySize());

if (statement->Fetch(rows)) {
return SQL_SUCCESS;
} else {
Expand Down
Loading