-
-
Notifications
You must be signed in to change notification settings - Fork 82
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
Conversation
There was a problem hiding this 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!
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 |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, makes sense! Done
There was a problem hiding this comment.
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.
func testMetadataParsing() { | ||
XCTAssertEqual(100, PostgresQueryMetadata(string: "SELECT 100")?.rows) | ||
XCTAssertEqual(0, PostgresQueryMetadata(string: "SELECT")?.rows) | ||
XCTAssertNil(PostgresQueryMetadata(string: "SELECT 100 100")) | ||
} |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome! Thanks!
Co-authored-by: Fabian Fett <[email protected]>
class PSQLMetadataTests: XCTestCase { | ||
func testSelect() { | ||
XCTAssertEqual(100, PostgresQueryMetadata(string: "SELECT 100")?.rows) | ||
XCTAssertEqual(0, PostgresQueryMetadata(string: "SELECT")?.rows) |
There was a problem hiding this comment.
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!
XCTAssertEqual(0, PostgresQueryMetadata(string: "SELECT")?.rows) | |
XCTAssertEqual(nil, PostgresQueryMetadata(string: "SELECT")?.rows) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tests fixed!
There was a problem hiding this 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
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