This is an automated email from the ASF dual-hosted git repository.
dkulp pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/avro.git
The following commit(s) were added to refs/heads/master by this push:
new c369dd1 Rename JSR310 conversion class to TimeConversions, deprecate
Joda conversion
c369dd1 is described below
commit c369dd1b4d2f807bfdec5b25317a5adee855d7fc
Author: Nandor Kollar <[email protected]>
AuthorDate: Fri Mar 29 11:45:19 2019 +0100
Rename JSR310 conversion class to TimeConversions, deprecate Joda conversion
---
...meConversions.java => JodaTimeConversions.java} | 113 +++++--------
.../java/org/apache/avro/data/TimeConversions.java | 104 ++++++++----
...nversions.java => TestJodaTimeConversions.java} | 30 ++--
.../avro/data/TestJsr310TimeConversions.java | 185 ---------------------
.../org/apache/avro/data/TestTimeConversions.java | 178 +++++++-------------
.../specific/TestRecordWithJsr310LogicalTypes.java | 141 ++++++++--------
.../avro/specific/TestRecordWithLogicalTypes.java | 48 +++---
.../avro/specific/TestSpecificLogicalTypes.java | 6 +-
.../avro/specific/TestSpecificToFromByteArray.java | 14 +-
.../avro/compiler/specific/SpecificCompiler.java | 18 +-
.../compiler/specific/TestSpecificCompiler.java | 42 +++--
.../avro/examples/baseball/FieldTest.java | 12 +-
12 files changed, 334 insertions(+), 557 deletions(-)
diff --git
a/lang/java/avro/src/main/java/org/apache/avro/data/Jsr310TimeConversions.java
b/lang/java/avro/src/main/java/org/apache/avro/data/JodaTimeConversions.java
similarity index 55%
rename from
lang/java/avro/src/main/java/org/apache/avro/data/Jsr310TimeConversions.java
rename to
lang/java/avro/src/main/java/org/apache/avro/data/JodaTimeConversions.java
index 0f608dc..ff767e1 100644
---
a/lang/java/avro/src/main/java/org/apache/avro/data/Jsr310TimeConversions.java
+++ b/lang/java/avro/src/main/java/org/apache/avro/data/JodaTimeConversions.java
@@ -22,14 +22,20 @@ import org.apache.avro.Conversion;
import org.apache.avro.LogicalType;
import org.apache.avro.LogicalTypes;
import org.apache.avro.Schema;
-
-import java.time.Instant;
-import java.time.LocalDate;
-import java.time.LocalTime;
-import java.util.concurrent.TimeUnit;
-
-public class Jsr310TimeConversions {
+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<LocalDate> {
+ private static final LocalDate EPOCH_DATE = new LocalDate(1970, 1, 1);
@Override
public Class<LocalDate> getConvertedType() {
@@ -43,14 +49,12 @@ public class Jsr310TimeConversions {
@Override
public LocalDate fromInt(Integer daysFromEpoch, Schema schema, LogicalType
type) {
- return LocalDate.ofEpochDay(daysFromEpoch);
+ return EPOCH_DATE.plusDays(daysFromEpoch);
}
@Override
public Integer toInt(LocalDate date, Schema schema, LogicalType type) {
- long epochDays = date.toEpochDay();
-
- return (int) epochDays;
+ return Days.daysBetween(EPOCH_DATE, date).getDays();
}
@Override
@@ -59,7 +63,7 @@ public class Jsr310TimeConversions {
}
}
- public static class TimeMillisConversion extends Conversion<LocalTime> {
+ public static class TimeConversion extends Conversion<LocalTime> {
@Override
public Class<LocalTime> getConvertedType() {
return LocalTime.class;
@@ -71,18 +75,13 @@ public class Jsr310TimeConversions {
}
@Override
- public String adjustAndSetValue(String varName, String valParamName) {
- return varName + " = " + valParamName +
".truncatedTo(java.time.temporal.ChronoUnit.MILLIS);";
- }
-
- @Override
public LocalTime fromInt(Integer millisFromMidnight, Schema schema,
LogicalType type) {
- return
LocalTime.ofNanoOfDay(TimeUnit.MILLISECONDS.toNanos(millisFromMidnight));
+ return LocalTime.fromMillisOfDay(millisFromMidnight);
}
@Override
public Integer toInt(LocalTime time, Schema schema, LogicalType type) {
- return (int) TimeUnit.NANOSECONDS.toMillis(time.toNanoOfDay());
+ return time.millisOfDay().get();
}
@Override
@@ -103,18 +102,8 @@ public class Jsr310TimeConversions {
}
@Override
- public String adjustAndSetValue(String varName, String valParamName) {
- return varName + " = " + valParamName +
".truncatedTo(java.time.temporal.ChronoUnit.MICROS);";
- }
-
- @Override
public LocalTime fromLong(Long microsFromMidnight, Schema schema,
LogicalType type) {
- return
LocalTime.ofNanoOfDay(TimeUnit.MICROSECONDS.toNanos(microsFromMidnight));
- }
-
- @Override
- public Long toLong(LocalTime time, Schema schema, LogicalType type) {
- return TimeUnit.NANOSECONDS.toMicros(time.toNanoOfDay());
+ return LocalTime.fromMillisOfDay(microsFromMidnight / 1000);
}
@Override
@@ -123,30 +112,32 @@ public class Jsr310TimeConversions {
}
}
- public static class TimestampMillisConversion extends Conversion<Instant> {
+ public static class LossyTimeMicrosConversion extends TimeMicrosConversion {
@Override
- public Class<Instant> getConvertedType() {
- return Instant.class;
+ public Long toLong(LocalTime time, Schema schema, LogicalType type) {
+ return 1000 * (long) time.millisOfDay().get();
}
+ }
+ public static class TimestampConversion extends Conversion<DateTime> {
@Override
- public String getLogicalTypeName() {
- return "timestamp-millis";
+ public Class<DateTime> getConvertedType() {
+ return DateTime.class;
}
@Override
- public String adjustAndSetValue(String varName, String valParamName) {
- return varName + " = " + valParamName +
".truncatedTo(java.time.temporal.ChronoUnit.MILLIS);";
+ public String getLogicalTypeName() {
+ return "timestamp-millis";
}
@Override
- public Instant fromLong(Long millisFromEpoch, Schema schema, LogicalType
type) {
- return Instant.ofEpochMilli(millisFromEpoch);
+ public DateTime fromLong(Long millisFromEpoch, Schema schema, LogicalType
type) {
+ return new DateTime(millisFromEpoch, DateTimeZone.UTC);
}
@Override
- public Long toLong(Instant timestamp, Schema schema, LogicalType type) {
- return timestamp.toEpochMilli();
+ public Long toLong(DateTime timestamp, Schema schema, LogicalType type) {
+ return timestamp.getMillis();
}
@Override
@@ -155,10 +146,10 @@ public class Jsr310TimeConversions {
}
}
- public static class TimestampMicrosConversion extends Conversion<Instant> {
+ public static class TimestampMicrosConversion extends Conversion<DateTime> {
@Override
- public Class<Instant> getConvertedType() {
- return Instant.class;
+ public Class<DateTime> getConvertedType() {
+ return DateTime.class;
}
@Override
@@ -167,38 +158,20 @@ public class Jsr310TimeConversions {
}
@Override
- public String adjustAndSetValue(String varName, String valParamName) {
- return varName + " = " + valParamName +
".truncatedTo(java.time.temporal.ChronoUnit.MICROS);";
- }
-
- @Override
- public Instant fromLong(Long microsFromEpoch, Schema schema, LogicalType
type) {
- long epochSeconds = microsFromEpoch / (1_000_000);
- long nanoAdjustment = (microsFromEpoch % (1_000_000)) * 1_000;
-
- return Instant.ofEpochSecond(epochSeconds, nanoAdjustment);
+ public DateTime fromLong(Long microsFromEpoch, Schema schema, LogicalType
type) {
+ return new DateTime(microsFromEpoch / 1000, DateTimeZone.UTC);
}
@Override
- public Long toLong(Instant instant, Schema schema, LogicalType type) {
- long seconds = instant.getEpochSecond();
- int nanos = instant.getNano();
-
- if (seconds < 0 && nanos > 0) {
- long micros = Math.multiplyExact(seconds + 1, 1_000_000);
- long adjustment = (nanos / 1_000L) - 1_000_000;
-
- return Math.addExact(micros, adjustment);
- } else {
- long micros = Math.multiplyExact(seconds, 1_000_000);
-
- return Math.addExact(micros, nanos / 1_000);
- }
+ public Schema getRecommendedSchema() {
+ return
LogicalTypes.timestampMicros().addToSchema(Schema.create(Schema.Type.LONG));
}
+ }
+ public static class LossyTimestampMicrosConversion extends
TimestampMicrosConversion {
@Override
- public Schema getRecommendedSchema() {
- return
LogicalTypes.timestampMicros().addToSchema(Schema.create(Schema.Type.LONG));
+ public Long toLong(DateTime timestamp, Schema schema, LogicalType type) {
+ return 1000 * timestamp.getMillis();
}
}
}
diff --git
a/lang/java/avro/src/main/java/org/apache/avro/data/TimeConversions.java
b/lang/java/avro/src/main/java/org/apache/avro/data/TimeConversions.java
index a84a95a..b20aa8b 100644
--- a/lang/java/avro/src/main/java/org/apache/avro/data/TimeConversions.java
+++ b/lang/java/avro/src/main/java/org/apache/avro/data/TimeConversions.java
@@ -22,15 +22,14 @@ 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;
+
+import java.time.Instant;
+import java.time.LocalDate;
+import java.time.LocalTime;
+import java.util.concurrent.TimeUnit;
public class TimeConversions {
public static class DateConversion extends Conversion<LocalDate> {
- private static final LocalDate EPOCH_DATE = new LocalDate(1970, 1, 1);
@Override
public Class<LocalDate> getConvertedType() {
@@ -44,12 +43,14 @@ public class TimeConversions {
@Override
public LocalDate fromInt(Integer daysFromEpoch, Schema schema, LogicalType
type) {
- return EPOCH_DATE.plusDays(daysFromEpoch);
+ return LocalDate.ofEpochDay(daysFromEpoch);
}
@Override
public Integer toInt(LocalDate date, Schema schema, LogicalType type) {
- return Days.daysBetween(EPOCH_DATE, date).getDays();
+ long epochDays = date.toEpochDay();
+
+ return (int) epochDays;
}
@Override
@@ -58,7 +59,7 @@ public class TimeConversions {
}
}
- public static class TimeConversion extends Conversion<LocalTime> {
+ public static class TimeMillisConversion extends Conversion<LocalTime> {
@Override
public Class<LocalTime> getConvertedType() {
return LocalTime.class;
@@ -70,13 +71,18 @@ public class TimeConversions {
}
@Override
+ public String adjustAndSetValue(String varName, String valParamName) {
+ return varName + " = " + valParamName +
".truncatedTo(java.time.temporal.ChronoUnit.MILLIS);";
+ }
+
+ @Override
public LocalTime fromInt(Integer millisFromMidnight, Schema schema,
LogicalType type) {
- return LocalTime.fromMillisOfDay(millisFromMidnight);
+ return
LocalTime.ofNanoOfDay(TimeUnit.MILLISECONDS.toNanos(millisFromMidnight));
}
@Override
public Integer toInt(LocalTime time, Schema schema, LogicalType type) {
- return time.millisOfDay().get();
+ return (int) TimeUnit.NANOSECONDS.toMillis(time.toNanoOfDay());
}
@Override
@@ -97,27 +103,30 @@ public class TimeConversions {
}
@Override
- public LocalTime fromLong(Long microsFromMidnight, Schema schema,
LogicalType type) {
- return LocalTime.fromMillisOfDay(microsFromMidnight / 1000);
+ public String adjustAndSetValue(String varName, String valParamName) {
+ return varName + " = " + valParamName +
".truncatedTo(java.time.temporal.ChronoUnit.MICROS);";
}
@Override
- public Schema getRecommendedSchema() {
- return
LogicalTypes.timeMicros().addToSchema(Schema.create(Schema.Type.LONG));
+ public LocalTime fromLong(Long microsFromMidnight, Schema schema,
LogicalType type) {
+ return
LocalTime.ofNanoOfDay(TimeUnit.MICROSECONDS.toNanos(microsFromMidnight));
}
- }
- public static class LossyTimeMicrosConversion extends TimeMicrosConversion {
@Override
public Long toLong(LocalTime time, Schema schema, LogicalType type) {
- return 1000 * (long) time.millisOfDay().get();
+ return TimeUnit.NANOSECONDS.toMicros(time.toNanoOfDay());
+ }
+
+ @Override
+ public Schema getRecommendedSchema() {
+ return
LogicalTypes.timeMicros().addToSchema(Schema.create(Schema.Type.LONG));
}
}
- public static class TimestampConversion extends Conversion<DateTime> {
+ public static class TimestampMillisConversion extends Conversion<Instant> {
@Override
- public Class<DateTime> getConvertedType() {
- return DateTime.class;
+ public Class<Instant> getConvertedType() {
+ return Instant.class;
}
@Override
@@ -126,13 +135,18 @@ public class TimeConversions {
}
@Override
- public DateTime fromLong(Long millisFromEpoch, Schema schema, LogicalType
type) {
- return new DateTime(millisFromEpoch, DateTimeZone.UTC);
+ public String adjustAndSetValue(String varName, String valParamName) {
+ return varName + " = " + valParamName +
".truncatedTo(java.time.temporal.ChronoUnit.MILLIS);";
}
@Override
- public Long toLong(DateTime timestamp, Schema schema, LogicalType type) {
- return timestamp.getMillis();
+ public Instant fromLong(Long millisFromEpoch, Schema schema, LogicalType
type) {
+ return Instant.ofEpochMilli(millisFromEpoch);
+ }
+
+ @Override
+ public Long toLong(Instant timestamp, Schema schema, LogicalType type) {
+ return timestamp.toEpochMilli();
}
@Override
@@ -141,10 +155,10 @@ public class TimeConversions {
}
}
- public static class TimestampMicrosConversion extends Conversion<DateTime> {
+ public static class TimestampMicrosConversion extends Conversion<Instant> {
@Override
- public Class<DateTime> getConvertedType() {
- return DateTime.class;
+ public Class<Instant> getConvertedType() {
+ return Instant.class;
}
@Override
@@ -153,20 +167,38 @@ public class TimeConversions {
}
@Override
- public DateTime fromLong(Long microsFromEpoch, Schema schema, LogicalType
type) {
- return new DateTime(microsFromEpoch / 1000, DateTimeZone.UTC);
+ public String adjustAndSetValue(String varName, String valParamName) {
+ return varName + " = " + valParamName +
".truncatedTo(java.time.temporal.ChronoUnit.MICROS);";
}
@Override
- public Schema getRecommendedSchema() {
- return
LogicalTypes.timestampMicros().addToSchema(Schema.create(Schema.Type.LONG));
+ public Instant fromLong(Long microsFromEpoch, Schema schema, LogicalType
type) {
+ long epochSeconds = microsFromEpoch / (1_000_000);
+ long nanoAdjustment = (microsFromEpoch % (1_000_000)) * 1_000;
+
+ return Instant.ofEpochSecond(epochSeconds, nanoAdjustment);
}
- }
- public static class LossyTimestampMicrosConversion extends
TimestampMicrosConversion {
@Override
- public Long toLong(DateTime timestamp, Schema schema, LogicalType type) {
- return 1000 * timestamp.getMillis();
+ public Long toLong(Instant instant, Schema schema, LogicalType type) {
+ long seconds = instant.getEpochSecond();
+ int nanos = instant.getNano();
+
+ if (seconds < 0 && nanos > 0) {
+ long micros = Math.multiplyExact(seconds + 1, 1_000_000);
+ long adjustment = (nanos / 1_000L) - 1_000_000;
+
+ return Math.addExact(micros, adjustment);
+ } else {
+ long micros = Math.multiplyExact(seconds, 1_000_000);
+
+ return Math.addExact(micros, nanos / 1_000);
+ }
+ }
+
+ @Override
+ public Schema getRecommendedSchema() {
+ return
LogicalTypes.timestampMicros().addToSchema(Schema.create(Schema.Type.LONG));
}
}
}
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/TestJodaTimeConversions.java
similarity index 91%
copy from
lang/java/avro/src/test/java/org/apache/avro/data/TestTimeConversions.java
copy to
lang/java/avro/src/test/java/org/apache/avro/data/TestJodaTimeConversions.java
index 9dee1ab..b17fd1b 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/TestJodaTimeConversions.java
@@ -23,7 +23,7 @@ import java.util.Date;
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.data.JodaTimeConversions.*;
import org.apache.avro.reflect.ReflectData;
import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
@@ -33,7 +33,7 @@ import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
-public class TestTimeConversions {
+public class TestJodaTimeConversions {
public static Schema DATE_SCHEMA;
public static Schema TIME_MILLIS_SCHEMA;
@@ -43,12 +43,12 @@ public class TestTimeConversions {
@BeforeClass
public static void createSchemas() {
- TestTimeConversions.DATE_SCHEMA =
LogicalTypes.date().addToSchema(Schema.create(Schema.Type.INT));
- TestTimeConversions.TIME_MILLIS_SCHEMA =
LogicalTypes.timeMillis().addToSchema(Schema.create(Schema.Type.INT));
- TestTimeConversions.TIME_MICROS_SCHEMA =
LogicalTypes.timeMicros().addToSchema(Schema.create(Schema.Type.LONG));
- TestTimeConversions.TIMESTAMP_MILLIS_SCHEMA =
LogicalTypes.timestampMillis()
+ 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));
- TestTimeConversions.TIMESTAMP_MICROS_SCHEMA =
LogicalTypes.timestampMicros()
+ TestJodaTimeConversions.TIMESTAMP_MICROS_SCHEMA =
LogicalTypes.timestampMicros()
.addToSchema(Schema.create(Schema.Type.LONG));
}
@@ -193,37 +193,39 @@ public class TestTimeConversions {
}
/*
- * model.addLogicalTypeConversion(new
TimeConversions.TimeMicrosConversion());
* model.addLogicalTypeConversion(new
- * TimeConversions.TimestampMicrosConversion());
+ * JodaTimeConversions.TimeMicrosConversion());
+ * model.addLogicalTypeConversion(new
+ * JodaTimeConversions.TimestampMicrosConversion());
*/
@Test
public void testDynamicSchemaWithDateConversion() throws
ClassNotFoundException {
- Schema schema = getReflectedSchemaByName("org.joda.time.LocalDate", new
TimeConversions.DateConversion());
+ 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
TimeConversions.TimeConversion());
+ 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
TimeConversions.TimeMicrosConversion());
+ 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
TimeConversions.TimestampConversion());
+ 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
TimeConversions.TimestampMicrosConversion());
+ Schema schema = getReflectedSchemaByName("org.joda.time.DateTime",
+ new JodaTimeConversions.TimestampMicrosConversion());
Assert.assertEquals("Reflected schema should be logicalType
timestampMicros", TIMESTAMP_MICROS_SCHEMA, schema);
}
diff --git
a/lang/java/avro/src/test/java/org/apache/avro/data/TestJsr310TimeConversions.java
b/lang/java/avro/src/test/java/org/apache/avro/data/TestJsr310TimeConversions.java
deleted file mode 100644
index c11b6e4..0000000
---
a/lang/java/avro/src/test/java/org/apache/avro/data/TestJsr310TimeConversions.java
+++ /dev/null
@@ -1,185 +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
- *
- * http://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.time.*;
-
-import org.apache.avro.LogicalTypes;
-import org.apache.avro.Schema;
-import org.apache.avro.data.Jsr310TimeConversions.*;
-import org.junit.Assert;
-import org.junit.BeforeClass;
-import org.junit.Test;
-
-public class TestJsr310TimeConversions {
-
- 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() {
- TestJsr310TimeConversions.DATE_SCHEMA =
LogicalTypes.date().addToSchema(Schema.create(Schema.Type.INT));
- TestJsr310TimeConversions.TIME_MILLIS_SCHEMA = LogicalTypes.timeMillis()
- .addToSchema(Schema.create(Schema.Type.INT));
- TestJsr310TimeConversions.TIME_MICROS_SCHEMA = LogicalTypes.timeMicros()
- .addToSchema(Schema.create(Schema.Type.LONG));
- TestJsr310TimeConversions.TIMESTAMP_MILLIS_SCHEMA =
LogicalTypes.timestampMillis()
- .addToSchema(Schema.create(Schema.Type.LONG));
- TestJsr310TimeConversions.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 = LocalDate.of(1970, 1, 6); // 5
- LocalDate Jan_1_1970 = LocalDate.of(1970, 1, 1); // 0
- LocalDate Dec_27_1969 = LocalDate.of(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 {
- TimeMillisConversion conversion = new TimeMillisConversion();
- LocalTime oneAM = LocalTime.of(1, 0);
- LocalTime afternoon = LocalTime.of(15, 14, 15, 926_000_000);
- 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", 3_600_000,
- (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 = LocalTime.of(1, 0);
- LocalTime afternoon = LocalTime.of(15, 14, 15, 926_551_000);
- long afternoonMicros = ((long) (15 * 60 + 14) * 60 + 15) * 1_000_000 +
926_551;
-
- 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(3_600_000_000L, TIME_MICROS_SCHEMA,
LogicalTypes.timeMicros()));
- Assert.assertEquals("15:14:15.926551 should be " + afternoonMicros,
afternoon,
- conversion.fromLong(afternoonMicros, TIME_MICROS_SCHEMA,
LogicalTypes.timeMicros()));
-
- 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", 3_600_000_000L,
- (long) conversion.toLong(oneAM, TIME_MICROS_SCHEMA,
LogicalTypes.timeMicros()));
- Assert.assertEquals("15:14:15.926551 should be " + afternoonMicros,
afternoonMicros,
- (long) conversion.toLong(afternoon, TIME_MICROS_SCHEMA,
LogicalTypes.timeMicros()));
- }
-
- @Test
- public void testTimestampMillisConversion() throws Exception {
- TimestampMillisConversion conversion = new TimestampMillisConversion();
- long nowInstant = Instant.now().toEpochMilli(); // ms precision
-
- // round trip
- Instant 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;
- Instant May_28_2015_21_46_53_221 = ZonedDateTime.of(2015, 5, 28, 21, 46,
53, 221_000_000, ZoneOffset.UTC)
- .toInstant();
-
- // known dates from https://www.epochconverter.com/
- // > Epoch
- 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()));
-
- // Epoch
- Assert.assertEquals("1970-01-01 should be 0", Instant.EPOCH,
- conversion.fromLong(0L, TIMESTAMP_MILLIS_SCHEMA,
LogicalTypes.timestampMillis()));
- Assert.assertEquals("1970-01-01 should be 0", 0L,
- (long) conversion.toLong(ZonedDateTime.ofInstant(Instant.EPOCH,
ZoneOffset.UTC).toInstant(),
- TIMESTAMP_MILLIS_SCHEMA, LogicalTypes.timestampMillis()));
-
- // < Epoch
- long Jul_01_1969_12_00_00_123_instant = -15854400000L + 123;
- Instant Jul_01_1969_12_00_00_123 = ZonedDateTime.of(1969, 7, 1, 12, 0, 0,
123_000_000, ZoneOffset.UTC).toInstant();
-
- Assert.assertEquals("Pre 1970 date should be correct",
Jul_01_1969_12_00_00_123,
- conversion.fromLong(Jul_01_1969_12_00_00_123_instant,
TIMESTAMP_MILLIS_SCHEMA, LogicalTypes.timestampMillis()));
- Assert.assertEquals("Pre 1970 date should be correct",
Jul_01_1969_12_00_00_123_instant,
- (long) conversion.toLong(Jul_01_1969_12_00_00_123,
TIMESTAMP_MILLIS_SCHEMA, LogicalTypes.timestampMillis()));
- }
-
- @Test
- public void testTimestampMicrosConversion() throws Exception {
- TimestampMicrosConversion conversion = new TimestampMicrosConversion();
-
- // known dates from https://www.epochconverter.com/
- // > Epoch
- long May_28_2015_21_46_53_221_843_instant = 1432849613221L * 1000 + 843;
- Instant May_28_2015_21_46_53_221_843 = ZonedDateTime.of(2015, 5, 28, 21,
46, 53, 221_843_000, ZoneOffset.UTC)
- .toInstant();
-
- Assert.assertEquals("Known date should be correct",
May_28_2015_21_46_53_221_843, conversion
- .fromLong(May_28_2015_21_46_53_221_843_instant,
TIMESTAMP_MICROS_SCHEMA, LogicalTypes.timestampMicros()));
-
- Assert.assertEquals("Known date should be correct",
May_28_2015_21_46_53_221_843_instant, (long) conversion
- .toLong(May_28_2015_21_46_53_221_843, TIMESTAMP_MICROS_SCHEMA,
LogicalTypes.timestampMillis()));
-
- // Epoch
- Assert.assertEquals("1970-01-01 should be 0", Instant.EPOCH,
- conversion.fromLong(0L, TIMESTAMP_MILLIS_SCHEMA,
LogicalTypes.timestampMillis()));
- Assert.assertEquals("1970-01-01 should be 0", 0L,
- (long) conversion.toLong(ZonedDateTime.ofInstant(Instant.EPOCH,
ZoneOffset.UTC).toInstant(),
- TIMESTAMP_MILLIS_SCHEMA, LogicalTypes.timestampMillis()));
-
- // < Epoch
- long Jul_01_1969_12_00_00_000_123_instant = -15854400000L * 1000 + 123;
- Instant Jul_01_1969_12_00_00_000_123 = ZonedDateTime.of(1969, 7, 1, 12, 0,
0, 123_000, ZoneOffset.UTC).toInstant();
-
- Assert.assertEquals("Pre 1970 date should be correct",
Jul_01_1969_12_00_00_000_123, conversion
- .fromLong(Jul_01_1969_12_00_00_000_123_instant,
TIMESTAMP_MILLIS_SCHEMA, LogicalTypes.timestampMillis()));
- 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()));
- }
-}
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 9dee1ab..a5f7a36 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
@@ -18,17 +18,11 @@
package org.apache.avro.data;
-import java.util.Date;
+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.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;
@@ -55,9 +49,9 @@ public class TestTimeConversions {
@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
+ LocalDate Jan_6_1970 = LocalDate.of(1970, 1, 6); // 5
+ LocalDate Jan_1_1970 = LocalDate.of(1970, 1, 1); // 0
+ LocalDate Dec_27_1969 = LocalDate.of(1969, 12, 27); // -5
Assert.assertEquals("6 Jan 1970 should be 5", 5,
(int) conversion.toInt(Jan_6_1970, DATE_SCHEMA, LogicalTypes.date()));
@@ -74,14 +68,14 @@ public class TestTimeConversions {
@Test
public void testTimeMillisConversion() throws Exception {
- TimeConversion conversion = new TimeConversion();
- LocalTime oneAM = new LocalTime(1, 0);
- LocalTime afternoon = new LocalTime(15, 14, 15, 926);
+ TimeMillisConversion conversion = new TimeMillisConversion();
+ LocalTime oneAM = LocalTime.of(1, 0);
+ LocalTime afternoon = LocalTime.of(15, 14, 15, 926_000_000);
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,
+ Assert.assertEquals("01:00 should be 3,600,000", 3_600_000,
(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()));
@@ -97,147 +91,93 @@ public class TestTimeConversions {
@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;
+ LocalTime oneAM = LocalTime.of(1, 0);
+ LocalTime afternoon = LocalTime.of(15, 14, 15, 926_551_000);
+ long afternoonMicros = ((long) (15 * 60 + 14) * 60 + 15) * 1_000_000 +
926_551;
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(3_600_000_000L, TIME_MICROS_SCHEMA,
LogicalTypes.timeMicros()));
+ Assert.assertEquals("15:14:15.926551 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,
+ Assert.assertEquals("01:00 should be 3,600,000,000", 3_600_000_000L,
(long) conversion.toLong(oneAM, TIME_MICROS_SCHEMA,
LogicalTypes.timeMicros()));
- Assert.assertEquals("15:14:15.926551 should be " + afternoonMicros,
dropMicros(afternoonMicros), // loses precision!
+ Assert.assertEquals("15:14:15.926551 should be " + afternoonMicros,
afternoonMicros,
(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();
+ TimestampMillisConversion conversion = new TimestampMillisConversion();
+ long nowInstant = Instant.now().toEpochMilli(); // ms precision
- DateTime now = conversion.fromLong(nowInstant, TIMESTAMP_MILLIS_SCHEMA,
LogicalTypes.timestampMillis());
+ // round trip
+ Instant 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);
+ Instant May_28_2015_21_46_53_221 = ZonedDateTime.of(2015, 5, 28, 21, 46,
53, 221_000_000, ZoneOffset.UTC)
+ .toInstant();
+ // known dates from https://www.epochconverter.com/
+ // > Epoch
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()));
+
+ // Epoch
+ Assert.assertEquals("1970-01-01 should be 0", Instant.EPOCH,
+ conversion.fromLong(0L, TIMESTAMP_MILLIS_SCHEMA,
LogicalTypes.timestampMillis()));
+ Assert.assertEquals("1970-01-01 should be 0", 0L,
+ (long) conversion.toLong(ZonedDateTime.ofInstant(Instant.EPOCH,
ZoneOffset.UTC).toInstant(),
+ TIMESTAMP_MILLIS_SCHEMA, LogicalTypes.timestampMillis()));
+
+ // < Epoch
+ long Jul_01_1969_12_00_00_123_instant = -15854400000L + 123;
+ Instant Jul_01_1969_12_00_00_123 = ZonedDateTime.of(1969, 7, 1, 12, 0, 0,
123_000_000, ZoneOffset.UTC).toInstant();
+
+ Assert.assertEquals("Pre 1970 date should be correct",
Jul_01_1969_12_00_00_123,
+ conversion.fromLong(Jul_01_1969_12_00_00_123_instant,
TIMESTAMP_MILLIS_SCHEMA, LogicalTypes.timestampMillis()));
+ Assert.assertEquals("Pre 1970 date should be correct",
Jul_01_1969_12_00_00_123_instant,
+ (long) conversion.toLong(Jul_01_1969_12_00_00_123,
TIMESTAMP_MILLIS_SCHEMA, LogicalTypes.timestampMillis()));
}
@Test
public void testTimestampMicrosConversion() throws Exception {
TimestampMicrosConversion conversion = new TimestampMicrosConversion();
+ // known dates from https://www.epochconverter.com/
+ // > Epoch
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);
+ Instant May_28_2015_21_46_53_221_843 = ZonedDateTime.of(2015, 5, 28, 21,
46, 53, 221_843_000, ZoneOffset.UTC)
+ .toInstant();
- Assert.assertEquals("Known date should be correct",
May_28_2015_21_46_53_221, conversion
+ Assert.assertEquals("Known date should be correct",
May_28_2015_21_46_53_221_843, 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);
+ Assert.assertEquals("Known date should be correct",
May_28_2015_21_46_53_221_843_instant, (long) conversion
+ .toLong(May_28_2015_21_46_53_221_843, TIMESTAMP_MICROS_SCHEMA,
LogicalTypes.timestampMillis()));
- 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()));
- }
+ // Epoch
+ Assert.assertEquals("1970-01-01 should be 0", Instant.EPOCH,
+ conversion.fromLong(0L, TIMESTAMP_MILLIS_SCHEMA,
LogicalTypes.timestampMillis()));
+ Assert.assertEquals("1970-01-01 should be 0", 0L,
+ (long) conversion.toLong(ZonedDateTime.ofInstant(Instant.EPOCH,
ZoneOffset.UTC).toInstant(),
+ TIMESTAMP_MILLIS_SCHEMA, LogicalTypes.timestampMillis()));
- /*
- * model.addLogicalTypeConversion(new
TimeConversions.TimeMicrosConversion());
- * model.addLogicalTypeConversion(new
- * TimeConversions.TimestampMicrosConversion());
- */
- @Test
- public void testDynamicSchemaWithDateConversion() throws
ClassNotFoundException {
- Schema schema = getReflectedSchemaByName("org.joda.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("org.joda.time.LocalTime", new
TimeConversions.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
TimeConversions.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
TimeConversions.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
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);
- }
+ // < Epoch
+ long Jul_01_1969_12_00_00_000_123_instant = -15854400000L * 1000 + 123;
+ Instant Jul_01_1969_12_00_00_000_123 = ZonedDateTime.of(1969, 7, 1, 12, 0,
0, 123_000, ZoneOffset.UTC).toInstant();
- private long dropMicros(long micros) {
- return micros / 1000 * 1000;
+ Assert.assertEquals("Pre 1970 date should be correct",
Jul_01_1969_12_00_00_000_123, conversion
+ .fromLong(Jul_01_1969_12_00_00_000_123_instant,
TIMESTAMP_MILLIS_SCHEMA, LogicalTypes.timestampMillis()));
+ 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()));
}
}
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
index bf21cd8..7abcb0b 100644
---
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
@@ -5,6 +5,7 @@
*/
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;
@@ -39,7 +40,7 @@ public class TestRecordWithJsr310LogicalTypes extends
org.apache.avro.specific.S
/**
* 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<TestRecordWithJsr310LogicalTypes>
createDecoder(SchemaStore resolver) {
@@ -87,7 +88,7 @@ public class TestRecordWithJsr310LogicalTypes extends
org.apache.avro.specific.S
/**
* All-args constructor.
- *
+ *
* @param b The new value for b
* @param i32 The new value for i32
* @param i64 The new value for i64
@@ -149,9 +150,9 @@ public class TestRecordWithJsr310LogicalTypes extends
org.apache.avro.specific.S
}
protected static final org.apache.avro.Conversions.DecimalConversion
DECIMAL_CONVERSION = new org.apache.avro.Conversions.DecimalConversion();
- protected static final
org.apache.avro.data.Jsr310TimeConversions.DateConversion DATE_CONVERSION = new
org.apache.avro.data.Jsr310TimeConversions.DateConversion();
- protected static final
org.apache.avro.data.Jsr310TimeConversions.TimeMillisConversion TIME_CONVERSION
= new org.apache.avro.data.Jsr310TimeConversions.TimeMillisConversion();
- protected static final
org.apache.avro.data.Jsr310TimeConversions.TimestampMillisConversion
TIMESTAMP_CONVERSION = new
org.apache.avro.data.Jsr310TimeConversions.TimestampMillisConversion();
+ 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 };
@@ -203,7 +204,7 @@ public class TestRecordWithJsr310LogicalTypes extends
org.apache.avro.specific.S
/**
* Gets the value of the 'b' field.
- *
+ *
* @return The value of the 'b' field.
*/
public java.lang.Boolean getB() {
@@ -212,7 +213,7 @@ public class TestRecordWithJsr310LogicalTypes extends
org.apache.avro.specific.S
/**
* Sets the value of the 'b' field.
- *
+ *
* @param value the value to set.
*/
public void setB(java.lang.Boolean value) {
@@ -221,7 +222,7 @@ public class TestRecordWithJsr310LogicalTypes extends
org.apache.avro.specific.S
/**
* Gets the value of the 'i32' field.
- *
+ *
* @return The value of the 'i32' field.
*/
public java.lang.Integer getI32() {
@@ -230,7 +231,7 @@ public class TestRecordWithJsr310LogicalTypes extends
org.apache.avro.specific.S
/**
* Sets the value of the 'i32' field.
- *
+ *
* @param value the value to set.
*/
public void setI32(java.lang.Integer value) {
@@ -239,7 +240,7 @@ public class TestRecordWithJsr310LogicalTypes extends
org.apache.avro.specific.S
/**
* Gets the value of the 'i64' field.
- *
+ *
* @return The value of the 'i64' field.
*/
public java.lang.Long getI64() {
@@ -248,7 +249,7 @@ public class TestRecordWithJsr310LogicalTypes extends
org.apache.avro.specific.S
/**
* Sets the value of the 'i64' field.
- *
+ *
* @param value the value to set.
*/
public void setI64(java.lang.Long value) {
@@ -257,7 +258,7 @@ public class TestRecordWithJsr310LogicalTypes extends
org.apache.avro.specific.S
/**
* Gets the value of the 'f32' field.
- *
+ *
* @return The value of the 'f32' field.
*/
public java.lang.Float getF32() {
@@ -266,7 +267,7 @@ public class TestRecordWithJsr310LogicalTypes extends
org.apache.avro.specific.S
/**
* Sets the value of the 'f32' field.
- *
+ *
* @param value the value to set.
*/
public void setF32(java.lang.Float value) {
@@ -275,7 +276,7 @@ public class TestRecordWithJsr310LogicalTypes extends
org.apache.avro.specific.S
/**
* Gets the value of the 'f64' field.
- *
+ *
* @return The value of the 'f64' field.
*/
public java.lang.Double getF64() {
@@ -284,7 +285,7 @@ public class TestRecordWithJsr310LogicalTypes extends
org.apache.avro.specific.S
/**
* Sets the value of the 'f64' field.
- *
+ *
* @param value the value to set.
*/
public void setF64(java.lang.Double value) {
@@ -293,7 +294,7 @@ public class TestRecordWithJsr310LogicalTypes extends
org.apache.avro.specific.S
/**
* Gets the value of the 's' field.
- *
+ *
* @return The value of the 's' field.
*/
public java.lang.CharSequence getS() {
@@ -302,7 +303,7 @@ public class TestRecordWithJsr310LogicalTypes extends
org.apache.avro.specific.S
/**
* Sets the value of the 's' field.
- *
+ *
* @param value the value to set.
*/
public void setS(java.lang.CharSequence value) {
@@ -311,7 +312,7 @@ public class TestRecordWithJsr310LogicalTypes extends
org.apache.avro.specific.S
/**
* Gets the value of the 'd' field.
- *
+ *
* @return The value of the 'd' field.
*/
public java.time.LocalDate getD() {
@@ -320,7 +321,7 @@ public class TestRecordWithJsr310LogicalTypes extends
org.apache.avro.specific.S
/**
* Sets the value of the 'd' field.
- *
+ *
* @param value the value to set.
*/
public void setD(java.time.LocalDate value) {
@@ -329,7 +330,7 @@ public class TestRecordWithJsr310LogicalTypes extends
org.apache.avro.specific.S
/**
* Gets the value of the 't' field.
- *
+ *
* @return The value of the 't' field.
*/
public java.time.LocalTime getT() {
@@ -338,7 +339,7 @@ public class TestRecordWithJsr310LogicalTypes extends
org.apache.avro.specific.S
/**
* Sets the value of the 't' field.
- *
+ *
* @param value the value to set.
*/
public void setT(java.time.LocalTime value) {
@@ -347,7 +348,7 @@ public class TestRecordWithJsr310LogicalTypes extends
org.apache.avro.specific.S
/**
* Gets the value of the 'ts' field.
- *
+ *
* @return The value of the 'ts' field.
*/
public java.time.Instant getTs() {
@@ -356,7 +357,7 @@ public class TestRecordWithJsr310LogicalTypes extends
org.apache.avro.specific.S
/**
* Sets the value of the 'ts' field.
- *
+ *
* @param value the value to set.
*/
public void setTs(java.time.Instant value) {
@@ -365,7 +366,7 @@ public class TestRecordWithJsr310LogicalTypes extends
org.apache.avro.specific.S
/**
* Gets the value of the 'dec' field.
- *
+ *
* @return The value of the 'dec' field.
*/
public java.math.BigDecimal getDec() {
@@ -374,7 +375,7 @@ public class TestRecordWithJsr310LogicalTypes extends
org.apache.avro.specific.S
/**
* Sets the value of the 'dec' field.
- *
+ *
* @param value the value to set.
*/
public void setDec(java.math.BigDecimal value) {
@@ -383,7 +384,7 @@ public class TestRecordWithJsr310LogicalTypes extends
org.apache.avro.specific.S
/**
* Creates a new TestRecordWithJsr310LogicalTypes RecordBuilder.
- *
+ *
* @return A new TestRecordWithJsr310LogicalTypes RecordBuilder
*/
public static TestRecordWithJsr310LogicalTypes.Builder newBuilder() {
@@ -393,7 +394,7 @@ public class TestRecordWithJsr310LogicalTypes extends
org.apache.avro.specific.S
/**
* Creates a new TestRecordWithJsr310LogicalTypes RecordBuilder by copying an
* existing Builder.
- *
+ *
* @param other The existing builder to copy.
* @return A new TestRecordWithJsr310LogicalTypes RecordBuilder
*/
@@ -408,7 +409,7 @@ public class TestRecordWithJsr310LogicalTypes extends
org.apache.avro.specific.S
/**
* Creates a new TestRecordWithJsr310LogicalTypes RecordBuilder by copying an
* existing TestRecordWithJsr310LogicalTypes instance.
- *
+ *
* @param other The existing instance to copy.
* @return A new TestRecordWithJsr310LogicalTypes RecordBuilder
*/
@@ -445,7 +446,7 @@ public class TestRecordWithJsr310LogicalTypes extends
org.apache.avro.specific.S
/**
* Creates a Builder by copying an existing Builder.
- *
+ *
* @param other The existing Builder to copy.
*/
private Builder(TestRecordWithJsr310LogicalTypes.Builder other) {
@@ -495,7 +496,7 @@ public class TestRecordWithJsr310LogicalTypes extends
org.apache.avro.specific.S
/**
* Creates a Builder by copying an existing
TestRecordWithJsr310LogicalTypes
* instance
- *
+ *
* @param other The existing instance to copy.
*/
private Builder(TestRecordWithJsr310LogicalTypes other) {
@@ -544,7 +545,7 @@ public class TestRecordWithJsr310LogicalTypes extends
org.apache.avro.specific.S
/**
* Gets the value of the 'b' field.
- *
+ *
* @return The value.
*/
public java.lang.Boolean getB() {
@@ -553,7 +554,7 @@ public class TestRecordWithJsr310LogicalTypes extends
org.apache.avro.specific.S
/**
* Sets the value of the 'b' field.
- *
+ *
* @param value The value of 'b'.
* @return This builder.
*/
@@ -566,7 +567,7 @@ public class TestRecordWithJsr310LogicalTypes extends
org.apache.avro.specific.S
/**
* Checks whether the 'b' field has been set.
- *
+ *
* @return True if the 'b' field has been set, false otherwise.
*/
public boolean hasB() {
@@ -575,7 +576,7 @@ public class TestRecordWithJsr310LogicalTypes extends
org.apache.avro.specific.S
/**
* Clears the value of the 'b' field.
- *
+ *
* @return This builder.
*/
public TestRecordWithJsr310LogicalTypes.Builder clearB() {
@@ -585,7 +586,7 @@ public class TestRecordWithJsr310LogicalTypes extends
org.apache.avro.specific.S
/**
* Gets the value of the 'i32' field.
- *
+ *
* @return The value.
*/
public java.lang.Integer getI32() {
@@ -594,7 +595,7 @@ public class TestRecordWithJsr310LogicalTypes extends
org.apache.avro.specific.S
/**
* Sets the value of the 'i32' field.
- *
+ *
* @param value The value of 'i32'.
* @return This builder.
*/
@@ -607,7 +608,7 @@ public class TestRecordWithJsr310LogicalTypes extends
org.apache.avro.specific.S
/**
* Checks whether the 'i32' field has been set.
- *
+ *
* @return True if the 'i32' field has been set, false otherwise.
*/
public boolean hasI32() {
@@ -616,7 +617,7 @@ public class TestRecordWithJsr310LogicalTypes extends
org.apache.avro.specific.S
/**
* Clears the value of the 'i32' field.
- *
+ *
* @return This builder.
*/
public TestRecordWithJsr310LogicalTypes.Builder clearI32() {
@@ -626,7 +627,7 @@ public class TestRecordWithJsr310LogicalTypes extends
org.apache.avro.specific.S
/**
* Gets the value of the 'i64' field.
- *
+ *
* @return The value.
*/
public java.lang.Long getI64() {
@@ -635,7 +636,7 @@ public class TestRecordWithJsr310LogicalTypes extends
org.apache.avro.specific.S
/**
* Sets the value of the 'i64' field.
- *
+ *
* @param value The value of 'i64'.
* @return This builder.
*/
@@ -648,7 +649,7 @@ public class TestRecordWithJsr310LogicalTypes extends
org.apache.avro.specific.S
/**
* Checks whether the 'i64' field has been set.
- *
+ *
* @return True if the 'i64' field has been set, false otherwise.
*/
public boolean hasI64() {
@@ -657,7 +658,7 @@ public class TestRecordWithJsr310LogicalTypes extends
org.apache.avro.specific.S
/**
* Clears the value of the 'i64' field.
- *
+ *
* @return This builder.
*/
public TestRecordWithJsr310LogicalTypes.Builder clearI64() {
@@ -667,7 +668,7 @@ public class TestRecordWithJsr310LogicalTypes extends
org.apache.avro.specific.S
/**
* Gets the value of the 'f32' field.
- *
+ *
* @return The value.
*/
public java.lang.Float getF32() {
@@ -676,7 +677,7 @@ public class TestRecordWithJsr310LogicalTypes extends
org.apache.avro.specific.S
/**
* Sets the value of the 'f32' field.
- *
+ *
* @param value The value of 'f32'.
* @return This builder.
*/
@@ -689,7 +690,7 @@ public class TestRecordWithJsr310LogicalTypes extends
org.apache.avro.specific.S
/**
* Checks whether the 'f32' field has been set.
- *
+ *
* @return True if the 'f32' field has been set, false otherwise.
*/
public boolean hasF32() {
@@ -698,7 +699,7 @@ public class TestRecordWithJsr310LogicalTypes extends
org.apache.avro.specific.S
/**
* Clears the value of the 'f32' field.
- *
+ *
* @return This builder.
*/
public TestRecordWithJsr310LogicalTypes.Builder clearF32() {
@@ -708,7 +709,7 @@ public class TestRecordWithJsr310LogicalTypes extends
org.apache.avro.specific.S
/**
* Gets the value of the 'f64' field.
- *
+ *
* @return The value.
*/
public java.lang.Double getF64() {
@@ -717,7 +718,7 @@ public class TestRecordWithJsr310LogicalTypes extends
org.apache.avro.specific.S
/**
* Sets the value of the 'f64' field.
- *
+ *
* @param value The value of 'f64'.
* @return This builder.
*/
@@ -730,7 +731,7 @@ public class TestRecordWithJsr310LogicalTypes extends
org.apache.avro.specific.S
/**
* Checks whether the 'f64' field has been set.
- *
+ *
* @return True if the 'f64' field has been set, false otherwise.
*/
public boolean hasF64() {
@@ -739,7 +740,7 @@ public class TestRecordWithJsr310LogicalTypes extends
org.apache.avro.specific.S
/**
* Clears the value of the 'f64' field.
- *
+ *
* @return This builder.
*/
public TestRecordWithJsr310LogicalTypes.Builder clearF64() {
@@ -749,7 +750,7 @@ public class TestRecordWithJsr310LogicalTypes extends
org.apache.avro.specific.S
/**
* Gets the value of the 's' field.
- *
+ *
* @return The value.
*/
public java.lang.CharSequence getS() {
@@ -758,7 +759,7 @@ public class TestRecordWithJsr310LogicalTypes extends
org.apache.avro.specific.S
/**
* Sets the value of the 's' field.
- *
+ *
* @param value The value of 's'.
* @return This builder.
*/
@@ -771,7 +772,7 @@ public class TestRecordWithJsr310LogicalTypes extends
org.apache.avro.specific.S
/**
* Checks whether the 's' field has been set.
- *
+ *
* @return True if the 's' field has been set, false otherwise.
*/
public boolean hasS() {
@@ -780,7 +781,7 @@ public class TestRecordWithJsr310LogicalTypes extends
org.apache.avro.specific.S
/**
* Clears the value of the 's' field.
- *
+ *
* @return This builder.
*/
public TestRecordWithJsr310LogicalTypes.Builder clearS() {
@@ -791,7 +792,7 @@ public class TestRecordWithJsr310LogicalTypes extends
org.apache.avro.specific.S
/**
* Gets the value of the 'd' field.
- *
+ *
* @return The value.
*/
public java.time.LocalDate getD() {
@@ -800,7 +801,7 @@ public class TestRecordWithJsr310LogicalTypes extends
org.apache.avro.specific.S
/**
* Sets the value of the 'd' field.
- *
+ *
* @param value The value of 'd'.
* @return This builder.
*/
@@ -813,7 +814,7 @@ public class TestRecordWithJsr310LogicalTypes extends
org.apache.avro.specific.S
/**
* Checks whether the 'd' field has been set.
- *
+ *
* @return True if the 'd' field has been set, false otherwise.
*/
public boolean hasD() {
@@ -822,7 +823,7 @@ public class TestRecordWithJsr310LogicalTypes extends
org.apache.avro.specific.S
/**
* Clears the value of the 'd' field.
- *
+ *
* @return This builder.
*/
public TestRecordWithJsr310LogicalTypes.Builder clearD() {
@@ -832,7 +833,7 @@ public class TestRecordWithJsr310LogicalTypes extends
org.apache.avro.specific.S
/**
* Gets the value of the 't' field.
- *
+ *
* @return The value.
*/
public java.time.LocalTime getT() {
@@ -841,7 +842,7 @@ public class TestRecordWithJsr310LogicalTypes extends
org.apache.avro.specific.S
/**
* Sets the value of the 't' field.
- *
+ *
* @param value The value of 't'.
* @return This builder.
*/
@@ -854,7 +855,7 @@ public class TestRecordWithJsr310LogicalTypes extends
org.apache.avro.specific.S
/**
* Checks whether the 't' field has been set.
- *
+ *
* @return True if the 't' field has been set, false otherwise.
*/
public boolean hasT() {
@@ -863,7 +864,7 @@ public class TestRecordWithJsr310LogicalTypes extends
org.apache.avro.specific.S
/**
* Clears the value of the 't' field.
- *
+ *
* @return This builder.
*/
public TestRecordWithJsr310LogicalTypes.Builder clearT() {
@@ -873,7 +874,7 @@ public class TestRecordWithJsr310LogicalTypes extends
org.apache.avro.specific.S
/**
* Gets the value of the 'ts' field.
- *
+ *
* @return The value.
*/
public java.time.Instant getTs() {
@@ -882,7 +883,7 @@ public class TestRecordWithJsr310LogicalTypes extends
org.apache.avro.specific.S
/**
* Sets the value of the 'ts' field.
- *
+ *
* @param value The value of 'ts'.
* @return This builder.
*/
@@ -895,7 +896,7 @@ public class TestRecordWithJsr310LogicalTypes extends
org.apache.avro.specific.S
/**
* Checks whether the 'ts' field has been set.
- *
+ *
* @return True if the 'ts' field has been set, false otherwise.
*/
public boolean hasTs() {
@@ -904,7 +905,7 @@ public class TestRecordWithJsr310LogicalTypes extends
org.apache.avro.specific.S
/**
* Clears the value of the 'ts' field.
- *
+ *
* @return This builder.
*/
public TestRecordWithJsr310LogicalTypes.Builder clearTs() {
@@ -914,7 +915,7 @@ public class TestRecordWithJsr310LogicalTypes extends
org.apache.avro.specific.S
/**
* Gets the value of the 'dec' field.
- *
+ *
* @return The value.
*/
public java.math.BigDecimal getDec() {
@@ -923,7 +924,7 @@ public class TestRecordWithJsr310LogicalTypes extends
org.apache.avro.specific.S
/**
* Sets the value of the 'dec' field.
- *
+ *
* @param value The value of 'dec'.
* @return This builder.
*/
@@ -936,7 +937,7 @@ public class TestRecordWithJsr310LogicalTypes extends
org.apache.avro.specific.S
/**
* Checks whether the 'dec' field has been set.
- *
+ *
* @return True if the 'dec' field has been set, false otherwise.
*/
public boolean hasDec() {
@@ -945,7 +946,7 @@ public class TestRecordWithJsr310LogicalTypes extends
org.apache.avro.specific.S
/**
* Clears the value of the 'dec' field.
- *
+ *
* @return This builder.
*/
public TestRecordWithJsr310LogicalTypes.Builder clearDec() {
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 d814c98..17cdf0c 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
@@ -7,7 +7,7 @@ package org.apache.avro.specific;
import java.math.BigDecimal;
-import org.apache.avro.data.TimeConversions;
+import org.apache.avro.data.JodaTimeConversions;
import org.apache.avro.message.BinaryMessageDecoder;
import org.apache.avro.message.BinaryMessageEncoder;
@@ -171,7 +171,7 @@ public class TestRecordWithLogicalTypes extends
org.apache.avro.specific.Specifi
/**
* Sets the value of the 'b' field.
- *
+ *
* @param value the value to set.
*/
public void setB(java.lang.Boolean value) {
@@ -187,7 +187,7 @@ public class TestRecordWithLogicalTypes extends
org.apache.avro.specific.Specifi
/**
* Sets the value of the 'i32' field.
- *
+ *
* @param value the value to set.
*/
public void setI32(java.lang.Integer value) {
@@ -203,7 +203,7 @@ public class TestRecordWithLogicalTypes extends
org.apache.avro.specific.Specifi
/**
* Sets the value of the 'i64' field.
- *
+ *
* @param value the value to set.
*/
public void setI64(java.lang.Long value) {
@@ -219,7 +219,7 @@ public class TestRecordWithLogicalTypes extends
org.apache.avro.specific.Specifi
/**
* Sets the value of the 'f32' field.
- *
+ *
* @param value the value to set.
*/
public void setF32(java.lang.Float value) {
@@ -235,7 +235,7 @@ public class TestRecordWithLogicalTypes extends
org.apache.avro.specific.Specifi
/**
* Sets the value of the 'f64' field.
- *
+ *
* @param value the value to set.
*/
public void setF64(java.lang.Double value) {
@@ -251,7 +251,7 @@ public class TestRecordWithLogicalTypes extends
org.apache.avro.specific.Specifi
/**
* Sets the value of the 's' field.
- *
+ *
* @param value the value to set.
*/
public void setS(java.lang.CharSequence value) {
@@ -267,7 +267,7 @@ public class TestRecordWithLogicalTypes extends
org.apache.avro.specific.Specifi
/**
* Sets the value of the 'd' field.
- *
+ *
* @param value the value to set.
*/
public void setD(org.joda.time.LocalDate value) {
@@ -283,7 +283,7 @@ public class TestRecordWithLogicalTypes extends
org.apache.avro.specific.Specifi
/**
* Sets the value of the 't' field.
- *
+ *
* @param value the value to set.
*/
public void setT(org.joda.time.LocalTime value) {
@@ -299,7 +299,7 @@ public class TestRecordWithLogicalTypes extends
org.apache.avro.specific.Specifi
/**
* Sets the value of the 'dec' field.
- *
+ *
* @param value the value to set.
*/
public void setDec(BigDecimal value) {
@@ -315,16 +315,16 @@ public class TestRecordWithLogicalTypes extends
org.apache.avro.specific.Specifi
/**
* Sets the value of the 'ts' field.
- *
+ *
* @param value the value to set.
*/
public void setTs(org.joda.time.DateTime value) {
this.ts = value;
}
- protected static final TimeConversions.DateConversion DATE_CONVERSION = new
TimeConversions.DateConversion();
- protected static final TimeConversions.TimeConversion TIME_CONVERSION = new
TimeConversions.TimeConversion();
- protected static final TimeConversions.TimestampConversion
TIMESTAMP_CONVERSION = new TimeConversions.TimestampConversion();
+ 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 };
@@ -478,7 +478,7 @@ public class TestRecordWithLogicalTypes extends
org.apache.avro.specific.Specifi
/**
* Sets the value of the 'b' field.
- *
+ *
* @param value the value to set.
*/
public TestRecordWithLogicalTypes.Builder setB(boolean value) {
@@ -512,7 +512,7 @@ public class TestRecordWithLogicalTypes extends
org.apache.avro.specific.Specifi
/**
* Sets the value of the 'i32' field.
- *
+ *
* @param value the value to set.
*/
public TestRecordWithLogicalTypes.Builder setI32(int value) {
@@ -546,7 +546,7 @@ public class TestRecordWithLogicalTypes extends
org.apache.avro.specific.Specifi
/**
* Sets the value of the 'i64' field.
- *
+ *
* @param value the value to set.
*/
public TestRecordWithLogicalTypes.Builder setI64(long value) {
@@ -580,7 +580,7 @@ public class TestRecordWithLogicalTypes extends
org.apache.avro.specific.Specifi
/**
* Sets the value of the 'f32' field.
- *
+ *
* @param value the value to set.
*/
public TestRecordWithLogicalTypes.Builder setF32(float value) {
@@ -614,7 +614,7 @@ public class TestRecordWithLogicalTypes extends
org.apache.avro.specific.Specifi
/**
* Sets the value of the 'f64' field.
- *
+ *
* @param value the value to set.
*/
public TestRecordWithLogicalTypes.Builder setF64(double value) {
@@ -648,7 +648,7 @@ public class TestRecordWithLogicalTypes extends
org.apache.avro.specific.Specifi
/**
* Sets the value of the 's' field.
- *
+ *
* @param value the value to set.
*/
public TestRecordWithLogicalTypes.Builder setS(java.lang.CharSequence
value) {
@@ -683,7 +683,7 @@ public class TestRecordWithLogicalTypes extends
org.apache.avro.specific.Specifi
/**
* Sets the value of the 'd' field.
- *
+ *
* @param value the value to set.
*/
public TestRecordWithLogicalTypes.Builder setD(org.joda.time.LocalDate
value) {
@@ -717,7 +717,7 @@ public class TestRecordWithLogicalTypes extends
org.apache.avro.specific.Specifi
/**
* Sets the value of the 't' field.
- *
+ *
* @param value the value to set.
*/
public TestRecordWithLogicalTypes.Builder setT(org.joda.time.LocalTime
value) {
@@ -751,7 +751,7 @@ public class TestRecordWithLogicalTypes extends
org.apache.avro.specific.Specifi
/**
* Sets the value of the 'ts' field.
- *
+ *
* @param value the value to set.
*/
public TestRecordWithLogicalTypes.Builder setTs(org.joda.time.DateTime
value) {
@@ -785,7 +785,7 @@ public class TestRecordWithLogicalTypes extends
org.apache.avro.specific.Specifi
/**
* Sedec the value of the 'dec' field.
- *
+ *
* @param value the value to set.
*/
public TestRecordWithLogicalTypes.Builder setDec(BigDecimal value) {
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
index 3e1d768..b6edf4d 100644
---
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
@@ -35,9 +35,9 @@ import java.util.List;
import org.apache.avro.Conversions;
import org.apache.avro.LogicalTypes;
import org.apache.avro.Schema;
-import org.apache.avro.data.TimeConversions.DateConversion;
-import org.apache.avro.data.TimeConversions.TimeConversion;
-import org.apache.avro.data.TimeConversions.TimestampConversion;
+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;
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 f5e2a10..d575205 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
@@ -25,7 +25,7 @@ import java.nio.ByteBuffer;
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.message.MissingSchemaException;
import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
@@ -48,9 +48,9 @@ public class TestSpecificToFromByteArray {
@Test
public void testSpecificToFromByteBufferWithoutLogicalTypes() throws
IOException {
TestRecordWithoutLogicalTypes record = new
TestRecordWithoutLogicalTypes(true, 34, 35L, 3.14F, 3019.34, null,
- new TimeConversions.DateConversion().toInt(LocalDate.now(), null,
null),
- new TimeConversions.TimeConversion().toInt(LocalTime.now(), null,
null),
- new
TimeConversions.TimestampConversion().toLong(DateTime.now().withZone(DateTimeZone.UTC),
null, 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),
new Conversions.DecimalConversion().toBytes(new BigDecimal("123.45"),
null, LogicalTypes.decimal(9, 2)));
ByteBuffer b = record.toByteBuffer();
@@ -62,9 +62,9 @@ public class TestSpecificToFromByteArray {
@Test(expected = MissingSchemaException.class)
public void testSpecificByteArrayIncompatibleWithLogicalTypes() throws
IOException {
TestRecordWithoutLogicalTypes withoutLogicalTypes = new
TestRecordWithoutLogicalTypes(true, 34, 35L, 3.14F, 3019.34,
- null, new TimeConversions.DateConversion().toInt(LocalDate.now(),
null, null),
- new TimeConversions.TimeConversion().toInt(LocalTime.now(), null,
null),
- new
TimeConversions.TimestampConversion().toLong(DateTime.now().withZone(DateTimeZone.UTC),
null, null),
+ 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),
new Conversions.DecimalConversion().toBytes(new BigDecimal("123.45"),
null, LogicalTypes.decimal(9, 2)));
ByteBuffer b = withoutLogicalTypes.toByteBuffer();
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 730a1e9..19fce11 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
@@ -38,8 +38,8 @@ import java.util.Set;
import org.apache.avro.Conversion;
import org.apache.avro.Conversions;
import org.apache.avro.LogicalTypes;
-import org.apache.avro.data.Jsr310TimeConversions;
import org.apache.avro.data.TimeConversions;
+import org.apache.avro.data.JodaTimeConversions;
import org.apache.avro.specific.SpecificData;
import org.apache.avro.Protocol;
@@ -100,19 +100,19 @@ public class SpecificCompiler {
JODA {
@Override
void addLogicalTypeConversions(SpecificData specificData) {
- specificData.addLogicalTypeConversion(new
TimeConversions.DateConversion());
- specificData.addLogicalTypeConversion(new
TimeConversions.TimeConversion());
- specificData.addLogicalTypeConversion(new
TimeConversions.TimestampConversion());
+ specificData.addLogicalTypeConversion(new
JodaTimeConversions.DateConversion());
+ specificData.addLogicalTypeConversion(new
JodaTimeConversions.TimeConversion());
+ specificData.addLogicalTypeConversion(new
JodaTimeConversions.TimestampConversion());
}
},
JSR310 {
@Override
void addLogicalTypeConversions(SpecificData specificData) {
- specificData.addLogicalTypeConversion(new
Jsr310TimeConversions.DateConversion());
- specificData.addLogicalTypeConversion(new
Jsr310TimeConversions.TimeMillisConversion());
- specificData.addLogicalTypeConversion(new
Jsr310TimeConversions.TimeMicrosConversion());
- specificData.addLogicalTypeConversion(new
Jsr310TimeConversions.TimestampMillisConversion());
- specificData.addLogicalTypeConversion(new
Jsr310TimeConversions.TimestampMicrosConversion());
+ 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());
}
};
diff --git
a/lang/java/compiler/src/test/java/org/apache/avro/compiler/specific/TestSpecificCompiler.java
b/lang/java/compiler/src/test/java/org/apache/avro/compiler/specific/TestSpecificCompiler.java
index bf1c7b3..eb4b93d 100644
---
a/lang/java/compiler/src/test/java/org/apache/avro/compiler/specific/TestSpecificCompiler.java
+++
b/lang/java/compiler/src/test/java/org/apache/avro/compiler/specific/TestSpecificCompiler.java
@@ -75,9 +75,14 @@ public class TestSpecificCompiler {
private File src = new File("src/test/resources/simple_record.avsc");
- /** Uses the system's java compiler to actually compile the generated code.
*/
static void assertCompilesWithJavaCompiler(File dstDir,
Collection<SpecificCompiler.OutputFile> outputs)
throws IOException {
+ assertCompilesWithJavaCompiler(dstDir, outputs, false);
+ }
+
+ /** Uses the system's java compiler to actually compile the generated code.
*/
+ static void assertCompilesWithJavaCompiler(File dstDir,
Collection<SpecificCompiler.OutputFile> outputs,
+ boolean ignoreWarnings) throws IOException {
if (outputs.isEmpty()) {
return; // Nothing to compile!
}
@@ -112,7 +117,9 @@ public class TestSpecificCompiler {
Collections.singletonList("-Xlint:all"), null,
fileManager.getJavaFileObjects(javaFiles.toArray(new File[0])));
boolean compilesWithoutError = cTask.call();
assertTrue(compilesWithoutError);
- assertEquals("Warnings produced when compiling generated code with
-Xlint:all", 0, warnings.size());
+ if (!ignoreWarnings) {
+ assertEquals("Warnings produced when compiling generated code with
-Xlint:all", 0, warnings.size());
+ }
}
private static Schema createSampleRecordSchema(int numStringFields, int
numDoubleFields) {
@@ -544,7 +551,8 @@ public class TestSpecificCompiler {
final Collection<String> usedConversionClasses =
compiler.getUsedConversionClasses(schema);
Assert.assertEquals(1, usedConversionClasses.size());
- Assert.assertEquals("org.apache.avro.data.TimeConversions.DateConversion",
usedConversionClasses.iterator().next());
+
Assert.assertEquals("org.apache.avro.data.JodaTimeConversions.DateConversion",
+ usedConversionClasses.iterator().next());
}
@Test
@@ -556,7 +564,8 @@ public class TestSpecificCompiler {
final Collection<String> usedConversionClasses =
compiler.getUsedConversionClasses(schema);
Assert.assertEquals(1, usedConversionClasses.size());
- Assert.assertEquals("org.apache.avro.data.TimeConversions.DateConversion",
usedConversionClasses.iterator().next());
+
Assert.assertEquals("org.apache.avro.data.JodaTimeConversions.DateConversion",
+ usedConversionClasses.iterator().next());
}
@Test
@@ -568,7 +577,8 @@ public class TestSpecificCompiler {
final Collection<String> usedConversionClasses =
compiler.getUsedConversionClasses(schema);
Assert.assertEquals(1, usedConversionClasses.size());
- Assert.assertEquals("org.apache.avro.data.TimeConversions.DateConversion",
usedConversionClasses.iterator().next());
+
Assert.assertEquals("org.apache.avro.data.JodaTimeConversions.DateConversion",
+ usedConversionClasses.iterator().next());
}
@Test
@@ -580,7 +590,8 @@ public class TestSpecificCompiler {
final Collection<String> usedConversionClasses =
compiler.getUsedConversionClasses(schema);
Assert.assertEquals(1, usedConversionClasses.size());
- Assert.assertEquals("org.apache.avro.data.TimeConversions.DateConversion",
usedConversionClasses.iterator().next());
+
Assert.assertEquals("org.apache.avro.data.JodaTimeConversions.DateConversion",
+ usedConversionClasses.iterator().next());
}
@Test
@@ -592,7 +603,8 @@ public class TestSpecificCompiler {
final Collection<String> usedConversionClasses =
compiler.getUsedConversionClasses(schema);
Assert.assertEquals(1, usedConversionClasses.size());
- Assert.assertEquals("org.apache.avro.data.TimeConversions.DateConversion",
usedConversionClasses.iterator().next());
+
Assert.assertEquals("org.apache.avro.data.JodaTimeConversions.DateConversion",
+ usedConversionClasses.iterator().next());
}
@Test
@@ -600,7 +612,7 @@ public class TestSpecificCompiler {
Schema logicalTypesWithMultipleFields = new Schema.Parser()
.parse(new
File("src/test/resources/logical_types_with_multiple_fields.avsc"));
assertCompilesWithJavaCompiler(new File(OUTPUT_DIR.getRoot(),
name.getMethodName()),
- new SpecificCompiler(logicalTypesWithMultipleFields, JODA).compile());
+ new SpecificCompiler(logicalTypesWithMultipleFields, JODA).compile(),
true);
}
@Test
@@ -631,11 +643,12 @@ public class TestSpecificCompiler {
Schema uuidSchema =
LogicalTypes.uuid().addToSchema(Schema.create(Schema.Type.STRING));
Assert.assertEquals("Should use date conversion for date type",
- "new org.apache.avro.data.TimeConversions.DateConversion()",
compiler.conversionInstance(dateSchema));
+ "new org.apache.avro.data.JodaTimeConversions.DateConversion()",
compiler.conversionInstance(dateSchema));
Assert.assertEquals("Should use time conversion for time type",
- "new org.apache.avro.data.TimeConversions.TimeConversion()",
compiler.conversionInstance(timeSchema));
+ "new org.apache.avro.data.JodaTimeConversions.TimeConversion()",
compiler.conversionInstance(timeSchema));
Assert.assertEquals("Should use timestamp conversion for date type",
- "new org.apache.avro.data.TimeConversions.TimestampConversion()",
compiler.conversionInstance(timestampSchema));
+ "new org.apache.avro.data.JodaTimeConversions.TimestampConversion()",
+ compiler.conversionInstance(timestampSchema));
Assert.assertEquals("Should use null for decimal if the flag is off",
"null",
compiler.conversionInstance(decimalSchema));
Assert.assertEquals("Should use null for decimal if the flag is off",
"null",
@@ -654,11 +667,12 @@ public class TestSpecificCompiler {
Schema uuidSchema =
LogicalTypes.uuid().addToSchema(Schema.create(Schema.Type.STRING));
Assert.assertEquals("Should use date conversion for date type",
- "new org.apache.avro.data.TimeConversions.DateConversion()",
compiler.conversionInstance(dateSchema));
+ "new org.apache.avro.data.JodaTimeConversions.DateConversion()",
compiler.conversionInstance(dateSchema));
Assert.assertEquals("Should use time conversion for time type",
- "new org.apache.avro.data.TimeConversions.TimeConversion()",
compiler.conversionInstance(timeSchema));
+ "new org.apache.avro.data.JodaTimeConversions.TimeConversion()",
compiler.conversionInstance(timeSchema));
Assert.assertEquals("Should use timestamp conversion for date type",
- "new org.apache.avro.data.TimeConversions.TimestampConversion()",
compiler.conversionInstance(timestampSchema));
+ "new org.apache.avro.data.JodaTimeConversions.TimestampConversion()",
+ compiler.conversionInstance(timestampSchema));
Assert.assertEquals("Should use null for decimal if the flag is off",
"new org.apache.avro.Conversions.DecimalConversion()",
compiler.conversionInstance(decimalSchema));
Assert.assertEquals("Should use null for decimal if the flag is off",
"null",
diff --git
a/lang/java/tools/src/test/compiler/output-string/avro/examples/baseball/FieldTest.java
b/lang/java/tools/src/test/compiler/output-string/avro/examples/baseball/FieldTest.java
index 5187554..88394f5 100644
---
a/lang/java/tools/src/test/compiler/output-string/avro/examples/baseball/FieldTest.java
+++
b/lang/java/tools/src/test/compiler/output-string/avro/examples/baseball/FieldTest.java
@@ -21,8 +21,8 @@ public class FieldTest extends
org.apache.avro.specific.SpecificRecordBase imple
private static SpecificData MODEL$ = new SpecificData();
static {
- MODEL$.addLogicalTypeConversion(new
org.apache.avro.data.Jsr310TimeConversions.TimestampMillisConversion());
- MODEL$.addLogicalTypeConversion(new
org.apache.avro.data.Jsr310TimeConversions.TimeMillisConversion());
+ MODEL$.addLogicalTypeConversion(new
org.apache.avro.data.TimeConversions.TimestampMillisConversion());
+ MODEL$.addLogicalTypeConversion(new
org.apache.avro.data.TimeConversions.TimeMillisConversion());
}
private static final BinaryMessageEncoder<FieldTest> ENCODER =
@@ -128,10 +128,10 @@ static {
new org.apache.avro.Conversion<?>[] {
null,
null,
- new
org.apache.avro.data.Jsr310TimeConversions.TimestampMillisConversion(),
- new
org.apache.avro.data.Jsr310TimeConversions.TimestampMicrosConversion(),
- new org.apache.avro.data.Jsr310TimeConversions.TimeMillisConversion(),
- new org.apache.avro.data.Jsr310TimeConversions.TimeMicrosConversion(),
+ new org.apache.avro.data.TimeConversions.TimestampMillisConversion(),
+ new org.apache.avro.data.TimeConversions.TimestampMicrosConversion(),
+ new org.apache.avro.data.TimeConversions.TimeMillisConversion(),
+ new org.apache.avro.data.TimeConversions.TimeMicrosConversion(),
null
};