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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Seems reasonable but is there maybe a way to do this with string_view instead of copying the string?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I suppose it's not likely to matter

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

A string copy is still necessary for the sake of trimming the string.

Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,21 @@
#include "arrow/flight/sql/odbc/odbc_impl/record_batch_transformer.h"
#include "arrow/flight/sql/odbc/odbc_impl/util.h"
#include "arrow/flight/types.h"
#include "arrow/util/string.h"

namespace arrow::flight::sql::odbc {

using arrow::Result;

static void AddTableType(std::string& table_type, std::vector<std::string>& table_types) {
std::string trimmed_type = arrow::internal::TrimString(table_type);

// Only put the string if the trimmed result is non-empty
if (!trimmed_type.empty()) {
table_types.emplace_back(std::move(trimmed_type));
}
}

void ParseTableTypes(const std::string& table_type,
std::vector<std::string>& table_types) {
bool encountered = false; // for checking if there is a single quote
Expand All @@ -36,36 +46,23 @@ void ParseTableTypes(const std::string& table_type,
for (char temp : table_type) { // while still in the string
switch (temp) { // switch depending on the character
case '\'': // if the character is a single quote
if (encountered) {
encountered = false; // if we already found a single quote, reset encountered
} else {
encountered =
true; // if we haven't found a single quote, set encountered to true
}
// track when we've encountered a single opening quote
// and are still looking for the closing quote
encountered = !encountered;
break;
case ',': // if it is a comma
if (!encountered) { // if we have not found a single quote
table_types.push_back(curr_parse); // put our current string into our vector
curr_parse = ""; // reset the current string
case ',': // if it is a comma
if (!encountered) { // if we have not found a single quote
AddTableType(curr_parse, table_types); // put current string into vector
curr_parse = ""; // reset the current string
break;
}
default: // if it is a normal character
if (encountered && isspace(temp)) {
curr_parse.push_back(temp); // if we have found a single quote put the
// whitespace, we don't care
} else if (temp == '\'' || temp == ' ') {
break; // if the current character is a single quote, trash it and go to
// the next character.
} else {
curr_parse.push_back(temp); // if all of the above failed, put the
// character into the current string
}
break; // go to the next character
[[fallthrough]];
default: // if it is a normal character
curr_parse.push_back(temp); // put the character into the current string
break; // go to the next character
}
}
table_types.emplace_back(
curr_parse); // if we have found a single quote put the whitespace,
// we don't care
AddTableType(curr_parse, table_types);
}

std::shared_ptr<ResultSet> GetTablesForSQLAllCatalogs(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,17 @@ TEST(TableTypeParser, ParsingWithSingleQuotesWithoutLeadingWhiteSpace) {
TEST(TableTypeParser, ParsingWithCommaInsideSingleQuotes) {
AssertParseTest("'TABLE, TEST', 'VIEW, TEMPORARY'", {"TABLE, TEST", "VIEW, TEMPORARY"});
}

TEST(TableTypeParser, ParsingWithManyLeadingAndTrailingWhiteSpaces) {
AssertParseTest(" TABLE , VIEW ", {"TABLE", "VIEW"});
}

TEST(TableTypeParser, ParsingWithOnlyWhiteSpaceBetweenCommas) {
AssertParseTest("TABLE, ,VIEW", {"TABLE", "VIEW"});
}

TEST(TableTypeParser, ParsingWithWhiteSpaceInsideValue) {
AssertParseTest("BASE TABLE", {"BASE TABLE"});
}

} // namespace arrow::flight::sql::odbc
Loading