diff --git a/ingester-example/src/main/java/io/greptime/StreamWritePOJOsQuickStart.java b/ingester-example/src/main/java/io/greptime/HighLevelApiStreamWriteQuickStart.java similarity index 90% rename from ingester-example/src/main/java/io/greptime/StreamWritePOJOsQuickStart.java rename to ingester-example/src/main/java/io/greptime/HighLevelApiStreamWriteQuickStart.java index 60ab0f6..8f184ac 100644 --- a/ingester-example/src/main/java/io/greptime/StreamWritePOJOsQuickStart.java +++ b/ingester-example/src/main/java/io/greptime/HighLevelApiStreamWriteQuickStart.java @@ -26,9 +26,9 @@ /** * @author jiachun.fjc */ -public class StreamWritePOJOsQuickStart { +public class HighLevelApiStreamWriteQuickStart { - private static final Logger LOG = LoggerFactory.getLogger(StreamWritePOJOsQuickStart.class); + private static final Logger LOG = LoggerFactory.getLogger(HighLevelApiStreamWriteQuickStart.class); public static void main(String[] args) throws ExecutionException, InterruptedException { GreptimeDB greptimeDB = TestConnector.connectToDefaultDB(); @@ -52,7 +52,7 @@ public static void main(String[] args) throws ExecutionException, InterruptedExc memories.add(m); } - StreamWriter, WriteOk> writer = greptimeDB.streamWriterPOJOs(); + StreamWriter, WriteOk> writer = greptimeDB.objectsStreamWriter(); // write data into stream writer.write(cpus); diff --git a/ingester-example/src/main/java/io/greptime/WritePOJOsQuickStart.java b/ingester-example/src/main/java/io/greptime/HighLevelApiWriteQuickStart.java similarity index 87% rename from ingester-example/src/main/java/io/greptime/WritePOJOsQuickStart.java rename to ingester-example/src/main/java/io/greptime/HighLevelApiWriteQuickStart.java index b372f4d..21478b1 100644 --- a/ingester-example/src/main/java/io/greptime/WritePOJOsQuickStart.java +++ b/ingester-example/src/main/java/io/greptime/HighLevelApiWriteQuickStart.java @@ -29,9 +29,9 @@ /** * @author jiachun.fjc */ -public class WritePOJOsQuickStart { +public class HighLevelApiWriteQuickStart { - private static final Logger LOG = LoggerFactory.getLogger(WritePOJOsQuickStart.class); + private static final Logger LOG = LoggerFactory.getLogger(HighLevelApiWriteQuickStart.class); public static void main(String[] args) throws ExecutionException, InterruptedException { GreptimeDB greptimeDB = TestConnector.connectToDefaultDB(); @@ -58,7 +58,7 @@ public static void main(String[] args) throws ExecutionException, InterruptedExc // For performance reasons, the SDK is designed to be purely asynchronous. // The return value is a future object. If you want to immediately obtain // the result, you can call `future.get()`. - CompletableFuture> puts = greptimeDB.writePOJOs(cpus, memories); + CompletableFuture> puts = greptimeDB.writeObjects(cpus, memories); Result result = puts.get(); @@ -71,8 +71,8 @@ public static void main(String[] args) throws ExecutionException, InterruptedExc LOG.error("Failed to write: {}", simpleResult.getErr()); } - List> delete_pojos = Arrays.asList(cpus.subList(0, 5), memories.subList(0, 5)); - Result deletes = greptimeDB.writePOJOs(delete_pojos, WriteOp.Delete).get(); + List> deletePojoObjects = Arrays.asList(cpus.subList(0, 5), memories.subList(0, 5)); + Result deletes = greptimeDB.writeObjects(deletePojoObjects, WriteOp.Delete).get(); if (deletes.isOk()) { LOG.info("Delete result: {}", result.getOk()); diff --git a/ingester-example/src/main/java/io/greptime/StreamWriteQuickStart.java b/ingester-example/src/main/java/io/greptime/LowLevelApiStreamWriteQuickStart.java similarity index 95% rename from ingester-example/src/main/java/io/greptime/StreamWriteQuickStart.java rename to ingester-example/src/main/java/io/greptime/LowLevelApiStreamWriteQuickStart.java index c5ac60d..d30ea2f 100644 --- a/ingester-example/src/main/java/io/greptime/StreamWriteQuickStart.java +++ b/ingester-example/src/main/java/io/greptime/LowLevelApiStreamWriteQuickStart.java @@ -27,9 +27,9 @@ /** * @author jiachun.fjc */ -public class StreamWriteQuickStart { +public class LowLevelApiStreamWriteQuickStart { - private static final Logger LOG = LoggerFactory.getLogger(StreamWriteQuickStart.class); + private static final Logger LOG = LoggerFactory.getLogger(LowLevelApiStreamWriteQuickStart.class); public static void main(String[] args) throws ExecutionException, InterruptedException { GreptimeDB greptimeDB = TestConnector.connectToDefaultDB(); diff --git a/ingester-example/src/main/java/io/greptime/WriteQuickStart.java b/ingester-example/src/main/java/io/greptime/LowLevelApiWriteQuickStart.java similarity index 96% rename from ingester-example/src/main/java/io/greptime/WriteQuickStart.java rename to ingester-example/src/main/java/io/greptime/LowLevelApiWriteQuickStart.java index 2e55e03..8ea8841 100644 --- a/ingester-example/src/main/java/io/greptime/WriteQuickStart.java +++ b/ingester-example/src/main/java/io/greptime/LowLevelApiWriteQuickStart.java @@ -31,9 +31,9 @@ /** * @author jiachun.fjc */ -public class WriteQuickStart { +public class LowLevelApiWriteQuickStart { - private static final Logger LOG = LoggerFactory.getLogger(WriteQuickStart.class); + private static final Logger LOG = LoggerFactory.getLogger(LowLevelApiWriteQuickStart.class); public static void main(String[] args) throws ExecutionException, InterruptedException { GreptimeDB greptimeDB = TestConnector.connectToDefaultDB(); diff --git a/ingester-example/src/main/java/io/greptime/QueryJDBC.java b/ingester-example/src/main/java/io/greptime/QueryJDBC.java index 5518178..047b2ab 100644 --- a/ingester-example/src/main/java/io/greptime/QueryJDBC.java +++ b/ingester-example/src/main/java/io/greptime/QueryJDBC.java @@ -103,6 +103,6 @@ public static void insertData(GreptimeDB greptimeDB) throws ExecutionException, c.setCpuSys(i + 0.12); cpus.add(c); } - greptimeDB.writePOJOs(cpus).get(); + greptimeDB.writeObjects(cpus).get(); } } diff --git a/ingester-protocol/src/main/java/io/greptime/CachedPojoMapper.java b/ingester-protocol/src/main/java/io/greptime/CachedPojoObjectMapper.java similarity index 92% rename from ingester-protocol/src/main/java/io/greptime/CachedPojoMapper.java rename to ingester-protocol/src/main/java/io/greptime/CachedPojoObjectMapper.java index 39ade93..ae88966 100644 --- a/ingester-protocol/src/main/java/io/greptime/CachedPojoMapper.java +++ b/ingester-protocol/src/main/java/io/greptime/CachedPojoObjectMapper.java @@ -39,15 +39,15 @@ * @author jiachun.fjc */ @SPI(priority = 9) -public class CachedPojoMapper implements PojoMapper { +public class CachedPojoObjectMapper implements PojoObjectMapper { private final LoadingCache, Map> classFieldCache; - public CachedPojoMapper() { + public CachedPojoObjectMapper() { this(1024); } - public CachedPojoMapper(int maxCachedPOJOs) { + public CachedPojoObjectMapper(int maxCachedPOJOs) { this.classFieldCache = CacheBuilder.newBuilder().maximumSize(maxCachedPOJOs) .build(new CacheLoader, Map>() { @@ -60,11 +60,11 @@ public Map load(Class key) { } @Override - public Table mapToTable(List pojos) { - Ensures.ensureNonNull(pojos, "pojos"); - Ensures.ensure(!pojos.isEmpty(), "pojos can not be empty"); + public Table mapToTable(List pojoObjects) { + Ensures.ensureNonNull(pojoObjects, "pojoObjects"); + Ensures.ensure(!pojoObjects.isEmpty(), "pojoObjects can not be empty"); - M first = pojos.get(0); + M first = pojoObjects.get(0); Class metricType = first.getClass(); @@ -88,7 +88,7 @@ public Table mapToTable(List pojos) { } Table table = Table.from(schemaBuilder.build()); - for (M pojo : pojos) { + for (M pojo : pojoObjects) { Class type = pojo.getClass(); if (!type.equals(metricType)) { throw new PojoException("All POJOs must be of the same type"); diff --git a/ingester-protocol/src/main/java/io/greptime/GreptimeDB.java b/ingester-protocol/src/main/java/io/greptime/GreptimeDB.java index c53c5be..84044b7 100644 --- a/ingester-protocol/src/main/java/io/greptime/GreptimeDB.java +++ b/ingester-protocol/src/main/java/io/greptime/GreptimeDB.java @@ -54,7 +54,7 @@ * * @author jiachun.fjc */ -public class GreptimeDB implements Write, WritePOJO, Lifecycle, Display { +public class GreptimeDB implements Write, WriteObject, Lifecycle, Display { private static final Logger LOG = LoggerFactory.getLogger(GreptimeDB.class); @@ -63,7 +63,7 @@ public class GreptimeDB implements Write, WritePOJO, Lifecycle, private static final String VERSION = Util.clientVersion(); private static final String NODE_ID = UUID.randomUUID().toString(); - private static final PojoMapper POJO_MAPPER = getDefaultPojoMapper(); + private static final PojoObjectMapper POJO_OBJECT_MAPPER = getDefaultPojoObjectMapper(); private final int id; private final AtomicBoolean started = new AtomicBoolean(false); @@ -140,21 +140,22 @@ public void ensureInitialized() { } @Override - public CompletableFuture> writePOJOs(Collection> pojos, WriteOp writeOp, Context ctx) { - List rows = new ArrayList<>(pojos.size()); - for (List pojo : pojos) { - rows.add(POJO_MAPPER.mapToTable(pojo)); + public CompletableFuture> writeObjects(Collection> objects, WriteOp writeOp, + Context ctx) { + List
rows = new ArrayList<>(objects.size()); + for (List pojo : objects) { + rows.add(POJO_OBJECT_MAPPER.mapToTable(pojo)); } return write(rows, writeOp, ctx); } @Override - public StreamWriter, WriteOk> streamWriterPOJOs(int maxPointsPerSecond, Context ctx) { + public StreamWriter, WriteOk> objectsStreamWriter(int maxPointsPerSecond, Context ctx) { StreamWriter delegate = streamWriter(maxPointsPerSecond, ctx); return new StreamWriter, WriteOk>() { @Override public StreamWriter, WriteOk> write(List val, WriteOp writeOp) { - Table table = POJO_MAPPER.mapToTable(val); + Table table = POJO_OBJECT_MAPPER.mapToTable(val); delegate.write(table, writeOp); return this; } @@ -320,12 +321,12 @@ private void truncateBuf() { } } - private static PojoMapper getDefaultPojoMapper() { + private static PojoObjectMapper getDefaultPojoObjectMapper() { try { - return ServiceLoader.load(PojoMapper.class).first(); + return ServiceLoader.load(PojoObjectMapper.class).first(); } catch (Throwable t) { LOG.warn("Failed to load `PojoMapper`, use default: `CachedPojoMapper(1024)`", t); - return new CachedPojoMapper(); + return new CachedPojoObjectMapper(); } } diff --git a/ingester-protocol/src/main/java/io/greptime/PojoMapper.java b/ingester-protocol/src/main/java/io/greptime/PojoObjectMapper.java similarity index 90% rename from ingester-protocol/src/main/java/io/greptime/PojoMapper.java rename to ingester-protocol/src/main/java/io/greptime/PojoObjectMapper.java index a0ceddc..56b01e4 100644 --- a/ingester-protocol/src/main/java/io/greptime/PojoMapper.java +++ b/ingester-protocol/src/main/java/io/greptime/PojoObjectMapper.java @@ -23,7 +23,7 @@ * * @author jiachun.fjc */ -public interface PojoMapper { +public interface PojoObjectMapper { - Table mapToTable(List pojos); + Table mapToTable(List pojoObjects); } diff --git a/ingester-protocol/src/main/java/io/greptime/WritePOJO.java b/ingester-protocol/src/main/java/io/greptime/WriteObject.java similarity index 60% rename from ingester-protocol/src/main/java/io/greptime/WritePOJO.java rename to ingester-protocol/src/main/java/io/greptime/WriteObject.java index 2a3ae95..a309f78 100644 --- a/ingester-protocol/src/main/java/io/greptime/WritePOJO.java +++ b/ingester-protocol/src/main/java/io/greptime/WriteObject.java @@ -26,53 +26,53 @@ import java.util.concurrent.CompletableFuture; /** - * Write POJO API: writes data in POJO object format to the DB. + * Write POJO object API: writes data in POJO object format to the DB. * * @author jiachun.fjc */ -public interface WritePOJO { +public interface WriteObject { /** - * @see #writePOJOs(Collection, WriteOp, Context) + * @see #writeObjects(Collection, WriteOp, Context) */ - default CompletableFuture> writePOJOs(List... pojos) { - return writePOJOs(Arrays.asList(pojos)); + default CompletableFuture> writeObjects(List... objects) { + return writeObjects(Arrays.asList(objects)); } /** - * @see #writePOJOs(Collection, WriteOp, Context) + * @see #writeObjects(Collection, WriteOp, Context) */ - default CompletableFuture> writePOJOs(Collection> pojos) { - return writePOJOs(pojos, WriteOp.Insert, Context.newDefault()); + default CompletableFuture> writeObjects(Collection> objects) { + return writeObjects(objects, WriteOp.Insert, Context.newDefault()); } /** - * @see #writePOJOs(Collection, WriteOp, Context) + * @see #writeObjects(Collection, WriteOp, Context) */ - default CompletableFuture> writePOJOs(Collection> pojos, WriteOp writeOp) { - return writePOJOs(pojos, writeOp, Context.newDefault()); + default CompletableFuture> writeObjects(Collection> objects, WriteOp writeOp) { + return writeObjects(objects, writeOp, Context.newDefault()); } /** * Write multiple rows of data (which can belong to multiple tables) to the database at once. * - * @param pojos a collection of data to be written, classified by table + * @param objects a collection of data to be written, classified by table * @param writeOp write operation(insert or delete) * @param ctx invoke context * @return write result */ - CompletableFuture> writePOJOs(Collection> pojos, WriteOp writeOp, Context ctx); + CompletableFuture> writeObjects(Collection> objects, WriteOp writeOp, Context ctx); /** - * @see #streamWriterPOJOs(int, Context) + * @see #objectsStreamWriter(int, Context) */ - default StreamWriter, WriteOk> streamWriterPOJOs() { - return streamWriterPOJOs(-1); + default StreamWriter, WriteOk> objectsStreamWriter() { + return objectsStreamWriter(-1); } /** - * @see #streamWriterPOJOs(int, Context) + * @see #objectsStreamWriter(int, Context) */ - default StreamWriter, WriteOk> streamWriterPOJOs(int maxPointsPerSecond) { - return streamWriterPOJOs(maxPointsPerSecond, Context.newDefault()); + default StreamWriter, WriteOk> objectsStreamWriter(int maxPointsPerSecond) { + return objectsStreamWriter(maxPointsPerSecond, Context.newDefault()); } /** @@ -90,5 +90,5 @@ default StreamWriter, WriteOk> streamWriterPOJOs(int maxPointsPerSecond) * @param ctx invoke context * @return a stream writer instance */ - StreamWriter, WriteOk> streamWriterPOJOs(int maxPointsPerSecond, Context ctx); + StreamWriter, WriteOk> objectsStreamWriter(int maxPointsPerSecond, Context ctx); } diff --git a/ingester-protocol/src/main/resources/META-INF/services/io.greptime.PojoMapper b/ingester-protocol/src/main/resources/META-INF/services/io.greptime.PojoMapper deleted file mode 100644 index 231782d..0000000 --- a/ingester-protocol/src/main/resources/META-INF/services/io.greptime.PojoMapper +++ /dev/null @@ -1 +0,0 @@ -io.greptime.CachedPojoMapper diff --git a/ingester-protocol/src/main/resources/META-INF/services/io.greptime.PojoObjectMapper b/ingester-protocol/src/main/resources/META-INF/services/io.greptime.PojoObjectMapper new file mode 100644 index 0000000..ca627b7 --- /dev/null +++ b/ingester-protocol/src/main/resources/META-INF/services/io.greptime.PojoObjectMapper @@ -0,0 +1 @@ +io.greptime.CachedPojoObjectMapper diff --git a/ingester-protocol/src/test/java/io/greptime/PojoMapperTest.java b/ingester-protocol/src/test/java/io/greptime/PojoObjectMapperTest.java similarity index 94% rename from ingester-protocol/src/test/java/io/greptime/PojoMapperTest.java rename to ingester-protocol/src/test/java/io/greptime/PojoObjectMapperTest.java index 60578bf..191fbd4 100644 --- a/ingester-protocol/src/test/java/io/greptime/PojoMapperTest.java +++ b/ingester-protocol/src/test/java/io/greptime/PojoObjectMapperTest.java @@ -28,7 +28,7 @@ /** * @author jiachun.fjc */ -public class PojoMapperTest { +public class PojoObjectMapperTest { @Test public void testToTable() { @@ -37,7 +37,7 @@ public void testToTable() { Pojo1Test pojo1 = createNewPojo1Test(); pojos1.add(pojo1); } - Table tp1 = new CachedPojoMapper().mapToTable(pojos1); + Table tp1 = new CachedPojoObjectMapper().mapToTable(pojos1); Assert.assertEquals("pojo1", tp1.tableName()); Assert.assertEquals(50, tp1.pointCount()); @@ -47,7 +47,7 @@ public void testToTable() { Pojo2Test pojo2 = createNewPojo2Test(); pojos2.add(pojo2); } - Table tp2 = new CachedPojoMapper().mapToTable(pojos2); + Table tp2 = new CachedPojoObjectMapper().mapToTable(pojos2); Assert.assertEquals("pojo2", tp2.tableName()); Assert.assertEquals(30, tp2.pointCount()); }