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

SQLite doesn't work with an existing persistent database file (it works only using an in-memory DB) #280

Closed
anna-geller opened this issue Apr 16, 2024 · 1 comment
Labels
bug Something isn't working
Milestone

Comments

@anna-geller
Copy link
Member

Expected Behavior

The following flow:

id: business_automations
namespace: tutorial

tasks:
  - id: get0
    type: io.kestra.plugin.fs.http.Download
    disabled: true
    uri: https://github.com/lerocha/chinook-database/blob/master/ChinookDatabase/DataSources/Chinook_Sqlite.sqlite

  - id: wdir
    type: io.kestra.core.tasks.flows.WorkingDirectory
    tasks:
      - id: get
        type: io.kestra.plugin.scripts.shell.Commands
        outputFiles:
          - "*.sqlite"
        taskRunner:
          type: io.kestra.core.models.tasks.runners.types.ProcessTaskRunner
        commands:
          - curl -L -o Chinook_Sqlite.sqlite https://github.com/lerocha/chinook-database/raw/master/ChinookDatabase/DataSources/Chinook_Sqlite.sqlite
      - id: db
        type: io.kestra.core.tasks.storages.LocalFiles
        inputs:
          Chinook_Sqlite.sqlite: "{{ outputs.get.outputFiles['Chinook_Sqlite.sqlite'] }}"

      - id: analyze_media_store
        type: io.kestra.plugin.jdbc.sqlite.Query
        description: Find the total number of tracks purchased in each genre
        url: jdbc:sqlite:Chinook_Sqlite.sqlite
        sql: |
          SELECT Genre.Name, COUNT(InvoiceLine.InvoiceLineId) AS TracksPurchased
          FROM Genre
          JOIN Track ON Genre.GenreId = Track.GenreId
          JOIN InvoiceLine ON Track.TrackId = InvoiceLine.TrackId
          GROUP BY Genre.Name
          ORDER BY TracksPurchased DESC;

you'll see an error that the DB or DB table is not found

I tried the same with the database file passed as input:

id: business_automations_v2
namespace: tutorial
inputs:
  - id: mydb
    type: FILE

tasks:
  - id: wdir
    type: io.kestra.core.tasks.flows.WorkingDirectory
    tasks:
      - id: db
        type: io.kestra.core.tasks.storages.LocalFiles
        inputs:
          Chinook_Sqlite.sqlite: "{{ inputs.mydb }}"

      - id: analyze_media_store
        type: io.kestra.plugin.jdbc.sqlite.Query
        description: Find the total number of tracks purchased in each genre
        url: jdbc:sqlite:Chinook_Sqlite.sqlite
        sql: |
          SELECT Genre.Name, COUNT(InvoiceLine.InvoiceLineId) AS TracksPurchased
          FROM Genre
          JOIN Track ON Genre.GenreId = Track.GenreId
          JOIN InvoiceLine ON Track.TrackId = InvoiceLine.TrackId
          GROUP BY Genre.Name
          ORDER BY TracksPurchased DESC;

To see that the actual DB is working, the same works perfectly fine in a Python script:

id: business_automations_python
namespace: tutorial

tasks:
  - id: py
    type: io.kestra.plugin.scripts.python.Script
    taskRunner:
      type: io.kestra.core.models.tasks.runners.types.ProcessTaskRunner
    beforeCommands:
      - pip install requests
    script: |
      import requests
      import sqlite3

      def download_file(url, filename):
          response = requests.get(url)
          response.raise_for_status()  
          
          with open(filename, 'wb') as f:
              f.write(response.content)

      url = "https://github.com/lerocha/chinook-database/raw/master/ChinookDatabase/DataSources/Chinook_Sqlite.sqlite"
      filename = "Chinook_Sqlite.sqlite"

      download_file(url, filename)
      print("Download completed successfully!")

      connection = sqlite3.connect('Chinook_Sqlite.sqlite')
      cursor = connection.cursor()
      cursor.execute("SELECT * FROM Artist")
      artists = cursor.fetchall()
      for artist in artists:
          print(artist)

      connection.commit()
      connection.close()

Actual Behaviour

No response

Steps To Reproduce

No response

Environment Information

  • Kestra Version: 0.17

Example flow

No response

@anna-geller anna-geller added the bug Something isn't working label Apr 16, 2024
@anna-geller anna-geller changed the title SQLite doesn't work with an existing persistent database files (works only using in-memory DB) SQLite doesn't work with an existing persistent database file (it works only using an in-memory DB) Apr 16, 2024
@anna-geller anna-geller added this to the v0.17.0 milestone Apr 16, 2024
iNikitaGricenko added a commit to iNikitaGricenko/plugin-jdbc that referenced this issue Apr 24, 2024
loicmathieu pushed a commit that referenced this issue May 17, 2024
…292)

* #280 SQLite connect to database from kestra storage

* Check if file exists in workingDirectory

* Added example with using existing sqliteFile. Changed path resolver. Changed check for file existence
@loicmathieu
Copy link
Member

Fixed by #292

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants