diff --git a/lang/java/avro/pom.xml b/lang/java/avro/pom.xml
index 0bed7aa982a..001597faa32 100644
--- a/lang/java/avro/pom.xml
+++ b/lang/java/avro/pom.xml
@@ -233,16 +233,10 @@
zstd-jni
true
-
- joda-time
- joda-time
- true
-
org.hamcrest
hamcrest-library
test
-
diff --git a/lang/java/avro/src/main/java/org/apache/avro/data/JodaTimeConversions.java b/lang/java/avro/src/main/java/org/apache/avro/data/JodaTimeConversions.java
deleted file mode 100644
index b0099477279..00000000000
--- a/lang/java/avro/src/main/java/org/apache/avro/data/JodaTimeConversions.java
+++ /dev/null
@@ -1,177 +0,0 @@
-/*
- * 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.data;
-
-import org.apache.avro.Conversion;
-import org.apache.avro.LogicalType;
-import org.apache.avro.LogicalTypes;
-import org.apache.avro.Schema;
-import org.joda.time.DateTime;
-import org.joda.time.DateTimeZone;
-import org.joda.time.Days;
-import org.joda.time.LocalDate;
-import org.joda.time.LocalTime;
-
-/**
- * @deprecated use {@link org.apache.avro.data.TimeConversions} instead of Joda
- * date/time API
- */
-@Deprecated
-public class JodaTimeConversions {
- public static class DateConversion extends Conversion {
- private static final LocalDate EPOCH_DATE = new LocalDate(1970, 1, 1);
-
- @Override
- public Class getConvertedType() {
- return LocalDate.class;
- }
-
- @Override
- public String getLogicalTypeName() {
- return "date";
- }
-
- @Override
- public LocalDate fromInt(Integer daysFromEpoch, Schema schema, LogicalType type) {
- return EPOCH_DATE.plusDays(daysFromEpoch);
- }
-
- @Override
- public Integer toInt(LocalDate date, Schema schema, LogicalType type) {
- return Days.daysBetween(EPOCH_DATE, date).getDays();
- }
-
- @Override
- public Schema getRecommendedSchema() {
- return LogicalTypes.date().addToSchema(Schema.create(Schema.Type.INT));
- }
- }
-
- public static class TimeConversion extends Conversion {
- @Override
- public Class getConvertedType() {
- return LocalTime.class;
- }
-
- @Override
- public String getLogicalTypeName() {
- return "time-millis";
- }
-
- @Override
- public LocalTime fromInt(Integer millisFromMidnight, Schema schema, LogicalType type) {
- return LocalTime.fromMillisOfDay(millisFromMidnight);
- }
-
- @Override
- public Integer toInt(LocalTime time, Schema schema, LogicalType type) {
- return time.millisOfDay().get();
- }
-
- @Override
- public Schema getRecommendedSchema() {
- return LogicalTypes.timeMillis().addToSchema(Schema.create(Schema.Type.INT));
- }
- }
-
- public static class TimeMicrosConversion extends Conversion {
- @Override
- public Class getConvertedType() {
- return LocalTime.class;
- }
-
- @Override
- public String getLogicalTypeName() {
- return "time-micros";
- }
-
- @Override
- public LocalTime fromLong(Long microsFromMidnight, Schema schema, LogicalType type) {
- return LocalTime.fromMillisOfDay(microsFromMidnight / 1000);
- }
-
- @Override
- public Schema getRecommendedSchema() {
- return LogicalTypes.timeMicros().addToSchema(Schema.create(Schema.Type.LONG));
- }
- }
-
- public static class LossyTimeMicrosConversion extends TimeMicrosConversion {
- @Override
- public Long toLong(LocalTime time, Schema schema, LogicalType type) {
- return 1000 * (long) time.millisOfDay().get();
- }
- }
-
- public static class TimestampConversion extends Conversion {
- @Override
- public Class getConvertedType() {
- return DateTime.class;
- }
-
- @Override
- public String getLogicalTypeName() {
- return "timestamp-millis";
- }
-
- @Override
- public DateTime fromLong(Long millisFromEpoch, Schema schema, LogicalType type) {
- return new DateTime(millisFromEpoch, DateTimeZone.UTC);
- }
-
- @Override
- public Long toLong(DateTime timestamp, Schema schema, LogicalType type) {
- return timestamp.getMillis();
- }
-
- @Override
- public Schema getRecommendedSchema() {
- return LogicalTypes.timestampMillis().addToSchema(Schema.create(Schema.Type.LONG));
- }
- }
-
- public static class TimestampMicrosConversion extends Conversion {
- @Override
- public Class getConvertedType() {
- return DateTime.class;
- }
-
- @Override
- public String getLogicalTypeName() {
- return "timestamp-micros";
- }
-
- @Override
- public DateTime fromLong(Long microsFromEpoch, Schema schema, LogicalType type) {
- return new DateTime(microsFromEpoch / 1000, DateTimeZone.UTC);
- }
-
- @Override
- public Schema getRecommendedSchema() {
- return LogicalTypes.timestampMicros().addToSchema(Schema.create(Schema.Type.LONG));
- }
- }
-
- public static class LossyTimestampMicrosConversion extends TimestampMicrosConversion {
- @Override
- public Long toLong(DateTime timestamp, Schema schema, LogicalType type) {
- return 1000 * timestamp.getMillis();
- }
- }
-}
diff --git a/lang/java/avro/src/test/java/org/apache/avro/data/TestJodaTimeConversions.java b/lang/java/avro/src/test/java/org/apache/avro/data/TestJodaTimeConversions.java
deleted file mode 100644
index 714dfcacf0a..00000000000
--- a/lang/java/avro/src/test/java/org/apache/avro/data/TestJodaTimeConversions.java
+++ /dev/null
@@ -1,245 +0,0 @@
-/*
- * 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.data;
-
-import java.util.Date;
-
-import org.apache.avro.Conversion;
-import org.apache.avro.LogicalTypes;
-import org.apache.avro.Schema;
-import org.apache.avro.data.JodaTimeConversions.*;
-import org.apache.avro.reflect.ReflectData;
-import org.joda.time.DateTime;
-import org.joda.time.DateTimeZone;
-import org.joda.time.LocalDate;
-import org.joda.time.LocalTime;
-import org.junit.Assert;
-import org.junit.BeforeClass;
-import org.junit.Test;
-
-public class TestJodaTimeConversions {
-
- public static Schema DATE_SCHEMA;
- public static Schema TIME_MILLIS_SCHEMA;
- public static Schema TIME_MICROS_SCHEMA;
- public static Schema TIMESTAMP_MILLIS_SCHEMA;
- public static Schema TIMESTAMP_MICROS_SCHEMA;
-
- @BeforeClass
- public static void createSchemas() {
- TestJodaTimeConversions.DATE_SCHEMA = LogicalTypes.date().addToSchema(Schema.create(Schema.Type.INT));
- TestJodaTimeConversions.TIME_MILLIS_SCHEMA = LogicalTypes.timeMillis().addToSchema(Schema.create(Schema.Type.INT));
- TestJodaTimeConversions.TIME_MICROS_SCHEMA = LogicalTypes.timeMicros().addToSchema(Schema.create(Schema.Type.LONG));
- TestJodaTimeConversions.TIMESTAMP_MILLIS_SCHEMA = LogicalTypes.timestampMillis()
- .addToSchema(Schema.create(Schema.Type.LONG));
- TestJodaTimeConversions.TIMESTAMP_MICROS_SCHEMA = LogicalTypes.timestampMicros()
- .addToSchema(Schema.create(Schema.Type.LONG));
- }
-
- @Test
- public void testDateConversion() throws Exception {
- DateConversion conversion = new DateConversion();
- LocalDate Jan_6_1970 = new LocalDate(1970, 1, 6); // 5
- LocalDate Jan_1_1970 = new LocalDate(1970, 1, 1); // 0
- LocalDate Dec_27_1969 = new LocalDate(1969, 12, 27); // -5
-
- Assert.assertEquals("6 Jan 1970 should be 5", 5,
- (int) conversion.toInt(Jan_6_1970, DATE_SCHEMA, LogicalTypes.date()));
- Assert.assertEquals("1 Jan 1970 should be 0", 0,
- (int) conversion.toInt(Jan_1_1970, DATE_SCHEMA, LogicalTypes.date()));
- Assert.assertEquals("27 Dec 1969 should be -5", -5,
- (int) conversion.toInt(Dec_27_1969, DATE_SCHEMA, LogicalTypes.date()));
-
- Assert.assertEquals("6 Jan 1970 should be 5", conversion.fromInt(5, DATE_SCHEMA, LogicalTypes.date()), Jan_6_1970);
- Assert.assertEquals("1 Jan 1970 should be 0", conversion.fromInt(0, DATE_SCHEMA, LogicalTypes.date()), Jan_1_1970);
- Assert.assertEquals("27 Dec 1969 should be -5", conversion.fromInt(-5, DATE_SCHEMA, LogicalTypes.date()),
- Dec_27_1969);
- }
-
- @Test
- public void testTimeMillisConversion() throws Exception {
- TimeConversion conversion = new TimeConversion();
- LocalTime oneAM = new LocalTime(1, 0);
- LocalTime afternoon = new LocalTime(15, 14, 15, 926);
- int afternoonMillis = ((15 * 60 + 14) * 60 + 15) * 1000 + 926;
-
- Assert.assertEquals("Midnight should be 0", 0,
- (int) conversion.toInt(LocalTime.MIDNIGHT, TIME_MILLIS_SCHEMA, LogicalTypes.timeMillis()));
- Assert.assertEquals("01:00 should be 3,600,000", 3600000,
- (int) conversion.toInt(oneAM, TIME_MILLIS_SCHEMA, LogicalTypes.timeMillis()));
- Assert.assertEquals("15:14:15.926 should be " + afternoonMillis, afternoonMillis,
- (int) conversion.toInt(afternoon, TIME_MILLIS_SCHEMA, LogicalTypes.timeMillis()));
-
- Assert.assertEquals("Midnight should be 0", LocalTime.MIDNIGHT,
- conversion.fromInt(0, TIME_MILLIS_SCHEMA, LogicalTypes.timeMillis()));
- Assert.assertEquals("01:00 should be 3,600,000", oneAM,
- conversion.fromInt(3600000, TIME_MILLIS_SCHEMA, LogicalTypes.timeMillis()));
- Assert.assertEquals("15:14:15.926 should be " + afternoonMillis, afternoon,
- conversion.fromInt(afternoonMillis, TIME_MILLIS_SCHEMA, LogicalTypes.timeMillis()));
- }
-
- @Test
- public void testTimeMicrosConversion() throws Exception {
- TimeMicrosConversion conversion = new TimeMicrosConversion();
- LocalTime oneAM = new LocalTime(1, 0);
- LocalTime afternoon = new LocalTime(15, 14, 15, 926);
- long afternoonMicros = ((long) (15 * 60 + 14) * 60 + 15) * 1000000 + 926551;
-
- Assert.assertEquals("Midnight should be 0", LocalTime.MIDNIGHT,
- conversion.fromLong(0L, TIME_MICROS_SCHEMA, LogicalTypes.timeMicros()));
- Assert.assertEquals("01:00 should be 3,600,000,000", oneAM,
- conversion.fromLong(3600000000L, TIME_MICROS_SCHEMA, LogicalTypes.timeMicros()));
- Assert.assertEquals("15:14:15.926000 should be " + afternoonMicros, afternoon,
- conversion.fromLong(afternoonMicros, TIME_MICROS_SCHEMA, LogicalTypes.timeMicros()));
-
- try {
- conversion.toLong(afternoon, TIMESTAMP_MICROS_SCHEMA, LogicalTypes.timestampMicros());
- Assert.fail("Should not convert LocalTime to long");
- } catch (UnsupportedOperationException e) {
- // expected
- }
- }
-
- @Test
- public void testLossyTimeMicrosConversion() throws Exception {
- TimeMicrosConversion conversion = new LossyTimeMicrosConversion();
- LocalTime oneAM = new LocalTime(1, 0);
- LocalTime afternoon = new LocalTime(15, 14, 15, 926);
- long afternoonMicros = ((long) (15 * 60 + 14) * 60 + 15) * 1000000 + 926551;
-
- Assert.assertEquals("Midnight should be 0", 0,
- (long) conversion.toLong(LocalTime.MIDNIGHT, TIME_MICROS_SCHEMA, LogicalTypes.timeMicros()));
- Assert.assertEquals("01:00 should be 3,600,000,000", 3600000000L,
- (long) conversion.toLong(oneAM, TIME_MICROS_SCHEMA, LogicalTypes.timeMicros()));
- Assert.assertEquals("15:14:15.926551 should be " + afternoonMicros, dropMicros(afternoonMicros), // loses precision!
- (long) conversion.toLong(afternoon, TIME_MICROS_SCHEMA, LogicalTypes.timeMicros()));
-
- Assert.assertEquals("Midnight should be 0", LocalTime.MIDNIGHT,
- conversion.fromLong(0L, TIME_MICROS_SCHEMA, LogicalTypes.timeMicros()));
- Assert.assertEquals("01:00 should be 3,600,000,000", oneAM,
- conversion.fromLong(3600000000L, TIME_MICROS_SCHEMA, LogicalTypes.timeMicros()));
- Assert.assertEquals("15:14:15.926000 should be " + afternoonMicros, afternoon,
- conversion.fromLong(afternoonMicros, TIME_MICROS_SCHEMA, LogicalTypes.timeMicros()));
- }
-
- @Test
- public void testTimestampMillisConversion() throws Exception {
- TimestampConversion conversion = new TimestampConversion();
- long nowInstant = new Date().getTime();
-
- DateTime now = conversion.fromLong(nowInstant, TIMESTAMP_MILLIS_SCHEMA, LogicalTypes.timestampMillis());
- long roundTrip = conversion.toLong(now, TIMESTAMP_MILLIS_SCHEMA, LogicalTypes.timestampMillis());
- Assert.assertEquals("Round-trip conversion should work", nowInstant, roundTrip);
-
- long May_28_2015_21_46_53_221_instant = 1432849613221L;
- DateTime May_28_2015_21_46_53_221 = new DateTime(2015, 5, 28, 21, 46, 53, 221, DateTimeZone.UTC);
-
- Assert.assertEquals("Known date should be correct", May_28_2015_21_46_53_221,
- conversion.fromLong(May_28_2015_21_46_53_221_instant, TIMESTAMP_MILLIS_SCHEMA, LogicalTypes.timestampMillis()));
- Assert.assertEquals("Known date should be correct", May_28_2015_21_46_53_221_instant,
- (long) conversion.toLong(May_28_2015_21_46_53_221, TIMESTAMP_MILLIS_SCHEMA, LogicalTypes.timestampMillis()));
- }
-
- @Test
- public void testTimestampMicrosConversion() throws Exception {
- TimestampMicrosConversion conversion = new TimestampMicrosConversion();
-
- long May_28_2015_21_46_53_221_843_instant = 1432849613221L * 1000 + 843;
- DateTime May_28_2015_21_46_53_221 = new DateTime(2015, 5, 28, 21, 46, 53, 221, DateTimeZone.UTC);
-
- Assert.assertEquals("Known date should be correct", May_28_2015_21_46_53_221, conversion
- .fromLong(May_28_2015_21_46_53_221_843_instant, TIMESTAMP_MICROS_SCHEMA, LogicalTypes.timestampMicros()));
-
- try {
- conversion.toLong(May_28_2015_21_46_53_221, TIMESTAMP_MICROS_SCHEMA, LogicalTypes.timestampMicros());
- Assert.fail("Should not convert DateTime to long");
- } catch (UnsupportedOperationException e) {
- // expected
- }
- }
-
- @Test
- public void testLossyTimestampMicrosConversion() throws Exception {
- TimestampMicrosConversion conversion = new LossyTimestampMicrosConversion();
- long nowInstant = new Date().getTime() * 1000 + 674; // add fake micros
-
- DateTime now = conversion.fromLong(nowInstant, TIMESTAMP_MICROS_SCHEMA, LogicalTypes.timestampMicros());
- long roundTrip = conversion.toLong(now, TIMESTAMP_MICROS_SCHEMA, LogicalTypes.timestampMicros());
- Assert.assertEquals("Round-trip conversion should lose microseconds", dropMicros(nowInstant), roundTrip);
-
- long May_28_2015_21_46_53_221_843_instant = 1432849613221L * 1000 + 843;
- DateTime May_28_2015_21_46_53_221 = new DateTime(2015, 5, 28, 21, 46, 53, 221, DateTimeZone.UTC);
-
- Assert.assertEquals("Known date should be correct", May_28_2015_21_46_53_221, conversion
- .fromLong(May_28_2015_21_46_53_221_843_instant, TIMESTAMP_MICROS_SCHEMA, LogicalTypes.timestampMicros()));
- Assert.assertEquals("Known date should be correct", dropMicros(May_28_2015_21_46_53_221_843_instant),
- (long) conversion.toLong(May_28_2015_21_46_53_221, TIMESTAMP_MICROS_SCHEMA, LogicalTypes.timestampMicros()));
- }
-
- /*
- * model.addLogicalTypeConversion(new
- * JodaTimeConversions.TimeMicrosConversion());
- * model.addLogicalTypeConversion(new
- * JodaTimeConversions.TimestampMicrosConversion());
- */
- @Test
- public void testDynamicSchemaWithDateConversion() throws ClassNotFoundException {
- Schema schema = getReflectedSchemaByName("org.joda.time.LocalDate", new JodaTimeConversions.DateConversion());
- Assert.assertEquals("Reflected schema should be logicalType date", DATE_SCHEMA, schema);
- }
-
- @Test
- public void testDynamicSchemaWithTimeConversion() throws ClassNotFoundException {
- Schema schema = getReflectedSchemaByName("org.joda.time.LocalTime", new JodaTimeConversions.TimeConversion());
- Assert.assertEquals("Reflected schema should be logicalType timeMillis", TIME_MILLIS_SCHEMA, schema);
- }
-
- @Test
- public void testDynamicSchemaWithTimeMicrosConversion() throws ClassNotFoundException {
- Schema schema = getReflectedSchemaByName("org.joda.time.LocalTime", new JodaTimeConversions.TimeMicrosConversion());
- Assert.assertEquals("Reflected schema should be logicalType timeMicros", TIME_MICROS_SCHEMA, schema);
- }
-
- @Test
- public void testDynamicSchemaWithDateTimeConversion() throws ClassNotFoundException {
- Schema schema = getReflectedSchemaByName("org.joda.time.DateTime", new JodaTimeConversions.TimestampConversion());
- Assert.assertEquals("Reflected schema should be logicalType timestampMillis", TIMESTAMP_MILLIS_SCHEMA, schema);
- }
-
- @Test
- public void testDynamicSchemaWithDateTimeMicrosConversion() throws ClassNotFoundException {
- Schema schema = getReflectedSchemaByName("org.joda.time.DateTime",
- new JodaTimeConversions.TimestampMicrosConversion());
- Assert.assertEquals("Reflected schema should be logicalType timestampMicros", TIMESTAMP_MICROS_SCHEMA, schema);
- }
-
- private Schema getReflectedSchemaByName(String className, Conversion> conversion) throws ClassNotFoundException {
- // one argument: a fully qualified class name
- Class> cls = Class.forName(className);
-
- // get the reflected schema for the given class
- ReflectData model = new ReflectData();
- model.addLogicalTypeConversion(conversion);
- return model.getSchema(cls);
- }
-
- private long dropMicros(long micros) {
- return micros / 1000 * 1000;
- }
-}
diff --git a/lang/java/avro/src/test/java/org/apache/avro/data/TestTimeConversions.java b/lang/java/avro/src/test/java/org/apache/avro/data/TestTimeConversions.java
index 69d9707acc2..dcce14a0d5d 100644
--- a/lang/java/avro/src/test/java/org/apache/avro/data/TestTimeConversions.java
+++ b/lang/java/avro/src/test/java/org/apache/avro/data/TestTimeConversions.java
@@ -20,9 +20,11 @@
import java.time.*;
+import org.apache.avro.Conversion;
import org.apache.avro.LogicalTypes;
import org.apache.avro.Schema;
import org.apache.avro.data.TimeConversions.*;
+import org.apache.avro.reflect.ReflectData;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
@@ -67,7 +69,7 @@ public void testDateConversion() throws Exception {
}
@Test
- public void testTimeMillisConversion() throws Exception {
+ public void testTimeMillisConversion() {
TimeMillisConversion conversion = new TimeMillisConversion();
LocalTime oneAM = LocalTime.of(1, 0);
LocalTime afternoon = LocalTime.of(15, 14, 15, 926_000_000);
@@ -180,4 +182,44 @@ public void testTimestampMicrosConversion() throws Exception {
Assert.assertEquals("Pre 1970 date should be correct", Jul_01_1969_12_00_00_000_123_instant, (long) conversion
.toLong(Jul_01_1969_12_00_00_000_123, TIMESTAMP_MILLIS_SCHEMA, LogicalTypes.timestampMillis()));
}
+
+ @Test
+ public void testDynamicSchemaWithDateConversion() throws ClassNotFoundException {
+ Schema schema = getReflectedSchemaByName("java.time.LocalDate", new TimeConversions.DateConversion());
+ Assert.assertEquals("Reflected schema should be logicalType date", DATE_SCHEMA, schema);
+ }
+
+ @Test
+ public void testDynamicSchemaWithTimeConversion() throws ClassNotFoundException {
+ Schema schema = getReflectedSchemaByName("java.time.LocalTime", new TimeConversions.TimeMillisConversion());
+ Assert.assertEquals("Reflected schema should be logicalType timeMillis", TIME_MILLIS_SCHEMA, schema);
+ }
+
+ @Test
+ public void testDynamicSchemaWithTimeMicrosConversion() throws ClassNotFoundException {
+ Schema schema = getReflectedSchemaByName("java.time.LocalTime", new TimeConversions.TimeMicrosConversion());
+ Assert.assertEquals("Reflected schema should be logicalType timeMicros", TIME_MICROS_SCHEMA, schema);
+ }
+
+ @Test
+ public void testDynamicSchemaWithDateTimeConversion() throws ClassNotFoundException {
+ Schema schema = getReflectedSchemaByName("java.time.Instant", new TimeConversions.TimestampMillisConversion());
+ Assert.assertEquals("Reflected schema should be logicalType timestampMillis", TIMESTAMP_MILLIS_SCHEMA, schema);
+ }
+
+ @Test
+ public void testDynamicSchemaWithDateTimeMicrosConversion() throws ClassNotFoundException {
+ Schema schema = getReflectedSchemaByName("java.time.Instant", new TimeConversions.TimestampMicrosConversion());
+ Assert.assertEquals("Reflected schema should be logicalType timestampMicros", TIMESTAMP_MICROS_SCHEMA, schema);
+ }
+
+ private Schema getReflectedSchemaByName(String className, Conversion> conversion) throws ClassNotFoundException {
+ // one argument: a fully qualified class name
+ Class> cls = Class.forName(className);
+
+ // get the reflected schema for the given class
+ ReflectData model = new ReflectData();
+ model.addLogicalTypeConversion(conversion);
+ return model.getSchema(cls);
+ }
}
diff --git a/lang/java/avro/src/test/java/org/apache/avro/specific/TestRecordWithJsr310LogicalTypes.java b/lang/java/avro/src/test/java/org/apache/avro/specific/TestRecordWithJsr310LogicalTypes.java
deleted file mode 100644
index 7abcb0be2c4..00000000000
--- a/lang/java/avro/src/test/java/org/apache/avro/specific/TestRecordWithJsr310LogicalTypes.java
+++ /dev/null
@@ -1,998 +0,0 @@
-/**
- * Autogenerated by Avro
- *
- * DO NOT EDIT DIRECTLY
- */
-package org.apache.avro.specific;
-
-import org.apache.avro.data.TimeConversions;
-import org.apache.avro.message.BinaryMessageDecoder;
-import org.apache.avro.message.BinaryMessageEncoder;
-import org.apache.avro.message.SchemaStore;
-
-@SuppressWarnings("all")
-@org.apache.avro.specific.AvroGenerated
-public class TestRecordWithJsr310LogicalTypes extends org.apache.avro.specific.SpecificRecordBase
- implements org.apache.avro.specific.SpecificRecord {
- private static final long serialVersionUID = 3313339903648295220L;
- public static final org.apache.avro.Schema SCHEMA$ = new org.apache.avro.Schema.Parser().parse(
- "{\"type\":\"record\",\"name\":\"TestRecordWithJsr310LogicalTypes\",\"namespace\":\"org.apache.avro.specific\",\"fields\":[{\"name\":\"b\",\"type\":\"boolean\"},{\"name\":\"i32\",\"type\":\"int\"},{\"name\":\"i64\",\"type\":\"long\"},{\"name\":\"f32\",\"type\":\"float\"},{\"name\":\"f64\",\"type\":\"double\"},{\"name\":\"s\",\"type\":[\"null\",\"string\"],\"default\":null},{\"name\":\"d\",\"type\":{\"type\":\"int\",\"logicalType\":\"date\"}},{\"name\":\"t\",\"type\":{\"type\":\"int\",\"logicalType\":\"time-millis\"}},{\"name\":\"ts\",\"type\":{\"type\":\"long\",\"logicalType\":\"timestamp-millis\"}},{\"name\":\"dec\",\"type\":{\"type\":\"bytes\",\"logicalType\":\"decimal\",\"precision\":9,\"scale\":2}}]}");
-
- public static org.apache.avro.Schema getClassSchema() {
- return SCHEMA$;
- }
-
- private static SpecificData MODEL$ = new SpecificData();
-
- private static final BinaryMessageEncoder ENCODER = new BinaryMessageEncoder(
- MODEL$, SCHEMA$);
-
- private static final BinaryMessageDecoder DECODER = new BinaryMessageDecoder(
- MODEL$, SCHEMA$);
-
- /**
- * Return the BinaryMessageDecoder instance used by this class.
- */
- public static BinaryMessageDecoder getDecoder() {
- return DECODER;
- }
-
- /**
- * Create a new BinaryMessageDecoder instance for this class that uses the
- * specified {@link SchemaStore}.
- *
- * @param resolver a {@link SchemaStore} used to find schemas by fingerprint
- */
- public static BinaryMessageDecoder createDecoder(SchemaStore resolver) {
- return new BinaryMessageDecoder(MODEL$, SCHEMA$, resolver);
- }
-
- /** Serializes this TestRecordWithJsr310LogicalTypes to a ByteBuffer. */
- public java.nio.ByteBuffer toByteBuffer() throws java.io.IOException {
- return ENCODER.encode(this);
- }
-
- /** Deserializes a TestRecordWithJsr310LogicalTypes from a ByteBuffer. */
- public static TestRecordWithJsr310LogicalTypes fromByteBuffer(java.nio.ByteBuffer b) throws java.io.IOException {
- return DECODER.decode(b);
- }
-
- @Deprecated
- public boolean b;
- @Deprecated
- public int i32;
- @Deprecated
- public long i64;
- @Deprecated
- public float f32;
- @Deprecated
- public double f64;
- @Deprecated
- public java.lang.CharSequence s;
- @Deprecated
- public java.time.LocalDate d;
- @Deprecated
- public java.time.LocalTime t;
- @Deprecated
- public java.time.Instant ts;
- @Deprecated
- public java.math.BigDecimal dec;
-
- /**
- * Default constructor. Note that this does not initialize fields to their
- * default values from the schema. If that is desired then one should use
- * newBuilder()
.
- */
- public TestRecordWithJsr310LogicalTypes() {
- }
-
- /**
- * All-args constructor.
- *
- * @param b The new value for b
- * @param i32 The new value for i32
- * @param i64 The new value for i64
- * @param f32 The new value for f32
- * @param f64 The new value for f64
- * @param s The new value for s
- * @param d The new value for d
- * @param t The new value for t
- * @param ts The new value for ts
- * @param dec The new value for dec
- */
- public TestRecordWithJsr310LogicalTypes(java.lang.Boolean b, java.lang.Integer i32, java.lang.Long i64,
- java.lang.Float f32, java.lang.Double f64, java.lang.CharSequence s, java.time.LocalDate d, java.time.LocalTime t,
- java.time.Instant ts, java.math.BigDecimal dec) {
- this.b = b;
- this.i32 = i32;
- this.i64 = i64;
- this.f32 = f32;
- this.f64 = f64;
- this.s = s;
- this.d = d;
- this.t = t;
- this.ts = ts;
- this.dec = dec;
- }
-
- @Override
- public org.apache.avro.Schema getSchema() {
- return SCHEMA$;
- }
-
- // Used by DatumWriter. Applications should not call.
- @Override
- public java.lang.Object get(int field$) {
- switch (field$) {
- case 0:
- return b;
- case 1:
- return i32;
- case 2:
- return i64;
- case 3:
- return f32;
- case 4:
- return f64;
- case 5:
- return s;
- case 6:
- return d;
- case 7:
- return t;
- case 8:
- return ts;
- case 9:
- return dec;
- default:
- throw new org.apache.avro.AvroRuntimeException("Bad index");
- }
- }
-
- protected static final org.apache.avro.Conversions.DecimalConversion DECIMAL_CONVERSION = new org.apache.avro.Conversions.DecimalConversion();
- protected static final TimeConversions.DateConversion DATE_CONVERSION = new TimeConversions.DateConversion();
- protected static final TimeConversions.TimeMillisConversion TIME_CONVERSION = new TimeConversions.TimeMillisConversion();
- protected static final TimeConversions.TimestampMillisConversion TIMESTAMP_CONVERSION = new TimeConversions.TimestampMillisConversion();
-
- private static final org.apache.avro.Conversion>[] conversions = new org.apache.avro.Conversion>[] { null, null,
- null, null, null, null, DATE_CONVERSION, TIME_CONVERSION, TIMESTAMP_CONVERSION, DECIMAL_CONVERSION, null };
-
- @Override
- public org.apache.avro.Conversion> getConversion(int field) {
- return conversions[field];
- }
-
- // Used by DatumReader. Applications should not call.
- @SuppressWarnings(value = "unchecked")
- @Override
- public void put(int field$, java.lang.Object value$) {
- switch (field$) {
- case 0:
- b = (java.lang.Boolean) value$;
- break;
- case 1:
- i32 = (java.lang.Integer) value$;
- break;
- case 2:
- i64 = (java.lang.Long) value$;
- break;
- case 3:
- f32 = (java.lang.Float) value$;
- break;
- case 4:
- f64 = (java.lang.Double) value$;
- break;
- case 5:
- s = (java.lang.CharSequence) value$;
- break;
- case 6:
- d = (java.time.LocalDate) value$;
- break;
- case 7:
- t = (java.time.LocalTime) value$;
- break;
- case 8:
- ts = (java.time.Instant) value$;
- break;
- case 9:
- dec = (java.math.BigDecimal) value$;
- break;
- default:
- throw new org.apache.avro.AvroRuntimeException("Bad index");
- }
- }
-
- /**
- * Gets the value of the 'b' field.
- *
- * @return The value of the 'b' field.
- */
- public java.lang.Boolean getB() {
- return b;
- }
-
- /**
- * Sets the value of the 'b' field.
- *
- * @param value the value to set.
- */
- public void setB(java.lang.Boolean value) {
- this.b = value;
- }
-
- /**
- * Gets the value of the 'i32' field.
- *
- * @return The value of the 'i32' field.
- */
- public java.lang.Integer getI32() {
- return i32;
- }
-
- /**
- * Sets the value of the 'i32' field.
- *
- * @param value the value to set.
- */
- public void setI32(java.lang.Integer value) {
- this.i32 = value;
- }
-
- /**
- * Gets the value of the 'i64' field.
- *
- * @return The value of the 'i64' field.
- */
- public java.lang.Long getI64() {
- return i64;
- }
-
- /**
- * Sets the value of the 'i64' field.
- *
- * @param value the value to set.
- */
- public void setI64(java.lang.Long value) {
- this.i64 = value;
- }
-
- /**
- * Gets the value of the 'f32' field.
- *
- * @return The value of the 'f32' field.
- */
- public java.lang.Float getF32() {
- return f32;
- }
-
- /**
- * Sets the value of the 'f32' field.
- *
- * @param value the value to set.
- */
- public void setF32(java.lang.Float value) {
- this.f32 = value;
- }
-
- /**
- * Gets the value of the 'f64' field.
- *
- * @return The value of the 'f64' field.
- */
- public java.lang.Double getF64() {
- return f64;
- }
-
- /**
- * Sets the value of the 'f64' field.
- *
- * @param value the value to set.
- */
- public void setF64(java.lang.Double value) {
- this.f64 = value;
- }
-
- /**
- * Gets the value of the 's' field.
- *
- * @return The value of the 's' field.
- */
- public java.lang.CharSequence getS() {
- return s;
- }
-
- /**
- * Sets the value of the 's' field.
- *
- * @param value the value to set.
- */
- public void setS(java.lang.CharSequence value) {
- this.s = value;
- }
-
- /**
- * Gets the value of the 'd' field.
- *
- * @return The value of the 'd' field.
- */
- public java.time.LocalDate getD() {
- return d;
- }
-
- /**
- * Sets the value of the 'd' field.
- *
- * @param value the value to set.
- */
- public void setD(java.time.LocalDate value) {
- this.d = value;
- }
-
- /**
- * Gets the value of the 't' field.
- *
- * @return The value of the 't' field.
- */
- public java.time.LocalTime getT() {
- return t;
- }
-
- /**
- * Sets the value of the 't' field.
- *
- * @param value the value to set.
- */
- public void setT(java.time.LocalTime value) {
- this.t = value;
- }
-
- /**
- * Gets the value of the 'ts' field.
- *
- * @return The value of the 'ts' field.
- */
- public java.time.Instant getTs() {
- return ts;
- }
-
- /**
- * Sets the value of the 'ts' field.
- *
- * @param value the value to set.
- */
- public void setTs(java.time.Instant value) {
- this.ts = value;
- }
-
- /**
- * Gets the value of the 'dec' field.
- *
- * @return The value of the 'dec' field.
- */
- public java.math.BigDecimal getDec() {
- return dec;
- }
-
- /**
- * Sets the value of the 'dec' field.
- *
- * @param value the value to set.
- */
- public void setDec(java.math.BigDecimal value) {
- this.dec = value;
- }
-
- /**
- * Creates a new TestRecordWithJsr310LogicalTypes RecordBuilder.
- *
- * @return A new TestRecordWithJsr310LogicalTypes RecordBuilder
- */
- public static TestRecordWithJsr310LogicalTypes.Builder newBuilder() {
- return new TestRecordWithJsr310LogicalTypes.Builder();
- }
-
- /**
- * Creates a new TestRecordWithJsr310LogicalTypes RecordBuilder by copying an
- * existing Builder.
- *
- * @param other The existing builder to copy.
- * @return A new TestRecordWithJsr310LogicalTypes RecordBuilder
- */
- public static TestRecordWithJsr310LogicalTypes.Builder newBuilder(TestRecordWithJsr310LogicalTypes.Builder other) {
- if (other == null) {
- return new TestRecordWithJsr310LogicalTypes.Builder();
- } else {
- return new TestRecordWithJsr310LogicalTypes.Builder(other);
- }
- }
-
- /**
- * Creates a new TestRecordWithJsr310LogicalTypes RecordBuilder by copying an
- * existing TestRecordWithJsr310LogicalTypes instance.
- *
- * @param other The existing instance to copy.
- * @return A new TestRecordWithJsr310LogicalTypes RecordBuilder
- */
- public static TestRecordWithJsr310LogicalTypes.Builder newBuilder(TestRecordWithJsr310LogicalTypes other) {
- if (other == null) {
- return new TestRecordWithJsr310LogicalTypes.Builder();
- } else {
- return new TestRecordWithJsr310LogicalTypes.Builder(other);
- }
- }
-
- /**
- * RecordBuilder for TestRecordWithJsr310LogicalTypes instances.
- */
- public static class Builder
- extends org.apache.avro.specific.SpecificRecordBuilderBase
- implements org.apache.avro.data.RecordBuilder {
-
- private boolean b;
- private int i32;
- private long i64;
- private float f32;
- private double f64;
- private java.lang.CharSequence s;
- private java.time.LocalDate d;
- private java.time.LocalTime t;
- private java.time.Instant ts;
- private java.math.BigDecimal dec;
-
- /** Creates a new Builder */
- private Builder() {
- super(SCHEMA$);
- }
-
- /**
- * Creates a Builder by copying an existing Builder.
- *
- * @param other The existing Builder to copy.
- */
- private Builder(TestRecordWithJsr310LogicalTypes.Builder other) {
- super(other);
- if (isValidValue(fields()[0], other.b)) {
- this.b = data().deepCopy(fields()[0].schema(), other.b);
- fieldSetFlags()[0] = other.fieldSetFlags()[0];
- }
- if (isValidValue(fields()[1], other.i32)) {
- this.i32 = data().deepCopy(fields()[1].schema(), other.i32);
- fieldSetFlags()[1] = other.fieldSetFlags()[1];
- }
- if (isValidValue(fields()[2], other.i64)) {
- this.i64 = data().deepCopy(fields()[2].schema(), other.i64);
- fieldSetFlags()[2] = other.fieldSetFlags()[2];
- }
- if (isValidValue(fields()[3], other.f32)) {
- this.f32 = data().deepCopy(fields()[3].schema(), other.f32);
- fieldSetFlags()[3] = other.fieldSetFlags()[3];
- }
- if (isValidValue(fields()[4], other.f64)) {
- this.f64 = data().deepCopy(fields()[4].schema(), other.f64);
- fieldSetFlags()[4] = other.fieldSetFlags()[4];
- }
- if (isValidValue(fields()[5], other.s)) {
- this.s = data().deepCopy(fields()[5].schema(), other.s);
- fieldSetFlags()[5] = other.fieldSetFlags()[5];
- }
- if (isValidValue(fields()[6], other.d)) {
- this.d = data().deepCopy(fields()[6].schema(), other.d);
- fieldSetFlags()[6] = other.fieldSetFlags()[6];
- }
- if (isValidValue(fields()[7], other.t)) {
- this.t = data().deepCopy(fields()[7].schema(), other.t);
- fieldSetFlags()[7] = other.fieldSetFlags()[7];
- }
- if (isValidValue(fields()[8], other.ts)) {
- this.ts = data().deepCopy(fields()[8].schema(), other.ts);
- fieldSetFlags()[8] = other.fieldSetFlags()[8];
- }
- if (isValidValue(fields()[9], other.dec)) {
- this.dec = data().deepCopy(fields()[9].schema(), other.dec);
- fieldSetFlags()[9] = other.fieldSetFlags()[9];
- }
- }
-
- /**
- * Creates a Builder by copying an existing TestRecordWithJsr310LogicalTypes
- * instance
- *
- * @param other The existing instance to copy.
- */
- private Builder(TestRecordWithJsr310LogicalTypes other) {
- super(SCHEMA$);
- if (isValidValue(fields()[0], other.b)) {
- this.b = data().deepCopy(fields()[0].schema(), other.b);
- fieldSetFlags()[0] = true;
- }
- if (isValidValue(fields()[1], other.i32)) {
- this.i32 = data().deepCopy(fields()[1].schema(), other.i32);
- fieldSetFlags()[1] = true;
- }
- if (isValidValue(fields()[2], other.i64)) {
- this.i64 = data().deepCopy(fields()[2].schema(), other.i64);
- fieldSetFlags()[2] = true;
- }
- if (isValidValue(fields()[3], other.f32)) {
- this.f32 = data().deepCopy(fields()[3].schema(), other.f32);
- fieldSetFlags()[3] = true;
- }
- if (isValidValue(fields()[4], other.f64)) {
- this.f64 = data().deepCopy(fields()[4].schema(), other.f64);
- fieldSetFlags()[4] = true;
- }
- if (isValidValue(fields()[5], other.s)) {
- this.s = data().deepCopy(fields()[5].schema(), other.s);
- fieldSetFlags()[5] = true;
- }
- if (isValidValue(fields()[6], other.d)) {
- this.d = data().deepCopy(fields()[6].schema(), other.d);
- fieldSetFlags()[6] = true;
- }
- if (isValidValue(fields()[7], other.t)) {
- this.t = data().deepCopy(fields()[7].schema(), other.t);
- fieldSetFlags()[7] = true;
- }
- if (isValidValue(fields()[8], other.ts)) {
- this.ts = data().deepCopy(fields()[8].schema(), other.ts);
- fieldSetFlags()[8] = true;
- }
- if (isValidValue(fields()[9], other.dec)) {
- this.dec = data().deepCopy(fields()[9].schema(), other.dec);
- fieldSetFlags()[9] = true;
- }
- }
-
- /**
- * Gets the value of the 'b' field.
- *
- * @return The value.
- */
- public java.lang.Boolean getB() {
- return b;
- }
-
- /**
- * Sets the value of the 'b' field.
- *
- * @param value The value of 'b'.
- * @return This builder.
- */
- public TestRecordWithJsr310LogicalTypes.Builder setB(boolean value) {
- validate(fields()[0], value);
- this.b = value;
- fieldSetFlags()[0] = true;
- return this;
- }
-
- /**
- * Checks whether the 'b' field has been set.
- *
- * @return True if the 'b' field has been set, false otherwise.
- */
- public boolean hasB() {
- return fieldSetFlags()[0];
- }
-
- /**
- * Clears the value of the 'b' field.
- *
- * @return This builder.
- */
- public TestRecordWithJsr310LogicalTypes.Builder clearB() {
- fieldSetFlags()[0] = false;
- return this;
- }
-
- /**
- * Gets the value of the 'i32' field.
- *
- * @return The value.
- */
- public java.lang.Integer getI32() {
- return i32;
- }
-
- /**
- * Sets the value of the 'i32' field.
- *
- * @param value The value of 'i32'.
- * @return This builder.
- */
- public TestRecordWithJsr310LogicalTypes.Builder setI32(int value) {
- validate(fields()[1], value);
- this.i32 = value;
- fieldSetFlags()[1] = true;
- return this;
- }
-
- /**
- * Checks whether the 'i32' field has been set.
- *
- * @return True if the 'i32' field has been set, false otherwise.
- */
- public boolean hasI32() {
- return fieldSetFlags()[1];
- }
-
- /**
- * Clears the value of the 'i32' field.
- *
- * @return This builder.
- */
- public TestRecordWithJsr310LogicalTypes.Builder clearI32() {
- fieldSetFlags()[1] = false;
- return this;
- }
-
- /**
- * Gets the value of the 'i64' field.
- *
- * @return The value.
- */
- public java.lang.Long getI64() {
- return i64;
- }
-
- /**
- * Sets the value of the 'i64' field.
- *
- * @param value The value of 'i64'.
- * @return This builder.
- */
- public TestRecordWithJsr310LogicalTypes.Builder setI64(long value) {
- validate(fields()[2], value);
- this.i64 = value;
- fieldSetFlags()[2] = true;
- return this;
- }
-
- /**
- * Checks whether the 'i64' field has been set.
- *
- * @return True if the 'i64' field has been set, false otherwise.
- */
- public boolean hasI64() {
- return fieldSetFlags()[2];
- }
-
- /**
- * Clears the value of the 'i64' field.
- *
- * @return This builder.
- */
- public TestRecordWithJsr310LogicalTypes.Builder clearI64() {
- fieldSetFlags()[2] = false;
- return this;
- }
-
- /**
- * Gets the value of the 'f32' field.
- *
- * @return The value.
- */
- public java.lang.Float getF32() {
- return f32;
- }
-
- /**
- * Sets the value of the 'f32' field.
- *
- * @param value The value of 'f32'.
- * @return This builder.
- */
- public TestRecordWithJsr310LogicalTypes.Builder setF32(float value) {
- validate(fields()[3], value);
- this.f32 = value;
- fieldSetFlags()[3] = true;
- return this;
- }
-
- /**
- * Checks whether the 'f32' field has been set.
- *
- * @return True if the 'f32' field has been set, false otherwise.
- */
- public boolean hasF32() {
- return fieldSetFlags()[3];
- }
-
- /**
- * Clears the value of the 'f32' field.
- *
- * @return This builder.
- */
- public TestRecordWithJsr310LogicalTypes.Builder clearF32() {
- fieldSetFlags()[3] = false;
- return this;
- }
-
- /**
- * Gets the value of the 'f64' field.
- *
- * @return The value.
- */
- public java.lang.Double getF64() {
- return f64;
- }
-
- /**
- * Sets the value of the 'f64' field.
- *
- * @param value The value of 'f64'.
- * @return This builder.
- */
- public TestRecordWithJsr310LogicalTypes.Builder setF64(double value) {
- validate(fields()[4], value);
- this.f64 = value;
- fieldSetFlags()[4] = true;
- return this;
- }
-
- /**
- * Checks whether the 'f64' field has been set.
- *
- * @return True if the 'f64' field has been set, false otherwise.
- */
- public boolean hasF64() {
- return fieldSetFlags()[4];
- }
-
- /**
- * Clears the value of the 'f64' field.
- *
- * @return This builder.
- */
- public TestRecordWithJsr310LogicalTypes.Builder clearF64() {
- fieldSetFlags()[4] = false;
- return this;
- }
-
- /**
- * Gets the value of the 's' field.
- *
- * @return The value.
- */
- public java.lang.CharSequence getS() {
- return s;
- }
-
- /**
- * Sets the value of the 's' field.
- *
- * @param value The value of 's'.
- * @return This builder.
- */
- public TestRecordWithJsr310LogicalTypes.Builder setS(java.lang.CharSequence value) {
- validate(fields()[5], value);
- this.s = value;
- fieldSetFlags()[5] = true;
- return this;
- }
-
- /**
- * Checks whether the 's' field has been set.
- *
- * @return True if the 's' field has been set, false otherwise.
- */
- public boolean hasS() {
- return fieldSetFlags()[5];
- }
-
- /**
- * Clears the value of the 's' field.
- *
- * @return This builder.
- */
- public TestRecordWithJsr310LogicalTypes.Builder clearS() {
- s = null;
- fieldSetFlags()[5] = false;
- return this;
- }
-
- /**
- * Gets the value of the 'd' field.
- *
- * @return The value.
- */
- public java.time.LocalDate getD() {
- return d;
- }
-
- /**
- * Sets the value of the 'd' field.
- *
- * @param value The value of 'd'.
- * @return This builder.
- */
- public TestRecordWithJsr310LogicalTypes.Builder setD(java.time.LocalDate value) {
- validate(fields()[6], value);
- this.d = value;
- fieldSetFlags()[6] = true;
- return this;
- }
-
- /**
- * Checks whether the 'd' field has been set.
- *
- * @return True if the 'd' field has been set, false otherwise.
- */
- public boolean hasD() {
- return fieldSetFlags()[6];
- }
-
- /**
- * Clears the value of the 'd' field.
- *
- * @return This builder.
- */
- public TestRecordWithJsr310LogicalTypes.Builder clearD() {
- fieldSetFlags()[6] = false;
- return this;
- }
-
- /**
- * Gets the value of the 't' field.
- *
- * @return The value.
- */
- public java.time.LocalTime getT() {
- return t;
- }
-
- /**
- * Sets the value of the 't' field.
- *
- * @param value The value of 't'.
- * @return This builder.
- */
- public TestRecordWithJsr310LogicalTypes.Builder setT(java.time.LocalTime value) {
- validate(fields()[7], value);
- this.t = value;
- fieldSetFlags()[7] = true;
- return this;
- }
-
- /**
- * Checks whether the 't' field has been set.
- *
- * @return True if the 't' field has been set, false otherwise.
- */
- public boolean hasT() {
- return fieldSetFlags()[7];
- }
-
- /**
- * Clears the value of the 't' field.
- *
- * @return This builder.
- */
- public TestRecordWithJsr310LogicalTypes.Builder clearT() {
- fieldSetFlags()[7] = false;
- return this;
- }
-
- /**
- * Gets the value of the 'ts' field.
- *
- * @return The value.
- */
- public java.time.Instant getTs() {
- return ts;
- }
-
- /**
- * Sets the value of the 'ts' field.
- *
- * @param value The value of 'ts'.
- * @return This builder.
- */
- public TestRecordWithJsr310LogicalTypes.Builder setTs(java.time.Instant value) {
- validate(fields()[8], value);
- this.ts = value;
- fieldSetFlags()[8] = true;
- return this;
- }
-
- /**
- * Checks whether the 'ts' field has been set.
- *
- * @return True if the 'ts' field has been set, false otherwise.
- */
- public boolean hasTs() {
- return fieldSetFlags()[8];
- }
-
- /**
- * Clears the value of the 'ts' field.
- *
- * @return This builder.
- */
- public TestRecordWithJsr310LogicalTypes.Builder clearTs() {
- fieldSetFlags()[8] = false;
- return this;
- }
-
- /**
- * Gets the value of the 'dec' field.
- *
- * @return The value.
- */
- public java.math.BigDecimal getDec() {
- return dec;
- }
-
- /**
- * Sets the value of the 'dec' field.
- *
- * @param value The value of 'dec'.
- * @return This builder.
- */
- public TestRecordWithJsr310LogicalTypes.Builder setDec(java.math.BigDecimal value) {
- validate(fields()[9], value);
- this.dec = value;
- fieldSetFlags()[9] = true;
- return this;
- }
-
- /**
- * Checks whether the 'dec' field has been set.
- *
- * @return True if the 'dec' field has been set, false otherwise.
- */
- public boolean hasDec() {
- return fieldSetFlags()[9];
- }
-
- /**
- * Clears the value of the 'dec' field.
- *
- * @return This builder.
- */
- public TestRecordWithJsr310LogicalTypes.Builder clearDec() {
- dec = null;
- fieldSetFlags()[9] = false;
- return this;
- }
-
- @Override
- @SuppressWarnings("unchecked")
- public TestRecordWithJsr310LogicalTypes build() {
- try {
- TestRecordWithJsr310LogicalTypes record = new TestRecordWithJsr310LogicalTypes();
- record.b = fieldSetFlags()[0] ? this.b : (java.lang.Boolean) defaultValue(fields()[0]);
- record.i32 = fieldSetFlags()[1] ? this.i32 : (java.lang.Integer) defaultValue(fields()[1]);
- record.i64 = fieldSetFlags()[2] ? this.i64 : (java.lang.Long) defaultValue(fields()[2]);
- record.f32 = fieldSetFlags()[3] ? this.f32 : (java.lang.Float) defaultValue(fields()[3]);
- record.f64 = fieldSetFlags()[4] ? this.f64 : (java.lang.Double) defaultValue(fields()[4]);
- record.s = fieldSetFlags()[5] ? this.s : (java.lang.CharSequence) defaultValue(fields()[5]);
- record.d = fieldSetFlags()[6] ? this.d : (java.time.LocalDate) defaultValue(fields()[6]);
- record.t = fieldSetFlags()[7] ? this.t : (java.time.LocalTime) defaultValue(fields()[7]);
- record.ts = fieldSetFlags()[8] ? this.ts : (java.time.Instant) defaultValue(fields()[8]);
- record.dec = fieldSetFlags()[9] ? this.dec : (java.math.BigDecimal) defaultValue(fields()[9]);
- return record;
- } catch (java.lang.Exception e) {
- throw new org.apache.avro.AvroRuntimeException(e);
- }
- }
- }
-
- @SuppressWarnings("unchecked")
- private static final org.apache.avro.io.DatumWriter WRITER$ = (org.apache.avro.io.DatumWriter) MODEL$
- .createDatumWriter(SCHEMA$);
-
- @Override
- public void writeExternal(java.io.ObjectOutput out) throws java.io.IOException {
- WRITER$.write(this, SpecificData.getEncoder(out));
- }
-
- @SuppressWarnings("unchecked")
- private static final org.apache.avro.io.DatumReader READER$ = (org.apache.avro.io.DatumReader) MODEL$
- .createDatumReader(SCHEMA$);
-
- @Override
- public void readExternal(java.io.ObjectInput in) throws java.io.IOException {
- READER$.read(this, SpecificData.getDecoder(in));
- }
-
-}
diff --git a/lang/java/avro/src/test/java/org/apache/avro/specific/TestRecordWithLogicalTypes.java b/lang/java/avro/src/test/java/org/apache/avro/specific/TestRecordWithLogicalTypes.java
index 17cdf0cd22e..f684de73096 100644
--- a/lang/java/avro/src/test/java/org/apache/avro/specific/TestRecordWithLogicalTypes.java
+++ b/lang/java/avro/src/test/java/org/apache/avro/specific/TestRecordWithLogicalTypes.java
@@ -5,17 +5,16 @@
*/
package org.apache.avro.specific;
-import java.math.BigDecimal;
-
-import org.apache.avro.data.JodaTimeConversions;
+import org.apache.avro.data.TimeConversions;
import org.apache.avro.message.BinaryMessageDecoder;
import org.apache.avro.message.BinaryMessageEncoder;
+import org.apache.avro.message.SchemaStore;
@SuppressWarnings("all")
@org.apache.avro.specific.AvroGenerated
public class TestRecordWithLogicalTypes extends org.apache.avro.specific.SpecificRecordBase
implements org.apache.avro.specific.SpecificRecord {
- private static final long serialVersionUID = -4211233492739285532L;
+ private static final long serialVersionUID = 3313339903648295220L;
public static final org.apache.avro.Schema SCHEMA$ = new org.apache.avro.Schema.Parser().parse(
"{\"type\":\"record\",\"name\":\"TestRecordWithLogicalTypes\",\"namespace\":\"org.apache.avro.specific\",\"fields\":[{\"name\":\"b\",\"type\":\"boolean\"},{\"name\":\"i32\",\"type\":\"int\"},{\"name\":\"i64\",\"type\":\"long\"},{\"name\":\"f32\",\"type\":\"float\"},{\"name\":\"f64\",\"type\":\"double\"},{\"name\":\"s\",\"type\":[\"null\",\"string\"],\"default\":null},{\"name\":\"d\",\"type\":{\"type\":\"int\",\"logicalType\":\"date\"}},{\"name\":\"t\",\"type\":{\"type\":\"int\",\"logicalType\":\"time-millis\"}},{\"name\":\"ts\",\"type\":{\"type\":\"long\",\"logicalType\":\"timestamp-millis\"}},{\"name\":\"dec\",\"type\":{\"type\":\"bytes\",\"logicalType\":\"decimal\",\"precision\":9,\"scale\":2}}]}");
@@ -31,12 +30,29 @@ public static org.apache.avro.Schema getClassSchema() {
private static final BinaryMessageDecoder DECODER = new BinaryMessageDecoder(
MODEL$, SCHEMA$);
- /** Serializes this ${schema.getName()} to a ByteBuffer. */
+ /**
+ * Return the BinaryMessageDecoder instance used by this class.
+ */
+ public static BinaryMessageDecoder getDecoder() {
+ return DECODER;
+ }
+
+ /**
+ * Create a new BinaryMessageDecoder instance for this class that uses the
+ * specified {@link SchemaStore}.
+ *
+ * @param resolver a {@link SchemaStore} used to find schemas by fingerprint
+ */
+ public static BinaryMessageDecoder createDecoder(SchemaStore resolver) {
+ return new BinaryMessageDecoder(MODEL$, SCHEMA$, resolver);
+ }
+
+ /** Serializes this TestRecordWithLogicalTypes to a ByteBuffer. */
public java.nio.ByteBuffer toByteBuffer() throws java.io.IOException {
return ENCODER.encode(this);
}
- /** Deserializes a ${schema.getName()} from a ByteBuffer. */
+ /** Deserializes a TestRecordWithLogicalTypes from a ByteBuffer. */
public static TestRecordWithLogicalTypes fromByteBuffer(java.nio.ByteBuffer b) throws java.io.IOException {
return DECODER.decode(b);
}
@@ -54,13 +70,13 @@ public static TestRecordWithLogicalTypes fromByteBuffer(java.nio.ByteBuffer b) t
@Deprecated
public java.lang.CharSequence s;
@Deprecated
- public org.joda.time.LocalDate d;
+ public java.time.LocalDate d;
@Deprecated
- public org.joda.time.LocalTime t;
+ public java.time.LocalTime t;
@Deprecated
- public org.joda.time.DateTime ts;
+ public java.time.Instant ts;
@Deprecated
- public BigDecimal dec;
+ public java.math.BigDecimal dec;
/**
* Default constructor. Note that this does not initialize fields to their
@@ -72,10 +88,21 @@ public TestRecordWithLogicalTypes() {
/**
* All-args constructor.
+ *
+ * @param b The new value for b
+ * @param i32 The new value for i32
+ * @param i64 The new value for i64
+ * @param f32 The new value for f32
+ * @param f64 The new value for f64
+ * @param s The new value for s
+ * @param d The new value for d
+ * @param t The new value for t
+ * @param ts The new value for ts
+ * @param dec The new value for dec
*/
public TestRecordWithLogicalTypes(java.lang.Boolean b, java.lang.Integer i32, java.lang.Long i64, java.lang.Float f32,
- java.lang.Double f64, java.lang.CharSequence s, org.joda.time.LocalDate d, org.joda.time.LocalTime t,
- org.joda.time.DateTime ts, BigDecimal dec) {
+ java.lang.Double f64, java.lang.CharSequence s, java.time.LocalDate d, java.time.LocalTime t,
+ java.time.Instant ts, java.math.BigDecimal dec) {
this.b = b;
this.i32 = i32;
this.i64 = i64;
@@ -122,6 +149,19 @@ public java.lang.Object get(int field$) {
}
}
+ protected static final org.apache.avro.Conversions.DecimalConversion DECIMAL_CONVERSION = new org.apache.avro.Conversions.DecimalConversion();
+ protected static final TimeConversions.DateConversion DATE_CONVERSION = new TimeConversions.DateConversion();
+ protected static final TimeConversions.TimeMillisConversion TIME_CONVERSION = new TimeConversions.TimeMillisConversion();
+ protected static final TimeConversions.TimestampMillisConversion TIMESTAMP_CONVERSION = new TimeConversions.TimestampMillisConversion();
+
+ private static final org.apache.avro.Conversion>[] conversions = new org.apache.avro.Conversion>[] { null, null,
+ null, null, null, null, DATE_CONVERSION, TIME_CONVERSION, TIMESTAMP_CONVERSION, DECIMAL_CONVERSION, null };
+
+ @Override
+ public org.apache.avro.Conversion> getConversion(int field) {
+ return conversions[field];
+ }
+
// Used by DatumReader. Applications should not call.
@SuppressWarnings(value = "unchecked")
@Override
@@ -146,16 +186,16 @@ public void put(int field$, java.lang.Object value$) {
s = (java.lang.CharSequence) value$;
break;
case 6:
- d = (org.joda.time.LocalDate) value$;
+ d = (java.time.LocalDate) value$;
break;
case 7:
- t = (org.joda.time.LocalTime) value$;
+ t = (java.time.LocalTime) value$;
break;
case 8:
- ts = (org.joda.time.DateTime) value$;
+ ts = (java.time.Instant) value$;
break;
case 9:
- dec = (BigDecimal) value$;
+ dec = (java.math.BigDecimal) value$;
break;
default:
throw new org.apache.avro.AvroRuntimeException("Bad index");
@@ -164,6 +204,8 @@ public void put(int field$, java.lang.Object value$) {
/**
* Gets the value of the 'b' field.
+ *
+ * @return The value of the 'b' field.
*/
public java.lang.Boolean getB() {
return b;
@@ -180,6 +222,8 @@ public void setB(java.lang.Boolean value) {
/**
* Gets the value of the 'i32' field.
+ *
+ * @return The value of the 'i32' field.
*/
public java.lang.Integer getI32() {
return i32;
@@ -196,6 +240,8 @@ public void setI32(java.lang.Integer value) {
/**
* Gets the value of the 'i64' field.
+ *
+ * @return The value of the 'i64' field.
*/
public java.lang.Long getI64() {
return i64;
@@ -212,6 +258,8 @@ public void setI64(java.lang.Long value) {
/**
* Gets the value of the 'f32' field.
+ *
+ * @return The value of the 'f32' field.
*/
public java.lang.Float getF32() {
return f32;
@@ -228,6 +276,8 @@ public void setF32(java.lang.Float value) {
/**
* Gets the value of the 'f64' field.
+ *
+ * @return The value of the 'f64' field.
*/
public java.lang.Double getF64() {
return f64;
@@ -244,6 +294,8 @@ public void setF64(java.lang.Double value) {
/**
* Gets the value of the 's' field.
+ *
+ * @return The value of the 's' field.
*/
public java.lang.CharSequence getS() {
return s;
@@ -260,8 +312,10 @@ public void setS(java.lang.CharSequence value) {
/**
* Gets the value of the 'd' field.
+ *
+ * @return The value of the 'd' field.
*/
- public org.joda.time.LocalDate getD() {
+ public java.time.LocalDate getD() {
return d;
}
@@ -270,14 +324,16 @@ public org.joda.time.LocalDate getD() {
*
* @param value the value to set.
*/
- public void setD(org.joda.time.LocalDate value) {
+ public void setD(java.time.LocalDate value) {
this.d = value;
}
/**
* Gets the value of the 't' field.
+ *
+ * @return The value of the 't' field.
*/
- public org.joda.time.LocalTime getT() {
+ public java.time.LocalTime getT() {
return t;
}
@@ -286,73 +342,83 @@ public org.joda.time.LocalTime getT() {
*
* @param value the value to set.
*/
- public void setT(org.joda.time.LocalTime value) {
+ public void setT(java.time.LocalTime value) {
this.t = value;
}
/**
* Gets the value of the 'ts' field.
+ *
+ * @return The value of the 'ts' field.
*/
- public org.joda.time.DateTime getTs() {
+ public java.time.Instant getTs() {
return ts;
}
/**
- * Sets the value of the 'dec' field.
+ * Sets the value of the 'ts' field.
*
* @param value the value to set.
*/
- public void setDec(BigDecimal value) {
- this.dec = value;
+ public void setTs(java.time.Instant value) {
+ this.ts = value;
}
/**
- * Gets the value of the 'ts' field.
+ * Gets the value of the 'dec' field.
+ *
+ * @return The value of the 'dec' field.
*/
- public BigDecimal getDec() {
+ public java.math.BigDecimal getDec() {
return dec;
}
/**
- * Sets the value of the 'ts' field.
+ * Sets the value of the 'dec' field.
*
* @param value the value to set.
*/
- public void setTs(org.joda.time.DateTime value) {
- this.ts = value;
- }
-
- protected static final JodaTimeConversions.DateConversion DATE_CONVERSION = new JodaTimeConversions.DateConversion();
- protected static final JodaTimeConversions.TimeConversion TIME_CONVERSION = new JodaTimeConversions.TimeConversion();
- protected static final JodaTimeConversions.TimestampConversion TIMESTAMP_CONVERSION = new JodaTimeConversions.TimestampConversion();
- protected static final org.apache.avro.Conversions.DecimalConversion DECIMAL_CONVERSION = new org.apache.avro.Conversions.DecimalConversion();
- private final org.apache.avro.Conversion>[] conversions = new org.apache.avro.Conversion>[] { null, null, null,
- null, null, null, DATE_CONVERSION, TIME_CONVERSION, TIMESTAMP_CONVERSION, DECIMAL_CONVERSION, null };
-
- @Override
- public org.apache.avro.Conversion> getConversion(int field) {
- return conversions[field];
+ public void setDec(java.math.BigDecimal value) {
+ this.dec = value;
}
- /** Creates a new TestRecordWithLogicalTypes RecordBuilder */
+ /**
+ * Creates a new TestRecordWithLogicalTypes RecordBuilder.
+ *
+ * @return A new TestRecordWithLogicalTypes RecordBuilder
+ */
public static TestRecordWithLogicalTypes.Builder newBuilder() {
return new TestRecordWithLogicalTypes.Builder();
}
/**
* Creates a new TestRecordWithLogicalTypes RecordBuilder by copying an existing
- * Builder
+ * Builder.
+ *
+ * @param other The existing builder to copy.
+ * @return A new TestRecordWithLogicalTypes RecordBuilder
*/
public static TestRecordWithLogicalTypes.Builder newBuilder(TestRecordWithLogicalTypes.Builder other) {
- return new TestRecordWithLogicalTypes.Builder(other);
+ if (other == null) {
+ return new TestRecordWithLogicalTypes.Builder();
+ } else {
+ return new TestRecordWithLogicalTypes.Builder(other);
+ }
}
/**
* Creates a new TestRecordWithLogicalTypes RecordBuilder by copying an existing
- * TestRecordWithLogicalTypes instance
+ * TestRecordWithLogicalTypes instance.
+ *
+ * @param other The existing instance to copy.
+ * @return A new TestRecordWithLogicalTypes RecordBuilder
*/
public static TestRecordWithLogicalTypes.Builder newBuilder(TestRecordWithLogicalTypes other) {
- return new TestRecordWithLogicalTypes.Builder(other);
+ if (other == null) {
+ return new TestRecordWithLogicalTypes.Builder();
+ } else {
+ return new TestRecordWithLogicalTypes.Builder(other);
+ }
}
/**
@@ -367,66 +433,72 @@ public static class Builder extends org.apache.avro.specific.SpecificRecordBuild
private float f32;
private double f64;
private java.lang.CharSequence s;
- private org.joda.time.LocalDate d;
- private org.joda.time.LocalTime t;
- private org.joda.time.DateTime ts;
- private BigDecimal dec;
+ private java.time.LocalDate d;
+ private java.time.LocalTime t;
+ private java.time.Instant ts;
+ private java.math.BigDecimal dec;
/** Creates a new Builder */
private Builder() {
- super(TestRecordWithLogicalTypes.SCHEMA$);
+ super(SCHEMA$);
}
- /** Creates a Builder by copying an existing Builder */
+ /**
+ * Creates a Builder by copying an existing Builder.
+ *
+ * @param other The existing Builder to copy.
+ */
private Builder(TestRecordWithLogicalTypes.Builder other) {
super(other);
if (isValidValue(fields()[0], other.b)) {
this.b = data().deepCopy(fields()[0].schema(), other.b);
- fieldSetFlags()[0] = true;
+ fieldSetFlags()[0] = other.fieldSetFlags()[0];
}
if (isValidValue(fields()[1], other.i32)) {
this.i32 = data().deepCopy(fields()[1].schema(), other.i32);
- fieldSetFlags()[1] = true;
+ fieldSetFlags()[1] = other.fieldSetFlags()[1];
}
if (isValidValue(fields()[2], other.i64)) {
this.i64 = data().deepCopy(fields()[2].schema(), other.i64);
- fieldSetFlags()[2] = true;
+ fieldSetFlags()[2] = other.fieldSetFlags()[2];
}
if (isValidValue(fields()[3], other.f32)) {
this.f32 = data().deepCopy(fields()[3].schema(), other.f32);
- fieldSetFlags()[3] = true;
+ fieldSetFlags()[3] = other.fieldSetFlags()[3];
}
if (isValidValue(fields()[4], other.f64)) {
this.f64 = data().deepCopy(fields()[4].schema(), other.f64);
- fieldSetFlags()[4] = true;
+ fieldSetFlags()[4] = other.fieldSetFlags()[4];
}
if (isValidValue(fields()[5], other.s)) {
this.s = data().deepCopy(fields()[5].schema(), other.s);
- fieldSetFlags()[5] = true;
+ fieldSetFlags()[5] = other.fieldSetFlags()[5];
}
if (isValidValue(fields()[6], other.d)) {
this.d = data().deepCopy(fields()[6].schema(), other.d);
- fieldSetFlags()[6] = true;
+ fieldSetFlags()[6] = other.fieldSetFlags()[6];
}
if (isValidValue(fields()[7], other.t)) {
this.t = data().deepCopy(fields()[7].schema(), other.t);
- fieldSetFlags()[7] = true;
+ fieldSetFlags()[7] = other.fieldSetFlags()[7];
}
if (isValidValue(fields()[8], other.ts)) {
this.ts = data().deepCopy(fields()[8].schema(), other.ts);
- fieldSetFlags()[8] = true;
+ fieldSetFlags()[8] = other.fieldSetFlags()[8];
}
if (isValidValue(fields()[9], other.dec)) {
this.dec = data().deepCopy(fields()[9].schema(), other.dec);
- fieldSetFlags()[9] = true;
+ fieldSetFlags()[9] = other.fieldSetFlags()[9];
}
}
/**
* Creates a Builder by copying an existing TestRecordWithLogicalTypes instance
+ *
+ * @param other The existing instance to copy.
*/
private Builder(TestRecordWithLogicalTypes other) {
- super(TestRecordWithLogicalTypes.SCHEMA$);
+ super(SCHEMA$);
if (isValidValue(fields()[0], other.b)) {
this.b = data().deepCopy(fields()[0].schema(), other.b);
fieldSetFlags()[0] = true;
@@ -471,6 +543,8 @@ private Builder(TestRecordWithLogicalTypes other) {
/**
* Gets the value of the 'b' field.
+ *
+ * @return The value.
*/
public java.lang.Boolean getB() {
return b;
@@ -479,7 +553,8 @@ public java.lang.Boolean getB() {
/**
* Sets the value of the 'b' field.
*
- * @param value the value to set.
+ * @param value The value of 'b'.
+ * @return This builder.
*/
public TestRecordWithLogicalTypes.Builder setB(boolean value) {
validate(fields()[0], value);
@@ -490,6 +565,8 @@ public TestRecordWithLogicalTypes.Builder setB(boolean value) {
/**
* Checks whether the 'b' field has been set.
+ *
+ * @return True if the 'b' field has been set, false otherwise.
*/
public boolean hasB() {
return fieldSetFlags()[0];
@@ -497,6 +574,8 @@ public boolean hasB() {
/**
* Clears the value of the 'b' field.
+ *
+ * @return This builder.
*/
public TestRecordWithLogicalTypes.Builder clearB() {
fieldSetFlags()[0] = false;
@@ -505,6 +584,8 @@ public TestRecordWithLogicalTypes.Builder clearB() {
/**
* Gets the value of the 'i32' field.
+ *
+ * @return The value.
*/
public java.lang.Integer getI32() {
return i32;
@@ -513,7 +594,8 @@ public java.lang.Integer getI32() {
/**
* Sets the value of the 'i32' field.
*
- * @param value the value to set.
+ * @param value The value of 'i32'.
+ * @return This builder.
*/
public TestRecordWithLogicalTypes.Builder setI32(int value) {
validate(fields()[1], value);
@@ -524,6 +606,8 @@ public TestRecordWithLogicalTypes.Builder setI32(int value) {
/**
* Checks whether the 'i32' field has been set.
+ *
+ * @return True if the 'i32' field has been set, false otherwise.
*/
public boolean hasI32() {
return fieldSetFlags()[1];
@@ -531,6 +615,8 @@ public boolean hasI32() {
/**
* Clears the value of the 'i32' field.
+ *
+ * @return This builder.
*/
public TestRecordWithLogicalTypes.Builder clearI32() {
fieldSetFlags()[1] = false;
@@ -539,6 +625,8 @@ public TestRecordWithLogicalTypes.Builder clearI32() {
/**
* Gets the value of the 'i64' field.
+ *
+ * @return The value.
*/
public java.lang.Long getI64() {
return i64;
@@ -547,7 +635,8 @@ public java.lang.Long getI64() {
/**
* Sets the value of the 'i64' field.
*
- * @param value the value to set.
+ * @param value The value of 'i64'.
+ * @return This builder.
*/
public TestRecordWithLogicalTypes.Builder setI64(long value) {
validate(fields()[2], value);
@@ -558,6 +647,8 @@ public TestRecordWithLogicalTypes.Builder setI64(long value) {
/**
* Checks whether the 'i64' field has been set.
+ *
+ * @return True if the 'i64' field has been set, false otherwise.
*/
public boolean hasI64() {
return fieldSetFlags()[2];
@@ -565,6 +656,8 @@ public boolean hasI64() {
/**
* Clears the value of the 'i64' field.
+ *
+ * @return This builder.
*/
public TestRecordWithLogicalTypes.Builder clearI64() {
fieldSetFlags()[2] = false;
@@ -573,6 +666,8 @@ public TestRecordWithLogicalTypes.Builder clearI64() {
/**
* Gets the value of the 'f32' field.
+ *
+ * @return The value.
*/
public java.lang.Float getF32() {
return f32;
@@ -581,7 +676,8 @@ public java.lang.Float getF32() {
/**
* Sets the value of the 'f32' field.
*
- * @param value the value to set.
+ * @param value The value of 'f32'.
+ * @return This builder.
*/
public TestRecordWithLogicalTypes.Builder setF32(float value) {
validate(fields()[3], value);
@@ -592,6 +688,8 @@ public TestRecordWithLogicalTypes.Builder setF32(float value) {
/**
* Checks whether the 'f32' field has been set.
+ *
+ * @return True if the 'f32' field has been set, false otherwise.
*/
public boolean hasF32() {
return fieldSetFlags()[3];
@@ -599,6 +697,8 @@ public boolean hasF32() {
/**
* Clears the value of the 'f32' field.
+ *
+ * @return This builder.
*/
public TestRecordWithLogicalTypes.Builder clearF32() {
fieldSetFlags()[3] = false;
@@ -607,6 +707,8 @@ public TestRecordWithLogicalTypes.Builder clearF32() {
/**
* Gets the value of the 'f64' field.
+ *
+ * @return The value.
*/
public java.lang.Double getF64() {
return f64;
@@ -615,7 +717,8 @@ public java.lang.Double getF64() {
/**
* Sets the value of the 'f64' field.
*
- * @param value the value to set.
+ * @param value The value of 'f64'.
+ * @return This builder.
*/
public TestRecordWithLogicalTypes.Builder setF64(double value) {
validate(fields()[4], value);
@@ -626,6 +729,8 @@ public TestRecordWithLogicalTypes.Builder setF64(double value) {
/**
* Checks whether the 'f64' field has been set.
+ *
+ * @return True if the 'f64' field has been set, false otherwise.
*/
public boolean hasF64() {
return fieldSetFlags()[4];
@@ -633,6 +738,8 @@ public boolean hasF64() {
/**
* Clears the value of the 'f64' field.
+ *
+ * @return This builder.
*/
public TestRecordWithLogicalTypes.Builder clearF64() {
fieldSetFlags()[4] = false;
@@ -641,6 +748,8 @@ public TestRecordWithLogicalTypes.Builder clearF64() {
/**
* Gets the value of the 's' field.
+ *
+ * @return The value.
*/
public java.lang.CharSequence getS() {
return s;
@@ -649,7 +758,8 @@ public java.lang.CharSequence getS() {
/**
* Sets the value of the 's' field.
*
- * @param value the value to set.
+ * @param value The value of 's'.
+ * @return This builder.
*/
public TestRecordWithLogicalTypes.Builder setS(java.lang.CharSequence value) {
validate(fields()[5], value);
@@ -660,6 +770,8 @@ public TestRecordWithLogicalTypes.Builder setS(java.lang.CharSequence value) {
/**
* Checks whether the 's' field has been set.
+ *
+ * @return True if the 's' field has been set, false otherwise.
*/
public boolean hasS() {
return fieldSetFlags()[5];
@@ -667,6 +779,8 @@ public boolean hasS() {
/**
* Clears the value of the 's' field.
+ *
+ * @return This builder.
*/
public TestRecordWithLogicalTypes.Builder clearS() {
s = null;
@@ -676,17 +790,20 @@ public TestRecordWithLogicalTypes.Builder clearS() {
/**
* Gets the value of the 'd' field.
+ *
+ * @return The value.
*/
- public org.joda.time.LocalDate getD() {
+ public java.time.LocalDate getD() {
return d;
}
/**
* Sets the value of the 'd' field.
*
- * @param value the value to set.
+ * @param value The value of 'd'.
+ * @return This builder.
*/
- public TestRecordWithLogicalTypes.Builder setD(org.joda.time.LocalDate value) {
+ public TestRecordWithLogicalTypes.Builder setD(java.time.LocalDate value) {
validate(fields()[6], value);
this.d = value;
fieldSetFlags()[6] = true;
@@ -695,6 +812,8 @@ public TestRecordWithLogicalTypes.Builder setD(org.joda.time.LocalDate value) {
/**
* Checks whether the 'd' field has been set.
+ *
+ * @return True if the 'd' field has been set, false otherwise.
*/
public boolean hasD() {
return fieldSetFlags()[6];
@@ -702,6 +821,8 @@ public boolean hasD() {
/**
* Clears the value of the 'd' field.
+ *
+ * @return This builder.
*/
public TestRecordWithLogicalTypes.Builder clearD() {
fieldSetFlags()[6] = false;
@@ -710,17 +831,20 @@ public TestRecordWithLogicalTypes.Builder clearD() {
/**
* Gets the value of the 't' field.
+ *
+ * @return The value.
*/
- public org.joda.time.LocalTime getT() {
+ public java.time.LocalTime getT() {
return t;
}
/**
* Sets the value of the 't' field.
*
- * @param value the value to set.
+ * @param value The value of 't'.
+ * @return This builder.
*/
- public TestRecordWithLogicalTypes.Builder setT(org.joda.time.LocalTime value) {
+ public TestRecordWithLogicalTypes.Builder setT(java.time.LocalTime value) {
validate(fields()[7], value);
this.t = value;
fieldSetFlags()[7] = true;
@@ -729,6 +853,8 @@ public TestRecordWithLogicalTypes.Builder setT(org.joda.time.LocalTime value) {
/**
* Checks whether the 't' field has been set.
+ *
+ * @return True if the 't' field has been set, false otherwise.
*/
public boolean hasT() {
return fieldSetFlags()[7];
@@ -736,6 +862,8 @@ public boolean hasT() {
/**
* Clears the value of the 't' field.
+ *
+ * @return This builder.
*/
public TestRecordWithLogicalTypes.Builder clearT() {
fieldSetFlags()[7] = false;
@@ -744,17 +872,20 @@ public TestRecordWithLogicalTypes.Builder clearT() {
/**
* Gets the value of the 'ts' field.
+ *
+ * @return The value.
*/
- public org.joda.time.DateTime getTs() {
+ public java.time.Instant getTs() {
return ts;
}
/**
* Sets the value of the 'ts' field.
*
- * @param value the value to set.
+ * @param value The value of 'ts'.
+ * @return This builder.
*/
- public TestRecordWithLogicalTypes.Builder setTs(org.joda.time.DateTime value) {
+ public TestRecordWithLogicalTypes.Builder setTs(java.time.Instant value) {
validate(fields()[8], value);
this.ts = value;
fieldSetFlags()[8] = true;
@@ -763,6 +894,8 @@ public TestRecordWithLogicalTypes.Builder setTs(org.joda.time.DateTime value) {
/**
* Checks whether the 'ts' field has been set.
+ *
+ * @return True if the 'ts' field has been set, false otherwise.
*/
public boolean hasTs() {
return fieldSetFlags()[8];
@@ -770,6 +903,8 @@ public boolean hasTs() {
/**
* Clears the value of the 'ts' field.
+ *
+ * @return This builder.
*/
public TestRecordWithLogicalTypes.Builder clearTs() {
fieldSetFlags()[8] = false;
@@ -777,40 +912,49 @@ public TestRecordWithLogicalTypes.Builder clearTs() {
}
/**
- * Gedec the value of the 'dec' field.
+ * Gets the value of the 'dec' field.
+ *
+ * @return The value.
*/
- public BigDecimal getDec() {
+ public java.math.BigDecimal getDec() {
return dec;
}
/**
- * Sedec the value of the 'dec' field.
+ * Sets the value of the 'dec' field.
*
- * @param value the value to set.
+ * @param value The value of 'dec'.
+ * @return This builder.
*/
- public TestRecordWithLogicalTypes.Builder setDec(BigDecimal value) {
- validate(fields()[8], value);
+ public TestRecordWithLogicalTypes.Builder setDec(java.math.BigDecimal value) {
+ validate(fields()[9], value);
this.dec = value;
- fieldSetFlags()[8] = true;
+ fieldSetFlags()[9] = true;
return this;
}
/**
* Checks whether the 'dec' field has been set.
+ *
+ * @return True if the 'dec' field has been set, false otherwise.
*/
public boolean hasDec() {
- return fieldSetFlags()[8];
+ return fieldSetFlags()[9];
}
/**
* Clears the value of the 'dec' field.
+ *
+ * @return This builder.
*/
public TestRecordWithLogicalTypes.Builder clearDec() {
- fieldSetFlags()[8] = false;
+ dec = null;
+ fieldSetFlags()[9] = false;
return this;
}
@Override
+ @SuppressWarnings("unchecked")
public TestRecordWithLogicalTypes build() {
try {
TestRecordWithLogicalTypes record = new TestRecordWithLogicalTypes();
@@ -820,31 +964,33 @@ public TestRecordWithLogicalTypes build() {
record.f32 = fieldSetFlags()[3] ? this.f32 : (java.lang.Float) defaultValue(fields()[3]);
record.f64 = fieldSetFlags()[4] ? this.f64 : (java.lang.Double) defaultValue(fields()[4]);
record.s = fieldSetFlags()[5] ? this.s : (java.lang.CharSequence) defaultValue(fields()[5]);
- record.d = fieldSetFlags()[6] ? this.d : (org.joda.time.LocalDate) defaultValue(fields()[6]);
- record.t = fieldSetFlags()[7] ? this.t : (org.joda.time.LocalTime) defaultValue(fields()[7]);
- record.ts = fieldSetFlags()[8] ? this.ts : (org.joda.time.DateTime) defaultValue(fields()[8]);
- record.dec = fieldSetFlags()[9] ? this.dec : (BigDecimal) defaultValue(fields()[9]);
+ record.d = fieldSetFlags()[6] ? this.d : (java.time.LocalDate) defaultValue(fields()[6]);
+ record.t = fieldSetFlags()[7] ? this.t : (java.time.LocalTime) defaultValue(fields()[7]);
+ record.ts = fieldSetFlags()[8] ? this.ts : (java.time.Instant) defaultValue(fields()[8]);
+ record.dec = fieldSetFlags()[9] ? this.dec : (java.math.BigDecimal) defaultValue(fields()[9]);
return record;
- } catch (Exception e) {
+ } catch (java.lang.Exception e) {
throw new org.apache.avro.AvroRuntimeException(e);
}
}
}
- private static final org.apache.avro.io.DatumWriter WRITER$ = new org.apache.avro.specific.SpecificDatumWriter(
- SCHEMA$);
+ @SuppressWarnings("unchecked")
+ private static final org.apache.avro.io.DatumWriter WRITER$ = (org.apache.avro.io.DatumWriter) MODEL$
+ .createDatumWriter(SCHEMA$);
@Override
public void writeExternal(java.io.ObjectOutput out) throws java.io.IOException {
- WRITER$.write(this, org.apache.avro.specific.SpecificData.getEncoder(out));
+ WRITER$.write(this, SpecificData.getEncoder(out));
}
- private static final org.apache.avro.io.DatumReader READER$ = new org.apache.avro.specific.SpecificDatumReader(
- SCHEMA$);
+ @SuppressWarnings("unchecked")
+ private static final org.apache.avro.io.DatumReader READER$ = (org.apache.avro.io.DatumReader) MODEL$
+ .createDatumReader(SCHEMA$);
@Override
public void readExternal(java.io.ObjectInput in) throws java.io.IOException {
- READER$.read(this, org.apache.avro.specific.SpecificData.getDecoder(in));
+ READER$.read(this, SpecificData.getDecoder(in));
}
}
diff --git a/lang/java/avro/src/test/java/org/apache/avro/specific/TestSpecificLogicalTypes.java b/lang/java/avro/src/test/java/org/apache/avro/specific/TestSpecificLogicalTypes.java
deleted file mode 100644
index 43d69739efd..00000000000
--- a/lang/java/avro/src/test/java/org/apache/avro/specific/TestSpecificLogicalTypes.java
+++ /dev/null
@@ -1,266 +0,0 @@
-/*
- * 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.specific;
-
-import static java.time.format.DateTimeFormatter.ISO_INSTANT;
-import static java.time.format.DateTimeFormatter.ISO_LOCAL_DATE;
-import static org.hamcrest.Matchers.*;
-
-import java.io.File;
-import java.io.IOException;
-import java.math.BigDecimal;
-import java.math.RoundingMode;
-import java.time.format.DateTimeFormatter;
-import java.time.format.DateTimeFormatterBuilder;
-import java.time.temporal.ChronoField;
-import java.time.temporal.ChronoUnit;
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.avro.Conversions;
-import org.apache.avro.LogicalTypes;
-import org.apache.avro.Schema;
-import org.apache.avro.data.JodaTimeConversions.DateConversion;
-import org.apache.avro.data.JodaTimeConversions.TimeConversion;
-import org.apache.avro.data.JodaTimeConversions.TimestampConversion;
-import org.apache.avro.file.DataFileReader;
-import org.apache.avro.file.DataFileWriter;
-import org.apache.avro.file.FileReader;
-import org.apache.avro.io.DatumReader;
-import org.apache.avro.io.DatumWriter;
-import org.joda.time.DateTime;
-import org.joda.time.DateTimeZone;
-import org.joda.time.LocalDate;
-import org.joda.time.LocalTime;
-import org.joda.time.chrono.ISOChronology;
-import org.joda.time.format.ISODateTimeFormat;
-import org.junit.Assert;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.TemporaryFolder;
-
-/**
- * This tests compatibility between classes generated before and after
- * AVRO-1684. TestRecordWithoutLogicalTypes and TestRecordWithLogicalTypes were
- * generated from the same schema, found in
- * src/test/resources/record_with_logical_types.avsc, and
- * TestRecordWithoutLogicalTypes was renamed to avoid the conflict.
- *
- * The classes should not be re-generated because they test compatibility of
- * Avro with existing Avro-generated sources. When using classes generated
- * before AVRO-1684, logical types should not be applied by the read or write
- * paths. Those files should behave as they did before.
- *
- * For AVRO-2079 {@link TestRecordWithJsr310LogicalTypes} was generated from the
- * same schema and tests were added to test compatibility between the two
- * versions.
- */
-public class TestSpecificLogicalTypes {
-
- // Override the default ISO_LOCAL_TIME to make sure that there are
- // trailing zero's in the format:
- // Expected: is "22:07:33.880"
- // but: was "22:07:33.88"
- private static final DateTimeFormatter ISO_LOCAL_TIME = new DateTimeFormatterBuilder()
- .appendValue(ChronoField.HOUR_OF_DAY, 2).appendLiteral(':').appendValue(ChronoField.MINUTE_OF_HOUR, 2)
- .optionalStart().appendLiteral(':').appendValue(ChronoField.SECOND_OF_MINUTE, 2).optionalStart()
- .appendFraction(ChronoField.NANO_OF_SECOND, 3, 3, true).toFormatter();
-
- @Rule
- public final TemporaryFolder temp = new TemporaryFolder();
-
- @Test
- public void testRecordWithLogicalTypes() throws IOException {
- TestRecordWithLogicalTypes record = new TestRecordWithLogicalTypes(true, 34, 35L, 3.14F, 3019.34, null,
- LocalDate.now(), LocalTime.now(), DateTime.now().withZone(DateTimeZone.UTC),
- new BigDecimal(123.45f).setScale(2, RoundingMode.HALF_DOWN));
-
- File data = write(TestRecordWithLogicalTypes.getClassSchema(), record);
- List actual = read(TestRecordWithLogicalTypes.getClassSchema(), data);
-
- Assert.assertEquals("Should match written record", record, actual.get(0));
- }
-
- @Test
- public void testRecordWithJsr310LogicalTypes() throws IOException {
- TestRecordWithJsr310LogicalTypes record = new TestRecordWithJsr310LogicalTypes(true, 34, 35L, 3.14F, 3019.34, null,
- java.time.LocalDate.now(), java.time.LocalTime.now().truncatedTo(ChronoUnit.MILLIS),
- java.time.Instant.now().truncatedTo(ChronoUnit.MILLIS),
- new BigDecimal(123.45f).setScale(2, RoundingMode.HALF_DOWN));
-
- File data = write(TestRecordWithJsr310LogicalTypes.getClassSchema(), record);
- List actual = read(TestRecordWithJsr310LogicalTypes.getClassSchema(), data);
-
- Assert.assertEquals("Should match written record", record, actual.get(0));
- }
-
- @Test
- public void testAbilityToReadJsr310RecordWrittenAsJodaRecord() throws IOException {
-
- TestRecordWithLogicalTypes withJoda = new TestRecordWithLogicalTypes(true, 34, 35L, 3.14F, 3019.34, null,
- LocalDate.now(), LocalTime.now(),
- // There is no reliable way to get fixed width string from ISO_INSTANT below
- // for granularity less than one second second.
- new DateTime((System.currentTimeMillis() / 1000) * 1000, ISOChronology.getInstance())
- .withZone(DateTimeZone.UTC),
- new BigDecimal(123.45f).setScale(2, RoundingMode.HALF_DOWN));
-
- File data = write(TestRecordWithLogicalTypes.getClassSchema(), withJoda);
- List actual = read(TestRecordWithJsr310LogicalTypes.getClassSchema(), data);
-
- Assert.assertThat(actual, is(not(empty())));
- TestRecordWithJsr310LogicalTypes withJsr310 = actual.get(0);
-
- Assert.assertThat(withJsr310.getB(), is(withJoda.getB()));
- Assert.assertThat(withJsr310.getI32(), is(withJoda.getI32()));
- Assert.assertThat(withJsr310.getI64(), is(withJoda.getI64()));
- Assert.assertThat(withJsr310.getF32(), is(withJoda.getF32()));
- Assert.assertThat(withJsr310.getF64(), is(withJoda.getF64()));
- Assert.assertThat(withJsr310.getS(), is(withJoda.getS()));
-
- Assert.assertThat(ISO_LOCAL_DATE.format(withJsr310.getD()), is(ISODateTimeFormat.date().print(withJoda.getD())));
- Assert.assertThat(ISO_LOCAL_TIME.format(withJsr310.getT()), is(ISODateTimeFormat.time().print(withJoda.getT())));
- Assert.assertThat(ISO_INSTANT.format(withJsr310.getTs()),
- is(ISODateTimeFormat.dateTimeNoMillis().print(withJoda.getTs())));
- Assert.assertThat(withJsr310.getDec(), comparesEqualTo(withJoda.getDec()));
- }
-
- @Test
- public void testAbilityToReadJodaRecordWrittenAsJsr310Record() throws IOException {
- TestRecordWithJsr310LogicalTypes withJsr310 = new TestRecordWithJsr310LogicalTypes(true, 34, 35L, 3.14F, 3019.34,
- null, java.time.LocalDate.now(), java.time.LocalTime.now().truncatedTo(ChronoUnit.MILLIS),
- java.time.Instant.now().truncatedTo(ChronoUnit.MILLIS),
- new BigDecimal(123.45f).setScale(2, RoundingMode.HALF_DOWN));
-
- File data = write(TestRecordWithJsr310LogicalTypes.getClassSchema(), withJsr310);
- List actual = read(TestRecordWithLogicalTypes.getClassSchema(), data);
-
- Assert.assertThat(actual, is(not(empty())));
- TestRecordWithLogicalTypes withJoda = actual.get(0);
-
- Assert.assertThat(withJoda.getB(), is(withJsr310.getB()));
- Assert.assertThat(withJoda.getI32(), is(withJsr310.getI32()));
- Assert.assertThat(withJoda.getI64(), is(withJsr310.getI64()));
- Assert.assertThat(withJoda.getF32(), is(withJsr310.getF32()));
- Assert.assertThat(withJoda.getF64(), is(withJsr310.getF64()));
- Assert.assertThat(withJoda.getS(), is(withJsr310.getS()));
- // all of these print in the ISO-8601 format
- Assert.assertThat(withJoda.getD().toString(), is(withJsr310.getD().toString()));
- Assert.assertThat(withJoda.getT().toString(), is(withJsr310.getT().toString()));
- Assert.assertThat(withJoda.getTs().toString(), is(withJsr310.getTs().toString()));
- Assert.assertThat(withJoda.getDec(), comparesEqualTo(withJsr310.getDec()));
- }
-
- @Test
- public void testRecordWithoutLogicalTypes() throws IOException {
- // the significance of the record without logical types is that it has the
- // same schema (besides record name) as the one with logical types,
- // including the type annotations. this verifies that the type annotations
- // are only applied if the record was compiled to use those types. this
- // ensures compatibility with already-compiled code.
-
- TestRecordWithoutLogicalTypes record = new TestRecordWithoutLogicalTypes(true, 34, 35L, 3.14F, 3019.34, null,
- new DateConversion().toInt(LocalDate.now(), null, null),
- new TimeConversion().toInt(LocalTime.now(), null, null),
- new TimestampConversion().toLong(DateTime.now().withZone(DateTimeZone.UTC), null, null),
- new Conversions.DecimalConversion().toBytes(new BigDecimal(123.45f).setScale(2, RoundingMode.HALF_DOWN), null,
- LogicalTypes.decimal(9, 2)));
-
- File data = write(TestRecordWithoutLogicalTypes.getClassSchema(), record);
- List actual = read(TestRecordWithoutLogicalTypes.getClassSchema(), data);
-
- Assert.assertEquals("Should match written record", record, actual.get(0));
- }
-
- @Test
- public void testRecordWritePrimitivesReadLogicalTypes() throws IOException {
- LocalDate date = LocalDate.now();
- LocalTime time = LocalTime.now();
- DateTime timestamp = DateTime.now().withZone(DateTimeZone.UTC);
- BigDecimal decimal = new BigDecimal(123.45f).setScale(2, RoundingMode.HALF_DOWN);
-
- TestRecordWithoutLogicalTypes record = new TestRecordWithoutLogicalTypes(true, 34, 35L, 3.14F, 3019.34, null,
- new DateConversion().toInt(date, null, null), new TimeConversion().toInt(time, null, null),
- new TimestampConversion().toLong(timestamp, null, null),
- new Conversions.DecimalConversion().toBytes(decimal, null, LogicalTypes.decimal(9, 2)));
-
- File data = write(TestRecordWithoutLogicalTypes.getClassSchema(), record);
- // read using the schema with logical types
- List actual = read(TestRecordWithLogicalTypes.getClassSchema(), data);
-
- TestRecordWithLogicalTypes expected = new TestRecordWithLogicalTypes(true, 34, 35L, 3.14F, 3019.34, null, date,
- time, timestamp, decimal);
-
- Assert.assertEquals("Should match written record", expected, actual.get(0));
- }
-
- @Test
- public void testRecordWriteLogicalTypesReadPrimitives() throws IOException {
- LocalDate date = LocalDate.now();
- LocalTime time = LocalTime.now();
- DateTime timestamp = DateTime.now().withZone(DateTimeZone.UTC);
- BigDecimal decimal = new BigDecimal(123.45f).setScale(2, RoundingMode.HALF_DOWN);
-
- TestRecordWithLogicalTypes record = new TestRecordWithLogicalTypes(true, 34, 35L, 3.14F, 3019.34, null, date, time,
- timestamp, decimal);
-
- File data = write(TestRecordWithLogicalTypes.getClassSchema(), record);
- // read using the schema with logical types
- List actual = read(TestRecordWithoutLogicalTypes.getClassSchema(), data);
-
- TestRecordWithoutLogicalTypes expected = new TestRecordWithoutLogicalTypes(true, 34, 35L, 3.14F, 3019.34, null,
- new DateConversion().toInt(date, null, null), new TimeConversion().toInt(time, null, null),
- new TimestampConversion().toLong(timestamp, null, null),
- new Conversions.DecimalConversion().toBytes(decimal, null, LogicalTypes.decimal(9, 2)));
-
- Assert.assertEquals("Should match written record", expected, actual.get(0));
- }
-
- private List read(Schema schema, File file) throws IOException {
- DatumReader reader = newReader(schema);
- List data = new ArrayList<>();
-
- try (FileReader fileReader = new DataFileReader<>(file, reader)) {
- for (D datum : fileReader) {
- data.add(datum);
- }
- }
-
- return data;
- }
-
- @SuppressWarnings("unchecked")
- private DatumReader newReader(Schema schema) {
- return SpecificData.get().createDatumReader(schema);
- }
-
- @SuppressWarnings("unchecked")
- private File write(Schema schema, D... data) throws IOException {
- File file = temp.newFile();
- DatumWriter writer = SpecificData.get().createDatumWriter(schema);
-
- try (DataFileWriter fileWriter = new DataFileWriter<>(writer)) {
- fileWriter.create(schema, file);
- for (D datum : data) {
- fileWriter.append(datum);
- }
- }
-
- return file;
- }
-}
diff --git a/lang/java/avro/src/test/java/org/apache/avro/specific/TestSpecificToFromByteArray.java b/lang/java/avro/src/test/java/org/apache/avro/specific/TestSpecificToFromByteArray.java
index 5ea4a4a3b5e..9bf40059bf4 100644
--- a/lang/java/avro/src/test/java/org/apache/avro/specific/TestSpecificToFromByteArray.java
+++ b/lang/java/avro/src/test/java/org/apache/avro/specific/TestSpecificToFromByteArray.java
@@ -17,66 +17,69 @@
*/
package org.apache.avro.specific;
-import static org.junit.Assert.assertEquals;
+import org.apache.avro.Conversions;
+import org.apache.avro.LogicalTypes;
+import org.apache.avro.message.MissingSchemaException;
+import org.junit.Test;
import java.io.IOException;
import java.math.BigDecimal;
import java.nio.ByteBuffer;
+import java.time.Instant;
+import java.time.LocalDate;
+import java.time.LocalTime;
+import java.time.temporal.ChronoUnit;
-import org.apache.avro.Conversions;
-import org.apache.avro.LogicalTypes;
-import org.apache.avro.data.JodaTimeConversions;
-import org.apache.avro.message.MissingSchemaException;
-import org.joda.time.DateTime;
-import org.joda.time.DateTimeZone;
-import org.joda.time.LocalDate;
-import org.joda.time.LocalTime;
-import org.junit.Test;
+import static org.junit.Assert.assertEquals;
public class TestSpecificToFromByteArray {
+
@Test
public void testSpecificToFromByteBufferWithLogicalTypes() throws IOException {
- TestRecordWithLogicalTypes record = new TestRecordWithLogicalTypes(true, 34, 35L, 3.14F, 3019.34, null,
- LocalDate.now(), LocalTime.now(), DateTime.now().withZone(DateTimeZone.UTC), new BigDecimal("123.45"));
+ // Java 9+ comes with NANO precision and since we encode it using millis
+ // precision
+ // Therefore we won't want to have NANOs in the input
+ LocalTime t = LocalTime.now().truncatedTo(ChronoUnit.MILLIS);
+ Instant instant = Instant.now().truncatedTo(ChronoUnit.MILLIS);
+
+ final TestRecordWithLogicalTypes record = new TestRecordWithLogicalTypes(true, 34, 35L, 3.14F, 3019.34, null,
+ LocalDate.now(), t, instant, new BigDecimal("123.45"));
- ByteBuffer b = record.toByteBuffer();
- TestRecordWithLogicalTypes copy = TestRecordWithLogicalTypes.fromByteBuffer(b);
+ final ByteBuffer b = record.toByteBuffer();
+ final TestRecordWithLogicalTypes copy = TestRecordWithLogicalTypes.fromByteBuffer(b);
assertEquals(record, copy);
}
@Test
public void testSpecificToFromByteBufferWithoutLogicalTypes() throws IOException {
- TestRecordWithoutLogicalTypes record = new TestRecordWithoutLogicalTypes(true, 34, 35L, 3.14F, 3019.34, null,
- new JodaTimeConversions.DateConversion().toInt(LocalDate.now(), null, null),
- new JodaTimeConversions.TimeConversion().toInt(LocalTime.now(), null, null),
- new JodaTimeConversions.TimestampConversion().toLong(DateTime.now().withZone(DateTimeZone.UTC), null, null),
+ final TestRecordWithoutLogicalTypes record = new TestRecordWithoutLogicalTypes(true, 34, 35L, 3.14F, 3019.34, null,
+ (int) System.currentTimeMillis() / 1000, (int) System.currentTimeMillis() / 1000, System.currentTimeMillis(),
new Conversions.DecimalConversion().toBytes(new BigDecimal("123.45"), null, LogicalTypes.decimal(9, 2)));
- ByteBuffer b = record.toByteBuffer();
- TestRecordWithoutLogicalTypes copy = TestRecordWithoutLogicalTypes.fromByteBuffer(b);
+ final ByteBuffer b = record.toByteBuffer();
+ final TestRecordWithoutLogicalTypes copy = TestRecordWithoutLogicalTypes.fromByteBuffer(b);
assertEquals(record, copy);
}
@Test(expected = MissingSchemaException.class)
public void testSpecificByteArrayIncompatibleWithLogicalTypes() throws IOException {
- TestRecordWithoutLogicalTypes withoutLogicalTypes = new TestRecordWithoutLogicalTypes(true, 34, 35L, 3.14F, 3019.34,
- null, new JodaTimeConversions.DateConversion().toInt(LocalDate.now(), null, null),
- new JodaTimeConversions.TimeConversion().toInt(LocalTime.now(), null, null),
- new JodaTimeConversions.TimestampConversion().toLong(DateTime.now().withZone(DateTimeZone.UTC), null, null),
+ final TestRecordWithoutLogicalTypes withoutLogicalTypes = new TestRecordWithoutLogicalTypes(true, 34, 35L, 3.14F,
+ 3019.34, null, (int) System.currentTimeMillis() / 1000, (int) System.currentTimeMillis() / 1000,
+ System.currentTimeMillis(),
new Conversions.DecimalConversion().toBytes(new BigDecimal("123.45"), null, LogicalTypes.decimal(9, 2)));
- ByteBuffer b = withoutLogicalTypes.toByteBuffer();
+ final ByteBuffer b = withoutLogicalTypes.toByteBuffer();
TestRecordWithLogicalTypes.fromByteBuffer(b);
}
@Test(expected = MissingSchemaException.class)
public void testSpecificByteArrayIncompatibleWithoutLogicalTypes() throws IOException {
- TestRecordWithLogicalTypes withLogicalTypes = new TestRecordWithLogicalTypes(true, 34, 35L, 3.14F, 3019.34, null,
- LocalDate.now(), LocalTime.now(), DateTime.now().withZone(DateTimeZone.UTC), new BigDecimal("123.45"));
+ final TestRecordWithLogicalTypes withLogicalTypes = new TestRecordWithLogicalTypes(true, 34, 35L, 3.14F, 3019.34,
+ null, LocalDate.now(), LocalTime.now(), Instant.now(), new BigDecimal("123.45"));
- ByteBuffer b = withLogicalTypes.toByteBuffer();
+ final ByteBuffer b = withLogicalTypes.toByteBuffer();
TestRecordWithoutLogicalTypes.fromByteBuffer(b);
}
}
diff --git a/lang/java/avro/src/test/resources/record_with_logical_types.avsc b/lang/java/avro/src/test/resources/TestRecordWithLogicalTypes.avsc
similarity index 100%
rename from lang/java/avro/src/test/resources/record_with_logical_types.avsc
rename to lang/java/avro/src/test/resources/TestRecordWithLogicalTypes.avsc
diff --git a/lang/java/compiler/pom.xml b/lang/java/compiler/pom.xml
index 533ff25da8e..cffcf816982 100644
--- a/lang/java/compiler/pom.xml
+++ b/lang/java/compiler/pom.xml
@@ -211,10 +211,6 @@
provided
-
- joda-time
- joda-time
-
diff --git a/lang/java/compiler/src/main/java/org/apache/avro/compiler/specific/ProtocolTask.java b/lang/java/compiler/src/main/java/org/apache/avro/compiler/specific/ProtocolTask.java
index e0d86bdfac3..eb35e1e3be4 100644
--- a/lang/java/compiler/src/main/java/org/apache/avro/compiler/specific/ProtocolTask.java
+++ b/lang/java/compiler/src/main/java/org/apache/avro/compiler/specific/ProtocolTask.java
@@ -23,7 +23,6 @@
import org.apache.avro.AvroRuntimeException;
import org.apache.avro.Protocol;
-import org.apache.avro.compiler.specific.SpecificCompiler.DateTimeLogicalTypeImplementation;
import org.apache.avro.generic.GenericData.StringType;
import org.apache.tools.ant.BuildException;
@@ -37,7 +36,6 @@ public class ProtocolTask extends Task {
private File src;
private File dest = new File(".");
private StringType stringType = StringType.CharSequence;
- private DateTimeLogicalTypeImplementation dateTimeLogicalTypeImplementation = DateTimeLogicalTypeImplementation.DEFAULT;
private final ArrayList filesets = new ArrayList<>();
@@ -61,17 +59,6 @@ public StringType getStringType() {
return this.stringType;
}
- /** Sets the date/time logical type type (either JODA or JSR310) */
- public void setDateTimeLogicalTypeImplementation(
- DateTimeLogicalTypeImplementation dateTimeLogicalTypeImplementation) {
- this.dateTimeLogicalTypeImplementation = dateTimeLogicalTypeImplementation;
- }
-
- /** Get the date/time logical type type (either JODA or JSR310) */
- public DateTimeLogicalTypeImplementation getDateTimeLogicalTypeImplementation() {
- return dateTimeLogicalTypeImplementation;
- }
-
/** Add a fileset. */
public void addFileset(FileSet set) {
filesets.add(set);
@@ -99,7 +86,7 @@ public void execute() {
protected void doCompile(File src, File dir) throws IOException {
Protocol protocol = Protocol.parse(src);
- SpecificCompiler compiler = new SpecificCompiler(protocol, getDateTimeLogicalTypeImplementation());
+ SpecificCompiler compiler = new SpecificCompiler(protocol);
compiler.setStringType(getStringType());
compiler.compileToDestination(src, dest);
}
diff --git a/lang/java/compiler/src/main/java/org/apache/avro/compiler/specific/SchemaTask.java b/lang/java/compiler/src/main/java/org/apache/avro/compiler/specific/SchemaTask.java
index 7cf5bc6bdd6..49280e50a95 100644
--- a/lang/java/compiler/src/main/java/org/apache/avro/compiler/specific/SchemaTask.java
+++ b/lang/java/compiler/src/main/java/org/apache/avro/compiler/specific/SchemaTask.java
@@ -26,9 +26,9 @@
public class SchemaTask extends ProtocolTask {
@Override
protected void doCompile(File src, File dest) throws IOException {
- Schema.Parser parser = new Schema.Parser();
- Schema schema = parser.parse(src);
- SpecificCompiler compiler = new SpecificCompiler(schema, getDateTimeLogicalTypeImplementation());
+ final Schema.Parser parser = new Schema.Parser();
+ final Schema schema = parser.parse(src);
+ final SpecificCompiler compiler = new SpecificCompiler(schema);
compiler.setStringType(getStringType());
compiler.compileToDestination(src, dest);
}
diff --git a/lang/java/compiler/src/main/java/org/apache/avro/compiler/specific/SpecificCompiler.java b/lang/java/compiler/src/main/java/org/apache/avro/compiler/specific/SpecificCompiler.java
index 9320480bc31..14d5a3e49a3 100644
--- a/lang/java/compiler/src/main/java/org/apache/avro/compiler/specific/SpecificCompiler.java
+++ b/lang/java/compiler/src/main/java/org/apache/avro/compiler/specific/SpecificCompiler.java
@@ -39,7 +39,6 @@
import org.apache.avro.Conversions;
import org.apache.avro.LogicalTypes;
import org.apache.avro.data.TimeConversions;
-import org.apache.avro.data.JodaTimeConversions;
import org.apache.avro.specific.SpecificData;
import org.apache.avro.Protocol;
@@ -96,29 +95,12 @@ public enum FieldVisibility {
PUBLIC, PUBLIC_DEPRECATED, PRIVATE
}
- public enum DateTimeLogicalTypeImplementation {
- JODA {
- @Override
- void addLogicalTypeConversions(SpecificData specificData) {
- specificData.addLogicalTypeConversion(new JodaTimeConversions.DateConversion());
- specificData.addLogicalTypeConversion(new JodaTimeConversions.TimeConversion());
- specificData.addLogicalTypeConversion(new JodaTimeConversions.TimestampConversion());
- }
- },
- JSR310 {
- @Override
- void addLogicalTypeConversions(SpecificData specificData) {
- specificData.addLogicalTypeConversion(new TimeConversions.DateConversion());
- specificData.addLogicalTypeConversion(new TimeConversions.TimeMillisConversion());
- specificData.addLogicalTypeConversion(new TimeConversions.TimeMicrosConversion());
- specificData.addLogicalTypeConversion(new TimeConversions.TimestampMillisConversion());
- specificData.addLogicalTypeConversion(new TimeConversions.TimestampMicrosConversion());
- }
- };
-
- public static final DateTimeLogicalTypeImplementation DEFAULT = JSR310;
-
- abstract void addLogicalTypeConversions(SpecificData specificData);
+ void addLogicalTypeConversions(SpecificData specificData) {
+ specificData.addLogicalTypeConversion(new TimeConversions.DateConversion());
+ specificData.addLogicalTypeConversion(new TimeConversions.TimeMillisConversion());
+ specificData.addLogicalTypeConversion(new TimeConversions.TimeMicrosConversion());
+ specificData.addLogicalTypeConversion(new TimeConversions.TimestampMillisConversion());
+ specificData.addLogicalTypeConversion(new TimeConversions.TimestampMicrosConversion());
}
private final SpecificData specificData = new SpecificData();
@@ -134,7 +116,6 @@ void addLogicalTypeConversions(SpecificData specificData) {
private boolean createAllArgsConstructor = true;
private String outputCharacterEncoding;
private boolean enableDecimalLogicalType = false;
- private final DateTimeLogicalTypeImplementation dateTimeLogicalTypeImplementation;
private String suffix = ".java";
private List