Repository navigation
feat: output write statistics per transaction #4620
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
Open
fbiville
wants to merge
1
commit into
GoogleCloudPlatform:main
Choose a base branch
from
fbiville:neo4j/emit_write_stats
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
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
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
82 changes: 82 additions & 0 deletions
82
...oglecloud-to-neo4j/src/main/java/com/google/cloud/teleport/v2/neo4j/utils/WriteStats.java
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 |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| /* | ||
| * Copyright (C) 2026 Google LLC | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); you may not | ||
| * use this file except in compliance with the License. You may obtain a copy of | ||
| * the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
| * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
| * License for the specific language governing permissions and limitations under | ||
| * the License. | ||
| */ | ||
| package com.google.cloud.teleport.v2.neo4j.utils; | ||
|
|
||
| import java.util.HashMap; | ||
| import java.util.Map; | ||
| import org.apache.beam.sdk.coders.RowCoder; | ||
| import org.apache.beam.sdk.schemas.Schema; | ||
| import org.apache.beam.sdk.values.Row; | ||
| import org.neo4j.driver.summary.ResultSummary; | ||
| import org.neo4j.driver.summary.SummaryCounters; | ||
|
|
||
| /** Beam helper for Neo4j write statistics records. */ | ||
| public final class WriteStats { | ||
|
|
||
| private static final Schema SCHEMA = | ||
| Schema.of( | ||
| Schema.Field.of("step", Schema.FieldType.STRING), | ||
| Schema.Field.of("batch_rows", Schema.FieldType.INT64), | ||
| Schema.Field.of("contains_updates", Schema.FieldType.BOOLEAN), | ||
| Schema.Field.of("contains_system_updates", Schema.FieldType.BOOLEAN), | ||
| Schema.Field.of("nodes_created", Schema.FieldType.INT64), | ||
| Schema.Field.of("nodes_deleted", Schema.FieldType.INT64), | ||
| Schema.Field.of("relationships_created", Schema.FieldType.INT64), | ||
| Schema.Field.of("relationships_deleted", Schema.FieldType.INT64), | ||
| Schema.Field.of("properties_set", Schema.FieldType.INT64), | ||
| Schema.Field.of("labels_added", Schema.FieldType.INT64), | ||
| Schema.Field.of("labels_removed", Schema.FieldType.INT64), | ||
| Schema.Field.of("indexes_added", Schema.FieldType.INT64), | ||
| Schema.Field.of("indexes_removed", Schema.FieldType.INT64), | ||
| Schema.Field.of("constraints_added", Schema.FieldType.INT64), | ||
| Schema.Field.of("constraints_removed", Schema.FieldType.INT64), | ||
| Schema.Field.of("system_updates", Schema.FieldType.INT64)); | ||
|
|
||
| public static RowCoder coder() { | ||
| return RowCoder.of(schema()); | ||
| } | ||
|
|
||
| /** | ||
| * Converts a write transaction's result summary into a statistics row. | ||
| * | ||
| * @param summary the summary returned by {@code Result#consume()}, which is never {@code null} | ||
| */ | ||
| public static Row convertToRow(String stepName, int batchSize, ResultSummary summary) { | ||
| SummaryCounters counters = summary.counters(); | ||
| Map<String, Object> values = new HashMap<>(); | ||
| values.put("step", stepName); | ||
| values.put("batch_rows", (long) batchSize); | ||
| values.put("contains_updates", counters.containsUpdates()); | ||
| values.put("contains_system_updates", counters.containsSystemUpdates()); | ||
| values.put("nodes_created", (long) counters.nodesCreated()); | ||
| values.put("nodes_deleted", (long) counters.nodesDeleted()); | ||
| values.put("relationships_created", (long) counters.relationshipsCreated()); | ||
| values.put("relationships_deleted", (long) counters.relationshipsDeleted()); | ||
| values.put("properties_set", (long) counters.propertiesSet()); | ||
| values.put("labels_added", (long) counters.labelsAdded()); | ||
| values.put("labels_removed", (long) counters.labelsRemoved()); | ||
| values.put("indexes_added", (long) counters.indexesAdded()); | ||
| values.put("indexes_removed", (long) counters.indexesRemoved()); | ||
| values.put("constraints_added", (long) counters.constraintsAdded()); | ||
| values.put("constraints_removed", (long) counters.constraintsRemoved()); | ||
| values.put("system_updates", (long) counters.systemUpdates()); | ||
| return Row.withSchema(schema()).withFieldValues(values).build(); | ||
| } | ||
|
|
||
| public static Schema schema() { | ||
| return SCHEMA; | ||
| } | ||
| } |
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.