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

Refactor/2479/simplify databackend contract #2710

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

blythed
Copy link
Collaborator

@blythed blythed commented Jan 2, 2025

Description

  • Only 1 type of query superduper.backends.base.query.Query
  • Implementations based on superduper_<impl>.Databackend
  • Simplifications to query API:
    • t.insert(...) instead of t.insert().execute() since we don't need to serialize insertions
    • t.update, t.delete deprecated
    • read queries have a simpler form t.filter(...).select(...).outputs(...), or t.like().(...) or t.(...).like()
    • t.get() to get one data point (eager)
    • t.ids() to get the ids (eager)
    • t.subset(ids) to subset a query
    • t.limit(n, offset=m) to get a chunk of data
  • .execute() no longer returns a cursor, instead a simple list
  • Remove the error prone t.column == x, replace with t['column'] == x
  • Simpler serialization of "complex items" with q.dict()['documents']

@blythed blythed requested a review from jieguangzhou January 14, 2025 20:52
@blythed
Copy link
Collaborator Author

blythed commented Jan 14, 2025

Still to do:

  • Solution for "raw queries"

@blythed blythed force-pushed the refactor/2479/simplify-databackend-contract branch 3 times, most recently from 9b12350 to 28e92a0 Compare January 15, 2025 09:44
@blythed
Copy link
Collaborator Author

blythed commented Jan 15, 2025

Still to do:

  • Solution for "raw queries"

Resolved

plugins/ibis/superduper_ibis/data_backend.py Show resolved Hide resolved
return query.limit(1).execute()[0]

def _wrap_results(self, query: Query, result, schema):
pid = self.primary_id(query)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Errors will occur for tables not created by SuperDuper. For example, tables that already exist in database cannot have their schema and primary_id retrieved.

Copy link
Collaborator Author

@blythed blythed Jan 17, 2025

Choose a reason for hiding this comment

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

Let me check.

Copy link
Collaborator

Choose a reason for hiding this comment

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

  1. Insert data into a table using a non-superduper method (such as ibis, SQL queries, etc.)
  2. Query the data from this table using superduper.

An error should occur.

superduper/components/table.py Show resolved Hide resolved
Comment on lines +119 to +132
def test_filter(db):
db.cfg.auto_schema = True

db['documents'].insert([{'x': i} for i in range(10)])

t = db['documents']

q = t.filter(t['x'] == 1)

results = q.execute()

assert len(results) == 1

assert results[0]['x'] == 1
Copy link
Collaborator

@jieguangzhou jieguangzhou Jan 15, 2025

Choose a reason for hiding this comment

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

We also need to test multiple conditions and difference conditions

difference conditions:

  1. isin
  2. >
  3. "!="
  4. ...

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Agreed.

@blythed blythed force-pushed the refactor/2479/simplify-databackend-contract branch 3 times, most recently from 2db34b1 to e80debb Compare January 17, 2025 14:19
@blythed blythed force-pushed the refactor/2479/simplify-databackend-contract branch from e80debb to 70b2929 Compare January 17, 2025 14:25
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