FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
datafusion-java/native/src/avro.rs at main · andygrove/datafusion-java · GitHub
andygrove
datafusion-java
Repository navigation
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
datafusion-java
/
native
/
src
/
avro.rs
Copy path
More file actions
More file actions
Latest commit
History
History
History
104 lines (96 loc) · 3.72 KB
Breadcrumbs
datafusion-java
/
native
/
src
/
avro.rs
Copy path
File metadata and controls
104 lines (96 loc) · 3.72 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
use
datafusion
::
error
::
DataFusionError
;
use
datafusion
::
execution
::
options
::
AvroReadOptions
;
use
datafusion
::
prelude
::
SessionContext
;
use
jni
::
objects
::
{
JByteArray
,
JClass
,
JString
}
;
use
jni
::
sys
::
jlong
;
use
jni
::
JNIEnv
;
use
prost
::
Message
;
use
crate
::
errors
::
{
try_unwrap_or_throw
,
JniResult
}
;
use
crate
::
proto_gen
::
AvroReadOptionsProto
;
use
crate
::
runtime
;
use
crate
::
schema
::
decode_optional_schema
;
fn
with_avro_options
<
R
>
(
env
:
&
mut
JNIEnv
,
options_bytes
:
JByteArray
,
schema_ipc_bytes
:
JByteArray
,
f
:
impl
FnOnce
(
AvroReadOptions
)
->
JniResult
<
R
>
,
)
->
JniResult
<
R
>
{
let
bytes
:
Vec
<
u8
>
= env
.
convert_byte_array
(
&
options_bytes
)
?
;
let
p =
AvroReadOptionsProto
::
decode
(
bytes
.
as_slice
(
)
)
?
;
let
schema =
decode_optional_schema
(
env
,
schema_ipc_bytes
)
?
;
// AvroReadOptions exposes `file_extension` as a public field (not a builder
// setter); `schema` is the only field with a fluent setter. Build via
// struct-update syntax to avoid clippy::field_reassign_with_default.
let
file_ext = p
.
file_extension
;
let
mut
opts =
AvroReadOptions
{
file_extension
:
&
file_ext
,
..
AvroReadOptions
::
default
(
)
}
;
if
let
Some
(
ref
s
)
= schema
{
opts = opts
.
schema
(
s
)
;
}
f
(
opts
)
}
#
[
no_mangle
]
pub
extern
"system"
fn
Java_org_apache_datafusion_SessionContext_registerAvroWithOptions
<
'
local
>
(
mut
env
:
JNIEnv
<
'
local
>
,
_class
:
JClass
<
'
local
>
,
handle
:
jlong
,
name
:
JString
<
'
local
>
,
path
:
JString
<
'
local
>
,
options_bytes
:
JByteArray
<
'
local
>
,
schema_ipc_bytes
:
JByteArray
<
'
local
>
,
)
{
try_unwrap_or_throw
(
&
mut
env
,
(
)
,
|env| ->
JniResult
<
(
)
>
{
if
handle ==
0
{
return
Err
(
"SessionContext handle is null"
.
into
(
)
)
;
}
let
ctx =
unsafe
{
&
*
(
handle
as
*
const
SessionContext
)
}
;
let
name
:
String
= env
.
get_string
(
&
name
)
?
.
into
(
)
;
let
path
:
String
= env
.
get_string
(
&
path
)
?
.
into
(
)
;
with_avro_options
(
env
,
options_bytes
,
schema_ipc_bytes
,
|opts|
{
runtime
(
)
.
block_on
(
async
{
ctx
.
register_avro
(
&
name
,
&
path
,
opts
)
.
await
?
;
Ok
::
<
(
)
,
DataFusionError
>
(
(
)
)
}
)
?
;
Ok
(
(
)
)
}
)
}
)
}
#
[
no_mangle
]
pub
extern
"system"
fn
Java_org_apache_datafusion_SessionContext_readAvroWithOptions
<
'
local
>
(
mut
env
:
JNIEnv
<
'
local
>
,
_class
:
JClass
<
'
local
>
,
handle
:
jlong
,
path
:
JString
<
'
local
>
,
options_bytes
:
JByteArray
<
'
local
>
,
schema_ipc_bytes
:
JByteArray
<
'
local
>
,
)
->
jlong
{
try_unwrap_or_throw
(
&
mut
env
,
0
,
|env| ->
JniResult
<
jlong
>
{
if
handle ==
0
{
return
Err
(
"SessionContext handle is null"
.
into
(
)
)
;
}
let
ctx =
unsafe
{
&
*
(
handle
as
*
const
SessionContext
)
}
;
let
path
:
String
= env
.
get_string
(
&
path
)
?
.
into
(
)
;
with_avro_options
(
env
,
options_bytes
,
schema_ipc_bytes
,
|opts|
{
let
df =
runtime
(
)
.
block_on
(
ctx
.
read_avro
(
path
,
opts
)
)
?
;
Ok
(
Box
::
into_raw
(
Box
::
new
(
df
)
)
as
jlong
)
}
)
}
)
}
Back
|
FazBrowse Home
|
New Git URL