bytebase/bytebase · error

failed to scan DDL row

Error message

failed to scan DDL row

What it means

After running SHOW CREATE TABLE, showCreateDDL scans each result row into a string (one DDL line per row); a rows.Scan failure aborts with this error. It indicates the Hive result row could not be decoded into the expected single string column.

Source

Thrown at backend/plugin/db/hive/dump.go:184

	objectName = fmt.Sprintf("`%s`", objectName)

	// 'SHOW CREATE TABLE' can also be used for dumping views
	stmt := fmt.Sprintf("SHOW CREATE %s %s", objectType, objectName)
	if objectType == "VIEW" {
		stmt = fmt.Sprintf("SHOW CREATE TABLE %s", objectName)
	}

	rows, err := d.db.QueryContext(ctx, stmt)
	if err != nil {
		return "", errors.Wrapf(err, "failed to execute %s", stmt)
	}
	defer rows.Close()

	var schemaDDL strings.Builder
	for rows.Next() {
		var ddlLine string
		if err := rows.Scan(&ddlLine); err != nil {
			return "", errors.Wrap(err, "failed to scan DDL row")
		}
		schemaDDL.WriteString(ddlLine)
		schemaDDL.WriteString("\n")
	}

	if err := rows.Err(); err != nil {
		return "", errors.Wrap(err, "error reading DDL rows")
	}

	if schemaDDL.Len() == 0 {
		return "", errors.New("empty DDL result")
	}

	return fmt.Sprintf(schemaStmtFmt, objectType, objectName, schemaDDL.String()), nil
}

func genIndexDDL(opts *IndexDDLOptions) (string, error) {
	var builder strings.Builder

View on GitHub (pinned to 1870550677)

Solutions

  1. Check the Hive driver version matches the HiveServer2 version in use
  2. Handle NULLs — scan into sql.NullString and skip empty rows
  3. Reproduce SHOW CREATE TABLE manually; if output is fine, the scan logic/driver is at fault
  4. Upgrade or pin the Hive client library to a compatible release

Example fix

// before
var ddlLine string
if err := rows.Scan(&ddlLine); err != nil {
	return "", errors.Wrap(err, "failed to scan DDL row")
}
// after
var ddlLine sql.NullString
if err := rows.Scan(&ddlLine); err != nil {
	return "", errors.Wrap(err, "failed to scan DDL row")
}
if ddlLine.Valid {
	schemaDDL.WriteString(ddlLine.String)
	schemaDDL.WriteString("\n")
}
Defensive patterns

Strategy: type-guard

Type guard

func scanDDLRow(rows *sql.Rows) (string, bool) {
	var s sql.NullString
	if err := rows.Scan(&s); err != nil || !s.Valid {
		return "", false
	}
	return s.String, true
}

Try / catch

if err := Dump(ctx, out, dbName); err != nil {
	if strings.Contains(err.Error(), "failed to scan DDL row") {
		// driver/type mismatch — check driver version compatibility
	}
}

Prevention

When it happens

Trigger: rows.Scan(&ddlLine) failed because the driver returned a NULL value, multiple columns were expected, or the value type is not convertible to string (driver/type mismatch).

Common situations: Hive driver returning a different column layout than expected; NULL DDL lines from a broken object; driver version mismatch between gohive/hive client library and HiveServer2 version.

Understand the failure class

Background: "invalid response format", "malformed payload", "missing data field": when an API returns 200 but the response shape is wrong — this error's family across 23 libraries.

Related errors


AI-assisted analysis of bytebase/bytebase@1870550677 (2026-09-06). Data as JSON: /api/errors/4181d6c3fd920864. Report an issue: GitHub.