Skip to content
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

Add column type test for uuid, json and map #812

Closed
wants to merge 5 commits into from
Closed
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
34 changes: 25 additions & 9 deletions test/duckdb_test/column_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,14 @@
module DuckDBTest
class ColumnTest < Minitest::Test
def setup
@@con ||= create_data
@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
Expand Down Expand Up @@ -36,6 +41,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)
Expand Down Expand Up @@ -68,6 +76,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)
Expand All @@ -77,12 +88,11 @@ 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
@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
Expand Down Expand Up @@ -117,6 +127,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
Expand Down Expand Up @@ -150,6 +163,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
Expand Down
Loading