hf200012 commented on a change in pull request #6490: URL: https://github.com/apache/incubator-doris/pull/6490#discussion_r693778066
########## File path: samples/doris-demo/flink-demo/src/main/java/org/apache/doris/demo/flink/analyze/DorisSource.java ########## @@ -0,0 +1,93 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package org.apache.doris.demo.flink.analyze; + +import org.apache.doris.demo.flink.User; +import org.apache.flink.configuration.Configuration; +import org.apache.flink.streaming.api.functions.source.RichSourceFunction; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.sql.*; Review comment: Don't use import * ########## File path: samples/doris-demo/flink-demo/src/main/java/org/apache/doris/demo/flink/DorisStreamLoad.java ########## @@ -0,0 +1,157 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package org.apache.doris.demo.flink; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.*; Review comment: Don't use import * ########## File path: samples/doris-demo/flink-demo/src/main/java/org/apache/doris/demo/flink/analyze/FlinkDorisConnectorAnalyze.java ########## @@ -0,0 +1,79 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package org.apache.doris.demo.flink.analyze; + +import org.apache.doris.demo.flink.User; +import org.apache.doris.flink.cfg.DorisStreamOptions; +import org.apache.doris.flink.datastream.DorisSourceFunction; +import org.apache.flink.api.common.functions.MapFunction; +import org.apache.flink.api.java.functions.KeySelector; +import org.apache.flink.streaming.api.datastream.DataStreamSource; +import org.apache.flink.streaming.api.datastream.SingleOutputStreamOperator; +import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment; + +import java.util.ArrayList; +import java.util.Properties; + + +/** + * This example mainly demonstrates the use of Flink connector to read Doris data, + * build DataStream for analysis, and sum. + * <p> + * use flink doris connector + */ +public class FlinkDorisConnectorAnalyze { + + public static void main(String[] args) throws Exception { + Properties properties = new Properties(); + properties.put("fenodes", "IP:8030"); + properties.put("username", "root"); + properties.put("password", ""); + properties.put("table.identifier", "test1.doris_test_source_2"); + + DorisStreamOptions options = new DorisStreamOptions(properties); + + final StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment(); + env.setParallelism(2); + + DataStreamSource dataStreamSource = env.addSource(new DorisSourceFunction(options, new User())); + + SingleOutputStreamOperator outputStream = dataStreamSource.map(new MapFunction<Object, User>() { + @Override + public User map(Object obj) throws Exception { + User user = new User(); + if (obj instanceof ArrayList<?>) { + user.setName(((ArrayList<?>) obj).get(0).toString()); + user.setAge(Integer.valueOf(((ArrayList<?>) obj).get(1).toString())); + user.setPrice(((ArrayList<?>) obj).get(2).toString()); + user.setSale(((ArrayList<?>) obj).get(3).toString()); + } + return user; + } + }); + + outputStream.keyBy(new KeySelector<User, String>() { + @Override + public String getKey(User user) throws Exception { + return user.getName(); + } + }) + .sum("age") Review comment: code style -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
