List of usage examples for com.amazonaws.services.dynamodbv2.model PutRequest addItemEntry
public PutRequest addItemEntry(String key, AttributeValue value)
From source file:dynamok.sink.DynamoDbSinkTask.java
License:Apache License
private PutRequest toPutRequest(SinkRecord record) { final PutRequest put = new PutRequest(); if (!config.ignoreRecordValue) { insert(ValueSource.RECORD_VALUE, record.valueSchema(), record.value(), put); }//from w ww . j a v a2 s . c o m if (!config.ignoreRecordKey) { insert(ValueSource.RECORD_KEY, record.keySchema(), record.key(), put); } if (config.kafkaCoordinateNames != null) { put.addItemEntry(config.kafkaCoordinateNames.topic, new AttributeValue().withS(record.topic())); put.addItemEntry(config.kafkaCoordinateNames.partition, new AttributeValue().withN(String.valueOf(record.kafkaPartition()))); put.addItemEntry(config.kafkaCoordinateNames.offset, new AttributeValue().withN(String.valueOf(record.kafkaOffset()))); } return put; }
From source file:dynamok.sink.DynamoDbSinkTask.java
License:Apache License
private void insert(ValueSource valueSource, Schema schema, Object value, PutRequest put) { final AttributeValue attributeValue; try {//from w w w. j a v a 2s .c om attributeValue = schema == null ? AttributeValueConverter.toAttributeValueSchemaless(value) : AttributeValueConverter.toAttributeValue(schema, value); } catch (DataException e) { log.error("Failed to convert record with schema={} value={}", schema, value, e); throw e; } final String topAttributeName = valueSource.topAttributeName(config); if (!topAttributeName.isEmpty()) { put.addItemEntry(topAttributeName, attributeValue); } else if (attributeValue.getM() != null) { put.setItem(attributeValue.getM()); } else { throw new ConnectException("No top attribute name configured for " + valueSource + ", and it could not be converted to Map: " + attributeValue); } }
From source file:org.apache.beam.sdk.io.aws.dynamodb.DynamoDBIOTestHelper.java
License:Apache License
private static PutRequest generatePutRequest(String hashKeyData, String rangeKeyData) { PutRequest putRequest = new PutRequest(); putRequest.addItemEntry(ATTR_NAME_1, new AttributeValue(hashKeyData)); putRequest.addItemEntry(ATTR_NAME_2, new AttributeValue().withN(rangeKeyData)); return putRequest; }