-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Invoke test and support for managed (windowed) tables
- Loading branch information
1 parent
dad69c6
commit b25a0d1
Showing
10 changed files
with
113 additions
and
31 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,4 @@ | ||
{"timestamp":"2015-12-12T19:11:01.249Z","event":"search","properties":{"city":"New York"},"user":{"id":"123412ds"}} | ||
{"timestamp":"2015-12-12T19:11:01.249Z","event":"search","properties":{"city":"New York"},"user":{"id":"123412ds1"}} | ||
{"timestamp":"2015-12-12T19:11:01.249Z","event":"search","properties":{"city":"Baltimore"},"user":{"id":"123412ds1"}} | ||
{"timestamp":"2015-12-12T19:11:01.249Z","event":"search","properties":{"city":"Baltimore"},"user":{"id":"123412ds1"}} |
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 |
---|---|---|
@@ -1,20 +1,51 @@ | ||
from sqlflow.sql import init_tables | ||
from sqlflow.handlers import InferredDiskBatch | ||
from sqlflow.serde import JSON | ||
from sqlflow.sql import init_tables, build_managed_tables | ||
from sqlflow.handlers import InferredDiskBatch, get_class | ||
from sqlflow.config import new_from_path | ||
|
||
|
||
def invoke(conn, config, fixture, setting_overrides={}): | ||
def invoke(conn, config, fixture, setting_overrides={}, flush_window=False): | ||
""" | ||
Invoke will initialize config and invoke the configured pipleline against | ||
the provided fixture. | ||
:param conn: | ||
:param config: | ||
:param fixture: | ||
:param setting_overrides: | ||
:param flush_window: Flushes the window after the invocation. | ||
:return: | ||
""" | ||
conf = new_from_path(config, setting_overrides) | ||
init_tables(conn, conf.tables) | ||
|
||
p = InferredDiskBatch( | ||
conf=conf, | ||
BatchHandler = get_class(conf.pipeline.type) | ||
h = BatchHandler( | ||
conf, | ||
deserializer=JSON(), | ||
conn=conn, | ||
).init() | ||
|
||
init_tables(conn, conf.tables) | ||
managed_tables = build_managed_tables( | ||
conn, | ||
conf.tables.sql, | ||
) | ||
if managed_tables: | ||
assert len(managed_tables) == 1, \ | ||
"only a single managed table is currently supported" | ||
|
||
with open(fixture) as f: | ||
for line in f: | ||
p.write(line) | ||
res = list(p.invoke()) | ||
cleaned_line = line.strip() | ||
if cleaned_line: | ||
h.write(cleaned_line) | ||
|
||
res = list(h.invoke()) | ||
if not flush_window: | ||
print(res) | ||
return res | ||
|
||
res = managed_tables[0].collect_closed() | ||
print(res) | ||
|
||
return res |
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 |
---|---|---|
@@ -1 +1 @@ | ||
from .handlers import Tumbling | ||
from .handlers import Tumbling, Table |
Empty file.
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,6 @@ | ||
import unittest | ||
|
||
|
||
class TestCase(unittest.TestCase): | ||
def test_fail(self): | ||
self.fail() |
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