You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@avro.apache.org by ie...@apache.org on 2020/06/09 10:02:35 UTC

[avro] branch branch-1.10 updated (951a40c -> 6fb4e13)

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

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


    from 951a40c  Preparing for release 1.10.0
     new 54d8f79  AVRO-2780: ProtobufData and ThriftData Can Get Into Endless Loop (#908)
     new 27eebc2  AVRO-2139: Add Test for Decimal @java-class Annotated Generated Classes (#909)
     new 6fb4e13  AVRO-1669: PHP Fixed null handling on fields. (#913)

The 3 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:
 .../org/apache/avro/generic/TestBuilderCopy.java   | 52 ++++++++++++++++++++++
 .../org/apache/avro/protobuf/ProtobufData.java     |  2 +-
 .../java/org/apache/avro/thrift/ThriftData.java    |  2 +-
 lang/php/lib/Datum/AvroIODatumWriter.php           |  2 +-
 lang/php/lib/Schema/AvroSchema.php                 |  7 +--
 lang/php/test/IODatumReaderTest.php                | 25 +++++++++++
 6 files changed, 81 insertions(+), 9 deletions(-)
 create mode 100644 lang/java/ipc/src/test/java/org/apache/avro/generic/TestBuilderCopy.java


[avro] 02/03: AVRO-2139: Add Test for Decimal @java-class Annotated Generated Classes (#909)

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

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

commit 27eebc2af0fca74834b71b3cabecdd664a099184
Author: belugabehr <12...@users.noreply.github.com>
AuthorDate: Mon Jun 8 08:59:50 2020 -0400

    AVRO-2139: Add Test for Decimal @java-class Annotated Generated Classes (#909)
---
 .../org/apache/avro/generic/TestBuilderCopy.java   | 52 ++++++++++++++++++++++
 1 file changed, 52 insertions(+)

diff --git a/lang/java/ipc/src/test/java/org/apache/avro/generic/TestBuilderCopy.java b/lang/java/ipc/src/test/java/org/apache/avro/generic/TestBuilderCopy.java
new file mode 100644
index 0000000..3fed9c2
--- /dev/null
+++ b/lang/java/ipc/src/test/java/org/apache/avro/generic/TestBuilderCopy.java
@@ -0,0 +1,52 @@
+/*
+ * 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.
+ */
+
+package org.apache.avro.generic;
+
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import java.util.HashMap;
+
+import org.junit.Test;
+
+import test.StringablesRecord;
+
+import static org.junit.Assert.assertEquals;
+
+/** Unit test for performing a builder copy of an object with a schema */
+public class TestBuilderCopy {
+  @Test
+  public void testBuilderCopy() {
+    StringablesRecord.Builder builder = StringablesRecord.newBuilder();
+    builder.setValue(new BigDecimal("1314.11"));
+
+    HashMap<String, BigDecimal> mapWithBigDecimalElements = new HashMap<>();
+    mapWithBigDecimalElements.put("testElement", new BigDecimal("220.11"));
+    builder.setMapWithBigDecimalElements(mapWithBigDecimalElements);
+
+    HashMap<BigInteger, String> mapWithBigIntKeys = new HashMap<>();
+    mapWithBigIntKeys.put(BigInteger.ONE, "testKey");
+    builder.setMapWithBigIntKeys(mapWithBigIntKeys);
+
+    StringablesRecord original = builder.build();
+
+    StringablesRecord duplicate = StringablesRecord.newBuilder(original).build();
+
+    assertEquals(duplicate, original);
+  }
+}


[avro] 03/03: AVRO-1669: PHP Fixed null handling on fields. (#913)

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

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

commit 6fb4e13322413f19d0522956a2941c88bf315fe2
Author: Siad Ardroumli <si...@gmail.com>
AuthorDate: Mon Jun 8 15:04:25 2020 +0200

    AVRO-1669: PHP Fixed null handling on fields. (#913)
---
 lang/php/lib/Datum/AvroIODatumWriter.php |  2 +-
 lang/php/lib/Schema/AvroSchema.php       |  7 +------
 lang/php/test/IODatumReaderTest.php      | 25 +++++++++++++++++++++++++
 3 files changed, 27 insertions(+), 7 deletions(-)

diff --git a/lang/php/lib/Datum/AvroIODatumWriter.php b/lang/php/lib/Datum/AvroIODatumWriter.php
index 7556319..000f070 100644
--- a/lang/php/lib/Datum/AvroIODatumWriter.php
+++ b/lang/php/lib/Datum/AvroIODatumWriter.php
@@ -163,7 +163,7 @@ class AvroIODatumWriter
     private function writeRecord($writers_schema, $datum, $encoder)
     {
         foreach ($writers_schema->fields() as $field) {
-            $this->writeData($field->type(), $datum[$field->name()], $encoder);
+            $this->writeData($field->type(), $datum[$field->name()] ?? null, $encoder);
         }
     }
 
diff --git a/lang/php/lib/Schema/AvroSchema.php b/lang/php/lib/Schema/AvroSchema.php
index 7b43922..6cbc73a 100644
--- a/lang/php/lib/Schema/AvroSchema.php
+++ b/lang/php/lib/Schema/AvroSchema.php
@@ -481,12 +481,7 @@ class AvroSchema
             case self::REQUEST_SCHEMA:
                 if (is_array($datum)) {
                     foreach ($expected_schema->fields() as $field) {
-                        if (
-                            !array_key_exists($field->name(), $datum) || !self::isValidDatum(
-                                $field->type(),
-                                $datum[$field->name()]
-                            )
-                        ) {
+                        if (!self::isValidDatum($field->type(), $datum[$field->name()] ?? null)) {
                             return false;
                         }
                     }
diff --git a/lang/php/test/IODatumReaderTest.php b/lang/php/test/IODatumReaderTest.php
index 05d56ba..e15d3ac 100644
--- a/lang/php/test/IODatumReaderTest.php
+++ b/lang/php/test/IODatumReaderTest.php
@@ -19,7 +19,10 @@
 
 namespace Apache\Avro\Tests;
 
+use Apache\Avro\Datum\AvroIOBinaryEncoder;
 use Apache\Avro\Datum\AvroIODatumReader;
+use Apache\Avro\Datum\AvroIODatumWriter;
+use Apache\Avro\IO\AvroStringIO;
 use Apache\Avro\Schema\AvroSchema;
 use PHPUnit\Framework\TestCase;
 
@@ -36,4 +39,26 @@ JSON;
             AvroSchema::parse($writers_schema),
             AvroSchema::parse($readers_schema)));
     }
+
+    public function testRecordNullField()
+    {
+        $schema_json = <<<_JSON
+{"name":"member",
+ "type":"record",
+ "fields":[{"name":"one", "type":"int"},
+           {"name":"two", "type":["null", "string"]}
+           ]}
+_JSON;
+
+        $schema = AvroSchema::parse($schema_json);
+        $datum = array("one" => 1);
+
+        $io = new AvroStringIO();
+        $writer = new AvroIODatumWriter($schema);
+        $encoder = new AvroIOBinaryEncoder($io);
+        $writer->write($datum, $encoder);
+        $bin = $io->string();
+
+        $this->assertSame('0200', bin2hex($bin));
+    }
 }


[avro] 01/03: AVRO-2780: ProtobufData and ThriftData Can Get Into Endless Loop (#908)

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

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

commit 54d8f793c234795514cb91ac2ff6dc290c5cee18
Author: belugabehr <12...@users.noreply.github.com>
AuthorDate: Mon Jun 8 08:58:18 2020 -0400

    AVRO-2780: ProtobufData and ThriftData Can Get Into Endless Loop (#908)
---
 .../protobuf/src/main/java/org/apache/avro/protobuf/ProtobufData.java   | 2 +-
 lang/java/thrift/src/main/java/org/apache/avro/thrift/ThriftData.java   | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/lang/java/protobuf/src/main/java/org/apache/avro/protobuf/ProtobufData.java b/lang/java/protobuf/src/main/java/org/apache/avro/protobuf/ProtobufData.java
index c4c0d9c..38f2d04 100644
--- a/lang/java/protobuf/src/main/java/org/apache/avro/protobuf/ProtobufData.java
+++ b/lang/java/protobuf/src/main/java/org/apache/avro/protobuf/ProtobufData.java
@@ -138,7 +138,7 @@ public class ProtobufData extends GenericData {
     try {
       Class c = SpecificData.get().getClass(schema);
       if (c == null)
-        return newRecord(old, schema); // punt to generic
+        return super.newRecord(old, schema); // punt to generic
       if (c.isInstance(old))
         return old; // reuse instance
       return c.getMethod("newBuilder").invoke(null);
diff --git a/lang/java/thrift/src/main/java/org/apache/avro/thrift/ThriftData.java b/lang/java/thrift/src/main/java/org/apache/avro/thrift/ThriftData.java
index eaf11c7..0e08318 100644
--- a/lang/java/thrift/src/main/java/org/apache/avro/thrift/ThriftData.java
+++ b/lang/java/thrift/src/main/java/org/apache/avro/thrift/ThriftData.java
@@ -159,7 +159,7 @@ public class ThriftData extends GenericData {
     try {
       Class c = ClassUtils.forName(SpecificData.getClassName(schema));
       if (c == null)
-        return newRecord(old, schema); // punt to generic
+        return super.newRecord(old, schema); // punt to generic
       if (c.isInstance(old))
         return old; // reuse instance
       return c.newInstance(); // create new instance