-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Core: Minor metadata table code harmonization for readable_metrics #7613
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -51,8 +51,8 @@ public Schema schema() { | |
| StructType partitionType = Partitioning.partitionType(table()); | ||
| Schema schema = ManifestEntry.getSchema(partitionType); | ||
| if (partitionType.fields().size() < 1) { | ||
| // avoid returning an empty struct, which is not always supported. instead, drop the partition | ||
| // field (id 102) | ||
| // avoid returning an empty struct, which is not always supported. | ||
| // instead, drop the partition field (id 102) | ||
| schema = TypeUtil.selectNot(schema, Sets.newHashSet(DataFile.PARTITION_ID)); | ||
| } | ||
|
|
||
|
|
@@ -133,16 +133,13 @@ public CloseableIterable<StructLike> rows() { | |
| Types.NestedField readableMetricsField = projection.findField(MetricsUtil.READABLE_METRICS); | ||
|
|
||
| if (readableMetricsField == null) { | ||
| CloseableIterable<StructLike> entryAsStruct = | ||
| CloseableIterable.transform( | ||
| entries(fileProjection), | ||
| entry -> (GenericManifestEntry<? extends ContentFile<?>>) entry); | ||
|
|
||
| StructProjection structProjection = structProjection(projection); | ||
| return CloseableIterable.transform(entryAsStruct, structProjection::wrap); | ||
|
|
||
| return CloseableIterable.transform( | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was trying to make both branches be more alike:
|
||
| entries(fileProjection), entry -> structProjection.wrap((StructLike) entry)); | ||
| } else { | ||
| Schema requiredFileProjection = requiredFileProjection(); | ||
| Schema actualProjection = removeReadableMetrics(readableMetricsField); | ||
| Schema actualProjection = removeReadableMetrics(projection, readableMetricsField); | ||
| StructProjection structProjection = structProjection(actualProjection); | ||
|
|
||
| return CloseableIterable.transform( | ||
|
|
@@ -153,9 +150,7 @@ public CloseableIterable<StructLike> rows() { | |
|
|
||
| /** | ||
| * Ensure that the underlying metrics used to populate readable metrics column are part of the | ||
| * file projection | ||
| * | ||
| * @return file projection with required columns to read readable metrics | ||
| * file projection. | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the return does not convey additional information, so removed it in favor of the method comment for brevity |
||
| */ | ||
| private Schema requiredFileProjection() { | ||
| Schema projectionForReadableMetrics = | ||
|
|
@@ -166,84 +161,59 @@ private Schema requiredFileProjection() { | |
| return TypeUtil.join(fileProjection, projectionForReadableMetrics); | ||
| } | ||
|
|
||
| private Schema removeReadableMetrics(Types.NestedField readableMetricsField) { | ||
| private Schema removeReadableMetrics( | ||
| Schema projectionSchema, Types.NestedField readableMetricsField) { | ||
| Set<Integer> readableMetricsIds = TypeUtil.getProjectedIds(readableMetricsField.type()); | ||
| return TypeUtil.selectNot(projection, readableMetricsIds); | ||
| return TypeUtil.selectNot(projectionSchema, readableMetricsIds); | ||
| } | ||
|
|
||
| private StructProjection structProjection(Schema projectedSchema) { | ||
| Schema manifestEntrySchema = ManifestEntry.wrapFileSchema(fileProjection.asStruct()); | ||
| return StructProjection.create(manifestEntrySchema, projectedSchema); | ||
| } | ||
|
|
||
| /** | ||
| * @param fileStructProjection projection to apply on the 'data_files' struct | ||
| * @return entries of this read task's manifest | ||
| */ | ||
| private CloseableIterable<? extends ManifestEntry<? extends ContentFile<?>>> entries( | ||
| Schema newFileProjection) { | ||
| return ManifestFiles.open(manifest, io, specsById).project(newFileProjection).entries(); | ||
| Schema fileStructProjection) { | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Make this method a bit more functional (input/output is more clear) |
||
| return ManifestFiles.open(manifest, io, specsById).project(fileStructProjection).entries(); | ||
| } | ||
|
|
||
| /** | ||
| * Given a manifest entry and its projection, append a 'readable_metrics' column that returns | ||
| * the entry's metrics in human-readable form. | ||
| * | ||
| * @param entry manifest entry | ||
| * @param structProjection projection to apply on the manifest entry | ||
| * @param readableMetricsField projected "readable_metrics" field | ||
| * @return struct representing projected manifest entry, with appended readable_metrics field | ||
| */ | ||
| private StructLike withReadableMetrics( | ||
| StructProjection structProjection, | ||
| ManifestEntry<? extends ContentFile<?>> entry, | ||
| Types.NestedField readableMetricsField) { | ||
| int projectionColumnCount = projection.columns().size(); | ||
| int metricsPosition = projection.columns().indexOf(readableMetricsField); | ||
|
|
||
| StructProjection entryStruct = structProjection.wrap((StructLike) entry); | ||
| StructProjection struct = structProjection.wrap((StructLike) entry); | ||
| int structSize = projection.columns().size(); | ||
|
|
||
| StructType projectedMetricType = | ||
| projection.findField(MetricsUtil.READABLE_METRICS).type().asStructType(); | ||
| MetricsUtil.ReadableMetricsStruct readableMetrics = | ||
| MetricsUtil.readableMetricsStruct(dataTableSchema, entry.file(), projectedMetricType); | ||
|
|
||
| return new ManifestEntryStructWithMetrics( | ||
| projectionColumnCount, metricsPosition, entryStruct, readableMetrics); | ||
| } | ||
|
|
||
| @Override | ||
| public Iterable<FileScanTask> split(long splitSize) { | ||
| return ImmutableList.of(this); // don't split | ||
| } | ||
| } | ||
|
|
||
| static class ManifestEntryStructWithMetrics implements StructLike { | ||
| private final StructProjection entryAsStruct; | ||
| private final MetricsUtil.ReadableMetricsStruct readableMetrics; | ||
| private final int projectionColumnCount; | ||
| private final int metricsPosition; | ||
|
|
||
| ManifestEntryStructWithMetrics( | ||
| int projectionColumnCount, | ||
| int metricsPosition, | ||
| StructProjection entryAsStruct, | ||
| MetricsUtil.ReadableMetricsStruct readableMetrics) { | ||
| this.entryAsStruct = entryAsStruct; | ||
| this.readableMetrics = readableMetrics; | ||
| this.projectionColumnCount = projectionColumnCount; | ||
| this.metricsPosition = metricsPosition; | ||
| } | ||
| readableMetrics(entry.file(), readableMetricsField); | ||
| int metricsPosition = projection.columns().indexOf(readableMetricsField); | ||
|
|
||
| @Override | ||
| public int size() { | ||
| return projectionColumnCount; | ||
| return new MetricsUtil.StructWithReadableMetrics( | ||
| struct, structSize, readableMetrics, metricsPosition); | ||
| } | ||
|
|
||
| @Override | ||
| public <T> T get(int pos, Class<T> javaClass) { | ||
| if (pos < metricsPosition) { | ||
| return entryAsStruct.get(pos, javaClass); | ||
| } else if (pos == metricsPosition) { | ||
| return javaClass.cast(readableMetrics); | ||
| } else { | ||
| // columnCount = fileAsStruct column count + the readable metrics field. | ||
| // When pos is greater than metricsPosition, the actual position of the field in | ||
| // fileAsStruct should be subtracted by 1. | ||
| return entryAsStruct.get(pos - 1, javaClass); | ||
| } | ||
| private MetricsUtil.ReadableMetricsStruct readableMetrics( | ||
| ContentFile<?> file, Types.NestedField readableMetricsField) { | ||
| StructType projectedMetricType = readableMetricsField.type().asStructType(); | ||
| return MetricsUtil.readableMetricsStruct(dataTableSchema, file, projectedMetricType); | ||
| } | ||
|
|
||
| @Override | ||
| public <T> void set(int pos, T value) { | ||
| throw new UnsupportedOperationException("ManifestEntryStructWithMetrics is read only"); | ||
| public Iterable<FileScanTask> split(long splitSize) { | ||
| return ImmutableList.of(this); // don't split | ||
| } | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not related, but fixing longstanding uneven line breaks introduced by the spotless refactor