public static InternalSchema pruneInternalSchemaByID(InternalSchema schema, List<Integer> fieldIds, List<Integer> topParentFieldIds) {
    Types.RecordType recordType = (Types.RecordType)pruneType(schema.getRecord(), fieldIds);
    // reorder top parent fields, since the recordType.fields() produced by pruneType maybe out of order.
    List<Types.Field> newFields = new ArrayList<>();
    if (topParentFieldIds != null && !topParentFieldIds.isEmpty()) {
      for (int id : topParentFieldIds) {
        Types.Field f = recordType.field(id);
        if (f != null) {
          newFields.add(f);
        } else {
          throw new HoodieSchemaException(String.format("cannot find pruned id %s in currentSchema %s", id, schema.toString()));
        }
      }
    }
    return new InternalSchema(newFields.isEmpty() ? recordType : Types.RecordType.get(newFields));
  }
@Test
  public void testPruneSchema() {
    Types.RecordType record = getSimpleRecordType();
    InternalSchema originSchema = new InternalSchema(Types.RecordType.get(record.fields()));
    List<Integer> prunedCols = new ArrayList<>();
    prunedCols.add(4);
    prunedCols.add(3);
    prunedCols.add(0);
    prunedCols.add(2);
    InternalSchema prunedSchema = InternalSchemaUtils.pruneInternalSchemaByID(originSchema, prunedCols, null);
    InternalSchema checkedSchema = new InternalSchema(Types.RecordType.get(Arrays.asList(new Types.Field[] {
            Types.Field.get(0, "bool", Types.BooleanType.get()),
            Types.Field.get(2, "long", Types.LongType.get()),
            Types.Field.get(3, "float", Types.FloatType.get()),
            Types.Field.get(4, "double", Types.DoubleType.get())
        })));
    assertEquals(prunedSchema, checkedSchema);

    // nest schema
    Types.RecordType nestRecord = getNestRecordType();
    InternalSchema originNestSchema = new InternalSchema(Types.RecordType.get(nestRecord.fields()));
    List<Integer> prunedNestCols = new ArrayList<>();
    prunedNestCols.add(0);
    prunedNestCols.add(1);
    prunedNestCols.add(5);
    prunedNestCols.add(11);
    InternalSchema prunedNestSchema = InternalSchemaUtils.pruneInternalSchemaByID(originNestSchema, prunedNestCols, null);
  }