├── .config └── dotnet-tools.json ├── .editorconfig ├── .github ├── dependabot.yml └── workflows │ ├── docs.yml │ ├── generate-bindings.yml │ ├── nightly-issue-template.md │ ├── nightly.yml │ ├── release.yml │ └── tiledb-csharp.yml ├── .gitignore ├── CONTRIBUTING.md ├── Directory.Build.props ├── Directory.Packages.props ├── LICENSE ├── README.md ├── TileDB-CSharp.sln ├── art ├── TileDB-default.svg └── logo.png ├── docs ├── .gitignore ├── api │ ├── .gitignore │ └── index.md ├── docfx.json ├── filterConfig.yml ├── index.md ├── logo.svg ├── obsoletions.md ├── rfc │ └── 1.read-void-bytes-with-span-cast.md ├── template │ └── partials │ │ └── logo.tmpl.partial └── toc.yml ├── examples └── TileDB.CSharp.Example │ ├── ExampleAggregateQuery.cs │ ├── ExampleDataframe.cs │ ├── ExampleFile.cs │ ├── ExampleGroup.cs │ ├── ExampleIncompleteQuery.cs │ ├── ExampleIncompleteQueryStringDimensions.cs │ ├── ExampleIncompleteQueryVariableSize.cs │ ├── ExampleQuery.cs │ ├── ExampleUtil.cs │ ├── ExampleVFS.cs │ ├── ExampleWritingDenseGlobal.cs │ ├── ExampleWritingSparseGlobal.cs │ ├── Program.cs │ └── TileDB.CSharp.Example.csproj ├── global.json ├── notebooks ├── README.md ├── array_metadata.ipynb ├── group.ipynb └── quickstart_dense.ipynb ├── nuget.config ├── scripts ├── generate-bindings │ ├── GenerateBindings.proj │ ├── README.md │ └── header.txt └── nuget │ ├── GenerateNuGetPackages.proj │ ├── README.md │ ├── TileDB.Native.nuspec │ ├── TileDB.Native.proj │ ├── TileDB.Native.runtime.template.nuspec │ └── TileDB.Native.runtime.template.proj ├── sources ├── NuGet.props └── TileDB.CSharp │ ├── AggregateOperation.cs │ ├── AggregateOperator.cs │ ├── Array.cs │ ├── ArrayMetadata.cs │ ├── ArraySchema.cs │ ├── ArraySchemaEvolution.cs │ ├── Attribute.cs │ ├── CompatibilitySuppressions.xml │ ├── Config.cs │ ├── ConfigIterator.cs │ ├── Context.cs │ ├── CoreUtil.cs │ ├── Dimension.cs │ ├── Domain.cs │ ├── Enumeration.cs │ ├── Enums.cs │ ├── ErrorHandling.cs │ ├── File.cs │ ├── FileStoreUtil.cs │ ├── Filter.cs │ ├── FilterList.cs │ ├── FragmentInfo.cs │ ├── Group.cs │ ├── GroupMetadata.cs │ ├── Interop │ ├── InteropAux.cs │ ├── Methods.cs │ ├── SpanExtensions.cs │ ├── TileDBSafeHandle.cs │ ├── tiledb_array_schema_evolution_t.cs │ ├── tiledb_array_schema_t.cs │ ├── tiledb_array_t.cs │ ├── tiledb_array_type_t.cs │ ├── tiledb_attribute_t.cs │ ├── tiledb_buffer_list_t.cs │ ├── tiledb_buffer_t.cs │ ├── tiledb_channel_operation_t.cs │ ├── tiledb_channel_operator_t.cs │ ├── tiledb_config_iter_t.cs │ ├── tiledb_config_t.cs │ ├── tiledb_consolidation_plan_t.cs │ ├── tiledb_ctx_t.cs │ ├── tiledb_current_domain_handle_t.cs │ ├── tiledb_current_domain_type_t.cs │ ├── tiledb_data_order_t.cs │ ├── tiledb_datatype_t.cs │ ├── tiledb_dimension_label_t.cs │ ├── tiledb_dimension_t.cs │ ├── tiledb_domain_t.cs │ ├── tiledb_encryption_type_t.cs │ ├── tiledb_enumeration_t.cs │ ├── tiledb_error_t.cs │ ├── tiledb_field_origin_t.cs │ ├── tiledb_filesystem_t.cs │ ├── tiledb_filter_list_t.cs │ ├── tiledb_filter_option_t.cs │ ├── tiledb_filter_t.cs │ ├── tiledb_filter_type_t.cs │ ├── tiledb_filter_webp_format_t.cs │ ├── tiledb_fragment_info_t.cs │ ├── tiledb_group_t.cs │ ├── tiledb_layout_t.cs │ ├── tiledb_mime_type_t.cs │ ├── tiledb_ndrectangle_handle_t.cs │ ├── tiledb_object_t.cs │ ├── tiledb_query_channel_t.cs │ ├── tiledb_query_condition_combination_op_t.cs │ ├── tiledb_query_condition_op_t.cs │ ├── tiledb_query_condition_t.cs │ ├── tiledb_query_field_t.cs │ ├── tiledb_query_status_details_reason_t.cs │ ├── tiledb_query_status_details_t.cs │ ├── tiledb_query_status_t.cs │ ├── tiledb_query_t.cs │ ├── tiledb_query_type_t.cs │ ├── tiledb_range_t.cs │ ├── tiledb_string_t.cs │ ├── tiledb_subarray_t.cs │ ├── tiledb_vfs_fh_t.cs │ ├── tiledb_vfs_mode_t.cs │ ├── tiledb_vfs_t.cs │ └── tiledb_walk_order_t.cs │ ├── InteropAugments.cs │ ├── Marshalling │ ├── MarshaledContiguousStringCollection.cs │ ├── MarshaledString.cs │ ├── MarshaledStringCollection.cs │ ├── MarshaledStringOut.cs │ ├── SafeHandleHolder.cs │ ├── SafeHandles │ │ ├── ArrayHandle.cs │ │ ├── ArraySchemaEvolutionHandle.cs │ │ ├── ArraySchemaHandle.cs │ │ ├── AttributeHandle.cs │ │ ├── ChannelOperationHandle.cs │ │ ├── ConfigHandle.cs │ │ ├── ConfigIteratorHandle.cs │ │ ├── ContextHandle.cs │ │ ├── DimensionHandle.cs │ │ ├── DomainHandle.cs │ │ ├── EnumerationHandle.cs │ │ ├── FilterHandle.cs │ │ ├── FilterListHandle.cs │ │ ├── FragmentInfoHandle.cs │ │ ├── GroupHandle.cs │ │ ├── QueryChannelHandle.cs │ │ ├── QueryConditionHandle.cs │ │ ├── QueryFieldHandle.cs │ │ ├── QueryHandle.cs │ │ ├── SubarrayHandle.cs │ │ ├── VFSFileHandle.cs │ │ └── VFSHandle.cs │ ├── ScratchBuffer.cs │ ├── SequentialPair.cs │ └── StringHandleHolder.cs │ ├── Obsoletions.cs │ ├── Query.cs │ ├── QueryChannel.cs │ ├── QueryCondition.cs │ ├── QueryField.cs │ ├── QueryStatusDetails.cs │ ├── README.md │ ├── Stats.cs │ ├── Subarray.cs │ ├── ThrowHelpers.cs │ ├── TileDB.CSharp.csproj │ ├── TileDBException.cs │ ├── VFS.cs │ ├── VFSFile.cs │ ├── build │ └── TileDB.CSharp.targets │ └── buildTransitive │ └── TileDB.CSharp.targets └── tests └── TileDB.CSharp.Test ├── AggregatesTest.cs ├── ArrayMetadataTest.cs ├── ArraySchemaEvolutionTest.cs ├── ArraySchemaTest.cs ├── ArrayTest.cs ├── AttributeTest.cs ├── ConfigTest.cs ├── ContextTest.cs ├── CoreUtilTest.cs ├── DeletesTest.cs ├── DimensionTest.cs ├── DomainTest.cs ├── EnumerationTest.cs ├── FilterListTest.cs ├── FilterTest.cs ├── FragmentInfoTest.cs ├── GroupTest.cs ├── IncompleteQueryTest.cs ├── QueryConditionTest.cs ├── QueryTest.cs ├── StatsTest.cs ├── TemporaryDirectory.cs ├── TestUtil.cs ├── TileDB.CSharp.Test.csproj └── VFSTest.cs /.config/dotnet-tools.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": 1, 3 | "isRoot": true, 4 | "tools": { 5 | "clangsharppinvokegenerator": { 6 | "version": "18.1.0.3", 7 | "commands": [ 8 | "ClangSharpPInvokeGenerator" 9 | ] 10 | }, 11 | "docfx": { 12 | "version": "2.78.2", 13 | "commands": [ 14 | "docfx" 15 | ] 16 | } 17 | } 18 | } -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | charset = utf-8 3 | end_of_line = crlf 4 | indent_style = space 5 | indent_size = 4 6 | insert_final_newline = true 7 | 8 | [*.{xml,*proj,props,targets,yml,nuspec}] 9 | indent_size = 2 10 | 11 | [*.cs] 12 | csharp_style_var_for_built_in_types=true:silent 13 | csharp_style_var_when_type_is_apparent=true:silent 14 | csharp_style_var_elsewhere=true:silent 15 | 16 | # This takes the address of, gets the size of, or declares a pointer to a managed type. 17 | # We check at runtime that generic types are not managed, and either way we can't take 18 | # a pointer to the heap by accident without using fixed or Unsafe.AsPointer. 19 | dotnet_diagnostic.CS8500.severity = None 20 | 21 | ## 22 | ## SonarAnalyzers.CSharp 23 | ## 24 | 25 | # Update this method so that its implementation is not identical to 'blah' 26 | dotnet_diagnostic.S4144.severity = None 27 | 28 | # Update this implementation of 'ISerializable' to conform to the recommended serialization pattern 29 | dotnet_diagnostic.S3925.severity = None 30 | 31 | # Rename class 'IOCActivator' to match pascal case naming rules, consider using 'IocActivator' 32 | dotnet_diagnostic.S101.severity = None 33 | 34 | # Remove unassigned auto-property 'Blah', or set its value 35 | dotnet_diagnostic.S3459.severity = None 36 | 37 | # Remove the unused private set accessor in property 'Version' 38 | dotnet_diagnostic.S1144.severity = None 39 | 40 | # 'System.Exception' should not be thrown by user code 41 | dotnet_diagnostic.S112.severity = None 42 | 43 | # Native methods should be wrapped 44 | # For some reason this warning shows even on auto-generated files. 45 | dotnet_diagnostic.S4200.severity = None 46 | 47 | # S3427: Method overloads with default parameter values should not overlap 48 | # If we oblige to this rule and remove the overload without the default parameter, 49 | # the package validator will complain. 50 | dotnet_diagnostic.S3427.severity = none 51 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | - package-ecosystem: "github-actions" 4 | directory: "/" 5 | schedule: 6 | interval: "weekly" 7 | - package-ecosystem: "nuget" 8 | directory: "/" 9 | schedule: 10 | interval: "weekly" 11 | groups: 12 | mstest: 13 | # Update MSTest packages together, they are sometimes incompatible with each other. 14 | patterns: ["MSTest.*"] 15 | -------------------------------------------------------------------------------- /.github/workflows/docs.yml: -------------------------------------------------------------------------------- 1 | name: Publish documentation 2 | 3 | on: 4 | push: 5 | branches: [ main ] 6 | 7 | jobs: 8 | build: 9 | runs-on: ubuntu-latest 10 | steps: 11 | - uses: actions/checkout@v4 12 | - uses: actions/setup-dotnet@v4 13 | with: 14 | dotnet-version: 8.0.4xx 15 | - name: Restore .NET local tools 16 | run: dotnet tool restore 17 | - name: Build docs 18 | run: dotnet tool run docfx ./docs/docfx.json 19 | - name: Upload GitHub Pages artifact 20 | uses: actions/upload-pages-artifact@v3 21 | with: 22 | path: docs/_site 23 | 24 | deploy: 25 | needs: build 26 | runs-on: ubuntu-latest 27 | permissions: 28 | pages: write 29 | id-token: write 30 | environment: 31 | name: github-pages 32 | url: ${{ steps.deployment.outputs.page_url }} 33 | steps: 34 | - name: Deploy to GitHub Pages 35 | id: deployment 36 | uses: actions/deploy-pages@v4 37 | -------------------------------------------------------------------------------- /.github/workflows/generate-bindings.yml: -------------------------------------------------------------------------------- 1 | name: Generate-Bindings 2 | 3 | run-name: 'Update bindings to version ${{inputs.version}}-${{inputs.commit_id}}' 4 | 5 | on: 6 | workflow_dispatch: 7 | inputs: 8 | version: 9 | description: 'TileDB version to generate bindings for' 10 | required: true 11 | type: string 12 | commit_id: 13 | description: 'Commit ID of the version' 14 | required: true 15 | type: string 16 | 17 | jobs: 18 | Generate-Bindings: 19 | runs-on: windows-latest 20 | steps: 21 | # Checks out repository 22 | - uses: actions/checkout@v4 23 | 24 | - uses: actions/setup-dotnet@v4 25 | with: 26 | dotnet-version: 8.0.4xx 27 | 28 | - name: Run the binding generation script 29 | run: dotnet msbuild ./scripts/generate-bindings/GenerateBindings.proj -p:Version=${{ inputs.version }} -p:VersionTag=${{ inputs.commit_id }} /restore 30 | 31 | - name: Create Pull Request 32 | uses: peter-evans/create-pull-request@v7 33 | with: 34 | branch: bindings-update/${{ inputs.version }} 35 | draft: true 36 | assignees: teo-tsirpanis 37 | title: 'Update bindings to version ${{inputs.version}}-${{inputs.commit_id}}' 38 | commit-message: 'Update bindings to version ${{inputs.version}}-${{inputs.commit_id}}' 39 | -------------------------------------------------------------------------------- /.github/workflows/nightly-issue-template.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Nightly GitHub Actions Build Fail on {{ date | date('ddd, MMMM Do YYYY') }} 3 | assignees: teo-tsirpanis 4 | labels: bug 5 | --- 6 | 7 | See run for more details: 8 | https://github.com/{{ env.GITHUB_REPOSITORY }}/actions/runs/{{ env.GITHUB_RUN_ID }} -------------------------------------------------------------------------------- /.github/workflows/release.yml: -------------------------------------------------------------------------------- 1 | name: Release 2 | 3 | on: 4 | push: 5 | tags: ['*'] 6 | 7 | jobs: 8 | Run-Tests: 9 | uses: ./.github/workflows/tiledb-csharp.yml 10 | Release: 11 | runs-on: ubuntu-latest 12 | needs: Run-Tests 13 | steps: 14 | - uses: actions/checkout@v4 15 | - uses: actions/setup-dotnet@v4 16 | with: 17 | dotnet-version: 8.0.4xx 18 | - name: Pack TileDB.CSharp 19 | run: dotnet pack -c Release ./sources/TileDB.CSharp/TileDB.CSharp.csproj -o pack 20 | # In case pushing to NuGet fails we upload the packages as artifacts to push them ourselves. 21 | # We must push these packages GitHub Actions generated because they are marked as deterministic. 22 | - name: Upload packages as artifacts 23 | uses: actions/upload-artifact@v4 24 | with: 25 | name: nuget-release 26 | path: pack/ 27 | - name: Push packages to NuGet 28 | shell: bash 29 | run: | 30 | cd pack 31 | dotnet nuget push "*.nupkg" -s https://api.nuget.org/v3/index.json -k ${{ secrets.TILEDB_CSHARP_NUGET_KEY }} 32 | -------------------------------------------------------------------------------- /.github/workflows/tiledb-csharp.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | 3 | on: 4 | push: 5 | branches: [ main, 'release/*' ] 6 | pull_request: 7 | branches: [ main, 'release/*' ] 8 | workflow_dispatch: 9 | workflow_call: 10 | 11 | jobs: 12 | Validate-Package: 13 | runs-on: ubuntu-latest 14 | steps: 15 | # Checks out repository 16 | - uses: actions/checkout@v4 17 | 18 | - uses: actions/setup-dotnet@v4 19 | with: 20 | dotnet-version: 8.0.4xx 21 | 22 | # Package validation runs as part of packing. 23 | - name: Dotnet pack for TileDB.CSharp 24 | run: | 25 | dotnet pack -c Release sources/TileDB.CSharp 26 | 27 | Run-Tests: 28 | strategy: 29 | fail-fast: false 30 | matrix: 31 | # Repeat this test for each os 32 | os: [ubuntu-latest, macos-latest, windows-latest] 33 | runs-on: ${{ matrix.os }} 34 | steps: 35 | # Checks out repository 36 | - uses: actions/checkout@v4 37 | 38 | - uses: actions/setup-dotnet@v4 39 | with: 40 | dotnet-version: 8.0.4xx 41 | 42 | # DotNet build 43 | - name: Dotnet build for TileDB.CSharp 44 | run: | 45 | dotnet build -c Release sources/TileDB.CSharp 46 | 47 | # DotNet test 48 | - name: Test TileDB.CSharp 49 | run: | 50 | dotnet test -c Release tests/TileDB.CSharp.Test 51 | 52 | - name: Run examples 53 | shell: bash 54 | run: | 55 | find examples/ -name *.csproj | xargs -I{} dotnet run --project {} 56 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Prerequisites 2 | *.d 3 | 4 | # Compiled Object files 5 | *.slo 6 | *.lo 7 | *.o 8 | *.obj 9 | 10 | # Precompiled Headers 11 | *.gch 12 | *.pch 13 | 14 | # Compiled Dynamic libraries 15 | *.so 16 | *.dylib 17 | *.dll 18 | 19 | # Fortran module files 20 | *.mod 21 | *.smod 22 | 23 | # Compiled Static libraries 24 | *.lai 25 | *.la 26 | *.a 27 | *.lib 28 | 29 | # Executables 30 | *.exe 31 | *.out 32 | *.app 33 | 34 | **/bin 35 | **/obj 36 | **/lib 37 | **/native 38 | !**/native/README.md 39 | 40 | **/libtiledb.* 41 | 42 | .idea 43 | .vscode 44 | 45 | TileDB-CSharp.sln.DotSettings.user 46 | 47 | TileDBConfig.cmake 48 | TileDbTargets*.cmake 49 | tiledb.pc 50 | 51 | .vs 52 | 53 | .DS_Store 54 | include 55 | temp 56 | *.binlog 57 | *.nupkg 58 | packages 59 | -------------------------------------------------------------------------------- /Directory.Build.props: -------------------------------------------------------------------------------- 1 | 2 | 3 | latest 4 | 5 | 6 | -------------------------------------------------------------------------------- /Directory.Packages.props: -------------------------------------------------------------------------------- 1 | 2 | 3 | true 4 | TileDB.Native 5 | 2 6 | 27 7 | [$(TileDBNativeVersionMajor).$(TileDBNativeVersionMinor).0,$(TileDBNativeVersionMajor).$([MSBuild]::Add($(TileDBNativeVersionMinor), 1)).0) 8 | 9 | 13 | true 14 | 15 | 17 | 18 | 19 | 22 | 23 | 24 | 25 | Local.$(TileDBNativePackageName) 26 | [0.0.0-local] 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 TileDB, Inc. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ![Licensed under the MIT License](https://img.shields.io/github/license/TileDB-Inc/TileDB-CSharp.svg) 2 | [![NuGet](https://img.shields.io/nuget/v/TileDB.CSharp.svg)](https://nuget.org/packages/TileDB.CSharp) 3 | [![Test](https://github.com/TileDB-Inc/TileDB-CSharp/actions/workflows/tiledb-csharp.yml/badge.svg?branch=main&event=push)](https://github.com/TileDB-Inc/TileDB-CSharp/actions/workflows/tiledb-csharp.yml) 4 | 5 | # TileDB-CSharp 6 | 7 | This repository contains the official C# bindings of the [TileDB Embedded](https://tiledb.com/products/tiledb-embedded) storage engine. See more information in [the README of the library project](sources/TileDB.CSharp/README.md). 8 | 9 | ## Install 10 | 11 | The library is available on [NuGet](https://nuget.org/packages/TileDB.CSharp). 12 | 13 | ## Build 14 | 15 | ```bash 16 | cd sources/TileDB.CSharp 17 | dotnet build -c Release 18 | ``` 19 | 20 | ## Test 21 | 22 | ```bash 23 | cd tests/TileDB.CSharp.Test 24 | dotnet test -c Release 25 | ``` 26 | 27 | ## Old version 28 | 29 | The SWIG-based 2.x version of this codebase is available in the [`archive`](https://github.com/TileDB-Inc/TileDB-CSharp/tree/archive) branch. 30 | -------------------------------------------------------------------------------- /TileDB-CSharp.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 17 4 | VisualStudioVersion = 17.4.33103.184 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TileDB.CSharp", "sources\TileDB.CSharp\TileDB.CSharp.csproj", "{47B5AEE4-59F8-4685-A244-0C5BA8DC518D}" 7 | EndProject 8 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TileDB.CSharp.Test", "tests\TileDB.CSharp.Test\TileDB.CSharp.Test.csproj", "{C770B213-685E-4845-BA62-96092A3AF27F}" 9 | EndProject 10 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TileDB.CSharp.Example", "examples\TileDB.CSharp.Example\TileDB.CSharp.Example.csproj", "{3F1C263E-AE13-4E74-945A-D8B30D2BC4EF}" 11 | EndProject 12 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "examples", "examples", "{7C55D112-DBCB-4930-95DA-BE2BDC385D09}" 13 | EndProject 14 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "build", "build", "{976083E6-C64F-43F2-ADCB-4D78278982A2}" 15 | ProjectSection(SolutionItems) = preProject 16 | .editorconfig = .editorconfig 17 | Directory.Build.props = Directory.Build.props 18 | Directory.Packages.props = Directory.Packages.props 19 | global.json = global.json 20 | EndProjectSection 21 | EndProject 22 | Global 23 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 24 | Debug|Any CPU = Debug|Any CPU 25 | Release|Any CPU = Release|Any CPU 26 | EndGlobalSection 27 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 28 | {47B5AEE4-59F8-4685-A244-0C5BA8DC518D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 29 | {47B5AEE4-59F8-4685-A244-0C5BA8DC518D}.Debug|Any CPU.Build.0 = Debug|Any CPU 30 | {47B5AEE4-59F8-4685-A244-0C5BA8DC518D}.Release|Any CPU.ActiveCfg = Release|Any CPU 31 | {47B5AEE4-59F8-4685-A244-0C5BA8DC518D}.Release|Any CPU.Build.0 = Release|Any CPU 32 | {C770B213-685E-4845-BA62-96092A3AF27F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 33 | {C770B213-685E-4845-BA62-96092A3AF27F}.Debug|Any CPU.Build.0 = Debug|Any CPU 34 | {C770B213-685E-4845-BA62-96092A3AF27F}.Release|Any CPU.ActiveCfg = Release|Any CPU 35 | {C770B213-685E-4845-BA62-96092A3AF27F}.Release|Any CPU.Build.0 = Release|Any CPU 36 | {3F1C263E-AE13-4E74-945A-D8B30D2BC4EF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 37 | {3F1C263E-AE13-4E74-945A-D8B30D2BC4EF}.Debug|Any CPU.Build.0 = Debug|Any CPU 38 | {3F1C263E-AE13-4E74-945A-D8B30D2BC4EF}.Release|Any CPU.ActiveCfg = Release|Any CPU 39 | {3F1C263E-AE13-4E74-945A-D8B30D2BC4EF}.Release|Any CPU.Build.0 = Release|Any CPU 40 | EndGlobalSection 41 | GlobalSection(SolutionProperties) = preSolution 42 | HideSolutionNode = FALSE 43 | EndGlobalSection 44 | GlobalSection(NestedProjects) = preSolution 45 | {3F1C263E-AE13-4E74-945A-D8B30D2BC4EF} = {7C55D112-DBCB-4930-95DA-BE2BDC385D09} 46 | EndGlobalSection 47 | GlobalSection(ExtensibilityGlobals) = postSolution 48 | SolutionGuid = {7D010889-FC86-4021-8E34-D940F1BF0E86} 49 | EndGlobalSection 50 | EndGlobal 51 | -------------------------------------------------------------------------------- /art/TileDB-default.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /art/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TileDB-Inc/TileDB-CSharp/6256ed2c92d848140590f55b243688a7c1c840fc/art/logo.png -------------------------------------------------------------------------------- /docs/.gitignore: -------------------------------------------------------------------------------- 1 | ############### 2 | # folder # 3 | ############### 4 | /**/DROP/ 5 | /**/TEMP/ 6 | /**/packages/ 7 | /**/bin/ 8 | /**/obj/ 9 | _site 10 | -------------------------------------------------------------------------------- /docs/api/.gitignore: -------------------------------------------------------------------------------- 1 | ############### 2 | # temp file # 3 | ############### 4 | *.yml 5 | .manifest 6 | -------------------------------------------------------------------------------- /docs/api/index.md: -------------------------------------------------------------------------------- 1 | # TileDB C# API Reference 2 | -------------------------------------------------------------------------------- /docs/docfx.json: -------------------------------------------------------------------------------- 1 | { 2 | "metadata": [ 3 | { 4 | "src": [ 5 | { 6 | "files": [ 7 | "sources/**.csproj" 8 | ], 9 | "src": ".." 10 | } 11 | ], 12 | "dest": "api", 13 | "disableGitFeatures": false, 14 | "disableDefaultFilter": false, 15 | "filter": "filterConfig.yml" 16 | } 17 | ], 18 | "build": { 19 | "content": [ 20 | { 21 | "files": [ 22 | "api/**.yml", 23 | "api/index.md" 24 | ] 25 | }, 26 | { 27 | "files": [ 28 | "toc.yml", 29 | "*.md" 30 | ] 31 | } 32 | ], 33 | "resource": [ 34 | { 35 | "files": [ 36 | "logo.svg" 37 | ] 38 | }, 39 | { 40 | "files": [ 41 | "art/**.svg" 42 | ], 43 | "src": ".." 44 | } 45 | ], 46 | "dest": "_site", 47 | "xrefService": [ 48 | "https://xref.docs.microsoft.com/query?uid={uid}" 49 | ], 50 | "globalMetadataFiles": [], 51 | "globalMetadata" : 52 | { 53 | "_appTitle" : "TileDB C# API", 54 | "_appFooter" : "Copyright © 2018-2023 TileDB Inc.", 55 | "_enableSearch": false 56 | }, 57 | "fileMetadataFiles": [], 58 | "template": [ 59 | "default", 60 | "template" 61 | ], 62 | "postProcessors": [], 63 | "markdownEngineName": "markdig", 64 | "noLangKeyword": false, 65 | "keepFileLink": false, 66 | "cleanupCacheHistory": false, 67 | "disableGitFeatures": false 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /docs/filterConfig.yml: -------------------------------------------------------------------------------- 1 | apiRules: 2 | - exclude: 3 | uidRegex: ^TileDB\.Interop 4 | type: Namespace 5 | - exclude: 6 | uidRegex: ^System\.Object 7 | type: member # Avoid list of inherited Object members for each type. 8 | -------------------------------------------------------------------------------- /docs/index.md: -------------------------------------------------------------------------------- 1 | [![The logo of TileDB](../art/TileDB-default.svg)](https://tiledb.com) 2 | 3 | # TileDB C# API 4 | 5 | Welcome to the documentation for the C# API for [TileDB Embedded](https://tiledb.com/products/tiledb-embedded/). Use the links at the top to navigate. 6 | -------------------------------------------------------------------------------- /docs/logo.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /docs/rfc/1.read-void-bytes-with-span-cast.md: -------------------------------------------------------------------------------- 1 | Design for untyped result data 2 | ------------------------------ 3 | 4 | The goal here is to plan and agree how we will handle multi-value out data 5 | which is returned pointer+size. 6 | 7 | I will focus on a specific signature here, but this design is intended to be 8 | used for any function which returns unknown-size, untyped data via 9 | `void**` + `size` (or similar single-typed out pointers like `char**`). 10 | 11 | Similar functions where this design is hopefully applicable: 12 | - `tiledb_dimension_get_domain` 13 | - `tiledb_array_get_metadata` 14 | - `tiledb_query_get_range{_*}` 15 | etc. 16 | 17 | The function signature we need to wrap is: 18 | 19 | ``` 20 | public static extern int tiledb_attribute_get_fill_value(tiledb_ctx_t* ctx, tiledb_attribute_t* attr, [NativeTypeName("const void **")] void** value, [NativeTypeName("uint64_t *")] ulong* size); 21 | ``` 22 | 23 | Here is a sketch of the proposed interface: 24 | 25 | 1) wrap the function above to return `bytes[]`: 26 | 27 | ``` 28 | public bytes[] get_fill_value(...) { 29 | fixed { 30 | void* value_p; 31 | ulong size; 32 | 33 | tiledb_attribute_get_fill_value( 34 | ctx_, 35 | attr_, 36 | &value_p, 37 | &size 38 | ); 39 | 40 | var fill_span = ReadOnlySpan fill_bytes(value_p, size); 41 | return span.ToArray(); // intentionally return copy here 42 | } 43 | } 44 | ``` 45 | 46 | 2) Then we can add a templated extension method which calls the `bytes[]` signature and returns the template type: 47 | 48 | ``` 49 | public T[] fill_value() where T : struct 50 | { 51 | // type check! 52 | 53 | fill_bytes = get_fill_value(...) // call function above 54 | 55 | // TBD does this copy again or just increase refcount of bytes? 56 | return MemoryMarshal.Cast(fill_bytes).Slice(0,size-1); 57 | } 58 | ``` -------------------------------------------------------------------------------- /docs/template/partials/logo.tmpl.partial: -------------------------------------------------------------------------------- 1 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /docs/toc.yml: -------------------------------------------------------------------------------- 1 | - name: Quick start 2 | href: https://docs.tiledb.com/main/how-to/installation/quick-install 3 | - name: API Documentation 4 | href: api/ 5 | homepage: api/index.md 6 | - name: Obsoletions 7 | href: obsoletions.md 8 | -------------------------------------------------------------------------------- /examples/TileDB.CSharp.Example/ExampleAggregateQuery.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | 4 | namespace TileDB.CSharp.Examples; 5 | 6 | static class ExampleAggregateQuery 7 | { 8 | private static readonly string ArrayPath = ExampleUtil.MakeExamplePath("aggregate-array"); 9 | private static readonly Context Ctx = Context.GetDefault(); 10 | 11 | private static void CreateArray() 12 | { 13 | // Create array 14 | var dim1 = Dimension.Create(Ctx, "rows", boundLower: 1, boundUpper: 4, extent: 4); 15 | var dim2 = Dimension.Create(Ctx, "cols", boundLower: 1, boundUpper: 4, extent: 4); 16 | var domain = new Domain(Ctx); 17 | domain.AddDimension(dim1); 18 | domain.AddDimension(dim2); 19 | var array_schema = new ArraySchema(Ctx, ArrayType.Sparse); 20 | var attr = new Attribute(Ctx, "a", DataType.Int32); 21 | array_schema.AddAttribute(attr); 22 | array_schema.SetDomain(domain); 23 | array_schema.Check(); 24 | 25 | Array.Create(Ctx, ArrayPath, array_schema); 26 | } 27 | 28 | private static void WriteArray() 29 | { 30 | using (var array_write = new Array(Ctx, ArrayPath)) 31 | { 32 | array_write.Open(QueryType.Write); 33 | using (var query_write = new Query(array_write)) 34 | { 35 | query_write.SetLayout(LayoutType.GlobalOrder); 36 | query_write.SetDataBuffer("rows", new int[] { 1, 2 }); 37 | query_write.SetDataBuffer("cols", new int[] { 1, 4 }); 38 | query_write.SetDataBuffer("a", new int[] { 1, 2 }); 39 | query_write.Submit(); 40 | query_write.SetDataBuffer("rows", new int[] { 3 }); 41 | query_write.SetDataBuffer("cols", new int[] { 3 }); 42 | query_write.SetDataBuffer("a", new int[] { 3 }); 43 | query_write.SubmitAndFinalize(); 44 | } 45 | array_write.Close(); 46 | } 47 | } 48 | 49 | private static void ReadArray() 50 | { 51 | ulong[] count = [0]; 52 | long[] sum = [0]; 53 | 54 | using (var array_read = new Array(Ctx, ArrayPath)) 55 | { 56 | array_read.Open(QueryType.Read); 57 | using var query_read = new Query(array_read); 58 | query_read.SetLayout(LayoutType.Unordered); 59 | using var channel = query_read.GetDefaultChannel(); 60 | channel.ApplyAggregate(AggregateOperation.Count, "Count"); 61 | channel.ApplyAggregate(AggregateOperation.Unary(AggregateOperator.Sum, "a"), "Sum"); 62 | query_read.SetDataBuffer("Count", count); 63 | query_read.SetDataBuffer("Sum", sum); 64 | query_read.Submit(); 65 | array_read.Close(); 66 | } 67 | 68 | Console.WriteLine($"Count: {count[0]}"); 69 | Console.WriteLine($"Sum: {sum[0]}"); 70 | } 71 | 72 | public static void Run() 73 | { 74 | if (Directory.Exists(ArrayPath)) 75 | { 76 | Directory.Delete(ArrayPath, true); 77 | } 78 | 79 | CreateArray(); 80 | WriteArray(); 81 | ReadArray(); 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /examples/TileDB.CSharp.Example/ExampleGroup.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | 5 | namespace TileDB.CSharp.Examples; 6 | 7 | public class ExampleGroup 8 | { 9 | private readonly Context _ctx; 10 | private readonly string _nameSpace; 11 | 12 | // Local access 13 | public ExampleGroup() 14 | { 15 | _ctx = Context.GetDefault(); 16 | _nameSpace = String.Empty; 17 | } 18 | 19 | // S3 access 20 | public ExampleGroup(string key, string secret) 21 | { 22 | var config = new Config(); 23 | config.Set("vfs.s3.aws_access_key_id", key); 24 | config.Set("vfs.s3.aws_secret_access_key", secret); 25 | _ctx = new Context(config); 26 | _nameSpace = String.Empty; 27 | } 28 | 29 | // TileDB Cloud access with token 30 | public ExampleGroup(string host, string token, string nameSpace) 31 | { 32 | var config = new Config(); 33 | config.Set("rest.server_address", host); 34 | config.Set("rest.token", token); 35 | _ctx = new Context(config); 36 | _nameSpace = nameSpace; 37 | } 38 | 39 | // TileDB Cloud access with basic authentication 40 | public ExampleGroup(string host, string username, string password, string nameSpace) 41 | { 42 | var config = new Config(); 43 | config.Set("rest.server_address", host); 44 | config.Set("rest.username", username); 45 | config.Set("rest.password", password); 46 | _ctx = new Context(config); 47 | _nameSpace = nameSpace; 48 | } 49 | 50 | public void CreateGroups(string pathOrBucket, string groupName1, string groupName2) 51 | { 52 | var groupURI1 = string.Join("/", new List(new string[] {pathOrBucket, groupName1})); 53 | var groupURI2 = string.Join("/", new List(new string[] { pathOrBucket, groupName2 })); 54 | 55 | if (_nameSpace == String.Empty) 56 | { 57 | if (Directory.Exists(groupURI1)) 58 | { 59 | Directory.Delete(groupURI1, true); 60 | } 61 | Group.Create(_ctx, groupURI1); 62 | 63 | if (Directory.Exists(groupURI2)) 64 | { 65 | Directory.Delete(groupURI2, true); 66 | } 67 | Group.Create(_ctx, groupURI2); 68 | return; 69 | } 70 | 71 | var groupURIToCreate1 = string.Format("tiledb://{0}/{1}", _nameSpace, groupURI1); 72 | Group.Create(_ctx, groupURIToCreate1); 73 | var groupURIToCreate2 = string.Format("tiledb://{0}/{1}", _nameSpace, groupURI2); 74 | Group.Create(_ctx, groupURIToCreate2); 75 | } 76 | 77 | public void NestGroup(string pathOrBucket, string parentGroupName, string childGroupName) 78 | { 79 | string parentGroupURI; 80 | string childGroupURI; 81 | if (_nameSpace == String.Empty) 82 | { 83 | parentGroupURI = string.Join("/", new List(new string[] { pathOrBucket, parentGroupName })); 84 | childGroupURI = string.Join("/", new List(new string[] { pathOrBucket, childGroupName })); 85 | } 86 | else 87 | { 88 | parentGroupURI = string.Format("tiledb://{0}/{1}", _nameSpace, parentGroupName); 89 | childGroupURI = string.Format("tiledb://{0}/{1}", _nameSpace, childGroupName); 90 | } 91 | 92 | var parentGroup = new Group(_ctx, parentGroupURI); 93 | parentGroup.Open(QueryType.Write); 94 | parentGroup.AddMember(childGroupURI, false, "groupMember2"); 95 | parentGroup.Close(); 96 | } 97 | 98 | public static void RunLocal() 99 | { 100 | var localGroupPath = ExampleUtil.MakeExamplePath("groups-local"); 101 | if (!Directory.Exists(localGroupPath)) 102 | { 103 | Directory.CreateDirectory(localGroupPath); 104 | } 105 | var localGroupName1 = "group1"; 106 | var localGroupName2 = "group2"; 107 | 108 | var exampleGroup = new ExampleGroup(); 109 | exampleGroup.CreateGroups(localGroupPath, localGroupName1, localGroupName2); 110 | exampleGroup.NestGroup(localGroupPath, localGroupName1, localGroupName2); 111 | } 112 | 113 | public static void RunCloud(string token, string nameSpace, string s3BucketPrefix, 114 | string host = "https://api.tiledb.com") 115 | { 116 | var cloudGroupName1 = "cloud_group1"; 117 | var cloudGroupName2 = "cloud_group2"; 118 | 119 | var exampleGroup = new ExampleGroup(host, token, nameSpace); 120 | exampleGroup.CreateGroups(s3BucketPrefix, cloudGroupName1, cloudGroupName2); 121 | exampleGroup.NestGroup(s3BucketPrefix, cloudGroupName1, cloudGroupName2); 122 | } 123 | } -------------------------------------------------------------------------------- /examples/TileDB.CSharp.Example/ExampleIncompleteQuery.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | 6 | namespace TileDB.CSharp.Examples; 7 | 8 | public static class ExampleIncompleteQuery 9 | { 10 | static readonly string ArrayPath = ExampleUtil.MakeExamplePath("sparse-incomplete-query"); 11 | private static readonly Context Ctx = Context.GetDefault(); 12 | 13 | private static void CreateArray() 14 | { 15 | var dim1 = Dimension.Create(Ctx, "rows", boundLower: 1, boundUpper: 10, extent: 4); 16 | var dim2 = Dimension.Create(Ctx, "cols", boundLower: 1, boundUpper: 10, extent: 4); 17 | 18 | var domain = new Domain(Ctx); 19 | domain.AddDimension(dim1); 20 | domain.AddDimension(dim2); 21 | 22 | var schema = new ArraySchema(Ctx, ArrayType.Sparse); 23 | schema.SetDomain(domain); 24 | 25 | var attr = new Attribute(Ctx, "a1", DataType.Int32); 26 | schema.AddAttribute(attr); 27 | schema.Check(); 28 | 29 | Array.Create(Ctx, ArrayPath, schema); 30 | } 31 | 32 | private static void WriteArray() 33 | { 34 | // Produce columns iteratively 35 | List colsList = new(); 36 | for (int i = 0; i < 10; i++) 37 | { 38 | colsList.AddRange(Enumerable.Range(1, 10)); 39 | } 40 | int[] colsData = colsList.ToArray(); 41 | 42 | // Produce rows using LINQ 43 | int[] rowsData = 44 | (from a in Enumerable.Range(1, 10) 45 | from b in Enumerable.Range(1, 10) 46 | select a).ToArray(); 47 | 48 | // Write a1 attribute with values 1-100 49 | int[] attrData = Enumerable.Range(1, 100).ToArray(); 50 | using (var arrayWrite = new Array(Ctx, ArrayPath)) 51 | { 52 | arrayWrite.Open(QueryType.Write); 53 | 54 | var queryWrite = new Query(arrayWrite); 55 | queryWrite.SetLayout(LayoutType.Unordered); 56 | queryWrite.SetDataBuffer("rows", rowsData); 57 | queryWrite.SetDataBuffer("cols", colsData); 58 | queryWrite.SetDataBuffer("a1", attrData); 59 | queryWrite.Submit(); 60 | 61 | Console.WriteLine($"Write query status: {queryWrite.Status()}"); 62 | arrayWrite.Close(); 63 | } 64 | } 65 | 66 | private static void ReadArray() 67 | { 68 | // Allocate buffers for 10 values per batch read 69 | var rowsRead = new int[10]; 70 | var colsRead = new int[10]; 71 | var attrRead = new int[10]; 72 | 73 | using (var arrayRead = new Array(Ctx, ArrayPath)) 74 | { 75 | arrayRead.Open(QueryType.Read); 76 | var queryRead = new Query(arrayRead); 77 | queryRead.SetLayout(LayoutType.Unordered); 78 | 79 | queryRead.SetDataBuffer("rows", rowsRead); 80 | queryRead.SetDataBuffer("cols", colsRead); 81 | queryRead.SetDataBuffer("a1", attrRead); 82 | 83 | int batchNum = 1; 84 | do 85 | { 86 | queryRead.Submit(); 87 | 88 | // Zip (row, col) together for pretty printing 89 | var coordList = 90 | rowsRead.Zip(colsRead, (row, col) => new Tuple(row, col)); 91 | // Zip (coordinate, value) together for pretty printing 92 | var resultList = 93 | coordList.Zip(attrRead, (coord, val) => new Tuple, int>(coord, val)); 94 | // Output read data as list of ((row, col), value) 95 | Console.WriteLine($"Batch #{batchNum++}: {string.Join(", ", resultList)}"); 96 | 97 | // If read is still incomplete, submit query again using allocated buffers 98 | } while (queryRead.Status() == QueryStatus.Incomplete); 99 | 100 | Console.WriteLine($"Final read query status: {queryRead.Status()}"); 101 | arrayRead.Close(); 102 | } 103 | } 104 | 105 | public static void Run() 106 | { 107 | if (Directory.Exists(ArrayPath)) 108 | { 109 | Directory.Delete(ArrayPath, true); 110 | } 111 | 112 | CreateArray(); 113 | WriteArray(); 114 | ReadArray(); 115 | } 116 | } 117 | -------------------------------------------------------------------------------- /examples/TileDB.CSharp.Example/ExampleQuery.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using TileDB.CSharp; 4 | namespace TileDB.CSharp.Examples; 5 | 6 | static class ExampleQuery 7 | { 8 | private static readonly string ArrayPath = ExampleUtil.MakeExamplePath("sparse-array"); 9 | private static readonly Context Ctx = Context.GetDefault(); 10 | 11 | private static void CreateArray() 12 | { 13 | // Create array 14 | var dim1 = Dimension.Create(Ctx, "rows", boundLower: 1, boundUpper: 4, extent: 4); 15 | var dim2 = Dimension.Create(Ctx, "cols", boundLower: 1, boundUpper: 4, extent: 4); 16 | var domain = new Domain(Ctx); 17 | domain.AddDimension(dim1); 18 | domain.AddDimension(dim2); 19 | var array_schema = new ArraySchema(Ctx, ArrayType.Sparse); 20 | var attr = new Attribute(Ctx, "a", DataType.Int32); 21 | array_schema.AddAttribute(attr); 22 | array_schema.SetDomain(domain); 23 | array_schema.Check(); 24 | 25 | Array.Create(Ctx, ArrayPath, array_schema); 26 | } 27 | 28 | private static void WriteArray() 29 | { 30 | var dim1_data_buffer = new int[3] { 1, 2, 3 }; 31 | var dim2_data_buffer = new int[3] { 1, 3, 4 }; 32 | var attr_data_buffer = new int[3] { 1, 2, 3 }; 33 | 34 | using (var array_write = new Array(Ctx, ArrayPath)) 35 | { 36 | array_write.Open(QueryType.Write); 37 | var query_write = new Query(array_write); 38 | query_write.SetLayout(LayoutType.Unordered); 39 | query_write.SetDataBuffer("rows", dim1_data_buffer); 40 | query_write.SetDataBuffer("cols", dim2_data_buffer); 41 | query_write.SetDataBuffer("a", attr_data_buffer); 42 | query_write.Submit(); 43 | array_write.Close(); 44 | } 45 | } 46 | 47 | private static void ReadArray() 48 | { 49 | var dim1_data_buffer_read = new int[3]; 50 | var dim2_data_buffer_read = new int[3]; 51 | var attr_data_buffer_read = new int[3]; 52 | 53 | using (var array_read = new Array(Ctx, ArrayPath)) 54 | { 55 | array_read.Open(QueryType.Read); 56 | var query_read = new Query(array_read); 57 | query_read.SetLayout(LayoutType.RowMajor); 58 | query_read.SetDataBuffer("rows", dim1_data_buffer_read); 59 | query_read.SetDataBuffer("cols", dim2_data_buffer_read); 60 | query_read.SetDataBuffer("a", attr_data_buffer_read); 61 | query_read.Submit(); 62 | array_read.Close(); 63 | } 64 | 65 | Console.WriteLine("dim1:{0},{1},{2}", dim1_data_buffer_read[0], dim1_data_buffer_read[1], dim1_data_buffer_read[2]); 66 | Console.WriteLine("dim2:{0},{1},{2}", dim2_data_buffer_read[0], dim2_data_buffer_read[1], dim2_data_buffer_read[2]); 67 | Console.WriteLine("attr:{0},{1},{2}", attr_data_buffer_read[0], attr_data_buffer_read[1], attr_data_buffer_read[2]); 68 | } 69 | 70 | public static void Run() 71 | { 72 | if (Directory.Exists(ArrayPath)) 73 | { 74 | Directory.Delete(ArrayPath, true); 75 | } 76 | 77 | CreateArray(); 78 | WriteArray(); 79 | ReadArray(); 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /examples/TileDB.CSharp.Example/ExampleUtil.cs: -------------------------------------------------------------------------------- 1 | using System.IO; 2 | 3 | namespace TileDB.CSharp.Examples; 4 | 5 | public static class ExampleUtil 6 | { 7 | static ExampleUtil() 8 | { 9 | if (!Directory.Exists(MakeExamplePath(""))) 10 | { 11 | Directory.CreateDirectory(MakeExamplePath("")); 12 | } 13 | } 14 | 15 | /// 16 | /// Normalizes temp directory 17 | /// 18 | /// Name of file to create temp path 19 | /// A full path to the local tempFile 20 | public static string MakeTempPath(string tempFile) => 21 | Path.Join(Path.Join(Path.GetTempPath(), "tiledb-csharp-temp"), tempFile); 22 | 23 | /// 24 | /// Normalizes temp directory for all examples 25 | /// 26 | /// Name of file to create temp path 27 | /// A full path to a local temp directory using provided fileName 28 | public static string MakeExamplePath(string fileName) => 29 | Path.Join(MakeTempPath("examples"), fileName); 30 | } 31 | -------------------------------------------------------------------------------- /examples/TileDB.CSharp.Example/ExampleVFS.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using TileDB.CSharp; 3 | using TileDB.CSharp.Examples; 4 | 5 | public static class ExampleVFS 6 | { 7 | public static void Run() 8 | { 9 | var config = new Config(); 10 | 11 | // To use S3, set a path starting with `s3://` here: 12 | string array_path = ExampleUtil.MakeExamplePath("test-example-vfs"); 13 | 14 | // To use S3, set credentials here (or in AWS_ environment variables) 15 | //config.Set("vfs.s3.aws_access_key_id", "..."); 16 | 17 | // To use S3 custom headers, set key-value pairs here: 18 | config.Set("vfs.s3.custom_headers.my_test_header", "test-test-1234"); 19 | 20 | 21 | using Context ctx = new Context(config); 22 | using VFS vfs = new VFS(ctx); 23 | 24 | if (vfs.IsDir(array_path)) 25 | { 26 | vfs.RemoveDir(array_path); 27 | } 28 | vfs.CreateDir(array_path); 29 | 30 | CreateFiles(); 31 | ListFiles(); 32 | 33 | void CreateFiles() 34 | { 35 | vfs.Touch(array_path + "/f1"); 36 | } 37 | 38 | void ListFiles() 39 | { 40 | var files = vfs.GetChildren(array_path); 41 | files.ForEach(Console.WriteLine); 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /examples/TileDB.CSharp.Example/ExampleWritingDenseGlobal.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | 4 | namespace TileDB.CSharp.Examples; 5 | 6 | public static class ExampleWritingDenseGlobal 7 | { 8 | private static readonly string ArrayPath = ExampleUtil.MakeExamplePath("writing-dense-global"); 9 | private static readonly Context Ctx = Context.GetDefault(); 10 | 11 | private static void CreateArray() 12 | { 13 | using var domain = new Domain(Ctx); 14 | // Create a 4x4 array with 2x2 tile dimensions; Total of 16 cells, 4 tiles, 4 cells each tile 15 | // + Same layout seen here: https://docs.tiledb.com/main/background/key-concepts-and-data-format#indexing 16 | domain.AddDimension(Dimension.Create(Ctx, "rows", 1, 4, 2)); 17 | domain.AddDimension(Dimension.Create(Ctx, "cols", 1, 4, 2)); 18 | 19 | using var schema = new ArraySchema(Ctx, ArrayType.Dense); 20 | Console.WriteLine($"Tile order: {schema.TileOrder()}; Cell order: {schema.CellOrder()}"); 21 | schema.SetDomain(domain); 22 | schema.AddAttribute(Attribute.Create(Ctx, "a1")); 23 | 24 | Array.Create(Ctx, ArrayPath, schema); 25 | } 26 | 27 | private static void WriteArray() 28 | { 29 | using var array = new Array(Ctx, ArrayPath); 30 | array.Open(QueryType.Write); 31 | 32 | using var queryWrite = new Query(array, QueryType.Write); 33 | queryWrite.SetLayout(LayoutType.GlobalOrder); 34 | // Slice rows 1-4, columns 1-2 for a total of 8 cells 35 | using var subarray = new Subarray(array); 36 | subarray.AddRange("rows", 1, 4); 37 | subarray.AddRange("cols", 1, 2); 38 | queryWrite.SetSubarray(subarray); 39 | 40 | // Write 4 cells 41 | queryWrite.SetDataBuffer("a1", new[] { 1, 2, 3, 4 }); 42 | queryWrite.Submit(); 43 | Console.WriteLine($"Write query #1 status: {queryWrite.Status()}"); 44 | 45 | // Write 4 more cells before we finalize the query 46 | queryWrite.SetDataBuffer("a1", new[] { 5, 6, 7, 8}); 47 | queryWrite.Submit(); 48 | Console.WriteLine($"Write query #2 status: {queryWrite.Status()}"); 49 | 50 | // Important: Global order writes must call Query.FinalizeQuery() 51 | queryWrite.FinalizeQuery(); 52 | array.Close(); 53 | } 54 | 55 | private static void ReadArray() 56 | { 57 | using var array = new Array(Ctx, ArrayPath); 58 | array.Open(QueryType.Read); 59 | using var readQuery = new Query(array, QueryType.Read); 60 | using var subarray = new Subarray(array); 61 | subarray.SetSubarray(1, 4, 1, 4); 62 | readQuery.SetSubarray(subarray); 63 | 64 | var a1Read = new int[16]; 65 | readQuery.SetDataBuffer("a1", a1Read); 66 | readQuery.Submit(); 67 | Console.WriteLine($"Read query status: {readQuery.Status()}"); 68 | Console.WriteLine($"a1 data: {string.Join(", ", a1Read)}"); 69 | 70 | array.Close(); 71 | } 72 | 73 | public static void Run() 74 | { 75 | if (Directory.Exists(ArrayPath)) 76 | { 77 | Directory.Delete(ArrayPath, true); 78 | } 79 | 80 | CreateArray(); 81 | WriteArray(); 82 | ReadArray(); 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /examples/TileDB.CSharp.Example/ExampleWritingSparseGlobal.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using System.Linq; 4 | 5 | namespace TileDB.CSharp.Examples; 6 | 7 | public static class ExampleWritingSparseGlobal 8 | { 9 | private static readonly string ArrayPath = ExampleUtil.MakeExamplePath("writing-sparse-global"); 10 | private static readonly Context Ctx = Context.GetDefault(); 11 | 12 | private static void CreateArray() 13 | { 14 | using var domain = new Domain(Ctx); 15 | // Create a 4x4 array with 2x2 tile dimensions; Total of 16 cells, 4 tiles, 4 cells each tile 16 | // + Same layout seen here: https://docs.tiledb.com/main/background/key-concepts-and-data-format#indexing 17 | domain.AddDimension(Dimension.Create(Ctx, "rows", 1, 4, 2)); 18 | domain.AddDimension(Dimension.Create(Ctx, "cols", 1, 4, 2)); 19 | 20 | using var schema = new ArraySchema(Ctx, ArrayType.Sparse); 21 | Console.WriteLine($"Tile order: {schema.TileOrder()}; Cell order: {schema.CellOrder()}"); 22 | schema.SetDomain(domain); 23 | schema.AddAttribute(Attribute.Create(Ctx, "a1")); 24 | 25 | Array.Create(Ctx, ArrayPath, schema); 26 | } 27 | 28 | private static void WriteArray() 29 | { 30 | using var array = new Array(Ctx, ArrayPath); 31 | array.Open(QueryType.Write); 32 | using var queryWrite = new Query(array, QueryType.Write); 33 | queryWrite.SetLayout(LayoutType.GlobalOrder); 34 | 35 | // Coordinates for global order writes must be provided in-order 36 | // + We may not write to (2, 1) before (1, 1); (2, 1) comes after (1, 1) in global order 37 | // + We will write 3 values at (1, 1), (2, 1), (2, 4) 38 | queryWrite.SetDataBuffer("rows", new[] { 1, 2, 2 }); 39 | queryWrite.SetDataBuffer("cols", new[] { 1, 1, 4 }); 40 | queryWrite.SetDataBuffer("a1", new[] { 1, 2, 3 }); 41 | queryWrite.Submit(); 42 | Console.WriteLine($"Write query #1 status: {queryWrite.Status()}"); 43 | 44 | // Write 3 more value at coordinates (3, 1), (4, 1), and (4, 4) 45 | queryWrite.SetDataBuffer("rows", new[] { 3, 4, 4 }); 46 | queryWrite.SetDataBuffer("cols", new[] { 1, 1, 4 }); 47 | queryWrite.SetDataBuffer("a1", new[] { 4, 5, 6 }); 48 | queryWrite.Submit(); 49 | Console.WriteLine($"Write query #2 status: {queryWrite.Status()}"); 50 | 51 | // Important: Global order writes must call Query.FinalizeQuery() 52 | queryWrite.FinalizeQuery(); 53 | array.Close(); 54 | } 55 | 56 | private static void ReadArray() 57 | { 58 | using var array = new Array(Ctx, ArrayPath); 59 | array.Open(QueryType.Read); 60 | using var readQuery = new Query(array, QueryType.Read); 61 | using var subarray = new Subarray(array); 62 | subarray.SetSubarray(1, 4, 1, 4); 63 | readQuery.SetSubarray(subarray); 64 | 65 | var rowsRead = new int[6]; 66 | var colsRead = new int[6]; 67 | var a1Read = new int[6]; 68 | readQuery.SetDataBuffer("rows", rowsRead); 69 | readQuery.SetDataBuffer("cols", colsRead); 70 | readQuery.SetDataBuffer("a1", a1Read); 71 | readQuery.Submit(); 72 | Console.WriteLine($"Read query status: {readQuery.Status()}"); 73 | var coordsRead = rowsRead.Zip(colsRead); 74 | var dataRead = coordsRead.Zip(a1Read); 75 | Console.WriteLine($"a1 data: {string.Join(", ", dataRead)}"); 76 | 77 | array.Close(); 78 | } 79 | 80 | public static void Run() 81 | { 82 | if (Directory.Exists(ArrayPath)) 83 | { 84 | Directory.Delete(ArrayPath, true); 85 | } 86 | 87 | CreateArray(); 88 | WriteArray(); 89 | ReadArray(); 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /examples/TileDB.CSharp.Example/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using TileDB.CSharp; 4 | namespace TileDB.CSharp.Examples; 5 | 6 | static class Program 7 | { 8 | static void Main(string[] args) 9 | { 10 | Console.WriteLine("TileDB Core Version: {0}", CoreUtil.GetCoreLibVersion()); 11 | 12 | ExampleQuery.Run(); 13 | ExampleIncompleteQuery.Run(); 14 | ExampleIncompleteQueryStringDimensions.Run(); 15 | ExampleIncompleteQueryVariableSize.Run(); 16 | ExampleWritingDenseGlobal.Run(); 17 | ExampleWritingSparseGlobal.Run(); 18 | ExampleDataframe.Run(); 19 | ExampleAggregateQuery.Run(); 20 | ExampleVFS.Run(); 21 | 22 | ExampleFile.RunLocal(); 23 | // ExampleFile.RunCloud("tiledb_api_token", "tiledb_namespace", "new_cloud_array_name", "s3://bucket/prefix/"); 24 | 25 | ExampleGroup.RunLocal(); 26 | // ExampleGroup.RunCloud("tiledb_api_token", "tiledb_namespace", "s3://bucket/prefix"); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /examples/TileDB.CSharp.Example/TileDB.CSharp.Example.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | enable 4 | Exe 5 | Major 6 | TileDB.CSharp.Examples 7 | net8.0 8 | true 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /global.json: -------------------------------------------------------------------------------- 1 | { 2 | "sdk": { 3 | "version": "8.0.400", 4 | "rollForward": "major" 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /notebooks/README.md: -------------------------------------------------------------------------------- 1 | # This directory contains .net interactive notebook demos 2 | ## Suggested extensions for VS Code 3 | 1. C# by Microsoft 4 | 2. .NET Interactive Notebooks by Microsoft 5 | 3. C# Extensions by JosKreativ 6 | 4. NuGet Package Manager by jmrog 7 | 8 | ## Add TileDB.CSharp in notebook 9 | ``` 10 | #r "nuget:TileDB.CSharp" 11 | ``` -------------------------------------------------------------------------------- /nuget.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /scripts/generate-bindings/README.md: -------------------------------------------------------------------------------- 1 | # Generating TileDB native bindings 2 | 3 | `GenerateBindings.proj` contains an MSBuild script that downloads the header files for a given version and uses `ClangSharpPInvokeGenerator` to generate the C# bindings to the TileDB C API. 4 | 5 | ## Prerequisites 6 | 7 | You need to go to [TileDB's GitHub Releases page](https://github.com/TileDB-Inc/TileDB/releases) and find the version and 7-digit commit ID for your release. 8 | 9 | ## Automatic generation 10 | 11 | The easiest way to generate bindings is by dispatching the [`generate-bindings` workflow](../../.github/workflows/generate-bindings.yml). It will run the script and submit a Pull Request with the changes. 12 | 13 | ## Manual generation 14 | 15 | The script can be ran locally with the `dotnet msbuild ./scripts/generate-bindings/GenerateBindings.proj -p:Version= -p:VersionTag= /restore` command. 16 | 17 | Only Windows is supported. 18 | -------------------------------------------------------------------------------- /scripts/generate-bindings/header.txt: -------------------------------------------------------------------------------- 1 | // 2 | -------------------------------------------------------------------------------- /scripts/nuget/README.md: -------------------------------------------------------------------------------- 1 | # TileDB native NuGet package generator 2 | 3 | This directory contains a script that: 4 | 5 | * Downloads the Core binaries from GitHub Releases. 6 | * Creates one NuGet package for each supported platform. 7 | * Creates one NuGet metapackage that routes to the packages above according to the platform. 8 | 9 | The script's source is in `GenerateNuGetPackages.proj`. The other files specify the properties of the packages. 10 | 11 | ## Usage 12 | 13 | ``` 14 | dotnet pack ./GenerateNuGetPackages.proj -p:Version= -p:VersionTag= 15 | ``` 16 | 17 | > `version-tag` is the seven-character commit hash of the release. 18 | 19 | The packages will be written in the `packages` subdirectory. You can change the output path with the `-p:OutDir=` option. 20 | 21 | The script is incremental, which means that it will try to avoid doing work that is already done. To be extra sure that no stale data is being used, run `dotnet clean` before packing. 22 | 23 | ## Supporting new platforms 24 | 25 | At the beginning of the file there is an `ItemGroup` that specifies `NativePlatform` items. To add support for a new platform you have to add a new item to this group. These are the metadata you have to define: 26 | 27 | |Name|Value| 28 | |----|-----| 29 | |`Include` (referred in the script as `Identity`; technically not part of metadata)|The platform's name as written in the GitHub Releases.| 30 | |`RuntimeId`|The platform's [.NET Runtime Identifier](https://learn.microsoft.com/en-us/dotnet/core/rid-catalog).| 31 | |`LibraryPath`|The native library's path, relative from the downloaded GitHub Releases artifact.| 32 | |`ArchiveExtension`|The artifact archive's extension, without the leading dot. Optional, defaults to `tar.gz`.| 33 | 34 | ## Development packages 35 | 36 | The script also supports generating development editions of the packages. This is used in nightly builds to allow testing with the binaries built from the `dev` and `release` branches. They have `Local.` prepended to their ID and their version is always `0.0.0-local+`. The build metadata that come after the `+` are used for informative purposes and are not a required part of the package's version. 37 | 38 | Grabbing the development packages from the nightly build's artifacts is preferred over manually creating them, but if you want to (for example to test Core binaries from a different branch), you can follow these steps: 39 | 40 | 1. Build the Core. 41 | 2. Copy the Core's `dist` folder to the `temp` subdirectory of this repository, renaming it to the _GitHub Releases_ name of the platform. 42 | 3. Run `dotnet pack -p:DevelopmentBuild=true -p:VersionTag=`. `VersionTag` is optional. 43 | 44 | When building development packages you don't have to include the artifacts for all platforms; the script will skip those whose artifacts do not exist. 45 | -------------------------------------------------------------------------------- /scripts/nuget/TileDB.Native.nuspec: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | $idPrefix$TileDB.Native 5 | $version$ 6 | TileDB Inc 7 | false 8 | MIT 9 | logo.png 10 | https://tiledb.com/products/tiledb-embedded/ 11 | 12 | The TileDB Embedded library. This is a metapackage that will route to the appropriate native package based on the runtime identifier. 13 | https://github.com/TileDB-Inc/TileDB/releases 14 | tiledb 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /scripts/nuget/TileDB.Native.proj: -------------------------------------------------------------------------------- 1 | 2 | 3 | true 4 | false 5 | true 6 | netstandard2.0 7 | TileDB.Native.nuspec 8 | idPrefix=$(PackageIdPrefix);version=$(Version) 9 | 10 | 11 | -------------------------------------------------------------------------------- /scripts/nuget/TileDB.Native.runtime.template.nuspec: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | $idPrefix$TileDB.Native.runtime.$rid$ 5 | $version$ 6 | TileDB Inc 7 | false 8 | MIT 9 | logo.png 10 | https://tiledb.com/products/tiledb-embedded/ 11 | 12 | Native binaries of TileDB Embedded for $rid$. 13 | https://github.com/TileDB-Inc/TileDB/releases 14 | tiledb 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /scripts/nuget/TileDB.Native.runtime.template.proj: -------------------------------------------------------------------------------- 1 | 2 | 3 | true 4 | false 5 | true 6 | netstandard2.0 7 | TileDB.Native.runtime.template.nuspec 8 | idPrefix=$(PackageIdPrefix);rid=$(RuntimeId);version=$(Version);nativelib=$(NativeLibraryPath) 9 | 10 | 11 | -------------------------------------------------------------------------------- /sources/NuGet.props: -------------------------------------------------------------------------------- 1 | 2 | 3 | TileDB Inc 4 | MIT 5 | logo.png 6 | https://tiledb.com/products/tiledb-embedded/ 7 | https://github.com/TileDB-Inc/TileDB-CSharp/releases 8 | tiledb 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /sources/TileDB.CSharp/AggregateOperation.cs: -------------------------------------------------------------------------------- 1 | using TileDB.CSharp.Marshalling.SafeHandles; 2 | using TileDB.Interop; 3 | 4 | namespace TileDB.CSharp; 5 | 6 | /// 7 | /// Represents an aggregate operation. 8 | /// 9 | /// 10 | /// This class abstracts the tiledb_channel_operation_t type of the TileDB C API. 11 | /// 12 | public abstract class AggregateOperation 13 | { 14 | // Prevent inheriting the class outside of this assembly. 15 | private protected AggregateOperation() { } 16 | 17 | /// 18 | /// Creates a unary aggregate operation. 19 | /// 20 | /// The to apply. 21 | /// The name of the field to apply the operator to. 22 | public static AggregateOperation Unary(AggregateOperator op, string fieldName) => new UnaryAggregateOperation(op, fieldName); 23 | 24 | /// 25 | /// An returning the number of values in the channel. 26 | /// 27 | public static AggregateOperation Count { get; } = new CountAggregateOperation(); 28 | 29 | internal abstract unsafe ChannelOperationHandle CreateHandle(Context ctx, Query q); 30 | 31 | private sealed class UnaryAggregateOperation : AggregateOperation 32 | { 33 | private readonly AggregateOperator _operator; 34 | 35 | private readonly string _fieldName; 36 | 37 | public UnaryAggregateOperation(AggregateOperator op, string fieldName) 38 | { 39 | _operator = op; 40 | _fieldName = fieldName; 41 | } 42 | 43 | internal override unsafe ChannelOperationHandle CreateHandle(Context ctx, Query q) 44 | { 45 | var handle = new ChannelOperationHandle(); 46 | bool successful = false; 47 | tiledb_channel_operation_t* op = null; 48 | try 49 | { 50 | using var ctxHandle = ctx.Handle.Acquire(); 51 | using var queryHandle = q.Handle.Acquire(); 52 | using var ms_fieldName = new MarshaledString(_fieldName); 53 | ctx.handle_error(Methods.tiledb_create_unary_aggregate(ctxHandle, queryHandle, _operator.GetHandle(ctxHandle), ms_fieldName, &op)); 54 | successful = true; 55 | } 56 | finally 57 | { 58 | if (successful) 59 | { 60 | handle.InitHandle(ctx, op); 61 | } 62 | else 63 | { 64 | handle.SetHandleAsInvalid(); 65 | } 66 | } 67 | return handle; 68 | } 69 | } 70 | 71 | private sealed class CountAggregateOperation : AggregateOperation 72 | { 73 | internal override unsafe ChannelOperationHandle CreateHandle(Context ctx, Query q) 74 | { 75 | var handle = new ChannelOperationHandle(); 76 | bool successful = false; 77 | tiledb_channel_operation_t* op = null; 78 | try 79 | { 80 | using var ctxHandle = ctx.Handle.Acquire(); 81 | ctx.handle_error(Methods.tiledb_aggregate_count_get(ctxHandle, &op)); 82 | successful = true; 83 | } 84 | finally 85 | { 86 | if (successful) 87 | { 88 | handle.InitHandle(ctx, op); 89 | } 90 | else 91 | { 92 | handle.SetHandleAsInvalid(); 93 | } 94 | } 95 | return handle; 96 | } 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /sources/TileDB.CSharp/AggregateOperator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using TileDB.Interop; 3 | 4 | namespace TileDB.CSharp; 5 | 6 | /// 7 | /// Represents an aggregate operator that can be applied over a query field. 8 | /// 9 | /// 10 | /// This class abstracts the tiledb_channel_operator_t type of the TileDB C API. 11 | /// 12 | public abstract class AggregateOperator 13 | { 14 | // Prevent inheriting the class outside of this assembly. 15 | private protected AggregateOperator() { } 16 | 17 | internal abstract unsafe tiledb_channel_operator_t* GetHandle(tiledb_ctx_t* ctx); 18 | 19 | /// 20 | /// Computes the sum of all values in the field. 21 | /// 22 | public static AggregateOperator Sum { get; } = new SimpleAggregateOperator(OperatorKind.Sum); 23 | 24 | /// 25 | /// Computes the minimum value in the field. 26 | /// 27 | public static AggregateOperator Min { get; } = new SimpleAggregateOperator(OperatorKind.Min); 28 | 29 | /// 30 | /// Computes the maximum value in the field. 31 | /// 32 | public static AggregateOperator Max { get; } = new SimpleAggregateOperator(OperatorKind.Max); 33 | 34 | /// 35 | /// Computes the mean of all values in the field. 36 | /// 37 | public static AggregateOperator Mean { get; } = new SimpleAggregateOperator(OperatorKind.Mean); 38 | 39 | /// 40 | /// Counts the number of null values in the field. 41 | /// 42 | public static AggregateOperator NullCount { get; } = new SimpleAggregateOperator(OperatorKind.NullCount); 43 | 44 | private enum OperatorKind 45 | { 46 | Sum, 47 | Min, 48 | Max, 49 | Mean, 50 | NullCount 51 | } 52 | 53 | private sealed class SimpleAggregateOperator : AggregateOperator 54 | { 55 | private readonly OperatorKind _kind; 56 | 57 | public SimpleAggregateOperator(OperatorKind kind) 58 | { 59 | _kind = kind; 60 | } 61 | 62 | internal override unsafe tiledb_channel_operator_t* GetHandle(tiledb_ctx_t* ctx) 63 | { 64 | tiledb_channel_operator_t* op; 65 | var ret = _kind switch 66 | { 67 | OperatorKind.Sum => Methods.tiledb_channel_operator_sum_get(ctx, &op), 68 | OperatorKind.Min => Methods.tiledb_channel_operator_min_get(ctx, &op), 69 | OperatorKind.Max => Methods.tiledb_channel_operator_max_get(ctx, &op), 70 | OperatorKind.Mean => Methods.tiledb_channel_operator_mean_get(ctx, &op), 71 | OperatorKind.NullCount => Methods.tiledb_channel_operator_null_count_get(ctx, &op), 72 | _ => throw new InvalidOperationException(), 73 | }; 74 | ErrorHandling.ThrowOnError(ret); 75 | return op; 76 | } 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /sources/TileDB.CSharp/CompatibilitySuppressions.xml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | PKV006 6 | net5.0 7 | 8 | -------------------------------------------------------------------------------- /sources/TileDB.CSharp/ConfigIterator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using TileDB.CSharp.Marshalling.SafeHandles; 4 | using TileDB.Interop; 5 | using ConfigHandle = TileDB.CSharp.Marshalling.SafeHandles.ConfigHandle; 6 | using ConfigIteratorHandle = TileDB.CSharp.Marshalling.SafeHandles.ConfigIteratorHandle; 7 | 8 | namespace TileDB.CSharp; 9 | 10 | [Obsolete(Obsoletions.ConfigIteratorMessage, DiagnosticId = Obsoletions.ConfigIteratorDiagId, UrlFormat = Obsoletions.SharedUrlFormat)] 11 | public sealed unsafe class ConfigIterator : IDisposable 12 | { 13 | private readonly ConfigIteratorHandle _handle; 14 | private readonly ConfigHandle _hConfig; 15 | private bool _disposed; 16 | 17 | internal ConfigIterator(ConfigHandle hConfig, string prefix) 18 | { 19 | _hConfig = hConfig; 20 | _handle = ConfigIteratorHandle.Create(hConfig, prefix); 21 | } 22 | 23 | public void Dispose() 24 | { 25 | Dispose(true); 26 | } 27 | 28 | private void Dispose(bool disposing) 29 | { 30 | if (_disposed) return; 31 | if (disposing && (!_handle.IsInvalid)) 32 | { 33 | _handle.Dispose(); 34 | } 35 | 36 | _disposed = true; 37 | } 38 | 39 | internal ConfigIteratorHandle Handle => _handle; 40 | 41 | // Internal overload that returns KVP to avoid the Tuple allocation. 42 | internal KeyValuePair HereImpl() 43 | { 44 | tiledb_error_t* p_tiledb_error; 45 | sbyte* paramPtr; 46 | sbyte* valuePtr; 47 | int status; 48 | using (var handle = _handle.Acquire()) 49 | { 50 | status = Methods.tiledb_config_iter_here(handle, ¶mPtr, &valuePtr, &p_tiledb_error); 51 | } 52 | 53 | ErrorHandling.CheckLastError(&p_tiledb_error, status); 54 | 55 | string param = MarshaledStringOut.GetStringFromNullTerminated(paramPtr); 56 | string value = MarshaledStringOut.GetStringFromNullTerminated(valuePtr); 57 | return new KeyValuePair(param, value); 58 | } 59 | 60 | public Tuple Here() 61 | { 62 | var here = HereImpl(); 63 | return new Tuple(here.Key, here.Value); 64 | } 65 | 66 | public void Next() 67 | { 68 | tiledb_error_t* p_tiledb_error; 69 | int status; 70 | using (var handle = _handle.Acquire()) 71 | { 72 | status = Methods.tiledb_config_iter_next(handle, &p_tiledb_error); 73 | } 74 | ErrorHandling.CheckLastError(&p_tiledb_error, status); 75 | } 76 | 77 | public bool Done() 78 | { 79 | tiledb_error_t* p_tiledb_error; 80 | int c_done; 81 | int status; 82 | using (var handle = _handle.Acquire()) 83 | { 84 | status = Methods.tiledb_config_iter_done(handle, &c_done, &p_tiledb_error); 85 | } 86 | ErrorHandling.CheckLastError(&p_tiledb_error, status); 87 | return c_done == 1; 88 | } 89 | 90 | public void Reset(string prefix) 91 | { 92 | tiledb_error_t* p_tiledb_error; 93 | using var ms_prefix = new MarshaledString(prefix); 94 | int status; 95 | using (var configHandle = _hConfig.Acquire()) 96 | using (var handle = _handle.Acquire()) 97 | { 98 | status = Methods.tiledb_config_iter_reset(configHandle, handle, ms_prefix, &p_tiledb_error); 99 | } 100 | ErrorHandling.CheckLastError(&p_tiledb_error, status); 101 | } 102 | } 103 | -------------------------------------------------------------------------------- /sources/TileDB.CSharp/ErrorHandling.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Diagnostics; 3 | using System.Diagnostics.CodeAnalysis; 4 | using System.Runtime.CompilerServices; 5 | using System.Text; 6 | using TileDB.Interop; 7 | 8 | namespace TileDB.CSharp; 9 | 10 | internal static class ErrorHandling 11 | { 12 | public static void ThrowIfNull([NotNull] object? obj, [CallerArgumentExpression(nameof(obj))] string? paramName = null) 13 | { 14 | if (obj == null) 15 | { 16 | ThrowHelpers.ThrowArgumentNull(paramName); 17 | } 18 | } 19 | 20 | public static void ThrowOnError(int errorCode) 21 | { 22 | if (errorCode == (int)Status.TILEDB_OK) 23 | { 24 | return; 25 | } 26 | throw new TileDBException($"Operation failed with error code {errorCode}.") { StatusCode = errorCode }; 27 | } 28 | 29 | public static unsafe void CheckLastError(tiledb_error_t** error, int status) 30 | { 31 | if (status == (int)Status.TILEDB_OK) 32 | { 33 | Debug.Assert(*error is null); 34 | return; 35 | } 36 | 37 | ThrowLastError(error, status); 38 | 39 | [DoesNotReturn] 40 | static void ThrowLastError(tiledb_error_t** error, int status) 41 | { 42 | sbyte* messagePtr; 43 | int messageResult = Methods.tiledb_error_message(*error, &messagePtr); 44 | Debug.Assert(messageResult == (int)Status.TILEDB_OK); 45 | string message = MarshaledStringOut.GetStringFromNullTerminated(messagePtr); 46 | Methods.tiledb_error_free(error); 47 | throw new TileDBException(message) { StatusCode = status }; 48 | } 49 | } 50 | 51 | /// is managed. 52 | public static void ThrowIfManagedType() 53 | { 54 | if (RuntimeHelpers.IsReferenceOrContainsReferences()) 55 | { 56 | ThrowHelpers.ThrowManagedType(); 57 | } 58 | } 59 | 60 | /// 61 | /// Returns whether values of type can be stored or 62 | /// retrieved from a TileDB buffer of type . 63 | /// 64 | private static unsafe bool AreTypesCompatible(DataType dataType) 65 | { 66 | if (EnumUtil.DataTypeToNumericType(dataType) == typeof(T)) 67 | { 68 | return true; 69 | } 70 | if (typeof(T) == typeof(bool) && dataType == DataType.Boolean) 71 | { 72 | return true; 73 | } 74 | if (typeof(T) == typeof(char) && dataType == DataType.StringUtf16) 75 | { 76 | return true; 77 | } 78 | return false; 79 | } 80 | 81 | /// 82 | /// Throws if values of type cannot be stored or 83 | /// retrieved from a TileDB buffer of type . 84 | /// 85 | public static void CheckDataType(DataType dataType) 86 | { 87 | ThrowIfManagedType(); 88 | if (!AreTypesCompatible(dataType)) 89 | { 90 | ThrowHelpers.ThrowTypeMismatch(dataType); 91 | } 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /sources/TileDB.CSharp/FileStoreUtil.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace TileDB.CSharp; 8 | 9 | public static class FileStoreUtil 10 | { 11 | public static void SaveFileToArray(Context ctx, string array_uri, string file) 12 | { 13 | if (string.IsNullOrEmpty(array_uri) || string.IsNullOrEmpty(file)) 14 | { 15 | return; 16 | } 17 | 18 | if (ctx == null) 19 | { 20 | Config cfg = new Config(); 21 | ctx = new Context(cfg); 22 | } 23 | 24 | File f = new File(ctx); 25 | var arraySchema = f.SchemaCreate(file); 26 | Array.Create(ctx, array_uri, arraySchema); 27 | f.URIImport( 28 | array_uri, 29 | file, 30 | MIMEType.AutoDetect 31 | ); 32 | } 33 | 34 | public static void SaveFileToCloudArray(Context ctx, string name_space, string array_uri, string file) 35 | { 36 | if (string.IsNullOrEmpty(name_space) || string.IsNullOrEmpty(array_uri) || string.IsNullOrEmpty(file)) 37 | { 38 | return; 39 | } 40 | 41 | if (ctx == null) 42 | { 43 | Config cfg = new Config(); 44 | ctx = new Context(cfg); 45 | } 46 | 47 | var array_name = array_uri.Split('/').Last(); 48 | var uri_create = string.Format("tiledb://{0}/{1}", name_space, array_uri); 49 | var uri_write = string.Format("tiledb://{0}/{1}", name_space, array_name); 50 | 51 | File f = new File(ctx); 52 | var arraySchema = f.SchemaCreate(file); 53 | Array.Create(ctx, uri_create, arraySchema); 54 | f.URIImport( 55 | uri_write, 56 | file, 57 | MIMEType.AutoDetect 58 | ); 59 | } 60 | 61 | public static void ExportArrayToFile(Context ctx, string file, string array_uri) 62 | { 63 | if (string.IsNullOrEmpty(array_uri) || string.IsNullOrEmpty(file)) 64 | { 65 | return; 66 | } 67 | if (ctx == null) 68 | { 69 | Config cfg = new Config(); 70 | ctx = new Context(cfg); 71 | } 72 | 73 | File f = new File(ctx); 74 | f.URIExport( 75 | file, 76 | array_uri 77 | ); 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /sources/TileDB.CSharp/Filter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Runtime.InteropServices; 4 | using TileDB.CSharp.Marshalling.SafeHandles; 5 | using TileDB.Interop; 6 | using FilterHandle = TileDB.CSharp.Marshalling.SafeHandles.FilterHandle; 7 | 8 | namespace TileDB.CSharp; 9 | 10 | public sealed unsafe class Filter : IDisposable 11 | { 12 | 13 | private readonly FilterHandle _handle; 14 | private readonly Context _ctx; 15 | private bool _disposed; 16 | 17 | 18 | public Filter(Context ctx, FilterType filterType) 19 | { 20 | _ctx = ctx; 21 | _handle = FilterHandle.Create(_ctx, (tiledb_filter_type_t)(filterType)); 22 | } 23 | 24 | internal Filter(Context ctx, FilterHandle handle) 25 | { 26 | _ctx = ctx; 27 | _handle = handle; 28 | } 29 | 30 | 31 | public void Dispose() 32 | { 33 | Dispose(true); 34 | } 35 | 36 | private void Dispose(bool disposing) 37 | { 38 | if (_disposed) return; 39 | if (disposing && (!_handle.IsInvalid)) 40 | { 41 | _handle.Dispose(); 42 | } 43 | 44 | _disposed = true; 45 | } 46 | 47 | internal FilterHandle Handle => _handle; 48 | 49 | /// 50 | /// Get filter type. 51 | /// 52 | /// 53 | public FilterType FilterType() 54 | { 55 | var tiledb_filter_type= tiledb_filter_type_t.TILEDB_FILTER_NONE; 56 | using var ctxHandle = _ctx.Handle.Acquire(); 57 | using var handle = _handle.Acquire(); 58 | _ctx.handle_error(Methods.tiledb_filter_get_type(ctxHandle, handle, &tiledb_filter_type)); 59 | return (FilterType)tiledb_filter_type; 60 | } 61 | 62 | /// 63 | /// Check expected type for filter option matches type of T 64 | /// 65 | /// Type of filter option value 66 | /// Filter option to run type check against 67 | /// Filter option does not support values of type T 68 | private void check_filter_option(FilterOption filterOption) 69 | { 70 | //check for filter option 71 | var ok = 72 | (filterOption == FilterOption.CompressionLevel && typeof(T) == typeof(int)) || 73 | (filterOption == FilterOption.BitWidthMaxWindow && typeof(T) == typeof(uint)) || 74 | (filterOption == FilterOption.PositiveDeltaMaxWindow && typeof(T) == typeof(uint)) || 75 | (filterOption == FilterOption.ScaleFloatByteWidth && typeof(T) == typeof(ulong)) || 76 | (filterOption == FilterOption.ScaleFloatFactor && typeof(T) == typeof(double)) || 77 | (filterOption == FilterOption.ScaleFloatOffset && typeof(T) == typeof(double)) || 78 | (filterOption == FilterOption.WebpQuality && typeof(T) == typeof(float)) || 79 | (filterOption == FilterOption.WebpInputFormat && typeof(T) == typeof(WebpInputFormat)) || 80 | (filterOption == FilterOption.WebpLossless && typeof(T) == typeof(bool)) || 81 | (filterOption == FilterOption.CompressionReinterpretDatatype && typeof(T) == typeof(DataType)); 82 | 83 | if (!ok) 84 | { 85 | throw new NotSupportedException($"Unsupported type for filter option: {filterOption}"); 86 | } 87 | } 88 | 89 | /// 90 | /// Set filter option. 91 | /// 92 | /// Type of option value we intend to set 93 | /// Filter option to set 94 | /// Filter option value 95 | public void SetOption(FilterOption filterOption, T value) where T: struct 96 | { 97 | //check for filter option 98 | check_filter_option(filterOption); 99 | 100 | using var ctxHandle = _ctx.Handle.Acquire(); 101 | using var handle = _handle.Acquire(); 102 | var tiledb_filter_option = (tiledb_filter_option_t)filterOption; 103 | _ctx.handle_error(Methods.tiledb_filter_set_option(ctxHandle, handle, tiledb_filter_option, &value)); 104 | } 105 | 106 | /// 107 | /// Get filter option. 108 | /// 109 | /// Type of option value we intend to get 110 | /// Filter option to get 111 | public T GetOption(FilterOption filterOption) where T: struct 112 | { 113 | //check for filter option 114 | check_filter_option(filterOption); 115 | 116 | var tiledb_filter_option = (tiledb_filter_option_t)filterOption; 117 | 118 | T result; 119 | using var ctxHandle = _ctx.Handle.Acquire(); 120 | using var handle = _handle.Acquire(); 121 | _ctx.handle_error(Methods.tiledb_filter_get_option(ctxHandle, handle, tiledb_filter_option, &result)); 122 | 123 | return result; 124 | } 125 | } 126 | -------------------------------------------------------------------------------- /sources/TileDB.CSharp/FilterList.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using TileDB.CSharp.Marshalling.SafeHandles; 3 | using TileDB.Interop; 4 | using FilterHandle = TileDB.CSharp.Marshalling.SafeHandles.FilterHandle; 5 | using FilterListHandle = TileDB.CSharp.Marshalling.SafeHandles.FilterListHandle; 6 | 7 | namespace TileDB.CSharp; 8 | 9 | public sealed unsafe class FilterList : IDisposable 10 | { 11 | private readonly FilterListHandle _handle; 12 | private readonly Context _ctx; 13 | private bool _disposed; 14 | 15 | public FilterList(Context ctx) 16 | { 17 | _ctx = ctx; 18 | _handle = FilterListHandle.Create(_ctx); 19 | } 20 | 21 | internal FilterList(Context ctx, FilterListHandle handle) 22 | { 23 | _ctx = ctx; 24 | _handle = handle; 25 | } 26 | 27 | public void Dispose() 28 | { 29 | Dispose(true); 30 | } 31 | 32 | private void Dispose(bool disposing) 33 | { 34 | if (_disposed) return; 35 | if (disposing && (!_handle.IsInvalid)) 36 | { 37 | _handle.Dispose(); 38 | } 39 | 40 | _disposed = true; 41 | } 42 | 43 | internal FilterListHandle Handle => _handle; 44 | 45 | /// 46 | /// Add a filter. 47 | /// 48 | /// 49 | public void AddFilter(Filter filter) 50 | { 51 | using var ctxHandle = _ctx.Handle.Acquire(); 52 | using var handle = _handle.Acquire(); 53 | using var filterHandle = filter.Handle.Acquire(); 54 | _ctx.handle_error(Methods.tiledb_filter_list_add_filter(ctxHandle, handle, filterHandle)); 55 | } 56 | 57 | /// 58 | /// Set maximum chunk size. 59 | /// 60 | /// 61 | public void SetMaxChunkSize(uint maxChunkSize) 62 | { 63 | using var ctxHandle = _ctx.Handle.Acquire(); 64 | using var handle = _handle.Acquire(); 65 | _ctx.handle_error(Methods.tiledb_filter_list_set_max_chunk_size(ctxHandle, handle, maxChunkSize)); 66 | } 67 | 68 | /// 69 | /// Get maximum chunk size. 70 | /// 71 | /// 72 | public uint MaxChunkSize() 73 | { 74 | using var ctxHandle = _ctx.Handle.Acquire(); 75 | using var handle = _handle.Acquire(); 76 | uint result; 77 | _ctx.handle_error(Methods.tiledb_filter_list_get_max_chunk_size(ctxHandle, handle, &result)); 78 | return result; 79 | } 80 | 81 | /// 82 | /// Get number of filter. 83 | /// 84 | /// 85 | public uint NFilters() 86 | { 87 | using var ctxHandle = _ctx.Handle.Acquire(); 88 | using var handle = _handle.Acquire(); 89 | uint result; 90 | _ctx.handle_error(Methods.tiledb_filter_list_get_nfilters(ctxHandle, handle, &result)); 91 | return result; 92 | } 93 | 94 | /// 95 | /// Get filter from index. 96 | /// 97 | /// 98 | /// 99 | public Filter Filter(uint filterIndex) 100 | { 101 | var handle = new FilterHandle(); 102 | var successful = false; 103 | tiledb_filter_t* filter_p = null; 104 | try 105 | { 106 | using (var ctxHandle = _ctx.Handle.Acquire()) 107 | using (var filterListHandle = _handle.Acquire()) 108 | { 109 | _ctx.handle_error(Methods.tiledb_filter_list_get_filter_from_index(ctxHandle, filterListHandle, filterIndex, &filter_p)); 110 | } 111 | successful = true; 112 | } 113 | finally 114 | { 115 | if (successful) 116 | { 117 | handle.InitHandle(filter_p); 118 | } 119 | else 120 | { 121 | handle.SetHandleAsInvalid(); 122 | } 123 | } 124 | 125 | return new Filter(_ctx, handle); 126 | } 127 | 128 | } 129 | -------------------------------------------------------------------------------- /sources/TileDB.CSharp/Interop/InteropAux.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel; 2 | using System; 3 | using TileDB.CSharp; 4 | 5 | namespace TileDB.Interop 6 | { 7 | [Obsolete(Obsoletions.TileDBInterop2Message, DiagnosticId = Obsoletions.TileDBInterop2DiagId, UrlFormat = Obsoletions.SharedUrlFormat)] 8 | [EditorBrowsable(EditorBrowsableState.Never)] 9 | // placeholder struct to avoid errors loading generated code 10 | public partial struct __sFILE 11 | { 12 | } 13 | } -------------------------------------------------------------------------------- /sources/TileDB.CSharp/Interop/SpanExtensions.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information. 2 | //https://github.com/dotnet/ClangSharp/blob/67c1e5243b9d58f2b28f10e3f9a82f7537fd9d88/sources/ClangSharp.Interop/Internals/SpanExtensions.cs 3 | 4 | using System; 5 | using System.ComponentModel; 6 | using System.Text; 7 | using TileDB.CSharp; 8 | 9 | namespace TileDB.Interop 10 | { 11 | [Obsolete(Obsoletions.TileDBInterop2Message, DiagnosticId = Obsoletions.TileDBInterop2DiagId, UrlFormat = Obsoletions.SharedUrlFormat)] 12 | [EditorBrowsable(EditorBrowsableState.Never)] 13 | public static unsafe class SpanExtensions 14 | { 15 | public static string AsString(this Span self) => AsString((ReadOnlySpan)self); 16 | 17 | public static string AsString(this ReadOnlySpan self) 18 | { 19 | if (self.IsEmpty) 20 | { 21 | return string.Empty; 22 | } 23 | 24 | fixed (byte* pSelf = self) 25 | { 26 | return Encoding.ASCII.GetString(pSelf, self.Length); 27 | } 28 | } 29 | } 30 | 31 | }//namespace -------------------------------------------------------------------------------- /sources/TileDB.CSharp/Interop/tiledb_array_schema_evolution_t.cs: -------------------------------------------------------------------------------- 1 | // 2 | 3 | using System.ComponentModel; 4 | using System; 5 | using TileDB.CSharp; 6 | 7 | namespace TileDB.Interop 8 | { 9 | [Obsolete(Obsoletions.TileDBInterop2Message, DiagnosticId = Obsoletions.TileDBInterop2DiagId, UrlFormat = Obsoletions.SharedUrlFormat)] 10 | [EditorBrowsable(EditorBrowsableState.Never)] 11 | public partial struct tiledb_array_schema_evolution_t 12 | { 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /sources/TileDB.CSharp/Interop/tiledb_array_schema_t.cs: -------------------------------------------------------------------------------- 1 | // 2 | 3 | using System.ComponentModel; 4 | using System; 5 | using TileDB.CSharp; 6 | 7 | namespace TileDB.Interop 8 | { 9 | [Obsolete(Obsoletions.TileDBInterop2Message, DiagnosticId = Obsoletions.TileDBInterop2DiagId, UrlFormat = Obsoletions.SharedUrlFormat)] 10 | [EditorBrowsable(EditorBrowsableState.Never)] 11 | public partial struct tiledb_array_schema_t 12 | { 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /sources/TileDB.CSharp/Interop/tiledb_array_t.cs: -------------------------------------------------------------------------------- 1 | // 2 | 3 | using System.ComponentModel; 4 | using System; 5 | using TileDB.CSharp; 6 | 7 | namespace TileDB.Interop 8 | { 9 | [Obsolete(Obsoletions.TileDBInterop2Message, DiagnosticId = Obsoletions.TileDBInterop2DiagId, UrlFormat = Obsoletions.SharedUrlFormat)] 10 | [EditorBrowsable(EditorBrowsableState.Never)] 11 | public partial struct tiledb_array_t 12 | { 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /sources/TileDB.CSharp/Interop/tiledb_array_type_t.cs: -------------------------------------------------------------------------------- 1 | // 2 | 3 | using System; 4 | using System.ComponentModel; 5 | using TileDB.CSharp; 6 | 7 | namespace TileDB.Interop 8 | { 9 | [Obsolete(Obsoletions.TileDBInterop3Message, DiagnosticId = Obsoletions.TileDBInterop3DiagId, UrlFormat = Obsoletions.SharedUrlFormat)] 10 | [EditorBrowsable(EditorBrowsableState.Never)] 11 | public enum tiledb_array_type_t 12 | { 13 | TILEDB_DENSE = 0, 14 | TILEDB_SPARSE = 1, 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /sources/TileDB.CSharp/Interop/tiledb_attribute_t.cs: -------------------------------------------------------------------------------- 1 | // 2 | 3 | using System.ComponentModel; 4 | using System; 5 | using TileDB.CSharp; 6 | 7 | namespace TileDB.Interop 8 | { 9 | [Obsolete(Obsoletions.TileDBInterop2Message, DiagnosticId = Obsoletions.TileDBInterop2DiagId, UrlFormat = Obsoletions.SharedUrlFormat)] 10 | [EditorBrowsable(EditorBrowsableState.Never)] 11 | public partial struct tiledb_attribute_t 12 | { 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /sources/TileDB.CSharp/Interop/tiledb_buffer_list_t.cs: -------------------------------------------------------------------------------- 1 | // 2 | 3 | namespace TileDB.Interop 4 | { 5 | internal partial struct tiledb_buffer_list_t 6 | { 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /sources/TileDB.CSharp/Interop/tiledb_buffer_t.cs: -------------------------------------------------------------------------------- 1 | // 2 | 3 | namespace TileDB.Interop 4 | { 5 | internal partial struct tiledb_buffer_t 6 | { 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /sources/TileDB.CSharp/Interop/tiledb_channel_operation_t.cs: -------------------------------------------------------------------------------- 1 | // 2 | 3 | namespace TileDB.Interop 4 | { 5 | internal partial struct tiledb_channel_operation_t 6 | { 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /sources/TileDB.CSharp/Interop/tiledb_channel_operator_t.cs: -------------------------------------------------------------------------------- 1 | // 2 | 3 | namespace TileDB.Interop 4 | { 5 | internal partial struct tiledb_channel_operator_t 6 | { 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /sources/TileDB.CSharp/Interop/tiledb_config_iter_t.cs: -------------------------------------------------------------------------------- 1 | // 2 | 3 | using System.ComponentModel; 4 | using System; 5 | using TileDB.CSharp; 6 | 7 | namespace TileDB.Interop 8 | { 9 | [Obsolete(Obsoletions.TileDBInterop2Message, DiagnosticId = Obsoletions.TileDBInterop2DiagId, UrlFormat = Obsoletions.SharedUrlFormat)] 10 | [EditorBrowsable(EditorBrowsableState.Never)] 11 | public partial struct tiledb_config_iter_t 12 | { 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /sources/TileDB.CSharp/Interop/tiledb_config_t.cs: -------------------------------------------------------------------------------- 1 | // 2 | 3 | using System.ComponentModel; 4 | using System; 5 | using TileDB.CSharp; 6 | 7 | namespace TileDB.Interop 8 | { 9 | [Obsolete(Obsoletions.TileDBInterop2Message, DiagnosticId = Obsoletions.TileDBInterop2DiagId, UrlFormat = Obsoletions.SharedUrlFormat)] 10 | [EditorBrowsable(EditorBrowsableState.Never)] 11 | public partial struct tiledb_config_t 12 | { 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /sources/TileDB.CSharp/Interop/tiledb_consolidation_plan_t.cs: -------------------------------------------------------------------------------- 1 | // 2 | 3 | namespace TileDB.Interop 4 | { 5 | internal partial struct tiledb_consolidation_plan_t 6 | { 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /sources/TileDB.CSharp/Interop/tiledb_ctx_t.cs: -------------------------------------------------------------------------------- 1 | // 2 | 3 | using System.ComponentModel; 4 | using System; 5 | using TileDB.CSharp; 6 | 7 | namespace TileDB.Interop 8 | { 9 | [Obsolete(Obsoletions.TileDBInterop2Message, DiagnosticId = Obsoletions.TileDBInterop2DiagId, UrlFormat = Obsoletions.SharedUrlFormat)] 10 | [EditorBrowsable(EditorBrowsableState.Never)] 11 | public partial struct tiledb_ctx_t 12 | { 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /sources/TileDB.CSharp/Interop/tiledb_current_domain_handle_t.cs: -------------------------------------------------------------------------------- 1 | // 2 | 3 | namespace TileDB.Interop 4 | { 5 | internal partial struct tiledb_current_domain_handle_t 6 | { 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /sources/TileDB.CSharp/Interop/tiledb_current_domain_type_t.cs: -------------------------------------------------------------------------------- 1 | // 2 | 3 | namespace TileDB.Interop 4 | { 5 | internal enum tiledb_current_domain_type_t 6 | { 7 | TILEDB_NDRECTANGLE = 0, 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /sources/TileDB.CSharp/Interop/tiledb_data_order_t.cs: -------------------------------------------------------------------------------- 1 | // 2 | 3 | namespace TileDB.Interop 4 | { 5 | internal enum tiledb_data_order_t 6 | { 7 | TILEDB_UNORDERED_DATA = 0, 8 | TILEDB_INCREASING_DATA = 1, 9 | TILEDB_DECREASING_DATA = 2, 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /sources/TileDB.CSharp/Interop/tiledb_datatype_t.cs: -------------------------------------------------------------------------------- 1 | // 2 | 3 | using System; 4 | using System.ComponentModel; 5 | using TileDB.CSharp; 6 | 7 | namespace TileDB.Interop 8 | { 9 | [Obsolete(Obsoletions.TileDBInterop3Message, DiagnosticId = Obsoletions.TileDBInterop3DiagId, UrlFormat = Obsoletions.SharedUrlFormat)] 10 | [EditorBrowsable(EditorBrowsableState.Never)] 11 | public enum tiledb_datatype_t 12 | { 13 | TILEDB_INT32 = 0, 14 | TILEDB_INT64 = 1, 15 | TILEDB_FLOAT32 = 2, 16 | TILEDB_FLOAT64 = 3, 17 | TILEDB_CHAR = 4, 18 | TILEDB_INT8 = 5, 19 | TILEDB_UINT8 = 6, 20 | TILEDB_INT16 = 7, 21 | TILEDB_UINT16 = 8, 22 | TILEDB_UINT32 = 9, 23 | TILEDB_UINT64 = 10, 24 | TILEDB_STRING_ASCII = 11, 25 | TILEDB_STRING_UTF8 = 12, 26 | TILEDB_STRING_UTF16 = 13, 27 | TILEDB_STRING_UTF32 = 14, 28 | TILEDB_STRING_UCS2 = 15, 29 | TILEDB_STRING_UCS4 = 16, 30 | TILEDB_ANY = 17, 31 | TILEDB_DATETIME_YEAR = 18, 32 | TILEDB_DATETIME_MONTH = 19, 33 | TILEDB_DATETIME_WEEK = 20, 34 | TILEDB_DATETIME_DAY = 21, 35 | TILEDB_DATETIME_HR = 22, 36 | TILEDB_DATETIME_MIN = 23, 37 | TILEDB_DATETIME_SEC = 24, 38 | TILEDB_DATETIME_MS = 25, 39 | TILEDB_DATETIME_US = 26, 40 | TILEDB_DATETIME_NS = 27, 41 | TILEDB_DATETIME_PS = 28, 42 | TILEDB_DATETIME_FS = 29, 43 | TILEDB_DATETIME_AS = 30, 44 | TILEDB_TIME_HR = 31, 45 | TILEDB_TIME_MIN = 32, 46 | TILEDB_TIME_SEC = 33, 47 | TILEDB_TIME_MS = 34, 48 | TILEDB_TIME_US = 35, 49 | TILEDB_TIME_NS = 36, 50 | TILEDB_TIME_PS = 37, 51 | TILEDB_TIME_FS = 38, 52 | TILEDB_TIME_AS = 39, 53 | TILEDB_BLOB = 40, 54 | TILEDB_BOOL = 41, 55 | TILEDB_GEOM_WKB = 42, 56 | TILEDB_GEOM_WKT = 43, 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /sources/TileDB.CSharp/Interop/tiledb_dimension_label_t.cs: -------------------------------------------------------------------------------- 1 | // 2 | 3 | namespace TileDB.Interop 4 | { 5 | internal partial struct tiledb_dimension_label_t 6 | { 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /sources/TileDB.CSharp/Interop/tiledb_dimension_t.cs: -------------------------------------------------------------------------------- 1 | // 2 | 3 | using System.ComponentModel; 4 | using System; 5 | using TileDB.CSharp; 6 | 7 | namespace TileDB.Interop 8 | { 9 | [Obsolete(Obsoletions.TileDBInterop2Message, DiagnosticId = Obsoletions.TileDBInterop2DiagId, UrlFormat = Obsoletions.SharedUrlFormat)] 10 | [EditorBrowsable(EditorBrowsableState.Never)] 11 | public partial struct tiledb_dimension_t 12 | { 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /sources/TileDB.CSharp/Interop/tiledb_domain_t.cs: -------------------------------------------------------------------------------- 1 | // 2 | 3 | using System.ComponentModel; 4 | using System; 5 | using TileDB.CSharp; 6 | 7 | namespace TileDB.Interop 8 | { 9 | [Obsolete(Obsoletions.TileDBInterop2Message, DiagnosticId = Obsoletions.TileDBInterop2DiagId, UrlFormat = Obsoletions.SharedUrlFormat)] 10 | [EditorBrowsable(EditorBrowsableState.Never)] 11 | public partial struct tiledb_domain_t 12 | { 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /sources/TileDB.CSharp/Interop/tiledb_encryption_type_t.cs: -------------------------------------------------------------------------------- 1 | // 2 | 3 | namespace TileDB.Interop 4 | { 5 | internal enum tiledb_encryption_type_t 6 | { 7 | TILEDB_NO_ENCRYPTION = 0, 8 | TILEDB_AES_256_GCM = 1, 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /sources/TileDB.CSharp/Interop/tiledb_enumeration_t.cs: -------------------------------------------------------------------------------- 1 | // 2 | 3 | namespace TileDB.Interop 4 | { 5 | internal partial struct tiledb_enumeration_t 6 | { 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /sources/TileDB.CSharp/Interop/tiledb_error_t.cs: -------------------------------------------------------------------------------- 1 | // 2 | 3 | namespace TileDB.Interop 4 | { 5 | internal partial struct tiledb_error_t 6 | { 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /sources/TileDB.CSharp/Interop/tiledb_field_origin_t.cs: -------------------------------------------------------------------------------- 1 | // 2 | 3 | namespace TileDB.Interop 4 | { 5 | internal enum tiledb_field_origin_t 6 | { 7 | TILEDB_ATTRIBUTE_FIELD = 0, 8 | TILEDB_DIMENSION_FIELD, 9 | TILEDB_AGGREGATE_FIELD, 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /sources/TileDB.CSharp/Interop/tiledb_filesystem_t.cs: -------------------------------------------------------------------------------- 1 | // 2 | 3 | namespace TileDB.Interop 4 | { 5 | internal enum tiledb_filesystem_t 6 | { 7 | TILEDB_HDFS = 0, 8 | TILEDB_S3 = 1, 9 | TILEDB_AZURE = 2, 10 | TILEDB_GCS = 3, 11 | TILEDB_MEMFS = 4, 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /sources/TileDB.CSharp/Interop/tiledb_filter_list_t.cs: -------------------------------------------------------------------------------- 1 | // 2 | 3 | using System.ComponentModel; 4 | using System; 5 | using TileDB.CSharp; 6 | 7 | namespace TileDB.Interop 8 | { 9 | [Obsolete(Obsoletions.TileDBInterop2Message, DiagnosticId = Obsoletions.TileDBInterop2DiagId, UrlFormat = Obsoletions.SharedUrlFormat)] 10 | [EditorBrowsable(EditorBrowsableState.Never)] 11 | public partial struct tiledb_filter_list_t 12 | { 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /sources/TileDB.CSharp/Interop/tiledb_filter_option_t.cs: -------------------------------------------------------------------------------- 1 | // 2 | 3 | namespace TileDB.Interop 4 | { 5 | internal enum tiledb_filter_option_t 6 | { 7 | TILEDB_COMPRESSION_LEVEL = 0, 8 | TILEDB_BIT_WIDTH_MAX_WINDOW = 1, 9 | TILEDB_POSITIVE_DELTA_MAX_WINDOW = 2, 10 | TILEDB_SCALE_FLOAT_BYTEWIDTH = 3, 11 | TILEDB_SCALE_FLOAT_FACTOR = 4, 12 | TILEDB_SCALE_FLOAT_OFFSET = 5, 13 | TILEDB_WEBP_QUALITY = 6, 14 | TILEDB_WEBP_INPUT_FORMAT = 7, 15 | TILEDB_WEBP_LOSSLESS = 8, 16 | TILEDB_COMPRESSION_REINTERPRET_DATATYPE = 9, 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /sources/TileDB.CSharp/Interop/tiledb_filter_t.cs: -------------------------------------------------------------------------------- 1 | // 2 | 3 | using System.ComponentModel; 4 | using System; 5 | using TileDB.CSharp; 6 | 7 | namespace TileDB.Interop 8 | { 9 | [Obsolete(Obsoletions.TileDBInterop2Message, DiagnosticId = Obsoletions.TileDBInterop2DiagId, UrlFormat = Obsoletions.SharedUrlFormat)] 10 | [EditorBrowsable(EditorBrowsableState.Never)] 11 | public partial struct tiledb_filter_t 12 | { 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /sources/TileDB.CSharp/Interop/tiledb_filter_type_t.cs: -------------------------------------------------------------------------------- 1 | // 2 | 3 | using System; 4 | using System.ComponentModel; 5 | using TileDB.CSharp; 6 | 7 | namespace TileDB.Interop 8 | { 9 | [Obsolete(Obsoletions.TileDBInterop3Message, DiagnosticId = Obsoletions.TileDBInterop3DiagId, UrlFormat = Obsoletions.SharedUrlFormat)] 10 | [EditorBrowsable(EditorBrowsableState.Never)] 11 | public enum tiledb_filter_type_t 12 | { 13 | TILEDB_FILTER_NONE = 0, 14 | TILEDB_FILTER_GZIP = 1, 15 | TILEDB_FILTER_ZSTD = 2, 16 | TILEDB_FILTER_LZ4 = 3, 17 | TILEDB_FILTER_RLE = 4, 18 | TILEDB_FILTER_BZIP2 = 5, 19 | TILEDB_FILTER_DOUBLE_DELTA = 6, 20 | TILEDB_FILTER_BIT_WIDTH_REDUCTION = 7, 21 | TILEDB_FILTER_BITSHUFFLE = 8, 22 | TILEDB_FILTER_BYTESHUFFLE = 9, 23 | TILEDB_FILTER_POSITIVE_DELTA = 10, 24 | TILEDB_FILTER_CHECKSUM_MD5 = 12, 25 | TILEDB_FILTER_CHECKSUM_SHA256 = 13, 26 | TILEDB_FILTER_DICTIONARY = 14, 27 | TILEDB_FILTER_SCALE_FLOAT = 15, 28 | TILEDB_FILTER_XOR = 16, 29 | TILEDB_FILTER_DEPRECATED = 17, 30 | TILEDB_FILTER_WEBP = 18, 31 | TILEDB_FILTER_DELTA = 19, 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /sources/TileDB.CSharp/Interop/tiledb_filter_webp_format_t.cs: -------------------------------------------------------------------------------- 1 | // 2 | 3 | namespace TileDB.Interop 4 | { 5 | internal enum tiledb_filter_webp_format_t 6 | { 7 | TILEDB_WEBP_NONE = 0, 8 | TILEDB_WEBP_RGB = 1, 9 | TILEDB_WEBP_BGR = 2, 10 | TILEDB_WEBP_RGBA = 3, 11 | TILEDB_WEBP_BGRA = 4, 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /sources/TileDB.CSharp/Interop/tiledb_fragment_info_t.cs: -------------------------------------------------------------------------------- 1 | // 2 | 3 | namespace TileDB.Interop 4 | { 5 | internal partial struct tiledb_fragment_info_t 6 | { 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /sources/TileDB.CSharp/Interop/tiledb_group_t.cs: -------------------------------------------------------------------------------- 1 | // 2 | 3 | using System.ComponentModel; 4 | using System; 5 | using TileDB.CSharp; 6 | 7 | namespace TileDB.Interop 8 | { 9 | [Obsolete(Obsoletions.TileDBInterop2Message, DiagnosticId = Obsoletions.TileDBInterop2DiagId, UrlFormat = Obsoletions.SharedUrlFormat)] 10 | [EditorBrowsable(EditorBrowsableState.Never)] 11 | public partial struct tiledb_group_t 12 | { 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /sources/TileDB.CSharp/Interop/tiledb_layout_t.cs: -------------------------------------------------------------------------------- 1 | // 2 | 3 | namespace TileDB.Interop 4 | { 5 | internal enum tiledb_layout_t 6 | { 7 | TILEDB_ROW_MAJOR = 0, 8 | TILEDB_COL_MAJOR = 1, 9 | TILEDB_GLOBAL_ORDER = 2, 10 | TILEDB_UNORDERED = 3, 11 | TILEDB_HILBERT = 4, 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /sources/TileDB.CSharp/Interop/tiledb_mime_type_t.cs: -------------------------------------------------------------------------------- 1 | // 2 | 3 | namespace TileDB.Interop 4 | { 5 | internal enum tiledb_mime_type_t 6 | { 7 | TILEDB_MIME_AUTODETECT = 0, 8 | TILEDB_MIME_TIFF = 1, 9 | TILEDB_MIME_PDF = 2, 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /sources/TileDB.CSharp/Interop/tiledb_ndrectangle_handle_t.cs: -------------------------------------------------------------------------------- 1 | // 2 | 3 | namespace TileDB.Interop 4 | { 5 | internal partial struct tiledb_ndrectangle_handle_t 6 | { 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /sources/TileDB.CSharp/Interop/tiledb_object_t.cs: -------------------------------------------------------------------------------- 1 | // 2 | 3 | namespace TileDB.Interop 4 | { 5 | internal enum tiledb_object_t 6 | { 7 | TILEDB_INVALID = 0, 8 | TILEDB_GROUP = 1, 9 | TILEDB_ARRAY = 2, 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /sources/TileDB.CSharp/Interop/tiledb_query_channel_t.cs: -------------------------------------------------------------------------------- 1 | // 2 | 3 | namespace TileDB.Interop 4 | { 5 | internal partial struct tiledb_query_channel_t 6 | { 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /sources/TileDB.CSharp/Interop/tiledb_query_condition_combination_op_t.cs: -------------------------------------------------------------------------------- 1 | // 2 | 3 | namespace TileDB.Interop 4 | { 5 | internal enum tiledb_query_condition_combination_op_t 6 | { 7 | TILEDB_AND = 0, 8 | TILEDB_OR = 1, 9 | TILEDB_NOT = 2, 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /sources/TileDB.CSharp/Interop/tiledb_query_condition_op_t.cs: -------------------------------------------------------------------------------- 1 | // 2 | 3 | namespace TileDB.Interop 4 | { 5 | internal enum tiledb_query_condition_op_t 6 | { 7 | TILEDB_LT = 0, 8 | TILEDB_LE = 1, 9 | TILEDB_GT = 2, 10 | TILEDB_GE = 3, 11 | TILEDB_EQ = 4, 12 | TILEDB_NE = 5, 13 | TILEDB_IN = 6, 14 | TILEDB_NOT_IN = 7, 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /sources/TileDB.CSharp/Interop/tiledb_query_condition_t.cs: -------------------------------------------------------------------------------- 1 | // 2 | 3 | using System.ComponentModel; 4 | using System; 5 | using TileDB.CSharp; 6 | 7 | namespace TileDB.Interop 8 | { 9 | [Obsolete(Obsoletions.TileDBInterop2Message, DiagnosticId = Obsoletions.TileDBInterop2DiagId, UrlFormat = Obsoletions.SharedUrlFormat)] 10 | [EditorBrowsable(EditorBrowsableState.Never)] 11 | public partial struct tiledb_query_condition_t 12 | { 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /sources/TileDB.CSharp/Interop/tiledb_query_field_t.cs: -------------------------------------------------------------------------------- 1 | // 2 | 3 | namespace TileDB.Interop 4 | { 5 | internal partial struct tiledb_query_field_t 6 | { 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /sources/TileDB.CSharp/Interop/tiledb_query_status_details_reason_t.cs: -------------------------------------------------------------------------------- 1 | // 2 | 3 | namespace TileDB.Interop 4 | { 5 | internal enum tiledb_query_status_details_reason_t 6 | { 7 | TILEDB_REASON_NONE = 0, 8 | TILEDB_REASON_USER_BUFFER_SIZE = 1, 9 | TILEDB_REASON_MEMORY_BUDGET = 2, 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /sources/TileDB.CSharp/Interop/tiledb_query_status_details_t.cs: -------------------------------------------------------------------------------- 1 | // 2 | 3 | namespace TileDB.Interop 4 | { 5 | internal partial struct tiledb_query_status_details_t 6 | { 7 | public tiledb_query_status_details_reason_t incomplete_reason; 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /sources/TileDB.CSharp/Interop/tiledb_query_status_t.cs: -------------------------------------------------------------------------------- 1 | // 2 | 3 | namespace TileDB.Interop 4 | { 5 | internal enum tiledb_query_status_t 6 | { 7 | TILEDB_FAILED = 0, 8 | TILEDB_COMPLETED = 1, 9 | TILEDB_INPROGRESS = 2, 10 | TILEDB_INCOMPLETE = 3, 11 | TILEDB_UNINITIALIZED = 4, 12 | TILEDB_INITIALIZED = 5, 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /sources/TileDB.CSharp/Interop/tiledb_query_t.cs: -------------------------------------------------------------------------------- 1 | // 2 | 3 | using System.ComponentModel; 4 | using System; 5 | using TileDB.CSharp; 6 | 7 | namespace TileDB.Interop 8 | { 9 | [Obsolete(Obsoletions.TileDBInterop2Message, DiagnosticId = Obsoletions.TileDBInterop2DiagId, UrlFormat = Obsoletions.SharedUrlFormat)] 10 | [EditorBrowsable(EditorBrowsableState.Never)] 11 | public partial struct tiledb_query_t 12 | { 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /sources/TileDB.CSharp/Interop/tiledb_query_type_t.cs: -------------------------------------------------------------------------------- 1 | // 2 | 3 | using System; 4 | using System.ComponentModel; 5 | using TileDB.CSharp; 6 | 7 | namespace TileDB.Interop 8 | { 9 | [Obsolete(Obsoletions.TileDBInterop3Message, DiagnosticId = Obsoletions.TileDBInterop3DiagId, UrlFormat = Obsoletions.SharedUrlFormat)] 10 | [EditorBrowsable(EditorBrowsableState.Never)] 11 | public enum tiledb_query_type_t 12 | { 13 | TILEDB_READ = 0, 14 | TILEDB_WRITE = 1, 15 | TILEDB_DELETE = 2, 16 | TILEDB_UPDATE = 3, 17 | TILEDB_MODIFY_EXCLUSIVE = 4, 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /sources/TileDB.CSharp/Interop/tiledb_range_t.cs: -------------------------------------------------------------------------------- 1 | // 2 | 3 | namespace TileDB.Interop 4 | { 5 | internal unsafe partial struct tiledb_range_t 6 | { 7 | [NativeTypeName("const void *")] 8 | public void* min; 9 | 10 | [NativeTypeName("uint64_t")] 11 | public ulong min_size; 12 | 13 | [NativeTypeName("const void *")] 14 | public void* max; 15 | 16 | [NativeTypeName("uint64_t")] 17 | public ulong max_size; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /sources/TileDB.CSharp/Interop/tiledb_string_t.cs: -------------------------------------------------------------------------------- 1 | // 2 | 3 | namespace TileDB.Interop 4 | { 5 | internal partial struct tiledb_string_t 6 | { 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /sources/TileDB.CSharp/Interop/tiledb_subarray_t.cs: -------------------------------------------------------------------------------- 1 | // 2 | 3 | namespace TileDB.Interop 4 | { 5 | internal partial struct tiledb_subarray_t 6 | { 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /sources/TileDB.CSharp/Interop/tiledb_vfs_fh_t.cs: -------------------------------------------------------------------------------- 1 | // 2 | 3 | namespace TileDB.Interop 4 | { 5 | internal partial struct tiledb_vfs_fh_t 6 | { 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /sources/TileDB.CSharp/Interop/tiledb_vfs_mode_t.cs: -------------------------------------------------------------------------------- 1 | // 2 | 3 | namespace TileDB.Interop 4 | { 5 | internal enum tiledb_vfs_mode_t 6 | { 7 | TILEDB_VFS_READ = 0, 8 | TILEDB_VFS_WRITE = 1, 9 | TILEDB_VFS_APPEND = 2, 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /sources/TileDB.CSharp/Interop/tiledb_vfs_t.cs: -------------------------------------------------------------------------------- 1 | // 2 | 3 | using System.ComponentModel; 4 | using System; 5 | using TileDB.CSharp; 6 | 7 | namespace TileDB.Interop 8 | { 9 | [Obsolete(Obsoletions.TileDBInterop2Message, DiagnosticId = Obsoletions.TileDBInterop2DiagId, UrlFormat = Obsoletions.SharedUrlFormat)] 10 | [EditorBrowsable(EditorBrowsableState.Never)] 11 | public partial struct tiledb_vfs_t 12 | { 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /sources/TileDB.CSharp/Interop/tiledb_walk_order_t.cs: -------------------------------------------------------------------------------- 1 | // 2 | 3 | namespace TileDB.Interop 4 | { 5 | internal enum tiledb_walk_order_t 6 | { 7 | TILEDB_PREORDER = 0, 8 | TILEDB_POSTORDER = 1, 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /sources/TileDB.CSharp/InteropAugments.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Diagnostics; 3 | 4 | // The Interop files are auto-generated so any additions to them will be made in this file to be preserved. 5 | 6 | namespace TileDB.Interop; 7 | 8 | /// Defines the type of a member as it was used in the native signature. 9 | [AttributeUsage(AttributeTargets.Struct | AttributeTargets.Enum | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter | AttributeTargets.ReturnValue, AllowMultiple = false, Inherited = true)] 10 | [Conditional("DEBUG")] 11 | internal sealed partial class NativeTypeNameAttribute : System.Attribute 12 | { 13 | private readonly string _name; 14 | 15 | /// Initializes a new instance of the class. 16 | /// The name of the type that was used in the native signature. 17 | public NativeTypeNameAttribute(string name) 18 | { 19 | _name = name; 20 | } 21 | 22 | /// Gets the name of the type that was used in the native signature. 23 | public string Name => _name; 24 | } 25 | -------------------------------------------------------------------------------- /sources/TileDB.CSharp/Marshalling/MarshaledContiguousStringCollection.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Runtime.InteropServices; 4 | using System.Text; 5 | using TileDB.Interop; 6 | 7 | namespace TileDB.CSharp.Marshalling; 8 | 9 | internal unsafe ref struct MarshaledContiguousStringCollection 10 | { 11 | public byte* Data { get; private set; } 12 | 13 | public ulong* Offsets { get; private set; } 14 | 15 | public ulong DataCount { get; private set; } 16 | 17 | public ulong OffsetsCount { get; private set; } 18 | 19 | public MarshaledContiguousStringCollection(IReadOnlyCollection strings, DataType dataType = DataType.StringAscii) 20 | { 21 | Encoding encoding = MarshaledString.GetEncoding(dataType); 22 | try 23 | { 24 | Offsets = (ulong*)NativeMemory.Alloc((nuint)strings.Count, sizeof(ulong)); 25 | OffsetsCount = (ulong)strings.Count * sizeof(ulong); 26 | ulong currentOffset = 0; 27 | DataCount = 0; 28 | foreach (var str in strings) 29 | { 30 | Offsets[currentOffset++] = DataCount; 31 | DataCount += (ulong)encoding.GetByteCount(str); 32 | } 33 | 34 | Data = (byte*)NativeMemory.Alloc((nuint)DataCount); 35 | int i = 0; 36 | foreach (var str in strings) 37 | { 38 | currentOffset = Offsets[i]; 39 | encoding.GetBytes(str, new Span(Data + currentOffset, checked((int)(DataCount - currentOffset)))); 40 | i++; 41 | } 42 | } 43 | catch 44 | { 45 | Dispose(); 46 | throw; 47 | } 48 | } 49 | 50 | public void Dispose() 51 | { 52 | if (Data is not null) 53 | { 54 | NativeMemory.Free(Data); 55 | Data = null; 56 | DataCount = 0; 57 | } 58 | if (Offsets is not null) 59 | { 60 | NativeMemory.Free(Offsets); 61 | Offsets = null; 62 | OffsetsCount = 0; 63 | } 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /sources/TileDB.CSharp/Marshalling/MarshaledString.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information. 2 | 3 | using System; 4 | using System.ComponentModel; 5 | using System.Diagnostics; 6 | using System.Runtime.InteropServices; 7 | using System.Text; 8 | using TileDB.CSharp; 9 | 10 | namespace TileDB.Interop; 11 | 12 | [Obsolete(Obsoletions.TileDBInterop2Message, DiagnosticId = Obsoletions.TileDBInterop2DiagId, UrlFormat = Obsoletions.SharedUrlFormat)] 13 | [EditorBrowsable(EditorBrowsableState.Never)] 14 | public unsafe struct MarshaledString : IDisposable 15 | { 16 | public MarshaledString(string input) 17 | { 18 | Value = AllocNullTerminated(input, out int length); 19 | Length = length; 20 | } 21 | 22 | internal static Encoding GetEncoding(DataType dataType) 23 | { 24 | switch (dataType) 25 | { 26 | case DataType.StringAscii: 27 | return Encoding.ASCII; 28 | case DataType.StringUtf8: 29 | return Encoding.UTF8; 30 | case DataType.StringUtf16: 31 | return Encoding.Unicode; 32 | case DataType.StringUtf32: 33 | return Encoding.UTF32; 34 | } 35 | ThrowHelpers.ThrowInvalidDataType(dataType); 36 | return null; 37 | } 38 | 39 | internal static sbyte* AllocNullTerminated(string str, out int length) 40 | { 41 | if (str is null) 42 | { 43 | length = 0; 44 | return null; 45 | } 46 | 47 | length = Encoding.ASCII.GetByteCount(str); 48 | var ptr = (sbyte*)NativeMemory.Alloc((nuint)length + 1); 49 | int bytesWritten = Encoding.ASCII.GetBytes(str, new Span(ptr, length)); 50 | Debug.Assert(bytesWritten == length); 51 | ptr[length] = 0; 52 | return ptr; 53 | } 54 | 55 | internal static void FreeNullTerminated(void* ptr) => NativeMemory.Free(ptr); 56 | 57 | public ReadOnlySpan AsSpan() => new ReadOnlySpan(Value, Length); 58 | 59 | public int Length { get; private set; } 60 | 61 | public sbyte* Value { get; private set; } 62 | 63 | public void Dispose() 64 | { 65 | if (Value != null) 66 | { 67 | NativeMemory.Free(Value); 68 | Value = null; 69 | Length = 0; 70 | } 71 | } 72 | 73 | public static implicit operator sbyte*(in MarshaledString value) => value.Value; 74 | 75 | public override string ToString() 76 | { 77 | var span = new ReadOnlySpan(Value, Length); 78 | return MarshaledStringOut.GetString(span); 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /sources/TileDB.CSharp/Marshalling/MarshaledStringCollection.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Runtime.InteropServices; 4 | using TileDB.Interop; 5 | 6 | namespace TileDB.CSharp.Marshalling; 7 | 8 | internal unsafe ref struct MarshaledStringCollection 9 | { 10 | public sbyte** Strings { get; private set; } 11 | 12 | public int Count { get; } 13 | 14 | public MarshaledStringCollection(IReadOnlyList strings) 15 | { 16 | Count = strings.Count; 17 | Strings = (sbyte**)NativeMemory.Alloc((nuint)Count, (nuint)sizeof(sbyte*)); 18 | 19 | try 20 | { 21 | for (int i = 0; i < Count; i++) 22 | { 23 | Strings[i] = MarshaledString.AllocNullTerminated(strings[i], out _); 24 | } 25 | } 26 | catch 27 | { 28 | Dispose(); 29 | throw; 30 | } 31 | } 32 | 33 | public void Dispose() 34 | { 35 | if (Strings is null) return; 36 | 37 | for (int i = 0; i < Count; i++) 38 | { 39 | MarshaledString.FreeNullTerminated(Strings[i]); 40 | } 41 | NativeMemory.Free(Strings); 42 | Strings = null; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /sources/TileDB.CSharp/Marshalling/MarshaledStringOut.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.ComponentModel; 3 | using System.Text; 4 | using TileDB.CSharp; 5 | 6 | namespace TileDB.Interop; 7 | 8 | [Obsolete(Obsoletions.TileDBInterop2Message, DiagnosticId = Obsoletions.TileDBInterop2DiagId, UrlFormat = Obsoletions.SharedUrlFormat)] 9 | [EditorBrowsable(EditorBrowsableState.Never)] 10 | public unsafe class LibC 11 | { 12 | // public struct handle_t {} 13 | // [DllImport(LibDllImport.LibCPath)] 14 | // public static extern void free(void* p); 15 | } 16 | 17 | [Obsolete(Obsoletions.TileDBInterop2Message, DiagnosticId = Obsoletions.TileDBInterop2DiagId, UrlFormat = Obsoletions.SharedUrlFormat)] 18 | [EditorBrowsable(EditorBrowsableState.Never)] 19 | public unsafe class MarshaledStringOut 20 | { 21 | public sbyte* Value; 22 | public MarshaledStringOut() 23 | { 24 | Value = null; 25 | } 26 | 27 | /// 28 | /// Encodes a read-only span of bytes into a string, using the default encoding. 29 | /// 30 | internal static string GetString(ReadOnlySpan span) => 31 | Encoding.ASCII.GetString(span); 32 | 33 | internal static string GetString(ReadOnlySpan span, DataType dataType) => 34 | dataType switch 35 | { 36 | DataType.StringAscii => Encoding.ASCII.GetString(span), 37 | DataType.StringUtf8 => Encoding.UTF8.GetString(span), 38 | DataType.StringUtf16 => Encoding.Unicode.GetString(span), 39 | DataType.StringUtf32=> Encoding.UTF32.GetString(span), 40 | _ => throw new ArgumentOutOfRangeException(nameof(dataType), dataType, "Unsupported string data type.") 41 | }; 42 | 43 | /// 44 | /// Encodes a null-terminated pointer of bytes into a string, using the default encoding. 45 | /// 46 | internal static unsafe string GetStringFromNullTerminated(sbyte* ptr) 47 | { 48 | if (ptr == null) 49 | { 50 | return string.Empty; 51 | } 52 | 53 | var span = new ReadOnlySpan(ptr, int.MaxValue); 54 | span = span[0..span.IndexOf((byte)0)]; 55 | return GetString(span); 56 | } 57 | 58 | public static implicit operator string(MarshaledStringOut s) => GetStringFromNullTerminated(s.Value); 59 | } 60 | -------------------------------------------------------------------------------- /sources/TileDB.CSharp/Marshalling/SafeHandleHolder.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.InteropServices; 3 | 4 | namespace TileDB.CSharp.Marshalling; 5 | 6 | internal struct SafeHandleHolder : IDisposable where TNativeObject : unmanaged 7 | { 8 | private readonly SafeHandle? _handle; 9 | private bool _isHeld; 10 | 11 | #pragma warning disable S3869 // "SafeHandle.DangerousGetHandle" should not be called 12 | public static unsafe implicit operator TNativeObject*(SafeHandleHolder holder) => 13 | (TNativeObject*)(holder._handle?.DangerousGetHandle() ?? (IntPtr)0); 14 | #pragma warning restore S3869 // "SafeHandle.DangerousGetHandle" should not be called 15 | 16 | public SafeHandleHolder(SafeHandle handle) 17 | { 18 | _handle = handle; 19 | _isHeld = false; 20 | _handle.DangerousAddRef(ref _isHeld); 21 | } 22 | 23 | public void Dispose() 24 | { 25 | if (!_isHeld) 26 | { 27 | return; 28 | } 29 | 30 | _isHeld = false; 31 | _handle?.DangerousRelease(); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /sources/TileDB.CSharp/Marshalling/SafeHandles/ArrayHandle.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.InteropServices; 3 | using TileDB.Interop; 4 | 5 | namespace TileDB.CSharp.Marshalling.SafeHandles; 6 | 7 | internal unsafe sealed class ArrayHandle : SafeHandle 8 | { 9 | public ArrayHandle() : base(IntPtr.Zero, true) { } 10 | 11 | public ArrayHandle(IntPtr handle, bool ownsHandle) : base(IntPtr.Zero, ownsHandle) { SetHandle(handle); } 12 | 13 | public static ArrayHandle Create(Context context, sbyte* uri) 14 | { 15 | var handle = new ArrayHandle(); 16 | var successful = false; 17 | tiledb_array_t* array = null; 18 | try 19 | { 20 | using (var ctx = context.Handle.Acquire()) 21 | { 22 | context.handle_error(Methods.tiledb_array_alloc(ctx, uri, &array)); 23 | } 24 | successful = true; 25 | } 26 | finally 27 | { 28 | if (successful) 29 | { 30 | handle.InitHandle(array); 31 | } 32 | else 33 | { 34 | handle.SetHandleAsInvalid(); 35 | } 36 | } 37 | 38 | return handle; 39 | } 40 | 41 | protected override bool ReleaseHandle() 42 | { 43 | fixed (IntPtr* p = &handle) 44 | { 45 | Methods.tiledb_array_free((tiledb_array_t**)p); 46 | } 47 | return true; 48 | } 49 | 50 | internal void InitHandle(tiledb_array_t* h) { SetHandle((IntPtr)h); } 51 | public override bool IsInvalid => handle == IntPtr.Zero; 52 | 53 | public SafeHandleHolder Acquire() => new(this); 54 | } 55 | -------------------------------------------------------------------------------- /sources/TileDB.CSharp/Marshalling/SafeHandles/ArraySchemaEvolutionHandle.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.InteropServices; 3 | using TileDB.Interop; 4 | 5 | namespace TileDB.CSharp.Marshalling.SafeHandles; 6 | 7 | internal unsafe sealed class ArraySchemaEvolutionHandle : SafeHandle 8 | { 9 | public ArraySchemaEvolutionHandle() : base(IntPtr.Zero, true) { } 10 | 11 | public ArraySchemaEvolutionHandle(IntPtr handle, bool ownsHandle) : base(IntPtr.Zero, ownsHandle) { SetHandle(handle); } 12 | 13 | public static ArraySchemaEvolutionHandle Create(Context context) 14 | { 15 | var handle = new ArraySchemaEvolutionHandle(); 16 | var successful = false; 17 | tiledb_array_schema_evolution_t* evolution = null; 18 | try 19 | { 20 | using (var contextHandle = context.Handle.Acquire()) 21 | { 22 | context.handle_error(Methods.tiledb_array_schema_evolution_alloc(contextHandle, &evolution)); 23 | } 24 | successful = true; 25 | } 26 | finally 27 | { 28 | if (successful) 29 | { 30 | handle.InitHandle(evolution); 31 | } 32 | else 33 | { 34 | handle.SetHandleAsInvalid(); 35 | } 36 | } 37 | 38 | return handle; 39 | } 40 | 41 | protected override bool ReleaseHandle() 42 | { 43 | fixed (IntPtr* p = &handle) 44 | { 45 | Methods.tiledb_array_schema_evolution_free((tiledb_array_schema_evolution_t**)p); 46 | } 47 | return true; 48 | } 49 | 50 | internal void InitHandle(tiledb_array_schema_evolution_t* h) => SetHandle((IntPtr)h); 51 | public override bool IsInvalid => handle == IntPtr.Zero; 52 | 53 | public SafeHandleHolder Acquire() => new(this); 54 | } 55 | -------------------------------------------------------------------------------- /sources/TileDB.CSharp/Marshalling/SafeHandles/ArraySchemaHandle.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.InteropServices; 3 | using TileDB.Interop; 4 | 5 | namespace TileDB.CSharp.Marshalling.SafeHandles; 6 | 7 | internal unsafe sealed class ArraySchemaHandle : SafeHandle 8 | { 9 | public ArraySchemaHandle() : base(IntPtr.Zero, true) { } 10 | 11 | public ArraySchemaHandle(IntPtr handle, bool ownsHandle) : base(IntPtr.Zero, ownsHandle) { SetHandle(handle); } 12 | 13 | public static ArraySchemaHandle Create(Context context, tiledb_array_type_t arrayType) 14 | { 15 | var handle = new ArraySchemaHandle(); 16 | var successful = false; 17 | tiledb_array_schema_t* schema = null; 18 | try 19 | { 20 | using (var ctx = context.Handle.Acquire()) 21 | { 22 | context.handle_error(Methods.tiledb_array_schema_alloc(ctx, arrayType, &schema)); 23 | } 24 | successful = true; 25 | } 26 | finally 27 | { 28 | if (successful) 29 | { 30 | handle.InitHandle(schema); 31 | } 32 | else 33 | { 34 | handle.SetHandleAsInvalid(); 35 | } 36 | } 37 | 38 | return handle; 39 | } 40 | 41 | protected override bool ReleaseHandle() 42 | { 43 | fixed (IntPtr* p = &handle) 44 | { 45 | Methods.tiledb_array_schema_free((tiledb_array_schema_t**)p); 46 | } 47 | return true; 48 | } 49 | 50 | internal void InitHandle(tiledb_array_schema_t* h) { SetHandle((IntPtr)h); } 51 | public override bool IsInvalid => handle == IntPtr.Zero; 52 | 53 | public SafeHandleHolder Acquire() => new(this); 54 | } 55 | -------------------------------------------------------------------------------- /sources/TileDB.CSharp/Marshalling/SafeHandles/AttributeHandle.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.InteropServices; 3 | using TileDB.Interop; 4 | 5 | namespace TileDB.CSharp.Marshalling.SafeHandles; 6 | 7 | internal unsafe sealed class AttributeHandle : SafeHandle 8 | { 9 | public AttributeHandle() : base(IntPtr.Zero, true) { } 10 | 11 | public AttributeHandle(IntPtr handle, bool ownsHandle) : base(IntPtr.Zero, ownsHandle) { SetHandle(handle); } 12 | 13 | public static AttributeHandle Create(Context context, string name, tiledb_datatype_t datatype) 14 | { 15 | var handle = new AttributeHandle(); 16 | var successful = false; 17 | tiledb_attribute_t* attribute = null; 18 | try 19 | { 20 | using var contextHandle = context.Handle.Acquire(); 21 | using var ms_name = new MarshaledString(name); 22 | context.handle_error(Methods.tiledb_attribute_alloc(contextHandle, ms_name, datatype, &attribute)); 23 | successful = true; 24 | } 25 | finally 26 | { 27 | if (successful) 28 | { 29 | handle.InitHandle(attribute); 30 | } 31 | else 32 | { 33 | handle.SetHandleAsInvalid(); 34 | } 35 | } 36 | 37 | return handle; 38 | } 39 | 40 | protected override bool ReleaseHandle() 41 | { 42 | fixed (IntPtr* p = &handle) 43 | { 44 | Methods.tiledb_attribute_free((tiledb_attribute_t**)p); 45 | } 46 | return true; 47 | } 48 | 49 | internal void InitHandle(tiledb_attribute_t* h) { SetHandle((IntPtr)h); } 50 | public override bool IsInvalid => handle == IntPtr.Zero; 51 | 52 | public SafeHandleHolder Acquire() => new(this); 53 | } 54 | -------------------------------------------------------------------------------- /sources/TileDB.CSharp/Marshalling/SafeHandles/ChannelOperationHandle.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.InteropServices; 3 | using TileDB.Interop; 4 | 5 | namespace TileDB.CSharp.Marshalling.SafeHandles; 6 | 7 | internal unsafe sealed class ChannelOperationHandle : SafeHandle 8 | { 9 | // Keep the context handle around until this handle gets freed. 10 | private SafeHandleHolder _ctx; 11 | 12 | public ChannelOperationHandle() : base(IntPtr.Zero, true) { } 13 | 14 | public ChannelOperationHandle(IntPtr handle, bool ownsHandle) : base(IntPtr.Zero, ownsHandle) { SetHandle(handle); } 15 | 16 | protected override bool ReleaseHandle() 17 | { 18 | fixed (IntPtr* p = &handle) 19 | { 20 | Methods.tiledb_aggregate_free(_ctx, (tiledb_channel_operation_t**)p); 21 | } 22 | _ctx.Dispose(); 23 | return true; 24 | } 25 | 26 | internal void InitHandle(Context ctx, tiledb_channel_operation_t* h) 27 | { 28 | _ctx = ctx.Handle.Acquire(); 29 | SetHandle((IntPtr)h); 30 | } 31 | public override bool IsInvalid => handle == IntPtr.Zero; 32 | 33 | public SafeHandleHolder Acquire() => new(this); 34 | } 35 | -------------------------------------------------------------------------------- /sources/TileDB.CSharp/Marshalling/SafeHandles/ConfigHandle.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.InteropServices; 3 | using TileDB.Interop; 4 | 5 | namespace TileDB.CSharp.Marshalling.SafeHandles; 6 | 7 | internal unsafe sealed class ConfigHandle : SafeHandle 8 | { 9 | public ConfigHandle() : base(IntPtr.Zero, true) { } 10 | 11 | public ConfigHandle(IntPtr handle, bool ownsHandle) : base(IntPtr.Zero, ownsHandle) { SetHandle(handle); } 12 | 13 | public static ConfigHandle Create() 14 | { 15 | var handle = new ConfigHandle(); 16 | var successful = false; 17 | tiledb_config_t* config = null; 18 | try 19 | { 20 | tiledb_error_t* error; 21 | ErrorHandling.ThrowOnError(Methods.tiledb_config_alloc(&config, &error)); 22 | successful = true; 23 | } 24 | finally 25 | { 26 | if (successful) 27 | { 28 | handle.InitHandle(config); 29 | } 30 | else 31 | { 32 | handle.SetHandleAsInvalid(); 33 | } 34 | } 35 | 36 | return handle; 37 | } 38 | 39 | protected override bool ReleaseHandle() 40 | { 41 | fixed (IntPtr* p = &handle) 42 | { 43 | Methods.tiledb_config_free((tiledb_config_t**)p); 44 | } 45 | return true; 46 | } 47 | 48 | internal void InitHandle(tiledb_config_t* h) { SetHandle((IntPtr)h); } 49 | public override bool IsInvalid => handle == IntPtr.Zero; 50 | 51 | public SafeHandleHolder Acquire() => new(this); 52 | } 53 | -------------------------------------------------------------------------------- /sources/TileDB.CSharp/Marshalling/SafeHandles/ConfigIteratorHandle.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.InteropServices; 3 | using TileDB.Interop; 4 | 5 | namespace TileDB.CSharp.Marshalling.SafeHandles; 6 | 7 | internal unsafe sealed class ConfigIteratorHandle : SafeHandle 8 | { 9 | public ConfigIteratorHandle() : base(IntPtr.Zero, true) { } 10 | 11 | public ConfigIteratorHandle(IntPtr handle, bool ownsHandle) : base(IntPtr.Zero, ownsHandle) { SetHandle(handle); } 12 | 13 | public static ConfigIteratorHandle Create(ConfigHandle hconfig, string prefix) 14 | { 15 | var handle = new ConfigIteratorHandle(); 16 | var successful = false; 17 | tiledb_config_iter_t* config_iter = null; 18 | try 19 | { 20 | using var config = hconfig.Acquire(); 21 | tiledb_error_t* error; 22 | using var ms_prefix = new MarshaledString(prefix); 23 | ErrorHandling.ThrowOnError(Methods.tiledb_config_iter_alloc(config, ms_prefix, &config_iter, &error)); 24 | successful = true; 25 | } 26 | finally 27 | { 28 | if (successful) 29 | { 30 | handle.InitHandle(config_iter); 31 | } 32 | else 33 | { 34 | handle.SetHandleAsInvalid(); 35 | } 36 | } 37 | 38 | return handle; 39 | } 40 | 41 | protected override bool ReleaseHandle() 42 | { 43 | fixed (IntPtr* p = &handle) 44 | { 45 | Methods.tiledb_config_iter_free((tiledb_config_iter_t**)p); 46 | } 47 | return true; 48 | } 49 | 50 | internal void InitHandle(tiledb_config_iter_t* h) { SetHandle((IntPtr)h); } 51 | public override bool IsInvalid => handle == IntPtr.Zero; 52 | 53 | public SafeHandleHolder Acquire() => new(this); 54 | } 55 | -------------------------------------------------------------------------------- /sources/TileDB.CSharp/Marshalling/SafeHandles/ContextHandle.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.InteropServices; 3 | using TileDB.Interop; 4 | 5 | namespace TileDB.CSharp.Marshalling.SafeHandles; 6 | 7 | internal unsafe sealed class ContextHandle : SafeHandle 8 | { 9 | public ContextHandle() : base(IntPtr.Zero, true) { } 10 | 11 | public ContextHandle(IntPtr handle, bool ownsHandle) : base(IntPtr.Zero, ownsHandle) { SetHandle(handle); } 12 | 13 | public static ContextHandle Create(ConfigHandle? configHandle = null) 14 | { 15 | var handle = new ContextHandle(); 16 | var successful = false; 17 | tiledb_ctx_t* context = null; 18 | try 19 | { 20 | using var configHandleHolder = configHandle?.Acquire() ?? default; 21 | ErrorHandling.ThrowOnError(Methods.tiledb_ctx_alloc(configHandleHolder, &context)); 22 | successful = true; 23 | } 24 | finally 25 | { 26 | if (successful) 27 | { 28 | handle.InitHandle(context); 29 | } 30 | else 31 | { 32 | handle.SetHandleAsInvalid(); 33 | } 34 | } 35 | 36 | return handle; 37 | } 38 | 39 | protected override bool ReleaseHandle() 40 | { 41 | fixed (IntPtr* p = &handle) 42 | { 43 | Methods.tiledb_ctx_free((tiledb_ctx_t**)p); 44 | } 45 | return true; 46 | } 47 | 48 | internal void InitHandle(tiledb_ctx_t* h) { SetHandle((IntPtr)h); } 49 | public override bool IsInvalid => handle == IntPtr.Zero; 50 | 51 | public SafeHandleHolder Acquire() => new(this); 52 | } 53 | -------------------------------------------------------------------------------- /sources/TileDB.CSharp/Marshalling/SafeHandles/DimensionHandle.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.InteropServices; 3 | using TileDB.Interop; 4 | 5 | namespace TileDB.CSharp.Marshalling.SafeHandles; 6 | 7 | internal unsafe sealed class DimensionHandle : SafeHandle 8 | { 9 | public DimensionHandle() : base(IntPtr.Zero, true) { } 10 | 11 | public DimensionHandle(IntPtr handle, bool ownsHandle) : base(IntPtr.Zero, ownsHandle) { SetHandle(handle); } 12 | 13 | public static DimensionHandle Create(Context context, string name, tiledb_datatype_t datatype, void* dimDomain, void* tileExtent) 14 | { 15 | var handle = new DimensionHandle(); 16 | var successful = false; 17 | tiledb_dimension_t* dimension = null; 18 | try 19 | { 20 | using var contextHandle = context.Handle.Acquire(); 21 | using var ms_name = new MarshaledString(name); 22 | context.handle_error(Methods.tiledb_dimension_alloc(contextHandle, ms_name, datatype, dimDomain, tileExtent, &dimension)); 23 | successful = true; 24 | } 25 | finally 26 | { 27 | if (successful) 28 | { 29 | handle.InitHandle(dimension); 30 | } 31 | else 32 | { 33 | handle.SetHandleAsInvalid(); 34 | } 35 | } 36 | 37 | return handle; 38 | } 39 | 40 | protected override bool ReleaseHandle() 41 | { 42 | fixed (IntPtr* p = &handle) 43 | { 44 | Methods.tiledb_dimension_free((tiledb_dimension_t**)p); 45 | } 46 | return true; 47 | } 48 | 49 | internal void InitHandle(tiledb_dimension_t* h) { SetHandle((IntPtr)h); } 50 | public override bool IsInvalid => handle == IntPtr.Zero; 51 | 52 | public SafeHandleHolder Acquire() => new(this); 53 | } 54 | -------------------------------------------------------------------------------- /sources/TileDB.CSharp/Marshalling/SafeHandles/DomainHandle.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.InteropServices; 3 | using TileDB.Interop; 4 | 5 | namespace TileDB.CSharp.Marshalling.SafeHandles; 6 | 7 | internal unsafe sealed class DomainHandle : SafeHandle 8 | { 9 | public DomainHandle() : base(IntPtr.Zero, true) { } 10 | 11 | public DomainHandle(IntPtr handle, bool ownsHandle) : base(IntPtr.Zero, ownsHandle) { SetHandle(handle); } 12 | 13 | public static DomainHandle Create(Context context) 14 | { 15 | var handle = new DomainHandle(); 16 | var successful = false; 17 | tiledb_domain_t* domain = null; 18 | try 19 | { 20 | using var contextHandle = context.Handle.Acquire(); 21 | context.handle_error(Methods.tiledb_domain_alloc(contextHandle, &domain)); 22 | successful = true; 23 | } 24 | finally 25 | { 26 | if (successful) 27 | { 28 | handle.InitHandle(domain); 29 | } 30 | else 31 | { 32 | handle.SetHandleAsInvalid(); 33 | } 34 | } 35 | 36 | return handle; 37 | } 38 | 39 | protected override bool ReleaseHandle() 40 | { 41 | fixed (IntPtr* p = &handle) 42 | { 43 | Methods.tiledb_domain_free((tiledb_domain_t**)p); 44 | } 45 | return true; 46 | } 47 | 48 | internal void InitHandle(tiledb_domain_t* h) { SetHandle((IntPtr)h); } 49 | public override bool IsInvalid => handle == IntPtr.Zero; 50 | 51 | public SafeHandleHolder Acquire() => new(this); 52 | } 53 | -------------------------------------------------------------------------------- /sources/TileDB.CSharp/Marshalling/SafeHandles/EnumerationHandle.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.InteropServices; 3 | using TileDB.Interop; 4 | 5 | namespace TileDB.CSharp.Marshalling.SafeHandles; 6 | 7 | internal unsafe sealed class EnumerationHandle : SafeHandle 8 | { 9 | public EnumerationHandle() : base(IntPtr.Zero, true) { } 10 | 11 | public EnumerationHandle(IntPtr handle, bool ownsHandle) : base(IntPtr.Zero, ownsHandle) { SetHandle(handle); } 12 | 13 | public static EnumerationHandle Create(Context context, string name, tiledb_datatype_t datatype, uint cellValNum, bool ordered, byte* data, ulong dataSize, ulong* offsets, ulong offsetsSize) 14 | { 15 | var handle = new EnumerationHandle(); 16 | var successful = false; 17 | tiledb_enumeration_t* enumeration = null; 18 | try 19 | { 20 | using var contextHandle = context.Handle.Acquire(); 21 | using var ms_name = new MarshaledString(name); 22 | context.handle_error(Methods.tiledb_enumeration_alloc(contextHandle, ms_name, datatype, cellValNum, 23 | ordered ? 1 : 0, data, dataSize, offsets, offsetsSize, &enumeration)); 24 | successful = true; 25 | } 26 | finally 27 | { 28 | if (successful) 29 | { 30 | handle.InitHandle(enumeration); 31 | } 32 | else 33 | { 34 | handle.SetHandleAsInvalid(); 35 | } 36 | } 37 | 38 | return handle; 39 | } 40 | 41 | public EnumerationHandle Extend(Context context, byte* data, ulong dataSize, ulong* offsets, ulong offsetsSize) 42 | { 43 | var handle = new EnumerationHandle(); 44 | var successful = false; 45 | tiledb_enumeration_t* enumeration = null; 46 | try 47 | { 48 | using var contextHandle = context.Handle.Acquire(); 49 | using var old_enumeration_handle = Acquire(); 50 | context.handle_error(Methods.tiledb_enumeration_extend(contextHandle, old_enumeration_handle, data, 51 | dataSize, offsets, offsetsSize, &enumeration)); 52 | successful = true; 53 | } 54 | finally 55 | { 56 | if (successful) 57 | { 58 | handle.InitHandle(enumeration); 59 | } 60 | else 61 | { 62 | handle.SetHandleAsInvalid(); 63 | } 64 | } 65 | 66 | return handle; 67 | } 68 | 69 | protected override bool ReleaseHandle() 70 | { 71 | fixed (IntPtr* p = &handle) 72 | { 73 | Methods.tiledb_enumeration_free((tiledb_enumeration_t**)p); 74 | } 75 | return true; 76 | } 77 | 78 | internal void InitHandle(tiledb_enumeration_t* h) { SetHandle((IntPtr)h); } 79 | public override bool IsInvalid => handle == IntPtr.Zero; 80 | 81 | public SafeHandleHolder Acquire() => new(this); 82 | } 83 | -------------------------------------------------------------------------------- /sources/TileDB.CSharp/Marshalling/SafeHandles/FilterHandle.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.InteropServices; 3 | using TileDB.Interop; 4 | 5 | namespace TileDB.CSharp.Marshalling.SafeHandles; 6 | 7 | internal unsafe sealed class FilterHandle : SafeHandle 8 | { 9 | public FilterHandle() : base(IntPtr.Zero, true) { } 10 | 11 | public FilterHandle(IntPtr handle, bool ownsHandle) : base(IntPtr.Zero, ownsHandle) { SetHandle(handle); } 12 | 13 | public static FilterHandle Create(Context context, tiledb_filter_type_t filterType) 14 | { 15 | var handle = new FilterHandle(); 16 | var successful = false; 17 | tiledb_filter_t* filter = null; 18 | try 19 | { 20 | using var contextHandle = context.Handle.Acquire(); 21 | context.handle_error(Methods.tiledb_filter_alloc(contextHandle, filterType, &filter)); 22 | successful = true; 23 | } 24 | finally 25 | { 26 | if (successful) 27 | { 28 | handle.InitHandle(filter); 29 | } 30 | else 31 | { 32 | handle.SetHandleAsInvalid(); 33 | } 34 | } 35 | 36 | return handle; 37 | } 38 | 39 | protected override bool ReleaseHandle() 40 | { 41 | fixed (IntPtr* p = &handle) 42 | { 43 | Methods.tiledb_filter_free((tiledb_filter_t**)p); 44 | } 45 | return true; 46 | } 47 | 48 | internal void InitHandle(tiledb_filter_t* h) { SetHandle((IntPtr)h); } 49 | public override bool IsInvalid => handle == IntPtr.Zero; 50 | 51 | public SafeHandleHolder Acquire() => new(this); 52 | } 53 | -------------------------------------------------------------------------------- /sources/TileDB.CSharp/Marshalling/SafeHandles/FilterListHandle.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.InteropServices; 3 | using TileDB.Interop; 4 | 5 | namespace TileDB.CSharp.Marshalling.SafeHandles; 6 | 7 | internal unsafe sealed class FilterListHandle : SafeHandle 8 | { 9 | public FilterListHandle() : base(IntPtr.Zero, true) { } 10 | 11 | public FilterListHandle(IntPtr handle, bool ownsHandle) : base(IntPtr.Zero, ownsHandle) { SetHandle(handle); } 12 | 13 | public static FilterListHandle Create(Context context) 14 | { 15 | var handle = new FilterListHandle(); 16 | var successful = false; 17 | tiledb_filter_list_t* filterList = null; 18 | try 19 | { 20 | using var contextHandle = context.Handle.Acquire(); 21 | context.handle_error(Methods.tiledb_filter_list_alloc(contextHandle, &filterList)); 22 | successful = true; 23 | } 24 | finally 25 | { 26 | if (successful) 27 | { 28 | handle.InitHandle(filterList); 29 | } 30 | else 31 | { 32 | handle.SetHandleAsInvalid(); 33 | } 34 | } 35 | 36 | return handle; 37 | } 38 | 39 | protected override bool ReleaseHandle() 40 | { 41 | fixed (IntPtr* p = &handle) 42 | { 43 | Methods.tiledb_filter_list_free((tiledb_filter_list_t**)p); 44 | } 45 | return true; 46 | } 47 | 48 | internal void InitHandle(tiledb_filter_list_t* h) { SetHandle((IntPtr)h); } 49 | public override bool IsInvalid => handle == IntPtr.Zero; 50 | 51 | public SafeHandleHolder Acquire() => new(this); 52 | } 53 | -------------------------------------------------------------------------------- /sources/TileDB.CSharp/Marshalling/SafeHandles/FragmentInfoHandle.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.InteropServices; 3 | using TileDB.Interop; 4 | 5 | namespace TileDB.CSharp.Marshalling.SafeHandles; 6 | 7 | internal unsafe sealed class FragmentInfoHandle : SafeHandle 8 | { 9 | public FragmentInfoHandle() : base(IntPtr.Zero, true) { } 10 | 11 | public FragmentInfoHandle(IntPtr handle, bool ownsHandle) : base(IntPtr.Zero, ownsHandle) { SetHandle(handle); } 12 | 13 | public static FragmentInfoHandle Create(Context context, sbyte* array_uri) 14 | { 15 | var handle = new FragmentInfoHandle(); 16 | bool successful = false; 17 | tiledb_fragment_info_t* fragmentInfo = null; 18 | try 19 | { 20 | using (var ctx = context.Handle.Acquire()) 21 | { 22 | context.handle_error(Methods.tiledb_fragment_info_alloc(ctx, array_uri, &fragmentInfo)); 23 | } 24 | successful = true; 25 | } 26 | finally 27 | { 28 | if (successful) 29 | { 30 | handle.InitHandle(fragmentInfo); 31 | } 32 | else 33 | { 34 | handle.SetHandleAsInvalid(); 35 | } 36 | } 37 | 38 | return handle; 39 | } 40 | 41 | protected override bool ReleaseHandle() 42 | { 43 | fixed (IntPtr* h = &handle) 44 | { 45 | Methods.tiledb_fragment_info_free((tiledb_fragment_info_t**)h); 46 | } 47 | return true; 48 | } 49 | 50 | private void InitHandle(tiledb_fragment_info_t* h) { SetHandle((IntPtr)h); } 51 | public override bool IsInvalid => handle == IntPtr.Zero; 52 | 53 | public SafeHandleHolder Acquire() => new(this); 54 | } 55 | -------------------------------------------------------------------------------- /sources/TileDB.CSharp/Marshalling/SafeHandles/GroupHandle.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.InteropServices; 3 | using TileDB.Interop; 4 | 5 | namespace TileDB.CSharp.Marshalling.SafeHandles; 6 | 7 | internal unsafe sealed class GroupHandle : SafeHandle 8 | { 9 | public GroupHandle() : base(IntPtr.Zero, true) { } 10 | 11 | public GroupHandle(IntPtr handle, bool ownsHandle) : base(IntPtr.Zero, ownsHandle) { SetHandle(handle); } 12 | 13 | public static GroupHandle Create(Context context, sbyte* uri) 14 | { 15 | var handle = new GroupHandle(); 16 | var successful = false; 17 | tiledb_group_t* group = null; 18 | try 19 | { 20 | using var contextHandle = context.Handle.Acquire(); 21 | context.handle_error(Methods.tiledb_group_alloc(contextHandle, uri, &group)); 22 | successful = true; 23 | } 24 | finally 25 | { 26 | if (successful) 27 | { 28 | handle.InitHandle(group); 29 | } 30 | else 31 | { 32 | handle.SetHandleAsInvalid(); 33 | } 34 | } 35 | 36 | return handle; 37 | } 38 | 39 | protected override bool ReleaseHandle() 40 | { 41 | fixed (IntPtr* p = &handle) 42 | { 43 | Methods.tiledb_group_free((tiledb_group_t**)p); 44 | } 45 | return true; 46 | } 47 | 48 | internal void InitHandle(tiledb_group_t* h) { SetHandle((IntPtr)h); } 49 | public override bool IsInvalid => handle == IntPtr.Zero; 50 | 51 | public SafeHandleHolder Acquire() => new(this); 52 | } 53 | -------------------------------------------------------------------------------- /sources/TileDB.CSharp/Marshalling/SafeHandles/QueryChannelHandle.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.InteropServices; 3 | using TileDB.Interop; 4 | 5 | namespace TileDB.CSharp.Marshalling.SafeHandles; 6 | 7 | internal unsafe sealed class QueryChannelHandle : SafeHandle 8 | { 9 | // Keep the context handle around until this handle gets freed. 10 | private SafeHandleHolder _ctx; 11 | 12 | public QueryChannelHandle() : base(IntPtr.Zero, true) { } 13 | 14 | public QueryChannelHandle(IntPtr handle, bool ownsHandle) : base(IntPtr.Zero, ownsHandle) { SetHandle(handle); } 15 | 16 | protected override bool ReleaseHandle() 17 | { 18 | fixed (IntPtr* p = &handle) 19 | { 20 | Methods.tiledb_query_channel_free(_ctx, (tiledb_query_channel_t**)p); 21 | } 22 | _ctx.Dispose(); 23 | return true; 24 | } 25 | 26 | internal void InitHandle(Context ctx, tiledb_query_channel_t* h) 27 | { 28 | _ctx = ctx.Handle.Acquire(); 29 | SetHandle((IntPtr)h); 30 | } 31 | public override bool IsInvalid => handle == IntPtr.Zero; 32 | 33 | public SafeHandleHolder Acquire() => new(this); 34 | } 35 | -------------------------------------------------------------------------------- /sources/TileDB.CSharp/Marshalling/SafeHandles/QueryConditionHandle.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.InteropServices; 3 | using TileDB.Interop; 4 | 5 | namespace TileDB.CSharp.Marshalling.SafeHandles; 6 | 7 | internal unsafe sealed class QueryConditionHandle : SafeHandle 8 | { 9 | public QueryConditionHandle() : base(IntPtr.Zero, true) { } 10 | 11 | public QueryConditionHandle(IntPtr handle, bool ownsHandle) : base(IntPtr.Zero, ownsHandle) { SetHandle(handle); } 12 | 13 | public static QueryConditionHandle Create(Context context) 14 | { 15 | var handle = new QueryConditionHandle(); 16 | var successful = false; 17 | tiledb_query_condition_t* queryCondition = null; 18 | try 19 | { 20 | using var contextHandle = context.Handle.Acquire(); 21 | context.handle_error(Methods.tiledb_query_condition_alloc(contextHandle, &queryCondition)); 22 | successful = true; 23 | } 24 | finally 25 | { 26 | if (successful) 27 | { 28 | handle.InitHandle(queryCondition); 29 | } 30 | else 31 | { 32 | handle.SetHandleAsInvalid(); 33 | } 34 | } 35 | 36 | return handle; 37 | } 38 | 39 | protected override bool ReleaseHandle() 40 | { 41 | fixed (IntPtr* p = &handle) 42 | { 43 | Methods.tiledb_query_condition_free((tiledb_query_condition_t**)p); 44 | } 45 | return true; 46 | } 47 | 48 | internal void InitHandle(tiledb_query_condition_t* h) { SetHandle((IntPtr)h); } 49 | public override bool IsInvalid => handle == IntPtr.Zero; 50 | 51 | public SafeHandleHolder Acquire() => new(this); 52 | } 53 | -------------------------------------------------------------------------------- /sources/TileDB.CSharp/Marshalling/SafeHandles/QueryFieldHandle.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.InteropServices; 3 | using TileDB.Interop; 4 | 5 | namespace TileDB.CSharp.Marshalling.SafeHandles; 6 | 7 | internal unsafe sealed class QueryFieldHandle : SafeHandle 8 | { 9 | // Keep the context handle around until this handle gets freed. 10 | private SafeHandleHolder _ctx; 11 | 12 | public QueryFieldHandle() : base(IntPtr.Zero, true) { } 13 | 14 | public QueryFieldHandle(IntPtr handle, bool ownsHandle) : base(IntPtr.Zero, ownsHandle) { SetHandle(handle); } 15 | 16 | protected override bool ReleaseHandle() 17 | { 18 | fixed (IntPtr* p = &handle) 19 | { 20 | Methods.tiledb_query_field_free(_ctx, (tiledb_query_field_t**)p); 21 | } 22 | _ctx.Dispose(); 23 | return true; 24 | } 25 | 26 | internal void InitHandle(Context ctx, tiledb_query_field_t* h) 27 | { 28 | _ctx = ctx.Handle.Acquire(); 29 | SetHandle((IntPtr)h); 30 | } 31 | public override bool IsInvalid => handle == IntPtr.Zero; 32 | 33 | public SafeHandleHolder Acquire() => new(this); 34 | } 35 | -------------------------------------------------------------------------------- /sources/TileDB.CSharp/Marshalling/SafeHandles/SubarrayHandle.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.InteropServices; 3 | using TileDB.Interop; 4 | 5 | namespace TileDB.CSharp.Marshalling.SafeHandles; 6 | 7 | internal unsafe sealed class SubarrayHandle : SafeHandle 8 | { 9 | public SubarrayHandle() : base(IntPtr.Zero, true) { } 10 | 11 | public SubarrayHandle(IntPtr handle, bool ownsHandle) : base(IntPtr.Zero, ownsHandle) { SetHandle(handle); } 12 | 13 | public static SubarrayHandle Create(Context context, ArrayHandle arrayHandle) 14 | { 15 | var handle = new SubarrayHandle(); 16 | var successful = false; 17 | tiledb_subarray_t* array = null; 18 | try 19 | { 20 | using (var ctx = context.Handle.Acquire()) 21 | using (var arrayHandleHolder = arrayHandle.Acquire()) 22 | { 23 | context.handle_error(Methods.tiledb_subarray_alloc(ctx, arrayHandleHolder, &array)); 24 | } 25 | successful = true; 26 | } 27 | finally 28 | { 29 | if (successful) 30 | { 31 | handle.InitHandle(array); 32 | } 33 | else 34 | { 35 | handle.SetHandleAsInvalid(); 36 | } 37 | } 38 | 39 | return handle; 40 | } 41 | 42 | protected override bool ReleaseHandle() 43 | { 44 | fixed (IntPtr* p = &handle) 45 | { 46 | Methods.tiledb_subarray_free((tiledb_subarray_t**)p); 47 | } 48 | return true; 49 | } 50 | 51 | internal void InitHandle(tiledb_subarray_t* h) { SetHandle((IntPtr)h); } 52 | public override bool IsInvalid => handle == IntPtr.Zero; 53 | 54 | public SafeHandleHolder Acquire() => new(this); 55 | } 56 | -------------------------------------------------------------------------------- /sources/TileDB.CSharp/Marshalling/SafeHandles/VFSFileHandle.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.InteropServices; 3 | using TileDB.Interop; 4 | 5 | namespace TileDB.CSharp.Marshalling.SafeHandles; 6 | 7 | internal unsafe sealed class VFSFileHandle : SafeHandle 8 | { 9 | public VFSFileHandle() : base(IntPtr.Zero, true) { } 10 | 11 | public VFSFileHandle(IntPtr handle, bool ownsHandle) : base(IntPtr.Zero, ownsHandle) { SetHandle(handle); } 12 | 13 | public static VFSFileHandle Open(Context context, VFSHandle vfsHandle, string uri, tiledb_vfs_mode_t mode) 14 | { 15 | var handle = new VFSFileHandle(); 16 | var successful = false; 17 | tiledb_vfs_fh_t* vfsFh = null; 18 | try 19 | { 20 | using var contextHandle = context.Handle.Acquire(); 21 | using var vfsHandleHolder = vfsHandle.Acquire(); 22 | using var ms_uri = new MarshaledString(uri); 23 | context.handle_error(Methods.tiledb_vfs_open(contextHandle, vfsHandleHolder, ms_uri, mode, &vfsFh)); 24 | successful = true; 25 | } 26 | finally 27 | { 28 | if (successful) 29 | { 30 | handle.InitHandle(vfsFh); 31 | } 32 | else 33 | { 34 | handle.SetHandleAsInvalid(); 35 | } 36 | } 37 | 38 | return handle; 39 | } 40 | 41 | protected override bool ReleaseHandle() 42 | { 43 | fixed (IntPtr* p = &handle) 44 | { 45 | Methods.tiledb_vfs_fh_free((tiledb_vfs_fh_t**)p); 46 | } 47 | return true; 48 | } 49 | 50 | internal void InitHandle(tiledb_vfs_fh_t* h) { SetHandle((IntPtr)h); } 51 | public override bool IsInvalid => handle == IntPtr.Zero; 52 | 53 | public SafeHandleHolder Acquire() => new(this); 54 | } 55 | -------------------------------------------------------------------------------- /sources/TileDB.CSharp/Marshalling/SafeHandles/VFSHandle.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.InteropServices; 3 | using TileDB.Interop; 4 | 5 | namespace TileDB.CSharp.Marshalling.SafeHandles; 6 | 7 | internal unsafe sealed class VFSHandle : SafeHandle 8 | { 9 | public VFSHandle() : base(IntPtr.Zero, true) { } 10 | 11 | public VFSHandle(IntPtr handle, bool ownsHandle) : base(IntPtr.Zero, ownsHandle) { SetHandle(handle); } 12 | 13 | public static VFSHandle Create(Context context, ConfigHandle? configHandle) 14 | { 15 | var handle = new VFSHandle(); 16 | var successful = false; 17 | tiledb_vfs_t* vfs = null; 18 | try 19 | { 20 | using var contextHandle = context.Handle.Acquire(); 21 | using var configHandleHolder = configHandle?.Acquire() ?? default; 22 | context.handle_error(Methods.tiledb_vfs_alloc(contextHandle, configHandleHolder, &vfs)); 23 | successful = true; 24 | } 25 | finally 26 | { 27 | if (successful) 28 | { 29 | handle.InitHandle(vfs); 30 | } 31 | else 32 | { 33 | handle.SetHandleAsInvalid(); 34 | } 35 | } 36 | 37 | return handle; 38 | } 39 | 40 | protected override bool ReleaseHandle() 41 | { 42 | fixed (IntPtr* p = &handle) 43 | { 44 | Methods.tiledb_vfs_free((tiledb_vfs_t**)p); 45 | } 46 | return true; 47 | } 48 | 49 | internal void InitHandle(tiledb_vfs_t* h) { SetHandle((IntPtr)h); } 50 | public override bool IsInvalid => handle == IntPtr.Zero; 51 | 52 | public SafeHandleHolder Acquire() => new(this); 53 | } 54 | -------------------------------------------------------------------------------- /sources/TileDB.CSharp/Marshalling/ScratchBuffer.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Buffers; 3 | using System.Runtime.InteropServices; 4 | 5 | #nullable enable 6 | 7 | namespace TileDB.CSharp.Marshalling; 8 | 9 | /// 10 | /// Manages temporary buffers with low GC pressure. 11 | /// 12 | /// 13 | /// Objects of this type should not be passed around; instead pass their property. 14 | /// 15 | /// The type of items this scratch buffer stores. 16 | internal ref struct ScratchBuffer 17 | { 18 | public Span Span { get; private set; } 19 | 20 | private T[]? _arrayToReturn; 21 | 22 | /// 23 | /// Creates a of length at least . 24 | /// 25 | /// The buffer's minimum length. 26 | /// A pre-allocated that will 27 | /// be preferred if it has at least elements. 28 | /// Whether to make be 29 | /// exactly of length . Defaults to . 30 | /// 31 | /// could be allocated from the stack using 32 | /// the keyword. If it is too small, 33 | /// will come from the array pool. 34 | /// 35 | /// 36 | public ScratchBuffer(int minimumLength, Span preAllocatedSpan, bool exactSize = false) 37 | { 38 | if (preAllocatedSpan.Length >= minimumLength) 39 | { 40 | Span = preAllocatedSpan; 41 | if (exactSize) 42 | { 43 | Span = Span[..minimumLength]; 44 | } 45 | _arrayToReturn = null; 46 | } 47 | else 48 | this = new ScratchBuffer(minimumLength); 49 | } 50 | 51 | /// 52 | /// Creates a of length at least . 53 | /// 54 | /// The buffer's minimum length. 55 | /// Whether to make be 56 | /// exactly of length . Defaults to . 57 | /// The created instance's 58 | /// will always come from the array pool. 59 | public ScratchBuffer(int minimumLength, bool exactSize = false) 60 | { 61 | Span = _arrayToReturn = ArrayPool.Shared.Rent(minimumLength); 62 | if (exactSize) 63 | { 64 | Span = Span[..minimumLength]; 65 | } 66 | } 67 | 68 | /// 69 | /// Allows directly using this in a statement. 70 | /// 71 | public ref T GetPinnableReference() => ref MemoryMarshal.GetReference(Span); 72 | 73 | /// 74 | /// Disposes the . 75 | /// 76 | /// 77 | /// This function must be always called after using a 78 | /// to release any pooled arrays that might have been used. You can use 79 | /// keyword to do it more intuitively. After disposal, the spans returned by the 80 | /// property must not be used, and accessing it will return an empty span. 81 | public void Dispose() 82 | { 83 | if (_arrayToReturn == null) return; 84 | 85 | Span = default; 86 | ArrayPool.Shared.Return(_arrayToReturn); 87 | _arrayToReturn = null; 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /sources/TileDB.CSharp/Marshalling/SequentialPair.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.InteropServices; 3 | 4 | namespace TileDB.CSharp.Marshalling; 5 | 6 | /// 7 | /// A struct containing two values of the same type that can be passed to native code. 8 | /// Has implicit conversion operators between . 9 | /// 10 | /// The type of the values 11 | /// 12 | /// We can't use value tuples in interop because they are marked with auto layout. 13 | /// 14 | [StructLayout(LayoutKind.Sequential)] 15 | internal struct SequentialPair 16 | { 17 | public T First; 18 | public T Second; 19 | 20 | public static implicit operator (T First, T Second)(SequentialPair x) => (x.First, x.Second); 21 | 22 | public static implicit operator SequentialPair((T First, T Second) x) => new() { First = x.First, Second = x.Second }; 23 | } 24 | -------------------------------------------------------------------------------- /sources/TileDB.CSharp/Marshalling/StringHandleHolder.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Diagnostics; 3 | using System.Text; 4 | using TileDB.Interop; 5 | 6 | namespace TileDB.CSharp.Marshalling; 7 | 8 | internal unsafe struct StringHandleHolder : IDisposable 9 | { 10 | internal tiledb_string_t* _handle; 11 | 12 | public void Dispose() 13 | { 14 | if (_handle == null) 15 | { 16 | return; 17 | } 18 | 19 | fixed (tiledb_string_t** handlePtr = &_handle) 20 | { 21 | int result = Methods.tiledb_string_free(handlePtr); 22 | Debug.Assert(result == (int)Status.TILEDB_OK); 23 | } 24 | } 25 | 26 | public override string ToString() 27 | { 28 | if (_handle == null) 29 | { 30 | return string.Empty; 31 | } 32 | 33 | byte* data; 34 | nuint length; 35 | ErrorHandling.ThrowOnError(Methods.tiledb_string_view(_handle, (sbyte**)&data, &length)); 36 | 37 | return Encoding.UTF8.GetString(data, checked((int)length)); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /sources/TileDB.CSharp/Obsoletions.cs: -------------------------------------------------------------------------------- 1 | namespace TileDB.CSharp; 2 | 3 | internal static class Obsoletions 4 | { 5 | #pragma warning disable S1075 // URIs should not be hardcoded 6 | public const string SharedUrlFormat = "https://tiledb-inc.github.io/TileDB-CSharp/obsoletions.html#{0}"; 7 | #pragma warning restore S1075 // URIs should not be hardcoded 8 | 9 | public const string LegacyEnumNamesMessage = "Enum values that start with TILEDB_ are obsolete."; 10 | public const string LegacyEnumNamesDiagId = "TILEDB0001"; 11 | 12 | public const string ObsoleteDataTypeMessage = "This data type is obsolete."; 13 | public const string ObsoleteDataTypeDiagId = "TILEDB0002"; 14 | 15 | public const string TileDBInteropMessage = "Members of the TileDB.Interop namespace should not be used by user code and will become internal in a future version."; 16 | public const string TileDBInteropDiagId = "TILEDB0003"; 17 | 18 | public const string ContextErrorHappenedMessage = "The Context.ErrorHappened event is obsolete and will not be invoked."; 19 | public const string ContextErrorHappenedDiagId = "TILEDB0004"; 20 | 21 | public const string ErrorExceptionMessage = "The ErrorException type is obsolete and will not be thrown. Catch TileDBException instead."; 22 | public const string ErrorExceptionDiagId = "TILEDB0005"; 23 | 24 | public const string DimensionCreateMessage = "The overload of Dimension.Create that accepts an array is obsolete. Use the overload that explicitly accepts the lower and upper bounds instead."; 25 | public const string DimensionCreateDiagId = "TILEDB0006"; 26 | 27 | public const string QueryConditionInitMessage = "The constructor and Init method of the QueryCondition classes is obsolete. Use the static Create methods instead."; 28 | public const string QueryConditionInitDiagId = "TILEDB0007"; 29 | 30 | public const string QueryConditionCombineMessage = "The QueryCondition.Combine method is obsolete. Use the '&', '|' and '!' operators instead."; 31 | public const string QueryConditionCombineDiagId = "TILEDB0008"; 32 | 33 | public const string ConsolidateMetadataMessage = "The Array.ConsolidateMetadata and ArrayMetadata.ConsolidateMetadata methods are obsolete. Call Array.Consolidate with the config value 'sm.consolidation.mode' set to 'array_meta' instead."; 34 | public const string ConsolidateMetadataDiagId = "TILEDB0009"; 35 | 36 | public const string QuerySubmitAsyncMessage = "The Query.SubmitAsync method is obsolete due to reliability problems and will be removed in a future release"; 37 | public const string QuerySubmitAsyncDiagId = "TILEDB0010"; 38 | 39 | public const string QuerySubarrayMessage = "Subarray-related methods of the Query class are obsolete and will become unavailable in a future version."; 40 | public const string QuerySubarrayDiagId = "TILEDB0011"; 41 | 42 | public const string TileDBInterop2Message = "Members of the TileDB.Interop namespace should not be used by user code and will become internal in a future version."; 43 | public const string TileDBInterop2DiagId = "TILEDB0012"; 44 | 45 | public const string DataTypeTypeConversionsMessage = "The EnumUtils.TypeToDataType and EnumUtils.DataTypeToType methods are obsolete and will be removed in a future version."; 46 | public const string DataTypeTypeConversionsDiagId = "TILEDB0013"; 47 | 48 | public const string TileDBInterop3Message = "Members of the TileDB.Interop namespace should not be used by user code and will become internal in a future version."; 49 | public const string TileDBInterop3DiagId = "TILEDB0014"; 50 | 51 | public const string ConfigIteratorMessage = "ConfigIterator is obsolete. Directly enumerate a Config or call its EnumerateOptions method instead."; 52 | public const string ConfigIteratorDiagId = "TILEDB0015"; 53 | 54 | public const string FilestoreApiMessage = "File is obsolete and will be removed in a future version."; 55 | public const string FilestoreApiDiagId = "TILEDB0016"; 56 | } 57 | -------------------------------------------------------------------------------- /sources/TileDB.CSharp/QueryChannel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using TileDB.CSharp.Marshalling.SafeHandles; 3 | using TileDB.Interop; 4 | 5 | namespace TileDB.CSharp; 6 | 7 | /// 8 | /// Represents a TileDB query channel object. 9 | /// 10 | public unsafe sealed class QueryChannel : IDisposable 11 | { 12 | private readonly Context _ctx; 13 | 14 | private readonly Query _query; 15 | 16 | private readonly QueryChannelHandle _handle; 17 | 18 | internal QueryChannel(Context ctx, Query query, QueryChannelHandle handle) 19 | { 20 | _ctx = ctx; 21 | _query = query; 22 | _handle = handle; 23 | } 24 | 25 | internal QueryChannelHandle Handle => _handle; 26 | 27 | /// 28 | public void Dispose() 29 | { 30 | _handle.Dispose(); 31 | } 32 | 33 | /// 34 | /// Adds an aggregate field to the . 35 | /// 36 | /// The operation to apply. 37 | /// The name under which the result of the operation will be available in the query. 38 | public void ApplyAggregate(AggregateOperation operation, string name) 39 | { 40 | using var ctxHandle = _ctx.Handle.Acquire(); 41 | using var handle = _handle.Acquire(); 42 | using var ms_name = new MarshaledString(name); 43 | using var operationHandle = operation.CreateHandle(_ctx, _query); 44 | using var operationHandlePtr = operationHandle.Acquire(); 45 | _ctx.handle_error(Methods.tiledb_channel_apply_aggregate(ctxHandle, handle, ms_name, operationHandlePtr)); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /sources/TileDB.CSharp/QueryField.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using TileDB.CSharp.Marshalling.SafeHandles; 3 | using TileDB.Interop; 4 | 5 | namespace TileDB.CSharp; 6 | 7 | /// 8 | /// Represents a TileDB query field object. 9 | /// 10 | public unsafe sealed class QueryField : IDisposable 11 | { 12 | private readonly Context _ctx; 13 | 14 | private readonly Query _query; 15 | 16 | private readonly QueryFieldHandle _handle; 17 | 18 | internal QueryField(Context ctx, Query query, QueryFieldHandle handle, string name) 19 | { 20 | _ctx = ctx; 21 | _query = query; 22 | _handle = handle; 23 | Name = name; 24 | } 25 | 26 | /// 27 | /// Gets the number of values per cell of the . 28 | /// 29 | public uint ValuesPerCell 30 | { 31 | get 32 | { 33 | using var ctxHandle = _ctx.Handle.Acquire(); 34 | using var handle = _handle.Acquire(); 35 | uint result; 36 | _ctx.handle_error(Methods.tiledb_field_cell_val_num(ctxHandle, handle, &result)); 37 | return result; 38 | } 39 | } 40 | 41 | /// 42 | /// Gets the data type of the . 43 | /// 44 | public DataType DataType 45 | { 46 | get 47 | { 48 | using var ctxHandle = _ctx.Handle.Acquire(); 49 | using var handle = _handle.Acquire(); 50 | tiledb_datatype_t result; 51 | _ctx.handle_error(Methods.tiledb_field_datatype(ctxHandle, handle, &result)); 52 | return (DataType)result; 53 | } 54 | } 55 | 56 | /// 57 | /// Gets the origin of the . 58 | /// 59 | public QueryFieldOrigin Origin 60 | { 61 | get 62 | { 63 | using var ctxHandle = _ctx.Handle.Acquire(); 64 | using var handle = _handle.Acquire(); 65 | tiledb_field_origin_t result; 66 | _ctx.handle_error(Methods.tiledb_field_origin(ctxHandle, handle, &result)); 67 | return (QueryFieldOrigin)result; 68 | } 69 | } 70 | 71 | /// 72 | /// The name of the . 73 | /// 74 | public string Name { get; } 75 | 76 | /// 77 | /// Gets the corresponding to the . 78 | /// 79 | public QueryChannel GetChannel() 80 | { 81 | var handle = new QueryChannelHandle(); 82 | var successful = false; 83 | tiledb_query_channel_t* channel = null; 84 | try 85 | { 86 | using (var ctxHandle = _ctx.Handle.Acquire()) 87 | using (var queryHandle = _handle.Acquire()) 88 | { 89 | _ctx.handle_error(Methods.tiledb_field_channel(ctxHandle, queryHandle, &channel)); 90 | } 91 | successful = true; 92 | } 93 | finally 94 | { 95 | if (successful) 96 | { 97 | handle.InitHandle(_ctx, channel); 98 | } 99 | else 100 | { 101 | handle.SetHandleAsInvalid(); 102 | } 103 | } 104 | 105 | return new QueryChannel(_ctx, _query, handle); 106 | } 107 | 108 | /// 109 | public void Dispose() 110 | { 111 | _handle.Dispose(); 112 | } 113 | } 114 | -------------------------------------------------------------------------------- /sources/TileDB.CSharp/QueryStatusDetails.cs: -------------------------------------------------------------------------------- 1 | using TileDB.Interop; 2 | 3 | namespace TileDB.CSharp; 4 | 5 | /// 6 | /// Specifies additional details about the status of a . 7 | /// 8 | public struct QueryStatusDetails 9 | { 10 | internal tiledb_query_status_details_t _details; 11 | 12 | /// 13 | /// The reason the cannot continue. 14 | /// 15 | public QueryStatusDetailsReason Reason 16 | { 17 | readonly get => (QueryStatusDetailsReason)_details.incomplete_reason; 18 | set => _details.incomplete_reason = (tiledb_query_status_details_reason_t)value; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /sources/TileDB.CSharp/README.md: -------------------------------------------------------------------------------- 1 | # TileDB.CSharp 2 | 3 | This package provides a C# interface to the [TileDB Embedded](https://tiledb.com/products/tiledb-embedded) storage engine. 4 | 5 | ## Usage 6 | 7 | After installing the package, see [the official documentation](https://docs.tiledb.com/main/) and [the C# example project](https://github.com/TileDB-Inc/TileDB-CSharp/tree/main/examples/TileDB.CSharp.Example) to learn how to use it. 8 | 9 | ### Resolving `DllNotFoundException`s 10 | 11 | To reduce the download size, the TileDB Embedded native library is downloaded only on [RID](https://learn.microsoft.com/en-us/dotnet/core/rid-catalog)-specific builds. If you are getting `DllNotFoundException`s that the library `tiledb` is not found, you have to specify an RID, and you will get a warning if you don't. There are many ways to do it: 12 | 13 | * 14 | __From the project file:__ 15 | 16 | Add one of the following properties to your project: 17 | 18 | ```xml 19 | 20 | win-x64 21 | 22 | true 23 | 24 | ``` 25 | 26 | * 27 | __From the .NET CLI:__ 28 | 29 | When building or publishing a project you can specify the `-r ` option to provide an RID. 30 | 31 | > Consult the .NET documentation for more information. 32 | 33 | Native binaries are provided for the following RIDs, and all that derive from them such as `win10-x64` or `ubuntu-x64`: 34 | 35 | * `win-x64` 36 | * `linux-x64` 37 | * `osx-x64` 38 | * `osx-arm64` 39 | 40 | ### Patching TileDB Embedded 41 | 42 | You can update to a newer patch version of TileDB Embedded by explicitly specifying a version of the [`TileDB.Native`](https://nuget.org/packages/TIleDB.Native) package in your project. 43 | -------------------------------------------------------------------------------- /sources/TileDB.CSharp/Stats.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using TileDB.Interop; 3 | 4 | namespace TileDB.CSharp; 5 | 6 | /// 7 | /// Contains methods related to collecting statistics of TileDB Embedded. 8 | /// 9 | public static unsafe class Stats 10 | { 11 | /// 12 | /// Enables statistic gathering 13 | /// 14 | public static void Enable() => ErrorHandling.ThrowOnError(Methods.tiledb_stats_enable()); 15 | 16 | /// 17 | /// Disables statistic gathering 18 | /// 19 | public static void Disable() => ErrorHandling.ThrowOnError(Methods.tiledb_stats_disable()); 20 | 21 | /// 22 | /// Resets all previously gathered statistics. 23 | /// 24 | public static void Reset() => ErrorHandling.ThrowOnError(Methods.tiledb_stats_reset()); 25 | 26 | /// 27 | /// Writes statistics to standard output. 28 | /// 29 | public static void Dump() => Console.WriteLine(Get()); 30 | 31 | /// 32 | /// Writes TileDB statistics to a file. 33 | /// 34 | /// Path to file to dump statistics 35 | public static void Dump(string filePath) => System.IO.File.WriteAllText(filePath, Get()); 36 | 37 | /// 38 | /// Gets a JSON string with statistics about TileDB Embedded. 39 | /// 40 | public static string Get() 41 | { 42 | sbyte* result = null; 43 | try 44 | { 45 | ErrorHandling.ThrowOnError(Methods.tiledb_stats_dump_str(&result)); 46 | return MarshaledStringOut.GetStringFromNullTerminated(result); 47 | } 48 | finally 49 | { 50 | if (result is not null) 51 | { 52 | ErrorHandling.ThrowOnError(Methods.tiledb_stats_free_str(&result)); 53 | } 54 | } 55 | } 56 | 57 | /// 58 | /// Gets a JSON string with raw statistics about TileDB Embedded. 59 | /// 60 | public static string GetRaw() 61 | { 62 | sbyte* result = null; 63 | try 64 | { 65 | ErrorHandling.ThrowOnError(Methods.tiledb_stats_raw_dump_str(&result)); 66 | return MarshaledStringOut.GetStringFromNullTerminated(result); 67 | } 68 | finally 69 | { 70 | if (result is not null) 71 | { 72 | ErrorHandling.ThrowOnError(Methods.tiledb_stats_free_str(&result)); 73 | } 74 | } 75 | } 76 | 77 | /// 78 | /// Enables heap profiling of TileDB Embedded. 79 | /// 80 | /// The file name prefix of the dumps. If it is 81 | /// or empty, dumps will be written to stdout. 82 | /// If non-zero, this spawns a dedicated 83 | /// thread to dump on this time interval. 84 | /// If non-zero, a dump will occur when the total 85 | /// number of lifetime allocated bytes is increased by more than this amount. 86 | /// If non-zero, labeled allocations with a number 87 | /// of bytes lower than this threshold will not be reported in the dump. 88 | public static void EnableHeapProfiler(string? fileNamePrefix, ulong dumpIntervalMilliseconds, ulong dumpIntervalBytes, ulong dumpThresholdBytes) 89 | { 90 | using var ms_fileNamePrefix = new MarshaledString(fileNamePrefix ?? ""); 91 | ErrorHandling.ThrowOnError(Methods.tiledb_heap_profiler_enable(ms_fileNamePrefix, dumpIntervalMilliseconds, dumpIntervalBytes, dumpThresholdBytes)); 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /sources/TileDB.CSharp/ThrowHelpers.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Diagnostics.CodeAnalysis; 3 | using System.Runtime.CompilerServices; 4 | 5 | namespace TileDB.CSharp; 6 | 7 | internal static class ThrowHelpers 8 | { 9 | [DoesNotReturn] 10 | public static void ThrowArgumentNull(string? paramName) => 11 | throw new ArgumentNullException(paramName); 12 | 13 | [DoesNotReturn] 14 | public static void ThrowInvalidDataType(DataType dataType, [CallerArgumentExpression(nameof(dataType))] string? paramName = null) => 15 | throw new ArgumentOutOfRangeException(nameof(dataType), dataType, "Invalid data type."); 16 | 17 | [DoesNotReturn] 18 | public static void ThrowTypeNotSupported() => 19 | throw new NotSupportedException("Type is not supported."); 20 | 21 | // We don't have to specify the type in the type argument, it can be seen from the stacktrace. 22 | [DoesNotReturn] 23 | public static void ThrowTypeMismatch(DataType type) => 24 | throw new ArgumentException($"Type is not compatible with data type {type}."); 25 | 26 | [DoesNotReturn] 27 | public static void ThrowStringTypeMismatch(DataType type) => 28 | throw new ArgumentException($"Cannot encode data type {type} into strings."); 29 | 30 | [DoesNotReturn] 31 | public static void ThrowTooBigSize(ulong size, [CallerArgumentExpression(nameof(size))] string? paramName = null) => 32 | throw new ArgumentOutOfRangeException(paramName, size, "Size argument is too big for the type to fit."); 33 | 34 | [DoesNotReturn] 35 | public static void ThrowQueryConditionDifferentContexts() => 36 | throw new InvalidOperationException("Cannot combine query conditions associated with different contexts."); 37 | 38 | [DoesNotReturn] 39 | public static void ThrowSubarrayLengthMismatch(string paramName) => 40 | throw new ArgumentException("The length of the data is not equal to double the length of dimensions.", paramName); 41 | 42 | [DoesNotReturn] 43 | public static void ThrowManagedType() => 44 | throw new NotSupportedException("Types with managed references are not supported."); 45 | 46 | [DoesNotReturn] 47 | public static void ThrowOperationNotAllowedOnReadQueries() => 48 | throw new NotSupportedException("The operation is not allowed on read queries."); 49 | 50 | [DoesNotReturn] 51 | public static void ThrowBufferCannotBeEmpty(string paramName) => 52 | throw new ArgumentException("Buffer cannot be empty.", paramName); 53 | 54 | [DoesNotReturn] 55 | public static void ThrowArgumentNullException(string paramName) => 56 | throw new ArgumentNullException(paramName); 57 | 58 | [DoesNotReturn] 59 | public static void ThrowBufferUnsafelySet() => 60 | throw new InvalidOperationException("Cannot get the number of elements read into a buffer set with the 'Query.UnsafeSetDataBuffer' method."); 61 | } 62 | -------------------------------------------------------------------------------- /sources/TileDB.CSharp/TileDB.CSharp.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net8.0 5 | false 6 | true 7 | enable 8 | TileDB.CSharp 9 | 5.17.0 10 | C# wrapper of the TileDB Embedded universal data engine. 11 | README.md 12 | true 13 | true 14 | 5.16.0 15 | $(NoWarn);TILEDB0012;TILEDB0013;TILEDB0014 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /sources/TileDB.CSharp/TileDBException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace TileDB.CSharp; 4 | 5 | /// 6 | /// This exception is thrown when a TileDB Embedded method fails with an error. 7 | /// 8 | /// 9 | /// Almost all methods of this library may throw it. 10 | /// 11 | public sealed class TileDBException : Exception 12 | { 13 | /// 14 | /// The exception's status code, as reported by tiledb_status_code function. 15 | /// 16 | public int StatusCode { get; set; } 17 | 18 | /// 19 | /// Creates a . 20 | /// 21 | public TileDBException() { } 22 | 23 | /// 24 | /// Creates a with a message. 25 | /// 26 | /// The exception's message. 27 | public TileDBException(string? message) : base(message) { } 28 | 29 | /// 30 | /// Creates a with a message and inner exception. 31 | /// 32 | /// The exception's message. 33 | /// The exception's inner exception. 34 | public TileDBException(string? message, Exception? inner) : base(message, inner) { } 35 | } 36 | -------------------------------------------------------------------------------- /sources/TileDB.CSharp/build/TileDB.CSharp.targets: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /sources/TileDB.CSharp/buildTransitive/TileDB.CSharp.targets: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /tests/TileDB.CSharp.Test/AggregatesTest.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.VisualStudio.TestTools.UnitTesting; 2 | 3 | namespace TileDB.CSharp.Test; 4 | 5 | [TestClass] 6 | public class AggregatesTest 7 | { 8 | [TestMethod] 9 | public unsafe void Test() 10 | { 11 | var context = Context.GetDefault(); 12 | 13 | using var tmpArrayPath = new TemporaryDirectory("aggregate_test"); 14 | 15 | using var array = new Array(context, tmpArrayPath); 16 | Assert.IsNotNull(array); 17 | 18 | using var array_schema = BuildArraySchema(context); 19 | Assert.IsNotNull(array_schema); 20 | 21 | array.Create(array_schema); 22 | 23 | array.Open(QueryType.Write); 24 | 25 | int[] data = [62, 26, 81, 86, 93, 0, 60, 25, 68, 28]; 26 | byte[] validity = [1, 1, 1, 1, 1, 0, 1, 1, 1, 1]; 27 | 28 | using (var query = new Query(array)) 29 | { 30 | query.SetLayout(LayoutType.RowMajor); 31 | query.SetDataBuffer("a1", data); 32 | query.SetValidityBuffer("a1", validity); 33 | 34 | query.Submit(); 35 | } 36 | array.Close(); 37 | 38 | array.Open(QueryType.Read); 39 | int[] dataRead = new int[data.Length]; 40 | byte[] validityRead = new byte[data.Length]; 41 | ulong count, nullCount; 42 | long sum; 43 | double mean; 44 | int min, max; 45 | byte sumValidity, meanValidity, minValidity, maxValidity; 46 | using (var query = new Query(array)) 47 | { 48 | query.SetLayout(LayoutType.RowMajor); 49 | using var subarray = new Subarray(array); 50 | subarray.AddRange(0, 1, 10); 51 | query.SetSubarray(subarray); 52 | 53 | using var channel = query.GetDefaultChannel(); 54 | channel.ApplyAggregate(AggregateOperation.Count, nameof(count)); 55 | channel.ApplyAggregate(AggregateOperation.Unary(AggregateOperator.Sum, "a1"), nameof(sum)); 56 | channel.ApplyAggregate(AggregateOperation.Unary(AggregateOperator.Mean, "a1"), nameof(mean)); 57 | channel.ApplyAggregate(AggregateOperation.Unary(AggregateOperator.Min, "a1"), nameof(min)); 58 | channel.ApplyAggregate(AggregateOperation.Unary(AggregateOperator.Max, "a1"), nameof(max)); 59 | channel.ApplyAggregate(AggregateOperation.Unary(AggregateOperator.NullCount, "a1"), nameof(nullCount)); 60 | 61 | using var countField = query.GetField(nameof(count)); 62 | Assert.AreEqual(nameof(count), countField.Name); 63 | Assert.AreEqual(DataType.UInt64, countField.DataType); 64 | Assert.AreEqual(1u, countField.ValuesPerCell); 65 | Assert.AreEqual(QueryFieldOrigin.Aggregate, countField.Origin); 66 | 67 | query.SetDataBuffer("a1", dataRead); 68 | query.SetValidityBuffer("a1", validityRead); 69 | query.SetDataBuffer(nameof(count), &count, 1); 70 | query.SetDataBuffer(nameof(sum), &sum, 1); 71 | query.SetValidityBuffer(nameof(sum), &sumValidity, 1); 72 | query.SetDataBuffer(nameof(mean), &mean, 1); 73 | query.SetValidityBuffer(nameof(mean), &meanValidity, 1); 74 | query.SetDataBuffer(nameof(min), &min, 1); 75 | query.SetValidityBuffer(nameof(min), &minValidity, 1); 76 | query.SetDataBuffer(nameof(max), &max, 1); 77 | query.SetValidityBuffer(nameof(max), &maxValidity, 1); 78 | query.SetDataBuffer(nameof(nullCount), &nullCount, 1); 79 | 80 | query.Submit(); 81 | 82 | CollectionAssert.AreEqual(data, dataRead); 83 | CollectionAssert.AreEqual(validity, validityRead); 84 | Assert.AreEqual((ulong)data.Length, count); 85 | Assert.AreEqual(529, sum); 86 | Assert.AreEqual(58.8, mean, 0.1); 87 | Assert.AreEqual(25, min); 88 | Assert.AreEqual(93, max); 89 | Assert.AreEqual(1, sumValidity); 90 | Assert.AreEqual(1, meanValidity); 91 | Assert.AreEqual(1, minValidity); 92 | Assert.AreEqual(1, maxValidity); 93 | } 94 | } 95 | 96 | private static ArraySchema BuildArraySchema(Context context) 97 | { 98 | var array_schema = new ArraySchema(context, ArrayType.Dense); 99 | using var domain = new Domain(context); 100 | using var dimension = Dimension.Create(context, "dim1", 1, 10, 5); 101 | domain.AddDimension(dimension); 102 | array_schema.SetDomain(domain); 103 | 104 | using var a1 = new Attribute(context, "a1", DataType.Int32); 105 | a1.SetNullable(true); 106 | array_schema.AddAttribute(a1); 107 | array_schema.Check(); 108 | return array_schema; 109 | } 110 | } 111 | -------------------------------------------------------------------------------- /tests/TileDB.CSharp.Test/ArrayMetadataTest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using Microsoft.VisualStudio.TestTools.UnitTesting; 4 | 5 | namespace TileDB.CSharp.Test; 6 | 7 | [TestClass] 8 | public class ArrayMetadataTest 9 | { 10 | [TestMethod] 11 | public void TestArrayMetadata() 12 | { 13 | var tmpArrayPath = TestUtil.MakeTestPath("metadata_array"); 14 | 15 | if (Directory.Exists(tmpArrayPath)) 16 | { 17 | Directory.Delete(tmpArrayPath, true); 18 | } 19 | createArrayMetadataArray(tmpArrayPath); 20 | writeArrayMetadata(tmpArrayPath); 21 | readArrayMetadata(tmpArrayPath); 22 | clearArrayMetadata(tmpArrayPath); 23 | } 24 | 25 | private void createArrayMetadataArray(string tmpArrayPath) 26 | { 27 | var context = Context.GetDefault(); 28 | 29 | var rowDim = Dimension.Create(context, "rows", 1, 4, 4); 30 | Assert.IsNotNull(rowDim); 31 | 32 | var colDim = Dimension.Create(context, "cols", 1, 4, 4); 33 | Assert.IsNotNull(rowDim); 34 | 35 | var domain = new Domain(context); 36 | Assert.IsNotNull(domain); 37 | 38 | domain.AddDimensions(rowDim, colDim); 39 | 40 | var array_schema = new ArraySchema(context, ArrayType.Sparse); 41 | Assert.IsNotNull(array_schema); 42 | var a1 = new Attribute(context, "a1", DataType.UInt32); 43 | Assert.IsNotNull(a1); 44 | 45 | array_schema.SetCellOrder(LayoutType.RowMajor); 46 | array_schema.SetTileOrder(LayoutType.RowMajor); 47 | 48 | array_schema.AddAttribute(a1); 49 | 50 | array_schema.SetDomain(domain); 51 | 52 | array_schema.Check(); 53 | 54 | var array = new Array(context, tmpArrayPath); 55 | Assert.IsNotNull(array); 56 | 57 | array.Create(array_schema); 58 | } 59 | 60 | private void writeArrayMetadata(string tmpArrayPath) 61 | { 62 | var context = Context.GetDefault(); 63 | 64 | var array = new Array(context, tmpArrayPath); 65 | Assert.IsNotNull(array); 66 | 67 | array.Open(QueryType.Write); 68 | 69 | array.PutMetadata("key1", [25]); 70 | 71 | array.PutMetadata("key2", [25, 26, 27, 28]); 72 | 73 | array.PutMetadata("key3", [25.1f]); 74 | 75 | array.PutMetadata("key4", [25.1f, 26.2f, 27.3f, 28.4f]); 76 | 77 | array.PutMetadata("key5", "This is TileDB array metadata, that supports Unicode characters! 🥳"); 78 | 79 | array.Close(); 80 | } 81 | 82 | private void readArrayMetadata(string tmpArrayPath) 83 | { 84 | var context = Context.GetDefault(); 85 | 86 | var array = new Array(context, tmpArrayPath); 87 | Assert.IsNotNull(array); 88 | 89 | array.Open(QueryType.Read); 90 | 91 | var v1 = array.GetMetadata("key1"); 92 | CollectionAssert.AreEqual(new int[]{ 25 }, v1); 93 | 94 | var v2 = array.GetMetadata("key2"); 95 | CollectionAssert.AreEqual(new int[]{ 25, 26, 27, 28 }, v2); 96 | 97 | var v3 = array.GetMetadata("key3"); 98 | CollectionAssert.AreEqual(new float[]{ 25.1f }, v3); 99 | 100 | var v4 = array.GetMetadata("key4"); 101 | CollectionAssert.AreEqual(new float[]{ 25.1f, 26.2f, 27.3f, 28.4f }, v4); 102 | 103 | var s = array.GetMetadata("key5"); 104 | Assert.AreEqual("This is TileDB array metadata, that supports Unicode characters! 🥳", s); 105 | 106 | var num = array.MetadataNum(); 107 | Assert.AreEqual((ulong)5, num); 108 | 109 | var keys = array.MetadataKeys(); 110 | CollectionAssert.AreEqual(new string[]{"key1", "key2", "key3", "key4", "key5"}, keys); 111 | 112 | var arrayMetadata = array.GetMetadataFromIndex(3); 113 | Assert.AreEqual("key4", arrayMetadata.key); 114 | Assert.AreEqual(4, arrayMetadata.key.Length); 115 | 116 | Assert.AreEqual(4, arrayMetadata.data.Length); 117 | 118 | array.Close(); 119 | } 120 | 121 | private void clearArrayMetadata(string tmpArrayPath) 122 | { 123 | var context = Context.GetDefault(); 124 | 125 | var array = new Array(context, tmpArrayPath); 126 | Assert.IsNotNull(array); 127 | 128 | array.Open(QueryType.Write); 129 | 130 | array.DeleteMetadata("key1"); 131 | array.DeleteMetadata("key2"); 132 | array.DeleteMetadata("key3"); 133 | array.DeleteMetadata("key4"); 134 | array.DeleteMetadata("key5"); 135 | array.Close(); 136 | } 137 | } 138 | -------------------------------------------------------------------------------- /tests/TileDB.CSharp.Test/ArraySchemaEvolutionTest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Microsoft.VisualStudio.TestTools.UnitTesting; 3 | 4 | namespace TileDB.CSharp.Test; 5 | 6 | [TestClass] 7 | public class ArraySchemaEvolutionTest 8 | { 9 | private static readonly string ArrayUri = TestUtil.MakeTestPath("test-schema-evolution"); 10 | 11 | [TestInitialize] 12 | public void CreateArray() 13 | { 14 | var ctx = Context.GetDefault(); 15 | 16 | var rows = Dimension.Create(ctx, "rows", 1, 4, 4); 17 | var cols = Dimension.Create(ctx, "cols", 1, 4, 4); 18 | 19 | var domain = new Domain(ctx); 20 | domain.AddDimensions(rows, cols); 21 | 22 | var schema = new ArraySchema(ctx, ArrayType.Dense); 23 | schema.SetDomain(domain); 24 | 25 | var nullableAttr = new Attribute(ctx, "a1", DataType.Int32); 26 | nullableAttr.SetNullable(true); 27 | schema.AddAttributes(nullableAttr, new Attribute(ctx, "a2", DataType.Int32), 28 | new Attribute(ctx, "a3", DataType.Boolean)); 29 | schema.Check(); 30 | TestUtil.CreateArray(ctx, ArrayUri, schema); 31 | } 32 | 33 | [TestMethod] 34 | public void TestSchemaEvolution() 35 | { 36 | var ctx = Context.GetDefault(); 37 | var array = new Array(ctx, ArrayUri); 38 | TestUtil.PrintLocalSchema(ArrayUri); 39 | 40 | array.Open(QueryType.Read); 41 | // Select existing attribute from schema to delete 42 | var delAttr = array.Schema().Attributes()["a3"]; 43 | array.Close(); 44 | 45 | var schemaEvolution = new ArraySchemaEvolution(ctx); 46 | 47 | var addAttr = new Attribute(ctx, "a4", DataType.Float32); 48 | schemaEvolution.AddAttribute(addAttr); 49 | schemaEvolution.DropAttribute("a2"); 50 | schemaEvolution.DropAttribute(delAttr); 51 | Console.WriteLine("Removing attributes `a2`, `a3`; Adding new attribute `a4`"); 52 | schemaEvolution.EvolveArray(ArrayUri); 53 | 54 | array.Open(QueryType.Read); 55 | var schema = array.Schema(); 56 | TestUtil.PrintLocalSchema(ArrayUri); 57 | Assert.IsTrue(schema.HasAttribute("a1")); 58 | Assert.IsFalse(schema.HasAttribute("a2")); 59 | Assert.IsFalse(schema.HasAttribute("a3")); 60 | Assert.IsTrue(schema.HasAttribute("a4")); 61 | array.Close(); 62 | 63 | schemaEvolution = new ArraySchemaEvolution(ctx); 64 | schemaEvolution.DropAttribute("a1"); 65 | Console.WriteLine("Removing attribute `a1` using Array.Evolve"); 66 | array.Evolve(schemaEvolution); 67 | 68 | array.Open(QueryType.Read); 69 | schema = array.Schema(); 70 | Assert.IsFalse(schema.HasAttribute("a1")); 71 | TestUtil.PrintLocalSchema(ArrayUri); 72 | array.Close(); 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /tests/TileDB.CSharp.Test/CoreUtilTest.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.VisualStudio.TestTools.UnitTesting; 2 | 3 | namespace TileDB.CSharp.Test; 4 | 5 | [TestClass] 6 | public class CoreUtilTest 7 | { 8 | [TestMethod] 9 | public void BuildConfigurationNonEmpty() 10 | { 11 | var buildConfiguration = CoreUtil.GetBuildConfiguration(); 12 | 13 | Assert.IsFalse(string.IsNullOrWhiteSpace(buildConfiguration)); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /tests/TileDB.CSharp.Test/DimensionTest.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.VisualStudio.TestTools.UnitTesting; 2 | using System; 3 | 4 | namespace TileDB.CSharp.Test; 5 | 6 | [TestClass] 7 | public class DimensionTest 8 | { 9 | [TestMethod] 10 | public void TestDimension() { 11 | var context = Context.GetDefault(); 12 | 13 | int bound_lower=1, bound_upper=10, extent = 5; 14 | var dimension = Dimension.Create(context, "test", bound_lower, bound_upper, extent); 15 | 16 | Assert.AreEqual("test", dimension.Name()); 17 | Assert.AreEqual(DataType.Int32, dimension.Type()); 18 | Assert.AreEqual(extent, dimension.TileExtent()); 19 | var dim_domain = dimension.GetDomain(); 20 | Assert.AreEqual((1, 10), dim_domain); 21 | 22 | var dump = dimension.ToString(); 23 | Assert.IsTrue(dump.Contains("test", StringComparison.Ordinal)); 24 | } 25 | 26 | [TestMethod] 27 | public void TestStringDimension() 28 | { 29 | var context = Context.GetDefault(); 30 | 31 | var dimension = Dimension.CreateString(context, "strdim"); 32 | Assert.AreEqual("strdim", dimension.Name()); 33 | Assert.AreEqual(DataType.StringAscii, dimension.Type()); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /tests/TileDB.CSharp.Test/DomainTest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Microsoft.VisualStudio.TestTools.UnitTesting; 3 | 4 | namespace TileDB.CSharp.Test; 5 | 6 | [TestClass] 7 | public class DomainTest 8 | { 9 | [TestMethod] 10 | public void TestDomain() { 11 | // Test context with config 12 | var context = Context.GetDefault(); 13 | 14 | // Test creating domain 15 | var domain = new Domain(context); 16 | 17 | // Test create dimension 18 | uint bound_lower=1, bound_upper=10, extent = 5; 19 | var dimension = Dimension.Create(context, "testuint", bound_lower, bound_upper, extent); 20 | 21 | Assert.AreEqual(false, domain.HasDimension("testuint")); 22 | domain.AddDimension(dimension); 23 | Assert.AreEqual(true, domain.HasDimension("testuint")); 24 | Assert.AreEqual(DataType.UInt32, domain.Type()); 25 | Assert.AreEqual(1, domain.NDim()); 26 | 27 | // Test create another dimension 28 | int bound_lower2=1, bound_upper2=10, extent2 = 5; 29 | var dimension2 = Dimension.Create(context, "testint", bound_lower2, bound_upper2, extent2); 30 | domain.AddDimension(dimension2); 31 | Assert.AreEqual(true, domain.HasDimension("testint")); 32 | Assert.ThrowsException(() => domain.Type()); 33 | Assert.AreEqual(2, domain.NDim()); 34 | 35 | var dim1 = domain.Dimension(0); 36 | Assert.AreEqual(DataType.UInt32, dim1.Type()); 37 | var dim2 = domain.Dimension(1); 38 | Assert.AreEqual(DataType.Int32, dim2.Type()); 39 | 40 | dim1 = domain.Dimension("testuint"); 41 | Assert.AreEqual(DataType.UInt32, dim1.Type()); 42 | Assert.AreEqual("testuint", dim1.Name()); 43 | 44 | dim2 = domain.Dimension("testint"); 45 | Assert.AreEqual(DataType.Int32, dim2.Type()); 46 | Assert.AreEqual("testint", dim2.Name()); 47 | 48 | var dump = domain.ToString(); 49 | Assert.IsTrue(dump.Contains("testuint", StringComparison.Ordinal)); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /tests/TileDB.CSharp.Test/FilterListTest.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.VisualStudio.TestTools.UnitTesting; 2 | 3 | namespace TileDB.CSharp.Test; 4 | 5 | [TestClass] 6 | public class FilterListTest 7 | { 8 | [TestMethod] 9 | public void NewFilterListIsValid() 10 | { 11 | var ctx = Context.GetDefault(); 12 | using var filter_list = new FilterList(ctx); 13 | var gzipFilter = new Filter(ctx, FilterType.Gzip); 14 | var gzip_compression_level = 3; 15 | gzipFilter.SetOption(FilterOption.CompressionLevel, gzip_compression_level); 16 | filter_list.AddFilter(gzipFilter); 17 | 18 | var bit_shuffle_filter = new Filter(ctx, FilterType.BitShuffle); 19 | filter_list.AddFilter(bit_shuffle_filter); 20 | 21 | var positive_delta_filter = new Filter(ctx, FilterType.PositiveDelta); 22 | const uint positiveDeltaMaxWindow = 1024; 23 | positive_delta_filter.SetOption(FilterOption.PositiveDeltaMaxWindow, positiveDeltaMaxWindow); 24 | filter_list.AddFilter(positive_delta_filter); 25 | 26 | const uint maxChunkSize = 512; 27 | filter_list.SetMaxChunkSize(maxChunkSize); 28 | 29 | const uint numFilters = 3; 30 | 31 | Assert.AreEqual(numFilters, filter_list.NFilters()); 32 | Assert.AreEqual(maxChunkSize, filter_list.MaxChunkSize()); 33 | 34 | var filter0 = filter_list.Filter(0); 35 | Assert.AreEqual(FilterType.Gzip, filter0.FilterType()); 36 | Assert.AreEqual(gzip_compression_level, filter0.GetOption(FilterOption.CompressionLevel)); 37 | 38 | var filter1 = filter_list.Filter(1); 39 | Assert.AreEqual(FilterType.BitShuffle, filter1.FilterType()); 40 | 41 | var filter2 = filter_list.Filter(2); 42 | Assert.AreEqual(FilterType.PositiveDelta, filter2.FilterType()); 43 | Assert.AreEqual(positiveDeltaMaxWindow, filter2.GetOption(FilterOption.PositiveDeltaMaxWindow)); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /tests/TileDB.CSharp.Test/FilterTest.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.VisualStudio.TestTools.UnitTesting; 2 | 3 | namespace TileDB.CSharp.Test; 4 | 5 | [TestClass] 6 | public class FilterTest 7 | { 8 | [TestMethod] 9 | public void NewBitShuffleFilterIsValid() 10 | { 11 | var ctx = Context.GetDefault(); 12 | using var filter = new Filter(ctx, FilterType.BitShuffle); 13 | Assert.AreEqual(FilterType.BitShuffle, filter.FilterType()); 14 | } 15 | 16 | [TestMethod] 17 | public void NewGzipFilterIsValid() 18 | { 19 | var ctx = Context.GetDefault(); 20 | using var filter = new Filter(ctx, FilterType.Gzip); 21 | Assert.AreEqual(FilterType.Gzip, filter.FilterType()); 22 | 23 | const int compressionLevel = 6; 24 | filter.SetOption(FilterOption.CompressionLevel, compressionLevel); 25 | Assert.AreEqual(compressionLevel, filter.GetOption(FilterOption.CompressionLevel)); 26 | } 27 | 28 | [TestMethod] 29 | public void NewPositiveDeltaFilterIsValid() 30 | { 31 | var ctx = Context.GetDefault(); 32 | using var filter = new Filter(ctx, FilterType.PositiveDelta); 33 | Assert.AreEqual(FilterType.PositiveDelta, filter.FilterType()); 34 | 35 | const uint positiveDeltaMaxWindow = 1024; 36 | filter.SetOption(FilterOption.PositiveDeltaMaxWindow, positiveDeltaMaxWindow); 37 | Assert.AreEqual(positiveDeltaMaxWindow, filter.GetOption(FilterOption.PositiveDeltaMaxWindow)); 38 | } 39 | 40 | [TestMethod] 41 | public void NewBitWidthReductionFilterIsValid() 42 | { 43 | var ctx = Context.GetDefault(); 44 | using var filter = new Filter(ctx, FilterType.BitWidthReduction); 45 | Assert.AreEqual(FilterType.BitWidthReduction, filter.FilterType()); 46 | 47 | const uint bidWidthMaxWindow = 256; 48 | filter.SetOption(FilterOption.BitWidthMaxWindow, bidWidthMaxWindow); 49 | Assert.AreEqual(bidWidthMaxWindow, filter.GetOption(FilterOption.BitWidthMaxWindow)); 50 | } 51 | 52 | [TestMethod] 53 | public void NewDictionaryFilterIsValid() 54 | { 55 | var ctx = Context.GetDefault(); 56 | using var filter = new Filter(ctx, FilterType.Dictionary); 57 | Assert.AreEqual(FilterType.Dictionary, filter.FilterType()); 58 | 59 | const int compressionLevel = 4; 60 | filter.SetOption(FilterOption.CompressionLevel, compressionLevel); 61 | Assert.AreEqual(compressionLevel, filter.GetOption(FilterOption.CompressionLevel)); 62 | } 63 | 64 | [TestMethod] 65 | public void NewFloatScalingFilterIsValid() 66 | { 67 | var ctx = Context.GetDefault(); 68 | using var filter = new Filter(ctx, FilterType.ScaleFloat); 69 | Assert.AreEqual(FilterType.ScaleFloat, filter.FilterType()); 70 | 71 | const double scale = 4.0; 72 | filter.SetOption(FilterOption.ScaleFloatFactor, scale); 73 | Assert.AreEqual(scale, filter.GetOption(FilterOption.ScaleFloatFactor)); 74 | 75 | const double offset = 1.0; 76 | filter.SetOption(FilterOption.ScaleFloatOffset, offset); 77 | Assert.AreEqual(offset, filter.GetOption(FilterOption.ScaleFloatOffset)); 78 | 79 | const ulong byteWidth = 4; 80 | filter.SetOption(FilterOption.ScaleFloatByteWidth, byteWidth); 81 | Assert.AreEqual(byteWidth, filter.GetOption(FilterOption.ScaleFloatByteWidth)); 82 | } 83 | 84 | [TestMethod] 85 | public void NewWebpFilterIsValid() 86 | { 87 | var ctx = Context.GetDefault(); 88 | using var filter = new Filter(ctx, FilterType.Webp); 89 | Assert.AreEqual(FilterType.Webp, filter.FilterType()); 90 | 91 | const float quality = 59.0f; 92 | filter.SetOption(FilterOption.WebpQuality, quality); 93 | Assert.AreEqual(quality, filter.GetOption(FilterOption.WebpQuality)); 94 | 95 | const WebpInputFormat inputFormat = WebpInputFormat.Bgra; 96 | filter.SetOption(FilterOption.WebpInputFormat, inputFormat); 97 | Assert.AreEqual(inputFormat, filter.GetOption(FilterOption.WebpInputFormat)); 98 | 99 | const bool lossless = false; 100 | filter.SetOption(FilterOption.WebpLossless, lossless); 101 | Assert.AreEqual(lossless, filter.GetOption(FilterOption.WebpLossless)); 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /tests/TileDB.CSharp.Test/StatsTest.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.VisualStudio.TestTools.UnitTesting; 2 | 3 | namespace TileDB.CSharp.Test; 4 | 5 | [TestClass] 6 | public class StatsTest 7 | { 8 | private static readonly string ArrayUri = TestUtil.MakeTestPath("test-stats"); 9 | 10 | [TestMethod] 11 | public void TestStats() 12 | { 13 | Stats.Enable(); 14 | 15 | var ctx = Context.GetDefault(); 16 | var row = Dimension.Create(ctx, "rows", 1, 4, 2); 17 | var col = Dimension.Create(ctx, "cols", 1, 4, 2); 18 | var domain = new Domain(ctx); 19 | domain.AddDimensions(row, col); 20 | var schema = new ArraySchema(ctx, ArrayType.Dense); 21 | schema.SetDomain(domain); 22 | schema.AddAttribute(new Attribute(ctx, "a1", DataType.Int32)); 23 | schema.Check(); 24 | TestUtil.CreateArray(ctx, ArrayUri, schema); 25 | 26 | var array = new Array(ctx, ArrayUri); 27 | array.Open(QueryType.Write); 28 | var query = new Query(array); 29 | query.SetLayout(LayoutType.RowMajor); 30 | var subarray = new Subarray(array); 31 | subarray.SetSubarray(1, 4, 1, 4); 32 | query.SetSubarray(subarray); 33 | query.SetDataBuffer("a1", new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 }); 34 | query.Submit(); 35 | Assert.AreEqual(query.Status(), QueryStatus.Completed); 36 | 37 | string? stats = null; 38 | stats = Stats.Get(); 39 | Assert.IsNotNull(stats); 40 | var filePath = TestUtil.MakeTestPath("test-stats-dump"); 41 | Stats.Dump(filePath); 42 | Assert.IsTrue(System.IO.File.Exists(filePath)); 43 | 44 | Stats.Dump(); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /tests/TileDB.CSharp.Test/TemporaryDirectory.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | 4 | namespace TileDB.CSharp.Test; 5 | 6 | internal readonly struct TemporaryDirectory : IDisposable 7 | { 8 | private readonly string _path; 9 | 10 | public TemporaryDirectory(string directoryName) 11 | { 12 | _path = Path.Join(Path.GetTempPath(), "tiledb-csharp-tests", directoryName); 13 | DeleteDirectory(_path); 14 | Directory.CreateDirectory(_path); 15 | } 16 | 17 | public void Dispose() 18 | { 19 | DeleteDirectory(_path); 20 | } 21 | 22 | public static implicit operator string(TemporaryDirectory directory) => directory._path; 23 | 24 | public static void DeleteDirectory(string directory) 25 | { 26 | try 27 | { 28 | Directory.Delete(directory, true); 29 | } 30 | catch (DirectoryNotFoundException) 31 | { 32 | // Don't fail if the directory does not exist. 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /tests/TileDB.CSharp.Test/TileDB.CSharp.Test.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | false 4 | enable 5 | Major 6 | TileDB.CSharp.Test 7 | net8.0 8 | true 9 | true 10 | GitHubActions 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 28 | 29 | 30 | --------------------------------------------------------------------------------