You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The duckplyr package aims at providing a fully compatible drop-in replacement for dplyr.
48
-
To achieve this, only a carefully selected subset of dplyr's operations, R functions, and R data types are implemented.
48
+
Currently, only a carefully selected subset of dplyr's operations, R functions, and R data types are implemented (see `vignette("limits")`).
49
49
Whenever a request cannot be handled by DuckDB, duckplyr falls back to dplyr.
50
50
51
-
## DuckDB operation
51
+
## A pipeline directly supported by duckplyr
52
52
53
53
The following operation is supported by duckplyr:
54
54
@@ -67,13 +67,18 @@ duckdb %>%
67
67
explain()
68
68
```
69
69
70
-
The plan shows three operations: a data frame scan (the input), a sort operation, and a projection (adding the `b` column and removing the `a` column).
71
-
Because each operation is supported by DuckDB, the resulting object contains a plan for the entire pipeline.
72
-
The plan is only executed when the data is needed.
70
+
The plan shows three **operations**:
73
71
74
-
## Relation objects
72
+
- a data frame scan (the input),
73
+
- a sort operation,
74
+
- a projection (adding the `b` column and removing the `a` column).
75
75
76
-
DuckDB accepts a tree of interconnected _relation objects_ as input.
76
+
Because each operation is supported by DuckDB, the resulting object contains a **plan for the entire pipeline**.
77
+
The plan is only executed when the data is needed, i.e. lazily (see `vignette("prudence")`).
78
+
79
+
### Relation objects
80
+
81
+
DuckDB accepts a tree of interconnected *relation objects* as input.
77
82
Each relation object represents a logical step of the execution plan.
78
83
The duckplyr package translates dplyr verbs into relation objects.
79
84
@@ -93,7 +98,7 @@ duckplyr::last_rel()
93
98
94
99
The `last_rel()` function now shows a relation that describes logical plan for executing the whole pipeline.
95
100
96
-
## Functionality not supported by DuckDB
101
+
## A pipeline with functionality not directly supported by duckplyr
97
102
98
103
Using a custom function with a side effect is not supported by DuckDB and triggers a dplyr fallback:
99
104
@@ -110,7 +115,7 @@ fallback <-
110
115
select(-a)
111
116
```
112
117
113
-
The `verbose_plus_one()` function is not supported by DuckDB, so the `mutate()` step is handled by dplyr and already executed when the pipeline is defined.
118
+
The `verbose_plus_one()` function is not supported by DuckDB, so the `mutate()` step is handled by dplyr and already executed when the pipeline is defined, i.e. eagerly.
114
119
This is confirmed by the `last_rel()` function:
115
120
116
121
```{r}
@@ -140,10 +145,26 @@ duckplyr::last_rel()
140
145
141
146
The `last_rel()` function confirms that only the final `select()` is handled by DuckDB again.
142
147
148
+
## Configure fallbacks
149
+
150
+
Using the `fallback_sitrep()` and `fallback_config()` functions you can examine and change settings related to fallbacks.
151
+
152
+
- You can choose to make fallbacks verbose with `fallback_config(info = TRUE)`.
153
+
154
+
- You can change settings related to logging and reporting fallback to duckplyr development team to inform their work. See `vignette("telemetry")`.
155
+
156
+
### Enforcing DuckDB operation
157
+
158
+
For any duck frame, one can control the automatic materialization.
159
+
For fallbacks to dplyr, automatic materialization must be allowed for the frame at hand, as dplyr necessitate eager evaluation.
160
+
161
+
Therefore, by making a data frame frugal, one can ensure a pipeline will error when a fallback to dplyr would have normally happened. See `vignette("prudence")`.
162
+
163
+
By using operations supported by duckplyr and avoiding fallbacks as much as possible, your pipelines will be executed by DuckDB in an optimized way.
164
+
143
165
## Conclusion
144
166
145
167
The fallback mechanism in duckplyr allows for a seamless integration of dplyr verbs and R functions that are not supported by DuckDB.
146
168
It is transparent to the user and only triggers when necessary.
147
169
With small or medium-sized data sets, it will not even be noticeable in most settings.
148
170
149
-
See `vignette("large")` for techniques for working with large data, `vignette("limits")` for the currently implementated translations, `vignette("prudence")` for details on controlling fallback behavior, and `vignette("telemetry")` for the automatic reporting of fallback situations.
0 commit comments