You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by ap...@apache.org on 2022/04/28 16:57:02 UTC
[arrow] branch master updated: MINOR: [C++] Fix building Flight tests
This is an automated email from the ASF dual-hosted git repository.
apitrou pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/arrow.git
The following commit(s) were added to refs/heads/master by this push:
new 306d0b4144 MINOR: [C++] Fix building Flight tests
306d0b4144 is described below
commit 306d0b4144527fb988da3b64ec74b53536d974f0
Author: Antoine Pitrou <an...@python.org>
AuthorDate: Thu Apr 28 18:56:53 2022 +0200
MINOR: [C++] Fix building Flight tests
Follow up to ARROW-16387, which enabled `-Wshorten-64-to-32` with CLang.
Closes #13025 from pitrou/flight-tests
Authored-by: Antoine Pitrou <an...@python.org>
Signed-off-by: Antoine Pitrou <an...@python.org>
---
.../flight/integration_tests/test_integration.cc | 8 +-
.../sql/example/sqlite_statement_batch_reader.cc | 100 +++++++++++----------
.../example/sqlite_tables_schema_batch_reader.cc | 2 +-
3 files changed, 58 insertions(+), 52 deletions(-)
diff --git a/cpp/src/arrow/flight/integration_tests/test_integration.cc b/cpp/src/arrow/flight/integration_tests/test_integration.cc
index 0ff6b4ad95..2e5609b6c0 100644
--- a/cpp/src/arrow/flight/integration_tests/test_integration.cc
+++ b/cpp/src/arrow/flight/integration_tests/test_integration.cc
@@ -358,10 +358,10 @@ class FlightSqlScenarioServer : public sql::FlightSqlServerBase {
arrow::Result<std::unique_ptr<FlightInfo>> GetFlightInfoSqlInfo(
const ServerCallContext& context, const sql::GetSqlInfo& command,
const FlightDescriptor& descriptor) override {
- ARROW_RETURN_NOT_OK(AssertEq<int>(2, command.info.size()));
- ARROW_RETURN_NOT_OK(AssertEq<int>(
+ ARROW_RETURN_NOT_OK(AssertEq<int64_t>(2, command.info.size()));
+ ARROW_RETURN_NOT_OK(AssertEq<int32_t>(
sql::SqlInfoOptions::SqlInfo::FLIGHT_SQL_SERVER_NAME, command.info[0]));
- ARROW_RETURN_NOT_OK(AssertEq<int>(
+ ARROW_RETURN_NOT_OK(AssertEq<int32_t>(
sql::SqlInfoOptions::SqlInfo::FLIGHT_SQL_SERVER_READ_ONLY, command.info[1]));
return GetFlightInfoForCommand(descriptor, sql::SqlSchema::GetSqlInfoSchema());
@@ -395,7 +395,7 @@ class FlightSqlScenarioServer : public sql::FlightSqlServerBase {
command.db_schema_filter_pattern.value()));
ARROW_RETURN_NOT_OK(AssertEq<std::string>("table_filter_pattern",
command.table_name_filter_pattern.value()));
- ARROW_RETURN_NOT_OK(AssertEq<int>(2, command.table_types.size()));
+ ARROW_RETURN_NOT_OK(AssertEq<int64_t>(2, command.table_types.size()));
ARROW_RETURN_NOT_OK(AssertEq<std::string>("table", command.table_types[0]));
ARROW_RETURN_NOT_OK(AssertEq<std::string>("view", command.table_types[1]));
ARROW_RETURN_NOT_OK(AssertEq<bool>(true, command.include_schema));
diff --git a/cpp/src/arrow/flight/sql/example/sqlite_statement_batch_reader.cc b/cpp/src/arrow/flight/sql/example/sqlite_statement_batch_reader.cc
index 08a03c4ca6..e31d6173ee 100644
--- a/cpp/src/arrow/flight/sql/example/sqlite_statement_batch_reader.cc
+++ b/cpp/src/arrow/flight/sql/example/sqlite_statement_batch_reader.cc
@@ -22,58 +22,57 @@
#include "arrow/builder.h"
#include "arrow/flight/sql/example/sqlite_statement.h"
-#define STRING_BUILDER_CASE(TYPE_CLASS, STMT, COLUMN) \
- case TYPE_CLASS##Type::type_id: { \
- int bytes = sqlite3_column_bytes(STMT, COLUMN); \
- const unsigned char* string = sqlite3_column_text(STMT, COLUMN); \
- if (string == nullptr) { \
- ARROW_RETURN_NOT_OK( \
- (reinterpret_cast<TYPE_CLASS##Builder&>(builder)).AppendNull()); \
- break; \
- } \
- ARROW_RETURN_NOT_OK( \
- (reinterpret_cast<TYPE_CLASS##Builder&>(builder)).Append(string, bytes)); \
- break; \
+#define STRING_BUILDER_CASE(TYPE_CLASS, STMT, COLUMN) \
+ case TYPE_CLASS##Type::type_id: { \
+ auto builder = reinterpret_cast<TYPE_CLASS##Builder*>(array_builder); \
+ const int bytes = sqlite3_column_bytes(STMT, COLUMN); \
+ const uint8_t* string = \
+ reinterpret_cast<const uint8_t*>(sqlite3_column_text(STMT, COLUMN)); \
+ if (string == nullptr) { \
+ ARROW_RETURN_NOT_OK(builder->AppendNull()); \
+ break; \
+ } \
+ ARROW_RETURN_NOT_OK(builder->Append(string, bytes)); \
+ break; \
}
-#define BINARY_BUILDER_CASE(TYPE_CLASS, STMT, COLUMN) \
- case TYPE_CLASS##Type::type_id: { \
- int bytes = sqlite3_column_bytes(STMT, COLUMN); \
- const void* blob = sqlite3_column_blob(STMT, COLUMN); \
- if (blob == nullptr) { \
- ARROW_RETURN_NOT_OK( \
- (reinterpret_cast<TYPE_CLASS##Builder&>(builder)).AppendNull()); \
- break; \
- } \
- ARROW_RETURN_NOT_OK( \
- (reinterpret_cast<TYPE_CLASS##Builder&>(builder)).Append((char*)blob, bytes)); \
- break; \
+#define BINARY_BUILDER_CASE(TYPE_CLASS, STMT, COLUMN) \
+ case TYPE_CLASS##Type::type_id: { \
+ auto builder = reinterpret_cast<TYPE_CLASS##Builder*>(array_builder); \
+ const int bytes = sqlite3_column_bytes(STMT, COLUMN); \
+ const uint8_t* blob = \
+ reinterpret_cast<const uint8_t*>(sqlite3_column_blob(STMT, COLUMN)); \
+ if (blob == nullptr) { \
+ ARROW_RETURN_NOT_OK(builder->AppendNull()); \
+ break; \
+ } \
+ ARROW_RETURN_NOT_OK(builder->Append(blob, bytes)); \
+ break; \
}
-#define INT_BUILDER_CASE(TYPE_CLASS, STMT, COLUMN) \
- case TYPE_CLASS##Type::type_id: { \
- if (sqlite3_column_type(stmt_, i) == SQLITE_NULL) { \
- ARROW_RETURN_NOT_OK( \
- (reinterpret_cast<TYPE_CLASS##Builder&>(builder)).AppendNull()); \
- break; \
- } \
- sqlite3_int64 value = sqlite3_column_int64(STMT, COLUMN); \
- ARROW_RETURN_NOT_OK( \
- (reinterpret_cast<TYPE_CLASS##Builder&>(builder)).Append(value)); \
- break; \
+#define INT_BUILDER_CASE(TYPE_CLASS, STMT, COLUMN) \
+ case TYPE_CLASS##Type::type_id: { \
+ using c_type = typename TYPE_CLASS##Type::c_type; \
+ auto builder = reinterpret_cast<TYPE_CLASS##Builder*>(array_builder); \
+ if (sqlite3_column_type(stmt_, i) == SQLITE_NULL) { \
+ ARROW_RETURN_NOT_OK(builder->AppendNull()); \
+ break; \
+ } \
+ const sqlite3_int64 value = sqlite3_column_int64(STMT, COLUMN); \
+ ARROW_RETURN_NOT_OK(builder->Append(static_cast<c_type>(value))); \
+ break; \
}
-#define FLOAT_BUILDER_CASE(TYPE_CLASS, STMT, COLUMN) \
- case TYPE_CLASS##Type::type_id: { \
- if (sqlite3_column_type(stmt_, i) == SQLITE_NULL) { \
- ARROW_RETURN_NOT_OK( \
- (reinterpret_cast<TYPE_CLASS##Builder&>(builder)).AppendNull()); \
- break; \
- } \
- double value = sqlite3_column_double(STMT, COLUMN); \
- ARROW_RETURN_NOT_OK( \
- (reinterpret_cast<TYPE_CLASS##Builder&>(builder)).Append(value)); \
- break; \
+#define FLOAT_BUILDER_CASE(TYPE_CLASS, STMT, COLUMN) \
+ case TYPE_CLASS##Type::type_id: { \
+ auto builder = reinterpret_cast<TYPE_CLASS##Builder*>(array_builder); \
+ if (sqlite3_column_type(stmt_, i) == SQLITE_NULL) { \
+ ARROW_RETURN_NOT_OK(builder->AppendNull()); \
+ break; \
+ } \
+ const double value = sqlite3_column_double(STMT, COLUMN); \
+ ARROW_RETURN_NOT_OK(builder->Append(value)); \
+ break; \
}
namespace arrow {
@@ -139,12 +138,14 @@ Status SqliteStatementBatchReader::ReadNext(std::shared_ptr<RecordBatch>* out) {
for (int i = 0; i < num_fields; i++) {
const std::shared_ptr<Field>& field = schema_->field(i);
const std::shared_ptr<DataType>& field_type = field->type();
- ArrayBuilder& builder = *builders[i];
+ ArrayBuilder* array_builder = builders[i].get();
// NOTE: This is not the optimal way of building Arrow vectors.
// That would be to presize the builders to avoiding several resizing operations
// when appending values and also to build one vector at a time.
switch (field_type->id()) {
+ // XXX This doesn't handle overflows when converting to the target
+ // integer type.
INT_BUILDER_CASE(Int64, stmt_, i)
INT_BUILDER_CASE(UInt64, stmt_, i)
INT_BUILDER_CASE(Int32, stmt_, i)
@@ -183,6 +184,11 @@ Status SqliteStatementBatchReader::ReadNext(std::shared_ptr<RecordBatch>* out) {
return Status::OK();
}
+#undef STRING_BUILDER_CASE
+#undef BINARY_BUILDER_CASE
+#undef INT_BUILDER_CASE
+#undef FLOAT_BUILDER_CASE
+
} // namespace example
} // namespace sql
} // namespace flight
diff --git a/cpp/src/arrow/flight/sql/example/sqlite_tables_schema_batch_reader.cc b/cpp/src/arrow/flight/sql/example/sqlite_tables_schema_batch_reader.cc
index f562325db0..68bde35c71 100644
--- a/cpp/src/arrow/flight/sql/example/sqlite_tables_schema_batch_reader.cc
+++ b/cpp/src/arrow/flight/sql/example/sqlite_tables_schema_batch_reader.cc
@@ -93,7 +93,7 @@ Status SqliteTablesWithSchemaBatchReader::ReadNext(std::shared_ptr<RecordBatch>*
column_fields.clear();
ARROW_RETURN_NOT_OK(
- schema_builder.Append(schema_buffer->data(), schema_buffer->size()));
+ schema_builder.Append(::arrow::util::string_view(*schema_buffer)));
}
std::shared_ptr<Array> schema_array;