-
Notifications
You must be signed in to change notification settings - Fork 512
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(fix)[avro] Use correct DatumWriter constructor (#5371)
- Loading branch information
1 parent
d235906
commit e1687eb
Showing
8 changed files
with
142 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
scio-avro/src/test/scala-avro-latest/com/spotify/scio/avro/AvroDatumFactoryTest.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
* Copyright 2024 Spotify AB | ||
* | ||
* Licensed 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 com.spotify.scio.avro | ||
|
||
import org.apache.avro.LogicalTypes | ||
import org.apache.avro.data.TimeConversions | ||
import org.apache.avro.specific.{SpecificDatumReader, SpecificDatumWriter} | ||
import org.scalatest.flatspec.AnyFlatSpec | ||
import org.scalatest.matchers.should.Matchers | ||
|
||
class AvroDatumFactoryTest extends AnyFlatSpec with Matchers { | ||
|
||
"SpecificRecordDatumFactory" should "load model with conversions" in { | ||
val factory = new SpecificRecordDatumFactory(classOf[LogicalTypesTest]) | ||
val schema = LogicalTypesTest.getClassSchema | ||
|
||
{ | ||
val writer = factory(schema) | ||
val data = writer.asInstanceOf[SpecificDatumWriter[LogicalTypesTest]].getData | ||
// top-level | ||
val timestamp = data.getConversionFor(LogicalTypes.timestampMillis()) | ||
timestamp shouldBe a[TimeConversions.TimestampMillisConversion] | ||
// nested-level | ||
val date = data.getConversionFor(LogicalTypes.date()) | ||
date shouldBe a[TimeConversions.DateConversion] | ||
val time = data.getConversionFor(LogicalTypes.timeMillis()) | ||
time shouldBe a[TimeConversions.TimeMillisConversion] | ||
} | ||
|
||
{ | ||
val reader = factory(schema, schema) | ||
val data = reader.asInstanceOf[SpecificDatumReader[LogicalTypesTest]].getData | ||
// top-level | ||
val timestamp = data.getConversionFor(LogicalTypes.timestampMillis()) | ||
timestamp shouldBe a[TimeConversions.TimestampMillisConversion] | ||
// nested-level | ||
val date = data.getConversionFor(LogicalTypes.date()) | ||
date shouldBe a[TimeConversions.DateConversion] | ||
val time = data.getConversionFor(LogicalTypes.timeMillis()) | ||
time shouldBe a[TimeConversions.TimeMillisConversion] | ||
} | ||
} | ||
|
||
it should "allow classes with 'conversions' field" in { | ||
val f = new SpecificRecordDatumFactory(classOf[NameConflict]) | ||
val schema = LogicalTypesTest.getClassSchema | ||
noException shouldBe thrownBy(f(schema)) | ||
noException shouldBe thrownBy(f(schema, schema)) | ||
} | ||
|
||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters