Skip to content
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

test: integration tests for duckdb #178

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

phdah
Copy link
Contributor

@phdah phdah commented Feb 5, 2025

Description

This follows the style and structure of both the postgres and bigquery integration tests.


What's left?

Edit: There seems to be some issue with the adapter. Will investigate it. Resolved by commit 98bac14ceda3:

Add Archived state in GetResult to not run async

This is a fix provided by @MattiasMTS in:
http://github.com/kndndrj/nvim-dbee/pull/177/files#diff-5234895d59f82777fe5b7e9e89ec74f054246a480b63d168a00142551ef6c6bcR48
  • Seems to be a race condition for creating the table returning empty result of the GetResult() function.
  • The GetStructure() returns empty. Not sure if this is expected or not.
    • Resolved by adding more depth to the driver's structure.
  • Want to look into if/how we can switch databases (catalog in DuckDB).
    • Resolved by adding the current database to show, but not allowing switching

Status

    --- PASS: TestDuckDBTestSuite/TestListOnlyOneDatabase (0.00s)
    --- PASS: TestDuckDBTestSuite/TestShouldCancelQuery (0.10s)
    --- PASS: TestDuckDBTestSuite/TestShouldFailInvalidQuery (0.00s)
    --- PASS: TestDuckDBTestSuite/TestShouldReturnColumns (0.00s)
    --- PASS: TestDuckDBTestSuite/TestShouldReturnManyRows (0.10s)
    --- PASS: TestDuckDBTestSuite/TestShouldReturnOneRows (0.11s)
    --- PASS: TestDuckDBTestSuite/TestShouldReturnStructure (0.03s)

Fixes

Added schema to DuckDB driver:
Screenshot 2025-02-05 at 11 30 55
Added catalog
Screenshot 2025-02-14 at 12 01 02

@phdah phdah changed the title Add integration tests for duckdb test: integration tests for duckdb Feb 5, 2025
@phdah phdah changed the title test: integration tests for duckdb test: integration tests for duckdb Feb 5, 2025
@phdah phdah force-pushed the phdah/integration-tests-duckdb branch 2 times, most recently from 900bfc8 to 58e11b9 Compare February 5, 2025 10:34
@phdah phdah force-pushed the phdah/integration-tests-duckdb branch from 58e11b9 to 97e47c4 Compare February 13, 2025 10:31
@phdah phdah marked this pull request as ready for review February 13, 2025 12:50
@phdah phdah force-pushed the phdah/integration-tests-duckdb branch from 97e47c4 to a29b1dc Compare February 14, 2025 09:39
@phdah
Copy link
Contributor Author

phdah commented Feb 14, 2025

There might be some overlap with this PR: #77

Copy link
Collaborator

@MattiasMTS MattiasMTS left a comment

Choose a reason for hiding this comment

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

nice work! ✨ left some few comments suggestions. Love some tests! 🧪

}

// SetupSuite initializes an in-memory DuckDB instance.
func (suite *DuckDBTestSuite) SetupSuite() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

wdyt about moving some of the ddl stuff to the NewDuckDBContainer construct, similar to e.g. what we did in #177 ?

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, would you suggest to also use a ddl seeds file for this, or just the initialization of it should go in New*Container methods?

Copy link
Collaborator

Choose a reason for hiding this comment

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

let's make any sql statements part of a seed file for easier scalability 😄 IMHO makes it easier to read what is happening in terms of 'logic' 😄

Copy link
Collaborator

Choose a reason for hiding this comment

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

so, you make a seed file for the sql file, then bootstrap that file as part of the NewDuckDBContainer construct :)

// NOTE: (phdah) As of now, swapping catalogs is not enabled
func (c *duckDriver) SelectDatabase(name string) error {
// no-op
return nil
Copy link
Collaborator

Choose a reason for hiding this comment

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

let's return an error here of fmt.Errorf("SelectDabase method not implemented yet") or something similar. Otherwise, it might be easy to confuse the user that there is a no-op even tho I am selecting a new database 'succesfully'. wdyt? 😄

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sounds good, let me try it out and see 😃

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So returning the error is kinda obstructing. Since the ListDatabases() only return the database you initially connected to, you can't really change anyway right now. I would suggest to keep the no-op. Thoughts?

Copy link
Collaborator

Choose a reason for hiding this comment

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

aha, ok gotcha!
Hmm I am tempted to say we should wait implementing these methods in a separate PR, then to actually implement them with no-op. Given, we don't want to confuse a user with feature of seeing databases but they aren't seeing what they 'expect'. Then it make sense to show nothing at all (because the feature doesn't exist) 😄

Do you think we'll make a PR adding this before the v0.2.0 release? 😋 if so, we can add this code and update it accordingly

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So after not to much looking in to this, one can attach to new/more databases. Then you can run use other_db and swap between them. But I would say that this is not really how one typically use DuckDB. But I liked the visual "feedback" of seeing what database I was attached to. But if it's possible to disable the select action only, that would maybe be a hybrid solution?

Regardless, I think you're right that this can be it's own PR after v0.2.0 😃 So, lets do that!

}

// NewDuckDBContainer creates a new in-memory DuckDB instance.
func NewDuckDBContainer(params *core.ConnectionParams) (*DuckDBContainer, error) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

perhaps a bit overengineered but you could make use of the generic testcontainer and boot up duckdb in that see (https://golang.testcontainers.org/features/creating_container/#genericcontainer). Might be useful in the future to remove any remaining local duckdb files or so.

Just adding a comment for idea sharing, no need to move away from the code there is now 😄

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, and good point. Not sure if/how duckdb stores in memory databases, but would assume they clean up after themselvs somehow. But in the future when we want to try connecting to persistent databases, perhaps this would be great!

This follows the style and structure of both the postgres and bigquery
integration tests.
This is currently just to make the UI show what catalog you start your
connection to. So no swapping is enabled. I did play around with `use
my_catalog` etc, in the `SelectDatabase()` function, but didn't get it
to properly work due to how the `Swap()` function works.
This actually showed issues with the helper function, so great!
@phdah phdah force-pushed the phdah/integration-tests-duckdb branch from 5b6f1f8 to 563a215 Compare February 14, 2025 16:52
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.

2 participants