主要是用于获取元组中指定字段的值,注意只能用于元组,不能用在其他数据类型。
代码 public static void main(String[] args) throws Exception {
StreamExecutionEnvironment executionEnvironment = StreamExecutionEnvironment.getExecutionEnvironment();
executionEnvironment.setParallelism(1);
DataStream> dataStream1 = executionEnvironment.fromCollection(Arrays.asList(
new Tuple3("sensor_1", 1547718199, 35.8),
new Tuple3("sensor_6", 1547718201, 15.4),
new Tuple3("sensor_7", 1547718202, 6.7),
new Tuple3("sensor_6", 1547718203, 15.9),
new Tuple3("sensor_10", 1547718205, 38.1),
new Tuple3("sensor_6", 1547718206, 15.1),
new Tuple3("sensor_6", 1547718209, 15.0)
));
SingleOutputStreamOperator projectStream = dataStream1.project(0, 2);
projectStream.print();
结果:
(sensor_1,35.8) (sensor_6,15.4) (sensor_7,6.7) (sensor_6,15.9) (sensor_10,38.1) (sensor_6,15.1) (sensor_6,15.0) Process finished with exit code 0



