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

Fix filter compile error when wrong quote #49

Merged
merged 1 commit into from
Jan 24, 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
9 changes: 5 additions & 4 deletions lib/ex_aliyun_ots/filter.ex
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ defmodule ExAliyunOts.Filter do

quote do
%Filter{
type: FilterType.composite_column(),
type: unquote(FilterType.composite_column()),
filter: %CompositeColumnValueFilter{
combinator: unquote(combinator),
sub_filters: unquote(sub_filters)
Expand All @@ -105,12 +105,13 @@ defmodule ExAliyunOts.Filter do

defp single_filter({comparator, _, [column_name, column_value]}) do
comparator = @comparator_mapping[comparator]
filter_type = FilterType.single_column()

quote location: :keep, bind_quoted: [column_name: column_name, column_value: column_value, comparator: comparator] do
quote location: :keep, bind_quoted: [column_name: column_name, column_value: column_value, comparator: comparator, filter_type: filter_type] do
case column_name do
{column_name, column_options} ->
%Filter{
type: FilterType.single_column(),
type: filter_type,
filter: %SingleColumnValueFilter{
comparator: comparator,
column_name: column_name,
Expand All @@ -123,7 +124,7 @@ defmodule ExAliyunOts.Filter do

column_name ->
%Filter{
type: FilterType.single_column(),
type: filter_type,
filter: %SingleColumnValueFilter{
comparator: comparator,
column_name: column_name,
Expand Down
11 changes: 11 additions & 0 deletions test/mixin/filter_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -123,4 +123,15 @@ defmodule ExAliyunOts.MixinTest.Filter do
)
end
end

test "build filter to ensure successfully quoted" do
{%ExAliyunOts.TableStoreFilter.Filter{filter: filter, type: type}, _} = ExAliyunOts.Filter.build_filter({:==, "some", [:a, 1]}) |> Code.eval_quoted()
assert filter.column_name == :a and filter.column_value == 1 and type == :FT_SINGLE_COLUMN_VALUE

{%ExAliyunOts.TableStoreFilter.Filter{filter: filter, type: type}, _} = ExAliyunOts.Filter.build_filter({:and, "some", [{:==, "some", [:b, 2]}, {:>=, "some", [:c, 10]}]}) |> Code.eval_quoted()
assert type == :FT_COMPOSITE_COLUMN_VALUE
[%{filter: sub1}, %{filter: sub2}] = filter.sub_filters
assert sub1.comparator == :CT_EQUAL and sub1.column_name == :b and sub1.column_value == 2
assert sub2.comparator == :CT_GREATER_EQUAL and sub2.column_name == :c and sub2.column_value == 10
end
end