Alter Table

void alterTable(String tableName, TableSpec tableSpec)

Function

Add or remove attributes

Modify table space size, read and write quotas

Modify the table's app permission control

Modify table description

Turn on or off globally ordered scan support

Method parameters

1.tableName : String : required

Specifies the name of the table to modify

2.tableSpec : TableSpec : required

Specifies the modified TableSpec

The new table's schema and meta data definition, including both parts of schema and meta

The schema part includes

1.entityGroupSpec : EntityGroupSpec : optional

entityGroupSpec includes List< KeySpec > attributes, used to specify attributes as an entity group key and the encoding of each attribute (asc/desc)

enableHash specifies whether to enable hash distribution for entity group keys

2.primaryIndex : List< KeySpec > : required

Specifies the attributes as the primary key, and the encoding of each attribute (asc/desc)

3.attributes : Map< String, DataType > : required

The mapping of attribute names to attribute data types defines the table attribute names and the data types of these attributes, and must include the attributes defined in the entityGroupSpec and primaryIndex defined previously.

4.secondaryIndexes : Map< String, LocalSecondaryIndexSpec > : optional

Multiple secondary indexes can be built on the table. This parameter defines the mapping of LocalSecondaryIndexSpec from the secondary index name to the secondary index, and defines the secondary index of the table

Among which is LocalSecondaryIndexSpec, which contains the following fields:

  • indexSchema: List< KeySpec > specifies which attributes are to be indexed, and the encoding method (asc/desc) when the key is recorded as an index
  • consistencyMode: SecondaryIndexConsistencyMode defines the index type, LAZY, EAGER, or IMMUTABLE
  • projections: List< String >, a list of attribute names defining which attributes' copy in the master record are included in the index record, able to set only if the index type is EAGER

5.streams : Map< String, StreamSpec > : optional

Multiple Streams can be built on the table. This parameter defines the StreamSpec mapping from the topic name to the Stream, and defines the Stream collection of the table

StreamSpec contains the following fields:

  • viewType: StreamViewType represents the Stream type, including RECORD_IMAGE and MUTATE_LOG
  • Attributes: List< String >, needs a list of attribute names of track
  • enableStream: boolean, enable switch

meta section

1.quota : TableQuota : required

Specifies table space size quota

2.throughput : ProvisionThroughput : required

Default read/write quotas for primary cluster

3.appAcl : Map< String, List< CannedAcl > > : optional

Defines the table's access permissions for the app under this account, refer to Permissions model</u></p>

4.description : String : optional

Brief description of the table

  1. exceededThroughput : ProvisionThroughput : required

The maximum read/write quota of the primary cluster, that is, the maximum throughput that the system may reach when it is idle, and the setting is larger than throughput, which allows for hypercapability

  1. slaveThroughput : ProvisionThroughput : required

Default cluster read/write quotas

  1. exceededSlaveThroughput : ProvisionThroughput : required

The maximum read/write quota of the standby cluster, that is, the maximum throughput that the system may reach when it is idle, and the setting is larger than slaveThroughput, which allows for hypercapability

Method return value

void

Exception error code

INTERNAL_ERROR(1): Server exception

ACCESS_DENIED(4): No permission to modify table

VALIDATION_FAILED(5): Parameter error

SIZE_EXCEED(6): The space quota or read/write quota exceeds the user's total quota

RESOURCE_NOT_FOUND(9): Table does not exist

RESOURCE_UNAVAILABLE(11) : There are other DDL operations under this account. Does not allow DDL operations at the same time

Limitation

Only table owner can modify table operations

You cannot modify the entity group keys and primary keys of the table

Cannot modify the attribute's data type

Cannot add index

Secondary indexes can only modify index type and only from IMMUTABLE to EAGER

Example

Take the example table as an example. The following shows the example code for modifying a table

$tableName = "php-note";
$tableSpec = $adminClient->describeTable($tableName);
$tableSpec->schema->attributes =  array(
    'userId' => DataType::STRING,
    'noteId' => DataType::INT64,
    'title' => DataType::STRING,
    'content' => DataType::STRING,
    'version' => DataType::INT64,
    'mtime' => DataType::INT64,
    'category' => DataType::STRING,
    'addAttribute' => DataType::STRING, // Add attributes
);

$tableSpec->metadata->throughput = new ProvisionThroughput(array(
    'readCapacity' => 200,
    'writeCapacity' => 400 //Change write quota to 400
));

$adminClient->alterTable($tableName, $tableSpec);

results matching ""

    No results matching ""