Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrading scala and scala.binary version from 2.12.14 to 2.13.14 #48

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@
<gpg.skip>true</gpg.skip>
<nexus.remote.skip>false</nexus.remote.skip>

<scala.version>2.12.14</scala.version>
<scala.binary.version>2.12</scala.binary.version>
<scala.version>2.13.14</scala.version>
<scala.binary.version>2.13</scala.binary.version>
<spark.version>3.3.3</spark.version>
<bigtable.java.version>2.42.0</bigtable.java.version>
<bigtable.java.emulator.version>0.175.0</bigtable.java.emulator.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import java.nio.ByteBuffer
import java.sql.Timestamp
import java.util
import java.util.HashMap
import scala.collection.JavaConversions._
import scala.jdk.CollectionConverters._

@InterfaceAudience.Private
abstract class AvroException(msg: String) extends Exception(msg)
Expand Down Expand Up @@ -69,10 +69,10 @@ object SchemaConverters {
case ENUM => SchemaType(StringType, nullable = false)

case RECORD =>
val fields = avroSchema.getFields.map { f =>
val fields = avroSchema.getFields.asScala.map { f =>
val schemaType = toSqlType(f.schema())
StructField(f.name, schemaType.dataType, schemaType.nullable)
}
}.toSeq

SchemaType(StructType(fields), nullable = false)

Expand All @@ -95,18 +95,18 @@ object SchemaConverters {
)

case UNION =>
if (avroSchema.getTypes.exists(_.getType == NULL)) {
if (avroSchema.getTypes.asScala.exists(_.getType == NULL)) {
// In case of a union with null, eliminate it and make a recursive call
val remainingUnionTypes =
avroSchema.getTypes.filterNot(_.getType == NULL)
avroSchema.getTypes.asScala.filterNot(_.getType == NULL)
if (remainingUnionTypes.size == 1) {
toSqlType(remainingUnionTypes.get(0)).copy(nullable = true)
toSqlType(remainingUnionTypes.head).copy(nullable = true)
} else {
toSqlType(Schema.createUnion(remainingUnionTypes))
toSqlType(Schema.createUnion(remainingUnionTypes.asJava))
.copy(nullable = true)
}
} else
avroSchema.getTypes.map(_.getType) match {
avroSchema.getTypes.asScala.map(_.getType) match {
case Seq(t1, t2) if Set(t1, t2) == Set(INT, LONG) =>
SchemaType(LongType, nullable = false)
case Seq(t1, t2) if Set(t1, t2) == Set(FLOAT, DOUBLE) =>
Expand Down Expand Up @@ -182,7 +182,7 @@ object SchemaConverters {
}
case RECORD =>
val fieldConverters =
schema.getFields.map(f => createConverterToSQL(f.schema))
schema.getFields.asScala.map(f => createConverterToSQL(f.schema))
(item: Any) =>
if (item == null) {
null
Expand All @@ -203,10 +203,10 @@ object SchemaConverters {
null
} else {
try {
item.asInstanceOf[GenericData.Array[Any]].map(elementConverter)
item.asInstanceOf[GenericData.Array[Any]].asScala.map(elementConverter)
} catch {
case e: Throwable =>
item.asInstanceOf[util.ArrayList[Any]].map(elementConverter)
item.asInstanceOf[util.ArrayList[Any]].asScala.map(elementConverter)
}
}
case MAP =>
Expand All @@ -217,19 +217,20 @@ object SchemaConverters {
} else {
item
.asInstanceOf[HashMap[Any, Any]]
.asScala
.map(x => (x._1.toString, valueConverter(x._2)))
.toMap
}
case UNION =>
if (schema.getTypes.exists(_.getType == NULL)) {
val remainingUnionTypes = schema.getTypes.filterNot(_.getType == NULL)
if (schema.getTypes.asScala.exists(_.getType == NULL)) {
val remainingUnionTypes = schema.getTypes.asScala.filterNot(_.getType == NULL)
if (remainingUnionTypes.size == 1) {
createConverterToSQL(remainingUnionTypes.get(0))
createConverterToSQL(remainingUnionTypes.head)
} else {
createConverterToSQL(Schema.createUnion(remainingUnionTypes))
createConverterToSQL(Schema.createUnion(remainingUnionTypes.asJava))
}
} else
schema.getTypes.map(_.getType) match {
schema.getTypes.asScala.map(_.getType) match {
case Seq(t1, t2) if Set(t1, t2) == Set(INT, LONG) =>
(item: Any) => {
item match {
Expand Down