You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@avro.apache.org by bl...@apache.org on 2019/10/06 11:36:34 UTC

[avro] branch branch-1.9 updated (6bc9f1e -> fea6888)

This is an automated email from the ASF dual-hosted git repository.

blachniet pushed a change to branch branch-1.9
in repository https://gitbox.apache.org/repos/asf/avro.git.


    from 6bc9f1e  AVRO-2557: Fix Java example user.avsc file address error (#646)
     new e24c2bf  AVRO-2522: Handle record types with Nullable and IList in their names (#663)
     new fea6888  AVRO-2522: Fix nullable resolution inside lists (#663)

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 lang/csharp/src/apache/main/CodeGen/CodeGen.cs     |  12 +--
 .../src/apache/main/Specific/ObjectCreator.cs      |   5 +-
 .../apache/test/Specific/EmbeddedGenericsRecord.cs | 114 +++++++++++++++++++++
 .../src/apache/test/Specific/ObjectCreatorTests.cs |  22 +++-
 .../src/apache/test/Specific/SpecificTests.cs      |  62 +++++++++++
 5 files changed, 205 insertions(+), 10 deletions(-)
 create mode 100644 lang/csharp/src/apache/test/Specific/EmbeddedGenericsRecord.cs


[avro] 01/02: AVRO-2522: Handle record types with Nullable and IList in their names (#663)

Posted by bl...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

blachniet pushed a commit to branch branch-1.9
in repository https://gitbox.apache.org/repos/asf/avro.git

commit e24c2bf12c039bb8488462aa8b03a89e7e323a8f
Author: Brian Lachniet <bl...@gmail.com>
AuthorDate: Sat Aug 24 08:36:49 2019 -0400

    AVRO-2522: Handle record types with Nullable and IList in their names
    (#663)
    
    (cherry picked commit from 6bccc286c13d9af41cface30c92e39705a998de7)
---
 .../src/apache/main/Specific/ObjectCreator.cs      |  5 ++---
 .../src/apache/test/Specific/ObjectCreatorTests.cs | 22 +++++++++++++++++++++-
 2 files changed, 23 insertions(+), 4 deletions(-)

diff --git a/lang/csharp/src/apache/main/Specific/ObjectCreator.cs b/lang/csharp/src/apache/main/Specific/ObjectCreator.cs
index 00a7f36..b0cf9ef 100644
--- a/lang/csharp/src/apache/main/Specific/ObjectCreator.cs
+++ b/lang/csharp/src/apache/main/Specific/ObjectCreator.cs
@@ -138,9 +138,8 @@ namespace Avro.Specific
 
                 // Modify provided type to ensure it can be discovered.
                 // This is mainly for Generics, and Nullables.
-                name = name.Replace("Nullable", "Nullable`1");
-                name = name.Replace("IList", "System.Collections.Generic.IList`1");
-                name = name.Replace("<", "[");
+                name = name.Replace("Nullable<", "Nullable`1[");
+                name = name.Replace("IList<", "System.Collections.Generic.IList`1[");
                 name = name.Replace(">", "]");
 
                 // if entry assembly different from current assembly, try entry assembly first
diff --git a/lang/csharp/src/apache/test/Specific/ObjectCreatorTests.cs b/lang/csharp/src/apache/test/Specific/ObjectCreatorTests.cs
index e95c10a..f17ff55 100644
--- a/lang/csharp/src/apache/test/Specific/ObjectCreatorTests.cs
+++ b/lang/csharp/src/apache/test/Specific/ObjectCreatorTests.cs
@@ -18,9 +18,10 @@
 using Avro.Specific;
 using Avro.Test.File;
 using NUnit.Framework;
+using System;
 using System.Collections.Generic;
 
-namespace Avro.test.Specific
+namespace Avro.Test.Specific
 {
     [TestFixture()]
     public class ObjectCreatorTests
@@ -78,5 +79,24 @@ namespace Avro.test.Specific
             Assert.True(typeof(IDictionary<string, Foo>).IsAssignableFrom(
                 objectCreator.GetType("Foo", Schema.Type.Map)));
         }
+
+        [TestCase(typeof(MyNullableFoo), "MyNullableFoo",
+            TestName = "TestComplexGetTypes_NullableInName")]
+        [TestCase(typeof(MyIListFoo), "MyIListFoo",
+            TestName = "TestComplexGetTypes_IListInName")]
+        public void TestComplexGetTypes(Type expecteType, string name)
+        {
+            var objectCreator = new ObjectCreator();
+
+            Assert.AreEqual(expecteType, objectCreator.GetType(name, Schema.Type.Record));
+        }
+
+        private class MyNullableFoo
+        {
+        }
+
+        private class MyIListFoo
+        {
+        }
     }
 }


[avro] 02/02: AVRO-2522: Fix nullable resolution inside lists (#663)

Posted by bl...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

blachniet pushed a commit to branch branch-1.9
in repository https://gitbox.apache.org/repos/asf/avro.git

commit fea6888bc211e76abd5823bf50d9bfb709b47ab7
Author: Brian Lachniet <bl...@gmail.com>
AuthorDate: Sat Aug 24 10:34:02 2019 -0400

    AVRO-2522: Fix nullable resolution inside lists (#663)
    
    (cherry picked commit from 23b6eb8a65cffbecc6166757a009644ace78f026)
---
 lang/csharp/src/apache/main/CodeGen/CodeGen.cs     |  12 +--
 .../apache/test/Specific/EmbeddedGenericsRecord.cs | 114 +++++++++++++++++++++
 .../src/apache/test/Specific/SpecificTests.cs      |  62 +++++++++++
 3 files changed, 182 insertions(+), 6 deletions(-)

diff --git a/lang/csharp/src/apache/main/CodeGen/CodeGen.cs b/lang/csharp/src/apache/main/CodeGen/CodeGen.cs
index 40c7256..10197a0 100644
--- a/lang/csharp/src/apache/main/CodeGen/CodeGen.cs
+++ b/lang/csharp/src/apache/main/CodeGen/CodeGen.cs
@@ -703,21 +703,21 @@ namespace Avro
             switch (schema.Tag)
             {
                 case Schema.Type.Null:
-                    return "System.Object";
+                    return typeof(object).ToString();
                 case Schema.Type.Boolean:
-                    if (nullible) return "System.Nullable<bool>";
+                    if (nullible) return $"System.Nullable<{typeof(bool)}>";
                     else return typeof(bool).ToString();
                 case Schema.Type.Int:
-                    if (nullible) return "System.Nullable<int>";
+                    if (nullible) return $"System.Nullable<{typeof(int)}>";
                     else return typeof(int).ToString();
                 case Schema.Type.Long:
-                    if (nullible) return "System.Nullable<long>";
+                    if (nullible) return $"System.Nullable<{typeof(long)}>";
                     else return typeof(long).ToString();
                 case Schema.Type.Float:
-                    if (nullible) return "System.Nullable<float>";
+                    if (nullible) return $"System.Nullable<{typeof(float)}>";
                     else return typeof(float).ToString();
                 case Schema.Type.Double:
-                    if (nullible) return "System.Nullable<double>";
+                    if (nullible) return $"System.Nullable<{typeof(double)}>";
                     else return typeof(double).ToString();
 
                 case Schema.Type.Bytes:
diff --git a/lang/csharp/src/apache/test/Specific/EmbeddedGenericsRecord.cs b/lang/csharp/src/apache/test/Specific/EmbeddedGenericsRecord.cs
new file mode 100644
index 0000000..c6595a2
--- /dev/null
+++ b/lang/csharp/src/apache/test/Specific/EmbeddedGenericsRecord.cs
@@ -0,0 +1,114 @@
+/*
+ * 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.
+ */
+// ------------------------------------------------------------------------------
+// <auto-generated>
+//    Generated by avrogen, version 1.10.0.0
+//    Changes to this file may cause incorrect behavior and will be lost if code
+//    is regenerated
+// </auto-generated>
+// ------------------------------------------------------------------------------
+namespace Avro.Test.Specific
+{
+	using System;
+	using System.Collections.Generic;
+	using System.Text;
+	using Avro;
+	using Avro.Specific;
+	
+	public partial class EmbeddedGenericsRecord : ISpecificRecord
+	{
+		public static Schema _SCHEMA = Avro.Schema.Parse(@"{""type"":""record"",""name"":""EmbeddedGenericsRecord"",""namespace"":""Avro.Test.Specific"",""fields"":[{""name"":""OptionalInt"",""type"":[""null"",""int""]},{""name"":""OptionalIntList"",""type"":{""type"":""array"",""items"":[""null"",""int""]}},{""name"":""OptionalIntMatrix"",""type"":{""type"":""array"",""items"":{""type"":""array"",""items"":{""type"":""array"",""items"":[""null"",""int""]}}}},{""name"":""IntMatrix"",""type"":{ [...]
+		private System.Nullable<System.Int32> _OptionalInt;
+		private IList<System.Nullable<System.Int32>> _OptionalIntList;
+		private IList<IList<IList<System.Nullable<System.Int32>>>> _OptionalIntMatrix;
+		private IList<IList<IList<System.Int32>>> _IntMatrix;
+		public virtual Schema Schema
+		{
+			get
+			{
+				return EmbeddedGenericsRecord._SCHEMA;
+			}
+		}
+		public System.Nullable<System.Int32> OptionalInt
+		{
+			get
+			{
+				return this._OptionalInt;
+			}
+			set
+			{
+				this._OptionalInt = value;
+			}
+		}
+		public IList<System.Nullable<System.Int32>> OptionalIntList
+		{
+			get
+			{
+				return this._OptionalIntList;
+			}
+			set
+			{
+				this._OptionalIntList = value;
+			}
+		}
+		public IList<IList<IList<System.Nullable<System.Int32>>>> OptionalIntMatrix
+		{
+			get
+			{
+				return this._OptionalIntMatrix;
+			}
+			set
+			{
+				this._OptionalIntMatrix = value;
+			}
+		}
+		public IList<IList<IList<System.Int32>>> IntMatrix
+		{
+			get
+			{
+				return this._IntMatrix;
+			}
+			set
+			{
+				this._IntMatrix = value;
+			}
+		}
+		public virtual object Get(int fieldPos)
+		{
+			switch (fieldPos)
+			{
+			case 0: return this.OptionalInt;
+			case 1: return this.OptionalIntList;
+			case 2: return this.OptionalIntMatrix;
+			case 3: return this.IntMatrix;
+			default: throw new AvroRuntimeException("Bad index " + fieldPos + " in Get()");
+			};
+		}
+		public virtual void Put(int fieldPos, object fieldValue)
+		{
+			switch (fieldPos)
+			{
+			case 0: this.OptionalInt = (System.Nullable<System.Int32>)fieldValue; break;
+			case 1: this.OptionalIntList = (IList<System.Nullable<System.Int32>>)fieldValue; break;
+			case 2: this.OptionalIntMatrix = (IList<IList<IList<System.Nullable<System.Int32>>>>)fieldValue; break;
+			case 3: this.IntMatrix = (IList<IList<IList<System.Int32>>>)fieldValue; break;
+			default: throw new AvroRuntimeException("Bad index " + fieldPos + " in Put()");
+			};
+		}
+	}
+}
diff --git a/lang/csharp/src/apache/test/Specific/SpecificTests.cs b/lang/csharp/src/apache/test/Specific/SpecificTests.cs
index 99df3bf..9da4b83 100644
--- a/lang/csharp/src/apache/test/Specific/SpecificTests.cs
+++ b/lang/csharp/src/apache/test/Specific/SpecificTests.cs
@@ -25,6 +25,8 @@ using System.CodeDom;
 using System.CodeDom.Compiler;
 using Avro.Specific;
 using System.Reflection;
+using Avro.Test.Specific;
+using System.Collections.Generic;
 
 namespace Avro.Test
 {
@@ -246,6 +248,66 @@ namespace Avro.Test
             Assert.AreEqual( EnumType.SECOND, rec2.enumType );
         }
 
+        [Test]
+        public void TestEmbeddedGenerics()
+        {
+            var srcRecord = new EmbeddedGenericsRecord
+            {
+                OptionalIntList = new List<int?> { 1, 2, null, 3, null, null },
+                OptionalIntMatrix = new List<IList<IList<int?>>>
+                {
+                    new List<IList<int?>>
+                    {
+                        new List<int?> { null, 2, },
+                        new List<int?> { null, null },
+                    },
+                    new List<IList<int?>>
+                    {
+                        new List<int?> { 5, 6, },
+                    },
+                    new List<IList<int?>> { },
+                },
+                IntMatrix = new List<IList<IList<int>>>
+                {
+                    new List<IList<int>>
+                    {
+                        new List<int> { 1, 2, },
+                        new List<int> { 3, 4, },
+                    },
+                    new List<IList<int>>
+                    {
+                        new List<int> { 5, 6, },
+                    },
+                    new List<IList<int>> { },
+                }
+            };
+            var stream = serialize(EmbeddedGenericsRecord._SCHEMA, srcRecord);
+            var dstRecord = deserialize<EmbeddedGenericsRecord>(stream,
+                EmbeddedGenericsRecord._SCHEMA, EmbeddedGenericsRecord._SCHEMA);
+
+            Assert.NotNull(dstRecord);
+            Assert.AreEqual(1, dstRecord.OptionalIntList[0]);
+            Assert.AreEqual(2, dstRecord.OptionalIntList[1]);
+            Assert.AreEqual(null, dstRecord.OptionalIntList[2]);
+            Assert.AreEqual(3, dstRecord.OptionalIntList[3]);
+            Assert.AreEqual(null, dstRecord.OptionalIntList[4]);
+            Assert.AreEqual(null, dstRecord.OptionalIntList[5]);
+            Assert.AreEqual(null, dstRecord.OptionalIntMatrix[0][0][0]);
+            Assert.AreEqual(2, dstRecord.OptionalIntMatrix[0][0][1]);
+            Assert.AreEqual(null, dstRecord.OptionalIntMatrix[0][1][0]);
+            Assert.AreEqual(null, dstRecord.OptionalIntMatrix[0][1][1]);
+            Assert.AreEqual(5, dstRecord.OptionalIntMatrix[1][0][0]);
+            Assert.AreEqual(6, dstRecord.OptionalIntMatrix[1][0][1]);
+            Assert.AreEqual(0, dstRecord.OptionalIntMatrix[2].Count);
+            Assert.AreEqual(1, dstRecord.IntMatrix[0][0][0]);
+            Assert.AreEqual(2, dstRecord.IntMatrix[0][0][1]);
+            Assert.AreEqual(3, dstRecord.IntMatrix[0][1][0]);
+            Assert.AreEqual(4, dstRecord.IntMatrix[0][1][1]);
+            Assert.AreEqual(5, dstRecord.IntMatrix[1][0][0]);
+            Assert.AreEqual(6, dstRecord.IntMatrix[1][0][1]);
+            Assert.AreEqual(0, dstRecord.IntMatrix[2].Count);
+        }
+
         private static S deserialize<S>(Stream ms, Schema ws, Schema rs) where S : class, ISpecificRecord
         {
             long initialPos = ms.Position;