-
Notifications
You must be signed in to change notification settings - Fork 154
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
avoid storing too much in arrangements (#7592)
GitOrigin-RevId: 9b36302c51750955938be4f20d6bb93ec487910f
- Loading branch information
1 parent
976cc83
commit 25325a6
Showing
8 changed files
with
729 additions
and
201 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import multiprocessing | ||
import resource | ||
import time | ||
|
||
import numpy as np | ||
|
||
import pathway as pw | ||
|
||
|
||
@pw.udf(deterministic=True) | ||
def embedder(x: str) -> np.ndarray: | ||
return np.arange(100_000) + ord(x[0]) | ||
|
||
|
||
@pw.udf(deterministic=True) | ||
def anti_embedder(x: np.ndarray) -> str: | ||
return chr(x[0]) | ||
|
||
|
||
class QuerySchema(pw.Schema): | ||
query: str | ||
|
||
|
||
class QuerySubject(pw.io.python.ConnectorSubject): | ||
def __init__(self, n: int) -> None: | ||
super().__init__() | ||
self.n = n | ||
|
||
def run(self): | ||
for i in range(self.n): | ||
time.sleep(0.001) | ||
self.next(query=f"{chr(i%26 + 97)}") | ||
|
||
|
||
class DocSchema(pw.Schema): | ||
doc: str | ||
|
||
|
||
class DocsSubject(pw.io.python.ConnectorSubject): | ||
def __init__(self, n: int) -> None: | ||
super().__init__() | ||
self.n = n | ||
|
||
def run(self): | ||
for doc in ["a", "b", "c", "d", "x", "z"]: | ||
self.next(doc=doc) | ||
time.sleep(0.001 * self.n + 10) | ||
|
||
|
||
def run(n: int) -> None: | ||
query = pw.io.python.read( | ||
QuerySubject(n), schema=QuerySchema, autocommit_duration_ms=100 | ||
) | ||
max_depth_2 = query.with_columns(vec=embedder(pw.this.query)) | ||
max_depth_3 = max_depth_2.with_columns(c=anti_embedder(pw.this.vec)) | ||
docs = pw.io.python.read(DocsSubject(n), schema=DocSchema) | ||
res = max_depth_3.join(docs, pw.left.query == pw.right.doc).select( | ||
pw.left.query, pw.left.c, pw.right.doc | ||
) | ||
|
||
pw.io.null.write(res) | ||
pw.run(monitoring_level=pw.MonitoringLevel.NONE) | ||
assert resource.getrusage(resource.RUSAGE_SELF).ru_maxrss < 1_500_000 | ||
|
||
|
||
def test_big_columns_are_not_stored_if_not_needed(): | ||
n = 100_000 | ||
p = multiprocessing.Process( | ||
target=run, | ||
args=(n,), | ||
) | ||
p.start() | ||
try: | ||
p.join(timeout=400) | ||
assert p.exitcode == 0 | ||
finally: | ||
p.terminate() | ||
p.join() |
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.