@Override public LinkedHashMap<String, String> getPartitions() { LinkedHashMap<String, String> partitions = super.getPartitions(); if (partitions == null) { partitions = new LinkedHashMap<String, String>(1); super.setPartitions(partitions); } partitions.put(DYNAMODB_KEYS, this.stringKeys); return partitions; } }
@Override public LinkedHashMap<String, String> getPartitions() { LinkedHashMap<String, String> partitions = super.getPartitions(); if (partitions == null) { partitions = new LinkedHashMap<String, String>(1); super.setPartitions(partitions); } partitions.put(DYNAMODB_KEYS, this.stringKeys); return partitions; } }
@Override public LinkedHashMap<String, String> getPartitions() { LinkedHashMap<String, String> partitions = super.getPartitions(); if (partitions == null) { partitions = new LinkedHashMap<String, String>(1); super.setPartitions(partitions); } if (this.shardId != null) { partitions.put(SHARD_ID, shardId); } return partitions; } }
@Override public LinkedHashMap<String, String> getPartitions() { LinkedHashMap<String, String> partitions = super.getPartitions(); if (partitions == null) { partitions = new LinkedHashMap<String, String>(1); super.setPartitions(partitions); } if (this.shardId != null) { partitions.put(SHARD_ID, shardId); } return partitions; } }
@Override public LinkedHashMap<String, String> getPartitions() { LinkedHashMap<String, String> partitions = super.getPartitions(); if (partitions == null) { partitions = new LinkedHashMap<String, String>(1); super.setPartitions(partitions); } partitions.put(FILENAME_PARTITION, DigestUtils.sha1Hex(this.s3Key)); return partitions; }
@Override public LinkedHashMap<String, String> getPartitions() { LinkedHashMap<String, String> partitions = super.getPartitions(); if (partitions == null) { partitions = new LinkedHashMap<String, String>(1); super.setPartitions(partitions); } partitions.put(FILENAME_PARTITION, DigestUtils.sha1Hex(this.s3Key)); return partitions; }
if (this.usePartitionsForRouting && ievent.getPartitions() != null) { payload.append("\"" + this.routingFieldName + "\":"); payload.append("\""); payload.append(ievent.getPartitions().entrySet().stream().map(s -> s.getKey() + "=" + s.getValue()) .collect(Collectors.joining("/"))); payload.append("\",");
if (this.usePartitionsForRouting && ievent.getPartitions() != null) { payload.append("\"" + this.routingFieldName + "\":"); payload.append("\""); payload.append(ievent.getPartitions().entrySet().stream().map(s -> s.getKey() + "=" + s.getValue()) .collect(Collectors.joining("/"))); payload.append("\",");
/** * Makes a new event by copying properties from another event. * * @param other event to copy */ private InternalEvent(InternalEvent other) { this.eventString = new String(other.getEventString()); this.context = other.context; this.eventSha1Hash = other.getEventSha1Hash(); this.arrivalTime = other.getArrivalTime(); this.eventTime = other.getEventTime(); this.serialized = other.getSerialized(); if (other.getPartitions() == null) { this.partitions = null; } else { this.partitions = new LinkedHashMap<String, String>(other.getPartitions()); } /* * We rely on the implementation to provide a deep copy here. */ if (other.getEventObj() != null) { this.eventObj = other.getEventObj().copy(); } /* * Note that this is a shallow copy of the metadata. Some metadata elements are reused across * multiple events within a function invocation. */ this.metadata.putAll(other.metadata); }
/** * Makes a new event by copying properties from another event. * * @param other event to copy */ private InternalEvent(InternalEvent other) { this.eventString = new String(other.getEventString()); this.context = other.context; this.eventSha1Hash = other.getEventSha1Hash(); this.arrivalTime = other.getArrivalTime(); this.eventTime = other.getEventTime(); this.serialized = other.getSerialized(); if (other.getPartitions() == null) { this.partitions = null; } else { this.partitions = new LinkedHashMap<String, String>(other.getPartitions()); } /* * We rely on the implementation to provide a deep copy here. */ if (other.getEventObj() != null) { this.eventObj = other.getEventObj().copy(); } /* * Note that this is a shallow copy of the metadata. Some metadata elements are reused across * multiple events within a function invocation. */ this.metadata.putAll(other.metadata); }
LinkedHashMap<String, String> partitions = ievent.getPartitions();
LinkedHashMap<String, String> partitions = ievent.getPartitions();
LinkedHashMap<String, String> partitions = ievent.getPartitions();
LinkedHashMap<String, String> partitions = ievent.getPartitions();
@Test public void testGetEvaluatedPartitionsString() throws FieldNotFoundException { List<PartitionSpec> partitionSpecs = new ArrayList<PartitionSpec>(1); List<String> sources = Arrays.asList("foo"); PartitionSpec spec = new PartitionSpec("foo", sources, PartitionSpec.Interpreter.STRING); partitionSpecs.add(spec); PartitionOperation op = new PartitionOperation(partitionSpecs); InternalEvent ievent = new InternalEvent("foo", null, 1); DummyStringEvent devent = spy(new DummyStringEvent("")); ievent.setEventObj(devent); doReturn("baz").when(devent).getFieldAsString("foo"); op.perform(ievent); LinkedHashMap<String, String> actual = ievent.getPartitions(); LinkedHashMap<String, String> expected = new LinkedHashMap<String, String>(1); expected.put("foo", "baz"); assertEquals(expected, actual); }
@Test public void testGetEvaluatedPartitionsStringMultipleFields() throws FieldNotFoundException { List<PartitionSpec> partitionSpecs = new ArrayList<PartitionSpec>(1); List<String> sources = Arrays.asList("one", "two"); PartitionSpec spec = new PartitionSpec("foo", sources, PartitionSpec.Interpreter.STRING); partitionSpecs.add(spec); PartitionOperation op = new PartitionOperation(partitionSpecs); InternalEvent ievent = new InternalEvent("foo", null, 1); DummyStringEvent devent = spy(new DummyStringEvent("")); ievent.setEventObj(devent); doThrow(FieldNotFoundException.class).doReturn("5").when(devent).getFieldAsString(any()); op.perform(ievent); LinkedHashMap<String, String> actual = ievent.getPartitions(); LinkedHashMap<String, String> expected = new LinkedHashMap<String, String>(1); expected.put("foo", "5"); assertEquals(expected, actual); }
@Test public void testGetEvaluatedPartitionsStatic() { List<PartitionSpec> partitionSpecs = new ArrayList<PartitionSpec>(1); PartitionSpec spec = new PartitionSpec("foo", Collections.emptyList(), PartitionSpec.Interpreter.STATIC, "123", 0); partitionSpecs.add(spec); PartitionOperation op = new PartitionOperation(partitionSpecs); InternalEvent ievent = new InternalEvent("foo", null, 1); DummyStringEvent devent = new DummyStringEvent(""); ievent.setEventObj(devent); op.perform(ievent); LinkedHashMap<String, String> actual = ievent.getPartitions(); LinkedHashMap<String, String> expected = new LinkedHashMap<String, String>(1); expected.put("foo", "123"); assertEquals(expected, actual); }
@Test public void testOperationThroughProcessor() throws FieldNotFoundException { List<PartitionSpec> partitionSpecs = new ArrayList<PartitionSpec>(1); List<String> sources = Arrays.asList("foo"); PartitionSpec spec = new PartitionSpec("foo", sources, PartitionSpec.Interpreter.STRING); partitionSpecs.add(spec); PartitionOperation op = new PartitionOperation(partitionSpecs); InternalEvent ievent = new InternalEvent("foo", null, 1); DummyStringEvent devent = spy(new DummyStringEvent("")); ievent.setEventObj(devent); doReturn("baz").when(devent).getFieldAsString("foo"); DummyOperationFactory opFact = new DummyOperationFactory(op); OperationProcessor opProc = new OperationProcessor(opFact); opProc.perform(Stream.of(ievent)).count(); LinkedHashMap<String, String> actual = ievent.getPartitions(); LinkedHashMap<String, String> expected = new LinkedHashMap<String, String>(1); expected.put("foo", "baz"); assertEquals(expected, actual); } }