Skip to content

Commit 6059a07

Browse files
Fokkoelectrum
authored andcommitted
Bump Apache Avro to 1.9.1
1 parent 48d50c4 commit 6059a07

File tree

5 files changed

+30
-6
lines changed

5 files changed

+30
-6
lines changed

pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -815,6 +815,12 @@
815815
</exclusions>
816816
</dependency>
817817

818+
<dependency>
819+
<groupId>org.apache.avro</groupId>
820+
<artifactId>avro</artifactId>
821+
<version>1.9.1</version>
822+
</dependency>
823+
818824
<dependency>
819825
<groupId>net.sf.opencsv</groupId>
820826
<artifactId>opencsv</artifactId>

presto-product-tests/conf/presto/etc/catalog/kafka/all_datatypes_avro_schema.avsc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
{
88
"name":"a_varchar",
99
"type":["null", "string"],
10-
"default": "null"
10+
"default": null
1111
},
1212
{
1313
"name":"a_bigint",

presto-product-tests/pom.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
<dependency>
2222
<groupId>org.apache.avro</groupId>
2323
<artifactId>avro</artifactId>
24-
<version>1.8.1</version>
2524
</dependency>
2625

2726
<dependency>

presto-record-decoder/pom.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@
5454
<dependency>
5555
<groupId>org.apache.avro</groupId>
5656
<artifactId>avro</artifactId>
57-
<version>1.8.1</version>
5857
</dependency>
5958

6059
<dependency>

presto-record-decoder/src/test/java/io/prestosql/decoder/avro/TestAvroDecoder.java

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,30 @@ private static String getAvroSchema(String name, String dataType)
8686
return getAvroSchema(ImmutableMap.of(name, dataType));
8787
}
8888

89+
private static String determineDefaultValue(String dataType)
90+
{
91+
// Apache Avro 1.9 is more strict on the nullability of data types.
92+
// If the data type is not nullable, then we don't want to set null as the default.
93+
if (dataType.contains("\"array\"")) {
94+
// In the case of an Array we just will return an empty array
95+
return ", \"default\": []";
96+
}
97+
if (dataType.contains("\"map\"")) {
98+
// In the case of a Map we just will return an empty map
99+
return ", \"default\": {}";
100+
}
101+
if (dataType.contains("null")) {
102+
// Will match ["null", "string"] and any other variation.
103+
return ", \"default\": null";
104+
}
105+
// In case of non-nullable types like "string"
106+
return "";
107+
}
108+
89109
private static String getAvroSchema(Map<String, String> fields)
90110
{
91111
String fieldSchema = fields.entrySet().stream()
92-
.map(entry -> "{\"name\": \"" + entry.getKey() + "\",\"type\": " + entry.getValue() + ",\"default\": null}")
112+
.map(entry -> "{\"name\": \"" + entry.getKey() + "\",\"type\": " + entry.getValue() + determineDefaultValue(entry.getValue()) + "}")
93113
.collect(Collectors.joining(","));
94114

95115
return "{\"type\" : \"record\"," +
@@ -424,7 +444,7 @@ public void testArrayDecodedAsArray()
424444
{
425445
DecoderTestColumnHandle row = new DecoderTestColumnHandle(0, "row", new ArrayType(BIGINT), "array_field", null, null, false, false, false);
426446

427-
Map<DecoderColumnHandle, FieldValueProvider> decodedRow = buildAndDecodeColumn(row, "array_field", "{\"type\": \"array\", \"items\": \"long\"}", ImmutableList.of(114L, 136L));
447+
Map<DecoderColumnHandle, FieldValueProvider> decodedRow = buildAndDecodeColumn(row, "array_field", "{\"type\": \"array\", \"items\": [\"long\"]}", ImmutableList.of(114L, 136L));
428448
checkArrayValue(decodedRow, row, new long[] {114, 136});
429449
}
430450

@@ -436,7 +456,7 @@ public void testArrayWithNulls()
436456

437457
List<Long> values = new ArrayList<>();
438458
values.add(null);
439-
Map<DecoderColumnHandle, FieldValueProvider> decodedRow = buildAndDecodeColumn(row, "array_field", "{\"type\": \"array\", \"items\": \"null\"}", values);
459+
Map<DecoderColumnHandle, FieldValueProvider> decodedRow = buildAndDecodeColumn(row, "array_field", "{\"type\": \"array\", \"items\": [\"null\"]}", values);
440460
checkArrayItemIsNull(decodedRow, row, new long[] {0});
441461
}
442462

0 commit comments

Comments
 (0)