Skip to content

Commit c9efa77

Browse files
authored
Merge pull request #14 from VictoriaMetrics/jdbc-driver
Initial JDBC driver support
2 parents ad07c97 + 259eb9f commit c9efa77

File tree

20 files changed

+4344
-9
lines changed

20 files changed

+4344
-9
lines changed

.github/workflows/release.yml

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ permissions:
1111
id-token: write
1212

1313
jobs:
14-
release:
14+
release-sql-to-logsql:
1515
runs-on: ubuntu-latest
1616
steps:
1717

@@ -90,3 +90,50 @@ jobs:
9090
args: release --clean --verbose --timeout 60m -f .goreleaser.yaml
9191
env:
9292
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
93+
94+
release-logsql-jdbc:
95+
runs-on: ubuntu-latest
96+
steps:
97+
98+
- name: Checkout
99+
uses: actions/checkout@v5
100+
with:
101+
fetch-depth: '0'
102+
fetch-tags: 'true'
103+
104+
- name: Install JDK and Maven
105+
uses: actions/setup-java@v4
106+
with:
107+
distribution: 'temurin'
108+
java-version: '11'
109+
cache: 'maven'
110+
111+
- name: Fetch tags
112+
run: |
113+
if [[ "${{ github.ref_type }}" != "tag" ]]; then
114+
git fetch --tags
115+
else
116+
echo "Skipping tag fetch - already on tag ${{ github.ref_name }}"
117+
fi
118+
119+
- name: Update Configuration
120+
working-directory: logsql-jdbc
121+
run: |
122+
if [[ "${{ github.ref_type }}" == "tag" ]]; then
123+
TAG_VERSION=$(echo "${{ github.ref_name }}" | sed 's/^v//')
124+
else
125+
LATEST_TAG=$(git tag --sort=-version:refname | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+(-.*)?$' | head -n 1)
126+
[ -z "$LATEST_TAG" ] && { echo "No release tag found"; exit 1; }
127+
TAG_VERSION=$(echo "$LATEST_TAG" | sed 's/^v//')
128+
echo "Using latest tag: $LATEST_TAG"
129+
fi
130+
mvn versions:set versions:commit -DnewVersion="${TAG_VERSION}";
131+
132+
- name: Publish package
133+
working-directory: logsql-jdbc
134+
run: |
135+
mvn -s ${{ github.workspace }}/.github/workflows/settings.xml -DskipTests --batch-mode deploy
136+
rm -rf */target/logsql-jdbc-*.jar
137+
env:
138+
USERNAME: ${{ secrets.USERNAME }}
139+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/settings.xml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
3+
4+
<activeProfiles>
5+
<activeProfile>github</activeProfile>
6+
</activeProfiles>
7+
8+
<profiles>
9+
<profile>
10+
<id>github</id>
11+
<repositories>
12+
<repository>
13+
<id>github</id>
14+
<url>https://maven.pkg.github.com/victoriametrics/sql-to-logsql</url>
15+
<snapshots>
16+
<enabled>true</enabled>
17+
</snapshots>
18+
</repository>
19+
</repositories>
20+
</profile>
21+
</profiles>
22+
23+
<servers>
24+
<server>
25+
<id>github</id>
26+
<username>${env.USERNAME}</username>
27+
<password>${env.GITHUB_TOKEN}</password>
28+
</server>
29+
</servers>
30+
</settings>

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,5 @@ dist-ssr
2222
*.njsproj
2323
*.sln
2424
*.sw?
25-
/sql-to-logsql
25+
/sql-to-logsql
26+
/logsql-jdbc/target/

.goreleaser.yaml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
version: 2
22
project_name: sql-to-logsql
33

4-
#before:
5-
# hooks:
6-
# - make ui-build
7-
84
builds:
95
- env:
106
- CGO_ENABLED=0
@@ -17,8 +13,6 @@ builds:
1713
- arm64
1814
- arm
1915
- "386"
20-
# hooks:
21-
# pre: make ui-build
2216
main: ./cmd/sql-to-logsql/main.go
2317
binary: sql-to-logsql
2418
ldflags:

Makefile

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
UI_DIR=cmd/sql-to-logsql/web/ui
22

3-
.PHONY: ui-install ui-build build backend-build run test
3+
.PHONY: ui-install ui-build build backend-build run test all jdbc-build jdbc-test
44

55
ui-install:
66
cd $(UI_DIR) && npm install
@@ -26,3 +26,9 @@ lint:
2626
bash ./scripts/lint-all.sh
2727

2828
all: test check lint build
29+
30+
jdbc-build:
31+
bash ./scripts/jdbc-build.sh
32+
33+
jdbc-test:
34+
bash ./scripts/jdbc-build.sh

logsql-jdbc/README.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# LogSQL JDBC Driver
2+
3+
This module provides a JDBC 4.0 compatible driver for the VictoriaLogs (via `sql-to-logsql` service).
4+
The driver interacts http(s) with sql-to-logsql API and exposes query results as regular JDBC result sets,
5+
making it possible to integrate VictoriaLogs with the broader JVM ecosystem (BI tools, JDBC-based frameworks, etc.).
6+
7+
## Connection URL
8+
9+
```
10+
jdbc:logsql://host[:port][/basePath]?property=value&...
11+
```
12+
13+
Supported properties:
14+
15+
- `scheme``http` (default) or `https`.
16+
- `endpoint` – optional VictoriaLogs endpoint URL override.
17+
- `bearerToken` – optional bearer token sent to the translation service.
18+
- `timeout` – request timeout in milliseconds (default 60000).
19+
- `verify` – when `false`, TLS certificate validation is disabled.
20+
- `header.<name>` – additional HTTP headers to include with every request.
21+
22+
Example:
23+
24+
```
25+
jdbc:logsql://localhost:8080?scheme=https&endpoint=https%3A%2F%2Fvictorialogs.example.com&bearerToken=secret
26+
```
27+
28+
Properties provided through `java.util.Properties` when creating the connection are merged with the URL query parameters (query parameters take precedence).
29+
30+
## Building
31+
32+
```
33+
mvn -DskipTests package
34+
```
35+
36+
The standard artifact is placed in `target/logsql-jdbc-<version>.jar`, and a fat jar with all dependencies is available as `target/logsql-jdbc-<version>-all.jar`.
37+
38+
## Testing
39+
40+
```
41+
mvn test
42+
```
43+
44+
These integration tests connect to https://play-sql.victoriametrics.com. They will be marked as skipped automatically if the playground cannot be reached (for example, when outbound network access is disabled).
45+
46+
## Notes
47+
48+
- The driver performs a health check against `/healthz` when establishing a connection.
49+
- Result sets are fully buffered in memory to simplify cursor navigation and metadata reporting. Avoid query patterns that return unbounded result sets.
50+
- HTTPS certificate verification can be disabled for testing by setting `verify=false`, but this is not recommended for production use.

logsql-jdbc/pom.xml

Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0"
2+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
6+
<groupId>com.victoriametrics</groupId>
7+
<artifactId>logsql-jdbc</artifactId>
8+
<version>0.0.0-SNAPSHOT</version>
9+
<packaging>jar</packaging>
10+
<name>LogsQL JDBC Driver</name>
11+
<description>JDBC driver for VictoriaLogs (via sql-to-logsql service)</description>
12+
<url>https://github.com/VictoriaMetrics/sql-to-logsql/tree/main/logsql-jdbc</url>
13+
14+
<organization>
15+
<name>VictoriaMetrics Inc.</name>
16+
<url>https://victoriametrics.com/</url>
17+
</organization>
18+
19+
<licenses>
20+
<license>
21+
<name>Apache License 2.0</name>
22+
<url>https://www.apache.org/licenses/LICENSE-2.0</url>
23+
</license>
24+
</licenses>
25+
26+
<developers>
27+
<developer>
28+
<name>VictoriaMetrics</name>
29+
<url>https://victoriametrics.com</url>
30+
</developer>
31+
</developers>
32+
33+
<issueManagement>
34+
<system>Github</system>
35+
<url>https://github.com/VictoriaMetrics/sql-to-logsql/issues</url>
36+
</issueManagement>
37+
38+
<ciManagement>
39+
<system>Github</system>
40+
<url>https://github.com/VictoriaMetrics/sql-to-logsql/actions</url>
41+
</ciManagement>
42+
43+
<distributionManagement>
44+
<repository>
45+
<id>github</id>
46+
<name>GitHub VictoriaMetrics Apache Maven Packages</name>
47+
<url>https://maven.pkg.github.com/VictoriaMetrics/sql-to-logsql</url>
48+
</repository>
49+
</distributionManagement>
50+
51+
<properties>
52+
<spec.title>JDBC</spec.title>
53+
<spec.version>4.2</spec.version>
54+
<maven.compiler.source>11</maven.compiler.source>
55+
<maven.compiler.target>11</maven.compiler.target>
56+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
57+
<jackson.version>2.17.2</jackson.version>
58+
<junit.jupiter.version>5.10.2</junit.jupiter.version>
59+
</properties>
60+
61+
<dependencies>
62+
<dependency>
63+
<groupId>com.fasterxml.jackson.core</groupId>
64+
<artifactId>jackson-databind</artifactId>
65+
<version>${jackson.version}</version>
66+
</dependency>
67+
<dependency>
68+
<groupId>org.junit.jupiter</groupId>
69+
<artifactId>junit-jupiter-api</artifactId>
70+
<version>${junit.jupiter.version}</version>
71+
<scope>test</scope>
72+
</dependency>
73+
<dependency>
74+
<groupId>org.junit.jupiter</groupId>
75+
<artifactId>junit-jupiter-engine</artifactId>
76+
<version>${junit.jupiter.version}</version>
77+
<scope>test</scope>
78+
</dependency>
79+
</dependencies>
80+
81+
<build>
82+
<plugins>
83+
<plugin>
84+
<groupId>org.apache.maven.plugins</groupId>
85+
<artifactId>maven-compiler-plugin</artifactId>
86+
<version>3.11.0</version>
87+
<configuration>
88+
<source>${maven.compiler.source}</source>
89+
<target>${maven.compiler.target}</target>
90+
</configuration>
91+
</plugin>
92+
<plugin>
93+
<groupId>org.apache.maven.plugins</groupId>
94+
<artifactId>maven-jar-plugin</artifactId>
95+
<version>3.3.0</version>
96+
<configuration>
97+
<archive>
98+
<manifestEntries>
99+
<Automatic-Module-Name>com.victoriametrics.logsql.jdbc</Automatic-Module-Name>
100+
</manifestEntries>
101+
</archive>
102+
</configuration>
103+
</plugin>
104+
<plugin>
105+
<groupId>org.apache.maven.plugins</groupId>
106+
<artifactId>maven-shade-plugin</artifactId>
107+
<version>3.5.3</version>
108+
<executions>
109+
<execution>
110+
<phase>package</phase>
111+
<goals>
112+
<goal>shade</goal>
113+
</goals>
114+
<configuration>
115+
<createDependencyReducedPom>false</createDependencyReducedPom>
116+
<shadedArtifactAttached>true</shadedArtifactAttached>
117+
<shadedClassifierName>all</shadedClassifierName>
118+
<filters>
119+
<filter>
120+
<artifact>*:*</artifact>
121+
<excludes>
122+
<exclude>META-INF/*.SF</exclude>
123+
<exclude>META-INF/*.DSA</exclude>
124+
<exclude>META-INF/*.RSA</exclude>
125+
</excludes>
126+
</filter>
127+
</filters>
128+
<transformers>
129+
<transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
130+
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
131+
<manifestEntries>
132+
<Automatic-Module-Name>com.victoriametrics.logsql.jdbc</Automatic-Module-Name>
133+
</manifestEntries>
134+
</transformer>
135+
</transformers>
136+
</configuration>
137+
</execution>
138+
</executions>
139+
</plugin>
140+
<plugin>
141+
<groupId>org.apache.maven.plugins</groupId>
142+
<artifactId>maven-surefire-plugin</artifactId>
143+
<version>3.2.5</version>
144+
<configuration>
145+
<useModulePath>false</useModulePath>
146+
</configuration>
147+
</plugin>
148+
</plugins>
149+
</build>
150+
</project>

0 commit comments

Comments
 (0)