Erste Schritte mit kundendefinierten Partitionsschlüsseln - Amazon Timestream

Die vorliegende Übersetzung wurde maschinell erstellt. Im Falle eines Konflikts oder eines Widerspruchs zwischen dieser übersetzten Fassung und der englischen Fassung (einschließlich infolge von Verzögerungen bei der Übersetzung) ist die englische Fassung maßgeblich.

Erste Schritte mit kundendefinierten Partitionsschlüsseln

Wählen Sie in der Konsole Tabellen aus und erstellen Sie eine neue Tabelle. Sie können auch eine verwendenSDK, um auf die CreateTable Aktion zuzugreifen, um neue Tabellen zu erstellen, die einen benutzerdefinierten Partitionsschlüssel enthalten können.

Erstellen Sie eine Tabelle mit einem Partitionsschlüssel vom Typ Dimension

Sie können die folgenden Codefragmente verwenden, um eine Tabelle mit einem Partitionsschlüssel vom Typ Dimension zu erstellen.

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)