1

I am testing read and write operations between hive table and pandas.

I am able to read from hive to pandas data frame successfully using the below code.

    from impala.dbapi import connect
    import pandas as pd
    conn = connect(host='myhostaddress',port=21050,kerberos_service_name='impala',
                 auth_mechanism='GSSAPI',use_ssl=True,
                  ca_cert='/opt/cloudera/...pem',
                  database='mydb'
                 )
    cursor = conn.cursor()


    df = pd.read_sql('select * from my_table',con=conn)

I am able to read the table from hive to pandas df.

Now trying to write a simple pandas df to hive table, using below code.

    test_df = pd.DataFrame({'A':[1,2,3],'B':[4,5,6]})
    test_df.to_sql('test_table',con=conn)

But, I'm getting an error

DatabaseErrorTraceback (most recent call last)
<ipython-input-24-967eed4bac18> in<module>()
----> 1 test_df.to_sql('test_table',con=conn)
    ....
    ....
DatabaseError: Execution failed on sql: SELECT name FROM sqlite_master WHERE type='table' AND name=?;
AnalysisException: Could not resolve table reference: 'sqlite_master'<br>
unable to rollback
mazaneicha
  • 8,794
  • 4
  • 33
  • 52
Pyd
  • 6,017
  • 18
  • 52
  • 109

0 Answers0