From b913f9fd1e8f14086e76677d95764aae71583237 Mon Sep 17 00:00:00 2001 From: Dario Di Pasquale Date: Tue, 9 May 2023 10:15:41 +0200 Subject: [PATCH 1/2] drop convert_null_values --- README.md | 3 --- config/config.exs | 1 - lib/avrora/avro_decoder_options.ex | 4 +--- lib/avrora/client.ex | 1 - lib/avrora/config.ex | 5 ----- test/avrora/codec/object_container_file_test.exs | 4 +--- test/avrora/codec/plain_test.exs | 4 +--- test/support/config.ex | 2 -- 8 files changed, 3 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index c79edaf2..6e63fbe5 100644 --- a/README.md +++ b/README.md @@ -89,7 +89,6 @@ defmodule MyClient do registry_user_agent: "Avrora/0.25.0 Elixir", schemas_path: "./priv/schemas", registry_schemas_autoreg: false, - convert_null_values: false, convert_map_to_proplist: false, names_cache_ttl: :timer.minutes(5), decoder_hook: &MyClient.decoder_hook/4 @@ -110,7 +109,6 @@ config :avrora, registry_user_agent: "Avrora/0.24.2 Elixir", # optional: if you want to return previous behaviour, set it to `nil` schemas_path: "./priv/schemas", registry_schemas_autoreg: false, # optional: if you want manually register schemas - convert_null_values: false, # optional: if you want to keep decoded `:null` values as is convert_map_to_proplist: false, # optional: if you want to restore the old behavior for decoding map-type names_cache_ttl: :timer.minutes(5), # optional: if you want periodic disk reads decoder_hook: &MyClient.decoder_hook/4 # optional: if you want to amend the data/result @@ -122,7 +120,6 @@ config :avrora, - `registry_user_agent`[v0.25] - HTTP `User-Agent` header for Schema Registry requests, default `Avrora/ Elixir` - `schemas_path` - Base path for locally stored schema files, default `./priv/schemas` - `registry_schemas_autoreg`[v0.13] - Flag for automatic schemas registration in the Schema Registry, default `true` -- `convert_null_values`[v0.14] - Flag for automatic conversion of decoded `:null` values into `nil`, default `true` - `convert_map_to_proplist`[v0.15] restore old behaviour and confiugre decoding map-type to proplist, default `false` - `names_cache_ttl`[v0.10] - Time in ms to cache schemas by name in memory, default `:infinity` - `decoder_hook`[v0.24] - Function with arity 4 to amend data or result, default `fn _, _, data, fun -> fun.(data) end` diff --git a/config/config.exs b/config/config.exs index 8e1cc952..d3228498 100644 --- a/config/config.exs +++ b/config/config.exs @@ -6,7 +6,6 @@ config :avrora, registry_auth: nil, registry_user_agent: nil, registry_schemas_autoreg: true, - convert_null_values: true, names_cache_ttl: :infinity config :logger, :console, format: "$time $metadata[$level] $levelpad$message\n" diff --git a/lib/avrora/avro_decoder_options.ex b/lib/avrora/avro_decoder_options.ex index f141222a..eb2c8cce 100644 --- a/lib/avrora/avro_decoder_options.ex +++ b/lib/avrora/avro_decoder_options.ex @@ -25,17 +25,15 @@ defmodule Avrora.AvroDecoderOptions do # NOTE: This is internal module function and should never be used directly @doc false def __hook__(type, sub_name_or_idx, data, decode_fun) do - convert = convert_null_values() decoder_hook = decoder_hook() result = decoder_hook.(type, sub_name_or_idx, data, decode_fun) - if convert == true && :avro.get_type_name(type) == @null_type_name, + if :avro.get_type_name(type) == @null_type_name, do: {nil, data}, else: result end - defp convert_null_values, do: Config.self().convert_null_values() defp convert_map_to_proplist, do: Config.self().convert_map_to_proplist() defp decoder_hook, do: Config.self().decoder_hook() end diff --git a/lib/avrora/client.ex b/lib/avrora/client.ex index 5a45f307..d098d41d 100644 --- a/lib/avrora/client.ex +++ b/lib/avrora/client.ex @@ -113,7 +113,6 @@ defmodule Avrora.Client do def registry_auth, do: get(@opts, :registry_auth, nil) def registry_user_agent, do: get(@opts, :registry_user_agent, "Avrora/#{version()} Elixir") def registry_schemas_autoreg, do: get(@opts, :registry_schemas_autoreg, true) - def convert_null_values, do: get(@opts, :convert_null_values, true) def convert_map_to_proplist, do: get(@opts, :convert_map_to_proplist, false) def names_cache_ttl, do: get(@opts, :names_cache_ttl, :infinity) def decoder_hook, do: get(@opts, :decoder_hook, fn _, _, data, fun -> fun.(data) end) diff --git a/lib/avrora/config.ex b/lib/avrora/config.ex index 8c120ed1..68fecc55 100644 --- a/lib/avrora/config.ex +++ b/lib/avrora/config.ex @@ -10,7 +10,6 @@ defmodule Avrora.Config do * `registry_auth` authentication settings for Schema Registry, default `nil` * `registry_user_agent` HTTP `User-Agent` header for Schema Registry requests, default `Avrora/ Elixir` * `registry_schemas_autoreg` automatically register schemas in Schema Registry, default `true` - * `convert_null_values` convert `:null` values in the decoded message into `nil`, default `true` * `convert_map_to_proplist` bring back old behavior and configure decoding AVRO map-type as proplist, default `false` * `names_cache_ttl` duration to cache global schema names millisecods, default `:infinity` * `decoder_hook` function to amend decoded payload, default `fn _, _, data, fun -> fun.(data) end` @@ -29,7 +28,6 @@ defmodule Avrora.Config do @callback registry_auth :: tuple() | nil @callback registry_user_agent :: String.t() | nil @callback registry_schemas_autoreg :: boolean() - @callback convert_null_values :: boolean() @callback convert_map_to_proplist :: boolean() @callback names_cache_ttl :: integer() | atom() @callback decoder_hook :: (any(), any(), any(), any() -> any()) @@ -59,9 +57,6 @@ defmodule Avrora.Config do @doc false def registry_schemas_autoreg, do: get_env(:registry_schemas_autoreg, true) - @doc false - def convert_null_values, do: get_env(:convert_null_values, true) - @doc false def convert_map_to_proplist, do: get_env(:convert_map_to_proplist, false) diff --git a/test/avrora/codec/object_container_file_test.exs b/test/avrora/codec/object_container_file_test.exs index 75ee4f97..4a71fe57 100644 --- a/test/avrora/codec/object_container_file_test.exs +++ b/test/avrora/codec/object_container_file_test.exs @@ -77,11 +77,9 @@ defmodule Avrora.Codec.ObjectContainerFileTest do end test "when payload is a valid binary and null values must be as is" do - stub(Avrora.ConfigMock, :convert_null_values, fn -> false end) - {:ok, decoded} = Codec.ObjectContainerFile.decode(null_value_message(), schema: null_value_schema()) - assert decoded == [%{"key" => "user-1", "value" => :null}] + assert decoded == [%{"key" => "user-1", "value" => nil}] end test "when payload is a valid binary and null values must be converted" do diff --git a/test/avrora/codec/plain_test.exs b/test/avrora/codec/plain_test.exs index c35549d6..9a9eb07f 100644 --- a/test/avrora/codec/plain_test.exs +++ b/test/avrora/codec/plain_test.exs @@ -78,11 +78,9 @@ defmodule Avrora.Codec.PlainTest do end test "when payload is a valid binary and null values must be as is" do - stub(Avrora.ConfigMock, :convert_null_values, fn -> false end) - {:ok, decoded} = Codec.Plain.decode(null_value_message(), schema: null_value_schema()) - assert decoded == %{"key" => "user-1", "value" => :null} + assert decoded == %{"key" => "user-1", "value" => nil} end test "when payload is a valid binary and null values must be converted" do diff --git a/test/support/config.ex b/test/support/config.ex index 184431f3..1158f2b2 100644 --- a/test/support/config.ex +++ b/test/support/config.ex @@ -44,8 +44,6 @@ defmodule Support.Config do @impl true def registry_schemas_autoreg, do: true @impl true - def convert_null_values, do: true - @impl true def names_cache_ttl, do: :infinity @impl true def decoder_hook, do: fn _, _, data, fun -> fun.(data) end From 414ece290691af577fc1c10cb255180565f5c872 Mon Sep 17 00:00:00 2001 From: Dario Di Pasquale Date: Tue, 9 May 2023 10:19:26 +0200 Subject: [PATCH 2/2] drop convert_map_to_proplist --- README.md | 3 --- lib/avrora/avro_decoder_options.ex | 16 +++++++--------- lib/avrora/client.ex | 1 - lib/avrora/config.ex | 5 ----- test/avrora/codec/object_container_file_test.exs | 8 -------- test/avrora/codec/plain_test.exs | 8 -------- test/support/config.ex | 2 -- 7 files changed, 7 insertions(+), 36 deletions(-) diff --git a/README.md b/README.md index 6e63fbe5..9e554361 100644 --- a/README.md +++ b/README.md @@ -89,7 +89,6 @@ defmodule MyClient do registry_user_agent: "Avrora/0.25.0 Elixir", schemas_path: "./priv/schemas", registry_schemas_autoreg: false, - convert_map_to_proplist: false, names_cache_ttl: :timer.minutes(5), decoder_hook: &MyClient.decoder_hook/4 end @@ -109,7 +108,6 @@ config :avrora, registry_user_agent: "Avrora/0.24.2 Elixir", # optional: if you want to return previous behaviour, set it to `nil` schemas_path: "./priv/schemas", registry_schemas_autoreg: false, # optional: if you want manually register schemas - convert_map_to_proplist: false, # optional: if you want to restore the old behavior for decoding map-type names_cache_ttl: :timer.minutes(5), # optional: if you want periodic disk reads decoder_hook: &MyClient.decoder_hook/4 # optional: if you want to amend the data/result ``` @@ -120,7 +118,6 @@ config :avrora, - `registry_user_agent`[v0.25] - HTTP `User-Agent` header for Schema Registry requests, default `Avrora/ Elixir` - `schemas_path` - Base path for locally stored schema files, default `./priv/schemas` - `registry_schemas_autoreg`[v0.13] - Flag for automatic schemas registration in the Schema Registry, default `true` -- `convert_map_to_proplist`[v0.15] restore old behaviour and confiugre decoding map-type to proplist, default `false` - `names_cache_ttl`[v0.10] - Time in ms to cache schemas by name in memory, default `:infinity` - `decoder_hook`[v0.24] - Function with arity 4 to amend data or result, default `fn _, _, data, fun -> fun.(data) end` diff --git a/lib/avrora/avro_decoder_options.ex b/lib/avrora/avro_decoder_options.ex index eb2c8cce..9123faa4 100644 --- a/lib/avrora/avro_decoder_options.ex +++ b/lib/avrora/avro_decoder_options.ex @@ -6,20 +6,19 @@ defmodule Avrora.AvroDecoderOptions do alias Avrora.Config - @options %{ - encoding: :avro_binary, - hook: &__MODULE__.__hook__/4, - is_wrapped: true, - map_type: :map, - record_type: :map - } @null_type_name "null" @doc """ A unified erlavro decoder options compatible for both binary and OCF decoders. """ def options do - if convert_map_to_proplist(), do: %{@options | map_type: :proplist}, else: @options + %{ + encoding: :avro_binary, + hook: &__MODULE__.__hook__/4, + is_wrapped: true, + map_type: :map, + record_type: :map + } end # NOTE: This is internal module function and should never be used directly @@ -34,6 +33,5 @@ defmodule Avrora.AvroDecoderOptions do else: result end - defp convert_map_to_proplist, do: Config.self().convert_map_to_proplist() defp decoder_hook, do: Config.self().decoder_hook() end diff --git a/lib/avrora/client.ex b/lib/avrora/client.ex index d098d41d..dd81c5d8 100644 --- a/lib/avrora/client.ex +++ b/lib/avrora/client.ex @@ -113,7 +113,6 @@ defmodule Avrora.Client do def registry_auth, do: get(@opts, :registry_auth, nil) def registry_user_agent, do: get(@opts, :registry_user_agent, "Avrora/#{version()} Elixir") def registry_schemas_autoreg, do: get(@opts, :registry_schemas_autoreg, true) - def convert_map_to_proplist, do: get(@opts, :convert_map_to_proplist, false) def names_cache_ttl, do: get(@opts, :names_cache_ttl, :infinity) def decoder_hook, do: get(@opts, :decoder_hook, fn _, _, data, fun -> fun.(data) end) def file_storage, do: unquote(:"Elixir.#{module}.Storage.File") diff --git a/lib/avrora/config.ex b/lib/avrora/config.ex index 68fecc55..4e1478dc 100644 --- a/lib/avrora/config.ex +++ b/lib/avrora/config.ex @@ -10,7 +10,6 @@ defmodule Avrora.Config do * `registry_auth` authentication settings for Schema Registry, default `nil` * `registry_user_agent` HTTP `User-Agent` header for Schema Registry requests, default `Avrora/ Elixir` * `registry_schemas_autoreg` automatically register schemas in Schema Registry, default `true` - * `convert_map_to_proplist` bring back old behavior and configure decoding AVRO map-type as proplist, default `false` * `names_cache_ttl` duration to cache global schema names millisecods, default `:infinity` * `decoder_hook` function to amend decoded payload, default `fn _, _, data, fun -> fun.(data) end` @@ -28,7 +27,6 @@ defmodule Avrora.Config do @callback registry_auth :: tuple() | nil @callback registry_user_agent :: String.t() | nil @callback registry_schemas_autoreg :: boolean() - @callback convert_map_to_proplist :: boolean() @callback names_cache_ttl :: integer() | atom() @callback decoder_hook :: (any(), any(), any(), any() -> any()) @callback file_storage :: module() @@ -57,9 +55,6 @@ defmodule Avrora.Config do @doc false def registry_schemas_autoreg, do: get_env(:registry_schemas_autoreg, true) - @doc false - def convert_map_to_proplist, do: get_env(:convert_map_to_proplist, false) - @doc false def names_cache_ttl, do: get_env(:names_cache_ttl, :infinity) diff --git a/test/avrora/codec/object_container_file_test.exs b/test/avrora/codec/object_container_file_test.exs index 4a71fe57..b95d1339 100644 --- a/test/avrora/codec/object_container_file_test.exs +++ b/test/avrora/codec/object_container_file_test.exs @@ -88,14 +88,6 @@ defmodule Avrora.Codec.ObjectContainerFileTest do assert decoded == [%{"key" => "user-1", "value" => nil}] end - test "when payload is a valid binary and map type must be decoded as proplist" do - stub(Avrora.ConfigMock, :convert_map_to_proplist, fn -> true end) - - {:ok, decoded} = Codec.ObjectContainerFile.decode(map_message()) - - assert decoded == [%{"map_field" => [{"key", "value"}]}] - end - test "when payload is a valid binary and map type must be decoded as map" do {:ok, decoded} = Codec.ObjectContainerFile.decode(map_message()) diff --git a/test/avrora/codec/plain_test.exs b/test/avrora/codec/plain_test.exs index 9a9eb07f..67670e4c 100644 --- a/test/avrora/codec/plain_test.exs +++ b/test/avrora/codec/plain_test.exs @@ -89,14 +89,6 @@ defmodule Avrora.Codec.PlainTest do assert decoded == %{"key" => "user-1", "value" => nil} end - test "when payload is a valid binary and map type must be decoded as proplist" do - stub(Avrora.ConfigMock, :convert_map_to_proplist, fn -> true end) - - {:ok, decoded} = Codec.Plain.decode(map_message(), schema: map_schema()) - - assert decoded == %{"map_field" => [{"key", "value"}]} - end - test "when payload is a valid binary and map type must be decoded as map" do {:ok, decoded} = Codec.Plain.decode(map_message(), schema: map_schema()) diff --git a/test/support/config.ex b/test/support/config.ex index 1158f2b2..0d7d8529 100644 --- a/test/support/config.ex +++ b/test/support/config.ex @@ -48,8 +48,6 @@ defmodule Support.Config do @impl true def decoder_hook, do: fn _, _, data, fun -> fun.(data) end @impl true - def convert_map_to_proplist, do: false - @impl true def file_storage, do: Avrora.Storage.FileMock @impl true def memory_storage, do: Avrora.Storage.MemoryMock