<dependency>
<groupId>org.apache.flink</groupId>
<artifactId>flink-table</artifactId>
<version>1.9.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.flink/flink-table-api-java-bridge -->
<dependency>
<groupId>org.apache.flink</groupId>
<artifactId>flink-table-api-java-bridge_2.11</artifactId>
<version>1.9.0</version>
</dependency>
<dependency>
<groupId>org.apache.flink</groupId>
<artifactId>flink-table-planner_2.11</artifactId>
<version>1.9.0</version>
<scope>provided</scope>
</dependency>
- 2.flink读取csv文件,并使用table api创建逻辑表,使用sql进行操作
public class CsvSource {
public static void main(String[] args) throws Exception {
ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
DataSet<Student> csvInput = env.readCsvFile("C:\\Users\\Lenovo\\Desktop\\test.csv")
.includeFields("10010")
.ignoreFirstLine()
.pojoType(Student.class,"name","score");
BatchTableEnvironment tableEnv = BatchTableEnvironment.create(env);
Table table = tableEnv.fromDataSet(csvInput);
tableEnv.registerTable("test_flink",table);
Table result = tableEnv.sqlQuery("select * from test_flink where name = 'suns1'");
DataSet<Student> doubleDataSet = tableEnv.toDataSet(result, Student.class);
doubleDataSet.print();
}