工作需要做查询并导出数据的接口,考虑了SpringBoot + Spark 和 Impala,Spark只测试了本地模式,时间有限暂时没有测试yarn模式,但是Spark更适合做数据分析,查询Impala 是比较高效的,选择了以 Impala 做查询引擎。这里整合下 Impala 做个记录。不过因为项目有其他处理模块,所以只把Impala部分拆分出来,是完整的独立模块。
目录
- @SpringBootApplication
- @Controller
- @Service
- Impala查询模块
- @configuration
- Result请求结果类
- Constants常量类
- con.properties
- application.properties
- pom.xml
层级关系

@SpringBootApplication
package com.sm
import org.springframework.boot.SpringApplication
import org.springframework.boot.autoconfigure.{EnableAutoConfiguration, SpringBootApplication}
import org.springframework.context.annotation.ComponentScan
/**
* SpringBoot 入口
*
* create by LiuJinHe 2019/9/23
*/
@EnableAutoConfiguration
@ComponentScan
@SpringBootApplication
class CrowdPackageApp
object CrowdPackageApp extends App {
SpringApplication.run(classOf[CrowdPackageApp])
}
@Controller
package com.sm.controller
import com.sm.service.CrowdService
import com.sm.service.impl.CrowdServiceImpl
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.web.bind.annotation.{CrossOrigin, RequestMapping, RequestMethod, RequestParam, ResponseBody, RestController}
/**
* 请求映射地址
*
* create by LiuJinHe 2019/9/23
*/
@RestController
@CrossOrigin
class CrowdController @Autowired()(crowdService:CrowdService){
/**
* 人群包导出请求
*/
@RequestMapping(value = Array("/crowd"), method = Array(RequestMethod.GET))
@ResponseBody
def exportCrowd(@RequestParam("channel_id") channelId: Int, @RequestParam("cp_game_ids") cpGameIds: String,
@RequestParam("action_type") actionType: Int, @RequestParam("os") os: Int,
@RequestParam("begin_time") beginTime: String, @RequestParam("end_time") endTime: String): String = {
crowdService.reqCrowd(channelId, cpGameIds, actionType, os, beginTime, endTime)
}
}
@Service
首先是 Trait,方便以后业务扩展。
package com.sm.service
/**
* 业务抽象类
*
* create by LiuJinHe 2019/9/24
*/
trait CrowdService {
def reqCrowd(channelId: Int, cpGameIds: String, actionType: Int, os: Int, beginTime: String, endTime: String):String
}
实现类
有其他业务代码,这里只拆分了Impala的。
package com.sm.service.impl
import scala.io.Sour

最低0.47元/天 解锁文章
1012

被折叠的 条评论
为什么被折叠?



