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

refactoring #830

Merged
merged 3 commits into from
Nov 30, 2024
Merged
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
23 changes: 2 additions & 21 deletions lib/duckdb/appender.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def append_uhugeint(value)
# appender.end_row
# appender.flush
def append_date(value)
date = to_date(value)
date = _parse_date(value)

_append_date(date.year, date.month, date.day)
end
Expand Down Expand Up @@ -200,31 +200,12 @@ def blob?(value) # :nodoc:
value.instance_of?(DuckDB::Blob) || value.encoding == Encoding::BINARY
end

def to_date(value) # :nodoc:
case value
when Date, Time
value
else
begin
Date.parse(value)
rescue StandardError
raise(ArgumentError, "Cannot parse argument `#{value}` to Date.")
end
end
end

def to_time(value) # :nodoc:
case value
when Time
value
when Date
value.to_time
else
begin
Time.parse(value)
rescue StandardError
raise(ArgumentError, "Cannot parse argument `#{value}` to Time or Date.")
end
_parse_time(value)
end
end
end
Expand Down
8 changes: 4 additions & 4 deletions test/duckdb_test/appender_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -295,12 +295,12 @@ def test_append_date
e = assert_raises(ArgumentError) do
sub_test_append_column2(:append_date, 'DATE', values: [20_211_010], expected: Date.parse('2021-10-10'))
end
assert_equal('Cannot parse argument `20211010` to Date.', e.message)
assert_match(/Cannot parse `20211010` to Date/, e.message)

e = assert_raises(ArgumentError) do
sub_test_append_column2(:append_date, 'DATE', values: ['2021-1010'], expected: Date.parse('2021-10-10'))
end
assert_equal('Cannot parse argument `2021-1010` to Date.', e.message)
assert_match(/Cannot parse `"2021-1010"` to Date/, e.message)
end

def test__append_interval
Expand Down Expand Up @@ -538,12 +538,12 @@ def test_append_timestamp
e = assert_raises(ArgumentError) do
sub_test_append_column2(:append_timestamp, 'TIMESTAMP', values: [20_211_116], expected: '2021-11-16')
end
assert_equal('Cannot parse argument `20211116` to Time or Date.', e.message)
assert_match(/Cannot parse `20211116` to Time/, e.message)

e = assert_raises(ArgumentError) do
sub_test_append_column2(:append_timestamp, 'TIMESTAMP', values: ['abc'], expected: '10:10:10')
end
assert_equal('Cannot parse argument `abc` to Time or Date.', e.message)
assert_match(/Cannot parse `"abc"` to Time/, e.message)
end

def test__append_hugeint
Expand Down