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

When no DB used we get: Code: 57. DB::Exception: Directory for table data data/default/testtable/ already exists. (TABLE_ALREADY_EXISTS) #18

Open
ceckoslab opened this issue Aug 31, 2024 · 3 comments

Comments

@ceckoslab
Copy link

I noticed that in the following conditions I get when I run the example script for second time:

Code: 57. DB::Exception: Directory for table data data/default/testtable/ already exists. (TABLE_ALREADY_EXISTS)

Repro:

const { query, Session } = require("chdb");

var ret;

// Test standalone query
ret = query("SELECT version(), 'Hello chDB', chdb()", "CSV");
console.log("Standalone Query Result:", ret);

// Test session query
// Create a new session instance
const session = new Session("./dir_for_table_already_exists");

session.query("CREATE TABLE IF NOT EXISTS testtable (id UInt32) ENGINE = MergeTree() ORDER BY id;");

I usually create a new DB and use the new DB but not everyone would be doing the same and could reach the same problem.

System info:

Apple M2 Pro
macOS 14.5 (23F79)
Node v20.9.0

  "dependencies": {
    "chdb": "^1.2.1"
  },
@auxten
Copy link
Member

auxten commented Sep 3, 2024

This is because new Session("./dir_for_table_already_exists") create session in the same dir.
After create the new table testtable you didn't call session.cleanup().
So, the second time you use the same dir as the session dir. testtable already exists.

You can also avoid this by new Session() which will create the session in random tmp dir.

@ceckoslab
Copy link
Author

I see @auxten

My intention is to have the inserted created tables & data available between sessions but I think that session.cleanup() will wipe out all the data:

  // Cleanup method to delete the temporary directory
  cleanup() {
    rmSync(this.path, { recursive: true }); // Replaced rmdirSync with rmSync
  }

I suppose that my use case is a bit different ... probably the usual CHDB user often starts CHDB, queries directly some data structure (CSV, JSON ...) or inserts data in CHDB that is not required when a new session get's started.

@auxten
Copy link
Member

auxten commented Sep 4, 2024

Thanks, I understand. Currently, chDB session implementation is a little tricky.
Like I explained here: https://github.com/orgs/chdb-io/discussions/196#discussioncomment-8406116
Here is the plan: chdb-io/chdb#197 (comment)

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

No branches or pull requests

2 participants