Add NVARCHAR (SQL_C_WCHAR) Output Support to .NET Core C# Language Extension#69
Add NVARCHAR (SQL_C_WCHAR) Output Support to .NET Core C# Language Extension#69SicongLiu2000 wants to merge 1 commit intomainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
Adds opt-in NVARCHAR (SQL_C_WCHAR) output support for .NET Core C# language extensions by allowing executors to override the default string output type per column.
Changes:
- Introduces
AbstractSqlServerExtensionExecutor.OutputColumnDataTypesto override output SQL types by column name. - Wires the override dictionary through session execution into output schema extraction, including validation and WCHAR byte-length sizing.
- Adds/updates native + managed tests, plus README and sample guidance for mixed VARCHAR/NVARCHAR outputs.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| language-extensions/dotnet-core-CSharp/src/managed/sdk/AbstractSqlServerExtensionExecutor.cs | Adds new OutputColumnDataTypes API for executors to configure string output types. |
| language-extensions/dotnet-core-CSharp/src/managed/CSharpOutputDataSet.cs | Applies per-column string type overrides with validation; reports DotNetWChar size as UTF-16 byte length. |
| language-extensions/dotnet-core-CSharp/src/managed/CSharpSession.cs | Passes executor OutputColumnDataTypes into ExtractColumns(). |
| language-extensions/dotnet-core-CSharp/test/src/managed/CSharpTestExecutor.cs | Adds managed test executors exercising default vs NVARCHAR vs mixed output behavior. |
| language-extensions/dotnet-core-CSharp/test/src/native/CSharpGetResultColumnTests.cpp | Adds native gtests validating result column metadata for NVARCHAR and mixed output. |
| language-extensions/dotnet-core-CSharp/sample/regex/pkg/RegexSample.cs | Documents (commented) example of configuring NVARCHAR output. |
| language-extensions/dotnet-core-CSharp/README.md | Documents Output Schema Support and how to use OutputColumnDataTypes. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| // Process and return data | ||
| return resultDataFrame; |
There was a problem hiding this comment.
The code sample returns resultDataFrame, but that variable isn’t defined in the example, so the snippet won’t compile if copied as-is. Consider returning input (as in other examples) or declare/build resultDataFrame in the snippet to keep the documentation self-contained.
| // Process and return data | |
| return resultDataFrame; | |
| // Process data if needed and return the DataFrame | |
| return input; |
| | SqlDataType | SQL Type | Encoding | Description | | ||
| |-------------|----------|----------|-------------| | ||
| | `SqlDataType.DotNetChar` | VARCHAR | UTF-8 | Default for string columns | | ||
| | `SqlDataType.DotNetWChar` | NVARCHAR | UTF-16 | Use for Unicode data | | ||
|
|
There was a problem hiding this comment.
The “Supported String Types” table rows start with ||, which creates an extra empty column in Markdown and renders incorrectly on GitHub. Use a single leading | for the header/separator/data rows so the table has the intended 4 columns.
| if (column.DataType == typeof(string) && outputColumnDataTypes != null) | ||
| { | ||
| if (outputColumnDataTypes.TryGetValue(column.Name, out var userType)) | ||
| { | ||
| if (userType != SqlDataType.DotNetChar && userType != SqlDataType.DotNetWChar) | ||
| { | ||
| throw new ArgumentException( | ||
| $"Invalid type override '{userType}' for string column '{column.Name}'. " + | ||
| $"Only DotNetChar and DotNetWChar are supported for string columns."); | ||
| } | ||
|
|
||
| dataType = userType; | ||
| Logging.Trace($"ExtractColumns: Column '{column.Name}' using user-specified type: {dataType}"); | ||
| } |
There was a problem hiding this comment.
These 'if' statements can be combined.
| if (column.DataType == typeof(string) && outputColumnDataTypes != null) | |
| { | |
| if (outputColumnDataTypes.TryGetValue(column.Name, out var userType)) | |
| { | |
| if (userType != SqlDataType.DotNetChar && userType != SqlDataType.DotNetWChar) | |
| { | |
| throw new ArgumentException( | |
| $"Invalid type override '{userType}' for string column '{column.Name}'. " + | |
| $"Only DotNetChar and DotNetWChar are supported for string columns."); | |
| } | |
| dataType = userType; | |
| Logging.Trace($"ExtractColumns: Column '{column.Name}' using user-specified type: {dataType}"); | |
| } | |
| if (column.DataType == typeof(string) | |
| && outputColumnDataTypes != null | |
| && outputColumnDataTypes.TryGetValue(column.Name, out var userType)) | |
| { | |
| if (userType != SqlDataType.DotNetChar && userType != SqlDataType.DotNetWChar) | |
| { | |
| throw new ArgumentException( | |
| $"Invalid type override '{userType}' for string column '{column.Name}'. " + | |
| $"Only DotNetChar and DotNetWChar are supported for string columns."); | |
| } | |
| dataType = userType; | |
| Logging.Trace($"ExtractColumns: Column '{column.Name}' using user-specified type: {dataType}"); |
Motivation
SQL Server distinguishes between
VARCHAR(byte-oriented, typically UTF-8) andNVARCHAR(UTF-16 Unicode). The existing C# extension always mapped .NETstringcolumns toVARCHAR, with no way to produceNVARCHARoutput. This is limiting for workloads that require native Unicode output or need to match anNVARCHARschema on the SQL Server side.Changes
API Surface
AbstractSqlServerExtensionExecutor.OutputColumnDataTypes— newDictionary<string, SqlDataType>property on the SDK base class. Extension authors populate this dictionary in theirExecute()method to override the default output type for specific string columns.Core Logic (
CSharpOutputDataSet.cs)ExtractColumns()now accepts an optionaloutputColumnDataTypesparameter.DotNetChar(VARCHAR) andDotNetWChar(NVARCHAR) are valid overrides for string columns; any other type throws anArgumentException.Session Wiring (
CSharpSession.cs)Execute()passes the executor'sOutputColumnDataTypesdictionary through toExtractColumns().Documentation (
README.md)Sample Update (
RegexSample.cs)OutputColumnDataTypesto produce NVARCHAR output, without changing the sample's default behavior.Test Coverage
Three new test executors and four new native Google Test cases were added:
GetNVarcharOutputResultColumnsTestOutputColumnDataTypes["text"] = DotNetWCharproducesSQL_C_WCHARoutput with correct byte-length column sizeGetPreserveNVarcharTypeResultColumnsTestOutputColumnDataTypesconfig is providedGetMixedStringOutputResultColumnsTestGetWStringResultColumnsTest(existing, updated)All 62 tests pass (release build, Windows).
Files Changed
src/managed/sdk/AbstractSqlServerExtensionExecutor.csOutputColumnDataTypespropertysrc/managed/CSharpOutputDataSet.cssrc/managed/CSharpSession.csOutputColumnDataTypestoExtractColumns()sample/regex/pkg/RegexSample.cstest/src/managed/CSharpTestExecutor.cstest/src/native/CSharpGetResultColumnTests.cppREADME.mdBreaking Changes
None. The default behavior is unchanged — all string columns output as VARCHAR (UTF-8) unless explicitly overridden via
OutputColumnDataTypes.