All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.apache.spark.sql.mlsql.sources.mysql.binlog.io.SchemaTool.scala Maven / Gradle / Ivy

There is a newer version: 1.0.4
Show newest version
package org.apache.spark.sql.mlsql.sources.mysql.binlog.io

import org.apache.hadoop.conf.Configuration
import org.apache.spark.sql.types._

/**
 * 2019-06-14 WilliamZhu([email protected])
 */
class SchemaTool(json: String, index: Int, _timeZone: String, hadoopConf: Configuration) {
  val schema = DataType.fromJson(json).asInstanceOf[StructType]


  def getColumnNameByIndex() = {
    schema(index).name
  }

  def timeZone = _timeZone

  def isBinary() = {
    schema(index).dataType == BinaryType
  }

  def isTimestamp() = {
    schema(index).dataType == TimestampType
  }

  def isDate() = {
    schema(index).dataType == DateType
  }

  def isBoolean() = {
    schema(index).dataType == BooleanType
  }

  def isLong() = {
    schema(index).dataType == LongType
  }

  def field = {
    schema(index)
  }

  def charset: String = {
    val allType = hadoopConf.get(s"binlog.field.decode.*")
    if (allType != null) {
      return allType
    }
    val fieldType = hadoopConf.get(s"binlog.field.decode.${getColumnNameByIndex}", "utf-8")
    return fieldType
  }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy