您好,登錄后才能下訂單哦!
本篇內容主要講解“怎么在SAP Cloud Platform上創建HANA并使用”,感興趣的朋友不妨來看看。本文介紹的方法操作簡單快捷,實用性強。下面就讓小編來帶大家學習“怎么在SAP Cloud Platform上創建HANA并使用”吧!
本文使用的csv文件
SAP HANA XS) enables you to create database schema, tables, views, and sequences as design-time files in the repository.
這個練習里,我們將會使用SAP HANA Extended Application Services (XS)提供的database schema,tables和views來實現數據導入的效果。
The HDBtable syntax is a collective term which includes the different configuration schema for each of the various design-time data artifacts, for example: schema (.hdbschema), sequence (.hdbsequence), table (.hdbtable), and view (.hdbview).
This is why we will be using the SAP HANA HDBtable syntax including Core Data Service (CDS) artifacts instead, which only requires the SAP HANA Web-based Development Workbench available with any SAP HANA MDC on the SAP Cloud Platform. All the objects will be created as design-time and will allow us to adapt the structure easily without reloading the data.
首先在SAP Cloud Platform Neo環境的HANA MDC實例里,打開HANA Web-based development workbench,切換到Catalog視圖:
點擊SQL,使用SQL語句創建一個新的user: MOVIELENS_USER
DROP USER MOVIELENS_USER CASCADE; CREATE USER MOVIELENS_USER PASSWORD Welcome18Welcome18 NO FORCE_FIRST_PASSWORD_CHANGE; ALTER USER MOVIELENS_USER DISABLE PASSWORD LIFETIME; call _SYS_REPO.GRANT_ACTIVATED_ROLE ('sap.hana.ide.roles::CatalogDeveloper' ,'MOVIELENS_USER'); call _SYS_REPO.GRANT_ACTIVATED_ROLE ('sap.hana.ide.roles::Developer' ,'MOVIELENS_USER'); call _SYS_REPO.GRANT_ACTIVATED_ROLE ('sap.hana.ide.roles::EditorDeveloper' ,'MOVIELENS_USER'); call _SYS_REPO.GRANT_ACTIVATED_ROLE ('sap.hana.xs.ide.roles::CatalogDeveloper' ,'MOVIELENS_USER'); call _SYS_REPO.GRANT_ACTIVATED_ROLE ('sap.hana.xs.ide.roles::Developer' ,'MOVIELENS_USER'); call _SYS_REPO.GRANT_ACTIVATED_ROLE ('sap.hana.xs.ide.roles::EditorDeveloper' ,'MOVIELENS_USER'); GRANT EXECUTE on _SYS_REPO.GRANT_ACTIVATED_ROLE TO MOVIELENS_USER WITH GRANT OPTION; GRANT EXECUTE on _SYS_REPO.GRANT_SCHEMA_PRIVILEGE_ON_ACTIVATED_CONTENT TO MOVIELENS_USER WITH GRANT OPTION; GRANT EXECUTE on _SYS_REPO.GRANT_PRIVILEGE_ON_ACTIVATED_CONTENT TO MOVIELENS_USER WITH GRANT OPTION; GRANT EXECUTE on _SYS_REPO.REVOKE_ACTIVATED_ROLE TO MOVIELENS_USER WITH GRANT OPTION; GRANT EXECUTE on _SYS_REPO.REVOKE_SCHEMA_PRIVILEGE_ON_ACTIVATED_CONTENT TO MOVIELENS_USER WITH GRANT OPTION; GRANT EXECUTE on _SYS_REPO.REVOKE_PRIVILEGE_ON_ACTIVATED_CONTENT TO MOVIELENS_USER WITH GRANT OPTION; GRANT "CREATE SCHEMA" TO MOVIELENS_USER; GRANT REPO.READ on "public" TO MOVIELENS_USER; GRANT REPO.MAINTAIN_IMPORTED_PACKAGES on "public" TO MOVIELENS_USER; GRANT REPO.MAINTAIN_NATIVE_PACKAGES on "public" TO MOVIELENS_USER; GRANT REPO.EDIT_NATIVE_OBJECTS on "public" TO MOVIELENS_USER; GRANT REPO.EDIT_IMPORTED_OBJECTS on "public" TO MOVIELENS_USER; GRANT REPO.ACTIVATE_NATIVE_OBJECTS on "public" TO MOVIELENS_USER; GRANT REPO.ACTIVATE_IMPORTED_OBJECTS on "public" TO MOVIELENS_USER;
執行后,該用戶創建成功:
注銷SYSTEM用戶,使用新創建的用戶登錄:
切換到Editor視圖:
在content節點下,右鍵菜單,新建一個Application:
Package維護成public.aa.movielens:
新建三個package,分別為data, hdb和service:
將之前鏈接里提供的csv文件導入data package內:
HANA schema是存放HANA數據庫對象諸如表,視圖,存儲過程等的容器。
新建一個.hdbschema文件,內容如下:
再創建一個user.hdbrole文件:
內容如下:
role public.aa.movielens.hdb::user extends catalog role "sap.pa.apl.base.roles::APL_EXECUTE", "AFLPM_CREATOR_ERASER_EXECUTE", "AFL__SYS_AFL_AFLPAL_EXECUTE" { schema public.aa.movielens.hdb:MOVIELENS.hdbschema: SELECT, EXECUTE, CREATE ANY; }
這個role定義了我們創建的這個應用工作時需要的權限:
最后創建CDS artifacts:
新建一個 data.hdbdd文件:
namespace public.aa.movielens.hdb; @Schema : 'MOVIELENS' context "data" { @Catalog.tableType : #COLUMN Entity LINKS { key MOVIEID : Integer; IMDBID : Integer; TMDBID : Integer; }; @Catalog.tableType : #COLUMN Entity MOVIES { key MOVIEID : Integer; TITLE : String(255); GENRES : String(255); }; @Catalog.tableType : #COLUMN Entity RATINGS { key USERID : Integer; key MOVIEID : Integer; RATING : hana.SMALLDECIMAL; TIMESTAMP : Integer; }; @Catalog.tableType : #COLUMN Entity TAGS { key USERID : Integer; key MOVIEID : Integer; key TAG : String(255); TIMESTAMP : Integer; }; };
使用下列的SQL語句將新創建的user role分配給用戶MOVIELENS_USER:
創建一個table-import配置文件,在里面指定存儲于csv文件里的數據,按照怎樣的邏輯寫入HANA MDC的持久化對象,比如數據庫表里。
hdb package里創建一個新的文件 data.hdbti :
import = [ { table = "public.aa.movielens.hdb::data.LINKS"; schema = "MOVIELENS" ; file = "public.aa.movielens.data:links.csv"; header = true; delimField = ","; delimEnclosing= "\""; }, { table = "public.aa.movielens.hdb::data.MOVIES"; schema = "MOVIELENS" ; file = "public.aa.movielens.data:movies.csv"; header = true; delimField = ","; delimEnclosing = "\""; }, { table = "public.aa.movielens.hdb::data.RATINGS"; schema = "MOVIELENS" ; file = "public.aa.movielens.data:ratings.csv"; header = true; delimField = ","; delimEnclosing= "\""; }, { table = "public.aa.movielens.hdb::data.TAGS"; schema = "MOVIELENS" ; file = "public.aa.movielens.data:tags.csv"; header = true; delimField = ","; delimEnclosing= "\""; } ];
此時執行下列SQL語句,就可以成功從HANA MDC實例的數據庫表里讀取源自csv文件里的數據了:
select 'links' as "table name", count(1) as "row count" from "MOVIELENS"."public.aa.movielens.hdb::data.LINKS" union all select 'movies' as "table name", count(1) as "row count" from "MOVIELENS"."public.aa.movielens.hdb::data.MOVIES" union all select 'ratings' as "table name", count(1) as "row count" from "MOVIELENS"."public.aa.movielens.hdb::data.RATINGS" union all select 'tags' as "table name", count(1) as "row count" from "MOVIELENS"."public.aa.movielens.hdb::data.TAGS";
到此,相信大家對“怎么在SAP Cloud Platform上創建HANA并使用”有了更深的了解,不妨來實際操作一番吧!這里是億速云網站,更多相關內容可以進入相關頻道進行查詢,關注我們,繼續學習!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。