├── .config └── dotnet-tools.json ├── .editorconfig ├── .github ├── ISSUE_TEMPLATE │ ├── bug_report.yml │ └── feature_request.yml ├── dependabot.yml └── workflows │ ├── check-required.yml │ └── ci.yml ├── .gitignore ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── LICENSE ├── ParquetSharp.DataFrame.DotSettings ├── ParquetSharp.DataFrame.Test ├── .editorconfig ├── DataFrameToParquet.cs ├── IsExternalInit.cs ├── ParquetSharp.DataFrame.Test.csproj ├── ParquetToDataFrame.cs └── UnitTestDisposableDirectory.cs ├── ParquetSharp.DataFrame.sln ├── ParquetSharp.DataFrame ├── .editorconfig ├── ColumnCreator.cs ├── DataFrameExtensions.cs ├── DataFrameSetter.cs ├── DataFrameWriter.cs ├── ParquetFileReaderExtensions.cs ├── ParquetSharp.DataFrame.csproj └── Unit.cs ├── README.md └── SECURITY.md /.config/dotnet-tools.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": 1, 3 | "isRoot": true, 4 | "tools": { 5 | "jetbrains.resharper.globaltools": { 6 | "version": "2021.3.1", 7 | "commands": [ 8 | "jb" 9 | ] 10 | }, 11 | "dotnet-format": { 12 | "version": "5.1.250801", 13 | "commands": [ 14 | "dotnet-format" 15 | ] 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | ; EditorConfig to support per-solution formatting. 2 | ; Use the EditorConfig VS add-in to make this work. 3 | ; http://editorconfig.org/ 4 | 5 | ; This is the default for the codeline. 6 | root = true 7 | 8 | [*] 9 | ; Don't use tabs for indentation. 10 | indent_style = space 11 | ; (Please don't specify an indent_size here; that has too many unintended consequences.) 12 | charset = utf-8 13 | trim_trailing_whitespace = true 14 | insert_final_newline = true 15 | 16 | ; Code files 17 | [*.{cs}] 18 | indent_size = 4 19 | 20 | ; All XML-based file formats 21 | [*.{config,csproj,nuspec,props,resx,ruleset,targets,vsct,vsixmanifest,xaml,xml,vsmanproj,swixproj}] 22 | indent_size = 2 23 | 24 | ; JSON files 25 | [*.json] 26 | indent_size = 2 27 | 28 | ; PowerShell scripts 29 | [*.{ps1}] 30 | indent_size = 4 31 | 32 | [*.{sh}] 33 | indent_size = 4 34 | 35 | ; Dotnet code style settings 36 | [*.{cs,vb}] 37 | ; Sort using and Import directives with System.* appearing first 38 | dotnet_sort_system_directives_first = true 39 | dotnet_separate_import_directive_groups = false 40 | 41 | ; IDE0003 Avoid "this." and "Me." if not necessary 42 | dotnet_style_qualification_for_field = false:warning 43 | dotnet_style_qualification_for_property = false:warning 44 | dotnet_style_qualification_for_method = false:warning 45 | dotnet_style_qualification_for_event = false:warning 46 | 47 | ; IDE0012 Use language keywords instead of framework type names for type references 48 | dotnet_style_predefined_type_for_locals_parameters_members = true:warning 49 | ; IDE0013 50 | dotnet_style_predefined_type_for_member_access = true:warning 51 | 52 | ; Suggest more modern language features when available 53 | dotnet_style_object_initializer = true:suggestion 54 | dotnet_style_collection_initializer = true:suggestion 55 | dotnet_style_explicit_tuple_names = true:suggestion 56 | dotnet_style_coalesce_expression = true:suggestion 57 | dotnet_style_null_propagation = true:suggestion 58 | 59 | ; Licence header 60 | file_header_template = -----------------------------------------------------------------------\n \n Copyright 2020 G-Research Limited\n\n Licensed under the Apache License, Version 2.0 (the "License"),\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an "AS IS" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n \n----------------------------------------------------------------------- 61 | 62 | ; CSharp code style settings 63 | [*.cs] 64 | ; IDE0007 'var' preferences 65 | csharp_style_var_for_built_in_types = true:none 66 | csharp_style_var_when_type_is_apparent = true:none 67 | csharp_style_var_elsewhere = false:none 68 | 69 | ; Prefer method-like constructs to have a block body 70 | csharp_style_expression_bodied_methods = false:none 71 | csharp_style_expression_bodied_constructors = false:none 72 | csharp_style_expression_bodied_operators = false:none 73 | 74 | ; Prefer property-like constructs to have an expression-body 75 | csharp_style_expression_bodied_properties = true:suggestion 76 | csharp_style_expression_bodied_indexers = true:suggestion 77 | csharp_style_expression_bodied_accessors = true:suggestion 78 | 79 | ; Suggest more modern language features when available 80 | csharp_style_pattern_matching_over_is_with_cast_check = true:none 81 | csharp_style_pattern_matching_over_as_with_null_check = true:none 82 | csharp_style_inlined_variable_declaration = true:none 83 | csharp_style_throw_expression = true:none 84 | csharp_style_conditional_delegate_call = true:suggestion 85 | 86 | ; Newline settings 87 | csharp_new_line_before_open_brace = all 88 | csharp_new_line_before_else = true 89 | csharp_new_line_before_catch = true 90 | csharp_new_line_before_finally = true 91 | csharp_new_line_before_members_in_object_initializers = true 92 | csharp_new_line_before_members_in_anonymous_types = true 93 | 94 | ; Naming styles 95 | dotnet_naming_style.pascal_case_style.capitalization = pascal_case 96 | dotnet_naming_style.camel_case_style.capitalization = camel_case 97 | 98 | ; Naming rule: async methods end in Async 99 | dotnet_naming_style.async_method_style.capitalization = pascal_case 100 | dotnet_naming_style.async_method_style.required_suffix = Async 101 | dotnet_naming_symbols.async_method_symbols.applicable_kinds = method 102 | dotnet_naming_symbols.async_method_symbols.required_modifiers = async 103 | dotnet_naming_rule.async_methods_rule.severity = suggestion 104 | dotnet_naming_rule.async_methods_rule.symbols = async_method_symbols 105 | dotnet_naming_rule.async_methods_rule.style = async_method_style 106 | 107 | ; Naming rule: Interfaces must be pascal-cased prefixed with I 108 | dotnet_naming_style.interface_style.capitalization = pascal_case 109 | dotnet_naming_style.interface_style.required_prefix = I 110 | dotnet_naming_symbols.interface_symbols.applicable_kinds = interface 111 | dotnet_naming_symbols.interface_symbols.applicable_accessibilities = * 112 | dotnet_naming_rule.interfaces_rule.severity = warning 113 | dotnet_naming_rule.interfaces_rule.symbols = interface_symbols 114 | dotnet_naming_rule.interfaces_rule.style = interface_style 115 | 116 | ; Naming rule: All methods and properties must be pascal-cased 117 | dotnet_naming_symbols.method_and_property_symbols.applicable_kinds = method,property,class,struct,enum:property,namespace 118 | dotnet_naming_symbols.method_and_property_symbols.applicable_accessibilities = * 119 | dotnet_naming_rule.methods_and_properties_rule.severity = warning 120 | dotnet_naming_rule.methods_and_properties_rule.symbols = method_and_property_symbols 121 | dotnet_naming_rule.methods_and_properties_rule.style = pascal_case_style 122 | 123 | ; Naming rule: Static fields must be pascal-cased 124 | dotnet_naming_symbols.static_member_symbols.applicable_kinds = field 125 | dotnet_naming_symbols.static_member_symbols.applicable_accessibilities = * 126 | dotnet_naming_symbols.static_member_symbols.required_modifiers = static 127 | dotnet_naming_symbols.const_member_symbols.applicable_kinds = field 128 | dotnet_naming_symbols.const_member_symbols.applicable_accessibilities = * 129 | dotnet_naming_symbols.const_member_symbols.required_modifiers = const 130 | dotnet_naming_rule.static_fields_rule.severity = warning 131 | dotnet_naming_rule.static_fields_rule.symbols = static_member_symbols 132 | dotnet_naming_rule.static_fields_rule.style = pascal_case_style 133 | 134 | ; Naming rule: Private members must be camel-cased and prefixed with underscore 135 | dotnet_naming_style.private_member_style.capitalization = camel_case 136 | dotnet_naming_style.private_member_style.required_prefix = _ 137 | dotnet_naming_symbols.private_field_symbols.applicable_kinds = field,event 138 | dotnet_naming_symbols.private_field_symbols.applicable_accessibilities = private,protected,internal 139 | dotnet_naming_rule.private_field_rule.severity = warning 140 | dotnet_naming_rule.private_field_rule.symbols = private_field_symbols 141 | dotnet_naming_rule.private_field_rule.style = private_member_style -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.yml: -------------------------------------------------------------------------------- 1 | name: Bug Report 2 | description: Create a bug report to help us improve ParquetSharp.DataFrame 3 | title: "[BUG]: " 4 | labels: [ "Bug" ] 5 | 6 | body: 7 | - type: markdown 8 | attributes: 9 | value: | 10 | **Thank you for reporting this issue!** 11 | To help us understand and address the problem effectively, please provide detailed information. 12 | You can refer to [this guide](https://stackoverflow.com/help/mcve) for tips on creating a good bug report. 13 | 14 | - type: textarea 15 | id: issue-description 16 | attributes: 17 | label: Issue Description 18 | description: A clear and concise description of the issue 19 | validations: 20 | required: true 21 | 22 | - type: textarea 23 | id: environment-information 24 | attributes: 25 | label: Environment Information 26 | description: "Please provide the following details:" 27 | value: | 28 | - ParquetSharp.DataFrame Version: [e.g. 0.1.0] 29 | - ParquetSharp Version: [e.g. 11.0.0] 30 | - .NET Framework/SDK Version: [e.g. .NET Framework 4.7.2] 31 | - Operating System: [e.g. Windows 10] 32 | validations: 33 | required: true 34 | 35 | - type: textarea 36 | id: steps-to-reproduce 37 | attributes: 38 | label: Steps To Reproduce 39 | description: Detailed steps to reproduce the behavior 40 | placeholder: | 41 | 1. Provide a minimal code example or steps. 42 | 2. Explain the exact error message or current behavior. 43 | validations: 44 | required: true 45 | 46 | - type: textarea 47 | id: expected-behavior 48 | attributes: 49 | label: Expected Behavior 50 | description: A clear and concise description of what you expected to happen. 51 | validations: 52 | required: true 53 | 54 | - type: textarea 55 | id: additional-context 56 | attributes: 57 | label: Additional Context (Optional) 58 | description: Add any other context about the problem here, including log outputs or screenshots if applicable. 59 | validations: 60 | required: false 61 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.yml: -------------------------------------------------------------------------------- 1 | name: Feature Request 2 | description: Suggest a new idea for ParquetSharp.DataFrame 3 | title: "[FEATURE REQUEST]: <title>" 4 | labels: [ "Feature Request" ] 5 | 6 | body: 7 | - type: textarea 8 | id: related-problem 9 | attributes: 10 | label: Is your feature request related to a problem? Please describe. 11 | description: A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] 12 | validations: 13 | required: true 14 | 15 | - type: textarea 16 | id: describe-solution 17 | attributes: 18 | label: Describe the solution you'd like 19 | description: A clear and concise description of what you want to happen. 20 | validations: 21 | required: true 22 | 23 | - type: textarea 24 | id: describe-alternatives 25 | attributes: 26 | label: Describe alternatives you've considered 27 | description: A clear and concise description of any alternative solutions or features you've considered. 28 | 29 | - type: textarea 30 | id: additional-context 31 | attributes: 32 | label: Additional context 33 | description: Add any other context or screenshots about the feature request here. 34 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | --- 2 | version: 2 3 | updates: 4 | - package-ecosystem: "github-actions" 5 | directory: "/" 6 | schedule: 7 | interval: "daily" 8 | -------------------------------------------------------------------------------- /.github/workflows/check-required.yml: -------------------------------------------------------------------------------- 1 | name: Check required jobs 2 | 3 | # This workflow is triggered when a workflow run for the CI is completed. 4 | # It checks if the "All required checks done" job was actually successful 5 | # (and not just skipped) and creates a check run if that is the case. The 6 | # check run can be used to protect the main branch from being merged if the 7 | # CI is not passing. 8 | 9 | on: 10 | workflow_run: 11 | types: [completed] 12 | workflows: [CI] 13 | 14 | permissions: 15 | actions: read 16 | checks: write 17 | 18 | jobs: 19 | required-jobs: 20 | name: Check required jobs 21 | runs-on: ubuntu-latest 22 | steps: 23 | - uses: actions/github-script@v7 24 | with: 25 | script: | 26 | // list jobs for worklow run attempt 27 | const { data: { jobs } } = await github.rest.actions.listJobsForWorkflowRunAttempt({ 28 | owner: context.payload.repository.owner.login, 29 | repo: context.payload.repository.name, 30 | run_id: context.payload.workflow_run.id, 31 | attempt_number: context.payload.workflow_run.run_attempt, 32 | }); 33 | // check if required job was successful 34 | var success = false; 35 | core.info(`Checking jobs for workflow run ${context.payload.workflow_run.html_url}`); 36 | jobs.forEach(job => { 37 | var mark = '-' 38 | if (job.name === 'All required checks done' && job.conclusion === 'success') { 39 | success = true; 40 | mark = '✅'; 41 | } 42 | core.info(`${mark} ${job.name}: ${job.conclusion}`); 43 | }); 44 | // create check run if job was successful 45 | if (success) { 46 | await github.rest.checks.create({ 47 | owner: context.payload.repository.owner.login, 48 | repo: context.payload.repository.name, 49 | name: 'All required checks succeeded', 50 | head_sha: context.payload.workflow_run.head_sha, 51 | status: 'completed', 52 | conclusion: 'success', 53 | output: { 54 | title: 'All required checks succeeded', 55 | summary: `See [workflow run](${context.payload.workflow_run.html_url}) for details.`, 56 | }, 57 | }); 58 | } 59 | -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | 3 | on: 4 | push: 5 | pull_request: 6 | 7 | env: 8 | DOTNET_CLI_TELEMETRY_OPTOUT: true 9 | DOTNET_NOLOGO: true 10 | 11 | jobs: 12 | 13 | check-format: 14 | if: github.event_name == 'push' || github.event.pull_request.head.repo.id != github.event.pull_request.base.repo.id 15 | name: Check format 16 | runs-on: ubuntu-latest 17 | steps: 18 | - name: Checkout 19 | uses: actions/checkout@v4 20 | - name: Setup .NET SDK 21 | uses: actions/setup-dotnet@v4 22 | with: 23 | dotnet-version: 8.0.x 24 | - name: Code formating check 25 | run: | 26 | dotnet tool restore 27 | dotnet tool run dotnet-format -- --check 28 | dotnet jb cleanupcode --profile="Built-in: Reformat Code" --settings="ParquetSharp.DataFrame.DotSettings" --verbosity=WARN "ParquetSharp.DataFrame" "ParquetSharp.DataFrame.Test" 29 | 30 | files=($(git diff --name-only)) 31 | if [ ${#files[@]} -gt 0 ] 32 | then 33 | for file in $files; do echo "::error file=$file::Code format check failed"; done 34 | exit 1 35 | fi 36 | 37 | # Build the nuget package and upload it as an artifact. 38 | build-nuget: 39 | if: github.event_name == 'push' || github.event.pull_request.head.repo.id != github.event.pull_request.base.repo.id 40 | name: Build NuGet package 41 | runs-on: ubuntu-latest 42 | steps: 43 | - name: Checkout 44 | uses: actions/checkout@v4 45 | - name: Setup .NET SDK 46 | uses: actions/setup-dotnet@v4 47 | with: 48 | dotnet-version: 8.0.x 49 | - name: Build project 50 | run: dotnet build ParquetSharp.DataFrame --configuration=Release 51 | - name: Build NuGet package 52 | run: dotnet pack ParquetSharp.DataFrame --configuration=Release --no-build --output nuget 53 | - name: Upload NuGet artifact 54 | uses: actions/upload-artifact@v4 55 | with: 56 | name: nuget-package 57 | path: nuget 58 | 59 | # Run .NET unit tests with the nuget package on all platforms and all supported .NET runtimes (thus testing the user workflow). 60 | test-nuget: 61 | strategy: 62 | matrix: 63 | os: [ubuntu-latest, macos-latest, macos-13, windows-latest] # macos-13 included for x64 64 | dotnet: [net6.0, net7.0, net8.0] 65 | include: 66 | - os: windows-latest 67 | dotnet: net472 68 | fail-fast: false 69 | name: Test NuGet package (.NET ${{ matrix.dotnet }} on ${{ matrix.os }}) 70 | runs-on: ${{ matrix.os }} 71 | needs: build-nuget 72 | steps: 73 | - name: Checkout 74 | uses: actions/checkout@v4 75 | - name: Get version 76 | id: get-version 77 | run: echo "version=$((Select-Xml -Path ./ParquetSharp.DataFrame/ParquetSharp.DataFrame.csproj -XPath '/Project/PropertyGroup/Version/text()').node.Value)" >> $env:GITHUB_OUTPUT 78 | shell: pwsh 79 | - name: Download NuGet artifact 80 | uses: actions/download-artifact@v4 81 | with: 82 | name: nuget-package 83 | path: nuget 84 | - name: Setup .NET 6 SDK 85 | if: matrix.dotnet == 'net6.0' 86 | uses: actions/setup-dotnet@v4 87 | with: 88 | dotnet-version: 6.0.x 89 | - name: Setup .NET 7 SDK 90 | if: matrix.dotnet == 'net7.0' 91 | uses: actions/setup-dotnet@v4 92 | with: 93 | dotnet-version: 7.0.x 94 | - name: Setup .NET 8 SDK 95 | uses: actions/setup-dotnet@v4 96 | with: 97 | dotnet-version: 8.0.x 98 | - name: Add local NuGet feed 99 | run: | 100 | dotnet new nugetconfig 101 | dotnet nuget add source -n local $PWD/nuget 102 | - name: Change test project references to use local NuGet package 103 | run: | 104 | dotnet remove ParquetSharp.DataFrame.Test reference ParquetSharp.DataFrame/ParquetSharp.DataFrame.csproj 105 | dotnet add ParquetSharp.DataFrame.Test package ParquetSharp.DataFrame -v ${{ steps.get-version.outputs.version }} 106 | - name: Build & Run .NET unit tests 107 | run: dotnet test ParquetSharp.DataFrame.Test --configuration=Release --framework ${{ matrix.dotnet }} 108 | 109 | # Virtual job that can be configured as a required check before a PR can be merged. 110 | # As GitHub considers a check as successful if it is skipped, we need to check its status in 111 | # another workflow (check-required.yml) and create a check there. 112 | all-required-checks-done: 113 | name: All required checks done 114 | needs: 115 | - check-format 116 | - test-nuget 117 | runs-on: ubuntu-latest 118 | steps: 119 | - run: echo "All required checks done" 120 | 121 | # Create a GitHub release and publish the NuGet packages to nuget.org when a tag is pushed. 122 | publish-release: 123 | if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/') && !github.event.repository.fork 124 | name: Publish release 125 | runs-on: ubuntu-latest 126 | needs: all-required-checks-done 127 | steps: 128 | - name: Checkout 129 | uses: actions/checkout@v4 130 | - name: Check version 131 | id: check-version 132 | shell: pwsh 133 | run: | 134 | $version = (Select-Xml -Path ./ParquetSharp.DataFrame/ParquetSharp.DataFrame.csproj -XPath '/Project/PropertyGroup/Version/text()').node.Value 135 | $tag = "${{ github.ref }}".SubString(10) 136 | if (-not ($tag -eq $version)) { 137 | echo "::error ::There is a mismatch between the project version ($version) and the tag ($tag)" 138 | exit 1 139 | } 140 | echo "version=$version" >> $env:GITHUB_OUTPUT 141 | - name: Download NuGet artifact 142 | uses: actions/download-artifact@v4 143 | with: 144 | name: nuget-package 145 | path: nuget 146 | # if version contains "-" treat it as pre-release 147 | # example: 1.0.0-beta1 148 | - name: Create release 149 | uses: softprops/action-gh-release@v2 150 | with: 151 | name: ParquetSharp.DataFrame ${{ steps.check-version.outputs.version }} 152 | draft: true 153 | prerelease: ${{ contains(steps.check-version.outputs.version, '-') }} 154 | files: | 155 | nuget/ParquetSharp.DataFrame.${{ steps.check-version.outputs.version }}.nupkg 156 | env: 157 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 158 | - name: Publish to NuGet 159 | run: dotnet nuget push nuget/ParquetSharp.DataFrame.${{ steps.check-version.outputs.version }}.nupkg --api-key ${{ secrets.NUGET_API_KEY }} --source https://api.nuget.org/v3/index.json 160 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | bin 2 | obj 3 | nuget 4 | .vs 5 | 6 | .idea 7 | *.user 8 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Code of Conduct 2 | 3 | Guiding us in our day-to-day interactions and decision-making are the values of trust, respect, collaboration and transparency. Our community welcomes participants from around the world with different experiences, personalities, unique perspectives, and great ideas to share. 4 | 5 | We expect this code of conduct to be honored by everyone who participates in the ParquetSharp community formally or informally. 6 | 7 | This code is not exhaustive or complete, and is a living document. It serves to distill our common understanding of a collaborative, shared environment and goals. We expect it to be followed in spirit as much as in the letter, so that it can enrich all of us and the technical communities in which we participate. 8 | 9 | 10 | ## Our Pledge 11 | 12 | In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation. 13 | 14 | ## Our Standards 15 | 16 | Examples of behavior that contributes to creating a positive environment include: 17 | 18 | * Using welcoming and inclusive language. 19 | * Being respectful of differing viewpoints and experiences. 20 | * Gracefully accepting constructive criticism. 21 | * Attempting collaboration before conflict. 22 | * Focusing on what is best for the community. 23 | * Appreciating time and effort contributed by members. 24 | * Showing empathy towards other community members. 25 | 26 | 27 | Examples of unacceptable behavior by participants include: 28 | 29 | * Violence, threats of violence, or inciting others to commit self-harm. 30 | * The use of sexualized language or imagery and unwelcome sexual attention or advances. 31 | * Trolling, intentionally spreading misinformation, insulting/derogatory comments, and personal or political attacks, including [challenging someone’s self-identity](https://lgbtq.technology/culture.html#discussion-of-labels). 32 | * Public or private [harassment](https://lgbtq.technology/coc.html#harassment), aggression, deliberate intimidation, or threats. 33 | * [Feigning or exaggerating surprise](https://www.recurse.com/manual#no-feigned-surprise) when someone admits to not knowing something, or excusing a disrespectful communication as “ironic” or “joking”. 34 | * Publishing others' private information, such as a physical or electronic address, without explicit permission. This includes any sort of “outing” of any aspect of someone’s identity without their consent. 35 | * Abuse of the reporting process to intentionally harass or exclude others. 36 | * Advocating for, or encouraging, any of the above behavior. 37 | * Other conduct which could reasonably be considered inappropriate in a professional or community setting. 38 | 39 | 40 | ## Our Responsibilities 41 | 42 | Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior. 43 | 44 | Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful. 45 | 46 | 47 | ## Scope 48 | 49 | This Code of Conduct applies both within spaces involving this project and in other spaces involving community members. This includes the repository, its Pull Requests and Issue tracker, its Twitter community, private email communications in the context of the project, and any events where members of the project are participating, as well as adjacent communities and venues affecting the project’s members. 50 | 51 | Depending on the violation, the maintainers may decide that violations of this code of conduct that have happened outside of the scope of the community may deem an individual unwelcome, and take appropriate action to maintain the comfort and safety of its members. 52 | 53 | As a project on GitHub, this project is additionally covered by the [GitHub Community Guidelines](https://help.github.com/articles/github-community-guidelines/). 54 | 55 | 56 | ## Enforcement 57 | 58 | While this code of conduct should be adhered to by participants, we recognize that sometimes people may have a bad day, or be unaware of some of the guidelines in this code of conduct. When that happens, or if they are violating this code of conduct, you may reply to them and point out this code of conduct. Such messages may be in public or in private, whatever is most appropriate. However, regardless of whether the message is public or not, it should still adhere to the relevant parts of this code of conduct and itself should not be abusive or disrespectful. Assume good faith; it is more likely that participants are unaware of their bad behaviour than that they intentionally try to degrade the quality of the discussion. 59 | 60 | As a small and young project, we don’t yet have a Code of Conduct enforcement team. We encourage contributors to try to resolve issues with respectful communication - [here is an example of how to do that](https://github.com/fsprojects/fantomas/pull/649#issuecomment-599965505). 61 | 62 | Should there be difficulties in dealing with the situation or you are uncomfortable speaking up, unacceptable behavior may be reported to conduct.parquetsharp@gr-oss.io. All complaints will be reviewed and investigated and will result in a response that is deemed necessary and appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. 63 | 64 | If you are unsure whether an incident is a violation, or whether the space where the incident took place is covered by our Code of Conduct, we encourage you to still address or report it. We would prefer to have a few extra reports where we decide to take no action than to let an incident go unnoticed and unresolved, resulting in an individual or group feeling like they can no longer participate in the community. Reports deemed as not a violation will also allow us to improve our Code of Conduct and processes surrounding it. 65 | 66 | Participants asked to stop any harassing behavior are expected to comply immediately. Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership. 67 | 68 | ## License 69 | 70 | This Code of Conduct is licensed under the [Creative Commons Attribution-ShareAlike 3.0 Unported License](https://creativecommons.org/licenses/by-sa/3.0/). 71 | 72 | ## Attribution 73 | 74 | This Code of Conduct is informed by and adapted from multiple sources: 75 | 76 | * [Apache Code of Conduct](https://www.apache.org/foundation/policies/conduct). 77 | * [Auth0 Contributor Code of Conduct](https://github.com/auth0/open-source-template/blob/master/CODE-OF-CONDUCT.md). 78 | * [Geek Feminism Wiki Anti-Harassment Policy](https://geekfeminism.wikia.org/wiki/Conference_anti-harassment/Policy). 79 | * [GitHub Community Guidelines](https://help.github.com/en/github/site-policy/github-community-guidelines). 80 | * [GitHub Contributor Covenant](https://www.contributor-covenant.org/). 81 | * [LGBTQ in Technology Slack Code of Conduct](http://lgbtq.technology/coc.html). 82 | * [Python Code of Conduct](https://www.python.org/psf/conduct/). 83 | * [Recurse Center User’s Manual](https://www.recurse.com/manual#no-feigned-surprise). 84 | * [Trio Code of Conduct](https://trio.readthedocs.io/en/stable/code-of-conduct.html). 85 | 86 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing to ParquetSharp.DataFrame 2 | 3 | Thank you for your interest in contributing! 🎉 4 | 5 | This library is primarily built and maintained to serve G-Research’s needs. While we welcome contributions, our main focus is ensuring the project continues to meet our requirements. We are more likely to accept bug fixes and documentation updates but may be conservative about new features. 6 | 7 | We will review issues and pull requests on a **best-effort** basis. 8 | 9 | ## Issues 10 | 11 | Please report bugs and feature requests by opening an [Issue](https://github.com/G-Research/ParquetSharp.DataFrame/issues). If possible, check for existing issues before submitting a new one. 12 | 13 | For security-related issues, **do not** open a public issue. Instead, refer to our [security policy](https://github.com/G-Research/ParquetSharp.DataFrame/blob/main/SECURITY.md). 14 | 15 | ## Pull Requests 16 | 17 | Before making large changes, open an issue to discuss your proposal. To increase the likelihood of acceptance: 18 | - Keep changes small and focused 19 | - Include tests for your modifications 20 | - Follow project coding standards 21 | - Provide clear explanations for design choices 22 | 23 | ## Code Style 24 | 25 | Ensure your code adheres to the project's formatting guidelines using: 26 | ```sh 27 | dotnet tool restore 28 | dotnet tool run dotnet-format -- --check 29 | dotnet jb cleanupcode --profile="Built-in: Reformat Code" --settings="ParquetSharp.DataFrame.DotSettings" --verbosity=WARN "ParquetSharp.DataFrame" "ParquetSharp.DataFrame.Test" 30 | ``` 31 | 32 | Thank you for contributing! 🚀 33 | 34 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /ParquetSharp.DataFrame.DotSettings: -------------------------------------------------------------------------------- 1 | <wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation"> 2 | <s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/WRAP_LINES/@EntryValue">False</s:Boolean> 3 | <s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/LINE_FEED_AT_FILE_END/@EntryValue">True</s:Boolean> 4 | <s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/PLACE_ACCESSOR_ATTRIBUTE_ON_SAME_LINE_EX/@EntryValue">NEVER</s:String> 5 | <s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/PLACE_ACCESSORHOLDER_ATTRIBUTE_ON_SAME_LINE_EX/@EntryValue">NEVER</s:String> 6 | <s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/PLACE_FIELD_ATTRIBUTE_ON_SAME_LINE_EX/@EntryValue">NEVER</s:String> 7 | </wpf:ResourceDictionary> 8 | -------------------------------------------------------------------------------- /ParquetSharp.DataFrame.Test/.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | end_of_line = lf 5 | charset = utf-8 6 | insert_final_newline = true 7 | indent_style = space 8 | indent_size = 4 9 | trim_trailing_whitespace = true 10 | 11 | [*.csproj] 12 | indent_size = 2 13 | resharper_xml_wrap_tags_and_pi = false 14 | 15 | [*.cs] 16 | csharp_new_line_before_members_in_object_initializers = false 17 | csharp_preserve_single_line_blocks = true 18 | resharper_blank_lines_after_block_statements = 0 19 | resharper_blank_lines_around_auto_property = 0 20 | resharper_blank_lines_around_single_line_type = 0 21 | resharper_csharp_blank_lines_around_field = 0 22 | resharper_csharp_insert_final_newline = true 23 | resharper_csharp_wrap_lines = false 24 | resharper_empty_block_style = multiline 25 | resharper_keep_existing_embedded_block_arrangement = false 26 | resharper_keep_existing_enum_arrangement = false 27 | resharper_max_attribute_length_for_same_line = 70 28 | resharper_place_accessorholder_attribute_on_same_line = false 29 | resharper_place_expr_accessor_on_single_line = true 30 | resharper_place_expr_method_on_single_line = true 31 | resharper_place_expr_property_on_single_line = true 32 | resharper_place_field_attribute_on_same_line = false 33 | resharper_place_simple_embedded_statement_on_same_line = true 34 | resharper_place_simple_initializer_on_single_line = false 35 | resharper_remove_blank_lines_near_braces_in_code = false 36 | resharper_remove_blank_lines_near_braces_in_declarations = false 37 | resharper_wrap_array_initializer_style = chop_if_long 38 | resharper_wrap_chained_binary_expressions = chop_if_long 39 | resharper_wrap_object_and_collection_initializer_style = chop_always 40 | -------------------------------------------------------------------------------- /ParquetSharp.DataFrame.Test/DataFrameToParquet.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using Microsoft.Data.Analysis; 6 | using Xunit; 7 | 8 | namespace ParquetSharp.DataFrame.Test 9 | { 10 | /// <summary> 11 | /// Test writing DataFrames to Parquet 12 | /// </summary> 13 | public class DataFrameToParquet 14 | { 15 | [Fact] 16 | public void TestToParquet() 17 | { 18 | int numRows = 10_000; 19 | var testColumns = GetTestColumns(); 20 | var columns = new List<DataFrameColumn>(testColumns.Length); 21 | var logicalTypeOverrides = new Dictionary<string, LogicalType>(); 22 | foreach (var testCol in testColumns) 23 | { 24 | var dataFrameCol = testCol.GetColumn(numRows); 25 | if (testCol.LogicalTypeOverride != null) 26 | { 27 | logicalTypeOverrides[dataFrameCol.Name] = testCol.LogicalTypeOverride; 28 | } 29 | 30 | columns.Add(dataFrameCol); 31 | } 32 | 33 | var dataFrame = new Microsoft.Data.Analysis.DataFrame(columns); 34 | 35 | using var dir = new UnitTestDisposableDirectory(); 36 | var filePath = Path.Combine(dir.Info.FullName, "test.parquet"); 37 | dataFrame.ToParquet(filePath, logicalTypeOverrides: logicalTypeOverrides); 38 | 39 | Assert.True(File.Exists(filePath)); 40 | 41 | using var fileReader = new ParquetFileReader(filePath); 42 | Assert.Equal(testColumns.Length, fileReader.FileMetaData.NumColumns); 43 | Assert.Equal(numRows, fileReader.FileMetaData.NumRows); 44 | 45 | long offset = 0; 46 | for (var rowGroupIdx = 0; rowGroupIdx < fileReader.FileMetaData.NumRowGroups; ++rowGroupIdx) 47 | { 48 | using var rowGroupReader = fileReader.RowGroup(rowGroupIdx); 49 | int colIdx = 0; 50 | foreach (var testCol in testColumns) 51 | { 52 | using var parquetCol = rowGroupReader.Column(colIdx++); 53 | using var logicalReader = parquetCol.LogicalReader(); 54 | testCol.VerifyData(logicalReader, offset); 55 | } 56 | 57 | offset += rowGroupReader.MetaData.NumRows; 58 | } 59 | } 60 | 61 | [Fact] 62 | public void TestToParquetWithMultipleRowGroups() 63 | { 64 | const int numRows = 10_000; 65 | const int rowGroupSize = 1024; 66 | var testColumns = GetTestColumns().Where(c => c.GetColumn(1).Name == "int32").ToArray(); 67 | Assert.Single(testColumns); 68 | 69 | var columns = new[] { testColumns[0].GetColumn(numRows) }; 70 | var dataFrame = new Microsoft.Data.Analysis.DataFrame(columns); 71 | using var dir = new UnitTestDisposableDirectory(); 72 | var filePath = Path.Combine(dir.Info.FullName, "test.parquet"); 73 | dataFrame.ToParquet(filePath, rowGroupSize: rowGroupSize); 74 | 75 | Assert.True(File.Exists(filePath)); 76 | 77 | using var fileReader = new ParquetFileReader(filePath); 78 | Assert.Equal(testColumns.Length, fileReader.FileMetaData.NumColumns); 79 | Assert.Equal(numRows, fileReader.FileMetaData.NumRows); 80 | 81 | Assert.Equal((numRows + rowGroupSize - 1) / rowGroupSize, fileReader.FileMetaData.NumRowGroups); 82 | 83 | long offset = 0; 84 | for (var rowGroupIdx = 0; rowGroupIdx < fileReader.FileMetaData.NumRowGroups; ++rowGroupIdx) 85 | { 86 | using var rowGroupReader = fileReader.RowGroup(rowGroupIdx); 87 | int colIdx = 0; 88 | foreach (var testCol in testColumns) 89 | { 90 | using var parquetCol = rowGroupReader.Column(colIdx++); 91 | using var logicalReader = parquetCol.LogicalReader(); 92 | testCol.VerifyData(logicalReader, offset); 93 | } 94 | 95 | offset += rowGroupReader.MetaData.NumRows; 96 | } 97 | } 98 | 99 | [Fact] 100 | public void TestCustomParquetWriterProperties() 101 | { 102 | int numRows = 10_000; 103 | var testColumns = GetTestColumns().Where(c => c.GetColumn(1).Name == "int32").ToArray(); 104 | Assert.Single(testColumns); 105 | 106 | using var dir = new UnitTestDisposableDirectory(); 107 | var filePath = Path.Combine(dir.Info.FullName, "test.parquet"); 108 | 109 | { 110 | var columns = new[] { testColumns[0].GetColumn(numRows) }; 111 | var dataFrame = new Microsoft.Data.Analysis.DataFrame(columns); 112 | 113 | using var propertiesBuilder = new WriterPropertiesBuilder(); 114 | propertiesBuilder.Compression(Compression.Gzip); 115 | using var properties = propertiesBuilder.Build(); 116 | 117 | dataFrame.ToParquet(filePath, properties); 118 | } 119 | 120 | Assert.True(File.Exists(filePath)); 121 | 122 | using var fileReader = new ParquetFileReader(filePath); 123 | Assert.Equal(testColumns.Length, fileReader.FileMetaData.NumColumns); 124 | Assert.Equal(numRows, fileReader.FileMetaData.NumRows); 125 | 126 | for (var rowGroupIdx = 0; rowGroupIdx < fileReader.FileMetaData.NumRowGroups; ++rowGroupIdx) 127 | { 128 | using var rowGroupReader = fileReader.RowGroup(rowGroupIdx); 129 | var columnMetadata = rowGroupReader.MetaData.GetColumnChunkMetaData(0); 130 | Assert.Equal(Compression.Gzip, columnMetadata.Compression); 131 | } 132 | } 133 | 134 | private struct TestColumn 135 | { 136 | public Func<int, DataFrameColumn> GetColumn { get; init; } 137 | 138 | public Action<LogicalColumnReader, long> VerifyData { get; init; } 139 | 140 | public LogicalType? LogicalTypeOverride { get; init; } 141 | } 142 | 143 | private static TestColumn[] GetTestColumns() 144 | { 145 | return new[] 146 | { 147 | new TestColumn 148 | { 149 | GetColumn = numRows => 150 | new ByteDataFrameColumn("uint8", Enumerable.Range(0, numRows).Select(i => (byte)(i % 256))), 151 | VerifyData = (reader, offset) => 152 | VerifyData(reader as LogicalColumnReader<byte>, offset, (i, elem) => Assert.Equal(i % 256, elem)), 153 | }, 154 | new TestColumn 155 | { 156 | GetColumn = numRows => 157 | new SByteDataFrameColumn("int8", Enumerable.Range(0, numRows).Select(i => (sbyte)(i % 256 - 128))), 158 | VerifyData = (reader, offset) => 159 | VerifyData(reader as LogicalColumnReader<sbyte>, offset, (i, elem) => Assert.Equal(i % 256 - 128, elem)), 160 | }, 161 | new TestColumn 162 | { 163 | GetColumn = numRows => 164 | new UInt16DataFrameColumn("uint16", Enumerable.Range(0, numRows).Select(i => (ushort)(i % ushort.MaxValue))), 165 | VerifyData = (reader, offset) => 166 | VerifyData(reader as LogicalColumnReader<ushort>, offset, (i, elem) => Assert.Equal(i % ushort.MaxValue, elem)), 167 | }, 168 | new TestColumn 169 | { 170 | GetColumn = numRows => 171 | new Int16DataFrameColumn("int16", Enumerable.Range(0, numRows).Select(i => (short)(i % short.MaxValue))), 172 | VerifyData = (reader, offset) => 173 | VerifyData(reader as LogicalColumnReader<short>, offset, (i, elem) => Assert.Equal(i % short.MaxValue, elem)), 174 | }, 175 | new TestColumn 176 | { 177 | GetColumn = numRows => 178 | new UInt32DataFrameColumn("uint32", Enumerable.Range(0, numRows).Select(i => (uint)i)), 179 | VerifyData = (reader, offset) => 180 | VerifyData(reader as LogicalColumnReader<uint>, offset, (i, elem) => Assert.Equal(i, elem)), 181 | }, 182 | new TestColumn 183 | { 184 | GetColumn = numRows => 185 | new Int32DataFrameColumn("int32", Enumerable.Range(0, numRows).Select(i => i)), 186 | VerifyData = (reader, offset) => 187 | VerifyData(reader as LogicalColumnReader<int>, offset, (i, elem) => Assert.Equal(i, elem)), 188 | }, 189 | new TestColumn 190 | { 191 | GetColumn = numRows => 192 | new Int32DataFrameColumn("nullable_int32", Enumerable.Range(0, numRows).Select(i => i % 10 == 0 ? (int?)null : i)), 193 | VerifyData = (reader, offset) => 194 | VerifyData(reader as LogicalColumnReader<int?>, offset, (i, elem) => Assert.Equal(i % 10 == 0 ? null : (int?)i, elem)), 195 | }, 196 | new TestColumn 197 | { 198 | GetColumn = numRows => 199 | new Int64DataFrameColumn("int64", Enumerable.Range(0, numRows).Select(i => (long)i)), 200 | VerifyData = (reader, offset) => 201 | VerifyData(reader as LogicalColumnReader<long>, offset, Assert.Equal), 202 | }, 203 | new TestColumn 204 | { 205 | GetColumn = numRows => 206 | new Int64DataFrameColumn("nullable_int64", Enumerable.Range(0, numRows).Select(i => i % 10 == 0 ? (long?)null : i)), 207 | VerifyData = (reader, offset) => 208 | VerifyData(reader as LogicalColumnReader<long?>, offset, (i, elem) => Assert.Equal(i % 10 == 0 ? null : (long?)i, elem)), 209 | }, 210 | new TestColumn 211 | { 212 | GetColumn = numRows => 213 | new SingleDataFrameColumn("float", Enumerable.Range(0, numRows).Select(i => (float)i)), 214 | VerifyData = (reader, offset) => 215 | VerifyData(reader as LogicalColumnReader<float>, offset, (i, elem) => Assert.Equal(i, elem)), 216 | }, 217 | new TestColumn 218 | { 219 | GetColumn = numRows => 220 | new SingleDataFrameColumn("nullable_float", Enumerable.Range(0, numRows).Select(i => i % 10 == 0 ? null : (float?)i)), 221 | VerifyData = (reader, offset) => 222 | VerifyData(reader as LogicalColumnReader<float?>, offset, (i, elem) => Assert.Equal(i % 10 == 0 ? null : (float?)i, elem)), 223 | }, 224 | new TestColumn 225 | { 226 | GetColumn = numRows => 227 | new DoubleDataFrameColumn("double", Enumerable.Range(0, numRows).Select(i => (double)i)), 228 | VerifyData = (reader, offset) => 229 | VerifyData(reader as LogicalColumnReader<double>, offset, (i, elem) => Assert.Equal(i, elem)), 230 | }, 231 | new TestColumn 232 | { 233 | GetColumn = numRows => 234 | new DoubleDataFrameColumn("nullable_double", Enumerable.Range(0, numRows).Select(i => i % 10 == 0 ? null : (double?)i)), 235 | VerifyData = (reader, offset) => 236 | VerifyData(reader as LogicalColumnReader<double?>, offset, (i, elem) => Assert.Equal(i % 10 == 0 ? null : (double?)i, elem)), 237 | }, 238 | new TestColumn 239 | { 240 | GetColumn = numRows => 241 | new BooleanDataFrameColumn("bool", Enumerable.Range(0, numRows).Select(i => i % 2 == 0)), 242 | VerifyData = (reader, offset) => 243 | VerifyData(reader as LogicalColumnReader<bool>, offset, (i, elem) => Assert.Equal(i % 2 == 0, elem)), 244 | }, 245 | new TestColumn 246 | { 247 | GetColumn = numRows => 248 | new BooleanDataFrameColumn("nullable_bool", Enumerable.Range(0, numRows).Select(i => i % 10 == 0 ? null : (bool?)(i % 2 == 0))), 249 | VerifyData = (reader, offset) => 250 | VerifyData(reader as LogicalColumnReader<bool?>, offset, (i, elem) => Assert.Equal(i % 10 == 0 ? null : (bool?)(i % 2 == 0), elem)), 251 | }, 252 | new TestColumn 253 | { 254 | GetColumn = numRows => 255 | new StringDataFrameColumn("string", Enumerable.Range(0, numRows).Select(i => i.ToString())), 256 | VerifyData = (reader, offset) => 257 | VerifyData(reader as LogicalColumnReader<string>, offset, (i, elem) => Assert.Equal(i.ToString(), elem)), 258 | }, 259 | new TestColumn 260 | { 261 | GetColumn = numRows => 262 | new PrimitiveDataFrameColumn<DateTime>("dateTime", Enumerable.Range(0, numRows).Select(i => new DateTime(2021, 12, 8) + TimeSpan.FromSeconds(i))), 263 | VerifyData = (reader, offset) => 264 | VerifyData(reader as LogicalColumnReader<DateTime>, offset, (i, elem) => Assert.Equal(new DateTime(2021, 12, 8) + TimeSpan.FromSeconds(i), elem)), 265 | }, 266 | new TestColumn 267 | { 268 | GetColumn = numRows => 269 | new PrimitiveDataFrameColumn<DateTime>("nullable_dateTime", Enumerable.Range(0, numRows).Select( 270 | i => i % 10 == 0 ? null : (DateTime?)(new DateTime(2021, 12, 8) + TimeSpan.FromSeconds(i)))), 271 | VerifyData = (reader, offset) => 272 | VerifyData(reader as LogicalColumnReader<DateTime?>, offset, (i, elem) => 273 | Assert.Equal(i % 10 == 0 ? null : (DateTime?)(new DateTime(2021, 12, 8) + TimeSpan.FromSeconds(i)), elem)), 274 | }, 275 | new TestColumn 276 | { 277 | GetColumn = numRows => 278 | new PrimitiveDataFrameColumn<TimeSpan>("timeSpan", Enumerable.Range(0, numRows).Select(i => TimeSpan.FromMilliseconds(i))), 279 | VerifyData = (reader, offset) => 280 | VerifyData(reader as LogicalColumnReader<TimeSpan>, offset, (i, elem) => Assert.Equal(TimeSpan.FromMilliseconds(i), elem)), 281 | }, 282 | new TestColumn 283 | { 284 | GetColumn = numRows => 285 | new PrimitiveDataFrameColumn<TimeSpan>("nullable_timeSpan", Enumerable.Range(0, numRows).Select( 286 | i => i % 10 == 0 ? null : (TimeSpan?)TimeSpan.FromMilliseconds(i))), 287 | VerifyData = (reader, offset) => 288 | VerifyData(reader as LogicalColumnReader<TimeSpan?>, offset, (i, elem) => Assert.Equal( 289 | i % 10 == 0 ? null : (TimeSpan?)TimeSpan.FromMilliseconds(i), elem)), 290 | }, 291 | new TestColumn 292 | { 293 | GetColumn = numRows => 294 | new PrimitiveDataFrameColumn<Date>("date", Enumerable.Range(0, numRows).Select(i => new Date(i))), 295 | VerifyData = (reader, offset) => 296 | VerifyData(reader as LogicalColumnReader<Date>, offset, (i, elem) => Assert.Equal(new Date((int)i), elem)), 297 | }, 298 | new TestColumn 299 | { 300 | GetColumn = numRows => 301 | new PrimitiveDataFrameColumn<Date>("nullable_date", Enumerable.Range(0, numRows).Select(i => i % 10 == 0 ? null : (Date?)new Date(i))), 302 | VerifyData = (reader, offset) => 303 | VerifyData(reader as LogicalColumnReader<Date?>, offset, (i, elem) => Assert.Equal(i % 10 == 0 ? null : (Date?)new Date((int)i), elem)), 304 | }, 305 | new TestColumn 306 | { 307 | GetColumn = numRows => 308 | new PrimitiveDataFrameColumn<DateTimeNanos>("dateTimeNanos", Enumerable.Range(0, numRows).Select(i => new DateTimeNanos(i))), 309 | VerifyData = (reader, offset) => 310 | VerifyData(reader as LogicalColumnReader<DateTimeNanos>, offset, (i, elem) => Assert.Equal(new DateTimeNanos(i), elem)), 311 | }, 312 | new TestColumn 313 | { 314 | GetColumn = numRows => 315 | new PrimitiveDataFrameColumn<DateTimeNanos>("nullable_dateTimeNanos", Enumerable.Range(0, numRows).Select( 316 | i => i % 10 == 0 ? null : (DateTimeNanos?)new DateTimeNanos(i))), 317 | VerifyData = (reader, offset) => 318 | VerifyData(reader as LogicalColumnReader<DateTimeNanos?>, offset, (i, elem) => Assert.Equal( 319 | i % 10 == 0 ? null : (DateTimeNanos?)new DateTimeNanos(i), elem)), 320 | }, 321 | new TestColumn 322 | { 323 | GetColumn = numRows => 324 | new PrimitiveDataFrameColumn<TimeSpanNanos>("timeSpanNanos", Enumerable.Range(0, numRows).Select(i => new TimeSpanNanos(i))), 325 | VerifyData = (reader, offset) => 326 | VerifyData(reader as LogicalColumnReader<TimeSpanNanos>, offset, (i, elem) => Assert.Equal(new TimeSpanNanos(i), elem)), 327 | }, 328 | new TestColumn 329 | { 330 | GetColumn = numRows => 331 | new PrimitiveDataFrameColumn<TimeSpanNanos>("nullable_timeSpanNanos", Enumerable.Range(0, numRows).Select( 332 | i => i % 10 == 0 ? null : (TimeSpanNanos?)new TimeSpanNanos(i))), 333 | VerifyData = (reader, offset) => 334 | VerifyData(reader as LogicalColumnReader<TimeSpanNanos?>, offset, (i, elem) => Assert.Equal( 335 | i % 10 == 0 ? null : (TimeSpanNanos?)new TimeSpanNanos(i), elem)), 336 | }, 337 | new TestColumn 338 | { 339 | GetColumn = numRows => 340 | new DecimalDataFrameColumn("decimal", Enumerable.Range(0, numRows).Select(i => new decimal(i) / 100)), 341 | VerifyData = (reader, offset) => 342 | VerifyData(reader as LogicalColumnReader<decimal>, offset, (i, elem) => Assert.Equal(new decimal(i) / 100, elem)), 343 | LogicalTypeOverride = LogicalType.Decimal(29, 3), 344 | }, 345 | new TestColumn 346 | { 347 | GetColumn = numRows => 348 | new DecimalDataFrameColumn("nullable_decimal", Enumerable.Range(0, numRows).Select( 349 | i => i % 10 == 0 ? null : (decimal?)(new decimal(i) / 100))), 350 | VerifyData = (reader, offset) => 351 | VerifyData(reader as LogicalColumnReader<decimal?>, offset, (i, elem) => Assert.Equal( 352 | i % 10 == 0 ? null : (decimal?)(new decimal(i) / 100), elem)), 353 | LogicalTypeOverride = LogicalType.Decimal(29, 3), 354 | }, 355 | new TestColumn 356 | { 357 | GetColumn = numRows => 358 | new Int32DataFrameColumn("int_as_byte", Enumerable.Range(0, numRows).Select(i => i % 256)), 359 | VerifyData = (reader, offset) => 360 | VerifyData(reader as LogicalColumnReader<byte>, offset, (i, elem) => Assert.Equal(i % 256, elem)), 361 | LogicalTypeOverride = LogicalType.Int(8, false), 362 | }, 363 | new TestColumn 364 | { 365 | GetColumn = numRows => 366 | new Int32DataFrameColumn("int_as_date", Enumerable.Range(0, numRows).Select(i => i)), 367 | VerifyData = (reader, offset) => 368 | VerifyData(reader as LogicalColumnReader<Date>, offset, (i, elem) => Assert.Equal(new Date(1970, 1, 1).AddDays((int)i), elem)), 369 | LogicalTypeOverride = LogicalType.Date(), 370 | }, 371 | new TestColumn 372 | { 373 | GetColumn = numRows => 374 | new Int32DataFrameColumn("int_as_time", Enumerable.Range(0, numRows).Select(i => i)), 375 | VerifyData = (reader, offset) => 376 | VerifyData(reader as LogicalColumnReader<TimeSpan>, offset, (i, elem) => Assert.Equal(TimeSpan.FromMilliseconds(i), elem)), 377 | LogicalTypeOverride = LogicalType.Time(isAdjustedToUtc: true, TimeUnit.Millis), 378 | }, 379 | }; 380 | } 381 | 382 | private static void VerifyData<TElement>( 383 | LogicalColumnReader<TElement>? columnReader, long offset, Action<long, TElement> verifier) 384 | { 385 | Assert.NotNull(columnReader); 386 | var buffer = new TElement[columnReader!.BufferLength]; 387 | long readerOffset = 0; 388 | while (columnReader.HasNext) 389 | { 390 | var read = columnReader.ReadBatch((Span<TElement>)buffer); 391 | for (int i = 0; i < read; ++i) 392 | { 393 | verifier(offset + readerOffset + i, buffer[i]); 394 | } 395 | 396 | readerOffset += read; 397 | } 398 | } 399 | } 400 | } 401 | -------------------------------------------------------------------------------- /ParquetSharp.DataFrame.Test/IsExternalInit.cs: -------------------------------------------------------------------------------- 1 | // ReSharper disable once CheckNamespace 2 | 3 | namespace System.Runtime.CompilerServices 4 | { 5 | // Needed to support init setters for dotnet < 5.0 6 | internal static class IsExternalInit 7 | { 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /ParquetSharp.DataFrame.Test/ParquetSharp.DataFrame.Test.csproj: -------------------------------------------------------------------------------- 1 | <Project Sdk="Microsoft.NET.Sdk"> 2 | 3 | <PropertyGroup> 4 | <TargetFrameworks>netcoreapp3.1;net6.0;net7.0</TargetFrameworks> 5 | <TargetFrameworks Condition="'$(OS)'=='Windows_NT'">$(TargetFrameworks);net472</TargetFrameworks> 6 | <LangVersion>9.0</LangVersion> 7 | <Nullable>enable</Nullable> 8 | <AssemblyName>ParquetSharp.DataFrame.Test</AssemblyName> 9 | <RootNamespace>ParquetSharp.DataFrame.Test</RootNamespace> 10 | <IsPackable>false</IsPackable> 11 | <TreatWarningsAsErrors>true</TreatWarningsAsErrors> 12 | <PlatformTarget Condition="'$(TargetFramework)'=='net472'">x64</PlatformTarget> 13 | </PropertyGroup> 14 | 15 | <ItemGroup> 16 | <PackageReference Include="Microsoft.Data.Analysis" Version="0.20.1" /> 17 | <PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.7.1" /> 18 | <PackageReference Include="ParquetSharp" Version="5.0.0" /> 19 | <PackageReference Include="xunit" Version="2.4.1" /> 20 | <PackageReference Include="xunit.runner.visualstudio" Version="2.4.3"> 21 | <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> 22 | <PrivateAssets>all</PrivateAssets> 23 | </PackageReference> 24 | </ItemGroup> 25 | 26 | <ItemGroup> 27 | <ProjectReference Include="..\ParquetSharp.DataFrame\ParquetSharp.DataFrame.csproj" /> 28 | </ItemGroup> 29 | 30 | </Project> 31 | -------------------------------------------------------------------------------- /ParquetSharp.DataFrame.Test/ParquetToDataFrame.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | using Microsoft.Data.Analysis; 4 | using ParquetSharp.IO; 5 | using Xunit; 6 | 7 | namespace ParquetSharp.DataFrame.Test 8 | { 9 | /// <summary> 10 | /// Test reading Parquet data into a DataFrame 11 | /// </summary> 12 | public class ParquetToDataFrame 13 | { 14 | [Fact] 15 | public void TestToDataFrame() 16 | { 17 | var testColumns = GetTestColumns(); 18 | const int numRows = 10_000; 19 | 20 | using var buffer = new ResizableBuffer(); 21 | using (var output = new BufferOutputStream(buffer)) 22 | { 23 | var columns = testColumns.Select(c => c.ParquetColumn).ToArray(); 24 | using var fileWriter = new ParquetFileWriter(output, columns); 25 | using var rowGroupWriter = fileWriter.AppendRowGroup(); 26 | 27 | foreach (var column in testColumns) 28 | { 29 | column.WriteColumn(numRows, rowGroupWriter.NextColumn()); 30 | } 31 | 32 | fileWriter.Close(); 33 | } 34 | 35 | using (var input = new BufferReader(buffer)) 36 | { 37 | using var fileReader = new ParquetFileReader(input); 38 | var dataFrame = fileReader.ToDataFrame(); 39 | 40 | Assert.Equal(testColumns.Length, dataFrame.Columns.Count); 41 | 42 | foreach (var column in testColumns) 43 | { 44 | var dataFrameColumn = dataFrame[column.ParquetColumn.Name]; 45 | Assert.IsType(column.ExpectedColumnType, dataFrameColumn); 46 | Assert.Equal(numRows, dataFrameColumn.Length); 47 | Assert.Equal(column.NullCount?.Invoke(numRows) ?? 0, dataFrameColumn.NullCount); 48 | column.VerifyColumn(dataFrameColumn); 49 | } 50 | 51 | fileReader.Close(); 52 | } 53 | } 54 | 55 | [Fact] 56 | public void TestSpecifyingColumnsToRead() 57 | { 58 | var testColumns = GetTestColumns(); 59 | const int numRows = 10_000; 60 | 61 | using var buffer = new ResizableBuffer(); 62 | using (var output = new BufferOutputStream(buffer)) 63 | { 64 | var columns = testColumns.Select(c => c.ParquetColumn).ToArray(); 65 | using var fileWriter = new ParquetFileWriter(output, columns); 66 | using var rowGroupWriter = fileWriter.AppendRowGroup(); 67 | 68 | foreach (var column in testColumns) 69 | { 70 | column.WriteColumn(numRows, rowGroupWriter.NextColumn()); 71 | } 72 | 73 | fileWriter.Close(); 74 | } 75 | 76 | var columnNames = new[] { "int", "nullable_bool", "float" }; 77 | 78 | using (var input = new BufferReader(buffer)) 79 | { 80 | using var fileReader = new ParquetFileReader(input); 81 | 82 | var dataFrame = fileReader.ToDataFrame(columns: columnNames); 83 | 84 | Assert.Equal(columnNames.Length, dataFrame.Columns.Count); 85 | 86 | foreach (var column in testColumns.Where(c => columnNames.Contains(c.ParquetColumn.Name))) 87 | { 88 | var dataFrameColumn = dataFrame[column.ParquetColumn.Name]; 89 | Assert.IsType(column.ExpectedColumnType, dataFrameColumn); 90 | Assert.Equal(numRows, dataFrameColumn.Length); 91 | Assert.Equal(column.NullCount?.Invoke(numRows) ?? 0, dataFrameColumn.NullCount); 92 | column.VerifyColumn(dataFrameColumn); 93 | } 94 | 95 | fileReader.Close(); 96 | } 97 | } 98 | 99 | [Fact] 100 | public void TestSpecifyingRowGroupsToRead() 101 | { 102 | const int rowsPerRowGroup = 1024; 103 | const int numRowGroups = 10; 104 | 105 | using var buffer = new ResizableBuffer(); 106 | using (var output = new BufferOutputStream(buffer)) 107 | { 108 | var columns = new Column[] { new Column<int>("col") }; 109 | using var fileWriter = new ParquetFileWriter(output, columns); 110 | 111 | for (var rowGroupIdx = 0; rowGroupIdx < numRowGroups; ++rowGroupIdx) 112 | { 113 | using var rowGroupWriter = fileWriter.AppendRowGroup(); 114 | using var logicalWriter = rowGroupWriter.NextColumn().LogicalWriter<int>(); 115 | logicalWriter.WriteBatch(Enumerable.Range(0, rowsPerRowGroup).Select(i => rowGroupIdx * rowsPerRowGroup + i).ToArray()); 116 | } 117 | 118 | fileWriter.Close(); 119 | } 120 | 121 | using (var input = new BufferReader(buffer)) 122 | { 123 | using var fileReader = new ParquetFileReader(input); 124 | // Specify a subset of row groups out of order 125 | var rowGroupIndices = new[] { 1, 6, 3, 4 }; 126 | var dataFrame = fileReader.ToDataFrame(rowGroupIndices: rowGroupIndices); 127 | fileReader.Close(); 128 | 129 | var column = dataFrame["col"]; 130 | Assert.Equal(rowsPerRowGroup * rowGroupIndices.Length, column.Length); 131 | for (var i = 0; i < column.Length; ++i) 132 | { 133 | var rowGroupIndex = rowGroupIndices[i / rowsPerRowGroup]; 134 | var expectedVal = rowGroupIndex * rowsPerRowGroup + i % rowsPerRowGroup; 135 | Assert.Equal(expectedVal, column[i]); 136 | } 137 | } 138 | } 139 | 140 | [Fact] 141 | public void ThrowsOnInvalidColumnName() 142 | { 143 | var testColumns = GetTestColumns(); 144 | const int numRows = 10_000; 145 | 146 | using var buffer = new ResizableBuffer(); 147 | using (var output = new BufferOutputStream(buffer)) 148 | { 149 | var columns = testColumns.Select(c => c.ParquetColumn).ToArray(); 150 | using var fileWriter = new ParquetFileWriter(output, columns); 151 | using var rowGroupWriter = fileWriter.AppendRowGroup(); 152 | 153 | foreach (var column in testColumns) 154 | { 155 | column.WriteColumn(numRows, rowGroupWriter.NextColumn()); 156 | } 157 | 158 | fileWriter.Close(); 159 | } 160 | 161 | var columnNames = new[] { "does_not_exist" }; 162 | 163 | using (var input = new BufferReader(buffer)) 164 | { 165 | using var fileReader = new ParquetFileReader(input); 166 | 167 | var exception = Assert.Throws<ArgumentException>(() => fileReader.ToDataFrame(columns: columnNames)); 168 | Assert.Contains("does_not_exist", exception.Message); 169 | } 170 | } 171 | 172 | private struct TestColumn 173 | { 174 | public Column ParquetColumn { get; init; } 175 | public Type ExpectedColumnType { get; init; } 176 | public Action<int, ColumnWriter> WriteColumn { get; init; } 177 | public Action<DataFrameColumn> VerifyColumn { get; init; } 178 | public Func<long, long>? NullCount { get; init; } 179 | } 180 | 181 | private static TestColumn[] GetTestColumns() 182 | { 183 | return new[] 184 | { 185 | new TestColumn 186 | { 187 | ParquetColumn = new Column<byte>("uint8"), 188 | ExpectedColumnType = typeof(ByteDataFrameColumn), 189 | WriteColumn = (numRows, columnWriter) => 190 | { 191 | using var logicalWriter = columnWriter.LogicalWriter<byte>(); 192 | logicalWriter.WriteBatch(Enumerable.Range(0, numRows).Select(i => (byte)(i % 256)).ToArray()); 193 | }, 194 | VerifyColumn = column => 195 | { 196 | for (int i = 0; i < column.Length; ++i) 197 | { 198 | Assert.Equal((byte)(i % 256), column[i]); 199 | } 200 | } 201 | }, 202 | new TestColumn 203 | { 204 | ParquetColumn = new Column<sbyte>("int8"), 205 | ExpectedColumnType = typeof(SByteDataFrameColumn), 206 | WriteColumn = (numRows, columnWriter) => 207 | { 208 | using var logicalWriter = columnWriter.LogicalWriter<sbyte>(); 209 | logicalWriter.WriteBatch(Enumerable.Range(0, numRows).Select(i => (sbyte)(i % 256 - 128)).ToArray()); 210 | }, 211 | VerifyColumn = column => 212 | { 213 | for (int i = 0; i < column.Length; ++i) 214 | { 215 | Assert.Equal((sbyte)(i % 256 - 128), column[i]); 216 | } 217 | } 218 | }, 219 | new TestColumn 220 | { 221 | ParquetColumn = new Column<ushort>("uint16"), 222 | ExpectedColumnType = typeof(UInt16DataFrameColumn), 223 | WriteColumn = (numRows, columnWriter) => 224 | { 225 | using var logicalWriter = columnWriter.LogicalWriter<ushort>(); 226 | logicalWriter.WriteBatch(Enumerable.Range(0, numRows).Select(i => (ushort)(i % ushort.MaxValue)).ToArray()); 227 | }, 228 | VerifyColumn = column => 229 | { 230 | for (int i = 0; i < column.Length; ++i) 231 | { 232 | Assert.Equal((ushort)(i % ushort.MaxValue), column[i]); 233 | } 234 | } 235 | }, 236 | new TestColumn 237 | { 238 | ParquetColumn = new Column<short>("int16"), 239 | ExpectedColumnType = typeof(Int16DataFrameColumn), 240 | WriteColumn = (numRows, columnWriter) => 241 | { 242 | using var logicalWriter = columnWriter.LogicalWriter<short>(); 243 | logicalWriter.WriteBatch(Enumerable.Range(0, numRows).Select(i => (short)(i % short.MaxValue)).ToArray()); 244 | }, 245 | VerifyColumn = column => 246 | { 247 | for (int i = 0; i < column.Length; ++i) 248 | { 249 | Assert.Equal((short)(i % short.MaxValue), column[i]); 250 | } 251 | } 252 | }, 253 | new TestColumn 254 | { 255 | ParquetColumn = new Column<int>("int"), 256 | ExpectedColumnType = typeof(Int32DataFrameColumn), 257 | WriteColumn = (numRows, columnWriter) => 258 | { 259 | using var logicalWriter = columnWriter.LogicalWriter<int>(); 260 | logicalWriter.WriteBatch(Enumerable.Range(0, numRows).ToArray()); 261 | }, 262 | VerifyColumn = column => 263 | { 264 | for (int i = 0; i < column.Length; ++i) 265 | { 266 | Assert.Equal(i, column[i]); 267 | } 268 | } 269 | }, 270 | new TestColumn 271 | { 272 | ParquetColumn = new Column<int?>("nullable_int"), 273 | ExpectedColumnType = typeof(Int32DataFrameColumn), 274 | WriteColumn = (numRows, columnWriter) => 275 | { 276 | using var logicalWriter = columnWriter.LogicalWriter<int?>(); 277 | logicalWriter.WriteBatch(Enumerable.Range(0, numRows).Select(i => i % 10 == 0 ? (int?)null : i).ToArray()); 278 | }, 279 | VerifyColumn = column => 280 | { 281 | for (int i = 0; i < column.Length; ++i) 282 | { 283 | Assert.Equal(i % 10 == 0 ? null : (int?)i, column[i]); 284 | } 285 | }, 286 | NullCount = numRows => numRows / 10, 287 | }, 288 | new TestColumn 289 | { 290 | ParquetColumn = new Column<long>("long"), 291 | ExpectedColumnType = typeof(Int64DataFrameColumn), 292 | WriteColumn = (numRows, columnWriter) => 293 | { 294 | using var logicalWriter = columnWriter.LogicalWriter<long>(); 295 | logicalWriter.WriteBatch(Enumerable.Range(0, numRows).Select(i => (long)i).ToArray()); 296 | }, 297 | VerifyColumn = column => 298 | { 299 | for (int i = 0; i < column.Length; ++i) 300 | { 301 | Assert.Equal((long)i, column[i]); 302 | } 303 | } 304 | }, 305 | new TestColumn 306 | { 307 | ParquetColumn = new Column<long?>("nullable_long"), 308 | ExpectedColumnType = typeof(Int64DataFrameColumn), 309 | WriteColumn = (numRows, columnWriter) => 310 | { 311 | using var logicalWriter = columnWriter.LogicalWriter<long?>(); 312 | logicalWriter.WriteBatch(Enumerable.Range(0, numRows).Select(i => i % 10 == 0 ? (long?)null : i).ToArray()); 313 | }, 314 | VerifyColumn = column => 315 | { 316 | for (long i = 0; i < column.Length; ++i) 317 | { 318 | Assert.Equal(i % 10 == 0 ? null : (long?)i, column[i]); 319 | } 320 | }, 321 | NullCount = numRows => numRows / 10, 322 | }, 323 | new TestColumn 324 | { 325 | ParquetColumn = new Column<float>("float"), 326 | ExpectedColumnType = typeof(SingleDataFrameColumn), 327 | WriteColumn = (numRows, columnWriter) => 328 | { 329 | using var logicalWriter = columnWriter.LogicalWriter<float>(); 330 | logicalWriter.WriteBatch(Enumerable.Range(0, numRows).Select(i => (float)i).ToArray()); 331 | }, 332 | VerifyColumn = column => 333 | { 334 | for (int i = 0; i < column.Length; ++i) 335 | { 336 | Assert.Equal((float)i, column[i]); 337 | } 338 | } 339 | }, 340 | new TestColumn 341 | { 342 | ParquetColumn = new Column<float?>("nullable_float"), 343 | ExpectedColumnType = typeof(SingleDataFrameColumn), 344 | WriteColumn = (numRows, columnWriter) => 345 | { 346 | using var logicalWriter = columnWriter.LogicalWriter<float?>(); 347 | logicalWriter.WriteBatch(Enumerable.Range(0, numRows).Select(i => i % 10 == 0 ? (float?)null : i).ToArray()); 348 | }, 349 | VerifyColumn = column => 350 | { 351 | for (int i = 0; i < column.Length; ++i) 352 | { 353 | Assert.Equal(i % 10 == 0 ? null : (float?)i, column[i]); 354 | } 355 | }, 356 | NullCount = numRows => numRows / 10, 357 | }, 358 | new TestColumn 359 | { 360 | ParquetColumn = new Column<double>("double"), 361 | ExpectedColumnType = typeof(DoubleDataFrameColumn), 362 | WriteColumn = (numRows, columnWriter) => 363 | { 364 | using var logicalWriter = columnWriter.LogicalWriter<double>(); 365 | logicalWriter.WriteBatch(Enumerable.Range(0, numRows).Select(i => (double)i).ToArray()); 366 | }, 367 | VerifyColumn = column => 368 | { 369 | for (int i = 0; i < column.Length; ++i) 370 | { 371 | Assert.Equal((double)i, column[i]); 372 | } 373 | } 374 | }, 375 | new TestColumn 376 | { 377 | ParquetColumn = new Column<double?>("nullable_double"), 378 | ExpectedColumnType = typeof(DoubleDataFrameColumn), 379 | WriteColumn = (numRows, columnWriter) => 380 | { 381 | using var logicalWriter = columnWriter.LogicalWriter<double?>(); 382 | logicalWriter.WriteBatch(Enumerable.Range(0, numRows).Select(i => i % 10 == 0 ? (double?)null : i).ToArray()); 383 | }, 384 | VerifyColumn = column => 385 | { 386 | for (int i = 0; i < column.Length; ++i) 387 | { 388 | Assert.Equal(i % 10 == 0 ? null : (double?)i, column[i]); 389 | } 390 | }, 391 | NullCount = numRows => numRows / 10, 392 | }, 393 | new TestColumn 394 | { 395 | ParquetColumn = new Column<string>("string"), 396 | ExpectedColumnType = typeof(StringDataFrameColumn), 397 | WriteColumn = (numRows, columnWriter) => 398 | { 399 | using var logicalWriter = columnWriter.LogicalWriter<string>(); 400 | logicalWriter.WriteBatch(Enumerable.Range(0, numRows).Select(i => i.ToString()).ToArray()); 401 | }, 402 | VerifyColumn = column => 403 | { 404 | for (int i = 0; i < column.Length; ++i) 405 | { 406 | Assert.Equal(i.ToString(), column[i]); 407 | } 408 | } 409 | }, 410 | new TestColumn 411 | { 412 | ParquetColumn = new Column<bool>("bool"), 413 | ExpectedColumnType = typeof(BooleanDataFrameColumn), 414 | WriteColumn = (numRows, columnWriter) => 415 | { 416 | using var logicalWriter = columnWriter.LogicalWriter<bool>(); 417 | logicalWriter.WriteBatch(Enumerable.Range(0, numRows).Select(i => i % 2 == 0).ToArray()); 418 | }, 419 | VerifyColumn = column => 420 | { 421 | for (int i = 0; i < column.Length; ++i) 422 | { 423 | Assert.Equal(i % 2 == 0, column[i]); 424 | } 425 | } 426 | }, 427 | new TestColumn 428 | { 429 | ParquetColumn = new Column<bool?>("nullable_bool"), 430 | ExpectedColumnType = typeof(BooleanDataFrameColumn), 431 | WriteColumn = (numRows, columnWriter) => 432 | { 433 | using var logicalWriter = columnWriter.LogicalWriter<bool?>(); 434 | logicalWriter.WriteBatch(Enumerable.Range(0, numRows).Select(i => i % 10 == 0 ? (bool?)null : (i % 2 == 0)).ToArray()); 435 | }, 436 | VerifyColumn = column => 437 | { 438 | for (int i = 0; i < column.Length; ++i) 439 | { 440 | Assert.Equal(i % 10 == 0 ? null : (bool?)(i % 2 == 0), column[i]); 441 | } 442 | }, 443 | NullCount = numRows => numRows / 10, 444 | }, 445 | new TestColumn 446 | { 447 | ParquetColumn = new Column<DateTime>("dateTime"), 448 | ExpectedColumnType = typeof(DateTimeDataFrameColumn), 449 | WriteColumn = (numRows, columnWriter) => 450 | { 451 | using var logicalWriter = columnWriter.LogicalWriter<DateTime>(); 452 | logicalWriter.WriteBatch( 453 | Enumerable.Range(0, numRows) 454 | .Select(i => new DateTime(2021, 12, 8) + TimeSpan.FromSeconds(i)).ToArray()); 455 | }, 456 | VerifyColumn = column => 457 | { 458 | for (int i = 0; i < column.Length; ++i) 459 | { 460 | Assert.Equal(new DateTime(2021, 12, 8) + TimeSpan.FromSeconds(i), column[i]); 461 | } 462 | } 463 | }, 464 | new TestColumn 465 | { 466 | ParquetColumn = new Column<DateTime?>("nullable_dateTime"), 467 | ExpectedColumnType = typeof(DateTimeDataFrameColumn), 468 | WriteColumn = (numRows, columnWriter) => 469 | { 470 | using var logicalWriter = columnWriter.LogicalWriter<DateTime?>(); 471 | logicalWriter.WriteBatch( 472 | Enumerable.Range(0, numRows) 473 | .Select(i => i % 10 == 0 ? (DateTime?)null : new DateTime(2021, 12, 8) + TimeSpan.FromSeconds(i)).ToArray()); 474 | }, 475 | VerifyColumn = column => 476 | { 477 | for (int i = 0; i < column.Length; ++i) 478 | { 479 | Assert.Equal(i % 10 == 0 ? null : (DateTime?)new DateTime(2021, 12, 8) + TimeSpan.FromSeconds(i), column[i]); 480 | } 481 | }, 482 | NullCount = numRows => numRows / 10, 483 | }, 484 | new TestColumn 485 | { 486 | ParquetColumn = new Column<DateTimeNanos>("dateTimeNanos"), 487 | ExpectedColumnType = typeof(PrimitiveDataFrameColumn<DateTimeNanos>), 488 | WriteColumn = (numRows, columnWriter) => 489 | { 490 | using var logicalWriter = columnWriter.LogicalWriter<DateTimeNanos>(); 491 | logicalWriter.WriteBatch( 492 | Enumerable.Range(0, numRows) 493 | .Select(i => new DateTimeNanos(i)).ToArray()); 494 | }, 495 | VerifyColumn = column => 496 | { 497 | for (int i = 0; i < column.Length; ++i) 498 | { 499 | Assert.Equal(new DateTimeNanos(i), column[i]); 500 | } 501 | } 502 | }, 503 | new TestColumn 504 | { 505 | ParquetColumn = new Column<DateTimeNanos?>("nullable_dateTimeNanos"), 506 | ExpectedColumnType = typeof(PrimitiveDataFrameColumn<DateTimeNanos>), 507 | WriteColumn = (numRows, columnWriter) => 508 | { 509 | using var logicalWriter = columnWriter.LogicalWriter<DateTimeNanos?>(); 510 | logicalWriter.WriteBatch( 511 | Enumerable.Range(0, numRows) 512 | .Select(i => (DateTimeNanos?)new DateTimeNanos(i)).ToArray()); 513 | }, 514 | VerifyColumn = column => 515 | { 516 | for (int i = 0; i < column.Length; ++i) 517 | { 518 | Assert.Equal(new DateTimeNanos(i), column[i]); 519 | } 520 | } 521 | }, 522 | new TestColumn 523 | { 524 | ParquetColumn = new Column<decimal>("decimal", LogicalType.Decimal(29, 3)), 525 | ExpectedColumnType = typeof(DecimalDataFrameColumn), 526 | WriteColumn = (numRows, columnWriter) => 527 | { 528 | using var logicalWriter = columnWriter.LogicalWriter<decimal>(); 529 | logicalWriter.WriteBatch(Enumerable.Range(0, numRows) 530 | .Select(i => new decimal(i) / 100).ToArray()); 531 | }, 532 | VerifyColumn = column => 533 | { 534 | for (int i = 0; i < column.Length; ++i) 535 | { 536 | Assert.Equal(new decimal(i) / 100, column[i]); 537 | } 538 | } 539 | }, 540 | new TestColumn 541 | { 542 | ParquetColumn = new Column<decimal?>("nullable_decimal", LogicalType.Decimal(29, 3)), 543 | ExpectedColumnType = typeof(DecimalDataFrameColumn), 544 | WriteColumn = (numRows, columnWriter) => 545 | { 546 | using var logicalWriter = columnWriter.LogicalWriter<decimal?>(); 547 | logicalWriter.WriteBatch(Enumerable.Range(0, numRows) 548 | .Select(i => i % 10 == 0 ? (decimal?)null : new decimal(i) / 100).ToArray()); 549 | }, 550 | VerifyColumn = column => 551 | { 552 | for (int i = 0; i < column.Length; ++i) 553 | { 554 | Assert.Equal(i % 10 == 0 ? null : (decimal?)new decimal(i) / 100, column[i]); 555 | } 556 | }, 557 | NullCount = numRows => numRows / 10, 558 | }, 559 | new TestColumn 560 | { 561 | ParquetColumn = new Column<Date>("date"), 562 | ExpectedColumnType = typeof(PrimitiveDataFrameColumn<Date>), 563 | WriteColumn = (numRows, columnWriter) => 564 | { 565 | using var logicalWriter = columnWriter.LogicalWriter<Date>(); 566 | logicalWriter.WriteBatch(Enumerable.Range(0, numRows).Select(i => new Date(i)).ToArray()); 567 | }, 568 | VerifyColumn = column => 569 | { 570 | for (int i = 0; i < column.Length; ++i) 571 | { 572 | Assert.Equal(new Date(i), column[i]); 573 | } 574 | } 575 | }, 576 | new TestColumn 577 | { 578 | ParquetColumn = new Column<Date?>("nullable_date"), 579 | ExpectedColumnType = typeof(PrimitiveDataFrameColumn<Date>), 580 | WriteColumn = (numRows, columnWriter) => 581 | { 582 | using var logicalWriter = columnWriter.LogicalWriter<Date?>(); 583 | logicalWriter.WriteBatch(Enumerable.Range(0, numRows).Select(i => (Date?)new Date(i)).ToArray()); 584 | }, 585 | VerifyColumn = column => 586 | { 587 | for (int i = 0; i < column.Length; ++i) 588 | { 589 | Assert.Equal(new Date(i), column[i]); 590 | } 591 | } 592 | }, 593 | new TestColumn 594 | { 595 | ParquetColumn = new Column<TimeSpan>("time_ms", LogicalType.Time(isAdjustedToUtc: true, TimeUnit.Millis)), 596 | ExpectedColumnType = typeof(PrimitiveDataFrameColumn<TimeSpan>), 597 | WriteColumn = (numRows, columnWriter) => 598 | { 599 | using var logicalWriter = columnWriter.LogicalWriter<TimeSpan>(); 600 | logicalWriter.WriteBatch(Enumerable.Range(0, numRows).Select(i => TimeSpan.FromMilliseconds(i)).ToArray()); 601 | }, 602 | VerifyColumn = column => 603 | { 604 | for (int i = 0; i < column.Length; ++i) 605 | { 606 | Assert.Equal(TimeSpan.FromMilliseconds(i), column[i]); 607 | } 608 | } 609 | }, 610 | new TestColumn 611 | { 612 | ParquetColumn = new Column<TimeSpan>("time_us", LogicalType.Time(isAdjustedToUtc: true, TimeUnit.Micros)), 613 | ExpectedColumnType = typeof(PrimitiveDataFrameColumn<TimeSpan>), 614 | WriteColumn = (numRows, columnWriter) => 615 | { 616 | using var logicalWriter = columnWriter.LogicalWriter<TimeSpan>(); 617 | logicalWriter.WriteBatch(Enumerable.Range(0, numRows).Select(i => TimeSpan.FromMilliseconds(i)).ToArray()); 618 | }, 619 | VerifyColumn = column => 620 | { 621 | for (int i = 0; i < column.Length; ++i) 622 | { 623 | Assert.Equal(TimeSpan.FromMilliseconds(i), column[i]); 624 | } 625 | } 626 | }, 627 | new TestColumn 628 | { 629 | ParquetColumn = new Column<TimeSpan?>("nullable_time_us", LogicalType.Time(isAdjustedToUtc: true, TimeUnit.Micros)), 630 | ExpectedColumnType = typeof(PrimitiveDataFrameColumn<TimeSpan>), 631 | WriteColumn = (numRows, columnWriter) => 632 | { 633 | using var logicalWriter = columnWriter.LogicalWriter<TimeSpan?>(); 634 | logicalWriter.WriteBatch(Enumerable.Range(0, numRows).Select(i => (TimeSpan?)TimeSpan.FromMilliseconds(i)).ToArray()); 635 | }, 636 | VerifyColumn = column => 637 | { 638 | for (int i = 0; i < column.Length; ++i) 639 | { 640 | Assert.Equal(TimeSpan.FromMilliseconds(i), column[i]); 641 | } 642 | } 643 | }, 644 | new TestColumn 645 | { 646 | ParquetColumn = new Column<TimeSpanNanos>("time_ns", LogicalType.Time(isAdjustedToUtc: true, TimeUnit.Nanos)), 647 | ExpectedColumnType = typeof(PrimitiveDataFrameColumn<TimeSpanNanos>), 648 | WriteColumn = (numRows, columnWriter) => 649 | { 650 | using var logicalWriter = columnWriter.LogicalWriter<TimeSpanNanos>(); 651 | logicalWriter.WriteBatch(Enumerable.Range(0, numRows).Select(i => new TimeSpanNanos(i)).ToArray()); 652 | }, 653 | VerifyColumn = column => 654 | { 655 | for (int i = 0; i < column.Length; ++i) 656 | { 657 | Assert.Equal(new TimeSpanNanos(i), column[i]); 658 | } 659 | } 660 | }, 661 | new TestColumn 662 | { 663 | ParquetColumn = new Column<TimeSpanNanos?>("nullable_time_ns", LogicalType.Time(isAdjustedToUtc: true, TimeUnit.Nanos)), 664 | ExpectedColumnType = typeof(PrimitiveDataFrameColumn<TimeSpanNanos>), 665 | WriteColumn = (numRows, columnWriter) => 666 | { 667 | using var logicalWriter = columnWriter.LogicalWriter<TimeSpanNanos?>(); 668 | logicalWriter.WriteBatch(Enumerable.Range(0, numRows).Select(i => (TimeSpanNanos?)new TimeSpanNanos(i)).ToArray()); 669 | }, 670 | VerifyColumn = column => 671 | { 672 | for (int i = 0; i < column.Length; ++i) 673 | { 674 | Assert.Equal(new TimeSpanNanos(i), column[i]); 675 | } 676 | } 677 | }, 678 | new TestColumn 679 | { 680 | ParquetColumn = new Column<Guid>("guid", LogicalType.Uuid()), 681 | ExpectedColumnType = typeof(PrimitiveDataFrameColumn<Guid>), 682 | WriteColumn = (numRows, columnWriter) => 683 | { 684 | using var logicalWriter = columnWriter.LogicalWriter<Guid>(); 685 | logicalWriter.WriteBatch(Enumerable.Range(0, numRows).Select(i => new Guid(i, 0, 0, new byte[] { 0, 0, 0, 0, 0, 0, 0, 0 })).ToArray()); 686 | }, 687 | VerifyColumn = column => 688 | { 689 | for (int i = 0; i < column.Length; ++i) 690 | { 691 | Assert.Equal(new Guid(i, 0, 0, new byte[] { 0, 0, 0, 0, 0, 0, 0, 0 }), column[i]); 692 | } 693 | } 694 | }, 695 | new TestColumn 696 | { 697 | ParquetColumn = new Column<Guid?>("nullable_guid", LogicalType.Uuid()), 698 | ExpectedColumnType = typeof(PrimitiveDataFrameColumn<Guid>), 699 | WriteColumn = (numRows, columnWriter) => 700 | { 701 | using var logicalWriter = columnWriter.LogicalWriter<Guid?>(); 702 | logicalWriter.WriteBatch(Enumerable.Range(0, numRows).Select(i => (Guid?)new Guid(i, 0, 0, new byte[] { 0, 0, 0, 0, 0, 0, 0, 0 })).ToArray()); 703 | }, 704 | VerifyColumn = column => 705 | { 706 | for (int i = 0; i < column.Length; ++i) 707 | { 708 | Assert.Equal(new Guid(i, 0, 0, new byte[] { 0, 0, 0, 0, 0, 0, 0, 0 }), column[i]); 709 | } 710 | } 711 | }, 712 | }; 713 | } 714 | } 715 | } 716 | -------------------------------------------------------------------------------- /ParquetSharp.DataFrame.Test/UnitTestDisposableDirectory.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | 4 | namespace ParquetSharp.DataFrame.Test 5 | { 6 | internal sealed class UnitTestDisposableDirectory : IDisposable 7 | { 8 | public UnitTestDisposableDirectory() 9 | { 10 | var path = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()); 11 | Info = new DirectoryInfo(path); 12 | Info.Create(); 13 | } 14 | 15 | public DirectoryInfo Info { get; } 16 | 17 | public void Dispose() 18 | { 19 | Info.Delete(true); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /ParquetSharp.DataFrame.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.6.30114.105 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ParquetSharp.DataFrame", "ParquetSharp.DataFrame\ParquetSharp.DataFrame.csproj", "{E976DBA7-43C8-4420-84A0-0ACA5C8B433F}" 7 | EndProject 8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ParquetSharp.DataFrame.Test", "ParquetSharp.DataFrame.Test\ParquetSharp.DataFrame.Test.csproj", "{148E23F2-2E8C-4B62-8BF3-F105FC9200FF}" 9 | EndProject 10 | Global 11 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 12 | Debug|Any CPU = Debug|Any CPU 13 | Debug|x64 = Debug|x64 14 | Debug|x86 = Debug|x86 15 | Release|Any CPU = Release|Any CPU 16 | Release|x64 = Release|x64 17 | Release|x86 = Release|x86 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 23 | {E976DBA7-43C8-4420-84A0-0ACA5C8B433F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 24 | {E976DBA7-43C8-4420-84A0-0ACA5C8B433F}.Debug|Any CPU.Build.0 = Debug|Any CPU 25 | {E976DBA7-43C8-4420-84A0-0ACA5C8B433F}.Debug|x64.ActiveCfg = Debug|Any CPU 26 | {E976DBA7-43C8-4420-84A0-0ACA5C8B433F}.Debug|x64.Build.0 = Debug|Any CPU 27 | {E976DBA7-43C8-4420-84A0-0ACA5C8B433F}.Debug|x86.ActiveCfg = Debug|Any CPU 28 | {E976DBA7-43C8-4420-84A0-0ACA5C8B433F}.Debug|x86.Build.0 = Debug|Any CPU 29 | {E976DBA7-43C8-4420-84A0-0ACA5C8B433F}.Release|Any CPU.ActiveCfg = Release|Any CPU 30 | {E976DBA7-43C8-4420-84A0-0ACA5C8B433F}.Release|Any CPU.Build.0 = Release|Any CPU 31 | {E976DBA7-43C8-4420-84A0-0ACA5C8B433F}.Release|x64.ActiveCfg = Release|Any CPU 32 | {E976DBA7-43C8-4420-84A0-0ACA5C8B433F}.Release|x64.Build.0 = Release|Any CPU 33 | {E976DBA7-43C8-4420-84A0-0ACA5C8B433F}.Release|x86.ActiveCfg = Release|Any CPU 34 | {E976DBA7-43C8-4420-84A0-0ACA5C8B433F}.Release|x86.Build.0 = Release|Any CPU 35 | {148E23F2-2E8C-4B62-8BF3-F105FC9200FF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 36 | {148E23F2-2E8C-4B62-8BF3-F105FC9200FF}.Debug|Any CPU.Build.0 = Debug|Any CPU 37 | {148E23F2-2E8C-4B62-8BF3-F105FC9200FF}.Debug|x64.ActiveCfg = Debug|Any CPU 38 | {148E23F2-2E8C-4B62-8BF3-F105FC9200FF}.Debug|x64.Build.0 = Debug|Any CPU 39 | {148E23F2-2E8C-4B62-8BF3-F105FC9200FF}.Debug|x86.ActiveCfg = Debug|Any CPU 40 | {148E23F2-2E8C-4B62-8BF3-F105FC9200FF}.Debug|x86.Build.0 = Debug|Any CPU 41 | {148E23F2-2E8C-4B62-8BF3-F105FC9200FF}.Release|Any CPU.ActiveCfg = Release|Any CPU 42 | {148E23F2-2E8C-4B62-8BF3-F105FC9200FF}.Release|Any CPU.Build.0 = Release|Any CPU 43 | {148E23F2-2E8C-4B62-8BF3-F105FC9200FF}.Release|x64.ActiveCfg = Release|Any CPU 44 | {148E23F2-2E8C-4B62-8BF3-F105FC9200FF}.Release|x64.Build.0 = Release|Any CPU 45 | {148E23F2-2E8C-4B62-8BF3-F105FC9200FF}.Release|x86.ActiveCfg = Release|Any CPU 46 | {148E23F2-2E8C-4B62-8BF3-F105FC9200FF}.Release|x86.Build.0 = Release|Any CPU 47 | EndGlobalSection 48 | EndGlobal 49 | -------------------------------------------------------------------------------- /ParquetSharp.DataFrame/.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | end_of_line = lf 5 | charset = utf-8 6 | insert_final_newline = true 7 | indent_style = space 8 | indent_size = 4 9 | trim_trailing_whitespace = true 10 | 11 | [*.csproj] 12 | indent_size = 2 13 | resharper_xml_wrap_tags_and_pi = false 14 | 15 | [*.cs] 16 | csharp_new_line_before_members_in_object_initializers = false 17 | csharp_preserve_single_line_blocks = true 18 | resharper_blank_lines_after_block_statements = 0 19 | resharper_blank_lines_around_auto_property = 0 20 | resharper_blank_lines_around_single_line_type = 0 21 | resharper_csharp_blank_lines_around_field = 0 22 | resharper_csharp_insert_final_newline = true 23 | resharper_csharp_wrap_lines = false 24 | resharper_empty_block_style = multiline 25 | resharper_keep_existing_embedded_block_arrangement = false 26 | resharper_keep_existing_enum_arrangement = false 27 | resharper_max_attribute_length_for_same_line = 70 28 | resharper_place_accessorholder_attribute_on_same_line = false 29 | resharper_place_expr_accessor_on_single_line = true 30 | resharper_place_expr_method_on_single_line = true 31 | resharper_place_expr_property_on_single_line = true 32 | resharper_place_field_attribute_on_same_line = false 33 | resharper_place_simple_embedded_statement_on_same_line = true 34 | resharper_place_simple_initializer_on_single_line = false 35 | resharper_remove_blank_lines_near_braces_in_code = false 36 | resharper_remove_blank_lines_near_braces_in_declarations = false 37 | resharper_wrap_array_initializer_style = chop_if_long 38 | resharper_wrap_chained_binary_expressions = chop_if_long 39 | resharper_wrap_object_and_collection_initializer_style = chop_always 40 | -------------------------------------------------------------------------------- /ParquetSharp.DataFrame/ColumnCreator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Diagnostics; 3 | using Microsoft.Data.Analysis; 4 | 5 | namespace ParquetSharp 6 | { 7 | /// <summary> 8 | /// LogicalColumnReaderVisitor that creates DataFrameColumns of the correct type, 9 | /// corresponding to the Parquet LogicalColumnReader type. 10 | /// </summary> 11 | internal sealed class ColumnCreator : ILogicalColumnReaderVisitor<DataFrameColumn> 12 | { 13 | /// <summary> 14 | /// Create a ColumnCreator 15 | /// </summary> 16 | /// <param name="columnName">Name of the column to create</param> 17 | /// <param name="numRows">Total number of rows in the column</param> 18 | public ColumnCreator(string columnName, long numRows) 19 | { 20 | _columnName = columnName; 21 | _numRows = numRows; 22 | } 23 | 24 | public DataFrameColumn OnLogicalColumnReader<TElement>(LogicalColumnReader<TElement> columnReader) 25 | { 26 | if (columnReader.ColumnDescriptor.LogicalType is IntLogicalType intType) 27 | { 28 | return ColumnFromIntType(intType); 29 | } 30 | 31 | switch (columnReader) 32 | { 33 | case LogicalColumnReader<string>: 34 | return new StringDataFrameColumn(_columnName, _numRows); 35 | case LogicalColumnReader<bool>: 36 | case LogicalColumnReader<bool?>: 37 | return new BooleanDataFrameColumn(_columnName, _numRows); 38 | case LogicalColumnReader<byte>: 39 | case LogicalColumnReader<byte?>: 40 | return new ByteDataFrameColumn(_columnName, _numRows); 41 | case LogicalColumnReader<sbyte>: 42 | case LogicalColumnReader<sbyte?>: 43 | return new SByteDataFrameColumn(_columnName, _numRows); 44 | case LogicalColumnReader<ushort>: 45 | case LogicalColumnReader<ushort?>: 46 | return new UInt16DataFrameColumn(_columnName, _numRows); 47 | case LogicalColumnReader<short>: 48 | case LogicalColumnReader<short?>: 49 | return new Int16DataFrameColumn(_columnName, _numRows); 50 | case LogicalColumnReader<uint>: 51 | case LogicalColumnReader<uint?>: 52 | return new UInt32DataFrameColumn(_columnName, _numRows); 53 | case LogicalColumnReader<int>: 54 | case LogicalColumnReader<int?>: 55 | return new Int32DataFrameColumn(_columnName, _numRows); 56 | case LogicalColumnReader<ulong>: 57 | case LogicalColumnReader<ulong?>: 58 | return new UInt64DataFrameColumn(_columnName, _numRows); 59 | case LogicalColumnReader<long>: 60 | case LogicalColumnReader<long?>: 61 | return new Int64DataFrameColumn(_columnName, _numRows); 62 | case LogicalColumnReader<float>: 63 | case LogicalColumnReader<float?>: 64 | return new SingleDataFrameColumn(_columnName, _numRows); 65 | case LogicalColumnReader<double>: 66 | case LogicalColumnReader<double?>: 67 | return new DoubleDataFrameColumn(_columnName, _numRows); 68 | case LogicalColumnReader<DateTime>: 69 | case LogicalColumnReader<DateTime?>: 70 | return new DateTimeDataFrameColumn(_columnName, _numRows); 71 | case LogicalColumnReader<DateTimeNanos>: 72 | case LogicalColumnReader<DateTimeNanos?>: 73 | return new PrimitiveDataFrameColumn<DateTimeNanos>(_columnName, _numRows); 74 | case LogicalColumnReader<decimal>: 75 | case LogicalColumnReader<decimal?>: 76 | return new DecimalDataFrameColumn(_columnName, _numRows); 77 | case LogicalColumnReader<Date>: 78 | case LogicalColumnReader<Date?>: 79 | return new PrimitiveDataFrameColumn<Date>(_columnName, _numRows); 80 | case LogicalColumnReader<TimeSpan>: 81 | case LogicalColumnReader<TimeSpan?>: 82 | return new PrimitiveDataFrameColumn<TimeSpan>(_columnName, _numRows); 83 | case LogicalColumnReader<TimeSpanNanos>: 84 | case LogicalColumnReader<TimeSpanNanos?>: 85 | return new PrimitiveDataFrameColumn<TimeSpanNanos>(_columnName, _numRows); 86 | case LogicalColumnReader<Guid>: 87 | case LogicalColumnReader<Guid?>: 88 | return new PrimitiveDataFrameColumn<Guid>(_columnName, _numRows); 89 | default: 90 | throw new NotImplementedException($"Unsupported column logical type: {typeof(TElement)}"); 91 | } 92 | } 93 | 94 | private DataFrameColumn ColumnFromIntType(IntLogicalType intType) 95 | { 96 | return (intType.BitWidth, intType.IsSigned) switch 97 | { 98 | (8, false) => new ByteDataFrameColumn(_columnName, _numRows), 99 | (8, true) => new SByteDataFrameColumn(_columnName, _numRows), 100 | (16, false) => new UInt16DataFrameColumn(_columnName, _numRows), 101 | (16, true) => new Int16DataFrameColumn(_columnName, _numRows), 102 | (32, false) => new UInt32DataFrameColumn(_columnName, _numRows), 103 | (32, true) => new Int32DataFrameColumn(_columnName, _numRows), 104 | (_, false) => new UInt64DataFrameColumn(_columnName, _numRows), 105 | (_, true) => new Int64DataFrameColumn(_columnName, _numRows) 106 | }; 107 | } 108 | 109 | private readonly string _columnName; 110 | private readonly long _numRows; 111 | } 112 | } 113 | -------------------------------------------------------------------------------- /ParquetSharp.DataFrame/DataFrameExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using Microsoft.Data.Analysis; 5 | 6 | namespace ParquetSharp 7 | { 8 | public static class DataFrameExtensions 9 | { 10 | /// <summary> 11 | /// Write a DataFrame in Parquet format 12 | /// </summary> 13 | /// <param name="dataFrame">The DataFrame to write</param> 14 | /// <param name="path">Path to write to</param> 15 | /// <param name="writerProperties">Optional writer properties that override the default properties</param> 16 | /// <param name="logicalTypeOverrides">Mapping from column names to Parquet logical types, 17 | /// overriding the default logical types. When writing decimal columns, a logical type must be provided 18 | /// to specify the precision and scale to use.</param> 19 | /// <param name="rowGroupSize">Maximum number of rows per row group</param> 20 | public static void ToParquet( 21 | this DataFrame dataFrame, string path, WriterProperties? writerProperties = null, 22 | IReadOnlyDictionary<string, LogicalType>? logicalTypeOverrides = null, int rowGroupSize = 1024 * 1024) 23 | { 24 | var schemaColumns = dataFrame.Columns.Select(col => GetSchemaColumn( 25 | col, logicalTypeOverrides != null && logicalTypeOverrides.TryGetValue(col.Name, out var logicalType) ? logicalType : null)).ToArray(); 26 | using var fileWriter = writerProperties == null 27 | ? new ParquetFileWriter(path, schemaColumns) 28 | : new ParquetFileWriter(path, schemaColumns, writerProperties); 29 | 30 | var numRows = dataFrame.Rows.Count; 31 | var offset = 0L; 32 | 33 | while (offset < numRows) 34 | { 35 | var batchSize = (int)Math.Min(numRows - offset, rowGroupSize); 36 | using var rowGroupWriter = fileWriter.AppendRowGroup(); 37 | foreach (var dataFrameColumn in dataFrame.Columns) 38 | { 39 | using var columnWriter = rowGroupWriter.NextColumn(); 40 | using var logicalWriter = columnWriter.LogicalWriter(); 41 | logicalWriter.Apply(new DataFrameWriter(dataFrameColumn, offset, batchSize)); 42 | } 43 | 44 | offset += batchSize; 45 | } 46 | 47 | fileWriter.Close(); 48 | } 49 | 50 | private static Column GetSchemaColumn(DataFrameColumn column, LogicalType? logicalTypeOverride) 51 | { 52 | var dataType = column.DataType; 53 | var nullable = column.NullCount > 0; 54 | if (dataType == typeof(decimal) && logicalTypeOverride == null) 55 | { 56 | throw new ArgumentException($"Logical type override must be specified for decimal column '{column.Name}'"); 57 | } 58 | 59 | if (nullable && dataType.IsValueType) 60 | { 61 | dataType = typeof(Nullable<>).MakeGenericType(dataType); 62 | } 63 | 64 | return new Column(dataType, column.Name, logicalTypeOverride); 65 | } 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /ParquetSharp.DataFrame/DataFrameSetter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Microsoft.Data.Analysis; 3 | 4 | namespace ParquetSharp 5 | { 6 | /// <summary> 7 | /// LogicalColumnReaderVisitor that sets values in a DataFrameColumn 8 | /// </summary> 9 | internal sealed class DataFrameSetter : ILogicalColumnReaderVisitor<Unit> 10 | { 11 | /// <summary> 12 | /// Create a DataFrameSetter 13 | /// </summary> 14 | /// <param name="dataFrameColumn">The column to read data into</param> 15 | /// <param name="offset">Position to begin inserting data at</param> 16 | public DataFrameSetter(DataFrameColumn dataFrameColumn, long offset) 17 | { 18 | _dataFrameColumn = dataFrameColumn; 19 | _offset = offset; 20 | } 21 | 22 | public Unit OnLogicalColumnReader<TElement>(LogicalColumnReader<TElement> columnReader) 23 | { 24 | var buffer = new TElement[columnReader.BufferLength]; 25 | long offset = 0; 26 | while (columnReader.HasNext) 27 | { 28 | var read = columnReader.ReadBatch((Span<TElement>)buffer); 29 | for (var i = 0; i != read; ++i) 30 | { 31 | _dataFrameColumn[_offset + offset + i] = buffer[i]; 32 | } 33 | 34 | offset += read; 35 | } 36 | 37 | return Unit.Instance; 38 | } 39 | 40 | private readonly DataFrameColumn _dataFrameColumn; 41 | private readonly long _offset; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /ParquetSharp.DataFrame/DataFrameWriter.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Data.Analysis; 2 | 3 | namespace ParquetSharp 4 | { 5 | /// <summary> 6 | /// LogicalColumnWriterVisitor that writes data from a DataFrame column 7 | /// </summary> 8 | internal sealed class DataFrameWriter : ILogicalColumnWriterVisitor<Unit> 9 | { 10 | /// <summary> 11 | /// Create a DataFrameWriter 12 | /// </summary> 13 | /// <param name="dataFrameColumn">The column to read data from</param> 14 | /// <param name="offset">The initial position to begin reading from</param> 15 | /// <param name="batchSize">The number of values to write</param> 16 | public DataFrameWriter(DataFrameColumn dataFrameColumn, long offset, int batchSize) 17 | { 18 | _dataFrameColumn = dataFrameColumn; 19 | _offset = offset; 20 | _batchSize = batchSize; 21 | } 22 | 23 | public Unit OnLogicalColumnWriter<TValue>(LogicalColumnWriter<TValue> columnWriter) 24 | { 25 | var values = new TValue[_batchSize]; 26 | for (var i = 0; i < _batchSize; ++i) 27 | { 28 | values[i] = (TValue)_dataFrameColumn[_offset + i]; 29 | } 30 | 31 | columnWriter.WriteBatch(values); 32 | return Unit.Instance; 33 | } 34 | 35 | private readonly DataFrameColumn _dataFrameColumn; 36 | private readonly long _offset; 37 | private readonly int _batchSize; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /ParquetSharp.DataFrame/ParquetFileReaderExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using Microsoft.Data.Analysis; 4 | 5 | namespace ParquetSharp 6 | { 7 | public static class ParquetFileReaderExtensions 8 | { 9 | /// <summary> 10 | /// Read all data from a parquet file into a DataFrame 11 | /// </summary> 12 | /// <param name="fileReader">Reader for the ParquetFile to read</param> 13 | /// <returns>Data from the Parquet file as a DataFrame</returns> 14 | public static DataFrame ToDataFrame(this ParquetFileReader fileReader) 15 | { 16 | return ToDataFrameImpl(fileReader, null, null); 17 | } 18 | 19 | /// <summary> 20 | /// Read specific row groups from a parquet file into a DataFrame 21 | /// </summary> 22 | /// <param name="fileReader">Reader for the ParquetFile to read</param> 23 | /// <param name="rowGroupIndices">Indices of row groups to read</param> 24 | /// <returns>Data from the Parquet file as a DataFrame</returns> 25 | public static DataFrame ToDataFrame(this ParquetFileReader fileReader, IReadOnlyList<int> rowGroupIndices) 26 | { 27 | return ToDataFrameImpl(fileReader, null, rowGroupIndices); 28 | } 29 | 30 | /// <summary> 31 | /// Read specific columns from a parquet file into a DataFrame 32 | /// </summary> 33 | /// <param name="fileReader">Reader for the ParquetFile to read</param> 34 | /// <param name="columns">List of columns to read</param> 35 | /// <returns>Column Data from the Parquet file as a DataFrame</returns> 36 | public static DataFrame ToDataFrame(this ParquetFileReader fileReader, IReadOnlyList<string> columns) 37 | { 38 | return ToDataFrameImpl(fileReader, columns, null); 39 | } 40 | 41 | /// <summary> 42 | /// Read specific columns and row groups from a parquet file into a DataFrame 43 | /// </summary> 44 | /// <param name="fileReader">Reader for the ParquetFile to read</param> 45 | /// <param name="columns">List of columns to read</param> 46 | /// <param name="rowGroupIndices">Indices of row groups to read</param> 47 | /// <returns>Column Data from the Parquet file as a DataFrame</returns> 48 | public static DataFrame ToDataFrame( 49 | this ParquetFileReader fileReader, IReadOnlyList<string> columns, IReadOnlyList<int> rowGroupIndices) 50 | { 51 | return ToDataFrameImpl(fileReader, columns, rowGroupIndices); 52 | } 53 | 54 | private static DataFrame ToDataFrameImpl( 55 | this ParquetFileReader fileReader, IReadOnlyList<string>? columns = null, IReadOnlyList<int>? rowGroupIndices = null) 56 | { 57 | var numColumns = columns?.Count ?? fileReader.FileMetaData.NumColumns; 58 | var dataFrameColumns = new List<DataFrameColumn>(numColumns); 59 | var numRows = rowGroupIndices == null ? fileReader.FileMetaData.NumRows : GetNumRows(fileReader, rowGroupIndices); 60 | 61 | var columnIndexMap = new int[numColumns]; 62 | for (var i = 0; i < numColumns; ++i) 63 | { 64 | columnIndexMap[i] = columns == null ? i : FindColumnIndex(columns[i], fileReader.FileMetaData.Schema); 65 | } 66 | 67 | long offset = 0; 68 | var numRowGroups = rowGroupIndices?.Count ?? fileReader.FileMetaData.NumRowGroups; 69 | for (var rowGroupIdx = 0; rowGroupIdx < numRowGroups; ++rowGroupIdx) 70 | { 71 | var fileRowGroupIdx = rowGroupIndices == null ? rowGroupIdx : rowGroupIndices[rowGroupIdx]; 72 | using var rowGroupReader = fileReader.RowGroup(fileRowGroupIdx); 73 | for (var colIdx = 0; colIdx < numColumns; ++colIdx) 74 | { 75 | using var columnReader = rowGroupReader.Column(columnIndexMap[colIdx]); 76 | using var logicalReader = columnReader.LogicalReader(); 77 | 78 | if (rowGroupIdx == 0) 79 | { 80 | // On first row group, create columns 81 | var columnCreator = new ColumnCreator(logicalReader.ColumnDescriptor.Name, numRows); 82 | dataFrameColumns.Add(logicalReader.Apply(columnCreator)); 83 | } 84 | 85 | // Read column data 86 | logicalReader.Apply(new DataFrameSetter(dataFrameColumns[colIdx], offset)); 87 | } 88 | 89 | offset += rowGroupReader.MetaData.NumRows; 90 | } 91 | 92 | return new DataFrame(dataFrameColumns); 93 | } 94 | 95 | private static long GetNumRows(ParquetFileReader fileReader, IReadOnlyList<int> rowGroupIndices) 96 | { 97 | var totalRows = 0L; 98 | foreach (var rowGroupIdx in rowGroupIndices) 99 | { 100 | using var rowGroupReader = fileReader.RowGroup(rowGroupIdx); 101 | totalRows += rowGroupReader.MetaData.NumRows; 102 | } 103 | 104 | return totalRows; 105 | } 106 | 107 | private static int FindColumnIndex(string column, SchemaDescriptor schema) 108 | { 109 | var index = schema.ColumnIndex(column); 110 | if (index < 0) 111 | { 112 | throw new ArgumentException($"Invalid column path '{column}'"); 113 | } 114 | 115 | return index; 116 | } 117 | } 118 | } 119 | -------------------------------------------------------------------------------- /ParquetSharp.DataFrame/ParquetSharp.DataFrame.csproj: -------------------------------------------------------------------------------- 1 | <Project Sdk="Microsoft.NET.Sdk"> 2 | 3 | <PropertyGroup> 4 | <TargetFrameworks>net471;netstandard2.1</TargetFrameworks> 5 | <LangVersion>9.0</LangVersion> 6 | <AssemblyName>ParquetSharp.DataFrame</AssemblyName> 7 | <RootNamespace>ParquetSharp</RootNamespace> 8 | <Nullable>enable</Nullable> 9 | <PlatformTarget Condition="'$(TargetFramework)'=='net471'">x64</PlatformTarget> 10 | <TreatWarningsAsErrors>true</TreatWarningsAsErrors> 11 | <Version>0.1.0</Version> 12 | <Company>G-Research</Company> 13 | <Authors>G-Research</Authors> 14 | <Product>ParquetSharp.DataFrame</Product> 15 | <Description>ParquetSharp.DataFrame is a .NET library for reading and writing Apache Parquet files into/from .NET DataFrames, using ParquetSharp.</Description> 16 | <Copyright>Copyright G-Research 2021</Copyright> 17 | <PackageProjectUrl>https://github.com/G-Research/ParquetSharp.DataFrame</PackageProjectUrl> 18 | <PackageTags>dataframe apache parquet gresearch g-research .net c#</PackageTags> 19 | <RepositoryType>git</RepositoryType> 20 | <RepositoryUrl>https://github.com/G-Research/ParquetSharp.DataFrame</RepositoryUrl> 21 | <PackageLicenseExpression>Apache-2.0</PackageLicenseExpression> 22 | </PropertyGroup> 23 | 24 | <ItemGroup> 25 | <PackageReference Include="Microsoft.Data.Analysis" Version="0.20.1" /> 26 | <PackageReference Include="ParquetSharp" Version="5.0.0" /> 27 | </ItemGroup> 28 | 29 | <ItemGroup Label="Additional nuget files"> 30 | <None Include="../LICENSE" Pack="true" PackagePath="" /> 31 | </ItemGroup> 32 | 33 | </Project> 34 | -------------------------------------------------------------------------------- /ParquetSharp.DataFrame/Unit.cs: -------------------------------------------------------------------------------- 1 | namespace ParquetSharp 2 | { 3 | internal sealed class Unit 4 | { 5 | public static readonly Unit Instance = new Unit(); 6 | 7 | private Unit() 8 | { 9 | } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ParquetSharp.DataFrame 2 | 3 | [![CI Status](https://github.com/G-Research/ParquetSharp.DataFrame/actions/workflows/ci.yml/badge.svg?branch=main&event=push)](https://github.com/G-Research/ParquetSharp.DataFrame/actions/workflows/ci.yml?query=branch%3Amain+event%3Apush) 4 | [![NuGet latest release](https://img.shields.io/nuget/v/ParquetSharp.DataFrame.svg)](https://www.nuget.org/packages/ParquetSharp.DataFrame) 5 | 6 | ParquetSharp.DataFrame is a .NET library for reading and writing Apache Parquet files into/from .NET [DataFrames][1], using [ParquetSharp][2]. 7 | 8 | [1]: https://docs.microsoft.com/en-us/dotnet/api/microsoft.data.analysis.dataframe 9 | [2]: https://github.com/G-Research/ParquetSharp 10 | 11 | ## Reading Parquet files 12 | 13 | Parquet data is read into a `DataFrame` using `ToDataFrame` extension methods on `ParquetFileReader`, 14 | for example: 15 | 16 | ```C# 17 | using ParquetSharp; 18 | 19 | using (var parquetReader = new ParquetFileReader(parquet_file_path)) 20 | { 21 | var dataFrame = parquetReader.ToDataFrame(); 22 | parquetReader.Close(); 23 | } 24 | ``` 25 | 26 | Overloads are provided that allow you to read specific columns from the Parquet file, 27 | and/or a subset of row groups: 28 | 29 | ```C# 30 | var dataFrame = parquetReader.ToDataFrame(columns: new [] {"col_1", "col_2"}); 31 | ``` 32 | 33 | ```C# 34 | var dataFrame = parquetReader.ToDataFrame(rowGroupIndices: new [] {0, 1}); 35 | ``` 36 | 37 | ## Writing Parquet files 38 | 39 | Parquet files are written using the `ToParquet` extension method on `DataFrame`: 40 | 41 | ```C# 42 | using ParquetSharp; 43 | using Microsoft.Data.Analysis; 44 | 45 | var dataFrame = new DataFrame(columns); 46 | dataFrame.ToParquet(parquet_file_path); 47 | ``` 48 | 49 | Parquet writing options can be overridden by providing an instance of `WriterProperties`: 50 | 51 | ```C# 52 | using (var propertiesBuilder = new WriterPropertiesBuilder()) 53 | { 54 | propertiesBuilder.Compression(Compression.Snappy); 55 | using (var properties = propertiesBuilder.Build()) 56 | { 57 | dataFrame.ToParquet(parquet_file_path, properties); 58 | } 59 | } 60 | ``` 61 | 62 | The logical type to use when writing a column can optionally be overridden. 63 | This is required when writing decimal columns, as you must specify the precision and scale to be used 64 | (see the [Parquet documentation](https://github.com/apache/parquet-format/blob/master/LogicalTypes.md#decimal) for more details). 65 | This also allows writing an integer column as a Parquet date or time. 66 | 67 | ```C# 68 | dataFrame.ToParquet(parquet_file_path, logicalTypeOverrides: new Dictionary<string, LogicalType> 69 | { 70 | {"decimal_column", LogicalType.Decimal(precision: 29, scale: 3)}, 71 | {"date_column", LogicalType.Date()}, 72 | {"time_column", LogicalType.Time(isAdjustedToUtc: true, TimeUnit.Millis)}, 73 | }); 74 | ``` 75 | 76 | ## Contributing 77 | 78 | We welcome new contributors! We will happily receive PRs for bug fixes or small changes. 79 | If you're contemplating something larger please get in touch first by opening a GitHub Issue describing the problem and how you propose to solve it. 80 | 81 | ## Security 82 | 83 | Please see our [security policy](https://github.com/G-Research/ParquetSharp.DataFrame/blob/main/SECURITY.md) for details on reporting security vulnerabilities. 84 | 85 | ## License 86 | 87 | Copyright 2021 G-Research 88 | 89 | Licensed under the Apache License, Version 2.0 (the "License"); you may not use these files except in compliance with the License. 90 | You may obtain a copy of the License at 91 | 92 | http://www.apache.org/licenses/LICENSE-2.0 93 | 94 | Unless required by applicable law or agreed to in writing, software 95 | distributed under the License is distributed on an "AS IS" BASIS, 96 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 97 | See the License for the specific language governing permissions and 98 | limitations under the License. 99 | -------------------------------------------------------------------------------- /SECURITY.md: -------------------------------------------------------------------------------- 1 | # Security and Coordinated Vulnerability Disclosure Policy 2 | 3 | This project appreciates and encourages coordinated disclosure of security vulnerabilities. We prefer that you use the GitHub reporting mechanism to privately report vulnerabilities. Under the main repository's security tab, click "Report a vulnerability" to open the advisory form. 4 | 5 | If you are unable to report it via GitHub, have received no response after repeated attempts, or have other security related questions, please contact security @ gr-oss.io and mention this project in the subject line. 6 | --------------------------------------------------------------------------------