用户工具

站点工具


call

差别

这里会显示出您选择的修订版和当前版本之间的差别。

到此差别页面的链接

两侧同时换到之前的修订记录 前一修订版
后一修订版
前一修订版
call [2019/12/29 14:44]
jinlong [批量数据接口调用]
call [2020/07/12 12:07] (当前版本)
行 112: 行 112:
 ==== 环境配置 ==== ==== 环境配置 ====
  
 +修改application.properties文件,主要修改以下内容:
  
 +  * spring.datasource.* : 数据库相关配置
 +  * eppdev.mlib.consumer.basic-url:​ 服务网关的基础地址
 +  * eppdev.mlib.batch.model-code:​ 模型编码
 +  * eppdev.mlib.batch.input-table.name:​ 输出表的表名
 +  * eppdev.mlib.batch.input-table.key:​ 输入表主键
 +  * eppdev.mlib.batch.input-table.columns:​ 输出表需要查询的字段列表
 +  * eppdev.mlib.batch.input-table.where:​ 定制查询条件,可以包括参数,用于命令传参数
 +  * eppdev.mlib.batch.fetch-size:​ 每次读取的数据量,避免一次性加载过量数据
 +  * eppdev.mlib.batch.output-table.name:​ 输出库表表名
 +  * eppdev.mlib.batch.output-table.key:​ 输出表的主键名称
 +  * eppdev.mlib.batch.output-table.column-maps:​ 输出字段的映射
  
-==== 执行调用 ====+> 其中spring.datasource.*配置模式同普通springboot工程, eppdev.mlib相关配置示例如下:
  
 +<​code>​
 +eppdev.mlib.consumer.basic-url = http://​localhost:​11524/​consumer ​
 +eppdev.mlib.batch.model-code = test-01
 +eppdev.mlib.batch.input-table.name = test_model_input
 +eppdev.mlib.batch.input-table.key = id
 +eppdev.mlib.batch.input-table.columns = id, sepal_width as `sepal.width`,​ sepal_height as `sepal.height`,​ petal_width as `petal.width`,​ petal_height as `petal.height`
 +eppdev.mlib.batch.input-table.where = create_time >= ${begin_time} ​ and create_time <= ${end_time}
 +eppdev.mlib.batch.fetch-size = 1000
 +eppdev.mlib.batch.output-table.name = test_model_output
 +eppdev.mlib.batch.output-table.key = id
 +eppdev.mlib.batch.output-table.column-maps = probability(Setosa) as probability_setosa,​ probability(Virginica) as probability_virginica,​ probability(Versicolor) as probability_versicolor,​ variety as variety
 +</​code>​
  
 +
 +==== 执行调用 ====
 +
 +<code shell>
 +./​eppdev-mlib-sdk-batch.jar -Dbegin_time="​2019-11-20 11:​24:​32"​ -Dend_time="​2019-11-21 12:​23:​24"​
 +</​code>​
  
  
 ===== HIVE UDF方式进行调用 ===== ===== HIVE UDF方式进行调用 =====
 +
 +使用hive udf进行模型调用,有以下两种方案:
 +
 +  * 使用eppdev-mlib-sdk-hive-udf原生方案,在进行udf调用的时候需要首先输入
 +    网关地址url、模型编码信息
 +  * 使用自定义udf,在进行调用的时候可以配置无需输入网关地址、模型编码信
 +
 +
 +==== 使用原生方案 ====
 +
 +=== 下载相应的软件包 ===
 +
 +目前eppdev-mlib提供的原生udf支持hive1.2,​ 2.3, 3.1三个版本,需要分别下载不同
 +的jar包来完成模型的调用:
 +
 +  * hive1.2: eppdev-mlib-sdk-hive-udf12.jar
 +  * hive2.3: eppdev-mlib-sdk-hive-udf23.jar
 +  * hive3.1: eppdev-mlib-sdk-hive-udf31.jar
 +
 +=== 上传jar到hdfs中 ===
 +
 +以hive2.3为例:
 +
 +<code shell>
 +hdfs dfs put eppdev-mlib-sdk-hive-udf23.jar /​user/​udf/​hive/​
 +</​code>​
 +
 +=== 在hive中创建自定义函数 ===
 +
 +<code sql>
 +create function eppdev_to_json as '​cn.eppdev.mlib.sdk.hive.udf.EppdevMlibToJsonUDF' ​
 +     using jar '​hdfs://​user/​udf/​hive/​eppdev-mlib-sdk-hive-udf23.jar';​
 +create function eppdev_mlib_calc as '​cn.eppdev.mlib.sdk.hive.udf.EppdevMlibCalcUDF'​
 +     using jar '​hdfs://​user/​udf/​hive/​eppdev-mlib-sdk-hive-udf23.jar';​
 +</​code>​
 +
 +
 +=== 在hive中进行模型调用 ===
 +
 +进行hive调用可以有两种方式:
 +
 +  - 输入3个参数(网关地址、模型编码、请求数据json),可以获取到全量的模型输入
 +  - 输入4个参数(网关地址、模型编码、请求json和所需的输出项),可以获取指定的输出项
 +
 +方法1: 三个参数获取结果json
 +
 +<code sql>
 +select ​
 +    eppdev_mlib_calc(
 +        '​http://​localhost:​11541/​consumer',​
 +        '​test-01',​
 +        eppdev_to_json(
 +            '​sepal.width',​ sepal_with,
 +            '​sepal.height',​ sepal_height,​
 +            '​petal.width',​ petal_width,​
 +            '​petal.height',​ petal_height
 +        )
 +    ) as full_result
 +from iris_data;
 +</​code>​
 +
 +输出结果为全量的json:
 +
 +<code json>
 +{
 +    "​probability(Setosa)":​ 1.0,
 +    "​probability(Virginica)":​ 0.0,
 +    "​probability(Versicolor)":​ 0.0,
 +    "​variety":​ "​Setosa"​
 +}
 +</​code>​
 +
 +
 +方法2:输入4个参数,直接获取具体结果
 +
 +<code sql>
 +select ​
 +    eppdev_mlib_calc(
 +        '​http://​localhost:​11541/​consumer',​
 +        '​test-01',​
 +        eppdev_to_json(
 +            '​sepal.width',​ sepal_with,
 +            '​sepal.height',​ sepal_height,​
 +            '​petal.width',​ petal_width,​
 +            '​petal.height',​ petal_height
 +        ),
 +        '​variety'​
 +    ) as variety
 +from iris_data;
 +</​code>​
 +
 +输出结果为veriety结果,如:Setosa
 +
 +
call.1577601854.txt.gz · 最后更改: 2020/07/12 12:07 (外部编辑)