-
Notifications
You must be signed in to change notification settings - Fork 146
Expand file tree
/
Copy pathsql_context.ex
More file actions
37 lines (28 loc) · 1022 Bytes
/
sql_context.ex
File metadata and controls
37 lines (28 loc) · 1022 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
defmodule Explorer.PolarsBackend.SQLContext do
@moduledoc false
defstruct resource: nil
alias Explorer.Native
alias Explorer.PolarsBackend.Native
alias Explorer.PolarsBackend.Shared
@type t :: %__MODULE__{resource: reference()}
@behaviour Explorer.Backend.SQLContext
def new() do
ctx = Native.sql_context_new()
Explorer.Backend.SQLContext.new(ctx)
end
def register(%Explorer.SQLContext{ctx: ctx} = context, name, %Explorer.DataFrame{data: df}) do
Native.sql_context_register(ctx, name, df)
context
end
def unregister(%Explorer.SQLContext{ctx: ctx} = context, name) do
Native.sql_context_unregister(ctx, name)
context
end
def execute(%Explorer.SQLContext{ctx: ctx}, query) do
case Native.sql_context_execute(ctx, query) do
{:ok, polars_ldf} -> Shared.create_dataframe(polars_ldf)
{:error, error} -> {:error, RuntimeError.exception(error)}
end
end
def get_tables(%Explorer.SQLContext{ctx: ctx}), do: Native.sql_context_get_tables(ctx)
end