Skip to content

NaN or Infinity inside ARRAY, MAP or STRUCT fails the whole result #573

Closed

Description

@jakubhrncar

QueryContext + rows.Next fails for an ARRAY, MAP or STRUCT column when one nested DOUBLE or FLOAT value is NaN, Infinity or -Infinity. The Arrow row scanner renders nested values as JSON text, and for a non-finite float jsonfmt.Append falls through to json.Marshal, which rejects it. The whole result fails with:

databricks: arrow row scanner failed getting column value for arr: json: unsupported value: NaN

The value is present in the Arrow batch, and the same value in a top-level DOUBLE column scans fine as a float64. The failure is only in the JSON rendering of nested values. It is the same in v1.17.0, v1.19.0 and on main (57bc51a).

Reproducer, against a SQL warehouse:

SELECT array(CAST('NaN' AS DOUBLE), CAST('Infinity' AS DOUBLE)) AS arr
rows, err := db.QueryContext(ctx, "SELECT array(CAST('NaN' AS DOUBLE), CAST('Infinity' AS DOUBLE)) AS arr")
// err == nil
var dest any
ok := rows.Next()
// ok == false
err = rows.Err()
// databricks: arrow row scanner failed getting column value for arr: json: unsupported value: NaN

Reproducer without a warehouse, in internal/rows/arrowbased on main:

func TestListOfDoubleWithNonFiniteValues(t *testing.T) {
	lb := array.NewListBuilder(memory.NewGoAllocator(), arrow.PrimitiveTypes.Float64)
	defer lb.Release()
	lb.Append(true)
	lb.ValueBuilder().(*array.Float64Builder).AppendValues([]float64{1.5, math.NaN(), math.Inf(1), math.Inf(-1)}, nil)
	arr := lb.NewArray()
	defer arr.Release()

	holder, err := (&arrowValueContainerMaker{}).makeColumnValueContainer(arr.DataType(), time.UTC, nil, nil)
	assert.NoError(t, err)
	assert.NoError(t, holder.SetValueArray(arr.Data()))

	_, err = holder.Value(0)
	assert.NoError(t, err) // json: unsupported value: NaN
}

The same happens for a MAP value and a STRUCT field, which use the same marshalScalar path.

Expected: a non-finite float inside a complex value does not fail the result. JSON has no literal for these values, so they could be rendered as the strings "NaN", "Infinity" and "-Infinity". These are regular DOUBLE and FLOAT values in Databricks SQL https://docs.databricks.com/aws/en/sql/language-manual/data-types/special-floating-point-values.

Activity

  1. cathleeny commented on Nov 19, 2026

    @cathleeny
    Collaborator

    Thanks for catching this and for the detailed reproducer, @jakubhrncar! It is fixed in #574: NaN and ±Infinity inside ARRAY, MAP and STRUCT values now render as the JSON strings "NaN", "Infinity" and "-Infinity" instead of failing the result.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions