首页 文章 精选 留言 我的

精选列表

搜索[节点类型],共10000篇文章
优秀的个人博客,低调大师

Hive SQL去重a,b和b,a类型

昨天开发找到我们DBA,要我们写一条Hive SQL。 需求: 有一个t表,主要有机场名称airport,机场的经纬度distance这两个列组成,想得到所有距离小于100的两个机场名。 其实写这个SQL的逻辑并不是很困难,难点是如何去重复值, 我用MySQL模拟的一个表,其实Hive语法和SQL差不多,插入了三条数据,a, b, c 分别代表三个机场名称,结构如下: mysql>showcreatetablet\G ***************************1.row*************************** Table:t CreateTable:CREATETABLE`t`( `airport`varchar(10)DEFAULTNULL, `distant`int(11)DEFAULTNULL )ENGINE=InnoDBDEFAULTCHARSET=utf8 1rowinset(0.00sec) mysql>select*fromt; +---------+---------+ |airport|distant| +---------+---------+ |a|130| |b|140| |c|150| +---------+---------+ 3rowsinset(0.00sec) 通过!=筛选掉本机场自己之间的比较,用abs函数取绝对值得到位置小于100的两个机场 mysql>selectt1.airport,t2.airportfromtt1,tt2wheret1.airport!=t2.airportandabs(t1.distant-t2.distant)<100; +---------+---------+ |airport|airport| +---------+---------+ |b|a| |c|a| |a|b| |c|b| |a|c| |b|c| +---------+---------+ 6rowsinset(0.00sec) 但是问题来了,(b,a) 与(a,b),(c,a)与(a,c),(c,b)与(b,c)这里被我们视为重复值,我们只需要得到其中某一行的数据,就知道是哪两个机场名了,那么,如何去掉这个重复值呢? 貌似distinct,group by都派不上用场了,最后咨询了一位资深的SQL高手,找到了这么一个函数hex(),可以把一个字符转化成十六进制,Hive也有对应的函数,效果如下: mysql>selectt1.airport,hex(t1.airport),t2.airport,hex(t2.airport)fromtt1,tt2wheret1.airport!=t2.airportandabs(t1.distant-t2.distant)<100; +---------+-----------------+---------+-----------------+ |airport|hex(t1.airport)|airport|hex(t2.airport)| +---------+-----------------+---------+-----------------+ |b|62|a|61| |c|63|a|61| |a|61|b|62| |c|63|b|62| |a|61|c|63| |b|62|c|63| +---------+-----------------+---------+-----------------+ 6rowsinset(0.00sec) 这样我们就可以通过比较机场1和机场2的大小,来去掉重复值了 mysql>selectt1.airport,t2.airportfromtt1,tt2wheret1.airport!=t2.airportandhex(t1.airport)<hex(t2.airport)andabs(t1.distant-t2.distant)<100; +---------+---------+ |airport|airport| +---------+---------+ |a|b| |a|c| |b|c| +---------+---------+ 3rowsinset(0.00sec) 最后再优化一下,结果如下: mysql>selectt1.airport,t2.airportfromtt1,tt2wherehex(t1.airport)<hex(t2.airport)andabs(t1.distant-t2.distant)<100; +---------+---------+ |airport|airport| +---------+---------+ |a|b| |a|c| |b|c| +---------+---------+ 3rowsinset(0.00sec) SQL并不复杂,没有太多表的join和子查询,但是之前遇到去掉重复值用distinct或者group by就可以解决了,这次貌似不太适用,所以记录一下,欢迎拍砖。 参考链接 https://dev.mysql.com/doc/refman/5.7/en/string-functions.html#function_hex https://cwiki.apache.org/confluence/display/Hive/LanguageManual+UDF#LanguageManualUDF-Built-inFunctions

优秀的个人博客,低调大师

jQuery EasyUI 重写datagrid的datetimebox编辑类型

datagrid的编辑框可以为datatimebox或者为datebox如下: 示例如下: { field: 'makeDate', title: '编制日期', width: 45, editor:{ type:'datebox' , options:{ editable:false } } } $.extend($.fn.datagrid.defaults.editors, { datebox : { init : function(container, options) { var box = $('<input />').appendTo(container); options.onSelect=function(){ var val = box.datebox('getValue'); //执行相关操作 } box.datebox(options); return box; }, getValue : function(target) { return $(target).datebox('getValue'); }, setValue : function(target, value) { $(target).datebox('setValue', value); }, resize : function(target, width) { var box = $(target); box.datebox('resize', width); }, destroy : function(target) { $(target).datebox('destroy'); }, } }); $.extend($.fn.datagrid.defaults.editors, { datetimebox : { init : function(container, options) { var box = $('<input />').appendTo(container); box.datetimebox(options); return box; }, getValue : function(target) { return $(target).datetimebox('getValue'); }, setValue : function(target, value) { $(target).datetimebox('setValue', value); }, resize : function(target, width) { var box = $(target); box.datetimebox('resize', width); }, destroy : function(target) { $(target).datetimebox('destroy'); }, } });

资源下载

更多资源
Nacos

Nacos

Nacos /nɑ:kəʊs/ 是 Dynamic Naming and Configuration Service 的首字母简称,一个易于构建 AI Agent 应用的动态服务发现、配置管理和AI智能体管理平台。Nacos 致力于帮助您发现、配置和管理微服务及AI智能体应用。Nacos 提供了一组简单易用的特性集,帮助您快速实现动态服务发现、服务配置、服务元数据、流量管理。Nacos 帮助您更敏捷和容易地构建、交付和管理微服务平台。

Spring

Spring

Spring框架(Spring Framework)是由Rod Johnson于2002年提出的开源Java企业级应用框架,旨在通过使用JavaBean替代传统EJB实现方式降低企业级编程开发的复杂性。该框架基于简单性、可测试性和松耦合性设计理念,提供核心容器、应用上下文、数据访问集成等模块,支持整合Hibernate、Struts等第三方框架,其适用范围不仅限于服务器端开发,绝大多数Java应用均可从中受益。

Rocky Linux

Rocky Linux

Rocky Linux(中文名:洛基)是由Gregory Kurtzer于2020年12月发起的企业级Linux发行版,作为CentOS稳定版停止维护后与RHEL(Red Hat Enterprise Linux)完全兼容的开源替代方案,由社区拥有并管理,支持x86_64、aarch64等架构。其通过重新编译RHEL源代码提供长期稳定性,采用模块化包装和SELinux安全架构,默认包含GNOME桌面环境及XFS文件系统,支持十年生命周期更新。

Sublime Text

Sublime Text

Sublime Text具有漂亮的用户界面和强大的功能,例如代码缩略图,Python的插件,代码段等。还可自定义键绑定,菜单和工具栏。Sublime Text 的主要功能包括:拼写检查,书签,完整的 Python API , Goto 功能,即时项目切换,多选择,多窗口等等。Sublime Text 是一个跨平台的编辑器,同时支持Windows、Linux、Mac OS X等操作系统。

用户登录
用户注册