Skip to content

Commit

Permalink
feat: query and write (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
bednar authored Jun 7, 2023
1 parent 91a0a2e commit c7ea599
Show file tree
Hide file tree
Showing 32 changed files with 4,026 additions and 85 deletions.
74 changes: 9 additions & 65 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,72 +1,16 @@
version: 2.1
commands:
client-test:
parameters:
project:
type: string
default: "Client.Test"
steps:
- checkout
- run:
name: Install Dependencies
command: |
dotnet restore
dotnet build --no-restore
- run:
name: Create a temp directory for artifacts
command: |
mkdir -p /tmp/artifacts
mkdir test-results
- run:
name: Run tests
command: dotnet test << parameters.project >> --collect "Xplat Code Coverage" --logger "junit;LogFilePath=../test-results/test-result.xml"
- run:
name: Coverage Report
command: |
dotnet tool install --tool-path="./reportgenerator/" dotnet-reportgenerator-globaltool
./reportgenerator/reportgenerator -reports:"<< parameters.project >>/TestResults/*/coverage.cobertura.xml" -targetdir:"report" -reporttypes:HtmlSummary "-sourcedirs:Client/"
mv report/summary.html /tmp/artifacts
cp test-results/test-result.xml /tmp/artifacts
when: always
- run:
name: Report test results to codecov
command: |
apt-get update
apt-get install gpg --yes
curl -Os https://uploader.codecov.io/latest/linux/codecov
curl -Os https://uploader.codecov.io/latest/linux/codecov.SHA256SUM
curl -Os https://uploader.codecov.io/latest/linux/codecov.SHA256SUM.sig
curl https://keybase.io/codecovsecurity/pgp_keys.asc | gpg --no-default-keyring --keyring trustedkeys.gpg --import
gpgv codecov.SHA256SUM.sig codecov.SHA256SUM
shasum -a 256 -c codecov.SHA256SUM
chmod +x ./codecov
./codecov
- store_artifacts:
path: /tmp/artifacts
- store_test_results:
path: test-results


jobs:
tests-java:
parameters:
maven-image:
type: string
default: &default-maven-image "cimg/openjdk:8.0"
arg-line:
type: string
default: ""
docker:
- image: << parameters.maven-image >>
- image: voltrondata/flight-sql:latest
environment:
FLIGHT_PASSWORD: "flight_password"
PRINT_QUERIES: "1"
- image: influxdb:latest
environment:
DOCKER_INFLUXDB_INIT_MODE: "setup"
DOCKER_INFLUXDB_INIT_USERNAME: "my-user"
DOCKER_INFLUXDB_INIT_PASSWORD: "my-password"
DOCKER_INFLUXDB_INIT_ORG: "my-org"
DOCKER_INFLUXDB_INIT_BUCKET: "my-bucket"
DOCKER_INFLUXDB_INIT_ADMIN_TOKEN: "my-token"
steps:
- checkout
- restore_cache:
Expand All @@ -77,7 +21,7 @@ jobs:
- run:
name: "Running tests"
command: |
mvn -B -U clean install -Dbuild.env=CI
mvn -B -U clean install -DargLine="@{argLine} << parameters.arg-line >>"
- save_cache:
name: Saving Maven Cache
key: *cache-key
Expand Down Expand Up @@ -125,7 +69,7 @@ jobs:
- maven-cache_v1-<< parameters.maven-image >>-
- run:
name: "Check dependency rules"
command: mvn enforcer:enforce -Drules=banDuplicatePomDependencyVersions,dependencyConvergence
command: mvn enforcer:enforce -Denforcer.rules=banDuplicatePomDependencyVersions,dependencyConvergence

check-licenses:
parameters:
Expand All @@ -150,14 +94,14 @@ workflows:
jobs:
- check-dependencies
- check-licenses
- tests-java:
name: jdk-8
- tests-java:
name: jdk-11
maven-image: "cimg/openjdk:11.0"
- tests-java:
name: jdk-17
maven-image: "cimg/openjdk:17.0"
arg-line: "--add-opens=java.base/java.nio=ALL-UNNAMED"
- tests-java:
name: jdk-19
maven-image: "cimg/openjdk:19.0"
name: jdk-20
maven-image: "cimg/openjdk:20.0"
arg-line: "--add-opens=java.base/java.nio=ALL-UNNAMED"
1 change: 1 addition & 0 deletions .github/workflows/linter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,5 @@ jobs:
VALIDATE_MARKDOWN: true
VALIDATE_BASH: true
VALIDATE_JAVA: true
JAVA_FILE_NAME: 'checkstyle.xml'
VALIDATE_GITHUB_ACTIONS: true
72 changes: 67 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,15 @@ The Java client that provides an easy and convenient way to interact with Influx
This package supports both writing data to InfluxDB and querying data using the FlightSQL client,
which allows you to execute SQL queries against InfluxDB IOx.

> :warning: This client requires Java 11 and is compatible up to and including Java 20.
## Installation

> :warning: Some JDK internals must be exposed by adding `--add-opens=java.base/java.nio=ALL-UNNAMED` to your JVM arguments.
Add the latest version of the client to your project:

##### Maven dependency:
### Maven dependency

```xml
<dependency>
Expand All @@ -42,7 +46,7 @@ Add the latest version of the client to your project:
</dependency>
```

##### Or when using Gradle:
### Or when using Gradle

```groovy
dependencies {
Expand All @@ -55,19 +59,77 @@ dependencies {
To start with the client, import the `com.influxdb.v3.client` package and create a `InfluxDBClient` by:

```java
// TBD
package com.influxdb.v3;

import java.time.Instant;
import java.util.stream.Stream;

import com.influxdb.v3.client.InfluxDBClient;
import com.influxdb.v3.client.query.QueryParameters;
import com.influxdb.v3.client.write.Point;

public class IOxExample {
public static void main(String[] args) throws Exception {
String hostUrl = "https://us-east-1-1.aws.cloud2.influxdata.com";
char[] authToken = "my-token".toCharArray();
String database = "database";

try (InfluxDBClient client = InfluxDBClient.getInstance(hostUrl, authToken, database)) {
// ...
}
}
}
```

to insert data, you can use code like this:

```java
// TBD
//
// Write by Point
//
Point point = Point.measurement("temperature")
.addTag("location", "west")
.addField("value", 55.15)
.setTimestamp(Instant.now().minusSeconds(-10));
client.writePoint(point);

//
// Write by LineProtocol
//
String record = "temperature,location=north value=60.0";
client.writeRecord(record);
```

to query your data, you can use code like this:

```java
// TBD
//
// Query by SQL
//
System.out.printf("--------------------------------------------------------%n");
System.out.printf("| %-8s | %-8s | %-30s |%n", "location", "value", "time");
System.out.printf("--------------------------------------------------------%n");

String sql = "select time,location,value from temperature order by time desc limit 10";
try (Stream<Object[]> stream = client.query(sql)) {
stream.forEach(row -> System.out.printf("| %-8s | %-8s | %-30s |%n", row[1], row[2], row[0]));
}

System.out.printf("--------------------------------------------------------%n%n");

//
// Query by InfluxQL
//
System.out.printf("-----------------------------------------%n");
System.out.printf("| %-16s | %-18s |%n", "time", "mean");
System.out.printf("-----------------------------------------%n");

String influxQL = "select MEAN(value) from temperature group by time(1d) fill(none) order by time desc limit 10";
try (Stream<Object[]> stream = client.query(influxQL, QueryParameters.INFLUX_QL)) {
stream.forEach(row -> System.out.printf("| %-16s | %-18s |%n", row[1], row[2]));
}

System.out.printf("-----------------------------------------%n");
```

## Feedback
Expand Down
3 changes: 1 addition & 2 deletions checkstyle.xml
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
<property name="specialImportsRegExp" value="com.influxdb"/>
<property name="sortImportsInGroupAlphabetically" value="true"/>
<property name="customImportOrderRules"
value="STANDARD_JAVA_PACKAGE###SPECIAL_IMPORTS###THIRD_PARTY_PACKAGE###STATIC"/>
value="STANDARD_JAVA_PACKAGE###THIRD_PARTY_PACKAGE###SPECIAL_IMPORTS###STATIC"/>
</module>


Expand Down Expand Up @@ -143,7 +143,6 @@
<!--module name="HiddenField"/-->
<module name="IllegalInstantiation"/>
<module name="InnerAssignment"/>
<module name="MagicNumber"/>
<module name="MissingSwitchDefault"/>
<!--<module name="RedundantThrows"/>-->
<module name="SimplifyBooleanExpression"/>
Expand Down
38 changes: 38 additions & 0 deletions examples/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
target/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
!**/src/test/**/target/

### IntelliJ IDEA ###
.idea/modules.xml
.idea/jarRepositories.xml
.idea/compiler.xml
.idea/libraries/
*.iws
*.iml
*.ipr

### Eclipse ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache

### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
build/
!**/src/main/**/build/
!**/src/test/**/build/

### VS Code ###
.vscode/

### Mac OS ###
.DS_Store
8 changes: 8 additions & 0 deletions examples/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Examples

> :warning: The examples depends on the "influxdb3-java" module and this module should be built first by running "mvn install" in the root directory.
> :warning: Some JDK internals must be exposed by adding `--add-opens=java.base/java.nio=ALL-UNNAMED` to your JVM arguments.
## Basic

- [IOxExample](src/main/java/com/influxdb/v3/IOxExample.java) - How to use write and query data from InfluxDB IOx
81 changes: 81 additions & 0 deletions examples/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<!--
The MIT License
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.influxdb.v3</groupId>
<artifactId>examples</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
<dependency>
<groupId>com.influxdb</groupId>
<artifactId>influxdb3-java</artifactId>
<version>1.0.0-SNAPSHOT</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.10.1</version>
<configuration>
<release>11</release>
</configuration>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>3.2.1</version>
<configuration>
<failsOnError>true</failsOnError>
<configLocation>../checkstyle.xml</configLocation>
<consoleOutput>true</consoleOutput>
<linkXRef>false</linkXRef>
<sourceDirectories>
<sourceDirectory>src/main/java</sourceDirectory>
</sourceDirectories>
</configuration>
<executions>
<execution>
<phase>verify</phase>
<goals>
<goal>checkstyle</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

</project>
Loading

0 comments on commit c7ea599

Please sign in to comment.