Skip to content

Commit

Permalink
Add numeric types support (close #349)
Browse files Browse the repository at this point in the history
  • Loading branch information
voropaevp committed Apr 27, 2023
1 parent 48bbb30 commit 8da88ae
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import scala.jdk.CollectionConverters._
/** Transform dependency-free schema-ddl AST into Google Cloud Java definitions */
object Adapter {
def adaptRow(row: Row): AnyRef = row match {
case Row.Null => null
case Row.Null => null
case Row.Primitive(value) => value.asInstanceOf[AnyRef]
case Row.Repeated(rows) =>
rows.map(adaptRow).asJava
Expand All @@ -34,8 +34,8 @@ object Adapter {

def adaptField(bigQueryField: DdlField): Field =
bigQueryField match {
case DdlField(name, record @ Type.Record(fields), mode) =>
val subFields = fields.map(adaptField)
case DdlField(name, record@Type.Record(fields), mode) =>
val subFields = fields.map(adaptField)
val fieldsList = FieldList.of(subFields.asJava)
Field.newBuilder(name, adaptType(record), fieldsList).setMode(adaptMode(mode)).build()
case DdlField(name, fieldType, mode) =>
Expand All @@ -52,13 +52,14 @@ object Adapter {
def adaptType(fieldType: Type): LegacySQLTypeName =
fieldType match {
case Type.Timestamp => LegacySQLTypeName.TIMESTAMP
case Type.Integer => LegacySQLTypeName.INTEGER
case Type.Boolean => LegacySQLTypeName.BOOLEAN
case Type.String => LegacySQLTypeName.STRING
case Type.Float => LegacySQLTypeName.FLOAT
case Type.Numeric => LegacySQLTypeName.NUMERIC
case Type.Date => LegacySQLTypeName.DATE
case Type.DateTime => LegacySQLTypeName.DATETIME
case Type.Integer => LegacySQLTypeName.INTEGER
case Type.Boolean => LegacySQLTypeName.BOOLEAN
case Type.String => LegacySQLTypeName.STRING
case Type.Float => LegacySQLTypeName.FLOAT
case Type.Numeric(precision, scale) if (precision <= 38) & (scale <= 9) => LegacySQLTypeName.NUMERIC
case _: Type.Numeric => LegacySQLTypeName.BIGNUMERIC
case Type.Date => LegacySQLTypeName.DATE
case Type.DateTime => LegacySQLTypeName.DATETIME
case Type.Record(_) => LegacySQLTypeName.RECORD
}
}
6 changes: 3 additions & 3 deletions project/Dependencies.scala
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,20 @@ object Dependencies {
val cats = "2.6.1"
val catsEffect = "3.3.12"
val catsRetry = "3.1.0"
val circe = "0.14.1"
val circe = "0.14.3"
val decline = "1.4.0"
val fs2 = "3.2.8"
val httpClient = "0.23.18"
val logging = "2.3.1"
val pubsubFs2 = "0.20.0"
val circeConfig = "0.8.0"
val circeConfig = "0.10.0"

// Scala Snowplow
val analyticsSdk = "2.1.0"
val badrows = "2.2.0"
val igluClient = "2.2.0"
val igluCore = "1.0.1"
val schemaDdl = "0.14.4"
val schemaDdl = "0.19.0-M1"

// Scala (test only)
val specs2 = "4.13.2"
Expand Down

0 comments on commit 8da88ae

Please sign in to comment.