Create table
Memory store writes
You can use the following code snippet to create a table that has magnetic store writes disabled, as a result you can only write data into your memory store retention window.
Note
These code snippets are based on full sample applications on GitHub
public void createTable() {
System.out.println("Creating table");
CreateTableRequest createTableRequest = new CreateTableRequest();
createTableRequest.setDatabaseName(DATABASE_NAME);
createTableRequest.setTableName(TABLE_NAME);
final RetentionProperties retentionProperties = new RetentionProperties()
.withMemoryStoreRetentionPeriodInHours(HT_TTL_HOURS)
.withMagneticStoreRetentionPeriodInDays(CT_TTL_DAYS);
createTableRequest.setRetentionProperties(retentionProperties);
try {
amazonTimestreamWrite.createTable(createTableRequest);
System.out.println("Table [" + TABLE_NAME + "] successfully created.");
} catch (ConflictException e) {
System.out.println("Table [" + TABLE_NAME + "] exists on database [" + DATABASE_NAME + "] . Skipping database creation");
}
}
Magnetic store writes
You can use the following code snippet to create a table with magnetic store writes enabled. With magnetic store writes you can write data into both your memory store retention window and magnetic store retention window.
Note
These code snippets are based on full sample applications on GitHub
public void createTable(String databaseName, String tableName) {
System.out.println("Creating table");
CreateTableRequest createTableRequest = new CreateTableRequest();
createTableRequest.setDatabaseName(databaseName);
createTableRequest.setTableName(tableName);
final RetentionProperties retentionProperties = new RetentionProperties()
.withMemoryStoreRetentionPeriodInHours(HT_TTL_HOURS)
.withMagneticStoreRetentionPeriodInDays(CT_TTL_DAYS);
createTableRequest.setRetentionProperties(retentionProperties);
// Enable MagneticStoreWrite
final MagneticStoreWriteProperties magneticStoreWriteProperties = new MagneticStoreWriteProperties()
.withEnableMagneticStoreWrites(true);
createTableRequest.setMagneticStoreWriteProperties(magneticStoreWriteProperties);
try {
amazonTimestreamWrite.createTable(createTableRequest);
System.out.println("Table [" + tableName + "] successfully created.");
} catch (ConflictException e) {
System.out.println("Table [" + tableName + "] exists on database [" + databaseName + "] . Skipping table creation");
//We do not throw exception here, we use the existing table instead
}
}