2

I have a simple impyla code, and I would like to create a pandas dataFrame from my cursor. My code is running but my dataframe is always an empty dataframe. If I run my query directly on impala, the result is not empty. This is how my code looks like:

from impala.dbapi import connect
from impala.util import as_pandas


conn = connect(host='impala_server', port=21051,
               user='user' , password='pass',
               use_ssl=True,
               auth_mechanism='PLAIN')
cursor = conn.cursor()
cursor.execute("SELECT * FROM TABLE")

results = cursor.fetchall()

df = as_pandas(cursor)

print(df.head())   

Help me please, what am I doing wrong?

Latika Agarwal
  • 973
  • 1
  • 6
  • 11
solarenqu
  • 804
  • 4
  • 19
  • 44

2 Answers2

1

Just remove:

results = cursor.fetchall()

from your code. It should work.

timgeb
  • 76,762
  • 20
  • 123
  • 145
1
'results = cursor.fetchall()  ' delete this line and it will be ok.

    from impala.dbapi import connect
    from impala.util import as_pandas
    
    conn = connect(host='****.com', port=****, database='****')
    cursor = conn.cursor()
    cursor.execute('select * from table limit 10')
    df = as_pandas(cursor)
    df.head()

I run the code above, and it run well.

Roberto Caboni
  • 7,252
  • 10
  • 25
  • 39
L.Hunter
  • 21
  • 3