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
36 changes: 22 additions & 14 deletions cpp/src/arrow/flight/sql/example/sqlite_server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@

#include "arrow/flight/sql/example/sqlite_server.h"

#define BOOST_NO_CXX98_FUNCTION_BASE // ARROW-17805
#include <boost/algorithm/string.hpp>
#include <mutex>
#include <random>
#include <sstream>
Expand All @@ -37,6 +35,7 @@
#include "arrow/scalar.h"
#include "arrow/util/checked_cast.h"
#include "arrow/util/logging.h"
#include "arrow/util/string.h"

namespace arrow {
namespace flight {
Expand All @@ -47,6 +46,11 @@ using arrow::internal::checked_cast;

namespace {

bool AsciiStartsWithCaseInsensitive(std::string_view value, std::string_view prefix) {
return value.size() >= prefix.size() && arrow::internal::AsciiEqualsCaseInsensitive(
value.substr(0, prefix.size()), prefix);
}

std::string PrepareQueryForGetTables(const GetTables& command) {
std::stringstream table_query;

Expand Down Expand Up @@ -174,15 +178,17 @@ arrow::Result<std::shared_ptr<DataType>> GetArrowType(const char* sqlite_type) {
return null();
}

if (boost::iequals(sqlite_type, "int") || boost::iequals(sqlite_type, "integer")) {
if (arrow::internal::AsciiEqualsCaseInsensitive(sqlite_type, "int") ||
arrow::internal::AsciiEqualsCaseInsensitive(sqlite_type, "integer")) {
return int64();
} else if (boost::iequals(sqlite_type, "REAL")) {
} else if (arrow::internal::AsciiEqualsCaseInsensitive(sqlite_type, "REAL")) {
return float64();
} else if (boost::iequals(sqlite_type, "BLOB")) {
} else if (arrow::internal::AsciiEqualsCaseInsensitive(sqlite_type, "BLOB")) {
return binary();
} else if (boost::iequals(sqlite_type, "TEXT") || boost::iequals(sqlite_type, "DATE") ||
boost::istarts_with(sqlite_type, "char") ||
boost::istarts_with(sqlite_type, "varchar")) {
} else if (arrow::internal::AsciiEqualsCaseInsensitive(sqlite_type, "TEXT") ||
arrow::internal::AsciiEqualsCaseInsensitive(sqlite_type, "DATE") ||
AsciiStartsWithCaseInsensitive(sqlite_type, "char") ||
AsciiStartsWithCaseInsensitive(sqlite_type, "varchar")) {
return utf8();
}
return Status::Invalid("Invalid SQLite type: ", sqlite_type);
Expand All @@ -194,15 +200,17 @@ int32_t GetSqlTypeFromTypeName(const char* sqlite_type) {
return SQLITE_NULL;
}

if (boost::iequals(sqlite_type, "int") || boost::iequals(sqlite_type, "integer")) {
if (arrow::internal::AsciiEqualsCaseInsensitive(sqlite_type, "int") ||
arrow::internal::AsciiEqualsCaseInsensitive(sqlite_type, "integer")) {
return SQLITE_INTEGER;
} else if (boost::iequals(sqlite_type, "REAL")) {
} else if (arrow::internal::AsciiEqualsCaseInsensitive(sqlite_type, "REAL")) {
return SQLITE_FLOAT;
} else if (boost::iequals(sqlite_type, "BLOB")) {
} else if (arrow::internal::AsciiEqualsCaseInsensitive(sqlite_type, "BLOB")) {
return SQLITE_BLOB;
} else if (boost::iequals(sqlite_type, "TEXT") || boost::iequals(sqlite_type, "DATE") ||
boost::istarts_with(sqlite_type, "char") ||
boost::istarts_with(sqlite_type, "varchar")) {
} else if (arrow::internal::AsciiEqualsCaseInsensitive(sqlite_type, "TEXT") ||
arrow::internal::AsciiEqualsCaseInsensitive(sqlite_type, "DATE") ||
AsciiStartsWithCaseInsensitive(sqlite_type, "char") ||
AsciiStartsWithCaseInsensitive(sqlite_type, "varchar")) {
return SQLITE_TEXT;
} else {
return SQLITE_NULL;
Expand Down
14 changes: 11 additions & 3 deletions cpp/src/arrow/flight/sql/test_app_cli.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
#include "arrow/util/config.h"

#include <gflags/gflags.h>
#define BOOST_NO_CXX98_FUNCTION_BASE // ARROW-17805
#include <boost/algorithm/string.hpp>
#include <iostream>
#include <memory>
#include <optional>
Expand All @@ -33,6 +31,7 @@
#include "arrow/pretty_print.h"
#include "arrow/status.h"
#include "arrow/table.h"
#include "arrow/util/string.h"

#ifdef ARROW_WITH_OPENTELEMETRY
# include "arrow/flight/otel_logging.h"
Expand Down Expand Up @@ -75,6 +74,15 @@ DEFINE_string(catalog, "", "Catalog");
DEFINE_string(schema, "", "Schema");
DEFINE_string(table, "", "Table");

namespace {

bool AsciiStartsWithCaseInsensitive(std::string_view value, std::string_view prefix) {
return value.size() >= prefix.size() && arrow::internal::AsciiEqualsCaseInsensitive(
value.substr(0, prefix.size()), prefix);
}

} // namespace

#ifdef ARROW_WITH_OPENTELEMETRY
class OtelScope {
public:
Expand Down Expand Up @@ -234,7 +242,7 @@ Status RunMain() {
}

if (info != NULLPTR &&
!boost::istarts_with(FLAGS_command, "PreparedStatementExecute")) {
!AsciiStartsWithCaseInsensitive(FLAGS_command, "PreparedStatementExecute")) {
return PrintResults(sql_client, call_options, info);
}

Expand Down
Loading