Java Code Examples for org.apache.iceberg.types.TypeUtil#getProjectedIds()

The following examples show how to use org.apache.iceberg.types.TypeUtil#getProjectedIds() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BaseTableScan.java    From iceberg with Apache License 2.0 6 votes vote down vote up
/**
 * To be able to make refinements {@link #select(Collection)} and {@link #caseSensitive(boolean)} in any order,
 * we resolve the schema to be projected lazily here.
 *
 * @return the Schema to project
 */
private Schema lazyColumnProjection() {
  Collection<String> selectedColumns = context.selectedColumns();
  if (selectedColumns != null) {
    Set<Integer> requiredFieldIds = Sets.newHashSet();

    // all of the filter columns are required
    requiredFieldIds.addAll(
        Binder.boundReferences(table.schema().asStruct(),
            Collections.singletonList(context.rowFilter()), context.caseSensitive()));

    // all of the projection columns are required
    Set<Integer> selectedIds;
    if (context.caseSensitive()) {
      selectedIds = TypeUtil.getProjectedIds(table.schema().select(selectedColumns));
    } else {
      selectedIds = TypeUtil.getProjectedIds(table.schema().caseInsensitiveSelect(selectedColumns));
    }
    requiredFieldIds.addAll(selectedIds);

    return TypeUtil.select(table.schema(), requiredFieldIds);
  }

  return schema;
}
 
Example 2
Source File: ProjectionDatumReader.java    From iceberg with Apache License 2.0 5 votes vote down vote up
@Override
public void setSchema(Schema newFileSchema) {
  this.fileSchema = newFileSchema;
  if (nameMapping == null && !AvroSchemaUtil.hasIds(fileSchema)) {
    nameMapping = MappingUtil.create(expectedSchema);
  }
  Set<Integer> projectedIds = TypeUtil.getProjectedIds(expectedSchema);
  Schema prunedSchema = AvroSchemaUtil.pruneColumns(newFileSchema, projectedIds, nameMapping);
  this.readSchema = AvroSchemaUtil.buildAvroProjection(prunedSchema, expectedSchema, renames);
  this.wrapped = newDatumReader();
}
 
Example 3
Source File: ParquetSchemaUtil.java    From iceberg with Apache License 2.0 4 votes vote down vote up
public static MessageType pruneColumns(MessageType fileSchema, Schema expectedSchema) {
  // column order must match the incoming type, so it doesn't matter that the ids are unordered
  Set<Integer> selectedIds = TypeUtil.getProjectedIds(expectedSchema);
  return (MessageType) ParquetTypeVisitor.visit(fileSchema, new PruneColumns(selectedIds));
}