Socket
Book a DemoInstallSign in
Socket

io.github.willena:influxql

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

io.github.willena:influxql

InfluxQL query builder and parser

1.2.1
Source
mavenMaven
Version published
Maintainers
1
Source

InfluxQL

CI MVN JDOC SNAP

Java library inspired from the official influxql and influxqb go package.

Building strongly typed and secure InfluxQL queries from string is not always an easy task You have to take care of the sanitization, keep the distinction between function, identifier, numbers and string literals to build a valid query.

The influxQL parser contains all the required types to manually build a query from scratch. More importantly it also contains String() method on each type and statement. The parse r then take care of escaping character, putting quotes or not, ...

The implementation is based on types from the go parser AST. Once a statement object is built the properly formated and escaped InfluxQL statement can be obtained by calling toString()

Download

Relases can be found from Maven and as github artifacts.


<dependency>
    <groupId>io.github.willena</groupId>
    <artifactId>influxql</artifactId>
    <version>${version}</version>
</dependency>

General information

  • Do not hesitate to check the JavaDoc
  • If you find something that is not working as expected, feel free to open a new issue or even better a pull requests.
  • No runtime checks are made. The generated query is only guaranteed to be syntax valid. Only the influxdb server will in the end decide if the request is valid, can be executed and targets existing data.

Query builder

Statements

See the list of statements and their builder

Shortcuts for functions, selectors, aggregations

All functions are an instance of the Call class. The FunctionFactory class defines a lot of static methods for known functions: See JavaDoc page

Simple Example


import io.github.willena.influxql.ast.expr.Dimension;
import io.github.willena.influxql.ast.expr.VarRef;
import io.github.willena.influxql.ast.field.Field;
import io.github.willena.influxql.ast.source.Measurement;
import io.github.willena.influxql.ast.statement.AlterRetentionPolicyStatement;
import io.github.willena.influxql.ast.statement.SelectStatement;
import io.github.willena.influxql.ast.extra.FunctionFactory.Aggregations.mean;
import io.github.willena.influxql.ast.source.Measurement.measurement;
import io.github.willena.influxql.ast.expr.Dimension.sampledBy;

import java.time.Duration;

public static void main(String[] args) {
    AlterRetentionPolicyStatement stm = new AlterRetentionPolicyStatement.Builder()
            .on("DB")
            .policyName("Policy")
            .build();

    System.out.println(stm);
    // Prints 'ALTER RETENTION POLICY Policy ON "DB"'

    SelectStatement select = new SelectStatement.Builder()
            .select(Field.of(mean(VarRef.of("field"))))
            .from(measurement("meas"))
            .groupBy(sampledBy(Duration.ofDays(1)))
            .build();
    System.out.println(select);
    // Prints 'SELECT MEAN(field) FROM meas GROUP BY time(1d)'
}

InfluxQL Parser

Parse multiple queries


import io.github.willena.influxql.ast.Query;
import io.github.willena.influxql.ast.statement.SelectStatement;

public static void main(String[] args) {
    Query st = Query.parse("CREATE DATABASE dbName; SELECT * FROM dbname WHERE time > '2020-01-01T00:00:00.000Z' and time < '2021-01-01T00:00:00.000Z'");
}

Parse single query


import io.github.willena.influxql.ast.Query;
import io.github.willena.influxql.ast.statement.SelectStatement;

public static void main(String[] args) {
    Query st = Query.parse("SELECT * FROM dbname WHERE time > '2020-01-01T00:00:00.000Z' and time < '2021-01-01T00:00:00.000Z'");
}

Parse specific statement


import io.github.willena.influxql.ast.statement.SelectStatement;

public static void main(String[] args) {
    SelectStatement st = SelectStatement.parse("SELECT * FROM dbname WHERE time > '2020-01-01T00:00:00.000Z' and time < '2021-01-01T00:00:00.000Z'");
}

Licence

   InfluxQL Java package
   Copyright 2024 Guillaume VILLENA aka "Willena"
   
   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at
   
      http://www.apache.org/licenses/LICENSE-2.0
   
   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.

FAQs

Package last updated on 03 Aug 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.