Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ jobs:
test:
runs-on: ubuntu-22.04
steps:
- name: Set up Rust
id: setup-rust
uses: dtolnay/rust-toolchain@stable
with:
toolchain: 1.90.0

- name: Checkout
uses: actions/checkout@v3

Expand Down Expand Up @@ -79,13 +85,19 @@ jobs:
with:
cmakeVersion: 3.31.6

# - name: Set up Rust
# id: setup-rust
# uses: dtolnay/rust-toolchain@stable
# with:
# toolchain: 1.90.0

- name: Determine TDengine branch
uses: haya14busa/action-cond@v1
id: determine-branch
with:
cond: ${{ github.base_ref == 'main' }}
if_true: "main"
if_false: "3.0"
if_true: "feat/TD-38480-3.0"
if_false: "feat/TD-38480-3.0"

- name: Checkout tdengine
uses: actions/checkout@v2
Expand All @@ -102,7 +114,7 @@ jobs:
rm build -rf
mkdir build
cd build
cmake ../ -DBUILD_JDBC=false -DCMAKE_INSTALL_PREFIX:PATH=`realpath ../../local/` -DBUILD_HTTP=false -DBUILD_DEPENDENCY_TESTS=false
cmake ../ -DWEBSOCKET=true -DBUILD_JDBC=false -DCMAKE_INSTALL_PREFIX:PATH=`realpath ../../local/` -DBUILD_HTTP=false -DBUILD_DEPENDENCY_TESTS=false
make -j14
sudo make install
ls -alh /etc/taos/
Expand All @@ -126,6 +138,7 @@ jobs:
export LD_LIBRARY_PATH=$PWD/TDengine_v3/build/build/lib
#source $VENV
export TDENGINE_URL=localhost:6041
export TDENGINE_DRIVER=websocket
curl -L -H "Authorization: Basic cm9vdDp0YW9zZGF0YQ==" -d "show databases" localhost:6041/rest/sql
poetry run pytest --cov-report term --cov-report html --cov-report xml --cov=taos --cov=taosrest --cov-append tests

Expand Down
5 changes: 2 additions & 3 deletions .github/workflows/mac.yml
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ jobs:
- name: Set up Python 3.12
uses: actions/setup-python@v4
with:
python-version: '3.12'
python-version: "3.12"

- name: get cache server by pr
if: github.event_name == 'pull_request'
Expand Down Expand Up @@ -347,13 +347,12 @@ jobs:
export GEOS_DIR=$(brew --prefix geos)
poetry env use python3.12
poetry install --no-interaction --no-root


#----------------------------------------------
# install your root project, if required
#----------------------------------------------
- name: Install library
run: |
run: |
export GEOS_CONFIG=$(brew --prefix geos)/bin/geos-config
export GEOS_DIR=$(brew --prefix geos)
poetry env use python3.12
Expand Down
2 changes: 1 addition & 1 deletion examples/bind-multi.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
params = new_multi_binds(16)
params[0].timestamp((1626861392589, 1626861392590, 1626861392591))
params[1].bool((True, None, False))
params[2].tinyint([-128, -128, None]) # -128 is tinyint null
params[2].tinyint([-128, -128, None]) # -128 is tinyint null
params[3].tinyint([0, 127, None])
params[4].smallint([3, None, 2])
params[5].int([3, 4, None])
Expand Down
5 changes: 2 additions & 3 deletions examples/connect_cloud_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@


def connect_to_cloud_use_token(url, token):
conn = taosrest.connect(url=url,
token=token)
conn = taosrest.connect(url=url, token=token)

print(conn.server_info)
cursor = conn.cursor()
Expand All @@ -17,7 +16,7 @@ def connect_to_cloud_use_token(url, token):
print(rows)


if __name__ == '__main__':
if __name__ == "__main__":
url = os.environ["TDENGINE_CLOUD_URL"]
token = os.environ["TDENGINE_CLOUD_TOKEN"]
connect_to_cloud_use_token(url, token)
15 changes: 8 additions & 7 deletions examples/connect_rest_examples.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
# ANCHOR: connect
from taosrest import connect, TaosRestConnection, TaosRestCursor

conn: TaosRestConnection = connect(url="http://localhost:6041",
user="root",
password="taosdata",
timeout=30)
conn: TaosRestConnection = connect(url="http://localhost:6041", user="root", password="taosdata", timeout=30)

# ANCHOR_END: connect
# ANCHOR: basic
# create STable
cursor: TaosRestCursor = conn.cursor()
cursor.execute("DROP DATABASE IF EXISTS power")
cursor.execute("CREATE DATABASE power")
cursor.execute("CREATE STABLE power.meters (ts TIMESTAMP, current FLOAT, voltage INT, phase FLOAT) TAGS (location BINARY(64), groupId INT)")
cursor.execute(
"CREATE STABLE power.meters (ts TIMESTAMP, current FLOAT, voltage INT, phase FLOAT) TAGS (location BINARY(64), groupId INT)"
)

# insert data
cursor.execute("""INSERT INTO power.d1001 USING power.meters TAGS('California.SanFrancisco', 2) VALUES ('2018-10-03 14:38:05.000', 10.30000, 219, 0.31000) ('2018-10-03 14:38:15.000', 12.60000, 218, 0.33000) ('2018-10-03 14:38:16.800', 12.30000, 221, 0.31000)
cursor.execute(
"""INSERT INTO power.d1001 USING power.meters TAGS('California.SanFrancisco', 2) VALUES ('2018-10-03 14:38:05.000', 10.30000, 219, 0.31000) ('2018-10-03 14:38:15.000', 12.60000, 218, 0.33000) ('2018-10-03 14:38:16.800', 12.30000, 221, 0.31000)
power.d1002 USING power.meters TAGS('California.SanFrancisco', 3) VALUES ('2018-10-03 14:38:16.650', 10.30000, 218, 0.25000)
power.d1003 USING power.meters TAGS('California.LosAngeles', 2) VALUES ('2018-10-03 14:38:05.500', 11.80000, 221, 0.28000) ('2018-10-03 14:38:16.600', 13.40000, 223, 0.29000)
power.d1004 USING power.meters TAGS('California.LosAngeles', 3) VALUES ('2018-10-03 14:38:05.000', 10.80000, 223, 0.29000) ('2018-10-03 14:38:06.500', 11.50000, 221, 0.35000)""")
power.d1004 USING power.meters TAGS('California.LosAngeles', 3) VALUES ('2018-10-03 14:38:05.000', 10.80000, 223, 0.29000) ('2018-10-03 14:38:06.500', 11.50000, 221, 0.35000)"""
)
print("inserted row count:", cursor.rowcount)

# query data
Expand Down
16 changes: 9 additions & 7 deletions examples/connect_rest_with_req_id_examples.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
# ANCHOR: connect
from taosrest import connect, TaosRestConnection, TaosRestCursor

conn = connect(url="http://localhost:6041",
user="root",
password="taosdata",
timeout=30)
conn = connect(url="http://localhost:6041", user="root", password="taosdata", timeout=30)

# ANCHOR_END: connect
# ANCHOR: basic
Expand All @@ -13,13 +10,18 @@
cursor.execute("DROP DATABASE IF EXISTS power", req_id=1)
cursor.execute("CREATE DATABASE power", req_id=2)
cursor.execute(
"CREATE STABLE power.meters (ts TIMESTAMP, current FLOAT, voltage INT, phase FLOAT) TAGS (location BINARY(64), groupId INT)", req_id=3)
"CREATE STABLE power.meters (ts TIMESTAMP, current FLOAT, voltage INT, phase FLOAT) TAGS (location BINARY(64), groupId INT)",
req_id=3,
)

# insert data
cursor.execute("""INSERT INTO power.d1001 USING power.meters TAGS('California.SanFrancisco', 2) VALUES ('2018-10-03 14:38:05.000', 10.30000, 219, 0.31000) ('2018-10-03 14:38:15.000', 12.60000, 218, 0.33000) ('2018-10-03 14:38:16.800', 12.30000, 221, 0.31000)
cursor.execute(
"""INSERT INTO power.d1001 USING power.meters TAGS('California.SanFrancisco', 2) VALUES ('2018-10-03 14:38:05.000', 10.30000, 219, 0.31000) ('2018-10-03 14:38:15.000', 12.60000, 218, 0.33000) ('2018-10-03 14:38:16.800', 12.30000, 221, 0.31000)
power.d1002 USING power.meters TAGS('California.SanFrancisco', 3) VALUES ('2018-10-03 14:38:16.650', 10.30000, 218, 0.25000)
power.d1003 USING power.meters TAGS('California.LosAngeles', 2) VALUES ('2018-10-03 14:38:05.500', 11.80000, 221, 0.28000) ('2018-10-03 14:38:16.600', 13.40000, 223, 0.29000)
power.d1004 USING power.meters TAGS('California.LosAngeles', 3) VALUES ('2018-10-03 14:38:05.000', 10.80000, 223, 0.29000) ('2018-10-03 14:38:06.500', 11.50000, 221, 0.35000)""", req_id=4)
power.d1004 USING power.meters TAGS('California.LosAngeles', 3) VALUES ('2018-10-03 14:38:05.000', 10.80000, 223, 0.29000) ('2018-10-03 14:38:06.500', 11.50000, 221, 0.35000)""",
req_id=4,
)
print("inserted row count:", cursor.rowcount)

# query data
Expand Down
2 changes: 1 addition & 1 deletion examples/connection_usage_native_reference.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,4 @@
# ANCHOR_END: query


conn.close()
conn.close()
6 changes: 4 additions & 2 deletions examples/connection_usage_native_reference_with_req_id.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
# change database. same as execute "USE db"
conn.select_db("test")
conn.execute("CREATE STABLE weather(ts TIMESTAMP, temperature FLOAT) TAGS (location INT)", req_id=3)
affected_row = conn.execute("INSERT INTO t1 USING weather TAGS(1) VALUES (now, 23.5) (now+1m, 23.5) (now+2m, 24.4)", req_id=4)
affected_row = conn.execute(
"INSERT INTO t1 USING weather TAGS(1) VALUES (now, 23.5) (now+1m, 23.5) (now+2m, 24.4)", req_id=4
)
print("affected_row", affected_row)
# output:
# affected_row 3
Expand Down Expand Up @@ -42,4 +44,4 @@
# ANCHOR_END: query


conn.close()
conn.close()
34 changes: 17 additions & 17 deletions examples/cursor_execute_many.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
import taos

env = {
'user': "root",
'password': "taosdata",
'host': "localhost",
'port': 6030,
"user": "root",
"password": "taosdata",
"host": "localhost",
"port": 6030,
}


def make_context(config):
db_protocol = config.get('db_protocol', 'taos')
db_user = config['user']
db_pass = config['password']
db_host = config['host']
db_port = config['port']
db_protocol = config.get("db_protocol", "taos")
db_user = config["user"]
db_pass = config["password"]
db_host = config["host"]
db_port = config["port"]

db_url = f"{db_protocol}://{db_user}:{db_pass}@{db_host}:{db_port}"
print('dsn: ', db_url)
print("dsn: ", db_url)

conn = taos.connect(**config)

db_name = config.get('database', 'c_cursor')
db_name = config.get("database", "c_cursor")

return conn, db_name

Expand Down Expand Up @@ -48,7 +48,7 @@ def test_cursor():
{
"name": "tb3",
"t1": 3,
}
},
]

res = cur.execute_many(
Expand All @@ -59,13 +59,13 @@ def test_cursor():
assert res == 0

data = [
('2018-10-03 14:38:05.100', 219),
('2018-10-03 14:38:15.300', 218),
('2018-10-03 14:38:16.800', 221),
("2018-10-03 14:38:05.100", 219),
("2018-10-03 14:38:15.300", 218),
("2018-10-03 14:38:16.800", 221),
]

for table in create_table_data:
table_name = table['name']
table_name = table["name"]

res = cur.execute_many(
f"insert into {table_name} values",
Expand All @@ -74,7 +74,7 @@ def test_cursor():
print(f"affected_rows: {res}")
assert res == 3

cur.execute('select * from stb')
cur.execute("select * from stb")

data = cur.fetchall()
column_names = [meta[0] for meta in cur.description]
Expand Down
4 changes: 3 additions & 1 deletion examples/cursor_usage_native_reference_with_req_id.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
for i in range(1000):
location = str(i % 10)
tb = "t" + location
cursor.execute(f"INSERT INTO {tb} USING weather TAGS({location}) VALUES (now+{i}a, 23.5) (now+{i + 1}a, 23.5)", req_id=5+i)
cursor.execute(
f"INSERT INTO {tb} USING weather TAGS({location}) VALUES (now+{i}a, 23.5) (now+{i + 1}a, 23.5)", req_id=5 + i
)

cursor.execute("SELECT count(*) FROM weather", req_id=1005)
data = cursor.fetchall()
Expand Down
2 changes: 1 addition & 1 deletion examples/json-tag.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
conn.execute("use py_test_json_type")

conn.execute("create stable s1 (ts timestamp, v1 int) tags (info json)")
conn.execute("create table s1_1 using s1 tags ('{\"k1\": \"v1\"}')")
conn.execute('create table s1_1 using s1 tags (\'{"k1": "v1"}\')')
tags = conn.query("select info, tbname from s1").fetch_all_into_dict()
print(tags)

Expand Down
30 changes: 14 additions & 16 deletions examples/native_all_type_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,25 @@
host = "127.0.0.1"
port = 6030


def json_tag_example():
conn = None
try:
conn = taos.connect(host=host,
port=port,
user="root",
password="taosdata")
conn = taos.connect(host=host, port=port, user="root", password="taosdata")
# create database
rows_affected: int = conn.execute(f"CREATE DATABASE IF NOT EXISTS example_json_tag")
print(f"Create database power successfully")
assert rows_affected == 0

rows_affected = conn.execute(
"create table if not exists example_json_tag.stb (ts timestamp, v int) tags(jt json)")
print(f"Create stable example_json_tag.stb successfully");
"create table if not exists example_json_tag.stb (ts timestamp, v int) tags(jt json)"
)
print(f"Create stable example_json_tag.stb successfully")
assert rows_affected == 0

rows_affected = conn.execute(
'insert into example_json_tag.tb1 using example_json_tag.stb tags(\'{"name":"value"}\') values(now, 1)')
'insert into example_json_tag.tb1 using example_json_tag.stb tags(\'{"name":"value"}\') values(now, 1)'
)
print(f"Successfully inserted {rows_affected} rows to example_json_tag.tb1.")

result = conn.query("SELECT ts, v, jt FROM example_json_tag.stb limit 100", req_id=1)
Expand All @@ -38,10 +38,7 @@ def json_tag_example():
def all_type_example():
conn = None
try:
conn = taos.connect(host=host,
port=port,
user="root",
password="taosdata")
conn = taos.connect(host=host, port=port, user="root", password="taosdata")
# create database
rows_affected: int = conn.execute(f"CREATE DATABASE IF NOT EXISTS all_type_example")
print(f"Create database power successfully")
Expand All @@ -55,7 +52,7 @@ def all_type_example():
"binary_col BINARY(100)",
"nchar_col NCHAR(100)",
"varbinary_col VARBINARY(100)",
"geometry_col GEOMETRY(100)"
"geometry_col GEOMETRY(100)",
]
tags = [
"int_tag INT",
Expand All @@ -64,7 +61,7 @@ def all_type_example():
"binary_tag BINARY(100)",
"nchar_tag NCHAR(100)",
"varbinary_tag VARBINARY(100)",
"geometry_tag GEOMETRY(100)"
"geometry_tag GEOMETRY(100)",
]

str_cols = ",".join(cols)
Expand All @@ -73,8 +70,10 @@ def all_type_example():
conn.execute("create table IF NOT EXISTS all_type_example.stb(%s) tags(%s)" % (str_cols, str_tags))
print(f"Create stable all_type_example.stb successfully")

rows_affected = conn.execute("INSERT INTO all_type_example.tb1 using all_type_example.stb tags(1, 1.1, true, 'binary_value', 'nchar_value', '\\x98f46e', 'POINT(100 100)') "
+ "values(now, 1, 1.1, true, 'binary_value', 'nchar_value', '\\x98f46e', 'POINT(100 100)')")
rows_affected = conn.execute(
"INSERT INTO all_type_example.tb1 using all_type_example.stb tags(1, 1.1, true, 'binary_value', 'nchar_value', '\\x98f46e', 'POINT(100 100)') "
+ "values(now, 1, 1.1, true, 'binary_value', 'nchar_value', '\\x98f46e', 'POINT(100 100)')"
)
print(f"Successfully inserted {rows_affected} rows to all_type_example.tb1.")

result = conn.query("SELECT * FROM all_type_example.stb limit 100", req_id=1)
Expand All @@ -92,4 +91,3 @@ def all_type_example():
if __name__ == "__main__":
json_tag_example()
all_type_example()

Loading
Loading