Skip to content

Latest commit

 

History

History
 
 

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 

README.md

Python Language Extension

Getting Started

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 Python extension version in this repository is compatible with SQL Server 2019 CU3 onwards.

Note that the Python Extension released in the current repository works with Python 3.7.x - to use the released package, follow this tutorial. For any other version of Python (3.6, 3.8, etc) you must modify and rebuild the Python Extension binaries using the following instructions.

Building

Windows

  1. Install CMake for Windows and Python.

  2. Install the package numpy into your python. This is needed to build boost_numpy in the next step.

  3. Download and build Boost Python with your version of Python. Make sure to build the static libraries.

  4. Install C++ Tools for CMake from the Build Tools for Visual Studio 2017. Download the Visual Studio 2017 Build Tools installer and check the Visual C++ build tools option under Workloads. In the sidebar on the right, make sure Visual C++ tools for CMake is checked, then install.

  5. Set CMAKE_ROOT, PYTHONHOME, and BOOST_ROOT pointing to their respective installation and build folders.

  6. Modify CMakeLists.txt. Change each find_library call to point to your custom python and boost libraries.

  7. Run build-python-extension.cmd which will generate:
    - PATH\TO\ENLISTMENT\build-output\pythonextension\windows\release\release\pythonextension.dll

  8. Run create-python-extension-zip.cmd which will generate:
    - PATH\TO\ENLISTMENT\build-output\pythonextension\windows\release\release\packages\python-lang-extension.zip
    This zip can be used in CREATE EXTERNAL LANGUAGE, as detailed in the tutorial in the Usage section below.

Linux

  1. Install CMake for Linux and Python

  2. Install the package numpy into your python. This is needed to build boost_numpy in the next step.

  3. Download and build Boost Python with your version of Python. Make sure to build the static libraries.

  4. Set PYTHONHOME and BOOST_ROOT to point to your python installation and boost build folder respectively.

  5. Modify CMakeLists.txt. Change each find_library call to point to your custom python and boost libraries.

  6. Modify PythonExtension.cpp. Change the value of x_PythonSoFile on line 37 to the name of your python so library file.

  7. Run build-python-extension.sh which will generate:
    - PATH/TO/ENLISTMENT/build-output/pythonextension/linux/release/libPythonExtension.so.1.1

  8. Run create-python-extension-zip.sh which will generate:
    - PATH/TO/ENLISTMENT/build-output/pythonextension/linux/release/packages/python-lang-extension.zip
    This zip can be used in CREATE EXTERNAL LANGUAGE, as detailed in the tutorial in the Usage section below.

Testing (Optional)

Windows

To unit test this extension,

  1. Install CMake for Windows. Set CMAKE_ROOT to point to the cmake installation folder. \

  2. Download or build (GoogleTest)[https://github.com/google/googletest]. \

  3. Run build-pythonextension-test.cmd which will generate: \

    • PATH\TO\ENLISTMENT\build-output\pythonextension-test\windows\release\pythonextension-test.exe
  4. Modify run-pythonextension-test.cmd to point GTEST_HOME and GTEST_LIB_PATH to your GTest binaries.

  5. Run run-pythonextension-test.cmd to run all the unit tests.

Linux

To unit test this extension,

  1. Run build-googletest.sh which will generate the gtest library essential to build the pythonextension-test binary: \

    • /PATH/TO/ENLISTMENT/build-output/googletest/linux/lib/libgtest.a
  2. Run build-pythonextension-test.sh which will generate: \

    • /PATH/TO/ENLISTMENT/build-output/pythonextension-test/windows/release/pythonextension-test.exe
  3. Run run-pythonextension-test.sh to run all the unit tests.

Usage

After downloading or building the Python extension zip, use CREATE EXTERNAL LANGUAGE to create the language on the SQL Server.

This tutorial will walk you through an end to end sample using the Python language extension.