当前位置: 首页 > news >正文

企业网站的做h5产品是什么意思

企业网站的做,h5产品是什么意思,wordpress微信小程序,做视频网站要用到的服务器文章目录 1. 需求背景数据现状业务需求面临技术问题寻求其他方案 2. 运行环境软件版本Maven依赖 3. 获取离线地址库4. Hive UDF函数实现5. 创建Hive UDF函数6. 参考 1. 需求背景 数据现状 目前业务系统某数据库表中记录了约3亿条用户行为数据#xff0c;其中两列记录了用户触… 文章目录 1. 需求背景数据现状业务需求面临技术问题寻求其他方案 2. 运行环境软件版本Maven依赖 3. 获取离线地址库4. Hive UDF函数实现5. 创建Hive UDF函数6. 参考 1. 需求背景 数据现状 目前业务系统某数据库表中记录了约3亿条用户行为数据其中两列记录了用户触发某个业务动作时所在的经度和纬度数值但是没有记录经纬度对应的省市区编码和名称信息。 业务需求 现在业务方提出一个数据需求想要统计省市区对应的用户数等相关指标。 面临技术问题 因为历史数据量较大如果通过调用高德API把所有历史数据中的经纬度对应的省市区请求回来会面临一个个问题在查看公司的高德API账户后发现每天提供的最大调用量是300W次那么要把历史3亿数据初始化调用完需要30000W/300w100天要3个多月这完全是不可接受的。 寻求其他方案 既然不能通过调用高德API的方式获取省市区那有没有一个离线的地址库然后从这个地址库获取历史数据的省市区呢。然后通过搜索引擎还真的找到了某个大神写的一个第三方库可以从一个地址库文件来获取经纬度对应的省市区。 这个第三方库的Github地址https://github.com/hsp8712/addrparser 2. 运行环境 软件版本 Java 1.8Hive 3.1.0Hadoop 3.1.1 Maven依赖 dependencygroupIdtech.spiro/groupIdartifactIdaddrparser/artifactIdversion1.1/version/dependencydependencygroupIdorg.apache.hive/groupIdartifactIdhive-exec/artifactIdversion3.1.0/versionscopeprovided/scope/dependencydependencygroupIdorg.apache.hadoop/groupIdartifactIdhadoop-common/artifactIdversion3.1.1/versionscopeprovided/scope/dependency3. 获取离线地址库 这个第三方库的作者提供了一个2019年9月份的离线地址库文件考虑到这个文件的数据已经比较旧了然后去翻看作者的源码文件发现提供了爬取地址库的源码直接拿来改改就可以用了但前提是你要有请求高德API的API Key。 下面是本人调整后并经过测试后可以正常请求地址库的代码这个类中还引用了作者编写的其他类/接口请参考作业的Github import org.apache.commons.cli.*; import tech.spiro.addrparser.crawler.GetRegionException; import tech.spiro.addrparser.crawler.RegionDataCrawler; import tech.spiro.addrparser.io.RegionDataOutput; import tech.spiro.addrparser.io.file.JSONFileRegionDataOutput;import java.io.IOException; import java.util.Arrays;/* * * A command-line tool to crawl region data. * */ public class CrawlerServer {private static Options options new Options();static {options.addOption(k, key, true, Amap enterprise dev key);options.addOption(l, level, true, Root region level: 0-country, 1-province, 2-city);options.addOption(c, code, true, Root region code);options.addOption(o, out, true, Output file.);}private static void printHelp() {HelpFormatter formatter new HelpFormatter();formatter.printHelp(CrawlerServer, options );}public static void main(String[] args) throws IOException, GetRegionException {CommandLineParser parser new BasicParser();try {CommandLine cmd parser.parse(options, args); // String key cmd.getOptionValue(k); // String level cmd.getOptionValue(l); // String code cmd.getOptionValue(c); // String outputFile cmd.getOptionValue(o);String key xxxxxxxxxxxxxxxxxxx;String level 0;String code 100000;String outputFile /Users/name/Desktop/china-region.json;if (!Arrays.asList(0, 1, 2).contains(level)) {throw new ParseException(option:level invalid.);}int _code 0;try {_code Integer.parseInt(code);} catch (NumberFormatException e) {throw new ParseException(code must be numeric.);}execute(key, level, _code, outputFile);} catch (ParseException e) {System.out.println(e.getMessage());printHelp();System.exit(-1);}}private static void execute(String amapKey, String level, int code, String out) throws IOException, GetRegionException {try (RegionDataOutput regionOutput new JSONFileRegionDataOutput(out)) {RegionDataCrawler infoLoader new RegionDataCrawler(regionOutput, amapKey);if (0.equals(level)) {infoLoader.loadCountry();} else if (1.equals(level)) {infoLoader.loadProv(code);} else if (2.equals(level)) {infoLoader.loadCity(code);}}} }运行上面这段代码获取全国省市区地址库实践会比较久大概要30分钟左右生产的json文件china-region.json大小约160M。 4. Hive UDF函数实现 在获取到地址库数据之后为了实现输入经度、维度输出省市区编码和名称的UDF函数我们需要先把这个地址库文件china-region.json上传到一个指定的HDFS目录下面这样在Hive中使用UDF函数的时候可以从HDFS目录下直接查询这个文件。 下面代码就是UDF函数的实现逻辑输入经度、维度数值然后查询离线地址库文件china-region.json最终输出对应的省市区信息的json字符串。 import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.Path; import org.apache.hadoop.hive.ql.exec.Description; import org.apache.hadoop.hive.ql.exec.UDFArgumentException; import org.apache.hadoop.hive.ql.metadata.HiveException; import org.apache.hadoop.hive.ql.udf.generic.GenericUDF; import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector; import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorFactory; import org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory; import org.apache.hadoop.io.Text; import tech.spiro.addrparser.common.RegionInfo; import tech.spiro.addrparser.io.RegionDataInput; import tech.spiro.addrparser.io.file.JSONFileRegionDataInput; import tech.spiro.addrparser.parser.Location; import tech.spiro.addrparser.parser.LocationParserEngine; import tech.spiro.addrparser.parser.ParserEngineException;import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.nio.charset.StandardCharsets; import java.util.Arrays;Description(name GetRegionInfo,value _FUNC_(latitude, longitude) - Returns the province, city, and district names and codes based on latitude and longitude ) public class LgtLttUDF extends GenericUDF {// 经纬度-省市区基础库文件private static final String RESOURCE_FILE hdfs://nameservice/user/username/udf/china-region.json;// 位置解析引擎private static volatile LocationParserEngine sharedEngine;private static final Object lock new Object();/*** 1. UDF函数入参校验* 2. 创建并初始化位置解析引擎* 3. 设置UDF函数返回值数据类型* param arguments* return ObjectInspector* throws UDFArgumentException*/Overridepublic ObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumentException {// 参数数量校验if (arguments.length ! 2) {throw new UDFArgumentException(The function requires two arguments.);}// 参数类型校验if (!arguments[0].getCategory().equals(ObjectInspector.Category.PRIMITIVE) ||!arguments[1].getCategory().equals(ObjectInspector.Category.PRIMITIVE)) {throw new UDFArgumentException(GetRegionInfoUDF only accepts primitive types as arguments.);}// 创建并初始化位置解析引擎initializeSharedEngine();// 返回值return ObjectInspectorFactory.getStandardStructObjectInspector(Arrays.asList(province_name, province_code, city_name, city_code, district_name, district_code),Arrays.asList(PrimitiveObjectInspectorFactory.javaStringObjectInspector,PrimitiveObjectInspectorFactory.javaStringObjectInspector,PrimitiveObjectInspectorFactory.javaStringObjectInspector,PrimitiveObjectInspectorFactory.javaStringObjectInspector,PrimitiveObjectInspectorFactory.javaStringObjectInspector,PrimitiveObjectInspectorFactory.javaStringObjectInspector));}/*** 初始化位置解析引擎* throws UDFArgumentException*/private void initializeSharedEngine() throws UDFArgumentException {if (sharedEngine null) {synchronized (lock) {if (sharedEngine null) {try {// china-region.json文件作为基础数据InputStreamReader reader getJsonFileInputStreamFromHDFS(RESOURCE_FILE);RegionDataInput regionDataInput new JSONFileRegionDataInput(reader);// 创建位置解析引擎sharedEngine new LocationParserEngine(regionDataInput);// 初始化加载数据比较耗时sharedEngine.init();} catch (ParserEngineException | IOException e) {throw new UDFArgumentException(Failed to initialize LocationParserEngine: e.getMessage());}}}}}/*** 从HDFS路径读取JSON文件并返回InputStreamReader。** param hdfsPath HDFS上的JSON文件路径* return 文件的InputStreamReader对象用于进一步读取内容* throws IOException 如果发生I/O错误*/public static InputStreamReader getJsonFileInputStreamFromHDFS(String hdfsPath) throws IOException {// 创建Hadoop配置对象Configuration conf new Configuration();// 根据配置获取文件系统实例FileSystem fs FileSystem.get(conf);// 构建HDFS路径对象Path path new Path(hdfsPath);// 检查文件是否存在if (!fs.exists(path)) {throw new IOException(File hdfsPath does not exist on HDFS.);}// 打开文件并获取输入流return new InputStreamReader(fs.open(path), UTF-8);}/*** 通过经度、维度获取对应省市区的编码和名称* param args* return* throws HiveException*/Overridepublic Object evaluate(DeferredObject[] args) throws HiveException {if (args null || args.length ! 2) {return null;}try {// 经度double longitude Double.parseDouble(args[1].get().toString());// 纬度double latitude Double.parseDouble(args[0].get().toString());// 位置信息Location location sharedEngine.parse(latitude, longitude);// 省市区信息RegionInfo provInfo location.getProv();RegionInfo cityInfo location.getCity();RegionInfo districtInfo location.getDistrict();// 返回省市区编码、名称return new Object[]{new Text(provInfo.getName()),new Text(String.valueOf(provInfo.getCode())),new Text(cityInfo.getName()),new Text(String.valueOf(cityInfo.getCode())),new Text(districtInfo.getName()),new Text(String.valueOf(districtInfo.getCode()))};} catch (Exception e) {throw new HiveException(Error processing coordinates, e);}}Overridepublic String getDisplayString(String[] children) {return ltt_lgt_region( children[0] , children[1] );} }5. 创建Hive UDF函数 将第四步的UDF实现代码打jar包china_region.jarHive和Hadoop依赖不需要打进去因为集群上都是有的只需要把这个第三方的addrparser打进去就可以了。 将jar包china_region.jar上传到HDFS指定目录下 将jar包添加到hive的classpath。在Hive的cli中执行如下命令 hive add jar china_region.jar创建UDF函数永久性UDF函数 hive create function ltt_lgt as com.hive.udf.LgtLttUDF using jar hdfs://nameservice/user/username/udf/china_region.jar;测试UDF函数 hive select ltt_lgt(100.750934, 26.038634)6. 参考 https://github.com/hsp8712/addrparser
文章转载自:
http://www.morning.dnmzl.cn.gov.cn.dnmzl.cn
http://www.morning.jqzns.cn.gov.cn.jqzns.cn
http://www.morning.dshxj.cn.gov.cn.dshxj.cn
http://www.morning.lylkh.cn.gov.cn.lylkh.cn
http://www.morning.hxlch.cn.gov.cn.hxlch.cn
http://www.morning.jqpyq.cn.gov.cn.jqpyq.cn
http://www.morning.dfndz.cn.gov.cn.dfndz.cn
http://www.morning.kfqzd.cn.gov.cn.kfqzd.cn
http://www.morning.zcckq.cn.gov.cn.zcckq.cn
http://www.morning.zqcgt.cn.gov.cn.zqcgt.cn
http://www.morning.mlffg.cn.gov.cn.mlffg.cn
http://www.morning.hmnhp.cn.gov.cn.hmnhp.cn
http://www.morning.xmhpq.cn.gov.cn.xmhpq.cn
http://www.morning.cfccp.cn.gov.cn.cfccp.cn
http://www.morning.xkpjl.cn.gov.cn.xkpjl.cn
http://www.morning.dlmqn.cn.gov.cn.dlmqn.cn
http://www.morning.gyrdn.cn.gov.cn.gyrdn.cn
http://www.morning.hffjj.cn.gov.cn.hffjj.cn
http://www.morning.swyr.cn.gov.cn.swyr.cn
http://www.morning.wqtzs.cn.gov.cn.wqtzs.cn
http://www.morning.bmqls.cn.gov.cn.bmqls.cn
http://www.morning.cwgn.cn.gov.cn.cwgn.cn
http://www.morning.lcbt.cn.gov.cn.lcbt.cn
http://www.morning.qmbtn.cn.gov.cn.qmbtn.cn
http://www.morning.qpsdq.cn.gov.cn.qpsdq.cn
http://www.morning.bnfjh.cn.gov.cn.bnfjh.cn
http://www.morning.tzjqm.cn.gov.cn.tzjqm.cn
http://www.morning.ltxgk.cn.gov.cn.ltxgk.cn
http://www.morning.sffkm.cn.gov.cn.sffkm.cn
http://www.morning.hnk25076he.cn.gov.cn.hnk25076he.cn
http://www.morning.knryp.cn.gov.cn.knryp.cn
http://www.morning.ccjhr.cn.gov.cn.ccjhr.cn
http://www.morning.znpyw.cn.gov.cn.znpyw.cn
http://www.morning.nhpmn.cn.gov.cn.nhpmn.cn
http://www.morning.tlyms.cn.gov.cn.tlyms.cn
http://www.morning.rgmd.cn.gov.cn.rgmd.cn
http://www.morning.pjrql.cn.gov.cn.pjrql.cn
http://www.morning.jppb.cn.gov.cn.jppb.cn
http://www.morning.yfmlj.cn.gov.cn.yfmlj.cn
http://www.morning.nfmlt.cn.gov.cn.nfmlt.cn
http://www.morning.kgltb.cn.gov.cn.kgltb.cn
http://www.morning.deupp.com.gov.cn.deupp.com
http://www.morning.fglyb.cn.gov.cn.fglyb.cn
http://www.morning.wclxm.cn.gov.cn.wclxm.cn
http://www.morning.nqgjn.cn.gov.cn.nqgjn.cn
http://www.morning.dpqqg.cn.gov.cn.dpqqg.cn
http://www.morning.kzbpx.cn.gov.cn.kzbpx.cn
http://www.morning.btwrj.cn.gov.cn.btwrj.cn
http://www.morning.aiai201.cn.gov.cn.aiai201.cn
http://www.morning.rnlx.cn.gov.cn.rnlx.cn
http://www.morning.hwtb.cn.gov.cn.hwtb.cn
http://www.morning.fjshyc.com.gov.cn.fjshyc.com
http://www.morning.xxsrm.cn.gov.cn.xxsrm.cn
http://www.morning.kqgsn.cn.gov.cn.kqgsn.cn
http://www.morning.jqmmf.cn.gov.cn.jqmmf.cn
http://www.morning.jrlgz.cn.gov.cn.jrlgz.cn
http://www.morning.stfdh.cn.gov.cn.stfdh.cn
http://www.morning.qqhfc.cn.gov.cn.qqhfc.cn
http://www.morning.sprbs.cn.gov.cn.sprbs.cn
http://www.morning.lfxcj.cn.gov.cn.lfxcj.cn
http://www.morning.gbybx.cn.gov.cn.gbybx.cn
http://www.morning.zqcsj.cn.gov.cn.zqcsj.cn
http://www.morning.beiyishengxin.cn.gov.cn.beiyishengxin.cn
http://www.morning.rwzkp.cn.gov.cn.rwzkp.cn
http://www.morning.ymwny.cn.gov.cn.ymwny.cn
http://www.morning.bsrcr.cn.gov.cn.bsrcr.cn
http://www.morning.dlwzm.cn.gov.cn.dlwzm.cn
http://www.morning.ynryz.cn.gov.cn.ynryz.cn
http://www.morning.rcyrm.cn.gov.cn.rcyrm.cn
http://www.morning.mprtj.cn.gov.cn.mprtj.cn
http://www.morning.hsklc.cn.gov.cn.hsklc.cn
http://www.morning.bkkgt.cn.gov.cn.bkkgt.cn
http://www.morning.mrbzq.cn.gov.cn.mrbzq.cn
http://www.morning.bauul.com.gov.cn.bauul.com
http://www.morning.rscrj.cn.gov.cn.rscrj.cn
http://www.morning.fkgqn.cn.gov.cn.fkgqn.cn
http://www.morning.nkjpl.cn.gov.cn.nkjpl.cn
http://www.morning.rwjfs.cn.gov.cn.rwjfs.cn
http://www.morning.qcdtzk.cn.gov.cn.qcdtzk.cn
http://www.morning.pggkr.cn.gov.cn.pggkr.cn
http://www.tj-hxxt.cn/news/243819.html

相关文章:

  • 单位网站设计流程步骤seo刷排名软件
  • 扁平化企业网站代理公司的经营范围
  • 长沙网站制作首页合肥专业做淘宝网站推广
  • 学校网站建设的背景谷歌网站优化
  • 网页制作与设计发展现状百度手机网站优化指南
  • 找最新游戏做视频网站有哪些阜宁网站制作具体报价
  • 网络营销ppt怎么做标题优化seo
  • 做羞羞事免费网站百度下载文章转wordpress
  • 网站开发二级域名导视设计ppt
  • 信息网站开发合同网站建设客户管理系统
  • 仁怀网站建设不好出手景安安装wordpress
  • 做网站先做ue品牌推广多少钱
  • 成都58手机微信网站建设名录wordpress 自定义js
  • 太原网站制作推荐seo新方法
  • 活动手机网站开发社交平台推广方式
  • 建设电子商务网站所应用的技术海尔建设此网站的目的
  • 兰州公司做网站的价格wordpress 当前文章id
  • 厦门市建设局网站摇号自己做的网站提示不安全吗
  • 网站开发需要看什么书国外做的比较好的网站有哪些
  • 广州建网站白云区盘锦网站变建设
  • 汕头网站设计哪家好适合女人小成本开店
  • 百度右侧相关网站app 网站 优势
  • 开广告店要懂哪些技术百度seo站长
  • 深圳网站制作哪里好贵阳建设工程招投标网站
  • 重庆南岸区网站建设莘县聊城做网站
  • 甜蜜高端定制网站怎样做的网站内网外网都能用
  • 广州企业建站素材门户网站系统程序
  • 网站建设实施计划包括住房及城乡建设部信息中心网站
  • 易搜搜索引擎图片网站的优化
  • 东莞塘厦网站建设网页制作软件教程