Skip to Content

Connect to Data Lake Relational Engine Using the Go Driver

Create and debug a Go application that connects to data lake Relational Engine.
You will learn
  • How to install Go
  • How to create and debug a Go application that queries a data lake Relational Engine
chaitya-patelChaitya PatelOctober 28, 2025

Prerequisites

  • You have completed the first tutorial in this group.

Go is an open-source programming language developed by Google to increase productivity among programmers. For more information, see the Go Documentation.

  • Step 1

    The first step is to check if Go is installed, and if so, which version. To do so, enter the following command:

    Shell
    Copy
    go version
    
    go version linux

    If Go is installed, then it will return the currently installed version, such as 1.23.4

    If it is not installed, download it from Download Go, run the installer, follow the provided instructions, and ensure that Go is in your path.

    On Linux, follow the instructions for the appropriate Linux version: Installing Go for openSUSE.

    Note: A new shell window must be opened for the system to recognize the Go installation and for executing any future Go commands.

  • Step 2

    The data lake Relational Engine Client interface for Go, like the other data lake Relational Engine client interfaces (except JDBC), makes use of a C library named SQLDBC.

    The Go driver loads the SQLDBC library named libdbcapiHDB using cgo. For further information on the following steps, consult Go (golang) Driver in the SAP HANA Cloud, Data Lake Client Interfaces Reference Guide. In order to use the Go Driver, a 64-bit gcc compiler is required.

    1. To check if a 64-bit gcc compiler is installed, run the following command:

      Shell
      Copy
      gcc --version
      

      On Windows (if needed), download the compiler from MinGW. Under WinLibs.com, follow the link to winlibs.com. Navigate to the Release versions section. Find the latest release version of the Zip archive (UCRT runtime) for Win64 – x86_64. Then extract the folder.

      download minGW from WinLibs

      If command prompt isn’t displaying the installed version after running the version check command, manually add the bin folder to your path by setting it in your System environment variables.

      On Windows, search Edit the System Environment Variables and click on Environment Variables….

      Edit Environment Variables

      Look for the Path environment variable within User variables and double click to edit. Select Browse and manually browse through your File Explorer to find the bin folder. Click “OK” on all environment variable windows to update.

      Add bin to path

      On Windows, to ensure the gcc compiler is installed, open a new Command prompt window and run the following command:

      Shell
      Copy
      gcc --version
      

      On Linux (if needed), install the System GNU C compiler for your version of Linux. Note that if you are using openSUSE, minGW is included in the installation for Go through YaST.

      gcc 64-bit
    2. Examine the Go environment by running the below command:

      Shell
      Copy
      go env
      

      Notice that GOROOT is set to a location such as C:\go or /usr/lib64/go/1.23. This is the location that the Go SDK is installed to.

      GOPATH is set to a location such as C:\Users\user\go or $HOME/go and defines the root of your workspace which stores your codebase.

    3. Set the CGO_LDFLAGS environment variable to point to the location of the HDLRE client library as shown below.

      On Windows, search Edit the System Environment Variables and click on Environment Variables. Add a NEW user variable. Set the variable name to CGO_LDFLAGS and the value as the location of dbcapi library: C:\SAP\hdlclient\IQ-17_1\bin64\dbcapi.dll

      Set Environment Variables

      It is also possible on Microsoft Windows to set this using the SETX command from a shell.

      On Linux, check if the following variable are defined.

      Shell (Linux)
      Copy
      echo $CGO_LDFLAGS
      echo $LD_LIBRARY_PATH
      

      If needed, open the ‘.bashrc’ or ‘.bash_profile’ and add the following lines. Note that the path may be different depending on the data lake client install used.

      Shell (Linux)
      Copy
      pico .bashrc
      export CGO_LDFLAGS=$HOME/sap/dlclient/IQ-17_1/lib64/libdbcapi_r.so
      export CGO_LDFLAGS=$HOME/sap/hdlclient/lib64/libdbcapi_r.so
      export LD_LIBRARY_PATH=$HOME/sap/dlclient/IQ-17_1/lib64
      export LD_LIBRARY_PATH=$HOME/sap/hdlclient/lib64
      
      .bash_profile contents
    4. Navigate to the driver folder and create a Go module. Note that the path may be different depending on the data lake client install used.

      Shell (Windows)
      Copy
      cd %IQDIR17%\sdk\golang\SAP\go-hdlre\driver
      go mod init "SAP/go-hdlre/driver"
      go mod tidy
      
      Shell (Linux)
      Copy
      cd $IQDIR17/sdk/golang-hdlre/src/SAP/go-hdlre/driver
      cd $IQDIR17/sdk/golang/SAP/go-hdlre/driver/
      go mod init "SAP/go-hdlre/driver"
      go mod tidy
      
      createModule

      The contents of the data lake Client folder is not writeable so you may need to change the permissions on the driver folder or copy files to a new location.

  • Step 3
    1. In a shell, create a folder named go, enter the newly created directory, and open a file named goQuery.go in an editor.

      Shell (Windows)
      Copy
      mkdir %HOMEPATH%\DataLakeClientsTutorial\go
      cd %HOMEPATH%\DataLakeClientsTutorial\go
      notepad goQuery.go
      
      Shell (Linux)
      Copy
      mkdir -p ~/DataLakeClientsTutorial/go
      cd ~/DataLakeClientsTutorial/go
      pico goQuery.go
      
    2. Add the code below to goQuery.go and then modify the connectString variable.

      Go Code
      Copy
      package main
      
      import (
        "fmt"
      	"database/sql"
      	"log"
      
        _ "SAP/go-hdlre/driver"
        )
      
      func main() {
        //specify the connection parameters
        connectString := "hdlre://User1:Password1@xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx.iq.hdl.prod-xxxx.hanacloud.ondemand.com:443?enc='TLS{tls_type=rsa;direct=yes}'"
      
        fmt.Println("Connect String is " + connectString)
      
        db, err := sql.Open("hdlre", connectString)
        if err != nil {
          log.Fatal(err)
          return
        }
        defer db.Close()
      
        rows, err := db.Query("SELECT NAME, ADDRESS from HOTELS.CUSTOMER")
        if err != nil {
          log.Fatal(err)
        }
        defer rows.Close()
      
        var lastName string
        var address string
        for rows.Next() {
          err = rows.Scan(&lastName, &address)
          if err != nil {
            log.Fatal(err)
          }
          fmt.Println(lastName + ": " + address)
        }
      
        err = rows.Err()
        if err != nil {
        	log.Fatal(err)
        }
      }
      

      Once the goQuery.go file has been updated, save and close the file.

    3. Create another go module and modify its contents:

      Shell (Windows)
      Copy
      go mod init "go/goQuery"
      go mod tidy
      notepad go.mod
      
      Shell (Linux)
      Copy
      go mod init "go/goQuery"
      go mod tidy
      pico go.mod
      
    4. Add the code below to go.mod under the go 1.23.4 (version) line:

      Ensure you have the correct path to the driver folder. The path depends on your installation. Note that two example locations are provided. Choose the one that’s closest to your installation and edit it if necessary.

      Code (Windows)
      Copy
      replace SAP/go-hdlre/driver v0.1.0 => C:\SAP\dlclient\IQ-17_1\SDK\golang\SAP\go-hdlre\driver   
      replace SAP/go-hdlre/driver v0.1.0 => C:\SAP\hdlclient\sdk\golang\SAP\go-hdlre\driver
      require SAP/go-hdlre/driver v0.1.0 
      
      Code (Linux)
      Copy
      replace SAP/go-hdlre/driver v0.1.0 => /home/name/sap/dlclient/IQ-17_1/sdk/golang-hdlre/src/SAP/go-hdlre/driver 
      replace SAP/go-hdlre/driver v0.1.0 => /home/name/sap/hdlclient/sdk/golang/SAP/go-hdlre/driver
      require SAP/go-hdlre/driver v0.1.0 
      
      go.mod contents
    5. Run the application or build and run the application:

      Shell
      Copy
      go run goQuery.go
      
      Shell Microsoft Windows
      Copy
      go build goQuery.go
      goQuery.exe
      
      Result

    For more information on the API’s used, consult the SAP HANA Cloud, data lake connection specific properties at Connect from Go to Data Lake Relational Engine, Go Database/SQL Tutorial, and Package SQL

  • Step 4

    Visual Studio Code provides plugins for Go and can be used to debug an application.

    1. If you have not already done so, download Visual Studio Code.

    2. If you have not already done so, in Visual Studio Code, choose File | Add Folder to Workspace, and then add the DataLakeClientsTutorial folder.

      Open Workspace
    3. Open the file goQuery.go.

      Go Extension

      Visual Studio Code will recognize the go file extension and will suggest installing the Go for Visual Studio Code extension. Click Install.

    4. Place a breakpoint.

      SetBreakpoint
    5. Select Run | Start Debugging.

      Notice that the program stops running at the breakpoint that was set.

      Observe the variable values in the leftmost pane. Step through the code.

      Breakpoint

      Note that debugging can also be performed from the command line using Delve.

  • Step 5

    Congratulations! You have now created and debugged a Go application that connects to and queries a data lake Relational Engine.


    Which of the following statements are true?

Back to top