?> addTable - WeAreCAS
table

addTable

Description

The addTable action is a fundamental mechanism for transferring data from a client-side process to the CAS server, creating an in-memory table. Unlike actions like loadTable which load data from server-side sources, addTable is specifically used by client libraries (SAS SWAT for Python, R, Lua) to upload data structures (e.g., Pandas DataFrames, R data frames) directly into a CAS table. It provides detailed control over the resulting table's properties, such as column types, lengths, labels, and memory layout.

table.addTable { append=TRUE | FALSE, caslib="string", columnar=TRUE | FALSE, commitRecords=64-bit-integer, commitSeconds=64-bit-integer, compress=TRUE | FALSE, copies=integer, descending={integer-1, ...}, label="string", maxMBytes=64-bit-integer, memoryFormat="DVR" | "INHERIT" | "STANDARD", orderBy={"variable-name-1", ...}, partition={"variable-name-1", ...}, promote=TRUE | FALSE, recLen=integer, repeat=TRUE | FALSE, replace=TRUE | FALSE, table="table-name", vars={{...}, ...} };
Settings
ParameterDescription
appendSpecifies whether to add rows from the table to an existing table.
caslibSpecifies the target caslib for the table.
columnarSpecifies to create the in-memory table in columnar format.
commitRecordsSpecifies the number of rows for the server to receive before committing the rows to the table.
commitSecondsSpecifies the number of seconds for the server to receive rows before committing the rows to the table.
compressWhen set to True, compresses the target table.
copiesSpecifies the number of redundant copies to make for the rows. Larger values provide greater fault tolerance but use more memory.
descendingSpecifies to reverse the sort order for the specified variables in the orderBy parameter.
labelSpecifies a descriptive label for the table.
maxMBytesSpecifies the maximum amount of physical memory, in megabytes, to allocate for the table.
memoryFormatSpecifies the memory format for the output table (DVR, INHERIT, or STANDARD).
orderBySpecifies the variable names to use for ordering rows within partitions.
partitionSpecifies the variable names to use as partitioning keys.
promoteWhen set to True, the table is added with a global scope, making it accessible to other sessions.
recLenSpecifies the length, in bytes, for a row. This is a required parameter.
repeatWhen set to True, the rows for the table are duplicated on every machine of a distributed server.
replaceWhen set to True, an existing table with the same name is overwritten.
tableSpecifies the output table name.
varsSpecifies the attributes for each variable, such as name, type, length, and format.
Data Preparation
Data Creation (Client-Side)

The `addTable` action is used by client-side utilities to upload data. For example, in Python, you would typically create a Pandas DataFrame first. This DataFrame is then uploaded to the CAS server, which internally uses the `addTable` action.

/* This is a conceptual representation. In practice, you'd use a client like Python's SWAT library. */
proc cas;
  /* Step 1: Define data on the client (e.g., a Pandas DataFrame in Python) */
  /* df = pd.DataFrame({'model': ['Mustang', 'F-150', 'Explorer'], 'msrp': [27000, 35000, 32000]}) */

  /* Step 2: Use the client library's upload function, which calls table.addTable */
  /* cas_conn.upload_frame(df, casout={'name':'cars', 'caslib':'casuser'}) */
quit;

Examples

This example demonstrates the typical usage of `addTable` via a client library. A local data structure is created and then uploaded to the CAS server, creating a new in-memory table named 'CARS' in the 'CASUSER' caslib.

SAS® / CAS Code
Copied!
1PROC CAS;
2 /* In Python, this would be: df = pd.DataFrame({'model': ['Mustang', 'F-150'], 'msrp': [27000, 35000]}); s.upload_frame(df, casout={'name':'cars', 'caslib':'casuser'}); */
3 TABLE.addTable / caslib='casuser' TABLE='CARS' vars={{name='model', type='varchar', LENGTH=10},{name='msrp', type='double'}};
4QUIT;
Result :
A new in-memory table named 'CARS' is created in the 'CASUSER' caslib with two columns, 'model' and 'msrp', and two rows of data.

This example shows a more advanced upload. It specifies column labels and formats. `replace=TRUE` ensures that if a table named 'SALES_DATA' already exists, it will be overwritten. `promote=TRUE` makes the table available to all other CAS sessions, not just the current one.

SAS® / CAS Code
Copied!
1PROC CAS;
2 /* Python equivalent: s.upload_frame(df, casout={'name':'sales_data', 'caslib':'casuser', 'replace':True, 'promote':True}, var_attr={'product_id':{'label':'Product Identifier'}, 'sale_date':{'format':'DATE9.'}}) */
3 TABLE.addTable /
4 caslib='casuser'
5 TABLE='SALES_DATA'
6 replace=TRUE
7 promote=TRUE
8 label='Quarterly Sales Figures'
9 vars={{
10 name='product_id',
11 type='varchar',
12 LENGTH=15,
13 label='Product Identifier'
14 },{
15 name='sale_date',
16 type='double',
17 FORMAT='DATE9.',
18 label='Date of Sale'
19 },{
20 name='sale_amount',
21 type='double',
22 FORMAT='DOLLAR12.2',
23 label='Sale Amount'
24 }};
25QUIT;
Result :
A global-scope in-memory table named 'SALES_DATA' is created or replaced in the 'CASUSER' caslib. The table has specified labels and formats for its columns and is accessible by other user sessions.

FAQ

What is the purpose of the addTable action?
How is the addTable action used with clients like CASL, Python, or R?
What does the 'append' parameter do?
What is the 'caslib' parameter used for?
What does the 'replace' parameter do?
How can I make a table available to other sessions?
What does the 'copies' parameter control?
What is the 'recLen' parameter and is it required?
How are variables defined when using the addTable action?

Associated Scenarios

Use Case
Daily Transactional Data Replacement

A retail company needs to upload its daily sales transactions into CAS for analysis. The process runs every morning, and the previous day's data must be completely replaced with...

Use Case
High-Volume IoT Sensor Data Ingestion with Partitioning and Redundancy

A manufacturing company ingests millions of data points from IoT sensors on its assembly line machines. To enable rapid failure analysis and predictive modeling, the data must b...

Use Case
Appending Marketing Campaign Responses

A marketing analytics team needs to consolidate customer responses from multiple campaign waves into a single master table. The initial data is loaded, and subsequent data from ...