Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .github/workflows/go-driver.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ jobs:
strategy:
matrix:
go-version: [ '1.18', '1.19' ]
distributions: ['zulu', 'temurin', 'microsoft']
defaults:
run:
working-directory: drivers/golang/age/
Expand All @@ -27,6 +28,15 @@ jobs:
uses: actions/setup-go@v3
with:
go-version: ${{ matrix.go-version }}

- name: Set up Java
uses: actions/setup-java@v3
with:
distribution: ${{ matrix.distributions }}
java-version: '17'

- name: Generate
run: go generate ./../...

- name: Build
run: go build -v ./...
Expand Down
6 changes: 6 additions & 0 deletions drivers/golang/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ AGType parser and driver support for [Apache AGE](https://age.apache.org/), grap
* over Go 1.18 / 1.19
* This module runs on golang standard api [database/sql](https://golang.org/pkg/database/sql/) and [antlr4-python3](https://github.com/antlr/antlr4/tree/master/runtime/Go/antlr)

### Installation (From source)
Run (Windows): install.bat
Run (Linux & OSX):
```
sh install.sh
```

### Go get
```
Expand Down
2 changes: 1 addition & 1 deletion drivers/golang/age/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
"strconv"
"strings"

"github.com/antlr/antlr4/runtime/Go/antlr"
"github.com/antlr/antlr4/runtime/Go/antlr/v4"
"github.com/apache/age/drivers/golang/parser"
)

Expand Down
2 changes: 1 addition & 1 deletion drivers/golang/age/mapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
"reflect"
"strings"

"github.com/antlr/antlr4/runtime/Go/antlr"
"github.com/antlr/antlr4/runtime/Go/antlr/v4"
"github.com/apache/age/drivers/golang/parser"
)

Expand Down
5 changes: 3 additions & 2 deletions drivers/golang/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,14 @@ module github.com/apache/age/drivers/golang
go 1.19

require (
github.com/antlr/antlr4/runtime/Go/antlr v0.0.0-20210521184019-c5ad59b459ec
github.com/lib/pq v1.10.2
github.com/antlr/antlr4/runtime/Go/antlr/v4 v4.0.0-20230321174746-8dcc6526cfb1
github.com/lib/pq v1.10.7
github.com/stretchr/testify v1.7.0
)

require (
github.com/davecgh/go-spew v1.1.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
golang.org/x/exp v0.0.0-20230321023759-10a507213a29 // indirect
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c // indirect
)
14 changes: 10 additions & 4 deletions drivers/golang/go.sum
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
github.com/antlr/antlr4/runtime/Go/antlr v0.0.0-20210521184019-c5ad59b459ec h1:EEyRvzmpEUZ+I8WmD5cw/vY8EqhambkOqy5iFr0908A=
github.com/antlr/antlr4/runtime/Go/antlr v0.0.0-20210521184019-c5ad59b459ec/go.mod h1:F7bn7fEU90QkQ3tnmaTx3LTKLEDqnwWODIYppRQ5hnY=
github.com/antlr/antlr4/runtime/Go/antlr/v4 v4.0.0-20230219212500-1f9a474cc2dc h1:ikxgKfnYm4kXCOohe1uCkVFwZcABDZbVsqginko+GY8=
github.com/antlr/antlr4/runtime/Go/antlr/v4 v4.0.0-20230219212500-1f9a474cc2dc/go.mod h1:pSwJ0fSY5KhvocuWSx4fz3BA8OrA1bQn+K1Eli3BRwM=
github.com/antlr/antlr4/runtime/Go/antlr/v4 v4.0.0-20230321174746-8dcc6526cfb1 h1:X8MJ0fnN5FPdcGF5Ij2/OW+HgiJrRg3AfHAx1PJtIzM=
github.com/antlr/antlr4/runtime/Go/antlr/v4 v4.0.0-20230321174746-8dcc6526cfb1/go.mod h1:pSwJ0fSY5KhvocuWSx4fz3BA8OrA1bQn+K1Eli3BRwM=
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/lib/pq v1.10.2 h1:AqzbZs4ZoCBp+GtejcpCpcxM3zlSMx29dXbUSeVtJb8=
github.com/lib/pq v1.10.2/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
github.com/lib/pq v1.10.7 h1:p7ZhMD+KsSRozJr34udlUrhboJwWAgCg34+/ZZNvZZw=
github.com/lib/pq v1.10.7/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
golang.org/x/exp v0.0.0-20230223210539-50820d90acfd h1:wtFuj4DoOcAdb82Zh2PI90xiaqgp7maYA7KxjQXVtkY=
golang.org/x/exp v0.0.0-20230223210539-50820d90acfd/go.mod h1:CxIveKay+FTh1D0yPZemJVgC/95VzuuOLq5Qi4xnoYc=
golang.org/x/exp v0.0.0-20230321023759-10a507213a29 h1:ooxPy7fPvB4kwsA2h+iBNHkAbp/4JxTSwCmvdjEYmug=
golang.org/x/exp v0.0.0-20230321023759-10a507213a29/go.mod h1:CxIveKay+FTh1D0yPZemJVgC/95VzuuOLq5Qi4xnoYc=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
Expand Down
85 changes: 85 additions & 0 deletions drivers/golang/install.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
@echo off

rem Install Java Development Kit (JDK)
echo Installing JDK...
if not exist "%ProgramFiles%\Java\jdk-19\" (
mkdir C:\temp
cd C:\temp
powershell Invoke-WebRequest -Uri "https://download.oracle.com/java/19/archive/jdk-19.0.2_windows-x64_bin.exe" -OutFile jdk-19.0.2_windows-x64_bin.exe
start /wait jdk-19.0.2_windows-x64_bin.exe /s ADDLOCAL="ToolsFeature" /s
del /f jdk-19.0.2_windows-x64_bin.exe
setx /M JAVA_HOME "C:\Program Files\Java\jdk-19.0.2"
setx /M PATH "%PATH%;%JAVA_HOME%\bin"
) else (
echo JDK already installed.
)

rem Install Apache Maven
echo Installing Apache Maven...
if not exist "%ProgramFiles%\Apache Maven\apache-maven-3.9.0\" (
mkdir C:\temp
cd C:\temp
powershell Invoke-WebRequest -Uri "https://dlcdn.apache.org/maven/maven-3/3.9.0/binaries/apache-maven-3.9.0-bin.zip" -OutFile apache-maven-3.9.0-bin.zip
powershell Expand-Archive apache-maven-3.9.0-bin.zip -DestinationPath \"%ProgramFiles%\Apache Maven\"
del /f apache-maven-3.9.0-bin.zip
setx /M PATH "%PATH%;%ProgramFiles%\Apache Maven\apache-maven-3.9.0-bin\bin"
) else (
echo Apache Maven already installed.
)

rem Download and install ANTLR
echo Downloading ANTLR...
if not exist "%ProgramFiles%\ANTLR" (
mkdir "%ProgramFiles%\ANTLR"
cd "%ProgramFiles%\ANTLR"
powershell Invoke-WebRequest -Uri "https://www.antlr.org/download/antlr-4.11.1-complete.jar" -OutFile "antlr-4.11.1-complete.jar"
setx /M PATH "%PATH%;%ProgramFiles%\ANTLR\"
setx /M CLASSPATH ".;%ProgramFiles%\ANTLR\antlr-4.11.1-complete.jar;%CLASSPATH%"
)

echo ANTLR installation complete.

rem Checking Compatablity for Golang
echo Checking if current version of Golang >= Go 1.18.....
set "minimum_version=1.18"
set "installed_version="
set "download_url=https://go.dev/dl/go1.19.7.windows-amd64.msi"

:: Check if Go is installed and get its version
set "go_path="
for %%i in (go.exe) do set "go_path=%%~$PATH:i"
if defined go_path (
for /f "tokens=3" %%v in ('go version 2^>^&1') do set "installed_version=%%v"
)

:: If Go is not installed or the version is less than 1.18, prompt the user to install a new version
if not defined installed_version (
echo installing Go
:: Download and install the latest version of Go
powershell -Command "& {Invoke-WebRequest -Uri "%download_url%" -OutFile '%TEMP%\go-minimum-version.msi'}"
start /wait msiexec /i "%TEMP%\go-minimum-version.msi"
for /f "tokens=3" %%v in ('go version 2^>^&1') do set "installed_version=%%v"
) else if "%installed_version%" lss "%minimum_version%" (
set /p "install_new_version=Go version %minimum_version% or higher is required. Would you like to install the latest version? (y/n)"
if /i "%install_new_version%"=="y" (
:: Download and install the latest version of Go
powershell -Command "& {Invoke-WebRequest -Uri "%download_url%" -OutFile '%TEMP%\go-minimum-version.msi'}"
start /wait msiexec /i "%TEMP%\go-minimum_version.msi"
for /f "tokens=3" %%v in ('go version 2^>^&1') do set "installed_version=%%v"
) else (
echo Please update Go version before installing driver.
goto skip
)
)

rem Installing Driver
echo --^> Generating ANTLR parser ^& lexer ^for Golang%
java org.antlr.v4.Tool -Dlanguage=Go -visitor Age.g4 -o parser/
echo --^> Installing Driver
go get -u ./...
goto end
:skip
echo Aborted
:end
pause
endlocal
141 changes: 141 additions & 0 deletions drivers/golang/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
#!/bin/sh

os=$(uname)
arch=$(uname -m)

java=$(java -version 2>&1 | head -n 1 | cut -d ' ' -f 3 | cut -d '.' -f 1 | cut -d '"' -f 2)
# Check JDK version
echo "Checking for JDK..."
if ! java -version >/dev/null 2>&1 || [ $java -lt 11 ]; then
echo "JDK not found or less than version 11, would you like to install? ()"
echo "Y/N ->"
read answer
if [ "$answer" = y ] || [ "$answer" = Y ]; then
echo "Installing..."
if [[ "$os" == "Darwin" ]]; then
cd /tmp
if [[ "$arch" == "x86_64" ]]; then
curl "https://download.oracle.com/java/20/latest/jdk-20_macos-x64_bin.dmg" -o jdk-20_bin.dmg
elif [[ "$arch" == "arm64" ]]; then
curl "https://download.oracle.com/java/20/latest/jdk-20_macos-aarch64_bin.dmg" -o jdk-20_bin.dmg
fi
hdiutil mount jdk-20_bin.dmg
# sudo installer -pkg "/Volumes/JDK 20/JDK 20.pkg" -target "/"
sudo open -w "/Volumes/JDK 20/JDK 20.pkg"
hdiutil unmount "/Volumes/JDK 20"
rm jdk-20_bin.dmg

elif [[ "$os" == "Linux" ]]; then
mkdir -p ~/tmp/jdk20
cd ~/tmp/jdk20
if [[ "$arch" == "x86_64" ]]; then
curl "https://download.oracle.com/java/20/latest/jdk-20_linux-x64_bin.tar.gz" -o jdk-20_bin.tar.gz
elif [[ "$arch" == "arm64" ]]; then
curl "https://download.oracle.com/java/20/latest/jdk-20_linux-aarch64_bin.tar.gz" -o jdk-20_bin.tar.gz
fi
sudo tar zxvf jdk-20_bin.tar.gz -C /usr/local/
cd ~/
rm -rf ~/tmp/jdk20/
fi
echo "JDK installation complete."
else
echo "Please install JDK >= 11.0.16"
exit 0
fi
else
echo "JDK already installed."
fi

antlr=$(/usr/local/jdk-20/bin/jar xf /usr/local/antlr/antlr-*-complete.jar META-INF/MANIFEST.MF >/dev/null 2>&1 && grep 'Implementation-Version' META-INF/MANIFEST.MF | cut -d ' ' -f 2 && rm -rf META-INF)
# Check ANTLR installation and version
echo "Checking for ANTLR..."
check_antlr () {
if [ ! -z $antlr ]; then
if ([ "$(echo $antlr | cut -d '.' -f 1)" -lt 4 ] && [ "$(echo $antlr | cut -d '.' -f 2)" -lt 11 ] && [ "$(echo $antlr | cut -d '.' -f 3)" -lt 1 ]); then
return 0
else
return 1
fi
else
return 0
fi
}

if check_antlr; then
echo "ANTLR not found in Default Location or less than version 4.11.1, would you like to Install?"
echo "(If installed in other location, please edit the location inside the shell script before running)"
echo "Y/N ->"
read answer
if [ "$answer" = y ] || [ "$answer" = Y ]; then
mkdir -p ~/tmp/antlr4.11.1
cd ~/tmp/antlr4.11.1
curl -LO "https://www.antlr.org/download/antlr-4.11.1-complete.jar"
sudo mkdir -p /usr/local/antlr
sudo mv ~/tmp/antlr4.11.1/antlr-4.11.1-complete.jar /usr/local/antlr/antlr-4.11.1-complete.jar

echo 'export CLASSPATH=".:/usr/local/antlr/antlr-4.11.1-complete.jar"' >>~/.bashrc
. ~/.bashrc
echo "ANTLR installation complete."
else
echo "Please install ANTLR >= 4.11.1"
exit 0
fi
#
else
echo "ANTLR already installed."
fi

# Check Go installation and version
echo "Checking for Go..."
if ! command -v go >/dev/null 2>&1 || { [ $(go version | grep -o -E '[0-9]+\.[0-9]+' | head -n 1 | cut -d '.' -f 1) -lt 1 ] && [ $(go version | grep -o -E '[0-9]+\.[0-9]+' | head -n 1 | cut -d '.' -f 2) -lt 19 ]; }; then
echo "Go not installed or version is less than 1.19, would you like to install?"
echo "Y/N ->"
read answer
if [ "$answer" = y ] || [ "$answer" = Y ]; then
if [[ "$os" == "Darwin" ]]; then
cd /tmp
if [[ "$arch" == "x86_64" ]]; then
curl "https://go.dev/dl/go1.20.2.darwin-amd64.pkg" -o go1.20.2.pkg
elif [[ "$arch" == "arm64" ]]; then
curl "https://go.dev/dl/go1.20.2.darwin-arm64.pkg" -o go1.20.2.pkg
fi

#sudo installer -pkg "go1.20.2.pkg" -target "/"
sudo open -w golang.pkg

elif [[ "$os" == "Linux" ]]; then
mdkir -p ~/tmp/go1.20.2
cd ~/tmp/go1.20.2
if [[ "$arch" == "x86_64" ]]; then
curl "https://go.dev/dl/go1.20.2.linux-amd64.tar.gz" -o go1.20.2.tar.gz
elif [[ "$arch" == "arm64" ]]; then
curl "https://go.dev/dl/go1.20.2.linux-arm64.tar.gz" -o go1.20.2.tar.gz
fi

if command -v go >/dev/null 2>&1; then
rm -rf /usr/local/go
fi
sudo tar -C /usr/local -xzf go1.20.2.linux-amd64.tar.gz

if ! [[ ":$PATH:" == *":/usr/local/go/bin:"* ]]; then
export PATH=$PATH:/usr/local/go/bin
fi
fi
echo "Go installation complete"
else
echo "Please install Go >= 1.19"
exit 0
fi
else
echo "Go already installed."
fi



echo "Generating Parser & Lexer..."
java -Xmx500M -cp "/usr/local/lib/antlr-4.11.1-complete.jar:$CLASSPATH" org.antlr.v4.Tool -Dlanguage=Go -visitor Age.g4

echo "Installing Driver..."
go get -u ./...
echo "Successfully Installed Driver!"
exit 0
13 changes: 0 additions & 13 deletions drivers/golang/parser/README.md

This file was deleted.

Loading