From ffeecc591cc7f8f8138e6e8187735f083291ff24 Mon Sep 17 00:00:00 2001 From: gregszero Date: Wed, 20 Nov 2024 12:57:22 -0300 Subject: [PATCH 1/5] Add column type test for uuid, json and map --- test/duckdb_test/column_test.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/test/duckdb_test/column_test.rb b/test/duckdb_test/column_test.rb index 1a2a68e4..78d17947 100644 --- a/test/duckdb_test/column_test.rb +++ b/test/duckdb_test/column_test.rb @@ -36,6 +36,9 @@ def test_type expected.push(:list) expected.push(:list) expected.push(:struct) + expected.push(:uuid) + expected.push(:varchar) # json + expected.push(:map) assert_equal( expected, @columns.map(&:type) @@ -68,6 +71,9 @@ def test_name expected.push('int_list_col') expected.push('varchar_list_col') expected.push('struct_col') + expected.push('uuid_col') + expected.push('json_col') + expected.push('map_col') assert_equal( expected, @columns.map(&:name) @@ -117,6 +123,9 @@ def create_table_sql sql += ', int_list_col INT[]' sql += ', varchar_list_col VARCHAR[]' sql += ', struct_col STRUCT(word VARCHAR, length INTEGER)' + sql += ', uuid_col UUID' + sql += ', json_col JSON' + sql += ', map_col MAP(INTEGER, VARCHAR)' sql += ')' sql end @@ -150,6 +159,9 @@ def insert_sql sql += ', [1, 2, 3]' sql += ", ['a', 'b', 'c']" sql += ", ROW('Ruby', 4)" + sql += ", '#{SecureRandom.uuid}'" + sql += ", '{\"key\": \"value\"}'" + sql += ", MAP([1, 2], ['Dog', 'Cat'])" sql += ')' sql end From 902826b23db6db25235d827e576cdf5fb1b6a207 Mon Sep 17 00:00:00 2001 From: gregszero Date: Wed, 20 Nov 2024 13:09:54 -0300 Subject: [PATCH 2/5] Run test with in memory db --- test/duckdb_test/column_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/duckdb_test/column_test.rb b/test/duckdb_test/column_test.rb index 78d17947..630ec21a 100644 --- a/test/duckdb_test/column_test.rb +++ b/test/duckdb_test/column_test.rb @@ -83,7 +83,7 @@ def test_name private def create_data - @@db ||= DuckDB::Database.open # FIXME + @@db ||= DuckDB::Database.open(':memory:') # FIXME con = @@db.connect con.query(create_type_enum_sql) con.query(create_table_sql) From a8185d0a426d92dfb89a270587df3dee7cd75858 Mon Sep 17 00:00:00 2001 From: gregszero Date: Wed, 20 Nov 2024 13:16:05 -0300 Subject: [PATCH 3/5] Cleanup db before run test (keeping class variables) --- test/duckdb_test/column_test.rb | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/test/duckdb_test/column_test.rb b/test/duckdb_test/column_test.rb index 630ec21a..9f426877 100644 --- a/test/duckdb_test/column_test.rb +++ b/test/duckdb_test/column_test.rb @@ -5,8 +5,9 @@ module DuckDBTest class ColumnTest < Minitest::Test def setup - @@con ||= create_data - @result = @@con.query('SELECT * from table1') + @@con ||= initialize_database + reset_database(@@con) + @result = @@con.query('SELECT * FROM table1') @columns = @result.columns end @@ -83,7 +84,7 @@ def test_name private def create_data - @@db ||= DuckDB::Database.open(':memory:') # FIXME + @@db ||= DuckDB::Database.open # FIXME con = @@db.connect con.query(create_type_enum_sql) con.query(create_table_sql) @@ -91,6 +92,27 @@ def create_data con end + def initialize_database + @@db ||= DuckDB::Database.open # FIXME + @@db.connect + end + + def reset_database(con) + drop_existing_schema(con) + setup_schema_and_data(con) + end + + def drop_existing_schema(con) + con.query('DROP TABLE IF EXISTS table1') + con.query('DROP TYPE IF EXISTS mood') + end + + def setup_schema_and_data(con) + con.query(create_type_enum_sql) + con.query(create_table_sql) + con.query(insert_sql) + end + def create_type_enum_sql "CREATE TYPE mood AS ENUM ('sad', 'ok', 'happy', 'π˜ΎπΎΦ…Ι­ 😎');" end From 8d2b1ded6992f7c06063910f31b6a61f11f0fc98 Mon Sep 17 00:00:00 2001 From: gregszero Date: Wed, 20 Nov 2024 13:19:26 -0300 Subject: [PATCH 4/5] Setup test with clean schema --- test/duckdb_test/column_test.rb | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/test/duckdb_test/column_test.rb b/test/duckdb_test/column_test.rb index 9f426877..7c29af3d 100644 --- a/test/duckdb_test/column_test.rb +++ b/test/duckdb_test/column_test.rb @@ -6,7 +6,7 @@ module DuckDBTest class ColumnTest < Minitest::Test def setup @@con ||= initialize_database - reset_database(@@con) + ensure_clean_schema(@@con) @result = @@con.query('SELECT * FROM table1') @columns = @result.columns end @@ -83,22 +83,17 @@ def test_name private - def create_data - @@db ||= DuckDB::Database.open # FIXME - con = @@db.connect - con.query(create_type_enum_sql) - con.query(create_table_sql) - con.query(insert_sql) - con - end - def initialize_database - @@db ||= DuckDB::Database.open # FIXME + @@db ||= DuckDB::Database.open(':memory:') # Ensure an in-memory DB @@db.connect end - def reset_database(con) - drop_existing_schema(con) + def ensure_clean_schema(con) + begin + drop_existing_schema(con) # Safely drop existing schema + rescue DuckDB::Error + # Ignore errors if schema does not exist (first run) + end setup_schema_and_data(con) end From f52f9f59529360cfaa607499f0c9fa1e3842bd0b Mon Sep 17 00:00:00 2001 From: gregszero Date: Wed, 20 Nov 2024 13:45:19 -0300 Subject: [PATCH 5/5] Clean test state --- test/duckdb_test/column_test.rb | 41 +++++++++++---------------------- 1 file changed, 14 insertions(+), 27 deletions(-) diff --git a/test/duckdb_test/column_test.rb b/test/duckdb_test/column_test.rb index 7c29af3d..7aa71dcf 100644 --- a/test/duckdb_test/column_test.rb +++ b/test/duckdb_test/column_test.rb @@ -5,10 +5,14 @@ module DuckDBTest class ColumnTest < Minitest::Test def setup - @@con ||= initialize_database - ensure_clean_schema(@@con) - @result = @@con.query('SELECT * FROM table1') - @columns = @result.columns + @db = DuckDB::Database.open + @con = @db.connect + create_data + end + + def teardown + @con.close if @con + @db = nil end def test_type @@ -83,29 +87,12 @@ def test_name private - def initialize_database - @@db ||= DuckDB::Database.open(':memory:') # Ensure an in-memory DB - @@db.connect - end - - def ensure_clean_schema(con) - begin - drop_existing_schema(con) # Safely drop existing schema - rescue DuckDB::Error - # Ignore errors if schema does not exist (first run) - end - setup_schema_and_data(con) - end - - def drop_existing_schema(con) - con.query('DROP TABLE IF EXISTS table1') - con.query('DROP TYPE IF EXISTS mood') - end - - def setup_schema_and_data(con) - con.query(create_type_enum_sql) - con.query(create_table_sql) - con.query(insert_sql) + def create_data + @con.query(create_type_enum_sql) + @con.query(create_table_sql) + @con.query(insert_sql) + @result = @con.query('SELECT * FROM table1') + @columns = @result.columns end def create_type_enum_sql