-
Notifications
You must be signed in to change notification settings - Fork 1.8k
AVRO-2825: [csharp] Resolve: C# Logical Types throw exception on unknown #3727
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
RawScape
wants to merge
10
commits into
apache:main
Choose a base branch
from
RawScape:fix-csharp-logical-types
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 8 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
308422d
AVRO-2825: [csharp] Resolve: C# Logical Types throw exception on unkn…
67af69b
[AVRO-3941] CSharp Resolve missing namespace issue
e035eb9
Resolve requested changes on PR 2751
f7c24aa
uncomment testcase after testing
bda040d
savepoint remove local setting files
d442161
backout chags for a different pr, adjust unit test
55edd4f
changes from code review
be5f758
Resolve remaining feedback for AVRO-2825 and fix complex logical type…
RawScape 97ef11f
Fix CodeQL warning: Use pattern matching to assert logicalSchema type…
RawScape d092398
Remove accidentally tracked launchSettings.json
RawScape File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
8 changes: 8 additions & 0 deletions
8
lang/csharp/src/apache/codegen/Properties/launchSettings.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| { | ||
| "profiles": { | ||
| "Avro.codegen": { | ||
| "commandName": "Project", | ||
| "commandLineArgs": " -s C:\\Users\\Thomas.Bruns\\source\\repos\\AzureDevOps\\TQL.Kafka.Samples\\TQL.Kafka.Samples\\TQL.Kafka.Samples.Messages\\v1\\cdc_tql_dbo_tbldrops.avsc .\\tab --namespace NO_SCHEMA_NAMESPACE:TQL.DEMO" | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,145 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * https://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Text; | ||
|
|
||
| namespace Avro.Util | ||
| { | ||
| /// <summary> | ||
| /// Class UnknownLogicalType. | ||
| /// Implements the <see cref="Avro.Util.LogicalType" /> | ||
| /// </summary> | ||
| /// <seealso cref="Avro.Util.LogicalType" /> | ||
| public class UnknownLogicalType : LogicalType | ||
| { | ||
| /// <summary> | ||
| /// Gets the schema. | ||
| /// </summary> | ||
| /// <value>The schema.</value> | ||
| public LogicalSchema Schema { get; } | ||
|
|
||
| /// <summary> | ||
| /// Initializes a new instance of the <see cref="UnknownLogicalType"/> class. | ||
| /// </summary> | ||
| /// <param name="schema">The schema.</param> | ||
| public UnknownLogicalType(LogicalSchema schema) : base(schema.LogicalTypeName) | ||
| { | ||
| this.Schema = schema; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Converts a logical value to an instance of its base type. | ||
| /// </summary> | ||
| /// <param name="logicalValue">The logical value to convert.</param> | ||
| /// <param name="schema">The schema that represents the target of the conversion.</param> | ||
| /// <returns>An object representing the encoded value of the base type.</returns> | ||
| public override object ConvertToBaseValue(object logicalValue, LogicalSchema schema) | ||
| { | ||
| return logicalValue; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Converts a base value to an instance of the logical type. | ||
| /// </summary> | ||
| /// <param name="baseValue">The base value to convert.</param> | ||
| /// <param name="schema">The schema that represents the target of the conversion.</param> | ||
| /// <returns>An object representing the encoded value of the logical type.</returns> | ||
| public override object ConvertToLogicalValue(object baseValue, LogicalSchema schema) | ||
| { | ||
| switch (schema.Name) | ||
| { | ||
| case @"string": | ||
| return (System.String)baseValue; | ||
| case @"boolean": | ||
| return (System.Boolean)baseValue; | ||
| case @"int": | ||
| return (System.Int32)baseValue; | ||
| case @"long": | ||
| return (System.Int64)baseValue; | ||
| case @"float": | ||
| return (System.Single)baseValue; | ||
| case @"double": | ||
| return (System.Double)baseValue; | ||
| case @"bytes": | ||
| return (System.Byte[])baseValue; | ||
| default: | ||
| return baseValue; | ||
| } | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Retrieve the .NET type that is represented by the logical type implementation. | ||
| /// </summary> | ||
| /// <param name="nullible">A flag indicating whether it should be nullible.</param> | ||
| /// <returns>Type.</returns> | ||
| public override Type GetCSharpType(bool nullible) | ||
| { | ||
| // handle all Primitive Types | ||
| switch (this.Schema.BaseSchema.Name) | ||
| { | ||
| case @"string": | ||
| return typeof(System.String); | ||
| case @"boolean": | ||
| return nullible ? typeof(System.Boolean?) : typeof(System.Boolean); | ||
| case @"int": | ||
| return nullible ? typeof(System.Int32?) : typeof(System.Int32); | ||
| case @"long": | ||
| return nullible ? typeof(System.Int64?) : typeof(System.Int64); | ||
| case @"float": | ||
| return nullible ? typeof(System.Single?) : typeof(System.Single); | ||
| case @"double": | ||
| return nullible ? typeof(System.Double?) : typeof(System.Double); | ||
| case @"bytes": | ||
| return typeof(System.Byte[]); | ||
| default: | ||
| return typeof(System.Object); | ||
| } | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Determines if a given object is an instance of the logical type. | ||
| /// </summary> | ||
| /// <param name="logicalValue">The logical value to test.</param> | ||
| /// <returns><c>true</c> if [is instance of logical type] [the specified logical value]; otherwise, <c>false</c>.</returns> | ||
| public override bool IsInstanceOfLogicalType(object logicalValue) | ||
| { | ||
| // handle all Primitive Types | ||
| switch (this.Schema.BaseSchema.Name) | ||
| { | ||
| case @"string": | ||
| return logicalValue is System.String; | ||
| case @"boolean": | ||
| return logicalValue is System.Boolean; | ||
| case @"int": | ||
| return logicalValue is System.Int32; | ||
| case @"long": | ||
| return logicalValue is System.Int64; | ||
| case @"float": | ||
| return logicalValue is System.Single; | ||
| case @"double": | ||
| return logicalValue is System.Double; | ||
| case @"bytes": | ||
| return logicalValue is System.Byte[]; | ||
| default: | ||
| return true; | ||
| } | ||
| } | ||
|
|
||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This might have been a mistakenly added file 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch, @RyanSkraba! I inherited that file when I brought Tom's original branch over.
I have deleted it and pushed the update.