### Install ParquetSharp NuGet package Source: https://github.com/g-research/parquetsharp/blob/master/docs/index.md Installs the ParquetSharp library into your .NET project. This makes the library's functionalities available for use. ```bash dotnet add package ParquetSharp ``` -------------------------------- ### Install ParquetSharp using NuGet CLI Source: https://github.com/g-research/parquetsharp/blob/master/docs/guides/PowerShell.md Installs the latest version of ParquetSharp into a 'lib' directory using the NuGet command-line interface. Ensure nuget.exe is in your PATH or current directory. ```powershell nuget install ParquetSharp -OutputDirectory lib ``` -------------------------------- ### Open Parquet File for Arrow Reading Source: https://github.com/g-research/parquetsharp/blob/master/docs/guides/Arrow.md Construct a FileReader to open a Parquet file for reading Arrow data. This example uses a file path. ```csharp using var fileReader = new FileReader("data.parquet"); ``` -------------------------------- ### Write a Parquet File with Three Columns Source: https://github.com/g-research/parquetsharp/blob/master/docs/index.md Demonstrates writing a Parquet file named 'float_timeseries.parquet' with 'Timestamp', 'ObjectId', and 'Value' columns using the low-level API. Ensure you have the necessary using statements and the ParquetSharp NuGet package installed. ```csharp using System; using ParquetSharp; class Program { static void Main() { var timestamps = new DateTime[] { DateTime.Now, DateTime.Now.AddMinutes(1) }; var objectIds = new int[] { 1, 2 }; var values = new float[] { 1.23f, 4.56f }; var columns = new Column[] { new Column("Timestamp"), new Column("ObjectId"), new Column("Value") }; using var file = new ParquetFileWriter("float_timeseries.parquet", columns); using var rowGroup = file.AppendRowGroup(); using (var timestampWriter = rowGroup.NextColumn().LogicalWriter()) { timestampWriter.WriteBatch(timestamps); } using (var objectIdWriter = rowGroup.NextColumn().LogicalWriter()) { objectIdWriter.WriteBatch(objectIds); } using (var valueWriter = rowGroup.NextColumn().LogicalWriter()) { valueWriter.WriteBatch(values); } file.Close(); Console.WriteLine("Parquet file written successfully!"); } } ``` -------------------------------- ### Copy ParquetSharp DLLs to bin Directory Source: https://github.com/g-research/parquetsharp/blob/master/docs/guides/PowerShell.md Copies the main ParquetSharp.dll and ParquetSharpNative.dll into the 'bin' directory. Update paths to match your installed ParquetSharp version, architecture, and OS. ```powershell # Replace path with the appropriate version of ParquetSharp Copy-Item -Path ".\lib\ParquetSharp.12.1.0\lib\net461\ParquetSharp.dll" -Destination ".\bin" # Replace path with the appropriate version of ParquetSharp and architecture Copy-Item -Path ".\lib\ParquetSharp.12.1.0\runtimes\win-x64\native\ParquetSharpNative.dll" -Destination ".\bin" ``` -------------------------------- ### Definition Level Analyzer with IColumnReaderVisitor Source: https://github.com/g-research/parquetsharp/blob/master/docs/guides/VisitorPatterns.md Implement IColumnReaderVisitor to analyze column data using definition levels. This example counts null values by checking definition levels against the maximum defined level for the column. ```csharp sealed class NullCountReader : IColumnReaderVisitor { public int OnColumnReader(ColumnReader columnReader) where TValue : unmanaged { const int bufferSize = 1024; var values = new TValue[bufferSize]; var defLevels = new short[bufferSize]; var repLevels = new short[bufferSize]; int nullCount = 0; while (columnReader.HasNext) { var read = columnReader.ReadBatch(bufferSize, defLevels, repLevels, values, out var valuesRead); // Count definition levels that indicate null for (int i = 0; i < read; i++) { if (defLevels[i] < columnReader.ColumnDescriptor.MaxDefinitionLevel) { nullCount++; } } } return nullCount; } } ``` -------------------------------- ### Create a new console project Source: https://github.com/g-research/parquetsharp/blob/master/docs/index.md Initializes a new .NET console application. This is the first step in setting up a project to use ParquetSharp. ```bash dotnet new console -n ParquetExample cd ParquetExample ``` -------------------------------- ### Initialize and Execute Dev Container CLI Source: https://github.com/g-research/parquetsharp/blob/master/README.md Commands to set up and run the development environment using the Dev Container CLI. This includes building C++ code and running C# tests. ```bash devcontainer up ``` ```bash devcontainer exec ./build_unix.sh ``` ```bash devcontainer exec dotnet test csharp.test ``` -------------------------------- ### Statistics.MinUntyped.get Source: https://github.com/g-research/parquetsharp/blob/master/csharp/PublicAPI.Shipped.txt Gets the minimum value in the statistics as an untyped object. ```APIDOC ## ParquetSharp.Statistics.MinUntyped.get ### Description Gets the minimum value in the statistics as an untyped object. ### Method abstract ### Return Value object! ``` -------------------------------- ### Statistics.MaxUntyped.get Source: https://github.com/g-research/parquetsharp/blob/master/csharp/PublicAPI.Shipped.txt Gets the maximum value in the statistics as an untyped object. ```APIDOC ## ParquetSharp.Statistics.MaxUntyped.get ### Description Gets the maximum value in the statistics as an untyped object. ### Method abstract ### Return Value object! ``` -------------------------------- ### ParquetSharp.FixedLenByteArray.Pointer Property Source: https://github.com/g-research/parquetsharp/blob/master/csharp/PublicAPI/netstandard2.1/PublicAPI.Shipped.txt Gets the native pointer to the FixedLenByteArray data. ```APIDOC ## FixedLenByteArray.Pointer Property ### Description Gets the native pointer to the FixedLenByteArray data. ### Method ParquetSharp.FixedLenByteArray.Pointer.get ### Return Value System.IntPtr - The native pointer to the FixedLenByteArray data. ``` -------------------------------- ### Build Native Unix Code and Run Tests Source: https://github.com/g-research/parquetsharp/blob/master/README.md Shell commands to build the C++ code and execute C# tests on a Unix-like system. This is the standard native build process for Linux and macOS. ```bash ./build_unix.sh ``` ```bash dotnet test csharp.test ``` -------------------------------- ### Initialize ParquetFileWriter with Custom Schema Source: https://github.com/g-research/parquetsharp/blob/master/docs/guides/Nested.md Create a ParquetFileWriter instance using a custom schema definition and writer properties, including compression settings. ```csharp using var propertiesBuilder = new WriterPropertiesBuilder(); propertiesBuilder.Compression(Compression.Snappy); using var writerProperties = propertiesBuilder.Build(); using var fileWriter = new ParquetFileWriter("objects.parquet", schema, writerProperties); ``` -------------------------------- ### ParquetSharp.ByteArray.Pointer Property Source: https://github.com/g-research/parquetsharp/blob/master/csharp/PublicAPI/netstandard2.1/PublicAPI.Shipped.txt Gets the native pointer to the ByteArray data. ```APIDOC ## ByteArray.Pointer Property ### Description Gets the native pointer to the ByteArray data. ### Method ParquetSharp.ByteArray.Pointer.get ### Return Value System.IntPtr - The native pointer to the ByteArray data. ``` -------------------------------- ### ConvertUuid Source: https://github.com/g-research/parquetsharp/blob/master/csharp/PublicAPI.Shipped.txt Converts a span of FixedLenByteArray representing UUIDs to a span of nullable Guid objects. ```APIDOC ## ConvertUuid ### Description Converts a span of `ParquetSharp.FixedLenByteArray` representing UUIDs, along with definition levels, to a span of nullable Guid objects. ### Method Signature `static ParquetSharp.LogicalRead.ConvertUuid(System.ReadOnlySpan source, System.ReadOnlySpan defLevels, System.Span destination, short definedLevel)` ``` -------------------------------- ### ParquetSharp.IO.Buffer Constructors and Properties Source: https://github.com/g-research/parquetsharp/blob/master/csharp/PublicAPI/net471/PublicAPI.Shipped.txt Details the constructor and properties for Buffer. ```APIDOC ## ParquetSharp.IO.Buffer ### Description Represents a memory buffer for I/O operations. ### Constructors #### Buffer(System.IntPtr data, long size) Initializes a new instance of the Buffer class. ### Properties #### Data -> System.IntPtr Gets the pointer to the buffer data. #### MutableData -> System.IntPtr Gets a mutable pointer to the buffer data. ``` -------------------------------- ### Buffer Constructors and Properties Source: https://github.com/g-research/parquetsharp/blob/master/csharp/PublicAPI/net8.0/PublicAPI.Shipped.txt Provides details on the constructors and properties for the Buffer class. ```APIDOC ## ParquetSharp.IO.Buffer.Buffer ### Description Constructor for the Buffer class. ### Signature `ParquetSharp.IO.Buffer.Buffer(nint data, long size) -> void` ## ParquetSharp.IO.Buffer.Data ### Description Gets the data pointer of the buffer. ### Signature `ParquetSharp.IO.Buffer.Data.get -> nint` ## ParquetSharp.IO.Buffer.MutableData ### Description Gets the mutable data pointer of the buffer. ### Signature `ParquetSharp.IO.Buffer.MutableData.get -> nint` ``` -------------------------------- ### Arrow Reader/Writer Properties Source: https://github.com/g-research/parquetsharp/blob/master/csharp/PublicAPI.Shipped.txt Static methods to get default properties for Arrow readers and writers. ```APIDOC ## Arrow Properties ### ArrowReaderProperties - **GetDefault()** -> ParquetSharp.Arrow.ArrowReaderProperties! Returns the default Arrow reader properties. ### ArrowWriterProperties - **GetDefault()** -> ParquetSharp.Arrow.ArrowWriterProperties! Returns the default Arrow writer properties. ``` -------------------------------- ### Open Parquet File Source: https://github.com/g-research/parquetsharp/blob/master/docs/guides/Reading.md Construct a ParquetFileReader from a file path or a managed stream. ```csharp using var fileReader = new ParquetFileReader("data.parquet"); ``` ```csharp using var input = new ManagedRandomAccessFile(File.OpenRead("data.parquet")); using var fileReader = new ParquetFileReader(input); ``` -------------------------------- ### Write Data in Batches Source: https://github.com/g-research/parquetsharp/blob/master/docs/guides/Arrow.md Write record batches to the Parquet file. Each call to WriteRecordBatch starts a new row group. ```csharp for (var batchNumber = 0; batchNumber < 10; ++batchNumber) { using var recordBatch = GetBatch(batchNumber); writer.WriteRecordBatch(recordBatch); } ``` -------------------------------- ### Run C# Program Source: https://github.com/g-research/parquetsharp/blob/master/docs/index.md Executes the C# program using the .NET CLI. ```bash dotnet run ``` -------------------------------- ### Get File Metadata Source: https://github.com/g-research/parquetsharp/blob/master/docs/guides/Reading.md Access file metadata such as the number of columns, rows, row groups, key-value metadata, and schema information. ```csharp int numColumns = fileReader.FileMetaData.NumColumns; long numRows = fileReader.FileMetaData.NumRows; int numRowGroups = fileReader.FileMetaData.NumRowGroups; IReadOnlyDictionary metadata = fileReader.FileMetaData.KeyValueMetadata; SchemaDescriptor schema = fileReader.FileMetaData.Schema; for (int columnIndex = 0; columnIndex < schema.NumColumns; ++columnIndex) { ColumnDescriptor column = schema.Column(columnIndex); string columnName = column.Name; } ``` -------------------------------- ### Write Data Column by Column Source: https://github.com/g-research/parquetsharp/blob/master/docs/guides/Arrow.md Explicitly start new row groups and write data column by column for finer control over data writing. ```csharp for (var batchNumber = 0; batchNumber < 10; ++batchNumber) { using var recordBatch = GetBatch(batchNumber); writer.NewRowGroup(recordBatch.Length); writer.WriteColumnChunk(recordBatch.Column(0)); writer.WriteColumnChunk(recordBatch.Column(1)); writer.WriteColumnChunk(recordBatch.Column(2)); } ``` -------------------------------- ### ParquetSharp.Schema.Node Constructor Source: https://github.com/g-research/parquetsharp/blob/master/csharp/PublicAPI/net471/PublicAPI.Shipped.txt Details the constructor for Schema.Node. ```APIDOC ## ParquetSharp.Schema.Node ### Description Represents a node in the Parquet schema tree. ### Constructors #### Node(System.IntPtr handle) Initializes a new instance of the Node class. ``` -------------------------------- ### ByteArray Constructors and Properties Source: https://github.com/g-research/parquetsharp/blob/master/csharp/PublicAPI/net8.0/PublicAPI.Shipped.txt Provides details on the constructors and properties for the ByteArray class. ```APIDOC ## ParquetSharp.ByteArray.ByteArray ### Description Constructor for the ByteArray class. ### Signature `ParquetSharp.ByteArray.ByteArray(nint pointer, int length) -> void` ## ParquetSharp.ByteArray.Pointer ### Description Gets the pointer to the byte array. ### Signature `readonly ParquetSharp.ByteArray.Pointer -> nint` ``` -------------------------------- ### Stream and File Handle Constructors Source: https://github.com/g-research/parquetsharp/blob/master/csharp/PublicAPI/net10.0/PublicAPI.Shipped.txt Information on constructors for OutputStream and RandomAccessFile, which use native handles. ```APIDOC ## ParquetSharp.IO.OutputStream.OutputStream ### Description Constructor for OutputStream. ### Signature `ParquetSharp.IO.OutputStream.OutputStream(nint handle)` ## ParquetSharp.IO.RandomAccessFile.RandomAccessFile ### Description Constructor for RandomAccessFile. ### Signature `ParquetSharp.IO.RandomAccessFile.RandomAccessFile(nint handle)` ``` -------------------------------- ### Build Native Windows Code and Run Tests Source: https://github.com/g-research/parquetsharp/blob/master/README.md PowerShell commands to build the C++ code and execute C# tests on a Windows native environment. Ensure CMake is in your PATH. ```pwsh build_windows.ps1 ``` ```pwsh dotnet test csharp.test ``` -------------------------------- ### Getting File Decryption Properties with External Key Material Source: https://github.com/g-research/parquetsharp/blob/master/docs/guides/Encryption.md When using external key material, specify the Parquet file path when creating file decryption properties. ```csharp using var fileDecryptionProperties = cryptoFactory.GetFileDecryptionProperties( kmsConnectionConfig, decryptionConfig, parquetFilePath); ``` -------------------------------- ### Getting File Encryption Properties with External Key Material Source: https://github.com/g-research/parquetsharp/blob/master/docs/guides/Encryption.md When using external key material, specify the Parquet file path when creating file encryption properties. ```csharp using var fileEncryptionProperties = cryptoFactory.GetFileEncryptionProperties( kmsConnectionConfig, encryptionConfig, parquetFilePath); ``` -------------------------------- ### Physical Type Inspector with IColumnWriterVisitor Source: https://github.com/g-research/parquetsharp/blob/master/docs/guides/VisitorPatterns.md Implement IColumnWriterVisitor to inspect the physical type of data being written. This example reports the physical type and includes a placeholder for low-level write operations. ```csharp sealed class PhysicalTypeWriter : IColumnWriterVisitor { public string OnColumnWriter(ColumnWriter columnWriter) where TValue : unmanaged { var physicalType = typeof(TValue).Name; Console.WriteLine($"Writing physical type: {physicalType}"); // Could perform low-level writes here if needed // columnWriter.WriteBatch(..., definitionLevels, repetitionLevels); return physicalType; } } ``` -------------------------------- ### Enable Buffered Stream for Logical API Source: https://github.com/g-research/parquetsharp/blob/master/docs/guides/MemoryBenchmarks.md Use this configuration for maximum memory efficiency with the Logical API. ```csharp EnableBufferedStream() ``` -------------------------------- ### LogicalType and Schema Node Constructors Source: https://github.com/g-research/parquetsharp/blob/master/csharp/PublicAPI/net10.0/PublicAPI.Shipped.txt Details constructors for LogicalType and Schema Node, which are initialized with native handles. ```APIDOC ## ParquetSharp.LogicalType.LogicalType ### Description Constructor for LogicalType. ### Signature `ParquetSharp.LogicalType.LogicalType(nint handle)` ## ParquetSharp.Schema.Node.Node ### Description Constructor for Schema Node. ### Signature `ParquetSharp.Schema.Node.Node(nint handle)` ``` -------------------------------- ### Override Logical Types for Timestamp and Time Source: https://github.com/g-research/parquetsharp/blob/master/docs/guides/Writing.md Control the representation of date and time values in Parquet by overriding the default logical types. This example sets millisecond resolution for timestamps and times. ```csharp var timestampColumn = new Column( "Timestamp", LogicalType.Timestamp(isAdjustedToUtc: true, timeUnit: TimeUnit.Millis)); var timeColumn = new Column( "Time", LogicalType.Time(isAdjustedToUtc: true, timeUnit: TimeUnit.Millis)); ``` -------------------------------- ### MSBuild Error: Microsoft.Cpp.Default.props Not Found Source: https://github.com/g-research/parquetsharp/blob/master/README.md This error indicates that the MSBuild project file 'Microsoft.Cpp.Default.props' is missing. Ensure that the 'Desktop development with C++' workload is selected during Visual Studio Build Tools installation. ```powershell error MSB4019: The imported project "C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\MSBuild\Microsoft\V VC\v170\Microsoft.Cpp.Default.props" was not found. Confirm that the expression in the Import declaration "C:\Program Fi les (x86)\Microsoft Visual Studio\2022\BuildTools\MSBuild\Microsoft\VC\v170\\Microsoft.Cpp.Default.props" is correct, a nd that the file exists on disk. ``` -------------------------------- ### Configure File Encryption Settings Source: https://github.com/g-research/parquetsharp/blob/master/docs/guides/Encryption.md Create an EncryptionConfiguration to specify how the Parquet file should be encrypted. This includes setting master keys for the footer and columns, and choosing between uniform or per-column encryption. ```csharp string footerKeyId = ...; using var encryptionConfig = new EncryptionConfiguration(footerKeyId); encryptionConfig.UniformEncryption = true; encryptionConfig.ColumnKeys = new Dictionary> { {"MasterKey1", new[] {"Column0", "Column1", "Column2"}}, {"MasterKey2", new[] {"Column3", "Column4"}}, }; encryptionConfig.DoubleWrapping = false; // Single-wrapping mode encryptionConfig.PlaintextFooter = true; ``` -------------------------------- ### Measure Parquet Write Time with Stopwatch Source: https://github.com/g-research/parquetsharp/blob/master/docs/guides/WriteBenchmarks.md Measures the time taken for Parquet file writing operations, excluding file reading. This is achieved using `Stopwatch` starting before `ParquetFileWriter` instantiation and stopping after `writer.Close()`. ```csharp var sw = Stopwatch.StartNew(); using var writer = new ParquetFileWriter(outputFile, columns, builder.Build()); // ... write row groups ... writer.Close(); sw.Stop(); ``` -------------------------------- ### Low-Level Encryption: Building File Encryption Properties Source: https://github.com/g-research/parquetsharp/blob/master/docs/guides/Encryption.md Manually specify AES keys for footer and column encryption. Use a builder pattern to configure keys and metadata for each column. ```csharp byte[] key0 = ...; // Bytes for 128, 192 or 256 bit AES key byte[] key1 = ...; byte[] key2 = ...; // Use key0 as the footer key using var builder = new FileEncryptionPropertiesBuilder(key0); // Configure encryption for two columns, using different keys. // Key metadata can be set in order to identify which key to use when later decrypting data. using var col0Builder = new ColumnEncryptionPropertiesBuilder("Column0"); using var col0Properties = col0Builder.Key(key1).KeyMetadata("key1").Build(); using var col1Builder = new ColumnEncryptionPropertiesBuilder("Column1"); using var col1Properties = col1Builder.Key(key2).KeyMetadata("key2").Build(); using var fileEncryptionProperties = builder .FooterKeyMetadata("key0") .EncryptedColumns(new[] { col0Properties, col1Properties, }) .Build(); ``` -------------------------------- ### ParquetSharp.IO.RandomAccessFile Constructor Source: https://github.com/g-research/parquetsharp/blob/master/csharp/PublicAPI/net471/PublicAPI.Shipped.txt Details the constructor for RandomAccessFile. ```APIDOC ## ParquetSharp.IO.RandomAccessFile ### Description Represents a file that allows random access for reading Parquet data. ### Constructors #### RandomAccessFile(System.IntPtr handle) Initializes a new instance of the RandomAccessFile class. ``` -------------------------------- ### CMake Error: C++ Compiler Not Found Source: https://github.com/g-research/parquetsharp/blob/master/README.md This error occurs when CMake cannot locate the C++ compiler (cl.exe). Ensure that 'C++/CLI support for build tools' is installed as an optional component for 'Desktop development with C++' in Visual Studio. ```powershell CMake Error at CMakeLists.txt:2 (project): The CMAKE_C_COMPILER: C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.37.32822/bin/Hostx64/x64/cl.exe is not a full path to an existing compiler tool. CMake Error at CMakeLists.txt:2 (project): The CMAKE_CXX_COMPILER: C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.37.32822/bin/Hostx64/x64/cl.exe is not a full path to an existing compiler tool. ``` -------------------------------- ### Buffer Constructors and Properties Source: https://github.com/g-research/parquetsharp/blob/master/csharp/PublicAPI/net10.0/PublicAPI.Shipped.txt Details the constructors and accessors for the Buffer class, used for managing data buffers. ```APIDOC ## ParquetSharp.IO.Buffer.Buffer ### Description Constructor for Buffer. ### Signature `ParquetSharp.IO.Buffer.Buffer(nint data, long size)` ## ParquetSharp.IO.Buffer.Data ### Description Gets the data pointer of the buffer. ### Signature `ParquetSharp.IO.Buffer.Data.get -> nint` ## ParquetSharp.IO.Buffer.MutableData ### Description Gets the mutable data pointer of the buffer. ### Signature `ParquetSharp.IO.Buffer.MutableData.get -> nint` ``` -------------------------------- ### Initialize CryptoFactory with KMS Client Factory Source: https://github.com/g-research/parquetsharp/blob/master/docs/guides/Encryption.md Create an instance of CryptoFactory, providing a factory method that creates instances of your custom IKmsClient. The CryptoFactory caches KMS clients. ```csharp using var cryptoFactory = new CryptoFactory(config => new MyKmsClient(config)); ``` -------------------------------- ### Initialize FileWriter Source: https://github.com/g-research/parquetsharp/blob/master/docs/guides/Arrow.md Initialize the FileWriter with the output file path and the Arrow schema. Alternatively, a .NET Stream or OutputStream subclass can be used. ```csharp using var writer = new FileWriter("data.parquet", schema); ``` -------------------------------- ### ParquetSharp.WriterProperties Methods and Properties Source: https://github.com/g-research/parquetsharp/blob/master/csharp/PublicAPI.Shipped.txt Provides configuration options for writing Parquet files, including methods to get compression settings and properties for data page size, dictionary encoding, max row group length, and statistics enablement. ```APIDOC ## ParquetSharp.WriterProperties ### Description Configures properties for writing Parquet files. ### Methods - `Compression(ParquetSharp.Schema.ColumnPath! path) -> ParquetSharp.Compression`: Gets the compression for the specified column path. - `CompressionLevel(ParquetSharp.Schema.ColumnPath! path) -> int`: Gets the compression level for the specified column path. - `DictionaryEnabled(ParquetSharp.Schema.ColumnPath! path) -> bool`: Checks if dictionary encoding is enabled for the specified column path. - `Encoding(ParquetSharp.Schema.ColumnPath! path) -> ParquetSharp.Encoding`: Gets the encoding for the specified column path. - `MaxStatisticsSize(ParquetSharp.Schema.ColumnPath! path) -> ulong`: Gets the maximum statistics size for the specified column path. - `StatisticsEnabled(ParquetSharp.Schema.ColumnPath! path) -> bool`: Checks if statistics are enabled for the specified column path. ### Properties - `CreatedBy` (string!): Gets the creator string for the Parquet file. - `DataPageSize` (long): Gets the size of data pages. - `DictionaryIndexEncoding` (ParquetSharp.Encoding): Gets the encoding used for dictionary indices. - `DictionaryPageEncoding` (ParquetSharp.Encoding): Gets the encoding used for dictionary pages. - `DictionaryPagesizeLimit` (long): Gets the limit for dictionary page size. - `FileEncryptionProperties` (ParquetSharp.FileEncryptionProperties!): Gets the file encryption properties. - `MaxRowGroupLength` (long): Gets the maximum row group length. - `PageChecksumEnabled` (bool): Indicates whether page checksums are enabled. ``` -------------------------------- ### Custom Type Factory for Column Name Matching Source: https://github.com/g-research/parquetsharp/blob/master/docs/guides/TypeFactories.md Implements a custom `LogicalTypeFactory` to override default type mappings based on column names. This allows specific columns to be read as custom logical types, such as `VolumeInDollars` when the column path starts with 'volumeInDollars'. ```csharp private sealed class CustomTypeFactory : LogicalTypeFactory { public override (Type physicalType, Type logicalType) GetSystemTypes( ColumnDescriptor descriptor, Type? columnLogicalTypeOverride) { using var descriptorPath = descriptor.Path; // Compare with the first entry in the descriptor path to handle array values if (columnLogicalTypeOverride == null && descriptorPath.ToDotVector().First() == "volumeInDollars") { return base.GetSystemTypes(descriptor, typeof(VolumeInDollars)); } return base.GetSystemTypes(descriptor, columnLogicalTypeOverride); } } ``` -------------------------------- ### ApplicationVersion Source: https://github.com/g-research/parquetsharp/blob/master/csharp/PublicAPI.Shipped.txt Provides access to the application version information. ```APIDOC ## ApplicationVersion ### Description Represents the version of the application. ### Properties - `readonly ParquetSharp.ApplicationVersion.Application` -> `string!` ``` -------------------------------- ### CMake Error: Visual Studio Not Detected Source: https://github.com/g-research/parquetsharp/blob/master/README.md This error occurs when CMake cannot find an instance of Visual Studio. Ensure all required Visual Studio Build Tools are installed, the relevant Visual Studio version is available, and consider rebooting or reinstalling Visual Studio. ```powershell CMake Error at CMakeLists.txt:2 (project): Generator Visual Studio 17 2022 could not find any instance of Visual Studio. ``` -------------------------------- ### Dev Container Configuration for Podman/SELinux Source: https://github.com/g-research/parquetsharp/blob/master/README.md Use these JSON configurations to modify the devcontainer.json file for Podman and SELinux compatibility. This ensures proper volume mounting and user permissions within the container. ```json "remoteUser": "root", "containerUser": "root", "workspaceMount": "", "runArgs": ["--volume=${localWorkspaceFolder}:/workspaces/${localWorkspaceFolderBasename}:Z"], "containerEnv": { "VCPKG_DEFAULT_BINARY_CACHE": "/home/vscode/.cache/vcpkg/archives" } ``` -------------------------------- ### Configure KMS Connection for Encryption Source: https://github.com/g-research/parquetsharp/blob/master/docs/guides/Encryption.md Set up KmsConnectionConfig with details required by your IKmsClient implementation to connect to the Key Management Service. These fields are specific to your KMS client. ```csharp using var kmsConnectionConfig = new KmsConnectionConfig(); // ParquetSharp doesn't require any config fields to be set, // the fields needed will depend on the IKmsClient implementation kmsConnectionConfig.KmsInstanceId = ...; kmsConnectionConfig.KmsInstanceUrl = ...; kmsConnectionConfig.KeyAccessToken = ...; ``` -------------------------------- ### ParquetSharp.IO.ResizableBuffer Constructor Source: https://github.com/g-research/parquetsharp/blob/master/csharp/PublicAPI.Shipped.txt Constructors for creating a ResizableBuffer with optional initial size and memory pool. ```APIDOC ## ParquetSharp.IO.ResizableBuffer.ResizableBuffer (initialSize, memoryPool) ### Description Initializes a new instance of the ResizableBuffer class with a specified initial size and memory pool. ### Method ResizableBuffer(long initialSize = 128, ParquetSharp.MemoryPool memoryPool = null) ### Parameters #### Path Parameters - **initialSize** (long, optional) - The initial size of the buffer. Defaults to 128. - **memoryPool** (ParquetSharp.MemoryPool?, optional) - The memory pool to use. Defaults to null. ``` ```APIDOC ## ParquetSharp.IO.ResizableBuffer.ResizableBuffer (initialSize) ### Description Initializes a new instance of the ResizableBuffer class with a specified initial size. ### Method ResizableBuffer(long initialSize) ### Parameters #### Path Parameters - **initialSize** (long) - The initial size of the buffer. ``` -------------------------------- ### ParquetSharp.Arrow.FileWriter Methods Source: https://github.com/g-research/parquetsharp/blob/master/csharp/PublicAPI.Shipped.txt Methods for interacting with the Arrow file writer. ```APIDOC ## ParquetSharp.Arrow.FileWriter.NewRowGroup ### Description Starts a new row group in the Arrow file writer. ### Method void NewRowGroup() ### Response #### Success Response (void) Indicates the row group was successfully started. ``` -------------------------------- ### Low-Level Encryption: Using a DecryptionKeyRetriever Source: https://github.com/g-research/parquetsharp/blob/master/docs/guides/Encryption.md Implement a custom DecryptionKeyRetriever to dynamically fetch AES keys based on key metadata, offering more flexibility than hardcoding keys. ```csharp internal sealed class MyKeyRetriever : ParquetSharp.DecryptionKeyRetriever { public override byte[] GetKey(string keyMetadata) { // Return AES key bytes based on the contents of the key metadata } } using var builder = new FileDecryptionPropertiesBuilder(); using var fileDecryptionProperties = builder .KeyRetriever(new MyKeyRetriever()) .Build(); ``` -------------------------------- ### ParquetSharp.IO.OutputStream Constructor Source: https://github.com/g-research/parquetsharp/blob/master/csharp/PublicAPI/net471/PublicAPI.Shipped.txt Details the constructor for OutputStream. ```APIDOC ## ParquetSharp.IO.OutputStream ### Description Represents an output stream for writing Parquet data. ### Constructors #### OutputStream(System.IntPtr handle) Initializes a new instance of the OutputStream class. ``` -------------------------------- ### Chunked Reading for Logical API Source: https://github.com/g-research/parquetsharp/blob/master/docs/guides/MemoryBenchmarks.md Choose this configuration for a balance between memory efficiency and performance with the Logical API. ```csharp Chunked reading ``` -------------------------------- ### Arrow API - Default Read Source: https://github.com/g-research/parquetsharp/blob/master/docs/guides/MemoryBenchmarks.md Demonstrates the default row-oriented access using Apache Arrow's columnar in-memory format with the FileReader. ```APIDOC ## Arrow API (FileReader) Row-oriented access using Apache Arrow’s columnar in-memory format. ### 1. Default Arrow Read ```csharp public async Task Arrow_Default() { using var reader = new FileReader(FilePath); using var batchReader = reader.GetRecordBatchReader(); Apache.Arrow.RecordBatch batch; while ((batch = await batchReader.ReadNextRecordBatchAsync()) != null) { using (batch) { for (int i = 0; i < batch.ColumnCount; i++) } } } ``` ``` -------------------------------- ### Helper Function for Record Batch Source: https://github.com/g-research/parquetsharp/blob/master/docs/guides/Arrow.md Create a helper function to build a record batch of data conforming to the defined Arrow schema. ```csharp const int numIds = 100; var startTime = DateTimeOffset.UtcNow; RecordBatch GetBatch(int batchNumber) => new RecordBatch(schema, new IArrowArray[] { new TimestampArray.Builder(millisecondTimestamp) .AppendRange(Enumerable.Repeat(startTime + TimeSpan.FromSeconds(batchNumber), numIds)) .Build(), new Int32Array.Builder() .AppendRange(Enumerable.Range(0, numIds)) .Build(), new FloatArray.Builder() .AppendRange(Enumerable.Range(0, numIds).Select(i => (float) (batchNumber * numIds + i))) .Build(), }, numIds); ``` -------------------------------- ### Copy Dependency DLLs to bin Directory Source: https://github.com/g-research/parquetsharp/blob/master/docs/guides/PowerShell.md Copies essential .NET dependency DLLs from the NuGet package 'lib' directory to a local 'bin' directory. Adjust paths based on actual library versions. ```powershell New-Item -Name "bin" -ItemType Directory Copy-Item -Path ".\lib\System.Buffers.4.5.1\lib\net461\System.Buffers.dll" -Destination ".\bin" Copy-Item -Path ".\lib\System.Memory.4.5.4\lib\net461\System.Memory.dll" -Destination ".\bin" Copy-Item -Path ".\lib\System.Numerics.Vectors.4.5.0\lib\net46\System.Numerics.Vectors.dll" -Destination ".\bin" Copy-Item -Path ".\lib\System.Runtime.CompilerServices.Unsafe.4.5.3\lib\net461\System.Runtime.CompilerServices.Unsafe.dll" -Destination ".\bin" Copy-Item -Path ".\lib\System.ValueTuple.4.5.0\lib\net461\System.ValueTuple.dll" -Destination ".\bin" ``` -------------------------------- ### Write Parquet File with Metadata Source: https://github.com/g-research/parquetsharp/blob/master/docs/guides/Writing.md Include custom key-value metadata in the Parquet file header during initialization of `ParquetFileWriter`. ```csharp var metadata = new Dictionary { {"foo": "bar"}, }; using var file = new ParquetFileWriter("float_timeseries.parquet", columns, keyValueMetadata: metadata); ``` -------------------------------- ### LogicalWrite From Conversions Source: https://github.com/g-research/parquetsharp/blob/master/csharp/PublicAPI/net8.0/PublicAPI.Shipped.txt Provides static methods for converting logical types from primitive types for writing. ```APIDOC ## ParquetSharp.LogicalWrite.FromDateOnly ### Description Converts a DateOnly value to an integer for writing. ### Signature `static ParquetSharp.LogicalWrite.FromDateOnly(System.DateOnly source) -> int` ## ParquetSharp.LogicalWrite.FromTimeOnlyMicros ### Description Converts a TimeOnly value to a long for writing (microseconds). ### Signature `static ParquetSharp.LogicalWrite.FromTimeOnlyMicros(System.TimeOnly source) -> long` ## ParquetSharp.LogicalWrite.FromTimeOnlyMillis ### Description Converts a TimeOnly value to an integer for writing (milliseconds). ### Signature `static ParquetSharp.LogicalWrite.FromTimeOnlyMillis(System.TimeOnly source) -> int` ``` -------------------------------- ### KmsConnectionConfig Class Source: https://github.com/g-research/parquetsharp/blob/master/csharp/PublicAPI.Shipped.txt Configuration class for establishing connections to KMS, allowing custom configurations and token management. ```APIDOC ## KmsConnectionConfig ### Description Configuration for connecting to a Key Management Service (KMS). ### Constructors #### KmsConnectionConfig() ```csharp KmsConnectionConfig() ``` ### Properties #### KmsInstanceUrl ```csharp string KmsInstanceUrl { get; set; } ``` #### KmsInstanceId ```csharp string KmsInstanceId { get; set; } ``` #### KeyAccessToken ```csharp string KeyAccessToken { get; set; } ``` #### CustomKmsConf ```csharp IReadOnlyDictionary CustomKmsConf { get; set; } ``` ### Methods #### RefreshKeyAccessToken ```csharp void RefreshKeyAccessToken(string newToken) ``` #### Dispose ```csharp void Dispose() ``` ``` -------------------------------- ### ParquetSharp.IO.Buffer Constructors and Properties Source: https://github.com/g-research/parquetsharp/blob/master/csharp/PublicAPI/netstandard2.1/PublicAPI.Shipped.txt Constructors and properties for the Buffer class, used for managing data buffers. ```APIDOC ## Buffer Constructor ### Description Initializes a new instance of the Buffer class. ### Method ParquetSharp.IO.Buffer.Buffer(System.IntPtr data, long size) ### Parameters - **data** (System.IntPtr) - The pointer to the buffer data. - **size** (long) - The size of the buffer. ``` ```APIDOC ## Buffer.Data Property ### Description Gets the pointer to the buffer data. ### Method ParquetSharp.IO.Buffer.Data.get ### Return Value System.IntPtr - The pointer to the buffer data. ``` ```APIDOC ## Buffer.MutableData Property ### Description Gets a mutable pointer to the buffer data. ### Method ParquetSharp.IO.Buffer.MutableData.get ### Return Value System.IntPtr - A mutable pointer to the buffer data. ``` -------------------------------- ### Restore and Apply Code Formatting Source: https://github.com/g-research/parquetsharp/blob/master/README.md Commands to restore the .NET tool formatter and apply code cleanup. This is used for maintaining consistent code style across the project and is also executed by the CI format checker. ```bash dotnet tool restore ``` ```bash dotnet jb cleanupcode "csharp" "csharp.test" "csharp.benchmark" --profile="Built-in: Reformat Code" --settings="ParquetSharp.DotSettings" --verbosity=WARN ``` -------------------------------- ### LogicalWrite From Methods Source: https://github.com/g-research/parquetsharp/blob/master/csharp/PublicAPI.Shipped.txt Utility methods for creating Parquet-compatible data types from common .NET types. ```APIDOC ## FromByteArray ### Description Creates a `ByteArray` from a byte array and a byte buffer. ### Method Signature `static ParquetSharp.LogicalWrite.FromByteArray(byte[]! array, ParquetSharp.ByteBuffer! byteBuffer) -> ParquetSharp.ByteArray` ``` ```APIDOC ## FromDateTimeMicros ### Description Converts a `DateTime` object to a 64-bit integer representing microseconds. ### Method Signature `static ParquetSharp.LogicalWrite.FromDateTimeMicros(System.DateTime source) -> long` ``` ```APIDOC ## FromDateTimeMillis ### Description Converts a `DateTime` object to a 32-bit integer representing milliseconds. ### Method Signature `static ParquetSharp.LogicalWrite.FromDateTimeMillis(System.DateTime source) -> long` ``` ```APIDOC ## FromDecimal ### Description Converts a decimal value to a fixed-length byte array using a specified multiplier and byte buffer. ### Method Signature `static ParquetSharp.LogicalWrite.FromDecimal(decimal source, decimal multiplier, ParquetSharp.ByteBuffer! byteBuffer) -> ParquetSharp.FixedLenByteArray` ``` ```APIDOC ## FromFixedLength ### Description Converts a value of a fixed-length type to a `FixedLenByteArray` using a provided byte buffer. ### Method Signature `static ParquetSharp.LogicalWrite.FromFixedLength(in TValue value, ParquetSharp.ByteBuffer! byteBuffer) -> ParquetSharp.FixedLenByteArray` ``` ```APIDOC ## FromString ### Description Converts a string to a `ByteArray` using a provided byte buffer. ### Method Signature `static ParquetSharp.LogicalWrite.FromString(string! str, ParquetSharp.ByteBuffer! byteBuffer) -> ParquetSharp.ByteArray` ``` ```APIDOC ## FromTimeSpanMicros ### Description Converts a `TimeSpan` to a 64-bit integer representing microseconds. ### Method Signature `static ParquetSharp.LogicalWrite.FromTimeSpanMicros(System.TimeSpan source) -> long` ``` ```APIDOC ## FromTimeSpanMillis ### Description Converts a `TimeSpan` to a 32-bit integer representing milliseconds. ### Method Signature `static ParquetSharp.LogicalWrite.FromTimeSpanMillis(System.TimeSpan source) -> int` ``` ```APIDOC ## FromUuid ### Description Converts a `Guid` to a `FixedLenByteArray` using a provided byte buffer. ### Method Signature `static ParquetSharp.LogicalWrite.FromUuid(System.Guid uuid, ParquetSharp.ByteBuffer! byteBuffer) -> ParquetSharp.FixedLenByteArray` ``` -------------------------------- ### IO.ManagedRandomAccessFile Source: https://github.com/g-research/parquetsharp/blob/master/csharp/PublicAPI.Shipped.txt A random access file wrapper for a `System.IO.Stream`. ```APIDOC ## IO.ManagedRandomAccessFile ### Description Provides random access file capabilities over a `System.IO.Stream`. ### Methods - `ManagedRandomAccessFile(System.IO.Stream stream)`: Initializes a new instance of the `ManagedRandomAccessFile` class with a specified stream. - `ManagedRandomAccessFile(System.IO.Stream stream, bool leaveOpen)`: Initializes a new instance of the `ManagedRandomAccessFile` class with a specified stream and a flag indicating whether to leave the stream open. ``` -------------------------------- ### ParquetFileWriter Constructors Source: https://github.com/g-research/parquetsharp/blob/master/csharp/PublicAPI.Shipped.txt Provides constructors for creating a ParquetFileWriter, allowing initialization with a file path or a stream, along with schema and writer properties. ```APIDOC ## ParquetFileWriter Constructors ### Description Constructors for `ParquetFileWriter` to create new Parquet files. ### Constructors - `ParquetFileWriter(string! path, ParquetSharp.Schema.GroupNode! schema, ParquetSharp.WriterProperties! writerProperties, System.Collections.Generic.IReadOnlyDictionary? keyValueMetadata = null)` - `ParquetFileWriter(System.IO.Stream! stream, ParquetSharp.Column![]! columns, ParquetSharp.LogicalTypeFactory? logicalTypeFactory = null, ParquetSharp.Compression compression = ParquetSharp.Compression.Snappy, System.Collections.Generic.IReadOnlyDictionary? keyValueMetadata = null, bool leaveOpen = false)` - `ParquetFileWriter(System.IO.Stream! stream, ParquetSharp.Column![]! columns, ParquetSharp.LogicalTypeFactory? logicalTypeFactory, ParquetSharp.WriterProperties! writerProperties, System.Collections.Generic.IReadOnlyDictionary? keyValueMetadata = null, bool leaveOpen = false)` - `ParquetFileWriter(System.IO.Stream! stream, ParquetSharp.Schema.GroupNode! schema, ParquetSharp.WriterProperties! writerProperties, System.Collections.Generic.IReadOnlyDictionary? keyValueMetadata = null, bool leaveOpen = false)` ``` -------------------------------- ### Configuring External Key Material for Encryption Source: https://github.com/g-research/parquetsharp/blob/master/docs/guides/Encryption.md Set internalKeyMaterial to false to store key material in separate JSON files, allowing master key rotation without rewriting Parquet files. ```csharp using var encryptionConfig = new EncryptionConfiguration(footerKeyId); encryptionConfig.InternalKeyMaterial = false; // External key material ``` -------------------------------- ### Load ParquetSharp Assembly using Add-Type Source: https://github.com/g-research/parquetsharp/blob/master/docs/guides/PowerShell.md Loads the ParquetSharp.dll assembly into the PowerShell session using `Add-Type`, specifying a custom path to the DLL. Ensure the path points to the correct version and framework. ```powershell # Replace path with the appropriate versions of ParquetSharp Add-Type -Path ".\lib\ParquetSharp.12.1.0\lib\net471\ParquetSharp.dll" ``` -------------------------------- ### Run code formatter Source: https://github.com/g-research/parquetsharp/blob/master/CONTRIBUTING.md Use JetBrains ReSharper Global Tools to enforce code formatting rules before committing. This ensures consistency across the codebase. ```bash dotnet tool restore dotnet jb cleanupcode "csharp" "csharp.test" "csharp.benchmark" --profile="Built-in: Reformat Code" --settings="ParquetSharp.DotSettings" ```