Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ Context ctx = Context.newDefault();
// Add a hint to make the database create a table with the specified TTL (time-to-live)
ctx = ctx.withHint("ttl", "3d");
// Set the compression algorithm to Zstd.
ctx = ctx.withCompression(Compression.Zstd)
ctx = ctx.withCompression(Compression.Zstd);
// Use the ctx when writing data to GreptimeDB
CompletableFuture<Result<WriteOk, Err>> future = client.write(Arrays.asList(table1, table2), WriteOp.Insert, ctx);
```
Expand Down
10 changes: 5 additions & 5 deletions ingester-example/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ These batching approaches can dramatically improve performance compared to makin

#### Examples

- [LowLevelApiWriteQuickStart.java](src/main/java/io/greptime/LowLevelApiWriteQuickStart.java)
- [LowLevelApiWriteQuickStart.java](src/main/java/io/greptime/quickstart/write/LowLevelApiWriteQuickStart.java)

This example demonstrates how to use the low-level API to write data to GreptimeDB. It covers:
* Defining table schemas with tags, timestamps, and fields
* Writing multiple rows of data to different tables
* Processing write results using the Result pattern
* Deleting data using the `WriteOp.Delete` operation

- [HighLevelApiWriteQuickStart.java](src/main/java/io/greptime/HighLevelApiWriteQuickStart.java)
- [HighLevelApiWriteQuickStart.java](src/main/java/io/greptime/quickstart/write/HighLevelApiWriteQuickStart.java)

This example demonstrates how to use the high-level API to write data to GreptimeDB. It covers:
* Writing data using POJO objects with annotations
Expand All @@ -61,15 +61,15 @@ This API is particularly well-suited for:

#### Examples

- [LowLevelApiStreamWriteQuickStart.java](src/main/java/io/greptime/LowLevelApiStreamWriteQuickStart.java)
- [LowLevelApiStreamWriteQuickStart.java](src/main/java/io/greptime/quickstart/write/LowLevelApiStreamWriteQuickStart.java)

This example demonstrates how to use the low-level API to write data to GreptimeDB using stream. It covers:
* Defining table schemas with tags, timestamps, and fields
* Writing multiple rows of data to different tables via streaming
* Finalizing the stream and retrieving write results
* Deleting data using the `WriteOp.Delete` operation

- [HighLevelApiStreamWriteQuickStart.java](src/main/java/io/greptime/HighLevelApiStreamWriteQuickStart.java)
- [HighLevelApiStreamWriteQuickStart.java](src/main/java/io/greptime/quickstart/write/HighLevelApiStreamWriteQuickStart.java)

This example demonstrates how to use the high-level API to write data to GreptimeDB using stream. It covers:
* Writing POJO objects directly to the stream
Expand Down Expand Up @@ -99,7 +99,7 @@ This API is ideal for scenarios such as:

### Examples

- [BulkWriteApiQuickStart.java](src/main/java/io/greptime/BulkWriteApiQuickStart.java)
- [BulkWriteApiQuickStart.java](src/main/java/io/greptime/quickstart/write/BulkWriteApiQuickStart.java)

This example demonstrates how to use the bulk write API to write large volumes of data to a single table with maximum efficiency. It covers:
* Configuring the bulk writer for optimal performance
Expand Down
22 changes: 20 additions & 2 deletions ingester-example/src/main/java/io/greptime/bench/DBConnector.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,36 @@

import io.greptime.GreptimeDB;
import io.greptime.options.GreptimeOptions;
import io.greptime.quickstart.query.QueryJDBCQuickStart;
import java.io.IOException;
import java.util.Properties;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* DBConnector is a helper class to connect to a GreptimeDB instance.
*/
public class DBConnector {

public static GreptimeDB connectTo(String[] endpoints, String dbname) {
GreptimeOptions opts = GreptimeOptions.newBuilder(endpoints, dbname)
private static final Logger LOG = LoggerFactory.getLogger(DBConnector.class);

public static GreptimeDB connect() {
Properties prop = new Properties();
try {
prop.load(QueryJDBCQuickStart.class.getResourceAsStream("/db-connection.properties"));
} catch (IOException e) {
throw new RuntimeException(e);
}
String database = (String) prop.get("db.database");
String endpointsStr = prop.getProperty("db.endpoints");
String[] endpoints = endpointsStr.split(",");
GreptimeOptions opts = GreptimeOptions.newBuilder(endpoints, database)
.writeMaxRetries(0)
.defaultStreamMaxWritePointsPerSecond(Integer.MAX_VALUE)
.useZeroCopyWriteInBulkWrite(true)
.build();
LOG.info("Connect to db: {}, endpoint: {}", database, endpointsStr);

return GreptimeDB.create(opts);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@
* limitations under the License.
*/

package io.greptime.bench;
package io.greptime.bench.benchmark;

import io.greptime.GreptimeDB;
import io.greptime.WriteOp;
import io.greptime.bench.DBConnector;
import io.greptime.bench.TableDataProvider;
import io.greptime.common.util.MetricsUtil;
import io.greptime.common.util.ServiceLoader;
import io.greptime.common.util.SystemPropertyUtil;
Expand Down Expand Up @@ -51,21 +53,18 @@ public class BatchingWriteBenchmark {
private static final Logger LOG = LoggerFactory.getLogger(BatchingWriteBenchmark.class);

public static void main(String[] args) throws Exception {
String endpoint = SystemPropertyUtil.get("db_endpoint", "127.0.0.1:4001");
String dbName = SystemPropertyUtil.get("db_name", "public");
boolean zstdCompression = SystemPropertyUtil.getBool("zstd_compression", true);
int batchSize = SystemPropertyUtil.getInt("batch_size_per_request", 64 * 1024);
int maxPointsPerSecond = SystemPropertyUtil.getInt("max_points_per_second", Integer.MAX_VALUE);
LOG.info("Connect to db: {}, endpoint: {}", dbName, endpoint);

LOG.info("Using zstd compression: {}", zstdCompression);
LOG.info("Batch size: {}", batchSize);
LOG.info("Max points per second: {}", maxPointsPerSecond);

// Start a metrics exporter
MetricsExporter metricsExporter = new MetricsExporter(MetricsUtil.metricRegistry());
metricsExporter.init(ExporterOptions.newDefault());

GreptimeDB greptimeDB = DBConnector.connectTo(new String[] {endpoint}, dbName);
GreptimeDB greptimeDB = DBConnector.connect();

Compression compression = zstdCompression ? Compression.Zstd : Compression.None;
Context ctx = Context.newDefault().withCompression(compression);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@
* limitations under the License.
*/

package io.greptime.bench;
package io.greptime.bench.benchmark;

import io.greptime.BulkStreamWriter;
import io.greptime.BulkWrite;
import io.greptime.GreptimeDB;
import io.greptime.bench.DBConnector;
import io.greptime.bench.TableDataProvider;
import io.greptime.common.util.MetricsUtil;
import io.greptime.common.util.ServiceLoader;
import io.greptime.common.util.SystemPropertyUtil;
Expand Down Expand Up @@ -47,19 +49,16 @@ public class BulkWriteBenchmark {
private static final Logger LOG = LoggerFactory.getLogger(BulkWriteBenchmark.class);

public static void main(String[] args) throws Exception {
String endpoint = SystemPropertyUtil.get("db_endpoint", "127.0.0.1:4001");
String dbName = SystemPropertyUtil.get("db_name", "public");
boolean zstdCompression = SystemPropertyUtil.getBool("zstd_compression", true);
int batchSize = SystemPropertyUtil.getInt("batch_size_per_request", 64 * 1024);
LOG.info("Connect to db: {}, endpoint: {}", dbName, endpoint);
LOG.info("Using zstd compression: {}", zstdCompression);
LOG.info("Batch size: {}", batchSize);

// Start a metrics exporter
MetricsExporter metricsExporter = new MetricsExporter(MetricsUtil.metricRegistry());
metricsExporter.init(ExporterOptions.newDefault());

GreptimeDB greptimeDB = DBConnector.connectTo(new String[] {endpoint}, dbName);
GreptimeDB greptimeDB = DBConnector.connect();

BulkWrite.Config cfg = BulkWrite.Config.newBuilder()
.allocatorInitReservation(0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@
* limitations under the License.
*/

package io.greptime.bench;
package io.greptime.bench.benchmark;

import io.greptime.GreptimeDB;
import io.greptime.StreamWriter;
import io.greptime.bench.DBConnector;
import io.greptime.bench.TableDataProvider;
import io.greptime.common.util.MetricsUtil;
import io.greptime.common.util.ServiceLoader;
import io.greptime.common.util.SystemPropertyUtil;
Expand Down Expand Up @@ -48,12 +50,9 @@ public class StreamingWriteBenchmark {
private static final Logger LOG = LoggerFactory.getLogger(StreamingWriteBenchmark.class);

public static void main(String[] args) throws Exception {
String endpoint = SystemPropertyUtil.get("db_endpoint", "127.0.0.1:4001");
String dbName = SystemPropertyUtil.get("db_name", "public");
boolean zstdCompression = SystemPropertyUtil.getBool("zstd_compression", true);
int batchSize = SystemPropertyUtil.getInt("batch_size_per_request", 64 * 1024);
int maxPointsPerSecond = SystemPropertyUtil.getInt("max_points_per_second", Integer.MAX_VALUE);
LOG.info("Connect to db: {}, endpoint: {}", dbName, endpoint);
LOG.info("Using zstd compression: {}", zstdCompression);
LOG.info("Batch size: {}", batchSize);
LOG.info("Max points per second: {}", maxPointsPerSecond);
Expand All @@ -62,7 +61,7 @@ public static void main(String[] args) throws Exception {
MetricsExporter metricsExporter = new MetricsExporter(MetricsUtil.metricRegistry());
metricsExporter.init(ExporterOptions.newDefault());

GreptimeDB greptimeDB = DBConnector.connectTo(new String[] {endpoint}, dbName);
GreptimeDB greptimeDB = DBConnector.connect();

Compression compression = zstdCompression ? Compression.Zstd : Compression.None;
Context ctx = Context.newDefault().withCompression(compression);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@
* limitations under the License.
*/

package io.greptime;
package io.greptime.metric;

import io.greptime.models.Column;
import io.greptime.models.DataType;
import io.greptime.models.Metric;

/**
*
* Memory metric class that represents CPU usage statistics.
*/
@Metric(name = "cpu_metric")
public class Cpu {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@
* limitations under the License.
*/

package io.greptime;
package io.greptime.metric;

import io.greptime.models.Column;
import io.greptime.models.DataType;
import io.greptime.models.Metric;

/**
*
* Memory metric class that represents memory usage statistics.
*/
@Metric(name = "mem_metric")
public class Memory {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,17 @@
* limitations under the License.
*/

package io.greptime;
package io.greptime.quickstart;

import io.greptime.GreptimeDB;
import io.greptime.common.util.SerializingExecutor;
import io.greptime.limit.LimitedPolicy;
import io.greptime.models.AuthInfo;
import io.greptime.options.GreptimeOptions;
import io.greptime.quickstart.query.QueryJDBCQuickStart;
import io.greptime.rpc.RpcOptions;
import java.io.IOException;
import java.util.Properties;

/**
*
Expand All @@ -30,11 +34,19 @@ public class TestConnector {
public static GreptimeDB connectToDefaultDB() {
// GreptimeDB has a default database named "public" in the default catalog "greptime",
// we can use it as the test database
String database = "public";
Properties prop = new Properties();

try {
prop.load(QueryJDBCQuickStart.class.getResourceAsStream("/db-connection.properties"));
} catch (IOException e) {
throw new RuntimeException(e);
}
String database = (String) prop.get("db.database");
// By default, GreptimeDB listens on port 4001 using the gRPC protocol.
// We can provide multiple endpoints that point to the same GreptimeDB cluster.
// The client will make calls to these endpoints based on a load balancing strategy.
String[] endpoints = {"127.0.0.1:4001"};
String endpointsStr = prop.getProperty("db.endpoints");
String[] endpoints = endpointsStr.split(",");
GreptimeOptions opts = GreptimeOptions.newBuilder(endpoints, database) // Optional, the default value is fine.
// Asynchronous thread pool, which is used to handle various asynchronous
// tasks in the SDK (You are using a purely asynchronous SDK). If you do not
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@
* limitations under the License.
*/

package io.greptime;
package io.greptime.quickstart.query;

import io.greptime.GreptimeDB;
import io.greptime.metric.Cpu;
import io.greptime.quickstart.TestConnector;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
Expand All @@ -33,9 +36,9 @@
/**
*
*/
public class QueryJDBC {
public class QueryJDBCQuickStart {

private static final Logger LOG = LoggerFactory.getLogger(QueryJDBC.class);
private static final Logger LOG = LoggerFactory.getLogger(QueryJDBCQuickStart.class);

public static void main(String[] args) throws Exception {
GreptimeDB greptimeDB = TestConnector.connectToDefaultDB();
Expand Down Expand Up @@ -82,7 +85,7 @@ public static void main(String[] args) throws Exception {

public static Connection getConnection() throws IOException, ClassNotFoundException, SQLException {
Properties prop = new Properties();
prop.load(QueryJDBC.class.getResourceAsStream("/db-connection.properties"));
prop.load(QueryJDBCQuickStart.class.getResourceAsStream("/db-connection.properties"));

String dbName = (String) prop.get("db.database-driver");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,16 @@
* limitations under the License.
*/

package io.greptime;
package io.greptime.quickstart.write;

import io.greptime.BulkStreamWriter;
import io.greptime.BulkWrite.Config;
import io.greptime.GreptimeDB;
import io.greptime.common.util.StringBuilderHelper;
import io.greptime.models.DataType;
import io.greptime.models.Table;
import io.greptime.models.TableSchema;
import io.greptime.quickstart.TestConnector;
import io.greptime.rpc.Compression;
import io.greptime.rpc.Context;
import java.math.BigDecimal;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,15 @@
* limitations under the License.
*/

package io.greptime;
package io.greptime.quickstart.write;

import io.greptime.GreptimeDB;
import io.greptime.StreamWriter;
import io.greptime.WriteOp;
import io.greptime.metric.Cpu;
import io.greptime.metric.Memory;
import io.greptime.models.WriteOk;
import io.greptime.quickstart.TestConnector;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CompletableFuture;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,16 @@
* limitations under the License.
*/

package io.greptime;
package io.greptime.quickstart.write;

import io.greptime.GreptimeDB;
import io.greptime.WriteOp;
import io.greptime.metric.Cpu;
import io.greptime.metric.Memory;
import io.greptime.models.Err;
import io.greptime.models.Result;
import io.greptime.models.WriteOk;
import io.greptime.quickstart.TestConnector;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,16 @@
* limitations under the License.
*/

package io.greptime;
package io.greptime.quickstart.write;

import io.greptime.GreptimeDB;
import io.greptime.StreamWriter;
import io.greptime.WriteOp;
import io.greptime.models.DataType;
import io.greptime.models.Table;
import io.greptime.models.TableSchema;
import io.greptime.models.WriteOk;
import io.greptime.quickstart.TestConnector;
import io.greptime.rpc.Compression;
import io.greptime.rpc.Context;
import java.util.concurrent.CompletableFuture;
Expand Down
Loading