本文整理汇总了Scala中org.apache.spark.sql.types.TimestampType类的典型用法代码示例。如果您正苦于以下问题:Scala TimestampType类的具体用法?Scala TimestampType怎么用?Scala TimestampType使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了TimestampType类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。
示例1: DateTimeColumn
//设置package包名称以及导入依赖的类
package me.danielpes.spark.datetime
import org.apache.spark.sql.Column
import org.apache.spark.sql.types.{DataType, DateType, TimestampType}
import org.apache.spark.sql.functions.{col, udf}
class DateTimeColumn(val col: Column, dataType: DataType = TimestampType) {
def +(p: Period): Column = dataType match {
case _: DateType => udf((d: java.sql.Date) => new RichDate(d) + p).apply(col)
case _: TimestampType => udf((ts: java.sql.Timestamp) => new RichDate(ts) + p).apply(col)
}
def -(p: Period): Column = this.+(-p)
override def toString: String = s"{column: ${col.toString}, type: ${dataType.toString}}"
}
object DateTimeColumn {
def apply(col: Column, dataType: DataType = TimestampType) = new DateTimeColumn(col, dataType)
def apply(col: Column, typeString: String) = new DateTimeColumn(col, typeFromString(typeString))
def apply(cName: String) = new DateTimeColumn(col(cName), TimestampType)
def apply(cName: String, dataType: DataType) = new DateTimeColumn(col(cName), dataType)
def apply(cName: String, typeString: String) = new DateTimeColumn(col(cName), typeFromString(typeString))
private def typeFromString(s: String): DataType = s match {
case "date" => DateType
case "timestamp" => TimestampType
}
}
示例2: FieldDateTime
//设置package包名称以及导入依赖的类
package com.esri.gdb
import java.nio.ByteBuffer
import java.sql.Timestamp
import org.apache.spark.sql.types.{Metadata, TimestampType}
class FieldDateTime(name: String, nullValueAllowed: Boolean, metadata:Metadata)
extends Field(name, TimestampType, nullValueAllowed, metadata) {
override def readValue(byteBuffer: ByteBuffer, oid: Int) = {
val numDays = byteBuffer.getDouble
// convert days since 12/30/1899 to 1/1/1970
val unixDays = numDays - 25569
val millis = (unixDays * 1000 * 60 * 60 * 24).ceil.toLong
new Timestamp(millis)
}
}