public static void checkValidWriteSchema(GroupType schema) {
    schema.accept(new TypeVisitor() {
      @Override
      public void visit(GroupType groupType) {
        if (groupType.getFieldCount() <= 0) {
          throw new InvalidSchemaException("Cannot write a schema with an empty group: " + groupType);
        }
        for (Type type : groupType.getFields()) {
          type.accept(this);
        }
      }

      @Override
      public void visit(MessageType messageType) {
        visit((GroupType) messageType);
      }

      @Override
      public void visit(PrimitiveType primitiveType) {}
    });
  }
@Test
  public void testWriteCheckGroupType() {
    TypeUtil.checkValidWriteSchema(Types.repeatedGroup()
        .required(INT32)
        .named("a")
        .optional(BINARY)
        .as(UTF8)
        .named("b")
        .named("valid_group"));

    TestTypeBuilders.assertThrows(
        "Should complain about empty GroupType", InvalidSchemaException.class, (Callable<Void>) () -> {
          TypeUtil.checkValidWriteSchema(new GroupType(REPEATED, "invalid_group"));
          return null;
        });
  }