Language Extensions is a feature of SQL Server used for executing external code. The relational data can be used in the external code using the extensibility framework.
For more information about SQL Server Language Extensions, refer to this documentation.
The RExtension version in this repository is compatible with SQL Server 2019 CU3 onwards. It integrates R in SQL Server and works with R >= v3.3, however it is strongly recommended to use the latest stable version. At the time of this writing, it is R v4.0.3.
To use this released R-language-extension.zip package, follow this tutorial. For any fixes or enhancements, you are welcome to modify, rebuild and use the binaries using the following instructions.
-
Install rtools40-x86_64.exe to get the gcc v8.3.0 toolchain. Set RTOOLS40_HOME to point to this rtools40 installation path. Also install Rtools35.exe to use MinGW Makefiles as the generator for cmake and mingw32-make as the build tool. Set RTOOLS35_HOME to point to this Rtools35 installation path.
-
Install CMake for Windows. Set CMAKE_ROOT to point to the cmake installation folder.
-
Install R for Windows and set R_HOME to point to your installation path.
-
Install the Rcpp and RInside packages into this R runtime. These are needed to seamlessly integrate and embed R in C++.
-
Run build-RExtension.cmd which will generate:
- PATH\TO\ENLISTMENT\build-output\RExtension\windows\release\libRExtension.dll -
Run create-RExtension-zip.cmd which will generate:
- PATH\TO\ENLISTMENT\build-output\RExtension\windows\release\packages\R-lang-extension.zip
This zip can be used in CREATE EXTERNAL LANGUAGE, as detailed in the tutorial in the Usage section below.
-
Install all packages necessary for c++ compilation on Linux based on your distribution.
#bash e.g. for Ubuntu sudo apt-get -q -y install unixodbc-dev sudo apt-get install build-essential software-properties-common -y sudo add-apt-repository ppa:ubuntu-toolchain-r/test -y sudo apt-get update -y sudo apt-get install gcc-7 g++-7 -y sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-7 70 --slave /usr/bin/g++ g++ /usr/bin/g++-7
-
Install R for Linux based on your distribution. Set R_HOME to point to your installation path, by default it is /usr/lib/R. Set R_INCLUDE_HOME to point to the R include files, by default it is /usr/share/R/include
#bash e.g. for Ubuntu sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys E298A3A825C0D65DFD57CBB651716619E084DAB9 sudo add-apt-repository 'deb https://cloud.r-project.org/bin/linux/ubuntu xenial-cran40/' sudo apt-get update sudo apt-get -y install r-base-core
-
Install the Rcpp and RInside packages into this R runtime. These are needed to seamlessly integrate and embed R in C++.
-
Run build-RExtension.sh which will generate:
- /PATH/TO/ENLISTMENT/build-output/RExtension/linux/release/libRExtension.so.1.1 -
Run create-R-extension-zip.sh which will generate:
- /PATH/TO/ENLISTMENT/build-output/RExtension/linux/release/packages/R-lang-extension.zip
This zip can be used in CREATE EXTERNAL LANGUAGE, as detailed in the tutorial in the Usage section below.
To unit test this extension,
- Run build-googletest.cmd which will generate the gtest library essential to build the RExtension-test executable: \
- PATH\TO\ENLISTMENT\build-output\googletest\windows\lib\libgtest.a
- Run build-RExtension-test.cmd which will generate: \
- PATH\TO\ENLISTMENT\build-output\RExtension-test\windows\release\RExtension-test.exe
- Run run-RExtension-test.cmd to run all the unit tests.
To unit test this extension,
- Run build-googletest.sh which will generate the gtest library essential to build the RExtension-test binary: \
- /PATH/TO/ENLISTMENT/build-output/googletest/linux/lib/libgtest.a
- Run build-RExtension-test.sh which will generate: \
- /PATH/TO/ENLISTMENT/build-output/RExtension-test/windows/release/RExtension-test.exe
- Run run-RExtension-test.sh to run all the unit tests.
After downloading or building the R-lang-extension.zip, use CREATE EXTERNAL LANGUAGE to register the language with SQL Server 2019 CU3+.
This tutorial will walk you through an end to end sample using the R language extension.