Skip to content

Commit

Permalink
Add function clause for %FSS.HTTP.Entry{} (#992)
Browse files Browse the repository at this point in the history
* Add function clause for `%FSS.HTTP.Entry{}`

* Add a test

* Clarify return type in comments

* Whoops, fix typo
  • Loading branch information
billylanchantin authored Sep 24, 2024
1 parent 9910365 commit ee0d4ae
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/explorer/data_frame.ex
Original file line number Diff line number Diff line change
Expand Up @@ -842,6 +842,7 @@ defmodule Explorer.DataFrame do
end

defp normalise_entry(%Local.Entry{} = entry, nil), do: {:ok, entry}
defp normalise_entry(%HTTP.Entry{} = entry, nil), do: {:ok, entry}
defp normalise_entry(%S3.Entry{config: %S3.Config{}} = entry, nil), do: {:ok, entry}

defp normalise_entry("s3://" <> _rest = entry, config) do
Expand Down
22 changes: 22 additions & 0 deletions test/explorer/data_frame/parquet_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,28 @@ defmodule Explorer.DataFrame.ParquetTest do
assert DF.to_columns(df1) == DF.to_columns(df)
end

test "reads a parquet file from an FSS entry", %{bypass: bypass, df: df_expected} do
# Setup a `GET` expectation for `path` that returns the expected
# DataFrame as a `parquet` binary.
path = "/path/to/file.parquet"
authorization = "Bearer my-token"

Bypass.expect(bypass, "GET", path, fn conn ->
assert [^authorization] = Plug.Conn.get_req_header(conn, "authorization")
bytes = Explorer.DataFrame.dump_parquet!(df_expected)
Plug.Conn.resp(conn, 200, bytes)
end)

# Build an `%FSS.HTTP.Entry{}` for `path` manually.
url = bypass |> http_endpoint() |> Path.join(path)
config = [headers: [{"authorization", authorization}]]
{:ok, %FSS.HTTP.Entry{} = entry} = FSS.HTTP.parse(url, config: config)

# Assert that we can read the parquet binary from that entry.
{:ok, df_actual} = DF.from_parquet(entry)
assert DF.to_columns(df_expected) == DF.to_columns(df_actual)
end

test "cannot find a parquet file", %{bypass: bypass} do
Bypass.expect(bypass, "GET", "/path/to/file.parquet", fn conn ->
Plug.Conn.resp(conn, 404, "not found")
Expand Down

0 comments on commit ee0d4ae

Please sign in to comment.