@Description("Recursively flattens GeometryCollections")
    @ScalarFunction("flatten_geometry_collections")
    @SqlType("array(" + GEOMETRY_TYPE_NAME + ")")
    public static Block flattenGeometryCollections(@SqlType(GEOMETRY_TYPE_NAME) Slice input)
    {
        OGCGeometry geometry = EsriGeometrySerde.deserialize(input);
        List<OGCGeometry> components = Streams.stream(
                flattenCollection(geometry)).collect(toImmutableList());
        BlockBuilder blockBuilder = GEOMETRY.createBlockBuilder(null, components.size());
        for (OGCGeometry component : components) {
            GEOMETRY.writeSlice(blockBuilder, EsriGeometrySerde.serialize(component));
        }
        return blockBuilder.build();
    }
@Test
    public void testFlattenGeometryCollections()
    {
        assertFlattenGeometryCollections("POINT (0 0)", "POINT (0 0)");
        assertFlattenGeometryCollections("MULTIPOINT ((0 0), (1 1))", "MULTIPOINT ((0 0), (1 1))");
        assertFlattenGeometryCollections("GEOMETRYCOLLECTION EMPTY");
        assertFlattenGeometryCollections("GEOMETRYCOLLECTION (POINT EMPTY)", "POINT EMPTY");
        assertFlattenGeometryCollections("GEOMETRYCOLLECTION (MULTIPOLYGON EMPTY)", "MULTIPOLYGON EMPTY");
        assertFlattenGeometryCollections("GEOMETRYCOLLECTION (POINT (0 0))", "POINT (0 0)");
        assertFlattenGeometryCollections(
                "GEOMETRYCOLLECTION (POINT (0 0), GEOMETRYCOLLECTION (POINT (1 1)))",
                "POINT (1 1)", "POINT (0 0)");
    }