简体   繁体   中英

Apache Flink error java.lang.ClassNotFoundException: org.apache.flink.table.sources.TableSource?

I am writing a streaming service in Apache Flink. I am basically picking data from a CSV file by using org.apache.flink.table.sources.CsvTableSource. Below is the code for same:

 StreamTableEnvironment streamTableEnvironment = TableEnvironment
                .getTableEnvironment(streamExecutionEnvironment);

    CsvTableSource csvTableSource = CsvTableSource.builder().path(pathToCsvFile)
            .field("XXX0", Types.SQL_TIMESTAMP).field("XXX1", Types.INT)
            .field("XXX2", Types.DECIMAL).field("XXX3", Types.INT).field("XXX4", Types.INT)
            .field("XXX9", Types.DECIMAL).field("XXX5", Types.STRING)
            .field("XXX6", Types.STRING).field("XXX7", Types.STRING).fieldDelimiter(",").lineDelimiter("\n")
            .ignoreFirstLine().ignoreParseErrors().build();

    streamTableEnvironment.registerTableSource("metrics_table", csvTableSource);

    Table selectedMetricTable = streamTableEnvironment.sqlQuery(getSQLQuery(metricsType, metricsGroupingLevel));

    DataStream<Tuple2<Boolean, MetricsTimeSeriesData>> metricStream = streamTableEnvironment
            .toRetractStream(selectedMetricTable, MetricsTimeSeriesData.class);

But its giving following error :

Caused by: java.lang.ClassNotFoundException: org.apache.flink.table.sources.TableSource

Here are the maven dependencies:

        <dependency>
            <groupId>org.apache.flink</groupId>
            <artifactId>flink-java</artifactId>
            <version>1.4.0</version>
        </dependency>
        <dependency>
            <groupId>org.apache.flink</groupId>
            <artifactId>flink-streaming-java_2.11</artifactId>
            <version>1.4.0</version>
        </dependency>
        <dependency>
            <groupId>org.apache.flink</groupId>
            <artifactId>flink-clients_2.11</artifactId>
            <version>1.4.0</version>
        </dependency>
        <dependency>
            <groupId>org.apache.flink</groupId>
            <artifactId>flink-table_2.11</artifactId>
            <version>1.4.0</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.flink</groupId>
            <artifactId>flink-scala_2.11</artifactId>
            <version>1.4.0</version>
        </dependency>
        <dependency>
            <groupId>org.apache.flink</groupId>
            <artifactId>flink-streaming-scala_2.11</artifactId>
            <version>1.4.0</version>
        </dependency>

I can see the source defination of the above class, still I am getting this error. Please Help?

The module flink-table is not shipped with the flink binary distribution, therefore it is not shipped to the cluster by default. You can either put that dependency to your cluster installation (in \\lib folder) see the last section of setup or you can submit your job as uber-jar with that dependency packaged, see here .

I am using Flink 1.8.0 version, I was facing the same issue. I able to fix it by adding below dependency in pom.xml by pointing to flink-table_2.12-1.8.0.jar from my system path.

        <dependency>
            <groupId>org.apache.flink</groupId>
            <artifactId>flink-table_2.12</artifactId>
            <version>1.8.0</version>
            <scope>system</scope>
            <systemPath>E:\flink-1.8.0-scala_2.12\opt\flink-table_2.12-1.8.0.jar</systemPath>
        </dependency>

Hope it will help you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM