diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 94c56de..1ea86e6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -90,7 +90,7 @@ jobs: if: steps.cache-otp.outputs.cache-hit != 'true' run: | mkdir -p ./cache/otp - curl -fSL https://cocoa.build/otp/v${{ env.OTP_VERSION }}/otp-x86_64-apple-darwin.tar.gz -o ./cache/otp/otp-v${{ env.OTP_VERSION }}-x86_64-apple-darwin.tar.gz + curl -fSL https://github.com/cocoa-xu/otp-build/releases/download/v${{ env.OTP_VERSION }}/otp-x86_64-apple-darwin.tar.gz -o ./cache/otp/otp-v${{ env.OTP_VERSION }}-x86_64-apple-darwin.tar.gz cd ./cache/otp tar -xzf otp-v${{ env.OTP_VERSION }}-x86_64-apple-darwin.tar.gz diff --git a/lib/adbc_column.ex b/lib/adbc_column.ex index 8c8198b..4780505 100644 --- a/lib/adbc_column.ex +++ b/lib/adbc_column.ex @@ -1198,14 +1198,16 @@ defmodule Adbc.Column do end defp handle_decimal(decimal_data, bits, scale) do - Enum.map(decimal_data, fn data -> - <> = data + Enum.map(decimal_data, fn + <> -> + if decimal < 0 do + Decimal.new(-1, -decimal, -scale) + else + Decimal.new(1, decimal, -scale) + end - if decimal < 0 do - Decimal.new(-1, -decimal, -scale) - else - Decimal.new(1, decimal, -scale) - end + nil -> + nil end) end diff --git a/test/adbc_column_test.exs b/test/adbc_column_test.exs index 92f55ed..d911c2e 100644 --- a/test/adbc_column_test.exs +++ b/test/adbc_column_test.exs @@ -41,6 +41,30 @@ defmodule Adbc.Column.Test do assert value == decode2 / :math.pow(10, scale) end + test "nil in data" do + bitwidth = 128 + precision = 19 + scale = 10 + + decimal_with_nil = %Adbc.Column{ + data: [nil], + metadata: nil, + name: nil, + nullable: true, + type: {:decimal, bitwidth, precision, scale} + } + + assert %Adbc.Column{ + name: nil, + type: {:decimal, ^bitwidth, ^precision, ^scale}, + nullable: true, + metadata: nil, + data: [nil], + length: nil, + offset: nil + } = Adbc.Column.materialize(decimal_with_nil) + end + test "floats" do value = 12345