Skip to content

Commit

Permalink
Add tests for SET in session
Browse files Browse the repository at this point in the history
  • Loading branch information
auxten committed Mar 20, 2024
1 parent 3f80118 commit ed68851
Showing 1 changed file with 38 additions and 3 deletions.
41 changes: 38 additions & 3 deletions tests/test_stateful.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import psutil
import unittest
from chdb import session
import chdb


test_state_dir = ".state_tmp_auxten_"
Expand Down Expand Up @@ -68,9 +69,7 @@ def test_path(self):

def test_mergetree(self):
sess = session.Session()
sess.query(
"CREATE DATABASE IF NOT EXISTS db_xxx_merge ENGINE = Atomic;", "CSV"
)
sess.query("CREATE DATABASE IF NOT EXISTS db_xxx_merge ENGINE = Atomic;", "CSV")
sess.query(
"CREATE TABLE IF NOT EXISTS db_xxx_merge.log_table_xxx (x String, y Int) ENGINE = MergeTree ORDER BY x;"
)
Expand Down Expand Up @@ -113,6 +112,42 @@ def test_two_sessions(self):
self.assertEqual(str(ret), "1\n2\n3\n4\n")
ret = sess2.query("SELECT * FROM db_xxx.tbl2", "CSV")
self.assertEqual(str(ret), "5\n6\n7\n8\n")
sess1.query(
"""
SET input_format_csv_use_best_effort_in_schema_inference = 0;
SET input_format_csv_skip_first_lines = 1;"""
)
# query level settings should not affect session level settings
ret = sess1.query(
"SELECT 123 SETTINGS input_format_csv_use_best_effort_in_schema_inference = 1;"
)
# check sess1 settings
ret = sess1.query("""SELECT value, changed FROM system.settings
WHERE name = 'input_format_csv_use_best_effort_in_schema_inference';""")
self.assertEqual(str(ret), '"0",1\n')
ret = sess1.query("""SELECT value, changed FROM system.settings
WHERE name = 'input_format_csv_skip_first_lines';""")
self.assertEqual(str(ret), '"1",1\n')

# sess2 should not be affected
ret = sess2.query("""SELECT value, changed FROM system.settings
WHERE name = 'input_format_csv_use_best_effort_in_schema_inference';""")
self.assertEqual(str(ret), '"1",0\n')
ret = sess2.query("""SELECT value, changed FROM system.settings
WHERE name = 'input_format_csv_skip_first_lines';""")
self.assertEqual(str(ret), '"0",0\n')

# stateless query should not be affected
ret = chdb.query(
"""SELECT value, changed FROM system.settings
WHERE name = 'input_format_csv_use_best_effort_in_schema_inference';"""
)
self.assertEqual(str(ret), '"1",0\n')
ret = chdb.query(
"""SELECT value, changed FROM system.settings
WHERE name = 'input_format_csv_skip_first_lines';"""
)
self.assertEqual(str(ret), '"0",0\n')

def test_context_mgr(self):
with session.Session() as sess:
Expand Down

0 comments on commit ed68851

Please sign in to comment.