-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
grab bag of non-controversial clean up tasks #26702
Merged
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
Next
Next commit
grab bag of non-contraversial clean up tasks
- Loading branch information
commit f80c459c2b4da7f03373cd7e486ab9eb2c1944f1
There are no files selected for viewing
This file contains 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 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 |
---|---|---|
|
@@ -34,8 +34,8 @@ public class RecordSizeEstimator { | |
* determined by {@code sampleBatchSize}. | ||
*/ | ||
public RecordSizeEstimator(final int sampleBatchSize) { | ||
this.streamRecordSizeEstimation = new HashMap<>(); | ||
this.streamSampleCountdown = new HashMap<>(); | ||
streamRecordSizeEstimation = new HashMap<>(); | ||
streamSampleCountdown = new HashMap<>(); | ||
this.sampleBatchSize = sampleBatchSize; | ||
} | ||
|
||
|
@@ -71,7 +71,7 @@ public long getEstimatedByteSize(final AirbyteRecordMessage record) { | |
} | ||
|
||
@VisibleForTesting | ||
static long getStringByteSize(final JsonNode data) { | ||
public static long getStringByteSize(final JsonNode data) { | ||
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. we end up using this in some tests later on |
||
// assume UTF-8 encoding, and each char is 4 bytes long | ||
return Jsons.serialize(data).length() * 4L; | ||
} | ||
|
This file contains 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
43 changes: 43 additions & 0 deletions
43
...s/base-java/src/main/java/io/airbyte/integrations/destination_async/AirbyteFileUtils.java
This file contains 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,43 @@ | ||
/* | ||
* Copyright (c) 2023 Airbyte, Inc., all rights reserved. | ||
*/ | ||
|
||
package io.airbyte.integrations.destination_async; | ||
|
||
import java.text.DecimalFormat; | ||
|
||
/** | ||
* Replicate the behavior of {@link org.apache.commons.io.FileUtils} to match the proclivities of | ||
* Davin and Charles. Courteously written by ChatGPT. | ||
*/ | ||
public class AirbyteFileUtils { | ||
|
||
private static final double ONE_KB = 1024; | ||
private static final double ONE_MB = ONE_KB * 1024; | ||
private static final double ONE_GB = ONE_MB * 1024; | ||
private static final double ONE_TB = ONE_GB * 1024; | ||
private static final DecimalFormat df = new DecimalFormat("#.##"); | ||
|
||
/** | ||
* Replicate the behavior of {@link org.apache.commons.io.FileUtils} but instead of rounding down to | ||
* the nearest whole number, it rounds to two decimal places. | ||
* | ||
* @param sizeInBytes size in bytes | ||
* @return human-readable size | ||
*/ | ||
public static String byteCountToDisplaySize(final long sizeInBytes) { | ||
|
||
if (sizeInBytes < ONE_KB) { | ||
return df.format(sizeInBytes) + " bytes"; | ||
} else if (sizeInBytes < ONE_MB) { | ||
return df.format((double) sizeInBytes / ONE_KB) + " KB"; | ||
} else if (sizeInBytes < ONE_GB) { | ||
return df.format((double) sizeInBytes / ONE_MB) + " MB"; | ||
} else if (sizeInBytes < ONE_TB) { | ||
return df.format((double) sizeInBytes / ONE_GB) + " GB"; | ||
} else { | ||
return df.format((double) sizeInBytes / ONE_TB) + " TB"; | ||
} | ||
} | ||
|
||
} |
This file contains 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
23 changes: 23 additions & 0 deletions
23
...se-java/src/test/java/io/airbyte/integrations/destination_async/AirbyteFileUtilsTest.java
This file contains 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,23 @@ | ||
/* | ||
* Copyright (c) 2023 Airbyte, Inc., all rights reserved. | ||
*/ | ||
|
||
package io.airbyte.integrations.destination_async; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
public class AirbyteFileUtilsTest { | ||
|
||
@Test | ||
void testByteCountToDisplaySize() { | ||
|
||
assertEquals("500 bytes", AirbyteFileUtils.byteCountToDisplaySize(500L)); | ||
assertEquals("1.95 KB", AirbyteFileUtils.byteCountToDisplaySize(2000L)); | ||
assertEquals("2.93 MB", AirbyteFileUtils.byteCountToDisplaySize(3072000L)); | ||
assertEquals("2.67 GB", AirbyteFileUtils.byteCountToDisplaySize(2872000000L)); | ||
assertEquals("1.82 TB", AirbyteFileUtils.byteCountToDisplaySize(2000000000000L)); | ||
} | ||
|
||
} |
This file contains 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 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.
in a single thread it wasn't really possible (or likely) for this to get called without accept getting called first. in a multi-threaded world that can actually happen pretty frequently, so when it log and move on.
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.
+1
maybe leave as a comment?