SAP DWC and Python Connected but cannot see views

351 Views Asked by At

I am connected to my DWC space with my Python script using the hdbcli library. I have also connected using SQLAlchemy as well to test. I can see all of my schema that are in DWC.

I have been following this tutorial: https://blogs.sap.com/2021/04/23/connecting-to-sap-data-warehouse-cloud-from-python-via-hdbcli-sqlalchemy-hana_ml/

I created a database user, allowed read and write access as well as allowed my IP address on the whitelist. I can see my schema names but cannot see my views (I created a "new graphical view" in DWC by combining 2 csv files and deployed it). I am not sure what I should be able to see here, but when I run:

engine.dialect.get_view_names(connection=connection, schema= 'TESTSARAHSANCHINI#PYTHON') 
output: []

I even tried creating my own table to push to DWC but it still comes back empty:

new_df = pd.DataFrame({"id": [1,2,3], "col1":["a","b","c"]})
new_df.to_sql("newtable",con=engine, index=False, if_exists="replace")
engine.table_names(schema='TESTSARAHSANCHINI#PYTHON')
output: []

Any ideas please on what am I supposed to do next? How do I add a view and/or see it?

Thank you!! =)

1

There are 1 best solutions below

0
Xavi Polo On

Remeber that HANA schema only shows DWC Views that are of type Analytical Dataset, and are "Exposed".

Anyway, I recommend to try the hana-ml library (from SAP), which allows you to convert a pandas dataframe to a HANA dataframe with hana_ml.dataframe.create_dataframe_from_pandas() and persist the data in HANA in one step.

It also has a progress bar (compatible with jupyter notebooks) which is very useful if you upload a lot of data to HANA.

from hana_ml import dataframe
conn = dataframe.ConnectionContext(address=host,
                                       port=443,
                                       user=username,
                                       password=password)
# query to test connection
hana_df = dataframe.DataFrame(conn, 'select 1 as "TEST" from DUMMY')
hana_df.collect()

# Upload pandas dataframe    
hana_df = dataframe.create_dataframe_from_pandas(connection_context=conn,
                                                    pandas_df=df,
                                                    table_name='MY_TABLE',
                                                    force=True, drop_exist_tab=True)

Note that SCHEMA is not necessary because the DWC User for upload data is specific to a DWC Space and therefore to a single HANA schema.