diff --git a/executor.go b/executor.go index 97f42acf1..589b0ace5 100644 --- a/executor.go +++ b/executor.go @@ -138,8 +138,8 @@ func (e *Executor) executeCall(ctx context.Context, index string, c *pql.Call, s return e.executeCount(ctx, index, c, slices, opt) case "SetBit": return e.executeSetBit(ctx, index, c, opt) - case "SetFieldValue": - return nil, e.executeSetFieldValue(ctx, index, c, opt) + case "SetValue": + return nil, e.executeSetValue(ctx, index, c, opt) case "SetRowAttrs": return nil, e.executeSetRowAttrs(ctx, index, c, opt) case "SetColumnAttrs": @@ -1107,46 +1107,40 @@ func (e *Executor) executeSetBitView(ctx context.Context, index string, c *pql.C return ret, nil } -// executeSetFieldValue executes a SetFieldValue() call. -func (e *Executor) executeSetFieldValue(ctx context.Context, index string, c *pql.Call, opt *ExecOptions) error { - frameName, ok := c.Args["frame"].(string) - if !ok { - return errors.New("SetFieldValue() frame required") - } - - // Retrieve frame. - frame := e.Holder.Frame(index, frameName) - if frame == nil { - return ErrFrameNotFound - } - +// executeSetValue executes a SetValue() call. +func (e *Executor) executeSetValue(ctx context.Context, index string, c *pql.Call, opt *ExecOptions) error { // Parse labels. columnID, ok, err := c.UintArg(columnLabel) if err != nil { - return fmt.Errorf("reading SetFieldValue() column: %v", err) + return fmt.Errorf("reading SetValue() column: %v", err) } else if !ok { - return fmt.Errorf("SetFieldValue() column field '%v' required", columnLabel) + return fmt.Errorf("SetValue() column field '%v' required", columnLabel) } // Copy args and remove reserved fields. args := pql.CopyArgs(c.Args) - delete(args, "frame") // While frame could technically work as a ColumnAttr argument, we are treating it as a reserved word primarily to avoid confusion. // Also, if we ever need to make ColumnAttrs frame-specific, then having this reserved word prevents backward incompatibility. delete(args, columnLabel) // Set values. for name, value := range args { + // Retrieve frame. + frame := e.Holder.Frame(index, name) + if frame == nil { + return ErrFrameNotFound + } + switch value := value.(type) { case int64: - if _, err := frame.SetFieldValue(columnID, name, value); err != nil { + if _, err := frame.SetValue(columnID, value); err != nil { return err } default: return ErrInvalidFieldValueType } + frame.Stats.Count("SetValue", 1, 1.0) } - frame.Stats.Count("SetFieldValue", 1, 1.0) // Do not forward call if this is already being forwarded. if opt.Remote { diff --git a/executor_test.go b/executor_test.go index fbce4d52d..a8cce5194 100644 --- a/executor_test.go +++ b/executor_test.go @@ -263,8 +263,8 @@ func TestExecutor_Execute_SetBit(t *testing.T) { } } -// Ensure a SetFieldValue() query can be executed. -func TestExecutor_Execute_SetFieldValue(t *testing.T) { +// Ensure a SetValue() query can be executed. +func TestExecutor_Execute_SetValue(t *testing.T) { t.Run("OK", func(t *testing.T) { hldr := test.MustOpenHolder() defer hldr.Close() @@ -283,9 +283,9 @@ func TestExecutor_Execute_SetFieldValue(t *testing.T) { // Set field values. e := test.NewExecutor(hldr.Holder, test.NewCluster(1)) - if _, err := e.Execute(context.Background(), "i", test.MustParse(`SetFieldValue(col=10, frame=f, f=25)`), nil, nil); err != nil { + if _, err := e.Execute(context.Background(), "i", test.MustParse(`SetValue(col=10, f=25)`), nil, nil); err != nil { t.Fatal(err) - } else if _, err := e.Execute(context.Background(), "i", test.MustParse(`SetFieldValue(col=100, frame=f, f=10)`), nil, nil); err != nil { + } else if _, err := e.Execute(context.Background(), "i", test.MustParse(`SetValue(col=100, f=10)`), nil, nil); err != nil { t.Fatal(err) } @@ -319,30 +319,23 @@ func TestExecutor_Execute_SetFieldValue(t *testing.T) { t.Fatal(err) } - t.Run("ErrFrameRequired", func(t *testing.T) { - e := test.NewExecutor(hldr.Holder, test.NewCluster(1)) - if _, err := e.Execute(context.Background(), "i", test.MustParse(`SetFieldValue(col=10, f=100)`), nil, nil); err == nil || err.Error() != `SetFieldValue() frame required` { - t.Fatalf("unexpected error: %s", err) - } - }) - t.Run("ErrColumnFieldRequired", func(t *testing.T) { e := test.NewExecutor(hldr.Holder, test.NewCluster(1)) - if _, err := e.Execute(context.Background(), "i", test.MustParse(`SetFieldValue(invalid_column_name=10, frame=f, f=100)`), nil, nil); err == nil || err.Error() != `SetFieldValue() column field 'col' required` { + if _, err := e.Execute(context.Background(), "i", test.MustParse(`SetValue(invalid_column_name=10, f=100)`), nil, nil); err == nil || err.Error() != `SetValue() column field 'col' required` { t.Fatalf("unexpected error: %s", err) } }) t.Run("ErrColumnFieldValue", func(t *testing.T) { e := test.NewExecutor(hldr.Holder, test.NewCluster(1)) - if _, err := e.Execute(context.Background(), "i", test.MustParse(`SetFieldValue(invalid_column_name="bad_column", frame=f, f=100)`), nil, nil); err == nil || err.Error() != `SetFieldValue() column field 'col' required` { + if _, err := e.Execute(context.Background(), "i", test.MustParse(`SetValue(invalid_column_name="bad_column", f=100)`), nil, nil); err == nil || err.Error() != `SetValue() column field 'col' required` { t.Fatalf("unexpected error: %s", err) } }) t.Run("ErrInvalidFieldValueType", func(t *testing.T) { e := test.NewExecutor(hldr.Holder, test.NewCluster(1)) - if _, err := e.Execute(context.Background(), "i", test.MustParse(`SetFieldValue(col=10, frame=f, f="hello")`), nil, nil); err == nil || err.Error() != `invalid field value type` { + if _, err := e.Execute(context.Background(), "i", test.MustParse(`SetValue(col=10, f="hello")`), nil, nil); err == nil || err.Error() != `invalid field value type` { t.Fatalf("unexpected error: %s", err) } }) @@ -598,14 +591,14 @@ func TestExecutor_Execute_MinMax(t *testing.T) { SetBit(frame=x, row=1, col=1) SetBit(frame=x, row=2, col=`+strconv.Itoa(SliceWidth+2)+`) - SetFieldValue(frame=f, f=20, col=0) - SetFieldValue(frame=f, f=-5, col=1) - SetFieldValue(frame=f, f=-5, col=2) - SetFieldValue(frame=f, f=10, col=3) - SetFieldValue(frame=f, f=30, col=`+strconv.Itoa(SliceWidth)+`) - SetFieldValue(frame=f, f=40, col=`+strconv.Itoa(SliceWidth+2)+`) - SetFieldValue(frame=f, f=50, col=`+strconv.Itoa((5*SliceWidth)+100)+`) - SetFieldValue(frame=f, f=60, col=`+strconv.Itoa(SliceWidth+1)+`) + SetValue(f=20, col=0) + SetValue(f=-5, col=1) + SetValue(f=-5, col=2) + SetValue(f=10, col=3) + SetValue(f=30, col=`+strconv.Itoa(SliceWidth)+`) + SetValue(f=40, col=`+strconv.Itoa(SliceWidth+2)+`) + SetValue(f=50, col=`+strconv.Itoa((5*SliceWidth)+100)+`) + SetValue(f=60, col=`+strconv.Itoa(SliceWidth+1)+`) `), nil, nil); err != nil { t.Fatal(err) } @@ -706,13 +699,13 @@ func TestExecutor_Execute_Sum(t *testing.T) { SetBit(frame=x, row=0, col=0) SetBit(frame=x, row=0, col=`+strconv.Itoa(SliceWidth+1)+`) - SetFieldValue(frame=foo, foo=20, col=0) - SetFieldValue(frame=bar, bar=2000, col=0) - SetFieldValue(frame=foo, foo=30, col=`+strconv.Itoa(SliceWidth)+`) - SetFieldValue(frame=foo, foo=40, col=`+strconv.Itoa(SliceWidth+2)+`) - SetFieldValue(frame=foo, foo=50, col=`+strconv.Itoa((5*SliceWidth)+100)+`) - SetFieldValue(frame=foo, foo=60, col=`+strconv.Itoa(SliceWidth+1)+`) - SetFieldValue(frame=other, other=1000, col=0) + SetValue(foo=20, col=0) + SetValue(bar=2000, col=0) + SetValue(foo=30, col=`+strconv.Itoa(SliceWidth)+`) + SetValue(foo=40, col=`+strconv.Itoa(SliceWidth+2)+`) + SetValue(foo=50, col=`+strconv.Itoa((5*SliceWidth)+100)+`) + SetValue(foo=60, col=`+strconv.Itoa(SliceWidth+1)+`) + SetValue(other=1000, col=0) `), nil, nil); err != nil { t.Fatal(err) } @@ -827,15 +820,15 @@ func TestExecutor_Execute_FieldRange(t *testing.T) { SetBit(frame=f, row=0, col=0) SetBit(frame=f, row=0, col=`+strconv.Itoa(SliceWidth+1)+`) - SetFieldValue(frame=foo, foo=20, col=50) - SetFieldValue(frame=bar, bar=2000, col=50) - SetFieldValue(frame=foo, foo=30, col=`+strconv.Itoa(SliceWidth)+`) - SetFieldValue(frame=foo, foo=10, col=`+strconv.Itoa(SliceWidth+2)+`) - SetFieldValue(frame=foo, foo=20, col=`+strconv.Itoa((5*SliceWidth)+100)+`) - SetFieldValue(frame=foo, foo=60, col=`+strconv.Itoa(SliceWidth+1)+`) - SetFieldValue(frame=other, other=1000, col=0) - SetFieldValue(frame=edge, edge=100, col=0) - SetFieldValue(frame=edge, edge=-100, col=1) + SetValue(foo=20, col=50) + SetValue(bar=2000, col=50) + SetValue(foo=30, col=`+strconv.Itoa(SliceWidth)+`) + SetValue(foo=10, col=`+strconv.Itoa(SliceWidth+2)+`) + SetValue(foo=20, col=`+strconv.Itoa((5*SliceWidth)+100)+`) + SetValue(foo=60, col=`+strconv.Itoa(SliceWidth+1)+`) + SetValue(other=1000, col=0) + SetValue(edge=100, col=0) + SetValue(edge=-100, col=1) `), nil, nil); err != nil { t.Fatal(err) } diff --git a/fragment.go b/fragment.go index 8044f579b..f2d7ad986 100644 --- a/fragment.go +++ b/fragment.go @@ -510,8 +510,8 @@ func (f *Fragment) FieldValue(columnID uint64, bitDepth uint) (value uint64, exi return value, true, nil } -// SetFieldValue uses a column of bits to set a multi-bit value. -func (f *Fragment) SetFieldValue(columnID uint64, bitDepth uint, value uint64) (changed bool, err error) { +// SetValue uses a column of bits to set a multi-bit value. +func (f *Fragment) SetValue(columnID uint64, bitDepth uint, value uint64) (changed bool, err error) { f.mu.Lock() defer f.mu.Unlock() @@ -541,8 +541,8 @@ func (f *Fragment) SetFieldValue(columnID uint64, bitDepth uint, value uint64) ( return changed, nil } -// importSetFieldValue is a more efficient SetFieldValue just for imports. -func (f *Fragment) importSetFieldValue(columnID uint64, bitDepth uint, value uint64) (changed bool, err error) { +// importSetValue is a more efficient SetValue just for imports. +func (f *Fragment) importSetValue(columnID uint64, bitDepth uint, value uint64) (changed bool, err error) { for i := uint(0); i < bitDepth; i++ { if value&(1<