Introdução às chaves de partição definidas pelo cliente - Amazon Timestream

As traduções são geradas por tradução automática. Em caso de conflito entre o conteúdo da tradução e da versão original em inglês, a versão em inglês prevalecerá.

Introdução às chaves de partição definidas pelo cliente

No console, escolha Tabelas e crie uma nova tabela. Você também pode usar um SDK para acessar a CreateTable ação para criar novas tabelas que podem incluir uma chave de partição definida pelo cliente.

Crie uma tabela com uma chave de partição do tipo dimensão

Você pode usar os seguintes trechos de código para criar uma tabela com uma chave de partição do tipo dimensão.

Java
public void createTableWithDimensionTypePartitionKeyExample() { 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); // Can specify enforcement level with OPTIONAL or REQUIRED final List<PartitionKey> partitionKeyWithDimensionAndOptionalEnforcement = Collections.singletonList(new PartitionKey() .withName(COMPOSITE_PARTITION_KEY_DIM_NAME) .withType(PartitionKeyType.DIMENSION) .withEnforcementInRecord(PartitionKeyEnforcementLevel.OPTIONAL)); Schema schema = new Schema(); schema.setCompositePartitionKey(partitionKeyWithDimensionAndOptionalEnforcement); createTableRequest.setSchema(schema); try { writeClient.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"); } }
Java v2
public void createTableWithDimensionTypePartitionKeyExample() { System.out.println("Creating table"); final RetentionProperties retentionProperties = RetentionProperties.builder() .memoryStoreRetentionPeriodInHours(HT_TTL_HOURS) .magneticStoreRetentionPeriodInDays(CT_TTL_DAYS) .build(); // Can specify enforcement level with OPTIONAL or REQUIRED final List<PartitionKey> partitionKeyWithDimensionAndOptionalEnforcement = Collections.singletonList(PartitionKey .builder() .name(COMPOSITE_PARTITION_KEY_DIM_NAME) .type(PartitionKeyType.DIMENSION) .enforcementInRecord(PartitionKeyEnforcementLevel.OPTIONAL) .build()); final Schema schema = Schema.builder() .compositePartitionKey(partitionKeyWithDimensionAndOptionalEnforcement).build(); final CreateTableRequest createTableRequest = CreateTableRequest.builder() .databaseName(DATABASE_NAME) .tableName(TABLE_NAME) .retentionProperties(retentionProperties) .schema(schema) .build(); try { writeClient.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"); } }
Go v1
func createTableWithDimensionTypePartitionKeyExample(){ // Can specify enforcement level with OPTIONAL or REQUIRED partitionKeyWithDimensionAndOptionalEnforcement := []*timestreamwrite.PartitionKey{ { Name: aws.String(CompositePartitionKeyDimName), EnforcementInRecord: aws.String("OPTIONAL"), Type: aws.String("DIMENSION"), }, } createTableInput := &timestreamwrite.CreateTableInput{ DatabaseName: aws.String(*databaseName), TableName: aws.String(*tableName), // Enable MagneticStoreWrite for Table MagneticStoreWriteProperties: &timestreamwrite.MagneticStoreWriteProperties{ EnableMagneticStoreWrites: aws.Bool(true), // Persist MagneticStoreWrite rejected records in S3 MagneticStoreRejectedDataLocation: &timestreamwrite.MagneticStoreRejectedDataLocation{ S3Configuration: &timestreamwrite.S3Configuration{ BucketName: aws.String("timestream-sample-bucket"), ObjectKeyPrefix: aws.String("TimeStreamCustomerSampleGo"), EncryptionOption: aws.String("SSE_S3"), }, }, }, Schema: &timestreamwrite.Schema{ CompositePartitionKey: partitionKeyWithDimensionAndOptionalEnforcement, } } _, err := writeSvc.CreateTable(createTableInput) }
Go v2
func (timestreamBuilder TimestreamBuilder) CreateTableWithDimensionTypePartitionKeyExample() error { partitionKeyWithDimensionAndOptionalEnforcement := []types.PartitionKey{ { Name: aws.String(CompositePartitionKeyDimName), EnforcementInRecord: types.PartitionKeyEnforcementLevelOptional, Type: types.PartitionKeyTypeDimension, }, } _, err := timestreamBuilder.WriteSvc.CreateTable(context.TODO(), &timestreamwrite.CreateTableInput{ DatabaseName: aws.String(databaseName), TableName: aws.String(tableName), MagneticStoreWriteProperties: &types.MagneticStoreWriteProperties{ EnableMagneticStoreWrites: aws.Bool(true), // Persist MagneticStoreWrite rejected records in S3 MagneticStoreRejectedDataLocation: &types.MagneticStoreRejectedDataLocation{ S3Configuration: &types.S3Configuration{ BucketName: aws.String(s3BucketName), EncryptionOption: "SSE_S3", }, }, }, Schema: &types.Schema{ CompositePartitionKey: partitionKeyWithDimensionAndOptionalEnforcement, }, }) if err != nil { fmt.Println("Error:") fmt.Println(err) } else { fmt.Println("Create table is successful") } return err }
Python
def create_table_with_measure_name_type_partition_key(self): print("Creating table") retention_properties = { 'MemoryStoreRetentionPeriodInHours': HT_TTL_HOURS, 'MagneticStoreRetentionPeriodInDays': CT_TTL_DAYS } partitionKey_with_measure_name = [ {'Type': 'MEASURE'} ] schema = { 'CompositePartitionKey': partitionKey_with_measure_name } try: self.client.create_table(DatabaseName=DATABASE_NAME, TableName=TABLE_NAME, RetentionProperties=retention_properties, Schema=schema) print("Table [%s] successfully created." % TABLE_NAME) except self.client.exceptions.ConflictException: print("Table [%s] exists on database [%s]. Skipping table creation" % ( TABLE_NAME, DATABASE_NAME)) except Exception as err: print("Create table failed:", err)