This commit is contained in:
hong-revo 2018-12-11 14:05:23 +11:00
Родитель e2e7533e9a
Коммит b93e5e29aa
12 изменённых файлов: 582 добавлений и 0 удалений

10
.Rbuildignore Normal file
Просмотреть файл

@ -0,0 +1,10 @@
^misc$
^\.vs$
\.sln$
\.Rproj$
\.Rxproj$
^\.Rproj\.user$
CONTRIBUTING.md
drat.sh
.travis.yml
^LICENSE\.md$

63
.gitattributes поставляемый Normal file
Просмотреть файл

@ -0,0 +1,63 @@
###############################################################################
# Set default behavior to automatically normalize line endings.
###############################################################################
* text=auto
###############################################################################
# Set default behavior for command prompt diff.
#
# This is need for earlier builds of msysgit that does not have it on by
# default for csharp files.
# Note: This is only used by command line
###############################################################################
#*.cs diff=csharp
###############################################################################
# Set the merge driver for project and solution files
#
# Merging from the command prompt will add diff markers to the files if there
# are conflicts (Merging from VS is not affected by the settings below, in VS
# the diff markers are never inserted). Diff markers may cause the following
# file extensions to fail to load in VS. An alternative would be to treat
# these files as binary and thus will always conflict and require user
# intervention with every merge. To do so, just uncomment the entries below
###############################################################################
#*.sln merge=binary
#*.csproj merge=binary
#*.vbproj merge=binary
#*.vcxproj merge=binary
#*.vcproj merge=binary
#*.dbproj merge=binary
#*.fsproj merge=binary
#*.lsproj merge=binary
#*.wixproj merge=binary
#*.modelproj merge=binary
#*.sqlproj merge=binary
#*.wwaproj merge=binary
###############################################################################
# behavior for image files
#
# image files are treated as binary by default.
###############################################################################
#*.jpg binary
#*.png binary
#*.gif binary
###############################################################################
# diff behavior for common document formats
#
# Convert binary document formats to text before diffing them. This feature
# is only available from the command line. Turn it on by uncommenting the
# entries below.
###############################################################################
#*.doc diff=astextplain
#*.DOC diff=astextplain
#*.docx diff=astextplain
#*.DOCX diff=astextplain
#*.dot diff=astextplain
#*.DOT diff=astextplain
#*.pdf diff=astextplain
#*.PDF diff=astextplain
#*.rtf diff=astextplain
#*.RTF diff=astextplain

265
.gitignore поставляемый Normal file
Просмотреть файл

@ -0,0 +1,265 @@
## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.
# User-specific files
*.suo
*.user
*.userosscache
*.sln.docstates
# User-specific files (MonoDevelop/Xamarin Studio)
*.userprefs
# Build results
[Dd]ebug/
[Dd]ebugPublic/
[Rr]elease/
[Rr]eleases/
x64/
x86/
bld/
[Bb]in/
[Oo]bj/
[Ll]og/
# Visual Studio 2015 cache/options directory
.vs/
# Uncomment if you have tasks that create the project's static files in wwwroot
#wwwroot/
# MSTest test Results
[Tt]est[Rr]esult*/
[Bb]uild[Ll]og.*
# NUNIT
*.VisualState.xml
TestResult.xml
# Build Results of an ATL Project
[Dd]ebugPS/
[Rr]eleasePS/
dlldata.c
# DNX
project.lock.json
project.fragment.lock.json
artifacts/
*_i.c
*_p.c
*_i.h
*.ilk
*.meta
*.obj
*.pch
*.pdb
*.pgc
*.pgd
*.rsp
*.sbr
*.tlb
*.tli
*.tlh
*.tmp
*.tmp_proj
*.log
*.vspscc
*.vssscc
.builds
*.pidb
*.svclog
*.scc
# Chutzpah Test files
_Chutzpah*
# Visual C++ cache files
ipch/
*.aps
*.ncb
*.opendb
*.opensdf
*.sdf
*.cachefile
*.VC.db
*.VC.VC.opendb
# Visual Studio profiler
*.psess
*.vsp
*.vspx
*.sap
# TFS 2012 Local Workspace
$tf/
# Guidance Automation Toolkit
*.gpState
# ReSharper is a .NET coding add-in
_ReSharper*/
*.[Rr]e[Ss]harper
*.DotSettings.user
# JustCode is a .NET coding add-in
.JustCode
# TeamCity is a build add-in
_TeamCity*
# DotCover is a Code Coverage Tool
*.dotCover
# NCrunch
_NCrunch_*
.*crunch*.local.xml
nCrunchTemp_*
# MightyMoose
*.mm.*
AutoTest.Net/
# Web workbench (sass)
.sass-cache/
# Installshield output folder
[Ee]xpress/
# DocProject is a documentation generator add-in
DocProject/buildhelp/
DocProject/Help/*.HxT
DocProject/Help/*.HxC
DocProject/Help/*.hhc
DocProject/Help/*.hhk
DocProject/Help/*.hhp
DocProject/Help/Html2
DocProject/Help/html
# Click-Once directory
publish/
# Publish Web Output
*.[Pp]ublish.xml
*.azurePubxml
# TODO: Comment the next line if you want to checkin your web deploy settings
# but database connection strings (with potential passwords) will be unencrypted
#*.pubxml
*.publishproj
# Microsoft Azure Web App publish settings. Comment the next line if you want to
# checkin your Azure Web App publish settings, but sensitive information contained
# in these scripts will be unencrypted
PublishScripts/
# NuGet Packages
*.nupkg
# The packages folder can be ignored because of Package Restore
**/packages/*
# except build/, which is used as an MSBuild target.
!**/packages/build/
# Uncomment if necessary however generally it will be regenerated when needed
#!**/packages/repositories.config
# NuGet v3's project.json files produces more ignoreable files
*.nuget.props
*.nuget.targets
# Microsoft Azure Build Output
csx/
*.build.csdef
# Microsoft Azure Emulator
ecf/
rcf/
# Windows Store app package directories and files
AppPackages/
BundleArtifacts/
Package.StoreAssociation.xml
_pkginfo.txt
# Visual Studio cache files
# files ending in .cache can be ignored
*.[Cc]ache
# but keep track of directories ending in .cache
!*.[Cc]ache/
# Others
ClientBin/
~$*
*~
*.dbmdl
*.dbproj.schemaview
*.jfm
*.pfx
*.publishsettings
node_modules/
orleans.codegen.cs
# Since there are multiple workflows, uncomment next line to ignore bower_components
# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
#bower_components/
# RIA/Silverlight projects
Generated_Code/
# Backup & report files from converting an old project file
# to a newer Visual Studio version. Backup files are not needed,
# because we have git ;-)
_UpgradeReport_Files/
Backup*/
UpgradeLog*.XML
UpgradeLog*.htm
# SQL Server files
*.mdf
*.ldf
# Business Intelligence projects
*.rdl.data
*.bim.layout
*.bim_*.settings
# Microsoft Fakes
FakesAssemblies/
# GhostDoc plugin setting file
*.GhostDoc.xml
# Node.js Tools for Visual Studio
.ntvs_analysis.dat
# Visual Studio 6 build log
*.plg
# Visual Studio 6 workspace options file
*.opt
# Visual Studio LightSwitch build output
**/*.HTMLClient/GeneratedArtifacts
**/*.DesktopClient/GeneratedArtifacts
**/*.DesktopClient/ModelManifest.xml
**/*.Server/GeneratedArtifacts
**/*.Server/ModelManifest.xml
_Pvt_Extensions
# Paket dependency manager
.paket/paket.exe
paket-files/
# FAKE - F# Make
.fake/
# JetBrains Rider
.idea/
*.sln.iml
# CodeRush
.cr/
# Python Tools for Visual Studio (PTVS)
__pycache__/
*.pyc
.RHistory
misc/
.Rproj.user

13
AzureDataExplorer.Rproj Normal file
Просмотреть файл

@ -0,0 +1,13 @@
Version: 1.0
RestoreWorkspace: Default
SaveWorkspace: Default
AlwaysSaveHistory: Default
EnableCodeIndexing: Yes
UseSpacesForTab: Yes
NumSpacesForTab: 2
Encoding: UTF-8
RnwWeave: Sweave
LaTeX: pdfLaTeX

25
AzureDataExplorer.rxproj Normal file
Просмотреть файл

@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Label="Globals">
<ProjectGuid>36d78550-39b7-492b-b333-e3b318a3f60b</ProjectGuid>
</PropertyGroup>
<PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">15.0</VisualStudioVersion>
<Configuration Condition="'$(Configuration)' == ''">Debug</Configuration>
<Platform Condition="'$(Platform)' == ''">AnyCPU</Platform>
</PropertyGroup>
<PropertyGroup>
<StartupFile>Script.R</StartupFile>
</PropertyGroup>
<ProjectExtensions>
<VisualStudio>
<UserProperties />
</VisualStudio>
</ProjectExtensions>
<Target Name="Build" />
<Import Project="$(MSBuildUserExtensionsPath)\Microsoft\VisualStudio\v$(VisualStudioVersion)\RTVS\Rules\rtvs.rules.props" Condition="Exists('$(MSBuildUserExtensionsPath)\Microsoft\VisualStudio\v$(VisualStudioVersion)\RTVS\Rules\rtvs.rules.props')" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\RTVS\Rules\rtvs.rules.props" Condition="Exists('$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\RTVS\Rules\rtvs.rules.props') And !Exists('$(MSBuildUserExtensionsPath)\Microsoft\VisualStudio\v$(VisualStudioVersion)\RTVS\Rules\rtvs.rules.props')" />
<Import Project="$(MSBuildUserExtensionsPath)\Microsoft\VisualStudio\v$(VisualStudioVersion)\RTVS\Targets\Microsoft.R.targets" Condition="Exists('$(MSBuildUserExtensionsPath)\Microsoft\VisualStudio\v$(VisualStudioVersion)\RTVS\Targets\Microsoft.R.targets')" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\RTVS\Targets\Microsoft.R.targets" Condition="Exists('$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\RTVS\Targets\Microsoft.R.targets') And !Exists('$(MSBuildUserExtensionsPath)\Microsoft\VisualStudio\v$(VisualStudioVersion)\RTVS\Targets\Microsoft.R.targets')" />
<Import Project="AzureDataExplorer.InMemory.Targets" Condition="Exists('AzureDataExplorer.InMemory.Targets')" />
</Project>

29
CONTRIBUTING.md Normal file
Просмотреть файл

@ -0,0 +1,29 @@
Contributions to **AzureDataExplorer** are welcome from anyone and are best sent as pull requests on [the GitHub repository](https://github.com/cloudyr/AzureDataExplorer/). This page provides some instructions to potential contributors about how to add to the package.
1. Contributions can be submitted as [a pull request](https://help.github.com/articles/creating-a-pull-request/) on GitHub by forking or cloning the [repo](https://github.com/cloudyr/AzureDataExplorer/), making changes and submitting the pull request.
2. The cloudyr project follows [a consistent style guide](http://cloudyr.github.io/styleguide/index.html) across all of its packages. Please refer to this when editing package code.
3. Pull requests should involve only one commit per substantive change. This means if you change multiple files (e.g., code and documentation), these changes should be committed together. If you don't know how to do this (e.g., you are making changes in the GitHub web interface) just submit anyway and the maintainer will clean things up.
4. All contributions must be submitted consistent with the package license ([MIT](https://opensource.org/licenses/MIT)).
5. Non-trivial contributions need to be noted in the `Authors@R` field in the [DESCRIPTION](https://github.com/cloudyr/AzureDataExplorer/blob/master/DESCRIPTION). Just follow the format of the existing entries to add your name (and, optionally, email address). Substantial contributions should also be noted in [`inst/CITATION`](https://github.com/cloudyr/AzureDataExplorer/blob/master/inst/CITATION).
6. The cloudyr project use royxgen code and documentation markup, so changes should be made to roxygen comments in the source code `.R` files. If changes are made, roxygen needs to be run. The easiest way to do this is a command line call to: `Rscript -e devtools::document()`. Please resolve any roxygen errors before submitting a pull request.
7. Please run `R CMD BUILD AzureDataExplorer` and `R CMD CHECK AzureDataExplorer_VERSION.tar.gz` before submitting the pull request to check for any errors.
Some specific types of changes that you might make are:
1. Bug fixes. Great!
2. Documentation-only changes (e.g., to Rd files, README, vignettes). This is great! All contributions are welcome.
3. New functionality. This is fine, but should be discussed on [the GitHub issues page](https://github.com/cloudyr/AzureDataExplorer/issues) before submitting a pull request.
3. Changes requiring a new package dependency should also be discussed on [the GitHub issues page](https://github.com/cloudyr/AzureDataExplorer/issues) before submitting a pull request.
4. Message translations. These are very appreciated! The format is a pain, but if you're doing this I'm assuming you're already familiar with it.
Any questions you have can be opened as GitHub issues or directed to hongooi (at) microsoft.com (for questions about this package) or thosjleeper (at) gmail.com (for questions about cloudyr in general).

27
DESCRIPTION Normal file
Просмотреть файл

@ -0,0 +1,27 @@
Package: AzureDataExplorer
Title: Interface to 'Azure Data Explorer'
Version: 0.0.1
Authors@R: c(
person("Hong", "Ooi", , "hongooi@microsoft.com", role = c("aut", "cre")),
person("Alex", "Kyllo", , "jekyllo@microsoft.com", role = "aut"),
person("Microsoft", role = "cph")
)
Description: Interface to 'Azure Data Explorer'
URL: https://github.com/cloudyr/AzureDataExplorer
BugReports: https://github.com/cloudyr/AzureDataExplorer/issues
License: MIT + file LICENSE
VignetteBuilder: knitr
Depends:
R (>= 3.3)
Imports:
utils,
httr (>= 1.3),
jsonlite,
R6,
bit64,
AzureRMR
Suggests:
knitr,
testthat
Roxygen: list(markdown=TRUE)
RoxygenNote: 6.1.0.9000

2
LICENSE Normal file
Просмотреть файл

@ -0,0 +1,2 @@
YEAR: 2018
COPYRIGHT HOLDER: Microsoft

21
LICENSE.md Normal file
Просмотреть файл

@ -0,0 +1,21 @@
# MIT License
Copyright (c) 2018 Microsoft
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

27
R/add_methods.R Normal file
Просмотреть файл

@ -0,0 +1,27 @@
.onLoad <- function(libname, pkgname)
{
## extending AzureRMR classes
AzureRMR::az_resource_group$set("public", "create_data_explorer", overwrite=TRUE,
function(name, location=self$location, compute="D13_v2", ...)
{
az_kusto$new(self$token, self$subscription, self$name,
type="Microsoft.Kusto/cluster", name=name, location=location,
sku=list(name=compute, tier="Standard"), ...)
})
AzureRMR::az_resource_group$set("public", "get_data_explorer", overwrite=TRUE,
function(name)
{
az_kusto$new(self$token, self$subscription, self$name,
type="Microsoft.Kusto/cluster", name=name)
})
AzureRMR::az_resource_group$set("public", "delete_data_explorer", overwrite=TRUE,
function(name, confirm=TRUE, wait=FALSE)
{
self$get_data_explorer(name, deployed_parms=list())$delete(confirm=confirm, wait=wait)
})
}

99
R/query.R Normal file
Просмотреть файл

@ -0,0 +1,99 @@
.kusto_app_id <- 'db662dc1-0cfe-4e1c-a843-19a68e65be58'
convert_kusto_datatype <- function(column, kusto_type)
{
if(kusto_type == 'long')
{
return(bit64::as.integer64(column))
} else if(kusto_type == 'integer')
{
return(as.integer(column))
} else if(kusto_type == 'datetime')
{
return(as.POSIXct(strptime(column, format='%Y-%m-%dT%H:%M:%OSZ', tz='UTC')))
} else if(kusto_type == 'real')
{
return(as.numeric(column))
} else if(kusto_type == 'bool')
{
return(as.logical(column))
} else
{
return(as.character(column))
}
}
convert_types <- function(df, coltypes)
{
df[] <- mapply(convert_kusto_datatype, df, coltypes)
df
}
execute_query <- function(token, server, db, query)
{
body_list <- list(
db=db,
properties=list(Options=list(queryconsistency="weakconsistency")),
csl=query
)
uri <- sprintf("https://%s.kusto.windows.net:443/v1/rest/query", server)
auth_str <- paste("Bearer", token)
r <- httr::POST(uri, httr::add_headers(Authorization=auth_str),
body=body_list, encode="json")
content <- httr::content(r, simplifyValues=TRUE)
httr::stop_for_status(r)
content
#if(r$status_code != 200)
#{
#if(!is.null(content$Message))
#{
#stop(sprintf("HTTP %d %s",
#r$status_code,
#content$Message))
#}
#else if(!is.null(content$error$innererror))
#{
#stop(
#sprintf(
#"HTTP %d %s\n%s\n%s\n%s",
#r$status_code,
#content$error$code,
#content$error$message,
#content$error$innererror$code,
#content$error$innererror$message
#)
#)
#} else
#{
#stop(
#sprintf(
#"HTTP %d %s\n%s",
#r$status_code,
#content$error$code,
#content$error$message
#)
#)
#}
#} else if(!is.null(content$Exceptions))
#{
#stop(sprintf("HTTP %d %s",
#r$status_code,
#content$Exceptions[[1]]))
#}
#table <- content$Tables[[1]]
#colnames <- sapply(table$Columns, function(x) x$ColumnName)
#coltypes <- sapply(table$Columns, function(x) x$ColumnType)
#rows <- table$Rows
#for(row in 1:length(rows))
#{
#rows[[row]]=lapply(rows[[row]], function(x) ifelse(is.null(x), NA, x))
#}
#names(df) <- colnames
#convert_types(df, coltypes)
}

Просмотреть файл

@ -1,2 +1,3 @@
# AzureDataExplorer # AzureDataExplorer
R interface to Azure Data Explorer (previously known as Kusto) R interface to Azure Data Explorer (previously known as Kusto)