<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();
}
```