Skip to content
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

Fix Brotli compression #144

Merged
merged 20 commits into from
Sep 11, 2024
Merged

Fix Brotli compression #144

merged 20 commits into from
Sep 11, 2024

Conversation

wilwade
Copy link
Member

@wilwade wilwade commented Sep 10, 2024

Note: The reference Brotli file doesn't work because it is too large. It decompresses to an extremely large size (1Gb+)

Closes #140
Closes #125 (Likely?)

A new brotli sample file was generated using python code seen below.

What Changed?

  • Moved the esbuild work to mjs. This was required to get some of the builds working correctly
  • Fixed bug in the esbuild when it tried to build the browser code in parallel with the test code causing a race condition
  • Split the compression.ts file into a browser version and a node version
  • Swapped over to use esbuild-plugin-wat which worked better than the copy-pasted one from esbuild
  • Integrated the brotli-wasm correctly for browser, but used brotli natively in nodejs

Testing!

  • There is a nodejs test for the node version
  • There is a browser test for it as well:
    1. npm i
    2. npm run build:browser
    3. npx serve .
    4. open http://localhost:3000/test/browser/ in your preferred browser
  • The example server also has it:
    • cd examples/server/
    • npm i
    • node app.js
    • cd ../../ && npm run serve
    • open http://localhost:3000/ in your preferred browser

Brotli Sample File generation script

import pandas as pd
import pyarrow as pa
import pyarrow.parquet as pq

# Create a small sample DataFrame
data = {
    'id': [1, 2, 3, 4, 5],
    'name': ['Alice', 'Bob', 'Charlie', 'David', 'Eve'],
    'age': [25, 30, 35, 40, 45]
}

df = pd.DataFrame(data)

# Convert DataFrame to PyArrow Table
table = pa.Table.from_pandas(df)

# Define output Parquet file path
output_file = "sample_brotli_compressed.parquet"

# Write to Parquet file with Brotli compression
pq.write_table(table, output_file, compression='BROTLI')

print(f"File {output_file} created successfully!")
``

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mjs version swap and removing now unused wasm plugin

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

esbuild-plugin-wat does what we did, but better!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mjs conversion

}
})
.then(() => {
return Promise.all(testTargets.map(esbuild.build));
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has to be after the other targets are built as it is dependent on it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Visible output!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replaced with the typescript version!

@@ -27,7 +27,7 @@ export const unsupported = [
'delta_encoding_optional_column.parquet', // DELTA_BINARY_PACKED unsupported
'delta_encoding_required_column.parquet', // DELTA_BINARY_PACKED unsupported
'delta_length_byte_array.parquet', // ZSTD unsupported, DELTA_BINARY_PACKED unsupported
'large_string_map.brotli.parquet', // BUG?
'large_string_map.brotli.parquet', // Fails as the large string is > 1 GB
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This took a while to figure out. It is a small file, but the large string test is very large. Too much for js for the most part.

@@ -216,6 +216,15 @@ describe('test-files', function () {
}
});

describe('Brotli compression', function () {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It works!

esbuild.mjs Outdated Show resolved Hide resolved
sourcemap: 'external',
bundle: true,
minify: false,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keeping minify off here for the local serve.

Copy link
Collaborator

@shannonwells shannonwells left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ran the examples and reviewed the code. Looks good to go, glad you found it was mainly a poor example file.

@wilwade wilwade merged commit 6797c99 into main Sep 11, 2024
1 check passed
@wilwade wilwade deleted the bug/fix-brotli-compression-140 branch September 11, 2024 19:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants