googleapis/mcp-toolbox · error

unable to parse row: %w

Error message

unable to parse row: %w

What it means

Trino RunSQL wraps results.Scan(values...) failures for each row. Scan fails when the driver cannot convert a Trino column value into the destination Go value (typically *any / sql.RawBytes style slots), e.g. unexpected types, oversized values, or NULL handling mismatches.

Source

Thrown at internal/sources/trino/trino.go:139

	defer results.Close()

	cols, err := results.Columns()
	if err != nil {
		return nil, fmt.Errorf("unable to retrieve column names: %w", err)
	}

	// create an array of values for each column, which can be re-used to scan each row
	rawValues := make([]any, len(cols))
	values := make([]any, len(cols))
	for i := range rawValues {
		values[i] = &rawValues[i]
	}

	out := []any{}
	for results.Next() {
		err := results.Scan(values...)
		if err != nil {
			return nil, fmt.Errorf("unable to parse row: %w", err)
		}
		vMap := make(map[string]any)
		for i, name := range cols {
			val := rawValues[i]
			if val == nil {
				vMap[name] = nil
				continue
			}

			// Convert byte arrays to strings for text fields
			if b, ok := val.([]byte); ok {
				vMap[name] = string(b)
			} else {
				vMap[name] = val
			}
		}
		out = append(out, vMap)
	}

View on GitHub (pinned to 8cc6e09de2)

Solutions

  1. Cast complex columns in SQL to strings (e.g. CAST(col AS VARCHAR)) so they scan as text
  2. Inspect the wrapped error for the offending column and type
  3. Update trino-go-client and coordinator versions for type-encoding compatibility
  4. Select only scalar columns needed instead of SELECT *

Example fix

// before
SELECT * FROM events  -- includes map<string,string> payload
// after
SELECT id, ts, CAST(payload AS VARCHAR) AS payload FROM events
Defensive patterns

Strategy: fallback

Validate before calling

// avoid complex types up front
safeStmt := strings.Replace(stmt, "SELECT *", "SELECT id, ts, CAST(payload AS VARCHAR) AS payload", 1)

Try / catch

out, err := src.RunSQL(ctx, stmt, params)
if err != nil && strings.Contains(err.Error(), "unable to parse row") {
    // fallback: cast complex columns to VARCHAR and retry
    out, err = src.RunSQL(ctx, castComplexColumnsToVarchar(stmt), params)
}

Prevention

When it happens

Trigger: Source.RunSQL while iterating results: a row contains a value the trino driver cannot scan into the pre-allocated value slots — often complex types (map, row, array), hyperloglog/bitmap columns, or values exceeding buffer expectations.

Common situations: SELECT * on tables with nested/complex Trino types; datetime precision conversions; binary columns; driver version incompatibility with newer Trino type encodings.

Understand the failure class

Related errors


AI-assisted analysis of googleapis/mcp-toolbox@8cc6e09de2 (2026-09-05). Data as JSON: /api/errors/4f6247ad5ed45e62. Report an issue: GitHub.