MCPcopy Create free account
hub / github.com/apecloud/myduckserver / Next

Method Next

pgserver/iter.go:140–231  ·  view source on GitHub ↗

Next retrieves the next row. It will return io.EOF if it's the last row.

(ctx *sql.Context)

Source from the content-addressed store, hash-verified

138
139// Next retrieves the next row. It will return io.EOF if it's the last row.
140func (iter *SqlRowIter) Next(ctx *sql.Context) (sql.Row, error) {
141 if !iter.rows.Next() {
142 if err := iter.rows.Err(); err != nil {
143 return nil, err
144 }
145 return nil, io.EOF
146 }
147
148 // Scan the values into the buffer
149 if err := iter.rows.Scan(iter.pointers[:len(iter.columns)]...); err != nil {
150 return nil, err
151 }
152
153 // logrus.Debugf("iter.decimals=%v, iter.lists=%v iter.buffer=%#v\n", iter.decimals, iter.lists, iter.buffer)
154
155 // Process decimal values
156 for _, idx := range iter.decimals {
157 switch v := iter.buffer[idx].(type) {
158 case nil:
159 continue
160 case duckdb.Decimal:
161 iter.buffer[idx] = pgtype.Numeric{Int: v.Value, Exp: -int32(v.Scale), Valid: true}
162 case string:
163 var n pgtype.Numeric
164 if err := n.Scan(v); err != nil {
165 return nil, err
166 }
167 iter.buffer[idx] = n
168 case []any:
169 array := make([]pgtype.Numeric, len(v))
170 for i, x := range v {
171 switch y := x.(type) {
172 case nil:
173 array[i] = pgtype.Numeric{}
174 case duckdb.Decimal:
175 array[i] = pgtype.Numeric{Int: y.Value, Exp: -int32(y.Scale), Valid: true}
176 case string:
177 if err := array[i].Scan(y); err != nil {
178 return nil, err
179 }
180 default:
181 return nil, fmt.Errorf("unexpected type %T for decimal value", x)
182 }
183 }
184 iter.buffer[idx] = array
185 default:
186 return nil, fmt.Errorf("unexpected type %T for decimal value", v)
187 }
188 }
189
190 // Process list values
191 for _, idx := range iter.lists {
192 var list []any
193 switch v := iter.buffer[idx].(type) {
194 case nil:
195 list = nil
196 case []pgtype.Numeric: // from the previous decimal processing step
197 iter.buffer[idx] = pgtype.FlatArray[pgtype.Numeric](v)

Callers 12

ReadRowsFunction · 0.45
StartMethod · 0.45
TestFuncReplacementFunction · 0.45
resultForOkIterFunction · 0.45
resultForEmptyIterFunction · 0.45
resultForMax1RowIterMethod · 0.45
resultForDefaultIterMethod · 0.45
TestSessParamFunction · 0.45
doSnapshotMethod · 0.45
NextMethod · 0.45
CaughtUpMethod · 0.45
UpdateSubscriptionsFunction · 0.45

Calls 1

ErrMethod · 0.45

Tested by 2

TestFuncReplacementFunction · 0.36
TestSessParamFunction · 0.36