Skip to content

Commit

Permalink
Revert default value feature (#563)
Browse files Browse the repository at this point in the history
Signed-off-by: Congqi Xia <[email protected]>
  • Loading branch information
congqixia authored Aug 23, 2023
1 parent f8f1c3f commit 9124e54
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 22 deletions.
9 changes: 0 additions & 9 deletions client/insert.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,15 +138,6 @@ func (c *GrpcClient) processInsertColumns(colSchema *entity.Schema, columns ...e
_, has := mNameColumn[field.Name]
if !has &&
!field.AutoID && !field.IsDynamic {
if field.DefaultValue != nil {
emptyColumn, err := entity.DefaultValueColumn(field.Name, field.DataType)
// no err will be throw
if err != nil {
return nil, 0, fmt.Errorf("empty column fail to create, field name:%s ", field.Name)
}
mNameColumn[field.Name] = emptyColumn
continue
}
return nil, 0, fmt.Errorf("field %s not passed", field.Name)
}
}
Expand Down
3 changes: 2 additions & 1 deletion client/insert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,13 +269,14 @@ func (s *InsertSuite) TestInsertSuccess() {
})

s.Run("missing_field_with_default_value", func() {
s.T().Skip("skip for default value test")
defer s.resetMock()
s.setupHasCollection(testCollectionName)
s.setupHasPartition(testCollectionName, "partition_1")

s.setupDescribeCollection(testCollectionName, entity.NewSchema().
WithField(entity.NewField().WithIsPrimaryKey(true).WithIsAutoID(true).WithName("ID").WithDataType(entity.FieldTypeInt64)).
WithField(entity.NewField().WithName("default_value").WithDataType(entity.FieldTypeInt64).WithDefaultValueLong(1)).
WithField(entity.NewField().WithName("default_value").WithDataType(entity.FieldTypeInt64)).
WithField(entity.NewField().WithName("vector").WithDataType(entity.FieldTypeFloatVector).WithTypeParams(entity.TypeParamDim, "128")),
)

Expand Down
6 changes: 2 additions & 4 deletions entity/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@ type Field struct {
IndexParams map[string]string
IsDynamic bool
IsPartitionKey bool
DefaultValue *schema.ValueField
}

// ProtoMessage generates corresponding FieldSchema
Expand All @@ -153,7 +152,6 @@ func (f *Field) ProtoMessage() *schema.FieldSchema {
IndexParams: MapKvPairs(f.IndexParams),
IsDynamic: f.IsDynamic,
IsPartitionKey: f.IsPartitionKey,
DefaultValue: f.DefaultValue,
}
}

Expand Down Expand Up @@ -200,6 +198,7 @@ func (f *Field) WithIsPartitionKey(isPartitionKey bool) *Field {
return f
}

/*
func (f *Field) WithDefaultValueBool(defaultValue bool) *Field {
f.DefaultValue = &schema.ValueField{
Data: &schema.ValueField_BoolData{
Expand Down Expand Up @@ -252,7 +251,7 @@ func (f *Field) WithDefaultValueString(defaultValue string) *Field {
},
}
return f
}
}*/

func (f *Field) WithTypeParams(key string, value string) *Field {
if f.TypeParams == nil {
Expand Down Expand Up @@ -290,7 +289,6 @@ func (f *Field) ReadProto(p *schema.FieldSchema) *Field {
f.IndexParams = KvPairsMap(p.GetIndexParams())
f.IsDynamic = p.GetIsDynamic()
f.IsPartitionKey = p.GetIsPartitionKey()
f.DefaultValue = p.GetDefaultValue()

return f
}
Expand Down
15 changes: 7 additions & 8 deletions entity/schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,13 @@ func TestFieldSchema(t *testing.T) {
NewField().WithName("int_field").WithDataType(FieldTypeInt64).WithIsAutoID(true).WithIsPrimaryKey(true).WithDescription("int_field desc"),
NewField().WithName("string_field").WithDataType(FieldTypeString).WithIsAutoID(false).WithIsPrimaryKey(true).WithIsDynamic(false).WithTypeParams("max_len", "32").WithDescription("string_field desc"),
NewField().WithName("partition_key").WithDataType(FieldTypeInt32).WithIsPartitionKey(true),
NewField().WithName("default_value_bool").WithDataType(FieldTypeBool).WithDefaultValueBool(true),
NewField().WithName("default_value_int").WithDataType(FieldTypeInt32).WithDefaultValueInt(1),
NewField().WithName("default_value_long").WithDataType(FieldTypeInt64).WithDefaultValueLong(1),
NewField().WithName("default_value_float").WithDataType(FieldTypeFloat).WithDefaultValueFloat(1),
NewField().WithName("default_value_double").WithDataType(FieldTypeDouble).WithDefaultValueDouble(1),
NewField().WithName("default_value_string").WithDataType(FieldTypeString).WithDefaultValueString("a"),
/*
NewField().WithName("default_value_bool").WithDataType(FieldTypeBool).WithDefaultValueBool(true),
NewField().WithName("default_value_int").WithDataType(FieldTypeInt32).WithDefaultValueInt(1),
NewField().WithName("default_value_long").WithDataType(FieldTypeInt64).WithDefaultValueLong(1),
NewField().WithName("default_value_float").WithDataType(FieldTypeFloat).WithDefaultValueFloat(1),
NewField().WithName("default_value_double").WithDataType(FieldTypeDouble).WithDefaultValueDouble(1),
NewField().WithName("default_value_string").WithDataType(FieldTypeString).WithDefaultValueString("a"),*/
}

for _, field := range fields {
Expand All @@ -41,7 +42,6 @@ func TestFieldSchema(t *testing.T) {
assert.Equal(t, field.AutoID, fieldSchema.GetAutoID())
assert.Equal(t, field.PrimaryKey, fieldSchema.GetIsPrimaryKey())
assert.Equal(t, field.IsPartitionKey, fieldSchema.GetIsPartitionKey())
assert.Equal(t, field.DefaultValue, fieldSchema.GetDefaultValue())
assert.Equal(t, field.IsDynamic, fieldSchema.GetIsDynamic())
assert.Equal(t, field.Description, fieldSchema.GetDescription())
assert.Equal(t, field.TypeParams, KvPairsMap(fieldSchema.GetTypeParams()))
Expand All @@ -56,7 +56,6 @@ func TestFieldSchema(t *testing.T) {
assert.Equal(t, field.Description, nf.Description)
assert.Equal(t, field.IsDynamic, nf.IsDynamic)
assert.Equal(t, field.IsPartitionKey, nf.IsPartitionKey)
assert.Equal(t, field.DefaultValue, nf.DefaultValue)
assert.EqualValues(t, field.TypeParams, nf.TypeParams)
}

Expand Down

0 comments on commit 9124e54

Please sign in to comment.