It was probably not difficult to discern from my previous Drill-themed post that I’m fairly excited about the Apache Drill 1.15.0 release. I’ve rounded out most of the existing corners for it in preparation for a long-overdue CRAN update and have been concentrating on two helper features: configuring & launching Drill embedded Docker containers and auto-generation of Drill CTAS queries.
Drill Docker Goodness
Starting with version 1.14.0, Apache provides Drill Docker images for use in experimenting/testing/building-off-of. They run Drill in single node standalone mode so you’re not going to be running this in “production� (unless you have light or just personal workloads). Docker is a great way to get to know Drill if you haven’t already played with it since you don’t have do do much except run the Docker image.
I’ve simplified this even more thanks to @rgfitzjohn’s most excellent stevedore
package which adds a robust R wrapper to the Docker client without relying on any heavy external dependencies such as reticulate
. The new drill_up()
function will auto-fetch the latest Drill image and launch a container so you can have a running Drill instance with virtually no effort on your part.
Just running the vanilla image isn’t enough since your goal is likely to do more than work with the built-in cp
data source. The default container launch scenario also doesn’t hook up any local filesystem paths to the container so you really can’t do much other than cp
-oriented queries. Rather than make you do all the work of figuring out how to machinate Docker command line arguments and manually configure a workspace that points to a local filesystem area in the Drill web admin GUI the drill_up()
function provides a data_dir
argument (that defaults to the getwd()
where you are in your R session) which will then auto-wire up that path into the container and create a dfs.d
workspace which auto-points to it for you. Here’s a sample execution:
1 |
|
You can use dc$stop()
to stop the container or use the printed container id to do it from the command line.
We’ll use this containerized Drill instance with the next feature but I need to thank @cboettig for the suggestion to make an auto-downloader-runner-thingy before doing that. (Thank you @cboettig!)
Taking the Tedium out of CTAS
@dseverski, an intrepid R, Drill & sergeant
user noticed some new package behavior with Drill 1.15.0 that ended up spawning a new feature: automatic generation of Drill CTAS statements.
Prior to 1.14.0 sergeant
had no way to accurately, precisely tell data types of the columns coming back since the REST API didn’t provide them (as noted in the previous Drill post). Now, it did rely on the JSON types to create the initial data frames but id also did something *kinda horribad: it ran readr::type_convert()
on the result sets
. Said operation had the singular benefit of auto-converting CSV/CSVH/TSV/PSV/etc data to something sane without having to worry about writing lengthy CTAS queries (at the expense of potentially confusing everyone, though that didn’t seem to happen).
With 1.15.0, the readr::type_convert()
crutch is gone, which results in less-than-helpful things like this when you have delimiter-separated values data:
1 |
|
So the package does what it finally should have been doing all along. But, as noted, that’s not great if you just wanted to quickly work with a directory of CSV files. In theory, you’re supposed to use Drill’s CREATE TABLE AS
then do a bunch of CASTS
and TO_
s to get proper data types. But who has time for that?
David had a stellar idea, might sergeant
be able to automagically create CTAS statements from a query?. Yes. Yes it just might be able to do that with the new ctas_profile()
function.
Let’s pipe the previous tbl()
into ctas_profile()
and see what we get:
1 |
|
1 |
|
There’s a parameter for the new table name which will cause the CHANGE____ME
to go away and when the function finds TIMESTAMP
or DATE
fields it knows to switch to their TO_
cousins and gives sample data with a reminder that you need to make a format string (I’ll eventually auto-generate them unless someone PRs it first). And, since nodoby but Java programmers remember Joda format strings (they’re different than what you’re used to) it provides a handy link to them if it detects the presence of those column types.
Now, we don’t need to actually create a new table (though converting a bunch of CSVs to Parquet is likely a good idea for performance reasons) to use that output. We can pass most of that new query right to tbl()
:
1 |
|
Ahhhh… Useful data types. (And, see what I mean about that daft format string? Also, WP is mangling the format string so add a comment if you need the actual string.)
FIN
As you can see questions, suggestions (and PRs!) are welcome and heeded on your social-coding platform of choice (though y’all still seem to be stuck on GH ).
NOTE: I’ll be subbing out most install_github()
links in READMEs and future blog posts for install_git()
counterparts pointing to my sr.ht repos (as I co-locate/migrate them there).
You can play with the new 0.8.0 features via devtools::install_git("https://git.sr.ht/~hrbrmstr/sergeant", ref="0.8.0")
.
Related