prestodb/presto · error · PrestoException

INVALID_FUNCTION_ARGUMENT

INVALID_FUNCTION_ARGUMENT

Error message

No rows supplied to spatial partition.

What it means

spatial_partitioning is an aggregate function that builds a KDB tree from sampled geometry rows. If zero rows were supplied to the aggregation (state.getCount() == 0), there is no data to build a partitioning from, so the output step throws INVALID_FUNCTION_ARGUMENT instead of returning a meaningless tree.

Source

Thrown at presto-main-base/src/main/java/com/facebook/presto/geospatial/SpatialPartitioningInternalAggregateFunction.java:87

            if (sampleIndex < MAX_SAMPLE_COUNT) {
                samples.set(toIntExact(sampleIndex), extent);
            }
        }

        state.setCount(state.getCount() + 1);
    }

    @CombineFunction
    public static void combine(SpatialPartitioningState state, SpatialPartitioningState otherState)
    {
        throw new UnsupportedOperationException("spatial_partitioning must run on a single node");
    }

    @OutputFunction(StandardTypes.VARCHAR)
    public static void output(SpatialPartitioningState state, BlockBuilder out)
    {
        if (state.getCount() == 0) {
            throw new PrestoException(INVALID_FUNCTION_ARGUMENT, "No rows supplied to spatial partition.");
        }

        List<Rectangle> samples = state.getSamples();

        int partitionCount = state.getPartitionCount();
        int maxItemsPerNode = (samples.size() + partitionCount - 1) / partitionCount;

        VARCHAR.writeString(out, KdbTreeUtils.toJson(buildKdbTree(maxItemsPerNode, samples)));
    }
}

View on GitHub (pinned to 55bb57d202)

Solutions

  1. Ensure the input query returns at least one non-null geometry row.
  2. Guard with a COUNT(*) check or run the aggregation only when data exists.
  3. Relax the WHERE filter or fix the join that eliminates all rows.

Example fix

// before
SELECT spatial_partitioning(geom, 100) FROM tiles WHERE partition_date = '2026-09-01'; -- empty
// after
SELECT spatial_partitioning(geom, 100) FROM tiles WHERE partition_date >= '2026-08-01'; -- non-empty range
Defensive patterns

Strategy: validation

Validate before calling

-- check input non-empty before aggregating
SELECT count(*) FROM tiles WHERE <your filter>; -- must be > 0
// app code: if (count == 0) skip building the partitioning;

Try / catch

try {
    tree = query("SELECT spatial_partitioning(geom, ?)", n);
} catch (PrestoException e) {
    if (e.getMessage().contains("No rows supplied to spatial partition")) {
        // fall back to a default partitioning or abort the job with a clear message
    }
}

Prevention

When it happens

Trigger: Calling spatial_partitioning(geometry, partition_count) over an empty table, a filtered-to-empty result set (WHERE clause matches nothing), or within a group where all rows were NULL geometry.

Common situations: Running a partitioning job before data is loaded, an over-restrictive WHERE filter, GROUP BY producing an empty group, upstream join eliminating all rows.

Related errors


AI-assisted analysis of prestodb/presto@55bb57d202 (2026-09-04). Data as JSON: /api/errors/b476e3c14e4ec25a. Report an issue: GitHub.