[
https://issues.apache.org/jira/browse/AVRO-2211?focusedWorklogId=751993&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-751993
]
ASF GitHub Bot logged work on AVRO-2211:
----------------------------------------
Author: ASF GitHub Bot
Created on: 02/Apr/22 21:09
Start Date: 02/Apr/22 21:09
Worklog Time Spent: 10m
Work Description: yanivru commented on a change in pull request #1597:
URL: https://github.com/apache/avro/pull/1597#discussion_r841119684
##########
File path: lang/csharp/src/apache/main/Schema/EnumSchema.cs
##########
@@ -98,20 +128,50 @@ internal static EnumSchema NewInstance(JToken jtok,
PropertyMap props, SchemaNam
/// <param name="names">list of named schema already read</param>
/// <param name="doc">documentation for this named schema</param>
/// <param name="defaultSymbol">default symbol</param>
+ /// <param name="shouldThrowParseException">If true, will throw <see
cref="SchemaParseException"/> in case of an error. If false, will throw <see
cref="AvroException"/> in case of an error.</param>
private EnumSchema(SchemaName name, IList<SchemaName> aliases,
List<string> symbols,
IDictionary<String, int> symbolMap, PropertyMap
props, SchemaNames names,
- string doc, string defaultSymbol)
+ string doc, string defaultSymbol, bool
shouldThrowParseException = true)
: base(Type.Enumeration, name, aliases, props,
names, doc)
{
- if (null == name.Name) throw new SchemaParseException("name cannot
be null for enum schema.");
+ if (null == name.Name) throw CreateException("name cannot be null
for enum schema.", shouldThrowParseException);
this.Symbols = symbols;
this.symbolMap = symbolMap;
if (null != defaultSymbol && !symbolMap.ContainsKey(defaultSymbol))
- throw new SchemaParseException($"Default symbol:
{defaultSymbol} not found in symbols");
+ throw CreateException($"Default symbol: {defaultSymbol} not
found in symbols", shouldThrowParseException);
Default = defaultSymbol;
}
+ private Exception CreateException(string message, bool
shouldCreateParseException)
+ {
+ return shouldCreateParseException ? new
SchemaParseException(message) : new AvroException(message);
+ }
+
+ /// <summary>
+ /// Creates symbols map from specified list of symbols.
+ /// Symbol map contains the names of the symbols and their index.
+ /// </summary>
+ /// <param name="symbols">List of symbols</param>
+ /// <returns>Symbol map</returns>
+ /// <exception cref="AvroException">Is thrown if the symbols list
contains duplicate symbols.</exception>
+ private static IDictionary<string, int>
CreateSymbolsMap(IEnumerable<string> symbols)
+ {
+ IDictionary<string, int> symbolMap = new Dictionary<string, int>();
+ int i = 0;
+ foreach (var symbol in symbols)
+ {
+ if (symbolMap.ContainsKey(symbol))
Review comment:
Yeah, just seen in spec that "Every symbol must match the regular
expression [A-Za-z_][A-Za-z0-9_]*"
So added the regex to the name verification.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
Issue Time Tracking
-------------------
Worklog Id: (was: 751993)
Time Spent: 4h 10m (was: 4h)
> SchemaBuilder equivalent or other means of schema creation
> ----------------------------------------------------------
>
> Key: AVRO-2211
> URL: https://issues.apache.org/jira/browse/AVRO-2211
> Project: Apache Avro
> Issue Type: Wish
> Components: csharp
> Reporter: Dan Stelljes
> Priority: Major
> Labels: pull-request-available
> Time Spent: 4h 10m
> Remaining Estimate: 0h
>
> Currently, the only way to create a schema is via the Schema.Parse method.
> We'd like to be able to build a schema programmatically—would it be possible
> to (1) introduce an analogue to the SchemaBuilder from the Java library or
> (2) expose constructors on Schema and its descendants?
> Would be more than happy to contribute work on this given some direction.
--
This message was sent by Atlassian Jira
(v8.20.1#820001)