Skip to content

Support AWS redshift queries #167

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jul 28, 2021
Merged

Support AWS redshift queries #167

merged 5 commits into from
Jul 28, 2021

Conversation

grennis
Copy link
Contributor

@grennis grennis commented Jul 24, 2021

This changes the metadata parser to accept a response that is missing the rowcount, event though this does not follow the spec. In my testing this allows my to now successfully query Redshift databases.

Fixes #166

@fabianfett fabianfett requested review from fabianfett and 0xTim July 24, 2021 22:25
Copy link
Collaborator

@fabianfett fabianfett left a comment

Choose a reason for hiding this comment

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

🚀 Thanks very much, for taking care of this. Let’s get this into the right form and land this!

Comment on lines 77 to 85
case "DELETE", "UPDATE", "SELECT", "MOVE", "FETCH", "COPY":
// <cmd> rows
guard parts.count == 2 else {
// Note, Redshift does not return the actual count as per the spec
guard parts.count == 1 || parts.count == 2 else {
return nil
}
self.command = .init(parts[0])
self.oid = nil
self.rows = Int(parts[1])
self.rows = parts.count == 2 ? Int(parts[1]) : 0
Copy link
Collaborator

Choose a reason for hiding this comment

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

Would you mind refactoring out, the “SELECT” into its own case? Right now we would also support UPDATE and friends without row number as well.

case “SELECT” where parts.count == 1:
    // AWS Redshift does not return the actual row count as defined in the postgres wire spec:
    // https://www.postgresql.org/docs/13/protocol-message-formats.html in section `CommandComplete`
    self.command = .init(“SELECT”)
    self.oid = nil
    self.rows = nil
case “DELETE”, “UPDATE”, “SELECT”, “MOVE”, “FETCH”, “COPY”:
    // all the previous code

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, makes sense! Done

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I did do it different from your comment since I figured if the row count is present, we should parse it. But if that's not important (I really have no idea), I'm happy to just set rows to nil. Please let me know.

Comment on lines 19 to 23
func testMetadataParsing() {
XCTAssertEqual(100, PostgresQueryMetadata(string: "SELECT 100")?.rows)
XCTAssertEqual(0, PostgresQueryMetadata(string: "SELECT")?.rows)
XCTAssertNil(PostgresQueryMetadata(string: "SELECT 100 100"))
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Would you mind creating a new test file for this test:

PostgresNIOTests/PostgresQueryMetadataTests.swift

Since it isn’t really related to PSQLData.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed!

Copy link
Collaborator

Choose a reason for hiding this comment

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

Awesome! Thanks!

class PSQLMetadataTests: XCTestCase {
func testSelect() {
XCTAssertEqual(100, PostgresQueryMetadata(string: "SELECT 100")?.rows)
XCTAssertEqual(0, PostgresQueryMetadata(string: "SELECT")?.rows)
Copy link
Collaborator

Choose a reason for hiding this comment

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

uff, this tests needs fixing as well!

Suggested change
XCTAssertEqual(0, PostgresQueryMetadata(string: "SELECT")?.rows)
XCTAssertEqual(nil, PostgresQueryMetadata(string: "SELECT")?.rows)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Tests fixed!

Copy link
Member

@0xTim 0xTim left a comment

Choose a reason for hiding this comment

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

LGTM. It's a pity there's no Redshift CI available in GH actions so for now we'll have to trust manual testing

@fabianfett fabianfett merged commit 1d37934 into vapor:main Jul 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support for AWS Redshift database
3 participants