-
Notifications
You must be signed in to change notification settings - Fork 14
feat(ws): support blob type #338
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
Merged
Merged
Changes from 6 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
c156f0e
style(ws): format code
qevolg a3515d7
feat(ws): support blob type
qevolg e9587ac
Merge remote-tracking branch 'origin' into feat/TD-35104
qevolg 8ea7fe9
Merge branch 'main' into feat/TD-35104
qevolg 3ea3aa0
test: add blob test case
qevolg 630a720
test: add TEST_TD_3360 env
qevolg f0ce9d5
chore: switch to taos main branch
qevolg 2bfa207
style: format code
qevolg 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 hidden or 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,149 @@ | ||
import datetime | ||
import time | ||
import taosws | ||
from taosws import Consumer | ||
import os | ||
|
||
|
||
def test_blob_sql(): | ||
value = os.getenv("TEST_TD_3360") | ||
if value is not None: | ||
return | ||
|
||
conn = taosws.connect("ws://localhost:6041") | ||
cursor = conn.cursor() | ||
|
||
try: | ||
cursor.execute("drop database if exists test_1753269319"), | ||
cursor.execute("create database test_1753269319"), | ||
cursor.execute("use test_1753269319"), | ||
qevolg marked this conversation as resolved.
Show resolved
Hide resolved
qevolg marked this conversation as resolved.
Show resolved
Hide resolved
qevolg marked this conversation as resolved.
Show resolved
Hide resolved
qevolg marked this conversation as resolved.
Show resolved
Hide resolved
qevolg marked this conversation as resolved.
Show resolved
Hide resolved
|
||
cursor.execute("create table t0(ts timestamp, c1 blob)"), | ||
cursor.execute("insert into t0 values(1752218982761, null)"), | ||
cursor.execute("insert into t0 values(1752218982762, '')"), | ||
cursor.execute("insert into t0 values(1752218982763, 'hello')"), | ||
qevolg marked this conversation as resolved.
Show resolved
Hide resolved
|
||
cursor.execute("insert into t0 values(1752218982764, '\\x12345678')"), | ||
qevolg marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
cursor.execute("select * from t0") | ||
rows = cursor.fetchall() | ||
|
||
assert len(rows) == 4 | ||
|
||
assert rows[0][0].timestamp() * 1000 == 1752218982761 | ||
assert rows[1][0].timestamp() * 1000 == 1752218982762 | ||
assert rows[2][0].timestamp() * 1000 == 1752218982763 | ||
assert rows[3][0].timestamp() * 1000 == 1752218982764 | ||
|
||
assert rows[0][1] is None | ||
assert rows[1][1] == b"" | ||
assert rows[2][1] == b"hello" | ||
assert rows[3][1] == b"\x124Vx" | ||
|
||
finally: | ||
cursor.execute("drop database test_1753269319") | ||
conn.close() | ||
|
||
|
||
def test_blob_stmt2(): | ||
value = os.getenv("TEST_TD_3360") | ||
if value is not None: | ||
return | ||
|
||
conn = taosws.connect("ws://localhost:6041") | ||
try: | ||
conn.execute("drop database if exists test_1753269333"), | ||
qevolg marked this conversation as resolved.
Show resolved
Hide resolved
|
||
conn.execute("create database test_1753269333"), | ||
conn.execute("use test_1753269333"), | ||
qevolg marked this conversation as resolved.
Show resolved
Hide resolved
qevolg marked this conversation as resolved.
Show resolved
Hide resolved
|
||
conn.execute("create table t0 (ts timestamp, c1 blob)"), | ||
qevolg marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
test_timestamps = [1726803356466, 1726803356467, 1726803356468, 1726803356469] | ||
test_blobs = [None, b"", b"hello", b"\x124Vx"] | ||
|
||
stmt2 = conn.stmt2_statement() | ||
stmt2.prepare("insert into t0 values (?, ?)") | ||
|
||
param = taosws.stmt2_bind_param_view( | ||
table_name="", | ||
tags=None, | ||
columns=[ | ||
taosws.millis_timestamps_to_column(test_timestamps), | ||
taosws.blob_to_column(test_blobs), | ||
], | ||
) | ||
stmt2.bind([param]) | ||
|
||
affected_rows = stmt2.execute() | ||
assert affected_rows == 4 | ||
|
||
stmt2.prepare("select * from t0 where ts > ?") | ||
|
||
param = taosws.stmt2_bind_param_view( | ||
table_name="", | ||
tags=None, | ||
columns=[ | ||
taosws.millis_timestamps_to_column([1726803356465]), | ||
], | ||
) | ||
stmt2.bind([param]) | ||
stmt2.execute() | ||
|
||
result = stmt2.result_set() | ||
expected_results = list(zip(test_timestamps, test_blobs)) | ||
|
||
actual_results = [] | ||
for row in result: | ||
dt = datetime.datetime.strptime(row[0], "%Y-%m-%d %H:%M:%S.%f %z") | ||
timestamp = int(dt.timestamp() * 1000) | ||
actual_results.append((timestamp, row[1])) | ||
|
||
assert actual_results == expected_results | ||
|
||
finally: | ||
conn.execute("drop database test_1753269333") | ||
conn.close() | ||
|
||
|
||
def test_blob_tmq(): | ||
value = os.getenv("TEST_TD_3360") | ||
if value is not None: | ||
return | ||
|
||
conn = taosws.connect("ws://localhost:6041") | ||
try: | ||
conn.execute("drop topic if exists topic_1753270984"), | ||
conn.execute("drop database if exists test_1753270984"), | ||
qevolg marked this conversation as resolved.
Show resolved
Hide resolved
qevolg marked this conversation as resolved.
Show resolved
Hide resolved
|
||
conn.execute("create database test_1753270984"), | ||
qevolg marked this conversation as resolved.
Show resolved
Hide resolved
qevolg marked this conversation as resolved.
Show resolved
Hide resolved
|
||
conn.execute("create topic topic_1753270984 as database test_1753270984"), | ||
conn.execute("use test_1753270984"), | ||
qevolg marked this conversation as resolved.
Show resolved
Hide resolved
|
||
conn.execute("create table t0 (ts timestamp, c1 int, c2 blob)"), | ||
qevolg marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
num = 100 | ||
|
||
sql = "insert into t0 values " | ||
for i in range(num): | ||
ts = 1726803356466 + i | ||
sql += f"({ts}, {i}, 'blob_{i}'), " | ||
conn.execute(sql) | ||
|
||
consumer = Consumer(dsn="ws://localhost:6041?group.id=10&auto.offset.reset=earliest") | ||
consumer.subscribe(["topic_1753270984"]) | ||
|
||
cnt = 0 | ||
|
||
while 1: | ||
message = consumer.poll(timeout=5.0) | ||
if message: | ||
for block in message: | ||
cnt += block.nrows() | ||
consumer.commit(message) | ||
else: | ||
break | ||
|
||
assert cnt == num | ||
|
||
consumer.unsubscribe() | ||
|
||
finally: | ||
time.sleep(3) | ||
conn.execute("drop topic topic_1753270984") | ||
conn.execute("drop database test_1753270984") | ||
conn.close() |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.