Apache spark 无法使用pyspark从配置单元表查询复杂的SQL语句
您好,我正在尝试从spark上下文查询配置单元表 我的代码:Apache spark 无法使用pyspark从配置单元表查询复杂的SQL语句,apache-spark,hive,pyspark,apache-spark-sql,Apache Spark,Hive,Pyspark,Apache Spark Sql,您好,我正在尝试从spark上下文查询配置单元表 我的代码: from pyspark.sql import HiveContext hive_context = HiveContext(sc) bank = hive_context.table('select * from db.table_name') bank.show() 像这样的简单查询工作正常,没有任何错误。 但当我尝试下面的查询时 query = """with table1 as ( select
from pyspark.sql import HiveContext
hive_context = HiveContext(sc)
bank = hive_context.table('select * from db.table_name')
bank.show()
像这样的简单查询工作正常,没有任何错误。
但当我尝试下面的查询时
query = """with table1 as ( select distinct a,b
from db_first.table_first
order by b )
--select * from table1 order by b
,c as ( select *
from db_first.table_two)
--select * from c
,d as ( select *
from c
where upper(e) = 'Y')
--select * from d
,f as ( select table1.b
,cast(regexp_extract(g,'(\\d+)-(A|B)-
(\\d+)(.*)',1) as Int) aid1
,regexp_extract(g,'(\\d+)-(A|B)-
(\\d+)(.*)',2) aid2
,cast(regexp_extract(g,'(\\d+)-(A|B)-
(\\d+)(.*)',3) as Int) aid3
,from_unixtime(cast(substr(lastdbupdatedts,1,10) as int),"yyyy-MM-dd
HH:mm:ss") lastupdts
,d.*
from d
left outer join table1
on d.hiba = table1.a)
select * from f order by b,aid1,aid2,aid3 limit 100"""
我得到下面的错误,请帮助
ParseExceptionTraceback (most recent call last)
<ipython-input-27-cedb6fad210d> in <module>()
3 hive_context = HiveContext(sc)
4 #bank = hive_context.table("bdalab.test_prodapt_inv")
----> 5 bank = hive_context.table(first)
ParseException: u"\nmismatched input '*' expecting <EOF>(line 1, pos 7)\n\n== SQL ==\nselect *
ParseExceptionTraceback(最近一次调用)
在()
3配置单元上下文=配置单元上下文(sc)
4#bank=hive_context.table(“bdalab.test_prodapt_inv”)
---->5 bank=hive_context.table(第一个)
ParseException:u“\n应为匹配的输入“*”(第1行,位置7)\n\n==SQL==\n选择*
如果我们使用sql查询,您需要使用.sql
方法,而不是.table
方法
1.使用.table方法,我们需要提供表名:
>>> hive_context.table("<db_name>.<table_name>").show()
>>> first ="with cte..."
>>> hive_context.sql(first).show()
@PA,您可以使用JDBC方法读取impala表(或者)我相信所有impala表都可以在hive中访问(如果是),然后使用
hive\u context.table()
我们可以读取表。