永发信息网

hive和sparksql的区别

答案:2  悬赏:60  手机版
解决时间 2021-02-09 10:57
  • 提问者网友:欲望失宠
  • 2021-02-08 21:45
hive和sparksql的区别
最佳答案
  • 五星知识达人网友:思契十里
  • 2021-02-08 22:51
历史上存在的原理,以前都是使用hive来构建数据仓库,所以存在大量对hive所管理的数据查询的需求。而hive、shark、sparlSQL都可以进行hive的数据查询。shark是使用了hive的sql语法解析器和优化器,修改了执行器,使之物理执行过程是跑在spark上;而sparkSQL是使用了自身的语法解析器、优化器和执行器,同时sparkSQL还扩展了接口,不单单支持hive数据的查询,可以进行多种数据源的数据查询。
全部回答
  • 1楼网友:神也偏爱
  • 2021-02-08 23:51
今天在看一些数据的时候发现,一些sparksql与hive之间在进行cast转化时候存在一些差异。 hiveversion 1.2.1 sparksql 1.6.0 总结: 在hive中, boolean类型的隐式转化,hive中非boolean非null转化默认为true, 而在sparksql中,则根据传入的不同数据类型判断值后返回结果. hive converts the results of the expression expr to . for example, cast(‘1’ as bigint) will convert the string ‘1’ to its integral representation. a null is returned if the conversion does not succeed. if cast(expr as boolean) hive returns true for a non-empty string. hive> select cast('false' as boolean) from default.dule; ok true123 sparksql 在sparksql中如果是string的话,会检查stringutils中枚举的;其他原子类型数据进行是否不等于0,不等于0返回true,否则为false 具体代码逻辑如下 classname: org.apache.spark.sql.catalyst.expressions.cast // udftoboolean private[this] def casttoboolean(from: datatype): any => any = from match { case stringtype => buildcast[utf8string](_, s => { if (stringutils.istruestring(s)) { true } else if (stringutils.isfalsestring(s)) { false } else { null } }) case timestamptype => buildcast[long](_, t => t != 0) case datetype => // hive would return null when cast from date to boolean buildcast[int](_, d => null) case longtype => buildcast[long](_, _ != 0) case integertype => buildcast[int](_, _ != 0) case shorttype => buildcast[short](_, _ != 0) case bytetype => buildcast[byte](_, _ != 0) case decimaltype() => buildcast[decimal](_, !_.iszero) case doubletype => buildcast[double](_, _ != 0) case floattype => buildcast[float](_, _ != 0) } classname: org.apache.spark.sql.catalyst.util.stringutils // private[this] val truestrings = set("t", "true", "y", "yes", "1").map(utf8string.fromstring) private[this] val falsestrings = set("f", "false", "n", "no", "0").map(utf8string.fromstring) def istruestring(s: utf8string): boolean = truestrings.contains(s.tolowercase) def isfalsestring(s: utf8string): boolean = falsestrings.contains(s.tolowercase)
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯