Skip to content

Commit

Permalink
enhance: Allow explict dynamic JSON column as insert data
Browse files Browse the repository at this point in the history
Related to #806

Previously all columns not appeared in schema definition are treated as
dynamic columns. This PR allows specifying one JSON column to be the
THE dynamic column data.

Signed-off-by: Congqi Xia <congqi.xia@zilliz.com>
  • Loading branch information
congqixia committed Aug 19, 2024
1 parent 4eff482 commit a88cf49
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions client/insert.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ func (c *GrpcClient) processInsertColumns(colSchema *entity.Schema, columns ...e
}
mNameColumn := make(map[string]entity.Column)
var dynamicColumns []entity.Column
hasExplictDynamicColumn := false
var expDynColumn entity.Column
for _, column := range columns {
_, dup := mNameColumn[column.Name()]
if dup {
Expand All @@ -100,6 +102,25 @@ func (c *GrpcClient) processInsertColumns(colSchema *entity.Schema, columns ...e
return nil, 0, errors.New("column size not match")
}
}

// check if explictly passing dynamic json column
if column.Type() == entity.FieldTypeJSON {
jsonColumn, ok := column.(*entity.ColumnJSONBytes)
if ok && jsonColumn.IsDynamic() {

Check failure on line 109 in client/insert.go

View workflow job for this annotation

GitHub Actions / lint

jsonColumn.IsDynamic undefined (type *entity.ColumnJSONBytes has no field or method IsDynamic) (typecheck)

Check failure on line 109 in client/insert.go

View workflow job for this annotation

GitHub Actions / lint

jsonColumn.IsDynamic undefined (type *entity.ColumnJSONBytes has no field or method IsDynamic) (typecheck)
// schema not match
if !isDynamic {
return nil, 0, fmt.Errorf("collection %s is not dynamic but insert data contains explict dynamic json field %s", colSchema.CollectionName, column.Name())
}
// multiple dynamic column
if hasExplictDynamicColumn {
return nil, 0, fmt.Errorf("multiple explict dynamic json column found")
}
hasExplictDynamicColumn = true
expDynColumn = column
continue
}
}

field, has := mNameField[column.Name()]
if !has {
if !isDynamic {
Expand Down Expand Up @@ -142,13 +163,19 @@ func (c *GrpcClient) processInsertColumns(colSchema *entity.Schema, columns ...e
fieldsData = append(fieldsData, fixedColumn.FieldData())
}
if len(dynamicColumns) > 0 {
if hasExplictDynamicColumn {
return nil, 0, fmt.Errorf("dynamic fields & explict dynamic column cannot be inserted at same time")
}
// use empty column name here
col, err := c.mergeDynamicColumns("", rowSize, dynamicColumns)
if err != nil {
return nil, 0, err
}
fieldsData = append(fieldsData, col)
}
if hasExplictDynamicColumn {
fieldsData = append(fieldsData, expDynColumn.FieldData())
}

return fieldsData, rowSize, nil
}
Expand Down

0 comments on commit a88cf49

Please sign in to comment.