WillAyd commented on code in PR #2219:
URL: https://github.com/apache/arrow-adbc/pull/2219#discussion_r1822727118
##########
c/driver/postgresql/database.cc:
##########
@@ -123,19 +136,88 @@ AdbcStatusCode PostgresDatabase::Disconnect(PGconn**
conn, struct AdbcError* err
return ADBC_STATUS_OK;
}
+namespace {
+
+// Parse an individual version in the form of "xxx.xxx.xxx".
+// If the version components aren't numeric, they will be zero.
+std::array<int, 3> ParseVersion(std::string_view version) {
+ std::array<int, 3> out{};
+ size_t component = 0;
+ size_t component_begin = 0;
+ size_t component_end = 0;
+
+ // While there are remaining version components and we haven't reached the
end of the
+ // string
+ while (component_begin < version.size() && component < out.size()) {
Review Comment:
Maybe a good use case for str::find here?
##########
c/driver/postgresql/connection.cc:
##########
@@ -478,19 +478,35 @@ AdbcStatusCode PostgresConnection::GetInfo(struct
AdbcConnection* connection,
for (size_t i = 0; i < info_codes_length; i++) {
switch (info_codes[i]) {
case ADBC_INFO_VENDOR_NAME:
- infos.push_back({info_codes[i], "PostgreSQL"});
+ if (RedshiftVersion()[0] > 0) {
+ infos.push_back({info_codes[i], "Redshift"});
Review Comment:
```suggestion
infos.emplace_back(info_codes[i], "Redshift");
```
Not sure how much we care about copies here but I think emplace_back would
be a better standard
##########
c/driver/postgresql/connection.cc:
##########
@@ -478,19 +478,35 @@ AdbcStatusCode PostgresConnection::GetInfo(struct
AdbcConnection* connection,
for (size_t i = 0; i < info_codes_length; i++) {
switch (info_codes[i]) {
case ADBC_INFO_VENDOR_NAME:
- infos.push_back({info_codes[i], "PostgreSQL"});
+ if (RedshiftVersion()[0] > 0) {
+ infos.push_back({info_codes[i], "Redshift"});
+ } else {
+ infos.push_back({info_codes[i], "PostgreSQL"});
+ }
+
break;
case ADBC_INFO_VENDOR_VERSION: {
- const char* stmt = "SHOW server_version_num";
- auto result_helper = PqResultHelper{conn_, std::string(stmt)};
- RAISE_STATUS(error, result_helper.Execute());
- auto it = result_helper.begin();
- if (it == result_helper.end()) {
- SetError(error, "[libpq] PostgreSQL returned no rows for '%s'",
stmt);
- return ADBC_STATUS_INTERNAL;
+ if (RedshiftVersion()[0] > 0) {
+ std::array<int, 3> version = RedshiftVersion();
+ std::string version_string = std::to_string(version[0]) + "." +
+ std::to_string(version[1]) + "." +
+ std::to_string(version[2]);
+ infos.push_back({info_codes[i], version_string});
Review Comment:
```suggestion
infos.emplace_back(info_codes[i], std::move(version_string));
```
I don't think C++ knows to move before this goes out of scope
--
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]