2
2
ArrowSubstraitCompiler <- R6 :: R6Class(
3
3
" ArrowSubstraitCompiler" ,
4
4
inherit = SubstraitCompiler ,
5
+ private = list (extension_uri = NULL ),
5
6
public = list (
6
7
initialize = function (... ) {
7
8
super $ initialize(... )
8
- self $ .fns = arrow_funs
9
+ self $ .fns <- arrow_funs
10
+ private $ extension_uri <- list (
11
+ " arithmetic" = substrait $ extensions $ SimpleExtensionURI $ create(
12
+ extension_uri_anchor = 1L ,
13
+ uri = " https://github.com/substrait-io/substrait/blob/main/extensions/functions_arithmetic.yaml"
14
+ ),
15
+ " comparison" = substrait $ extensions $ SimpleExtensionURI $ create(
16
+ extension_uri_anchor = 2L ,
17
+ uri = " https://github.com/substrait-io/substrait/blob/main/extensions/functions_comparison.yaml"
18
+ )
19
+ )
20
+ },
21
+ extension_uri_anchor = function (name ) {
22
+ prefix <- strsplit(name , " ." , fixed = TRUE )[[1 ]][1 ]
23
+ private $ extension_uri [[prefix ]]$ extension_uri_anchor
9
24
},
10
25
evaluate = function (... ) {
11
26
plan <- self $ plan()
12
27
13
- # Here we only implement 'add()', so this works because the only
14
- # function that we ever use is contained in this extensions definition.
15
- plan $ extension_uris [[1 ]]$ uri <-
16
- " https://github.com/substrait-io/substrait/blob/main/extensions/functions_arithmetic.yaml"
17
-
18
28
substrait_eval_arrow(
19
29
plan = plan ,
20
30
tables = self $ named_table_list(),
21
31
col_names = self $ schema $ names
22
32
)
33
+ },
34
+ plan = function () {
35
+ plan <- super $ plan()
36
+
37
+ for (i in seq_along(plan $ extensions )) {
38
+ if (is.null(plan $ extensions [[i ]]$ extension_function )) {
39
+ next
40
+ }
41
+
42
+ short_name <- strsplit(plan $ extensions [[i ]]$ extension_function $ name , " ." , fixed = TRUE )[[1 ]][2 ]
43
+ plan $ extensions [[i ]]$ extension_function $ name <- short_name
44
+ }
45
+
46
+ plan
23
47
}
24
48
)
25
49
)
@@ -29,7 +53,7 @@ arrow_funs <- new.env(parent = emptyenv())
29
53
30
54
arrow_funs [[" +" ]] <- function (lhs , rhs ) {
31
55
substrait_call(
32
- " add" ,
56
+ " arithmetic. add" ,
33
57
substrait $ FunctionArgument $ create(
34
58
enum_ = substrait $ FunctionArgument $ Enum $ create(unspecified = substrait_proto_auto())
35
59
),
@@ -39,6 +63,15 @@ arrow_funs[["+"]] <- function(lhs, rhs) {
39
63
)
40
64
}
41
65
66
+ arrow_funs [[" >" ]] <- function (lhs , rhs ) {
67
+ substrait_call(
68
+ " comparison.gt" ,
69
+ lhs ,
70
+ rhs ,
71
+ .output_type = substrait_boolean()
72
+ )
73
+ }
74
+
42
75
# ' Create an Arrow Substrait Compiler
43
76
# '
44
77
# ' @param object A [data.frame()], [arrow::Table], [arrow::RecordBatch],
@@ -198,7 +231,6 @@ from_substrait.RecordBatch <- function(msg, x, ...) {
198
231
199
232
substrait_eval_arrow <- function (plan , tables , col_names ) {
200
233
stopifnot(has_arrow_with_substrait())
201
-
202
234
plan <- as_substrait(plan , " substrait.Plan" )
203
235
stopifnot(rlang :: is_named2(tables ))
204
236
0 commit comments