obs-browser icon indicating copy to clipboard operation
obs-browser copied to clipboard

Support request for multiple return types aka when len(results.List) > 1

Open sachaarbonel opened this issue 7 years ago • 2 comments

https://github.com/microo8/plgo/blob/a744149107575082de08228b103e8bc95129ca43/plgo/functions.go#L129

Hi @microo8 sorry to bothering you again could you add support for multiple return types. I thought I could make a PR but my go skills still need some work lol. BUT I've made my homework here is the AST on my package :

33  .  .  .  Type: *ast.FuncType {
    34  .  .  .  .  Func: returned-values.go:5:1
    35  .  .  .  .  Params: *ast.FieldList {
    36  .  .  .  .  .  Opening: returned-values.go:5:7
    37  .  .  .  .  .  Closing: returned-values.go:5:8
    38  .  .  .  .  }
    39  .  .  .  .  Results: *ast.FieldList {
    40  .  .  .  .  .  Opening: returned-values.go:5:10
    41  .  .  .  .  .  List: []*ast.Field (len = 3) {
    42  .  .  .  .  .  .  0: *ast.Field {
    43  .  .  .  .  .  .  .  Type: *ast.ArrayType {
    44  .  .  .  .  .  .  .  .  Lbrack: returned-values.go:5:11
    45  .  .  .  .  .  .  .  .  Elt: *ast.Ident {
    46  .  .  .  .  .  .  .  .  .  NamePos: returned-values.go:5:13
    47  .  .  .  .  .  .  .  .  .  Name: "float64"
    48  .  .  .  .  .  .  .  .  }
    49  .  .  .  .  .  .  .  }
    50  .  .  .  .  .  .  }
    51  .  .  .  .  .  .  1: *ast.Field {
    52  .  .  .  .  .  .  .  Type: *ast.ArrayType {
    53  .  .  .  .  .  .  .  .  Lbrack: returned-values.go:5:22
    54  .  .  .  .  .  .  .  .  Elt: *ast.Ident {
    55  .  .  .  .  .  .  .  .  .  NamePos: returned-values.go:5:24
    56  .  .  .  .  .  .  .  .  .  Name: "float64"
    57  .  .  .  .  .  .  .  .  }
    58  .  .  .  .  .  .  .  }
    59  .  .  .  .  .  .  }
    60  .  .  .  .  .  .  2: *ast.Field {
    61  .  .  .  .  .  .  .  Type: *ast.ArrayType {
    62  .  .  .  .  .  .  .  .  Lbrack: returned-values.go:5:33
    63  .  .  .  .  .  .  .  .  Elt: *ast.Ident {
    64  .  .  .  .  .  .  .  .  .  NamePos: returned-values.go:5:35
    65  .  .  .  .  .  .  .  .  .  Name: "float64"
    66  .  .  .  .  .  .  .  .  }
    67  .  .  .  .  .  .  .  }
    68  .  .  .  .  .  .  }
    69  .  .  .  .  .  }

sachaarbonel avatar Aug 23 '18 16:08 sachaarbonel

The results.List must be just one. You are writing functions that are called from sql.

What do you expect to get when calling select E()?

microo8 avatar Aug 24 '18 05:08 microo8

Well a possible solution could be :

SELECT (E(inputed_floats)).outCA, (E(inputed_floats)).outB, (E(inputed_floats)).outC FROM some_table;

With my E func being slightly changed for the example :

func E(inA float64, inB float64, inC float64,) (outA []float64, outB []float64, outC []float64) {
	return []float64{inA}, []float64{inB}, []float64{inC}
}

I expect the result to be like that :

    outA     |      outB       |    outC  
-----------+-------------+-----------
{inAvalue} |   {inBvalue} |  {inCvalue}
(1 row)

I guess we'll have to parse the returned values variable names for the composite types. Let me know what do you think of my proposal.

sachaarbonel avatar Aug 24 '18 09:08 sachaarbonel