Skip to content

Commit 442bd23

Browse files
authored
fix: correct default value backfill during AddField (#45644)
issue: #44585 pr: #45634 Signed-off-by: zhenshan.cao <[email protected]>
1 parent bafa5bd commit 442bd23

27 files changed

+454
-360
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ require (
1616
github.com/gin-gonic/gin v1.9.1
1717
github.com/go-playground/validator/v10 v10.14.0
1818
github.com/gofrs/flock v0.8.1
19-
github.com/golang/protobuf v1.5.4
19+
github.com/golang/protobuf v1.5.4 // indirect
2020
github.com/google/btree v1.1.2
2121
github.com/grpc-ecosystem/go-grpc-middleware v1.3.0
2222
github.com/klauspost/compress v1.17.9

internal/parser/planparserv2/parser_visitor.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
"github.com/milvus-io/milvus-proto/go-api/v2/schemapb"
1313
parser "github.com/milvus-io/milvus/internal/parser/planparserv2/generated"
1414
"github.com/milvus-io/milvus/pkg/v2/proto/planpb"
15-
"github.com/milvus-io/milvus/pkg/v2/util/funcutil"
15+
"github.com/milvus-io/milvus/pkg/v2/util/timestamptz"
1616
"github.com/milvus-io/milvus/pkg/v2/util/typeutil"
1717
)
1818

@@ -1953,7 +1953,7 @@ func (v *ParserVisitor) VisitTimestamptzCompareForward(ctx *parser.TimestamptzCo
19531953

19541954
compareOp := cmpOpMap[ctx.GetOp2().GetTokenType()]
19551955

1956-
timestamptzInt64, err := funcutil.ValidateAndReturnUnixMicroTz(unquotedCompareStr, v.args.Timezone)
1956+
timestamptzInt64, err := timestamptz.ValidateAndReturnUnixMicroTz(unquotedCompareStr, v.args.Timezone)
19571957
if err != nil {
19581958
return err
19591959
}
@@ -2017,7 +2017,7 @@ func (v *ParserVisitor) VisitTimestamptzCompareReverse(ctx *parser.TimestamptzCo
20172017
return fmt.Errorf("unsupported comparison operator for reverse Timestamptz: %s", ctx.GetOp2().GetText())
20182018
}
20192019

2020-
timestamptzInt64, err := funcutil.ValidateAndReturnUnixMicroTz(unquotedCompareStr, v.args.Timezone)
2020+
timestamptzInt64, err := timestamptz.ValidateAndReturnUnixMicroTz(unquotedCompareStr, v.args.Timezone)
20212021
if err != nil {
20222022
return err
20232023
}

internal/proxy/http_req_impl.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import (
3737
"github.com/milvus-io/milvus/pkg/v2/util/merr"
3838
"github.com/milvus-io/milvus/pkg/v2/util/metricsinfo"
3939
"github.com/milvus-io/milvus/pkg/v2/util/paramtable"
40+
"github.com/milvus-io/milvus/pkg/v2/util/timestamptz"
4041
"github.com/milvus-io/milvus/pkg/v2/util/typeutil"
4142
)
4243

@@ -350,6 +351,13 @@ func describeCollection(node *Proxy) gin.HandlerFunc {
350351
return
351352
}
352353

354+
// Convert TIMESTAMPTZ default values back to string format for the user.
355+
if err := timestamptz.RewriteTimestampTzDefaultValueToString(describeCollectionResp.Schema); err != nil {
356+
c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{
357+
mhttp.HTTPReturnMessage: err.Error(),
358+
})
359+
}
360+
353361
describePartitionResp, err := rootCoord.ShowPartitions(c, &milvuspb.ShowPartitionsRequest{
354362
Base: &commonpb.MsgBase{
355363
MsgType: commonpb.MsgType_ShowPartitions,

internal/proxy/impl.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -843,7 +843,6 @@ func (node *Proxy) BatchDescribeCollection(ctx context.Context, request *milvusp
843843
CollectionName: collectionName,
844844
}
845845
}
846-
847846
responses = append(responses, describeCollectionResponse)
848847
}
849848

internal/proxy/service_provider.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"github.com/milvus-io/milvus/pkg/v2/util/merr"
1919
"github.com/milvus-io/milvus/pkg/v2/util/paramtable"
2020
"github.com/milvus-io/milvus/pkg/v2/util/timerecord"
21+
"github.com/milvus-io/milvus/pkg/v2/util/timestamptz"
2122
"github.com/milvus-io/milvus/pkg/v2/util/typeutil"
2223
)
2324

@@ -207,6 +208,12 @@ func (node *CachedProxyServiceProvider) DescribeCollection(ctx context.Context,
207208
return nil, err
208209
}
209210

211+
err = timestamptz.RewriteTimestampTzDefaultValueToString(resp.Schema)
212+
if err != nil {
213+
log.Info("failed to rewrite timestamp value", zap.Error(err))
214+
return nil, err
215+
}
216+
210217
resp.CollectionID = c.collID
211218
resp.UpdateTimestamp = c.updateTimestamp
212219
resp.UpdateTimestampStr = fmt.Sprintf("%d", c.updateTimestamp)

internal/proxy/task.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ import (
4242
"github.com/milvus-io/milvus/pkg/v2/util/funcutil"
4343
"github.com/milvus-io/milvus/pkg/v2/util/merr"
4444
"github.com/milvus-io/milvus/pkg/v2/util/paramtable"
45+
"github.com/milvus-io/milvus/pkg/v2/util/timestamptz"
4546
"github.com/milvus-io/milvus/pkg/v2/util/typeutil"
4647
)
4748

@@ -418,7 +419,7 @@ func (t *createCollectionTask) PreExecute(ctx context.Context) error {
418419

419420
// Validate timezone
420421
tz, exist := funcutil.TryGetAttrByKeyFromRepeatedKV(common.TimezoneKey, t.GetProperties())
421-
if exist && !funcutil.IsTimezoneValid(tz) {
422+
if exist && !timestamptz.IsTimezoneValid(tz) {
422423
return merr.WrapErrParameterInvalidMsg("unknown or invalid IANA Time Zone ID: %s", tz)
423424
}
424425

@@ -1209,7 +1210,7 @@ func (t *alterCollectionTask) PreExecute(ctx context.Context) error {
12091210
}
12101211
// Check the validation of timezone
12111212
userDefinedTimezone, exist := funcutil.TryGetAttrByKeyFromRepeatedKV(common.TimezoneKey, t.Properties)
1212-
if exist && !funcutil.IsTimezoneValid(userDefinedTimezone) {
1213+
if exist && !timestamptz.IsTimezoneValid(userDefinedTimezone) {
12131214
return merr.WrapErrParameterInvalidMsg("unknown or invalid IANA Time Zone ID: %s", userDefinedTimezone)
12141215
}
12151216
} else if len(t.GetDeleteKeys()) > 0 {

internal/proxy/task_database.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
"github.com/milvus-io/milvus/pkg/v2/util/funcutil"
1717
"github.com/milvus-io/milvus/pkg/v2/util/merr"
1818
"github.com/milvus-io/milvus/pkg/v2/util/paramtable"
19+
"github.com/milvus-io/milvus/pkg/v2/util/timestamptz"
1920
)
2021

2122
type createDatabaseTask struct {
@@ -74,7 +75,7 @@ func (cdt *createDatabaseTask) PreExecute(ctx context.Context) error {
7475
return err
7576
}
7677
tz, exist := funcutil.TryGetAttrByKeyFromRepeatedKV(common.TimezoneKey, cdt.GetProperties())
77-
if exist && !funcutil.IsTimezoneValid(tz) {
78+
if exist && !timestamptz.IsTimezoneValid(tz) {
7879
return merr.WrapErrParameterInvalidMsg("unknown or invalid IANA Time Zone ID: %s", tz)
7980
}
8081
return nil
@@ -277,7 +278,7 @@ func (t *alterDatabaseTask) PreExecute(ctx context.Context) error {
277278
if len(t.GetProperties()) > 0 {
278279
// Check the validation of timezone
279280
userDefinedTimezone, exist := funcutil.TryGetAttrByKeyFromRepeatedKV(common.TimezoneKey, t.Properties)
280-
if exist && !funcutil.IsTimezoneValid(userDefinedTimezone) {
281+
if exist && !timestamptz.IsTimezoneValid(userDefinedTimezone) {
281282
return merr.WrapErrParameterInvalidMsg("unknown or invalid IANA Time Zone ID: %s", userDefinedTimezone)
282283
}
283284
}

internal/proxy/task_query.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import (
3434
"github.com/milvus-io/milvus/pkg/v2/util/merr"
3535
"github.com/milvus-io/milvus/pkg/v2/util/paramtable"
3636
"github.com/milvus-io/milvus/pkg/v2/util/timerecord"
37+
"github.com/milvus-io/milvus/pkg/v2/util/timestamptz"
3738
"github.com/milvus-io/milvus/pkg/v2/util/tsoutil"
3839
"github.com/milvus-io/milvus/pkg/v2/util/typeutil"
3940
)
@@ -242,7 +243,7 @@ func parseQueryParams(queryParamsPair []*commonpb.KeyValuePair) (*queryParams, e
242243
}
243244

244245
timezone, _ = funcutil.TryGetAttrByKeyFromRepeatedKV(common.TimezoneKey, queryParamsPair)
245-
if (timezone != "") && !funcutil.IsTimezoneValid(timezone) {
246+
if (timezone != "") && !timestamptz.IsTimezoneValid(timezone) {
246247
return nil, merr.WrapErrParameterInvalidMsg("unknown or invalid IANA Time Zone ID: %s", timezone)
247248
}
248249

internal/proxy/task_search.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import (
3737
"github.com/milvus-io/milvus/pkg/v2/util/metric"
3838
"github.com/milvus-io/milvus/pkg/v2/util/paramtable"
3939
"github.com/milvus-io/milvus/pkg/v2/util/timerecord"
40+
"github.com/milvus-io/milvus/pkg/v2/util/timestamptz"
4041
"github.com/milvus-io/milvus/pkg/v2/util/tsoutil"
4142
"github.com/milvus-io/milvus/pkg/v2/util/typeutil"
4243
)
@@ -286,7 +287,7 @@ func (t *searchTask) PreExecute(ctx context.Context) error {
286287

287288
timezone, exist := funcutil.TryGetAttrByKeyFromRepeatedKV(common.TimezoneKey, t.request.SearchParams)
288289
if exist {
289-
if !funcutil.IsTimezoneValid(timezone) {
290+
if !timestamptz.IsTimezoneValid(timezone) {
290291
log.Info("get invalid timezone from request", zap.String("timezone", timezone))
291292
return merr.WrapErrParameterInvalidMsg("unknown or invalid IANA Time Zone ID: %s", timezone)
292293
}

internal/proxy/util.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ import (
6060
"github.com/milvus-io/milvus/pkg/v2/util/merr"
6161
"github.com/milvus-io/milvus/pkg/v2/util/metric"
6262
"github.com/milvus-io/milvus/pkg/v2/util/paramtable"
63+
"github.com/milvus-io/milvus/pkg/v2/util/timestamptz"
6364
"github.com/milvus-io/milvus/pkg/v2/util/tsoutil"
6465
"github.com/milvus-io/milvus/pkg/v2/util/typeutil"
6566
)
@@ -2915,7 +2916,7 @@ func timestamptzUTC2IsoStr(results []*schemapb.FieldData, colTimezone string) er
29152916
localTime := t.In(location)
29162917

29172918
// 3. Format using the optimized logic (max 6 digits, no trailing zeros)
2918-
isoStrings[i] = funcutil.FormatTimeMicroWithoutTrailingZeros(localTime)
2919+
isoStrings[i] = timestamptz.FormatTimeMicroWithoutTrailingZeros(localTime)
29192920
}
29202921

29212922
// Replace the TimestamptzData with the new StringData in place.

0 commit comments

Comments
 (0)