Skip to content

Commit

Permalink
Switches nil values to delete columns instead of filling with empty s…
Browse files Browse the repository at this point in the history
…tring. Change made to integrate better with BigQuery adapter in short term
  • Loading branch information
jscott22 committed Feb 2, 2019
1 parent 280b80f commit fb5be0a
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 3 deletions.
14 changes: 12 additions & 2 deletions lib/typed/mutations.ex
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,21 @@ defmodule Bigtable.Typed.Mutations do

_ ->
accum
|> Bigtable.Mutations.set_cell(family_name, column_qualifier, v)
|> add_cell_mutation(family_name, column_qualifier, v)
end
end)
end

defp add_cell_mutation(accum, family_name, column_qualifier, nil) do
accum
|> Bigtable.Mutations.delete_from_column(family_name, column_qualifier)
end

defp add_cell_mutation(accum, family_name, column_qualifier, value) do
accum
|> Bigtable.Mutations.set_cell(family_name, column_qualifier, value)
end

defp nested_map(type, value, accum, family_name, column_qualifier) do
if value == nil or value == "" do
niled_map = nil_values(type)
Expand All @@ -55,7 +65,7 @@ defmodule Bigtable.Typed.Mutations do
if is_map(v) do
Map.put(accum, k, nil_values(v))
else
Map.put(accum, k, "")
Map.put(accum, k, nil)
end
end)
end
Expand Down
64 changes: 63 additions & 1 deletion test/typed/mutations_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,69 @@ defmodule TypedMutationsTest do
}
}

expected = expected_entry("", "")
expected = %Google.Bigtable.V2.MutateRowsRequest.Entry{
row_key: "Test#1",
mutations: [
%Google.Bigtable.V2.Mutation{
mutation:
{:set_cell,
%Google.Bigtable.V2.Mutation.SetCell{
column_qualifier: "test_column",
family_name: "test_family",
timestamp_micros: -1,
value: "false"
}}
},
%Google.Bigtable.V2.Mutation{
mutation:
{:delete_from_column,
%Google.Bigtable.V2.Mutation.DeleteFromColumn{
column_qualifier: "test_nested.double_nested.double_nested_a",
family_name: "test_family",
time_range: %Google.Bigtable.V2.TimestampRange{
end_timestamp_micros: 0,
start_timestamp_micros: 0
}
}}
},
%Google.Bigtable.V2.Mutation{
mutation:
{:delete_from_column,
%Google.Bigtable.V2.Mutation.DeleteFromColumn{
column_qualifier: "test_nested.double_nested.double_nested_b",
family_name: "test_family",
time_range: %Google.Bigtable.V2.TimestampRange{
end_timestamp_micros: 0,
start_timestamp_micros: 0
}
}}
},
%Google.Bigtable.V2.Mutation{
mutation:
{:delete_from_column,
%Google.Bigtable.V2.Mutation.DeleteFromColumn{
column_qualifier: "test_nested.nested_a",
family_name: "test_family",
time_range: %Google.Bigtable.V2.TimestampRange{
end_timestamp_micros: 0,
start_timestamp_micros: 0
}
}}
},
%Google.Bigtable.V2.Mutation{
mutation:
{:delete_from_column,
%Google.Bigtable.V2.Mutation.DeleteFromColumn{
column_qualifier: "test_nested.nested_b",
family_name: "test_family",
time_range: %Google.Bigtable.V2.TimestampRange{
end_timestamp_micros: 0,
start_timestamp_micros: 0
}
}}
}
]
}

result = Mutations.create_mutations(context.row_key, context.type_spec, map)

Expand Down

0 comments on commit fb5be0a

Please sign in to comment.