Skip to content

Auto-defuse SUP output#7016

Open
mattnibs wants to merge 1 commit into
mainfrom
auto-defuse
Open

Auto-defuse SUP output#7016
mattnibs wants to merge 1 commit into
mainfrom
auto-defuse

Conversation

@mattnibs
Copy link
Copy Markdown
Collaborator

@mattnibs mattnibs commented Jun 2, 2026

This pr adds functionality to auto-defuse fusion values in SUP output. If the -fusion flag is enabled, fusion values will be displayed.

@mattnibs mattnibs requested a review from a team June 2, 2026 21:36
This pr adds functionality to auto-defuse fusion values in sup output.
If the -fusion flag is enabled fusion values will be displayed.
}
p.sr.Reset(super.DecodeString(in.Bytes()))
val, err := p.zr.Read()
val, err := sup.ParseValue(p.sctx, byteconv.UnsafeString(in.Bytes()))
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change creates a lot of extra work for the garbage collector on each parse_sup() call. I wouldn't cry about that if there were no other way to avoid the import cycle, but how about doing it in anyio instead of supio?

--- a/sio/anyio/writer.go
+++ b/sio/anyio/writer.go
@@ -4,7 +4,11 @@ import (
        "fmt"
        "io"

+       "github.com/brimdata/super"
        "github.com/brimdata/super/csup"
+       "github.com/brimdata/super/runtime/sam/expr"
+       "github.com/brimdata/super/runtime/sam/expr/function"
+       "github.com/brimdata/super/sbuf"
        "github.com/brimdata/super/sio/arrowio"
        "github.com/brimdata/super/sio/bsupio"
        "github.com/brimdata/super/sio/csvio"
@@ -20,12 +24,13 @@ import (
 )

 type WriterOpts struct {
-       Format string
-       BSUP   *bsupio.WriterOpts // Nil means use defaults via bsupio.NewWriter.
-       CSV    csvio.WriterOpts
-       DB     dbio.WriterOpts
-       JSON   jsonio.WriterOpts
-       SUP    supio.WriterOpts
+       Format    string
+       SUPFusion bool
+       BSUP      *bsupio.WriterOpts // Nil means use defaults via bsupio.NewWriter.
+       CSV       csvio.WriterOpts
+       DB        dbio.WriterOpts
+       JSON      jsonio.WriterOpts
+       SUP       supio.WriterOpts
 }

 func NewWriter(w io.WriteCloser, opts WriterOpts) (vio.PushCloser, error) {
@@ -52,7 +57,11 @@ func NewWriter(w io.WriteCloser, opts WriterOpts) (vio.PushCloser, error) {
        case "parquet":
                return parquetio.NewWriter(w), nil
        case "sup", "":
-               return supio.NewWriter(w, opts.SUP), nil
+               w := supio.NewWriter(w, opts.SUP)
+               if !opts.SUPFusion {
+                       return &supDefuser{w, function.NewDefuse(super.NewContext())}, nil
+               }
+               return w, nil
        case "table":
                return tableio.NewWriter(w), nil
        case "tsv":
@@ -65,6 +74,21 @@ func NewWriter(w io.WriteCloser, opts WriterOpts) (vio.PushCloser, error) {
        }
 }

+type supDefuser struct {
+       *supio.Writer
+       defuse expr.Function
+}
+
+func (d *supDefuser) Push(vec vector.Any) error {
+       for _, val := range sbuf.Materialize(vec).Values() {
+               val = d.defuse.Call([]super.Value{val})
+               if err := d.Writer.Write(val); err != nil {
+                       return err
+               }
+       }
+       return nil
+}
+

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ugh I really don't have like having surprising behavior like this.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd honestly rather just duplicate the code in supio.Reader in sam/expr/function.ParseSUP.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants