def getDataTypeForName()

in tools/bigquery-hive-external-table-loader/src/main/scala/com/google/cloud/bqhiveloader/Mapping.scala [54:87]


  def getDataTypeForName(dataTypeName: String): DataType = {
    dataTypeName match {
      case x if x.startsWith("varchar") => StringType
      case x if x == StringType.typeName => StringType
      case x if x == IntegerType.typeName => IntegerType
      case x if x == "int" => IntegerType
      case x if x == "smallint" => ShortType
      case x if x == "tinyint" => ShortType
      case x if x == "bigint" => LongType
      case x if x == LongType.typeName => LongType
      case x if x == DoubleType.typeName => DoubleType
      case x if x == DateType.typeName => DateType
      case x if x == TimestampType.typeName => TimestampType
      case x if x == FloatType.typeName => FloatType
      case x if x == ShortType.typeName => ShortType
      case x if x == BooleanType.typeName => BooleanType
      case x if x == ByteType.typeName => ByteType
      case x if x.startsWith("char") => StringType
      case x if x.startsWith("decimal") =>
        x.toLowerCase
          .stripPrefix("decimal(")
          .stripSuffix(")")
          .split(",") match {
          case Array(precision, scale) if precision.forall(_.isDigit) && scale.forall(_.isDigit) =>
            DecimalType(precision.toInt, scale.toInt)
          case _ =>
            DecimalType(19,2)
        }
      case x if x.startsWith("array") => ArrayType(IntegerType)
      case x if x.startsWith("struct") => StructType(Seq.empty[StructField])
      case _ =>
        throw new RuntimeException(s"Unexpected DataType '$dataTypeName'")
    }
  }