当前位置:   article > 正文

Spark 之 DataType_spark datatype

spark datatype
TimestampType
spark-sql> create table if not exists test_emr_date(
         >     id      int,
         >     datetime1   timestamp
         > );
  • 1
  • 2
  • 3
  • 4
spark-sql> 
         > insert into test_emr_date values (1,timestamp'2021-11-29 00:01:00');
Time taken: 0.497 seconds
  • 1
  • 2
  • 3
spark-sql> 
         > insert into test_emr_date values (1,timestamp'2021-11-29 00:01:00.100');
Time taken: 0.36 seconds

  • 1
  • 2
  • 3
  • 4
spark-sql> 
         > select * from test_emr_date;
1	2021-11-29 00:01:00.1
1	2021-11-29 00:01:00
  • 1
  • 2
  • 3
  • 4
DecimalType
/**
 * Extra factory methods and pattern matchers for Decimals.
 *
 * @since 1.3.0
 */
@Stable
object DecimalType extends AbstractDataType {
  import scala.math.min

  val MAX_PRECISION = 38
  val MAX_SCALE = 38
  val SYSTEM_DEFAULT: DecimalType = DecimalType(MAX_PRECISION, 18)
  val USER_DEFAULT: DecimalType = DecimalType(10, 0)
  val MINIMUM_ADJUSTED_SCALE = 6

  // The decimal types compatible with other numeric types
  private[sql] val BooleanDecimal = DecimalType(1, 0)
  private[sql] val ByteDecimal = DecimalType(3, 0)
  private[sql] val ShortDecimal = DecimalType(5, 0)
  private[sql] val IntDecimal = DecimalType(10, 0)
  private[sql] val LongDecimal = DecimalType(20, 0)
  private[sql] val FloatDecimal = DecimalType(14, 7)
  private[sql] val DoubleDecimal = DecimalType(30, 15)
  private[sql] val BigIntDecimal = DecimalType(38, 0)
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
spark functions
> select from_unixtime(123456789);
java.version:1.8.0_371
1973-11-30 05:33:09
Time taken: 0.603 seconds, Fetched 1 row(s)
  • 1
  • 2
  • 3
  • 4
 > select from_unixtime(0);
java.version:1.8.0_371
1970-01-01 08:00:00
Time taken: 0.246 seconds, Fetched 1 row(s)
  • 1
  • 2
  • 3
  • 4
> select datediff('2013-05-31 13:00:00', '2013-04-30 12:30:00');
java.version:1.8.0_371
31
Time taken: 0.072 seconds, Fetched 1 row(s)
  • 1
  • 2
  • 3
  • 4
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Cpp五条/article/detail/603680
推荐阅读
相关标签
  

闽ICP备14008679号