Closed cocoa-xu closed 3 months ago
I wonder if we should introduce a proper buffer API instead. IIRC, for bulk inserts, each column is an arrow buffer. So maybe we should have: ADBC.Buffer.u8([0, 2, 3])
and so forth.
So the supported arguments would be:
[
123, # int64, inferred
"string", # string, inferred
4.56, # double, inferred
true, # bool, inferred
false, # bool, inferred
nil, # na, inferred
%ADBC.Buffer{}
]
Then, for named arguments, we support either maps or keyword lists. Then we can also provide query APIs that return buffers, this way we can easily pass the result of a query to another query. WDYT?
I wonder if we should introduce a proper buffer API instead. IIRC, for bulk inserts, each column is an arrow buffer. So maybe we should have:
ADBC.Buffer.u8([0, 2, 3])
and so forth.So the supported arguments would be:
[ 123, # int64, inferred "string", # string, inferred 4.56, # double, inferred true, # bool, inferred false, # bool, inferred nil, # na, inferred %ADBC.Buffer{} ]
Then, for named arguments, we support either maps or keyword lists. Then we can also provide query APIs that return buffers, this way we can easily pass the result of a query to another query. WDYT?
Ahh, ADBC.Buffer
sounds definitely better! I'll try to implement it and send a PR :)
Database like Google BigQuery also supports named parameters in SQL queries:
To support named parameters, we need to change
elixir_to_arrow_type_struct
inadbc_nif.cpp
and allow users to pass a map/keyword list:positional parameters: This is the first case and basically what we're supporting now, which is a list where each element's type can be one of
number()
,binary()
,boolean()
andnil
.And users cannot specify the type of their parameters.
Therefore, one possible way is to use a 2-tuple,
{type, value}
, where the first element specifies the type and the second one is the corresponding value. And we can infer their types if not specified. For now, we can prioritise the support for most basic types.The possible value for
type
can be one of:i8
:i16
:i32
:i64
:u8
:u16
:u32
:u64
:f16
:f32
:f64
:string
:binary
:boolean
nil
We can add support for complex types like list and struct later.
the above example corresponds to a 1-row-11-column arrow record. For databases that support bulk inserts, we can pass a list for each column:
the above example corresponds to a 3-row-11-column arrow record.
Of course, each column should have the same length and these values in a column should have the same types (except for
nil
if the column is nullable)named parameters: This is the second case where it should be a map or keyword list, similar to the first case, but the keys are column names, e.g.,
the above example corresponds to a 1-row-4-column arrow record.
As for bulk inserts, we'd have
the above example corresponds to a 3-row-4-column arrow record.