lidavidm commented on code in PR #14082:
URL: https://github.com/apache/arrow/pull/14082#discussion_r1049005281


##########
cpp/src/arrow/flight/sql/adbc_driver_internal.h:
##########
@@ -0,0 +1,198 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+#pragma once
+
+#include <cstdint>
+#include <cstring>
+#include <memory>
+#include <optional>
+#include <string>
+#include <string_view>
+
+#include "arrow/array/array_binary.h"
+#include "arrow/flight/client.h"
+#include "arrow/flight/client_tracing_middleware.h"
+#include "arrow/flight/sql/server.h"
+#include "arrow/flight/sql/visibility.h"
+#include "arrow/record_batch.h"
+#include "arrow/status.h"
+#include "arrow/table.h"
+#include "arrow/type.h"
+#include "arrow/type_traits.h"
+#include "arrow/util/checked_cast.h"
+#include "arrow/util/macros.h"
+#include "arrow/util/string_builder.h"
+
+// Override the built-in visibility defines with Arrow's
+#define ADBC_EXPORT ARROW_FLIGHT_SQL_EXPORT
+#include "arrow/c/adbc_internal.h"  // IWYU pragma: export
+
+namespace arrow::flight::sql {
+
+// Internal utilities for the Flight SQL driver.
+
+#define ADBC_RETURN_NOT_OK(EXPR)         \
+  do {                                   \
+    auto _s = (EXPR);                    \
+    if (_s != ADBC_STATUS_OK) return _s; \
+  } while (false)
+
+#ifdef ARROW_EXTRA_ERROR_CONTEXT
+#define ADBC_ARROW_RETURN_NOT_OK(ERROR, EXPR)                       \
+  do {                                                              \
+    if (Status _s = (EXPR); !_s.ok()) {                             \
+      _s.AddContextLine(__FILE__, __LINE__, ARROW_STRINGIFY(EXPR)); \
+      SetError(error, _s);                                          \
+      return ::arrow::flight::sql::ArrowToAdbcStatusCode(_s);       \
+    }                                                               \
+  } while (false)
+#else
+#define ADBC_ARROW_RETURN_NOT_OK(ERROR, EXPR)                 \
+  do {                                                        \
+    if (Status _s = (EXPR); !_s.ok()) {                       \
+      SetError(error, _s);                                    \
+      return ::arrow::flight::sql::ArrowToAdbcStatusCode(_s); \
+    }                                                         \
+  } while (false)
+#endif
+
+ARROW_FLIGHT_SQL_EXPORT
+AdbcStatusCode ArrowToAdbcStatusCode(const Status& status);
+ARROW_FLIGHT_SQL_EXPORT
+void ReleaseError(struct AdbcError* error);
+ARROW_FLIGHT_SQL_EXPORT
+FlightClientOptions DefaultClientOptions();
+
+/// Helper to populate an AdbcError
+template <typename... Args>
+void SetError(struct AdbcError* error, Args&&... args) {
+  if (!error) return;
+  std::string message = util::StringBuilder("[Flight SQL] ", 
std::forward<Args>(args)...);
+  if (error->message) {
+    message.reserve(message.size() + 1 + std::strlen(error->message));
+    message.append(1, '\n');
+    message.append(error->message);
+    delete[] error->message;
+  }
+  error->message = new char[message.size() + 1];
+  message.copy(error->message, message.size());
+  error->message[message.size()] = '\0';
+  error->release = ReleaseError;
+}
+
+template <typename ArrowType,
+          typename ArrayType = typename TypeTraits<ArrowType>::ArrayType>
+auto GetNotNull(const RecordBatch& batch, int col_index, int64_t row_index) {
+  return arrow::internal::checked_cast<const 
ArrayType&>(*batch.column(col_index))
+      .GetView(row_index);
+}
+
+template <typename ArrowType,
+          typename ArrayType = typename TypeTraits<ArrowType>::ArrayType>
+std::optional<std::invoke_result_t<decltype(&ArrayType::GetView), ArrayType, 
int64_t>>

Review Comment:
   The compiler didn't deduce it in the other case. (It got confused between 
nullopt_t and the concrete type.)



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to