All Products
Search
Document Center

Tablestore:What do I do if the error "The count of attribute columns exceeds the maximum:128" is reported when I use Tablestore SDK for Java to write data to a Tablestore data table?

Last Updated:Oct 19, 2023

Problem description

The following error is reported when I use Tablestore SDK for Java to write data to a Tablestore data table:

The count of attribute columns exceeds the maximum:128

Possible cause

When you write data to a Tablestore data table, you can write up to 1,024 columns to a row. When you use a TableStoreWriter client, the client allows you to write up to 128 columns to a row by default.

Solution

When you use Tablestore SDK for Java to construct a TableStoreWriter client, you can modify the MaxColumnsCount parameter to increase the number of columns that can be written to a row.

Note

In Tablestore SDK for Java, the OTS_AK_ENV environment variable indicates the AccessKey ID of an Alibaba Cloud account or a Resource Access Management (RAM) user, and the OTS_SK_ENV environment variable indicates the AccessKey secret of the Alibaba Cloud account or RAM user. Specify the AccessKey pair based on your business requirements. For more information about how to configure environment variables, see the Configure environment variables section of the "Initialization" topic.

final String endPoint = ""; 
String accessKeyId = System.getenv("OTS_AK_ENV");
String accessKeySecret = System.getenv("OTS_SK_ENV");
final String instanceName = "";

ClientConfiguration cc = new ClientConfiguration();
cc.setRetryStrategy(new DefaultRetryStrategy()); // Customize a retry policy. To improve the success rate of data writing, you can use a more radical retry policy. 
AsyncClient asyncClient = new AsyncClient(endPoint, accessKeyId, accessKeySecret, instanceName, cc);

// Initialize the client.
WriterConfig config = new WriterConfig();
config.setMaxBatchSize(4 * 1024 * 1024); // Specify the maximum size of requests that can be imported at a time. Default value: 4 MB. 
config.setMaxColumnsCount(128); // Specify the maximum number of columns that can be written to a row. Default value: 128. 
config.setBufferSize(1024); // Specify the maximum number of data rows that can be buffered in the memory. Default value: 1024. The value of this parameter must be an exponential multiple of 2. 
config.setMaxBatchRowsCount(100); // Specify the maximum number of rows that can be imported at a time. Default value: 100. 
config.setConcurrency(10); // Specify the maximum number of concurrent requests. Default value: 10. 
config.setMaxAttrColumnSize(2 * 1024 * 1024); // Specify the maximum size of the value of the attribute column. Default value: 2 MB. 
config.setMaxPKColumnSize(1024); // Specify the maximum size of the value of the primary key column. Default value: 1 KB. 
config.setFlushInterval(10000); // Specify the interval at which the flush operation is triggered in the buffer. Default value: 10. Unit: seconds. 

// Configure a callback. OTSWriter uses this callback to report the rows that are imported or failed to be imported. This callback counts the number of rows that are imported and the number of rows that failed to be imported. 

AtomicLong succeedCount = new AtomicLong();
AtomicLong failedCount = new AtomicLong();
TableStoreCallback<RowChange, ConsumedCapacity> callback = new SampleCallback(succeedCount, failedCount);
ExecutorService executor = Executors.newFixedThreadPool(2);
TableStoreWriter tablestoreWriter = new DefaultTableStoreWriter(asyncClient, tableName, config, callback, executor);