rdblue commented on a change in pull request #2952:
URL: https://github.com/apache/iceberg/pull/2952#discussion_r693534089
##########
File path: api/src/main/java/org/apache/iceberg/types/TypeUtil.java
##########
@@ -42,6 +42,45 @@
private TypeUtil() {
}
+ /**
+ * Project extracts particular fields from a schema. Unlike
+ * {@link TypeUtil#select(Schema, Set)}, project will pick out only
+ * the fields enumerated, this means no sub fields will be selected
+ * unless they are explicitly requested.
+ * @param schema to project fields from
+ * @param fieldIds list of explicit fields to extract
+ * @return the schema with all fields fields not selected removed
+ */
+ public static Schema project(Schema schema, Set<Integer> fieldIds) {
+ Preconditions.checkNotNull(schema, "Schema cannot be null");
+
+ Types.StructType result = project(schema.asStruct(), fieldIds);
+ if (Objects.equals(schema.asStruct(), result)) {
+ return schema;
+ } else if (result != null) {
+ if (schema.getAliases() != null) {
+ return new Schema(result.fields(), schema.getAliases());
+ } else {
+ return new Schema(result.fields());
+ }
+ }
+ return new Schema();
+ }
+
+ public static Types.StructType project(Types.StructType struct, Set<Integer>
fieldIds) {
+ Preconditions.checkNotNull(struct, "Struct cannot be null");
+ Preconditions.checkNotNull(fieldIds, "Field ids cannot be null");
+
+ Type result = visit(struct, new PruneColumns(fieldIds, false));
+ if (struct == result) {
Review comment:
Should this be `.equals`? We used to use identity, but there are build
warnings so now we just use `equals`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]