Skip to content
R interface to Kusto/Azure Data Explorer
Branch: master
Clone or download
alexkyllo and Hong-Revo add compute and copy_to verbs (#45)
* add compute and copy_to verbs

* fix integration tests for compute and copy_to

* recompile documentation for compute.tbl_kusto

* remove ame_src

* qualify dplyr calls in test cases, and test copy_to where source is a query on the same db

* Update .gitignore

* review changes

* rm extraneous {}'s
Latest commit 388edf1 Mar 27, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
R add compute and copy_to verbs (#45) Mar 26, 2019
man add compute and copy_to verbs (#45) Mar 26, 2019
tests
.Rbuildignore initial commit Dec 11, 2018
.gitattributes initial commit Dec 11, 2018
.gitignore
.travis.yml Create .travis.yml Jan 29, 2019
AzureKusto.Rproj initial name change Jan 9, 2019
AzureKusto.rxproj initial name change Jan 9, 2019
AzureKusto.sln initial name change Jan 9, 2019
DESCRIPTION
LICENSE initial commit Dec 11, 2018
LICENSE.md
NAMESPACE
README.md update install instructions Mar 1, 2019

README.md

AzureKusto

R interface to Kusto, also known as Azure Data Explorer, a fast and highly scalable data exploration service.

Installation

You can install the development version from GitHub. Note that if you are using Microsoft R, AzureKusto requires recent versions of some packages which will likely not be in your default MRAN snapshot. You can set the repository to CRAN before installing.

options(repos="https://cloud.r-project.org")
devtools::install_github("cloudyr/AzureKusto")

Example Usage

Kusto Endpoint Interface

Connect to a Kusto cluster by instantiating a kusto_database_endpoint object with the cluster URI and database name.

library(AzureKusto)

Samples <- kusto_database_endpoint(server="https://help.kusto.windows.net", database="Samples")

# To sign in, use a web browser to open the page https://microsoft.com/devicelogin and enter the code FPD8GZPY9 to authenticate.
# Waiting for device code in browser...
# Press Esc/Ctrl + C to abort
# Authentication complete.

Now you can issue queries to the Kusto database with run_query and get the results back as a data.frame.

res <- run_query(Samples, "StormEvents | summarize EventCount = count() by State | order by State asc")

head(res)

##            State EventCount
## 1        ALABAMA       1315
## 2         ALASKA        257
## 3 AMERICAN SAMOA         16
## 4        ARIZONA        340
## 5       ARKANSAS       1028
## 6 ATLANTIC NORTH        188

run_query() also supports query parameters. Simply pass your parameters as additional keyword arguments and they will be escaped and interpolated into the query string.

res <- run_query(Samples, "MyFunction(lim)", lim=10L)

Command statements work much the same way, except that they do not accept parameters.

res <- run_query(Samples, ".show tables | count")

dplyr Interface

The package also implements a dplyr-style interface for building a query upon a tbl_kusto object and then running it on the remote Kusto database and returning the result as a regular tibble object with collect().

library(dplyr)

StormEvents <- tbl_kusto(Samples, "StormEvents")

q <- StormEvents %>%
    group_by(State) %>%
    summarize(EventCount=n()) %>%
    arrange(State)

show_query(q)

## <KQL> database('Samples').['StormEvents']
## | summarize ['EventCount'] = count() by ['State']
## | order by ['State'] asc

collect(q)

## # A tibble: 67 x 2
##    State          EventCount
##    <chr>               <dbl>
##  1 ALABAMA              1315
##  2 ALASKA                257
##  3 AMERICAN SAMOA         16
##  4 ARIZONA               340
##  5 ARKANSAS             1028
##  6 ATLANTIC NORTH        188
##  7 ATLANTIC SOUTH        193
##  8 CALIFORNIA            898
##  9 COLORADO             1654
## 10 CONNECTICUT           148
## # ... with 57 more rows

tbl_kusto also accepts query parameters, in case the Kusto source table is a parameterized function:

MyFunctionDate <- tbl_kusto(Samples, "MyFunctionDate(dt)", dt=as.Date("2019-01-01"))

MyFunctionDate %>%
    select(StartTime, EndTime, EpisodeId, EventId, State) %>%
    head() %>%
    collect()

## # A tibble: 6 x 5
##   StartTime           EndTime             EpisodeId EventId State         
##   <dttm>              <dttm>                  <int>   <int> <chr>         
## 1 2007-09-29 08:11:00 2007-09-29 08:11:00     11091   61032 ATLANTIC SOUTH
## 2 2007-09-18 20:00:00 2007-09-19 18:00:00     11074   60904 FLORIDA       
## 3 2007-09-20 21:57:00 2007-09-20 22:05:00     11078   60913 FLORIDA       
## 4 2007-12-30 16:00:00 2007-12-30 16:05:00     11749   64588 GEORGIA       
## 5 2007-12-20 07:50:00 2007-12-20 07:53:00     12554   68796 MISSISSIPPI   
## 6 2007-12-20 10:32:00 2007-12-20 10:36:00     12554   68814 MISSISSIPPI   

cloudyr project logo

You can’t perform that action at this time.