alinaliBQ commented on code in PR #40939: URL: https://github.com/apache/arrow/pull/40939#discussion_r2380390763
########## cpp/src/arrow/flight/sql/odbc/flight_sql/utils.h: ########## @@ -0,0 +1,124 @@ +// 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 <arrow/flight/sql/odbc/odbcabstraction/include/odbcabstraction/exceptions.h> +#include <arrow/flight/sql/odbc/odbcabstraction/include/odbcabstraction/types.h> +#include <arrow/flight/types.h> +#include <boost/xpressive/xpressive.hpp> +#include <codecvt> +#include <functional> +#include <optional> + +namespace driver { +namespace flight_sql { + +typedef std::function<std::shared_ptr<arrow::Array>(const std::shared_ptr<arrow::Array>&)> + ArrayConvertTask; + +using std::optional; + +inline void ThrowIfNotOK(const arrow::Status& status) { + if (!status.ok()) { + throw odbcabstraction::DriverException(status.message()); + } +} + +template <typename T, typename AttributeTypeT> +inline bool CheckIfSetToOnlyValidValue(const AttributeTypeT& value, T allowed_value) { + return boost::get<T>(value) == allowed_value; +} + +template <typename BUILDER, typename T> +arrow::Status AppendToBuilder(BUILDER& builder, optional<T> opt_value) { + if (opt_value) { + return builder.Append(*opt_value); + } else { + return builder.AppendNull(); + } +} + +template <typename BUILDER, typename T> +arrow::Status AppendToBuilder(BUILDER& builder, T value) { + return builder.Append(value); +} + +odbcabstraction::SqlDataType GetDataTypeFromArrowField_V3( + const std::shared_ptr<arrow::Field>& field, bool useWideChar); + +odbcabstraction::SqlDataType EnsureRightSqlCharType( + odbcabstraction::SqlDataType data_type, bool useWideChar); + +int16_t ConvertSqlDataTypeFromV3ToV2(int16_t data_type_v3); Review Comment: The function is not using an enum because imo enums aren't necessary in this case. The ODBC data type returned here serves as a return output value (to the BI tools etc) only, not for working with other parts of the driver. The ODBC data type values are fixed macros defined inside the system ODBC library (e.g., `sqlext.h`): https://github.com/microsoft/ODBCTest/blob/0d629c7e4ff7b01398a5ac71d20c43362d0f43bf/ODBC%204.0/inc/sqlext.h#L463-L464 -- 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]
