Skip to content

Commit eea3844

Browse files
committed
pr feedback/notes/todos
1 parent 9f14225 commit eea3844

2 files changed

Lines changed: 21 additions & 4 deletions

File tree

server/functions/framework/interpreted_function.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,10 @@ func (iFunc InterpretedFunction) QuerySingleReturn(ctx *sql.Context, stack plpgs
138138
}
139139
fromType, ok := sch[0].Type.(*pgtypes.DoltgresType)
140140
if !ok {
141+
// TODO: We ensure we have a DoltgresType, but we should also convert the value to
142+
// ensure it's in the correct form for the DoltgresType. This logic lives in
143+
// pgexpressions.GMSCast, but need to be extracted to avoid a dependency cycle
144+
// so it can be used here and from server.plpgsql.
141145
fromType, err = pgtypes.FromGmsTypeToDoltgresType(sch[0].Type)
142146
if err != nil {
143147
return nil, err

server/plpgsql/interpreter_logic.go

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,11 @@ func call(ctx *sql.Context, iFunc InterpretedFunction, stack InterpreterStack) (
273273
if err != nil {
274274
return nil, err
275275
}
276-
stack.BufferReturnQueryResults(convertRowsToRecords(schema, rows))
276+
records, err := convertRowsToRecords(schema, rows)
277+
if err != nil {
278+
return nil, err
279+
}
280+
stack.BufferReturnQueryResults(records)
277281

278282
case OpCode_ScopeBegin:
279283
stack.PushScope()
@@ -292,7 +296,7 @@ func call(ctx *sql.Context, iFunc InterpretedFunction, stack InterpreterStack) (
292296

293297
// convertRowsToRecords iterates overs |rows| and converts each field in each row
294298
// into a RecordValue. |schema| is specified for type information.
295-
func convertRowsToRecords(schema sql.Schema, rows []sql.Row) [][]pgtypes.RecordValue {
299+
func convertRowsToRecords(schema sql.Schema, rows []sql.Row) ([][]pgtypes.RecordValue, error) {
296300
records := make([][]pgtypes.RecordValue, 0, len(rows))
297301
for _, row := range rows {
298302
record := make([]pgtypes.RecordValue, len(row))
@@ -302,7 +306,16 @@ func convertRowsToRecords(schema sql.Schema, rows []sql.Row) [][]pgtypes.RecordV
302306
if !ok {
303307
// non-Doltgres types are still used in analysis, but we only support disk serialization
304308
// for Doltgres types, so we must convert the GMS type to the nearest Doltgres type here.
305-
doltgresType = pgtypes.FromGmsType(t)
309+
// TODO: this conversion isn't fully accurate. expression.GMSCast has additional logic in
310+
// its Eval() method to handle types more exactly and also handles converting the
311+
// value to ensure it is well formed for the returned DoltgresType. We can't
312+
// currently use GMSCast directly here though, because of a dependency cycle, so
313+
// that conversion logic needs to be extracted into a package both places can import.
314+
var err error
315+
doltgresType, err = pgtypes.FromGmsTypeToDoltgresType(t)
316+
if err != nil {
317+
return nil, err
318+
}
306319
}
307320

308321
record[i] = pgtypes.RecordValue{
@@ -313,7 +326,7 @@ func convertRowsToRecords(schema sql.Schema, rows []sql.Row) [][]pgtypes.RecordV
313326
records = append(records, record)
314327
}
315328

316-
return records
329+
return records, nil
317330
}
318331

319332
// applyNoticeOptions adds the specified |options| to the |noticeResponse|.

0 commit comments

Comments
 (0)