-
Notifications
You must be signed in to change notification settings - Fork 80
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
feat: Support Multijoin in the Python client #6020
Open
jmao-denver
wants to merge
2
commits into
deephaven:main
Choose a base branch
from
jmao-denver:5884-pyclient-multijoin
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
# | ||
# Copyright (c) 2016-2024 Deephaven Data Labs and Patent Pending | ||
# | ||
import unittest | ||
|
||
from pyarrow import csv | ||
|
||
from pydeephaven import DHError, Session | ||
from pydeephaven.table import MultiJoinInput, multi_join | ||
from tests.testbase import BaseTestCase | ||
|
||
|
||
class MultiJoinTestCase(BaseTestCase): | ||
def setUp(self): | ||
super().setUp() | ||
pa_table = csv.read_csv(self.csv_file) | ||
self.static_tableA = self.session.import_table(pa_table).select(["a", "b", "c1=c", "d1=d", "e1=e"]) | ||
self.static_tableB = self.static_tableA.update(["c2=c1+1", "d2=d1+2", "e2=e1+3"]).drop_columns( | ||
["c1", "d1", "e1"]) | ||
self.ticking_tableA = self.session.time_table("PT00:00:00.001").update( | ||
["a = i", "b = i*i % 13", "c1 = i * 13 % 23", "d1 = a + b", "e1 = a - b"]).drop_columns(["Timestamp"]) | ||
self.ticking_tableB = self.ticking_tableA.update(["c2=c1+1", "d2=d1+2", "e2=e1+3"]).drop_columns( | ||
["c1", "d1", "e1"]) | ||
|
||
def tearDown(self) -> None: | ||
self.static_tableA = None | ||
self.static_tableB = None | ||
self.ticking_tableA = None | ||
self.ticking_tableB = None | ||
super().tearDown() | ||
|
||
def test_static_simple(self): | ||
# Test with multiple input tables | ||
mj_table = multi_join(input=[self.static_tableA, self.static_tableB], on=["a", "b"]) | ||
|
||
# Output table is static | ||
self.assertFalse(mj_table.is_refreshing) | ||
# Output table has same # rows as sources | ||
self.assertEqual(mj_table.size, self.static_tableA.size) | ||
self.assertEqual(mj_table.size, self.static_tableB.size) | ||
|
||
# Test with a single input table | ||
mj_table = multi_join(self.static_tableA, ["a", "b"]) | ||
|
||
# Output table is static | ||
self.assertFalse(mj_table.is_refreshing) | ||
# Output table has same # rows as sources | ||
self.assertEqual(mj_table.size, self.static_tableA.size) | ||
|
||
def test_ticking_simple(self): | ||
# Test with multiple input tables | ||
mj_table = multi_join(input=[self.ticking_tableA, self.ticking_tableB], on=["a", "b"]) | ||
|
||
# Output table is refreshing | ||
self.assertTrue(mj_table.is_refreshing) | ||
|
||
# Test with a single input table | ||
mj_table = multi_join(input=self.ticking_tableA, on=["a", "b"]) | ||
|
||
# Output table is refreshing | ||
self.assertTrue(mj_table.is_refreshing) | ||
|
||
def test_static(self): | ||
# Test with multiple input | ||
mj_input = [ | ||
MultiJoinInput(table=self.static_tableA, on=["key1=a", "key2=b"], joins=["c1", "e1"]), | ||
MultiJoinInput(table=self.static_tableB, on=["key1=a", "key2=b"], joins=["d2"]) | ||
] | ||
mj_table = multi_join(mj_input) | ||
|
||
# Output table is static | ||
self.assertFalse(mj_table.is_refreshing) | ||
# Output table has same # rows as sources | ||
self.assertEqual(mj_table.size, self.static_tableA.size) | ||
self.assertEqual(mj_table.size, self.static_tableB.size) | ||
|
||
# Test with a single input | ||
mj_table = multi_join(MultiJoinInput(table=self.static_tableA, on=["key1=a", "key2=b"], joins="c1")) | ||
|
||
# Output table is static | ||
self.assertFalse(mj_table.is_refreshing) | ||
# Output table has same # rows as sources | ||
self.assertEqual(mj_table.size, self.static_tableA.size) | ||
|
||
def test_ticking(self): | ||
# Test with multiple input | ||
mj_input = [ | ||
MultiJoinInput(table=self.ticking_tableA, on=["key1=a", "key2=b"], joins=["c1", "e1"]), | ||
MultiJoinInput(table=self.ticking_tableB, on=["key1=a", "key2=b"], joins=["d2"]) | ||
] | ||
mj_table = multi_join(mj_input) | ||
|
||
# Output table is refreshing | ||
self.assertTrue(mj_table.is_refreshing) | ||
|
||
# Test with a single input | ||
mj_table = multi_join(input=MultiJoinInput(table=self.ticking_tableA, on=["key1=a", "key2=b"], joins="c1")) | ||
|
||
# Output table is refreshing | ||
self.assertTrue(mj_table.is_refreshing) | ||
|
||
def test_errors(self): | ||
# Assert the exception is raised when providing MultiJoinInput and the on parameter is not None (omitted). | ||
mj_input = [ | ||
MultiJoinInput(table=self.ticking_tableA, on=["key1=a", "key2=b"], joins=["c1", "e1"]), | ||
MultiJoinInput(table=self.ticking_tableB, on=["key1=a", "key2=b"], joins=["d2"]) | ||
] | ||
with self.assertRaises(DHError): | ||
mj_table = multi_join(mj_input, on=["key1=a", "key2=b"]) | ||
|
||
session = Session() | ||
t = session.time_table("PT00:00:00.001").update( | ||
["a = i", "b = i*i % 13", "c1 = i * 13 % 23", "d1 = a + b", "e1 = a - b"]).drop_columns(["Timestamp"]) | ||
|
||
# Assert the exception is raised when to-be-joined tables are not from the same session. | ||
mj_input = [ | ||
MultiJoinInput(table=self.ticking_tableA, on=["key1=a", "key2=b"], joins=["c1", "e1"]), | ||
MultiJoinInput(table=t, on=["key1=a", "key2=b"], joins=["d2"]) | ||
] | ||
with self.assertRaises(DHError) as cm: | ||
mj_table = multi_join(mj_input) | ||
self.assertIn("all tables must be from the same session", str(cm.exception)) | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
The return type here is
Table
where thedeephaven
method returnsMultiJoinTable
.MultiJoinTable
does not inherit fromTable
and has a different API. Users ofMultiJoinTable
must calltable()
to get a table to use. I think I complained about this during that review. Without adding aMultiJoinTable
on the client side, the APIs are incompatible.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.
See #6020 (comment)