Skip to content

Commit

Permalink
chore: PR review refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
Ziinc committed May 10, 2024
1 parent 88d9ee0 commit 456e382
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 25 deletions.
21 changes: 11 additions & 10 deletions lib/logflare/backends/source_sup.ex
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,17 @@ defmodule Logflare.Backends.SourceSup do
end

specs =
([
%Backend{
type: :bigquery,
config: %{
project_id: project_id,
dataset_id: dataset_id
}
}
| ingest_backends
] ++ rules_backends)
[
%Backend{
type: :bigquery,
config: %{
project_id: project_id,
dataset_id: dataset_id
}
}
| ingest_backends
]
|> Enum.concat(rules_backends)
|> Enum.map(&Backend.child_spec(source, &1))
|> Enum.uniq()

Expand Down
21 changes: 9 additions & 12 deletions lib/logflare/logs/lql/lql_parser.ex
Original file line number Diff line number Diff line change
Expand Up @@ -170,19 +170,16 @@ defmodule Logflare.Lql.Parser do
defp maybe_cast_value(%{value: "false"} = c), do: %{c | value: false}

defp maybe_cast_value(%{value: v} = c) do
int = Integer.parse(v)
flt = Float.parse(v)

parsed =
cond do
match?({_val, ""}, int) ->
elem(int, 0)

match?({_val, ""}, flt) ->
elem(flt, 0)

true ->
v
case Integer.parse(v) do
{num, ""} ->
num

_ ->
case Float.parse(v) do
{num, ""} -> num
_ -> v
end
end

%{c | value: parsed}
Expand Down
4 changes: 1 addition & 3 deletions lib/logflare/utils.ex
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,10 @@ defmodule Logflare.Utils do
"""
@spec stringify_keys(map()) :: map()
def stringify_keys(map = %{}) do
map
|> Enum.map(fn
Map.new(map, fn
{k, v} when is_atom(k) -> {Atom.to_string(k), stringify_keys(v)}
{k, v} when is_binary(k) -> {k, stringify_keys(v)}
end)
|> Enum.into(%{})
end

def stringify_keys([head | rest]) do
Expand Down

0 comments on commit 456e382

Please sign in to comment.