星火SQL - 使用特定的SQL语句从MS SQL服务器的负载数据,而不是表名 [英] Spark SQL - load data from MS SQL server using particular SQL statement, not table name

查看:136
本文介绍了星火SQL - 使用特定的SQL语句从MS SQL服务器的负载数据,而不是表名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想我失去了一些东西,但找不出什么。
我想加载使用特定的SQL语句使用SQLContext和JDBC数据

I think I am missing something but can't figure what. I want to load data using SQLContext and JDBC using particular sql statement like

select top 1000 text from table1 with (nolock)
where threadid in (
  select distinct id from table2 with (nolock)
  where flag=2 and date >= '1/1/2015' and  userid in (1, 2, 3)
)

哪种方法SQLContext我应该使用?例如只见始终指定表名和上,下缘。

Which method of SQLContext should I use? Examples I saw always specify table name and lower and upper margin.

先谢谢了。

推荐答案

您应该通过一个有效的子查询作为 DBTABLE 参数。例如,在斯卡拉:

You should pass a valid subquery as a dbtable argument. For example in Scala:

val query = """(SELECT TOP 1000 
  --and the rest of your query
  -- ...
) AS tmp"""

val url: String = ??? 

val jdbcDF = sqlContext.read.format("jdbc")
  .options(Map("url" -> url, "dbtable" -> query))
  .load()

这篇关于星火SQL - 使用特定的SQL语句从MS SQL服务器的负载数据,而不是表名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆