-
Notifications
You must be signed in to change notification settings - Fork 6
[12] Added metrics when writing files to iceberg from parquet. #15
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
db104db
[12] Added metrics when writing files to iceberg from parquet.
subkanthi c0b6c29
[12] Removed empty space in imports.
subkanthi 604b334
Pulled changes from master, resolved conflicts
subkanthi e6178be
Fixed formatting.
subkanthi c065ff0
Added metrics in describe command.
subkanthi a2f1647
Used iceberg conversions to get lower bound and upper bound values.
subkanthi 8a047b8
Add command line arguments to include metrics for describe command.
subkanthi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,10 +19,12 @@ local-mc mb --ignore-existing local/bucket1 | |
|
|
||
| # start Iceberg REST Catalog server | ||
| ice-rest-catalog | ||
| or using the jar file. | ||
| /ice/examples/scratch$ java -jar ../../ice-rest-catalog/target/ice-rest-catalog-jar-with-dependencies.jar & | ||
|
|
||
|
|
||
| # insert data into catalog | ||
| ice insert flowers.iris -p \ | ||
| file://iris.parquet | ||
| ice | ||
|
Collaborator
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. looks unintentional |
||
|
|
||
| ice insert nyc.taxis -p \ | ||
| https://d37ci6vzurychx.cloudfront.net/trip-data/yellow_tripdata_2025-01.parquet | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,23 +3,28 @@ | |
| import com.fasterxml.jackson.databind.ObjectMapper; | ||
| import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; | ||
| import java.io.IOException; | ||
| import java.nio.ByteBuffer; | ||
| import java.time.Instant; | ||
| import java.time.ZoneId; | ||
| import java.time.format.DateTimeFormatter; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import java.util.stream.Collectors; | ||
| import org.apache.iceberg.Snapshot; | ||
| import org.apache.iceberg.Table; | ||
| import org.apache.iceberg.*; | ||
| import org.apache.iceberg.catalog.Namespace; | ||
| import org.apache.iceberg.catalog.TableIdentifier; | ||
| import org.apache.iceberg.io.CloseableIterable; | ||
| import org.apache.iceberg.rest.RESTCatalog; | ||
| import org.apache.iceberg.types.Conversions; | ||
| import org.apache.iceberg.types.Types; | ||
|
|
||
| public final class Describe { | ||
|
|
||
| private Describe() {} | ||
|
|
||
| // TODO: refactor: the use of StringBuilder below is absolutely criminal | ||
| public static void run(RESTCatalog catalog, String target, boolean json) throws IOException { | ||
| public static void run(RESTCatalog catalog, String target, boolean json, boolean includeMetrics) | ||
| throws IOException { | ||
| String targetNamespace = null; | ||
| String targetTable = null; | ||
| if (target != null && !target.isEmpty()) { | ||
|
|
@@ -102,6 +107,10 @@ public static void run(RESTCatalog catalog, String target, boolean json) throws | |
| } | ||
| sb.append("\t\t\t\tlocation: " + snapshot.manifestListLocation() + "\n"); | ||
| } | ||
|
|
||
| if (includeMetrics) { | ||
| printTableMetrics(table, sb); | ||
| } | ||
| } | ||
| if (!tableMatched) { | ||
| sb.append(" []\n"); | ||
|
|
@@ -117,6 +126,49 @@ public static void run(RESTCatalog catalog, String target, boolean json) throws | |
| System.out.println(r); | ||
| } | ||
|
|
||
| /** | ||
| * Print table metrics | ||
| * | ||
| * @param table | ||
| */ | ||
| private static void printTableMetrics(Table table, StringBuilder buffer) throws IOException { | ||
|
Collaborator
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. nit: this javadoc conveys no extra info beyond method name. I'd just drop it |
||
| TableScan scan = table.newScan().includeColumnStats(); | ||
| CloseableIterable<FileScanTask> tasks = scan.planFiles(); | ||
|
|
||
| for (FileScanTask task : tasks) { | ||
| DataFile dataFile = task.file(); | ||
| buffer.append("\t\t\tmetrics:\n"); | ||
| buffer.append("\t\t\t file: " + dataFile.path() + "\n"); | ||
| buffer.append("\t\t\t record_count: " + dataFile.recordCount() + "\n"); | ||
|
|
||
| Map<Integer, Long> valueCounts = dataFile.valueCounts(); | ||
| Map<Integer, Long> nullCounts = dataFile.nullValueCounts(); | ||
| Map<Integer, ByteBuffer> lowerBounds = dataFile.lowerBounds(); | ||
| Map<Integer, ByteBuffer> upperBounds = dataFile.upperBounds(); | ||
|
|
||
| buffer.append("\t\t\t columns:\n"); | ||
| for (Types.NestedField field : table.schema().columns()) { | ||
| int id = field.fieldId(); | ||
| buffer.append("\t\t\t " + field.name() + ":\n"); | ||
| buffer.append("\t\t\t value_count: " + valueCounts.get(id) + "\n"); | ||
| buffer.append("\t\t\t null_count: " + nullCounts.get(id) + "\n"); | ||
|
|
||
| ByteBuffer lower = lowerBounds.get(id); | ||
| ByteBuffer upper = upperBounds.get(id); | ||
|
|
||
| String lowerStr = | ||
| lower != null ? Conversions.fromByteBuffer(field.type(), lower).toString() : "null"; | ||
| String upperStr = | ||
| upper != null ? Conversions.fromByteBuffer(field.type(), upper).toString() : "null"; | ||
|
|
||
| buffer.append("\t\t\t lower_bound: " + lowerStr + "\n"); | ||
| buffer.append("\t\t\t upper_bound: " + upperStr + "\n"); | ||
| } | ||
| } | ||
|
|
||
| tasks.close(); | ||
| } | ||
|
|
||
| private static String convertYamlToJson(String yaml) throws IOException { | ||
| ObjectMapper yamlReader = new ObjectMapper(new YAMLFactory()); | ||
| Object obj = yamlReader.readValue(yaml, Object.class); | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 section (of README) is already followed by
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.
TIP: if you execute
link-local, ice & ice-rest-catalog will point to local-ice & local-ice-rest-catalog when inside the repo. Just make sure you have direnv installed.