org.apache.flink.util.CollectionUtil Java Examples
The following examples show how to use
org.apache.flink.util.CollectionUtil.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: InfluxDBSink.java From flink-learning with Apache License 2.0 | 6 votes |
@Override public void invoke(MetricEvent metricEvent, Context context) throws Exception { if (StringUtils.isNullOrWhitespaceOnly(metricEvent.getName())) { throw new RuntimeException("No measurement defined"); } Point.Builder builder = Point.measurement(metricEvent.getName()) .time(metricEvent.getTimestamp(), TimeUnit.MILLISECONDS); if (!CollectionUtil.isNullOrEmpty(metricEvent.getFields())) { builder.fields(metricEvent.getFields()); } if (!CollectionUtil.isNullOrEmpty(metricEvent.getTags())) { builder.tag(metricEvent.getTags()); } Point point = builder.build(); influxDBClient.write(point); }
Example #2
Source File: InfluxDBSink.java From flink-learning with Apache License 2.0 | 6 votes |
@Override public void invoke(MetricEvent metricEvent, Context context) throws Exception { if (StringUtils.isNullOrWhitespaceOnly(metricEvent.getName())) { throw new RuntimeException("No measurement defined"); } Point.Builder builder = Point.measurement(metricEvent.getName()) .time(metricEvent.getTimestamp(), TimeUnit.MILLISECONDS); if (!CollectionUtil.isNullOrEmpty(metricEvent.getFields())) { builder.fields(metricEvent.getFields()); } if (!CollectionUtil.isNullOrEmpty(metricEvent.getTags())) { builder.tag(metricEvent.getTags()); } Point point = builder.build(); influxDBClient.write(point); }
Example #3
Source File: InfluxDBSink.java From bahir-flink with Apache License 2.0 | 6 votes |
/** * Called when new data arrives to the sink, and forwards it to InfluxDB. * * @param dataPoint {@link InfluxDBPoint} */ @Override public void invoke(InfluxDBPoint dataPoint, Context context) throws Exception { if (StringUtils.isNullOrWhitespaceOnly(dataPoint.getMeasurement())) { throw new RuntimeException("No measurement defined"); } Point.Builder builder = Point.measurement(dataPoint.getMeasurement()) .time(dataPoint.getTimestamp(), TimeUnit.MILLISECONDS); if (!CollectionUtil.isNullOrEmpty(dataPoint.getFields())) { builder.fields(dataPoint.getFields()); } if (!CollectionUtil.isNullOrEmpty(dataPoint.getTags())) { builder.tag(dataPoint.getTags()); } Point point = builder.build(); influxDBClient.write(point); }
Example #4
Source File: OperatorStateInputFormat.java From flink with Apache License 2.0 | 5 votes |
private OperatorStateInputSplit[] subPartitionSingleSplit(int minNumSplits, OperatorStateInputSplit[] splits) { if (splits.length == 0) { return splits; } // We only want to output a single instance of the union state so we only need // to transform a single input split. An arbitrary split is chosen and // sub-partitioned for better data distribution across the cluster. return CollectionUtil.mapWithIndex( CollectionUtil.partition(splits[0].getPrioritizedManagedOperatorState().get(0).asList(), minNumSplits), (state, index) -> new OperatorStateInputSplit(new StateObjectCollection<>(new ArrayList<>(state)), index) ).toArray(OperatorStateInputSplit[]::new); }
Example #5
Source File: OperatorStateInputFormat.java From flink with Apache License 2.0 | 5 votes |
private OperatorStateInputSplit[] getOperatorStateInputSplits(int minNumSplits) { final Map<OperatorInstanceID, List<OperatorStateHandle>> newManagedOperatorStates = new HashMap<>(); StateAssignmentOperation.reDistributePartitionableStates( Collections.singletonList(operatorState), minNumSplits, Collections.singletonList(operatorState.getOperatorID()), newManagedOperatorStates, new HashMap<>()); return CollectionUtil.mapWithIndex( newManagedOperatorStates.values(), (handles, index) -> new OperatorStateInputSplit(new StateObjectCollection<>(handles), index) ).toArray(OperatorStateInputSplit[]::new); }
Example #6
Source File: KeyedStateInputFormat.java From flink with Apache License 2.0 | 5 votes |
@Override public KeyGroupRangeInputSplit[] createInputSplits(int minNumSplits) throws IOException { final int maxParallelism = operatorState.getMaxParallelism(); final List<KeyGroupRange> keyGroups = sortedKeyGroupRanges(minNumSplits, maxParallelism); return CollectionUtil.mapWithIndex( keyGroups, (keyGroupRange, index) -> createKeyGroupRangeInputSplit( operatorState, maxParallelism, keyGroupRange, index) ).toArray(KeyGroupRangeInputSplit[]::new); }
Example #7
Source File: OperatorStateInputFormat.java From flink with Apache License 2.0 | 5 votes |
private OperatorStateInputSplit[] subPartitionSingleSplit(int minNumSplits, OperatorStateInputSplit[] splits) { if (splits.length == 0) { return splits; } // We only want to output a single instance of the union state so we only need // to transform a single input split. An arbitrary split is chosen and // sub-partitioned for better data distribution across the cluster. return CollectionUtil.mapWithIndex( CollectionUtil.partition(splits[0].getPrioritizedManagedOperatorState().get(0).asList(), minNumSplits), (state, index) -> new OperatorStateInputSplit(new StateObjectCollection<>(new ArrayList<>(state)), index) ).toArray(OperatorStateInputSplit[]::new); }
Example #8
Source File: OperatorStateInputFormat.java From flink with Apache License 2.0 | 5 votes |
private OperatorStateInputSplit[] getOperatorStateInputSplits(int minNumSplits) { Map<OperatorInstanceID, List<OperatorStateHandle>> newManagedOperatorStates = reDistributePartitionableStates( singletonList(operatorState), minNumSplits, singletonList(OperatorIDPair.generatedIDOnly(operatorState.getOperatorID())), OperatorSubtaskState::getManagedOperatorState, RoundRobinOperatorStateRepartitioner.INSTANCE); return CollectionUtil.mapWithIndex( newManagedOperatorStates.values(), (handles, index) -> new OperatorStateInputSplit(new StateObjectCollection<>(handles), index) ).toArray(OperatorStateInputSplit[]::new); }
Example #9
Source File: KeyedStateInputFormat.java From flink with Apache License 2.0 | 5 votes |
@Override public KeyGroupRangeInputSplit[] createInputSplits(int minNumSplits) throws IOException { final int maxParallelism = operatorState.getMaxParallelism(); final List<KeyGroupRange> keyGroups = sortedKeyGroupRanges(minNumSplits, maxParallelism); return CollectionUtil.mapWithIndex( keyGroups, (keyGroupRange, index) -> createKeyGroupRangeInputSplit( operatorState, maxParallelism, keyGroupRange, index) ).toArray(KeyGroupRangeInputSplit[]::new); }
Example #10
Source File: TaskExecutorPartitionTrackerImpl.java From flink with Apache License 2.0 | 5 votes |
@Override public void stopTrackingAndReleaseJobPartitionsFor(JobID producingJobId) { Collection<ResultPartitionID> partitionsForJob = CollectionUtil.project( stopTrackingPartitionsFor(producingJobId), PartitionTrackerEntry::getResultPartitionId); shuffleEnvironment.releasePartitionsLocally(partitionsForJob); }
Example #11
Source File: JobMasterPartitionTrackerImpl.java From flink with Apache License 2.0 | 5 votes |
@Override public void stopTrackingAndReleasePartitionsFor(ResourceID producingTaskExecutorId) { Preconditions.checkNotNull(producingTaskExecutorId); Collection<ResultPartitionDeploymentDescriptor> resultPartitionIds = CollectionUtil.project(stopTrackingPartitionsFor(producingTaskExecutorId), PartitionTrackerEntry::getMetaInfo); internalReleasePartitions(producingTaskExecutorId, resultPartitionIds); }
Example #12
Source File: JobMasterPartitionTrackerImpl.java From flink with Apache License 2.0 | 5 votes |
@Override public void stopTrackingAndReleaseOrPromotePartitionsFor(ResourceID producingTaskExecutorId) { Preconditions.checkNotNull(producingTaskExecutorId); Collection<ResultPartitionDeploymentDescriptor> resultPartitionIds = CollectionUtil.project(stopTrackingPartitionsFor(producingTaskExecutorId), PartitionTrackerEntry::getMetaInfo); internalReleaseOrPromotePartitions(producingTaskExecutorId, resultPartitionIds); }
Example #13
Source File: SourceOperator.java From flink with Apache License 2.0 | 5 votes |
@Override public void open() throws Exception { final MetricGroup metricGroup = getMetricGroup(); final SourceReaderContext context = new SourceReaderContext() { @Override public MetricGroup metricGroup() { return metricGroup; } @Override public void sendSourceEventToCoordinator(SourceEvent event) { operatorEventGateway.sendEventToCoordinator(new SourceEventWrapper(event)); } }; // in the future when we support both batch and streaming modes for the source operator, // and when this one is migrated to the "eager initialization" operator (StreamOperatorV2), // then we should evaluate this during operator construction. eventTimeLogic = TimestampsAndWatermarks.createStreamingEventTimeLogic( watermarkStrategy, metricGroup, getProcessingTimeService(), getExecutionConfig().getAutoWatermarkInterval()); sourceReader = readerFactory.apply(context); // restore the state if necessary. final List<SplitT> splits = CollectionUtil.iterableToList(readerState.get()); if (!splits.isEmpty()) { sourceReader.addSplits(splits); } // Start the reader. sourceReader.start(); // Register the reader to the coordinator. registerReader(); eventTimeLogic.startPeriodicWatermarkEmits(); }
Example #14
Source File: SourceOperatorTest.java From flink with Apache License 2.0 | 5 votes |
@Test public void testSnapshotState() throws Exception { StateInitializationContext stateContext = getStateContext(); operator.initializeState(stateContext); operator.open(); MockSourceSplit newSplit = new MockSourceSplit((2)); operator.handleOperatorEvent(new AddSplitEvent<>( Collections.singletonList(newSplit), new MockSourceSplitSerializer())); operator.snapshotState(new StateSnapshotContextSynchronousImpl(100L, 100L)); // Verify the splits in state. List<MockSourceSplit> splitsInState = CollectionUtil.iterableToList(operator.getReaderState().get()); assertEquals(Arrays.asList(MOCK_SPLIT, newSplit), splitsInState); }
Example #15
Source File: StatisticsDao.java From pinpoint with Apache License 2.0 | 5 votes |
private List<JoinStatBo> castJoinStatBoList(List<? extends JoinStatBo> JoinStatBoList) { if (CollectionUtil.isNullOrEmpty(JoinStatBoList)) { return new ArrayList<>(0); } return new ArrayList<>(JoinStatBoList); }