当前位置: 首页>>代码示例>>Java>>正文


Java FilterFunction类代码示例

本文整理汇总了Java中org.apache.flink.api.common.functions.FilterFunction的典型用法代码示例。如果您正苦于以下问题:Java FilterFunction类的具体用法?Java FilterFunction怎么用?Java FilterFunction使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


FilterFunction类属于org.apache.flink.api.common.functions包,在下文中一共展示了FilterFunction类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: main

import org.apache.flink.api.common.functions.FilterFunction; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
	StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();

	Properties properties = new Properties();
	properties.setProperty("bootstrap.servers", "localhost:9092");
	properties.setProperty("group.id", "test");

	DataStream<TemperatureEvent> inputEventStream = env.addSource(
			new FlinkKafkaConsumer09<TemperatureEvent>("test", new EventDeserializationSchema(), properties));

	Pattern<TemperatureEvent, ?> warningPattern = Pattern.<TemperatureEvent> begin("first")
			.subtype(TemperatureEvent.class).where(new FilterFunction<TemperatureEvent>() {
				private static final long serialVersionUID = 1L;

				public boolean filter(TemperatureEvent value) {
					if (value.getTemperature() >= 26.0) {
						return true;
					}
					return false;
				}
			}).within(Time.seconds(10));

	DataStream<Alert> patternStream = CEP.pattern(inputEventStream, warningPattern)
			.select(new PatternSelectFunction<TemperatureEvent, Alert>() {
				private static final long serialVersionUID = 1L;

				public Alert select(Map<String, TemperatureEvent> event) throws Exception {

					return new Alert("Temperature Rise Detected:" + event.get("first").getTemperature()
							+ " on machine name:" + event.get("first").getMachineName());
				}

			});

	patternStream.print();
	env.execute("CEP on Temperature Sensor");
}
 
开发者ID:PacktPublishing,项目名称:Mastering-Apache-Flink,代码行数:38,代码来源:KafkaApp.java

示例2: testDefaultName

import org.apache.flink.api.common.functions.FilterFunction; //导入依赖的package包/类
@Test
public void testDefaultName() {
	ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();

	DataSet<String> strs = env.fromCollection(Arrays.asList("a", "b"));

	// WARNING: The test will fail if this line is being moved down in the file (the line-number is hard-coded)
	strs.filter(new FilterFunction<String>() {
		private static final long serialVersionUID = 1L;

		@Override
		public boolean filter(String value) throws Exception {
			return value.equals("a");
		}
	}).output(new DiscardingOutputFormat<String>());
	Plan plan = env.createProgramPlan();
	testForName("Filter at testDefaultName(NamesTest.java:55)", plan);
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:19,代码来源:NamesTest.java

示例3: testFilterVertices

import org.apache.flink.api.common.functions.FilterFunction; //导入依赖的package包/类
@SuppressWarnings("serial")
@Test
public void testFilterVertices() throws Exception {
	/*
	 * Test filterOnVertices:
	 */
	final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();

	Graph<Long, Long, Long> graph = Graph.fromDataSet(TestGraphUtils.getLongLongVertexData(env),
		TestGraphUtils.getLongLongEdgeData(env), env);

	DataSet<Edge<Long, Long>> data = graph.filterOnVertices(new FilterFunction<Vertex<Long, Long>>() {
		public boolean filter(Vertex<Long, Long> vertex) throws Exception {
			return (vertex.getValue() > 2);
		}
	}).getEdges();

	List<Edge<Long, Long>> result = data.collect();

	expectedResult = "3,4,34\n" +
		"3,5,35\n" +
		"4,5,45\n";

	compareResultAsTuples(result, expectedResult);
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:26,代码来源:GraphOperationsITCase.java

示例4: testFilterEdges

import org.apache.flink.api.common.functions.FilterFunction; //导入依赖的package包/类
@SuppressWarnings("serial")
@Test
public void testFilterEdges() throws Exception {
	/*
	 * Test filterOnEdges:
	 */
	final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();

	Graph<Long, Long, Long> graph = Graph.fromDataSet(TestGraphUtils.getLongLongVertexData(env),
		TestGraphUtils.getLongLongEdgeData(env), env);

	DataSet<Edge<Long, Long>> data = graph.filterOnEdges(new FilterFunction<Edge<Long, Long>>() {
		public boolean filter(Edge<Long, Long> edge) throws Exception {
			return (edge.getValue() > 34);
		}
	}).getEdges();

	List<Edge<Long, Long>> result = data.collect();

	expectedResult = "3,5,35\n" +
		"4,5,45\n" +
		"5,1,51\n";

	compareResultAsTuples(result, expectedResult);
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:26,代码来源:GraphOperationsITCase.java

示例5: testInheritOverride

import org.apache.flink.api.common.functions.FilterFunction; //导入依赖的package包/类
@Test
public void testInheritOverride() {
	// verify that we can explicitly disable inheritance of the input slot sharing groups

	StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();

	FilterFunction<Long> dummyFilter = new FilterFunction<Long>() {
		@Override
		public boolean filter(Long value) {
			return false;
		}
	};

	DataStream<Long> src1 = env.generateSequence(1, 10).slotSharingGroup("group-1");
	DataStream<Long> src2 = env.generateSequence(1, 10).slotSharingGroup("group-1");

	// this should not inherit group but be in "default"
	src1.union(src2).filter(dummyFilter).slotSharingGroup("default");
	JobGraph jobGraph = env.getStreamGraph().getJobGraph();

	List<JobVertex> vertices = jobGraph.getVerticesSortedTopologicallyFromSources();

	assertEquals(vertices.get(0).getSlotSharingGroup(), vertices.get(1).getSlotSharingGroup());
	assertNotEquals(vertices.get(0).getSlotSharingGroup(), vertices.get(2).getSlotSharingGroup());
	assertNotEquals(vertices.get(1).getSlotSharingGroup(), vertices.get(2).getSlotSharingGroup());
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:27,代码来源:SlotAllocationTest.java

示例6: getGraphs

import org.apache.flink.api.common.functions.FilterFunction; //导入依赖的package包/类
/**
 * {@inheritDoc}
 */
@Override
public GraphCollection getGraphs(final GradoopIdSet identifiers) {

  DataSet<GraphHead> newGraphHeads = this.getGraphHeads()
    .filter(new FilterFunction<GraphHead>() {
      @Override
      public boolean filter(GraphHead graphHead) throws Exception {
        return identifiers.contains(graphHead.getId());
      }
    });

  // build new vertex set
  DataSet<Vertex> vertices = getVertices()
    .filter(new InAnyGraph<>(identifiers));

  // build new edge set
  DataSet<Edge> edges = getEdges()
    .filter(new InAnyGraph<>(identifiers));

  return new GraphCollection(
    getConfig().getGraphCollectionFactory().fromDataSets(newGraphHeads, vertices, edges),
    getConfig());
}
 
开发者ID:dbs-leipzig,项目名称:gradoop,代码行数:27,代码来源:GraphCollection.java

示例7: getCollection

import org.apache.flink.api.common.functions.FilterFunction; //导入依赖的package包/类
/**
 * Returns a collection of all logical graph contained in that EPGM database.
 *
 * @return collection of all logical graphs
 */
@Deprecated
public GraphCollection getCollection() {
  DataSet<Vertex> newVertices = database.getVertices()
      .filter(new FilterFunction<Vertex>() {
        @Override
        public boolean filter(Vertex vertex) throws
          Exception {
          return vertex.getGraphCount() > 0;
        }
      });
  DataSet<Edge> newEdges = database.getEdges()
    .filter(new FilterFunction<Edge>() {
      @Override
      public boolean filter(Edge longEDEdge) throws Exception {
        return longEDEdge.getGraphCount() > 0;
      }
    });

  return config.getGraphCollectionFactory()
    .fromDataSets(database.getGraphHeads(), newVertices, newEdges);
}
 
开发者ID:dbs-leipzig,项目名称:gradoop,代码行数:27,代码来源:EPGMDatabase.java

示例8: testSelectionWithResult

import org.apache.flink.api.common.functions.FilterFunction; //导入依赖的package包/类
@Test
public void testSelectionWithResult() throws Exception {
  FlinkAsciiGraphLoader loader = getSocialNetworkLoader();

  GraphCollection inputCollection =
    loader.getGraphCollectionByVariables("g0", "g1", "g2");

  GraphCollection expectedOutputCollection =
    loader.getGraphCollectionByVariables("g0", "g1");

  FilterFunction<GraphHead> predicateFunc = (FilterFunction<GraphHead>) entity ->
    entity.hasProperty("vertexCount") && entity.getPropertyValue("vertexCount").getInt() == 3;

  GraphCollection outputCollection = inputCollection.select(predicateFunc);

  collectAndAssertTrue(
    expectedOutputCollection.equalsByGraphElementIds(outputCollection));
}
 
开发者ID:dbs-leipzig,项目名称:gradoop,代码行数:19,代码来源:SelectionTest.java

示例9: plan

import org.apache.flink.api.common.functions.FilterFunction; //导入依赖的package包/类
public void plan() throws Exception {

        String clickStreamInputFilename = args[0];
        outputFilename = args[1];

        result = ClickStreamHelper.getClickStreamDataSet(env, clickStreamInputFilename)
                .filter(new FilterFunction<ClickStreamTuple>() {
                    @Override
                    public boolean filter(ClickStreamTuple test) throws Exception {
                        int impressions = test.getImpressions();
                        int allClicks = 0;

                        for (int clicks : test.getOutClicks().values()) {
                            allClicks += clicks;
                        }

                        // Is record valid?
                        return (allClicks > impressions);
                    }
                });

    }
 
开发者ID:wikimedia,项目名称:citolytics,代码行数:23,代码来源:ValidateClickStreamData.java

示例10: main

import org.apache.flink.api.common.functions.FilterFunction; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
	
	// set up the execution environment
	final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
	System.err.println("Using input="+args[0]);
	// get input data
	DataSet<String> text = env.readTextFile(args[0]);
	DataSet<String> res = text.filter(new FilterFunction<String>() {
		@Override
		public boolean filter(String value) throws Exception {
			return false;
		}
	});
	res.writeAsText("file:///tmp/out", WriteMode.OVERWRITE);
	
	// execute program
	env.execute("Read only job");
}
 
开发者ID:project-flink,项目名称:flink-perf,代码行数:19,代码来源:Readonly.java

示例11: main

import org.apache.flink.api.common.functions.FilterFunction; //导入依赖的package包/类
public static void main(String... args) throws Exception {
    final StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
    DataStream<WikipediaEditEvent> edits = env.addSource(new WikipediaEditsSource());

    edits.filter((FilterFunction<WikipediaEditEvent>) edit -> {
        return !edit.isBotEdit() && edit.getByteDiff() > 1000;
    })
    .print();

    env.execute();
}
 
开发者ID:mushketyk,项目名称:flink-examples,代码行数:12,代码来源:FilterWikiEdits.java

示例12: main

import org.apache.flink.api.common.functions.FilterFunction; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
	StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
	DataStream<TemperatureEvent> inputEventStream = env.fromElements(new TemperatureEvent("xyz", 22.0),
			new TemperatureEvent("xyz", 20.1), new TemperatureEvent("xyz", 21.1), new TemperatureEvent("xyz", 22.2),
			new TemperatureEvent("xyz", 29.1), new TemperatureEvent("xyz", 22.3), new TemperatureEvent("xyz", 22.1),
			new TemperatureEvent("xyz", 22.4), new TemperatureEvent("xyz", 22.7),
			new TemperatureEvent("xyz", 27.0));

	Pattern<TemperatureEvent, ?> warningPattern = Pattern.<TemperatureEvent> begin("first")
			.subtype(TemperatureEvent.class).where(new FilterFunction<TemperatureEvent>() {
				private static final long serialVersionUID = 1L;

				public boolean filter(TemperatureEvent value) {
					if (value.getTemperature() >= 26.0) {
						return true;
					}
					return false;
				}
			}).within(Time.seconds(10));

	DataStream<Alert> patternStream = CEP.pattern(inputEventStream, warningPattern)
			.select(new PatternSelectFunction<TemperatureEvent, Alert>() {
				private static final long serialVersionUID = 1L;

				public Alert select(Map<String, TemperatureEvent> event) throws Exception {

					return new Alert("Temperature Rise Detected");
				}

			});

	patternStream.print();
	env.execute("CEP on Temperature Sensor");
}
 
开发者ID:PacktPublishing,项目名称:Mastering-Apache-Flink,代码行数:35,代码来源:App.java

示例13: main

import org.apache.flink.api.common.functions.FilterFunction; //导入依赖的package包/类
public static void main(String[] args) throws Exception {

		// read parameters
		ParameterTool params = ParameterTool.fromArgs(args);
		String nycTaxiRidesPath = params.getRequired("nycTaxiRidesPath");

		final int popThreshold = 20;        // threshold for popular places
		final int maxEventDelay = 60;       // events are out of order by max 60 seconds
		final int servingSpeedFactor = 600; // events of 10 minutes are served in 1 second

		// set up streaming execution environment
		StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();

		// ===============================================================================
		//   1. remember to set this job to use "Event Time"
		// ===============================================================================
		env.setStreamTimeCharacteristic(TimeCharacteristic.EventTime);

		// start the data generator
		DataStream<TaxiRide> rides = env.addSource(
				new TaxiRideSource(nycTaxiRidesPath, maxEventDelay, servingSpeedFactor));

		// ===============================================================================
		//   2. again, filter ride events to contain only valid geo coordinates
		//   3. map each ride event to a tuple 2 pair: (grid cell id, the event)
		//   4. partition the stream by the grid cell id
		//   5. aggregate the number of ride events (start and end) in each grid cell
		//      over a sliding window (span 15 minutes, slide 1 minute), and output:
		//      (cellId, time, eventCount)
		//   6. filter out window outputs if the number of ride events is
		//      lower than POPULAR_THRESHOLD.
		//   7. map the grid cell back to geo coordinates, and print as format:
		//      (lon, lat, time, eventCount)
		// ===============================================================================
		DataStream<Tuple4<Float, Float, Long, Integer>> popularSpots = rides
				// 2. again, filter ride events to contain only valid geo coordinates
				.filter(new NYCFilter())
				// 3. map each ride event to a tuple 2 pair: (grid cell id, the event)
				.map(new GridCellMatcher())
				// 4. partition the stream by the grid cell id
				.keyBy(0)
				// 5. aggregate the number of ride events (start and end) in each grid cell
				//	  over a sliding window (span 15 minutes, slide 1 minute), and output: (cellId, time, eventCount)
				.timeWindow(Time.minutes(15), Time.minutes(5))
				.apply(new RideCounter())
				// 6. filter out window outputs if the number of ride events is
				// 	  lower than POPULAR_THRESHOLD.
				.filter(new FilterFunction<Tuple3<Integer, Long, Integer>>() {
					@Override
					public boolean filter(Tuple3<Integer, Long, Integer> count) throws Exception {
						return count.f2 >= popThreshold;
					}
				})
				// 7. map the grid cell back to geo coordinates, and print as format: (lon, lat, time, eventCount)
				.map(new GridToCoordinates());

		// print result on stdout
		popularSpots.print();

		// execute the transformation pipeline
		env.execute("Popular Places");
	}
 
开发者ID:flink-taiwan,项目名称:jcconf2016-workshop,代码行数:63,代码来源:TaxiRidePopularPlacesAnswer.java

示例14: readRawData

import org.apache.flink.api.common.functions.FilterFunction; //导入依赖的package包/类
private DataSet<String> readRawData(String path, ExecutionEnvironment env) {
    DataSet<String> data = env.readTextFile(path).filter(new FilterFunction<String>() {
        @Override
        public boolean filter(String value) throws Exception {
            if (value.length() > 1) {
                return true;
            }
            return false;
        }
    });
    return data;
}
 
开发者ID:IIDP,项目名称:OSTMap,代码行数:13,代码来源:GraphLoader.java

示例15: getFilteredDataSet

import org.apache.flink.api.common.functions.FilterFunction; //导入依赖的package包/类
private DataSet<Tuple2<IntValue, IntValue>> getFilteredDataSet(ExecutionEnvironment env) {
	return getDataSet(env)
		.filter(new FilterFunction<Tuple2<IntValue, IntValue>>() {
			@Override
			public boolean filter(Tuple2<IntValue, IntValue> value) throws Exception {
				return (value.f0.getValue() % 2) == 0;
			}
		});
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:10,代码来源:OverwriteObjects.java


注:本文中的org.apache.flink.api.common.functions.FilterFunction类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。