@@ -19,7 +19,7 @@ var _ sql.ExecSourceRel = IntSequenceTable{}
1919type IntSequenceTable struct {
2020 db sql.Database
2121 name string
22- Len int64
22+ Len sql. Expression
2323}
2424
2525func (s IntSequenceTable ) NewInstance (ctx * sql.Context , db sql.Database , args []sql.Expression ) (sql.Node , error ) {
@@ -34,15 +34,11 @@ func (s IntSequenceTable) NewInstance(ctx *sql.Context, db sql.Database, args []
3434 if ! ok {
3535 return nil , fmt .Errorf ("sequence table expects 1st argument to be column name" )
3636 }
37- lenExp , ok := args [1 ].( * expression. Literal )
38- if ! ok {
39- return nil , fmt .Errorf ("sequence table expects arguments to be literal expressions " )
37+ lenExp := args [1 ]
38+ if ! sql . IsNumberType ( lenExp . Type ()) {
39+ return nil , fmt .Errorf ("sequence table expects length argument to be a number " )
4040 }
41- length , _ , err := types .Int64 .Convert (ctx , lenExp .Value ())
42- if ! ok {
43- return nil , fmt .Errorf ("%w; sequence table expects 2nd argument to be a sequence length integer" , err )
44- }
45- return IntSequenceTable {db : db , name : name , Len : length .(int64 )}, nil
41+ return IntSequenceTable {db : db , name : name , Len : lenExp }, nil
4642}
4743
4844func (s IntSequenceTable ) Resolved () bool {
@@ -85,8 +81,20 @@ func (s IntSequenceTable) Children() []sql.Node {
8581 return []sql.Node {}
8682}
8783
88- func (s IntSequenceTable ) RowIter (_ * sql.Context , _ sql.Row ) (sql.RowIter , error ) {
89- rowIter := & SequenceTableFnRowIter {i : 0 , n : s .Len }
84+ func (s IntSequenceTable ) RowIter (ctx * sql.Context , row sql.Row ) (sql.RowIter , error ) {
85+ iterLen , err := s .Len .Eval (ctx , row )
86+ if err != nil {
87+ return nil , err
88+ }
89+ iterLenVal , ok , err := types .Int64 .Convert (ctx , iterLen )
90+ if err != nil {
91+ return nil , err
92+ }
93+ if ! ok {
94+ return nil , fmt .Errorf ("sequence table expects integer argument" )
95+ }
96+
97+ rowIter := & SequenceTableFnRowIter {i : 0 , n : iterLenVal .(int64 )}
9098 return rowIter , nil
9199}
92100
0 commit comments