Connect to Data Lake Relational Engine Using the Go Driver
- How to install Go
- How to create and debug a Go application that queries a data lake Relational Engine
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:
ShellCopygo version
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
libdbcapiHDBusing 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-bitgcccompiler is required.-
To check if a 64-bit
gcccompiler is installed, run the following command:ShellCopygcc --versionOn 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.

If command prompt isn’t displaying the installed version after running the version check command, manually add the
binfolder to your path by setting it in your System environment variables.On Windows, search Edit the System Environment Variables and click on Environment Variables….

Look for the
Pathenvironment 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.
On Windows, to ensure the gcc compiler is installed, open a new Command prompt window and run the following command:
ShellCopygcc --versionOn 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.

-
Examine the Go environment by running the below command:
ShellCopygo envNotice that GOROOT is set to a location such as
C:\goor/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\goor$HOME/goand defines the root of your workspace which stores your codebase. -
Set the
CGO_LDFLAGSenvironment 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
dbcapilibrary:C:\SAP\hdlclient\IQ-17_1\bin64\dbcapi.dll
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)Copyecho $CGO_LDFLAGS echo $LD_LIBRARY_PATHIf 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)Copypico .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
-
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)Copycd %IQDIR17%\sdk\golang\SAP\go-hdlre\driver go mod init "SAP/go-hdlre/driver" go mod tidyShell (Linux)Copycd $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
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
-
In a shell, create a folder named
go, enter the newly created directory, and open a file namedgoQuery.goin an editor.Shell (Windows)Copymkdir %HOMEPATH%\DataLakeClientsTutorial\go cd %HOMEPATH%\DataLakeClientsTutorial\go notepad goQuery.goShell (Linux)Copymkdir -p ~/DataLakeClientsTutorial/go cd ~/DataLakeClientsTutorial/go pico goQuery.go -
Add the code below to
goQuery.goand then modify the connectString variable.Go CodeCopypackage 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.gofile has been updated, save and close the file. -
Create another go module and modify its contents:
Shell (Windows)Copygo mod init "go/goQuery" go mod tidy notepad go.modShell (Linux)Copygo mod init "go/goQuery" go mod tidy pico go.mod -
Add the code below to
go.modunder 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)Copyreplace 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.0Code (Linux)Copyreplace 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
-
Run the application or build and run the application:
ShellCopygo run goQuery.goShell Microsoft WindowsCopygo build goQuery.go goQuery.exe
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.
-
If you have not already done so, download Visual Studio Code.
-
If you have not already done so, in Visual Studio Code, choose File | Add Folder to Workspace, and then add the
DataLakeClientsTutorialfolder.
-
Open the file
goQuery.go.
Visual Studio Code will recognize the
gofile extension and will suggest installing the Go for Visual Studio Code extension. Click Install. -
Place a breakpoint.

-
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.

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?