We’re smarter together. Learn from this collection of community knowledge and add your expertise.

SAS® Viya™ Caslib

by SAS Employee UttamKumar on ‎05-25-2017 10:06 AM (687 Views)

In SAS® Viya™ a caslib is an in-memory space on the CAS server to hold tables, access controls, and data source information. A caslib provides access to data from the data source environment and access to in-memory tables that are loaded to CAS from data sources. Caslibs create an association with access controls that define which user groups and individual users are authorized to access the data tables listed within a caslib.

 

Caslib type

A caslib can be personal, pre-defined, or manually added to the CAS server. The user authorization determines the user interaction with each type of caslib.  

 

Personal caslib

A personal caslib can be configured while installing and configuring the CAS server. When a CAS session is initiated, the personal caslib is always available with global scope. This enables users to access CAS tables from any session with the same user ID. For example, in your test SAS Viya environment, you can have ‘casuser’ as the personal caslib.

 

Pre-defined caslib

Pre-defined caslibs are defined and managed by CAS administrators and have global scope. The data access controls are managed by the CAS server administrator to grant the permission to multiple users for caslib access. Pre-defined caslibs are used for popular data sources utilized by a range of CAS users. For example, in your CAS environment, you might have pre-defined caslibs for Hadoop-Hive or Oracle data sources.  

 

Manually added caslib

Authorized users can add caslibs to the CAS server by running a caslib statement from SAS® Studio. In general, the manual caslibs are added in a program where there is need for ad hoc data access and users do not want to share the same data with all other users on the CAS server.   

 

 

Caslib scope

The caslib is an in-memory space in the CAS server to hold tables. When a data table is loaded to the CAS server under caslib, the caslib scope, in association with access controls, facilitates CAS table access for users. Depending on the caslib scope, the CAS table can be shared with other users. There are two scopes for caslibs: session and global.  

 

Session-Scope caslib

When a caslib is defined without including the GLOBAL option, the caslib is a session-scoped caslib. When a table is loaded to the CAS server with session-scoped caslib, the table is available to that specific CAS user session only.  

 

The following SAS code illustrates the creation of a manual caslib (HiveCaslib) defined as a session scope and data loaded to the CAS server within the same caslib. Notice, the CASLIB statement has no GLOBAL option. The PROC CASUTIL statement to load data to the CAS server also does not have the PROMOTE option. The PROMOTE option is valid only when the caslib is defined with global scope.

 

CAS mySession host="gatekrbhdp01.gatehadoop.com" SESSOPTS=( CASLIB=casuser TIMEOUT=999 LOCALE="en_US");

 

/* Assign Std HIVE CASLIB */

caslib hivelib desc="HIVE Caslib"

    datasource=(SRCTYPE="HIVE",SERVER="gatekrbhdp01.gatehadoop.com",    

    HADOOPCONFIGDIR="/opt/sas/hadoop/client_conf/",

    HADOOPJARPATH="/opt/sas/hadoop/client_jar/",

    schema="default",dfDebug=sqlinfo);

 

/* Load HIVE tables (In memory) */

proc casutil;

   load casdata="stocks" casout="stocks" outcaslib="hivelib" incaslib="hivelib";

quit;  

 

 

After loading data, when PROC CASUTIL is executed using the list table statement from the same user session, the output is displayed as a session-local caslib along with associated tables.

 

proc casutil;

   list tables incaslib="hivelib";

run;

 

caslib_1.PNG  

When the same user initiates a new session and tries to access a caslib and table loaded from the previous session, the caslib and table are not available in the new session since it was session-scoped. The following SAS code illustrates the creation of a new session by the same user who is trying to access the caslib and associated table that were loaded in the previous session. Notice the “CAS mySession2…..” statement.

 

CAS mySession2 host="gatekrbhdp01.gatehadoop.com" SESSOPTS=( CASLIB=casuser TIMEOUT=999 LOCALE="en_US");

 

proc casutil;

   list tables incaslib="hivelib";

run;  

 

 

SAS log with error message:

56

57 proc casutil;

NOTE: The UUID 'fadb6249-2976-3146-b7ad-b79bf4809f4d' is connected using session MYSESSION2.

58 ! list tables incaslib="hivelib";

ERROR: The caslib 'hivelib' does not exist in this session.

ERROR: The action stopped due to errors.

59 run;      

 

 

Global-Scope caslib

When a caslib is defined using a CASLIB statement with the GLOBAL option, the caslib is defined as a global-scoped caslib. The global-scoped caslib and associated table could be made available to other users in the CAS server by updating the caslib’s access controls. A group of users or individual users can be included in caslib access controls. If a table is loaded to the CAS server with the PROMOTE option within a global-scoped caslib, the table is available to all users who have access permission to the caslib.  

 

If a table is loaded to the CAS server without the PROMOTE option, within a global-scoped caslib, the table is still personal to the owner and not yet shared with the rest of the users on the CAS server.  

 

The CAS server administrator or authorized user can create session-scoped and global-scoped caslibs, and manage the access controls on caslibs. A table can be promoted from a session caslib to a global caslib.  

 

The following SAS code illustrates the creation of a manual, global-scoped caslib (HiveCaslib) and data load to the CAS server in the same caslib. Notice the CASLIB statement has the GLOBAL option to make it global-scoped and the PROC CASUTIL statement has the PROMOTE option to make it a shared table.

 

CAS mySession host="gatekrbhdp01.gatehadoop.com" SESSOPTS=( CASLIB=casuser TIMEOUT=999 LOCALE="en_US");

/* Assign Std HIVE CASLIB */

caslib hivelib desc="HIVE Caslib"

    datasource=(SRCTYPE="HIVE",SERVER="gatekrbhdp01.gatehadoop.com",    

    HADOOPCONFIGDIR="/opt/sas/hadoop/client_conf/",

    HADOOPJARPATH="/opt/sas/hadoop/client_jar/",

    schema="default",dfDebug=sqlinfo) GLOBAL ;

 

/* Load HIVE tables (In memory) */

proc casutil;

   load casdata="stocks" casout="stocks" outcaslib="hivelib" incaslib="hivelib" PROMOTE ;

quit;  

 

 

After the data is loaded, when the PROC CASUTIL is executed with the list table statement from the same user session, the output displays the caslib as a global-scoped caslib along with associated promoted tables.

 

proc casutil;

    list tables incaslib="hivelib";

run;

 

caslib_2.PNG  

 

Once a global caslib is created, it appears under the list of caslibs on the Configuration tab on the Access Controls window. The CAS administrator can edit and update the user privileges to share the caslibs and associated tables with the rest of the users on the CAS server. A group of users or individual users can be granted access to the global-scoped caslibs on the CAS server. caslib_3.PNG  

 

Once global caslib access control privileges are updated for a user, a new CAS session with the new user (valid user) can access the global CAS table. The following code illustrates the creation of a new CAS session by user sasdemo02 and the access to the CAS table created by user sasdemo01 in the global caslib. Upon execution of the assign _all_ statement, the global caslib is available to user sasdemo02.  

 

CAS mySession2 host="gatekrbhdp01.gatehadoop.com" SESSOPTS=( CASLIB=casuser TIMEOUT=999 LOCALE="en_US");

 

/* Show CASLIB in SAS Studio */

CASLIB _ALL_ ASSIGN;

 

caslib_4.PNG  

The listed CAS data table can be opened by user sasdemo02 from available global caslibs. caslib_5.PNG  

 

User privileges for creating session-scoped and global-scoped caslibs are managed by the CAS administrator using the following screen. A group of users or individual users can be granted permission to create session-scoped and global-scoped caslibs on the CAS server. caslib_6.PNG    

 

Related reading

For more information and documentation about SAS Viya caslibs, see the Documentation Page. You can also read SAS Cloud Analytics Services Fundamentals.   

Contributors
Your turn
Sign In!

Want to write an article? Sign in with your profile.