Читать книгу SAS Viya - Kevin D. Smith - Страница 9

Importing SWAT and Getting Connected

Оглавление

The only thing you need to know about the CAS server in order to get connected is the host name, the port number, your user name, and your password. The SWAT package contains the CAS class that is used to communicate with the server. The arguments to the CAS class are hostname, port, username, and password1, in that order. Note that you can use the REST interface by specifying the HTTP port that is used by the CAS server. The CAS class can autodetect the port type for the standard CAS port and HTTP. However, if you use HTTPS, you must specify protocol=’https’ as a keyword argument to the CAS constructor. You can also specify ‘cas’ or ‘http’ to explicitly override autodetection.

In [1]: import swat

In [2]: conn = swat.CAS('server-name.mycompany.com', 5570,

...: 'username', 'password')

When you connect to CAS, it creates a session on the server. By default, all resources (CAS actions, data tables, options, and so on) are available only to that session. Some resources can be promoted to a global scope, which we discuss later in the book.

To see what CAS actions are available, use the help method on the CAS connection object, which calls the help action on the CAS server.

In [3]: out = conn.help()

NOTE: Available Action Sets and Actions:

NOTE: accessControl

NOTE: assumeRole - Assumes a role

NOTE: dropRole - Relinquishes a role

NOTE: showRolesIn - Shows the currently active role

NOTE: showRolesAllowed - Shows the roles that a user

is a member of

NOTE: isInRole - Shows whether a role is assumed

NOTE: isAuthorized - Shows whether access is authorized

NOTE: isAuthorizedActions - Shows whether access is

authorized to actions

NOTE: isAuthorizedTables - Shows whether access is authorized

to tables

NOTE: isAuthorizedColumns - Shows whether access is authorized

to columns

NOTE: listAllPrincipals - Lists all principals that have

explicit access controls

NOTE: whatIsEffective - Lists effective access and

explanations (Origins)

NOTE: partition - Partitions a table

NOTE: recordCount - Shows the number of rows in a Cloud

Analytic Services table

NOTE: loadDataSource - Loads one or more data source interfaces

NOTE: update - Updates rows in a table

The printed notes describe all of the CAS action sets and the actions in those action sets. The help action also returns the action set and action information as a return value. The return values from all actions are in the form of CASResults objects, which are a subclass of the Python collections.OrderedDict class. To see a list of all of the keys, use the keys method just as you would with any Python dictionary. In this case, the keys correspond to the names of the CAS action sets.

In [4]: list(out.keys())

Out[4]:

['accessControl',

'builtins',

'configuration',

'dataPreprocess',

'dataStep',

'percentile',

'search',

'session',

'sessionProp',

'simple',

'table']

Printing the contents of the return value shows all of the top-level keys as sections. In the case of the help action, the information about each action set is returned in a table in each section. These tables are stored in the dictionary as Pandas DataFrames.

In [5]: out

Out[5]:

[accessControl]

name description

0 assumeRole Assumes a role

1 dropRole Relinquishes a role

2 showRolesIn Shows the currently active role

3 showRolesAllowed Shows the roles that a user is a mem...

4 isInRole Shows whether a role is assumed

5 isAuthorized Shows whether access is authorized

6 isAuthorizedActions Shows whether access is authorized t...

7 isAuthorizedTables Shows whether access is authorized t...

8 isAuthorizedColumns Shows whether access is authorized t...

9 listAllPrincipals Lists all principals that have expli...

10 whatIsEffective Lists effective access and explanati...

11 listAcsData Lists access controls for caslibs, t...

12 listAcsActionSet Lists access controls for an action ...

13 repAllAcsCaslib Replaces all access controls for a c...

14 repAllAcsTable Replaces all access controls for a t...

15 repAllAcsColumn Replaces all access controls for a c...

16 repAllAcsActionSet Replaces all access controls for an ...

17 repAllAcsAction Replaces all access controls for an ...

18 updSomeAcsCaslib Adds, deletes, and modifies some acc...

19 updSomeAcsTable Adds, deletes, and modifies some acc...

... truncated ...

+ Elapsed: 0.0034s, user: 0.003s, mem: 0.164mb

Since the output is based on the dictionary object, you can access each key individually as well.

In [6]: out['builtins']

Out[6]:

name description

0 addNode Adds a machine to the server

1 removeNode Remove one or more machines from the...

2 help Shows the parameters for an action o...

3 listNodes Shows the host names used by the server

4 loadActionSet Loads an action set for use in this ...

5 installActionSet Loads an action set in new sessions ...

6 log Shows and modifies logging levels

7 queryActionSet Shows whether an action set is loaded

8 queryName Checks whether a name is an action o...

9 reflect Shows detailed parameter information...

10 serverStatus Shows the status of the server

11 about Shows the status of the server

12 shutdown Shuts down the server

13 userInfo Shows the user information for your ...

14 actionSetInfo Shows the build information from loa...

15 history Shows the actions that were run in t...

16 casCommon Provides parameters that are common ...

17 ping Sends a single request to the server...

18 echo Prints the supplied parameters to th...

19 modifyQueue Modifies the action response queue s...

20 getLicenseInfo Shows the license information for a ...

21 refreshLicense Refresh SAS license information from...

22 httpAddress Shows the HTTP address for the serve...

The keys are commonly alphanumeric, so the CASResults object was extended to enable you to access keys as attributes as well. This just keeps your code a bit cleaner. However, you should be aware that if a result key has the same name as a Python dictionary method, the dictionary method takes precedence. In the following code, we access the builtins key again, but this time we access it as if it were an attribute.

In [7]: out.builtins

Out[7]:

name description

0 addNode Adds a machine to the server

1 removeNode Remove one or more machines from the...

2 help Shows the parameters for an action o...

3 listNodes Shows the host names used by the server

4 loadActionSet Loads an action set for use in this ...

5 installActionSet Loads an action set in new sessions ...

6 log Shows and modifies logging levels

7 queryActionSet Shows whether an action set is loaded

8 queryName Checks whether a name is an action o...

9 reflect Shows detailed parameter information...

10 serverStatus Shows the status of the server

11 about Shows the status of the server

12 shutdown Shuts down the server

13 userInfo Shows the user information for your ...

14 actionSetInfo Shows the build information from loa...

15 history Shows the actions that were run in t...

16 casCommon Provides parameters that are common ...

17 ping Sends a single request to the server...

18 echo Prints the supplied parameters to th...

19 modifyQueue Modifies the action response queue s...

20 getLicenseInfo Shows the license information for a ...

21 refreshLicense Refresh SAS license information from...

22 httpAddress Shows the HTTP address for the serve...

SAS Viya

Подняться наверх