public static RowType projectRowType(@Nonnull RowType rowType, @Nonnull int[] projection)
            throws IllegalArgumentException {
        final int fieldCnt = rowType.getFieldCount();
        return RowType.of(
                Arrays.stream(projection)
                        .mapToObj(
                                index -> {
                                    if (index >= fieldCnt) {
                                        throw new IllegalArgumentException(
                                                String.format(
                                                        "Invalid projection index: %d of source rowType size: %d",
                                                        index, fieldCnt));
                                    }
                                    return rowType.getTypeAt(index);
                                })
                        .toArray(LogicalType[]::new),
                Arrays.stream(projection)
                        .mapToObj(index -> rowType.getFieldNames().get(index))
                        .toArray(String[]::new));
    }
@Test
    void testInvalidProjectRowType() {

        assertThatThrownBy(() -> RowTypeUtils.projectRowType(srcType, new int[] {0, 1, 2, 3}))
                .isInstanceOf(IllegalArgumentException.class)
                .hasMessageContaining("Invalid projection index: 3");

        assertThatThrownBy(() -> RowTypeUtils.projectRowType(srcType, new int[] {0, 1, 3}))
                .isInstanceOf(IllegalArgumentException.class)
                .hasMessageContaining("Invalid projection index: 3");

        assertThatThrownBy(() -> RowTypeUtils.projectRowType(srcType, new int[] {0, 0, 0, 0}))
                .isInstanceOf(ValidationException.class)
                .hasMessageContaining("Field names must be unique. Found duplicates");
    }