首页 文章 精选 留言 我的

精选列表

搜索[类型安全],共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'); }, } });

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

Objective-C 处理动态类型的方法

方法 问题或行为 -(BOOL) isKindOfClass : class-object 对象是不是class-object或其子类的成员 -(BOOL) isMemberOfClass:class-object 对象是不是class-object的成员 -(BOOL) respondsToSelector:Selector 对象是否能够响应selector所指定的方法 -(BOOL) instancesRespondToSelector 指定的类实例是否能响应selector -(BOOL) isSubclassOfClass:class-object 对象是否是指定类的子类 -(id) performSelector:selector 应用selector指定的方法 -(id) performSelector:selector withObject:object 应用selector指定的方法 -(id) performSelector:selector withObject:object1 withObject : object2 应用selector指定的方法 测试实验设计 继承关系图: Rectangle.h Square.h 在main.h中的测试如下: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 // //main.m //Square // //CreatedbyAppleon2017/9/9. //Copyright2017年Apple.Allrightsreserved. // #import<Foundation/Foundation.h> #import"Square.h" int main( int argc, const char *argv[]){ @autoreleasepool{ Square*mySquare=[[Squarealloc]init]; //isMemberof if ([mySquareisMemberOfClass:[Square class ]]==YES) { NSLog(@ "mySquareisamemberofSquareclass" ); // } if ([mySquareisMemberOfClass:[Rectangle class ]]==YES) { NSLog(@ "mySquareissmemberofRectamgleclass" ); } if ([mySquareisMemberOfClass:[NSObject class ]]==YES) { NSLog(@ "mySquareisamemberofNSObjectclass" ); } //isKindOf if ([mySquareisKindOfClass:[Square class ]]==YES) { NSLog(@ "mySquareisakindofSquareclass" ); // } if ([mySquareisKindOfClass:[Rectangle class ]]==YES) { NSLog(@ "mySquareisskindofRectamgleclass" ); } if ([mySquareisKindOfClass:[NSObject class ]]==YES) { NSLog(@ "mySquareisakindofNSObjectclass" ); // } //respondsTo: if ([mySquarerespondsToSelector:@selector(setSide:)]==YES) { NSLog(@ "mySquarerespondstosetSide:method" ); } if ([mySquarerespondsToSelector:@selector(setWidth:addHeight:)]==YES) { NSLog(@ "mySquarerespondstosetWidth:addHeight:method" ); } if ([SquarerespondsToSelector:@selector(alloc)]==YES) { NSLog(@ "Squareclassrespondstoallocmethod" ); } //instancesRespondTo: if ([RectangleinstancesRespondToSelector:@selector(setSide:)]==YES) { NSLog(@ "InstancesofrespondtosetSide:method" ); } if ([SquareinstancesRespondToSelector:@selector(setWidth:addHeight:)]==YES) { NSLog(@ "InstancesofSquarerespondtosetWidth:addHeight::method" ); } if ([SquareisSubclassOfClass:[Rectangle class ]]==YES) { NSLog(@ "Squareisasubclassofarectangle" ); } return 0; } } 本文转自Aonaufly51CTO博客,原文链接:http://blog.51cto.com/aonaufly/1963970,如需转载请自行联系原作者

资源下载

更多资源
腾讯云软件源

腾讯云软件源

为解决软件依赖安装时官方源访问速度慢的问题,腾讯云为一些软件搭建了缓存服务。您可以通过使用腾讯云软件源站来提升依赖包的安装速度。为了方便用户自由搭建服务架构,目前腾讯云软件源站支持公网访问和内网访问。

Nacos

Nacos

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

Rocky Linux

Rocky Linux

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

WebStorm

WebStorm

WebStorm 是jetbrains公司旗下一款JavaScript 开发工具。目前已经被广大中国JS开发者誉为“Web前端开发神器”、“最强大的HTML5编辑器”、“最智能的JavaScript IDE”等。与IntelliJ IDEA同源,继承了IntelliJ IDEA强大的JS部分的功能。

用户登录
用户注册