Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 2 additions & 2 deletions examples/src/main/java/io/milvus/v2/TimestampExample.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ private static void insertData() {
int rowCount = 10;
ZoneId zone = ZoneId.of("Asia/Shanghai");
DateTimeFormatter formatter = DateTimeFormatter.ISO_OFFSET_DATE_TIME;
System.out.printf("\n================= Insert with timezone: %s =================", zone);
System.out.printf("\n================= Insert with timezone: %s =================\n", zone);

// Insert entities by rows
List<JsonObject> rows = new ArrayList<>();
Expand Down Expand Up @@ -195,7 +195,7 @@ public static void main(String[] args) {
createCollection();
insertData();

List<String> timezones = Arrays.asList("America/Havana", "Africa/Bangui", "Australia/Sydney");
List<String> timezones = Arrays.asList("Asia/Shanghai", "America/Havana", "Africa/Bangui", "Australia/Sydney");

for (String timezone : timezones) {
System.out.printf("\n================= Query with timezone: %s =================", timezone);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@
import java.io.IOException;
import java.net.URL;
import java.nio.ByteBuffer;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.concurrent.TimeUnit;

Expand Down Expand Up @@ -139,6 +143,8 @@ public static class CloudImportConsts {
private static final String ALL_TYPES_COLLECTION_NAME = "java_sdk_bulkwriter_all_v2";
private static final Integer DIM = 512;
private static final Integer ARRAY_CAPACITY = 10;
private static final String TIME_ZONE = "Asia/Shanghai";

private static MilvusClientV2 milvusClient;

public static void main(String[] args) throws Exception {
Expand Down Expand Up @@ -256,6 +262,15 @@ private static Map<String, Object> genOriginStruct(int seed) {
return st;
}

private static String genTimestamptz(int i) {
ZoneId zone = ZoneId.of(TIME_ZONE);
DateTimeFormatter formatter = DateTimeFormatter.ISO_OFFSET_DATE_TIME;
LocalDateTime tt = LocalDateTime.of(2025, 1, 1, 0, 0, 0);
tt = tt.plusDays(i);
ZonedDateTime zt = tt.atZone(zone);
return zt.format(formatter);
}

private static List<Map<String, Object>> genOriginalData(int count) {
List<Map<String, Object>> data = new ArrayList<>();
for (int i = 0; i < count; ++i) {
Expand All @@ -272,6 +287,10 @@ private static List<Map<String, Object>> genOriginalData(int count) {
row.put("json", String.format("{\"dummy\": %s, \"ok\": \"name_%s\"}", i, i));
row.put("geometry", String.format("POINT (%d %d)", i, i));

// timestamptz field

row.put("timestamp", genTimestamptz(i));

// vector field
row.put("float_vector", CommonUtils.generateFloatVector(DIM));
row.put("binary_vector", CommonUtils.generateBinaryVector(DIM).array());
Expand Down Expand Up @@ -311,6 +330,7 @@ private static List<Map<String, Object>> genOriginalData(int count) {
row.put("varchar", null);
row.put("json", null);
row.put("geometry", null);
row.put("timestamp", null);

// vector field
row.put("float_vector", CommonUtils.generateFloatVector(DIM));
Expand Down Expand Up @@ -355,6 +375,7 @@ private static List<JsonObject> genImportData(List<Map<String, Object>> original
}
rowObject.addProperty("varchar", row.get("varchar") == null ? null : (String) row.get("varchar"));
rowObject.addProperty("geometry", row.get("geometry") == null ? null : (String) row.get("geometry"));
rowObject.addProperty("timestamp", row.get("timestamp") == null ? null : (String) row.get("timestamp"));

// Note: for JSON field, use gson.fromJson() to construct a real JsonObject
// don't use rowObject.addProperty("json", jsonContent) since the value is treated as a string, not a JsonObject
Expand Down Expand Up @@ -510,10 +531,10 @@ private static void callBulkInsert(List<List<String>> batchFiles) throws Interru
JsonObject getImportProgressObject = convertJsonObject(getImportProgressResult);
String state = getImportProgressObject.getAsJsonObject("data").get("state").getAsString();
String progress = getImportProgressObject.getAsJsonObject("data").get("progress").getAsString();
if ("Failed" .equals(state)) {
if ("Failed".equals(state)) {
String reason = getImportProgressObject.getAsJsonObject("data").get("reason").getAsString();
throw new RuntimeException(String.format("The job %s failed, reason: %s", jobId, reason));
} else if ("Completed" .equals(state)) {
} else if ("Completed".equals(state)) {
System.out.printf("The job %s completed%n", jobId);
break;
} else {
Expand Down Expand Up @@ -702,6 +723,8 @@ private static void verifyImportData(CreateCollectionReq.CollectionSchema collec
comparePrint(collectionSchema, originalEntity, fetchedEntity, "double");
comparePrint(collectionSchema, originalEntity, fetchedEntity, "varchar");
comparePrint(collectionSchema, originalEntity, fetchedEntity, "json");
comparePrint(collectionSchema, originalEntity, fetchedEntity, "geometry");
comparePrint(collectionSchema, originalEntity, fetchedEntity, "timestamp");

comparePrint(collectionSchema, originalEntity, fetchedEntity, "array_bool");
comparePrint(collectionSchema, originalEntity, fetchedEntity, "array_int8");
Expand Down Expand Up @@ -816,6 +839,7 @@ private static List<QueryResp.QueryResult> query(String expr, List<String> outpu
.filter(expr)
.outputFields(outputFields)
.consistencyLevel(ConsistencyLevel.STRONG)
.timezone(TIME_ZONE)
.build();
QueryResp response = milvusClient.query(test);
return response.getQueryResults();
Expand Down Expand Up @@ -948,6 +972,11 @@ private static CreateCollectionReq.CollectionSchema buildAllTypesSchema() {
.dataType(DataType.Geometry)
.isNullable(true)
.build());
schemaV2.addField(AddFieldReq.builder()
.fieldName("timestamp")
.dataType(DataType.Timestamptz)
.isNullable(true)
.build());

// vector fields
schemaV2.addField(AddFieldReq.builder()
Expand Down
Loading