Home > Mobile >  Scala:Cannot resolve overloaded method 'fromCollection', while 'fromCollection'
Scala:Cannot resolve overloaded method 'fromCollection', while 'fromCollection'

Time:06-20

I use flink to process some data. And I found fromCollection in StreamExecutionEnvironment has many implementations.

enter image description here

Som part of the pom.xml is :

    <properties>
        <maven.compiler.source>8</maven.compiler.source>
        <maven.compiler.target>8</maven.compiler.target>

        <scala.version>2.12.16</scala.version>
        <scala.binary.version>2.12</scala.binary.version>
        <flink.version>1.14.4</flink.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
        </dependency>

        

        <!-- SQL Server-->
        <dependency>
            <groupId>com.microsoft.sqlserver</groupId>
            <artifactId>sqljdbc4</artifactId>
            <version>4.0</version>
        </dependency>

        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>druid-spring-boot-starter</artifactId>
            <version>1.1.10</version>
        </dependency>

       

        <dependency>
            <groupId>org.scala-lang</groupId>
            <artifactId>scala-library</artifactId>
            <version>${scala.version}</version>
        </dependency>

        <dependency>
            <groupId>com.microsoft.sqlserver</groupId>
            <artifactId>mssql-jdbc</artifactId>
            <scope>runtime</scope>
        </dependency>

       

        <dependency>
            <groupId>org.apache.flink</groupId>
            <artifactId>flink-streaming-scala_${scala.binary.version}</artifactId>
            <version>1.14.4</version>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>org.apache.flink</groupId>
            <artifactId>flink-clients_${scala.binary.version}</artifactId>
            <version>1.14.4</version>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>org.apache.flink</groupId>
            <artifactId>flink-runtime-web_${scala.binary.version}</artifactId>
            <version>1.14.4</version>
        </dependency>
    </dependencies>

It seems that Scala cannot dertemine which fromCollection method to use.

package com.mycode.learnflink.ts.sync

import com.mycode.learnflink.model.datasourcesync.domain.RiverWaterRegime
import org.apache.flink.streaming.api.datastream.DataStreamSource
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment



class SyncWater {

  var cachedRiverWaterRegimes: List[RiverWaterRegime] = List()
  private val BATCH_SIZE = 1000
  private var size = 0

  def flinkProcess(list:List[RiverWaterRegime] ): Unit = {
    val env = StreamExecutionEnvironment.getExecutionEnvironment
    env.setParallelism(6)

    val source:DataStreamSource[String] = env.fromCollection(list) // Error:Cannot resolve overloaded method 'fromCollection'
    
  }
  
}

What can I do to eliminate this error?

CodePudding user response:

In your case, the imported package should be Scala ones.

Here is the example.

import org.apache.flink.streaming.api.scala.{StreamExecutionEnvironment, createTypeInformation}

class SyncWater {

  type RiverWaterRegime = Int
  private val BATCH_SIZE = 1000
  private var size = 0

  def flinkProcess(list:List[RiverWaterRegime] ): Unit = {
    val env = StreamExecutionEnvironment.getExecutionEnvironment
    env.setParallelism(6)

    val source = env.fromCollection(list)

  }
}

  • Related