简体   繁体   English

scala.collection.Seq在Java上不起作用

[英]scala.collection.Seq doesn't work on Java

Using: 使用:

  • Apache Spark 2.0.1 Apache Spark 2.0.1
  • Java 7 Java 7

On the Apache Spark Java API documentation for the class DataSet appears an example to use the method join using a scala.collection.Seq parameter to specify the columns names. 在DataSet类的Apache Spark Java API文档上,出现了一个示例 ,该示例使用使用scala.collection.Seq参数的方法join指定列名称。 But I'm not able to use it. 但是我无法使用它。 On the documentation they provide the following example: 在文档中,他们提供了以下示例:

df1.join(df2, Seq("user_id", "user_name"))

Error: Can not find Symbol Method Seq(String) 错误:找不到符号方法Seq(String)

My Code: 我的代码:

import org.apache.spark.sql.Dataset;
import org.apache.spark.sql.Row;
import scala.collection.Seq;

public class UserProfiles {

public static void calcTopShopLookup() {
    Dataset<Row> udp = Spark.getDataFrameFromMySQL("my_schema","table_1");

    Dataset<Row> result = Spark.getSparkSession().table("table_2").join(udp,Seq("col_1","col_2"));
}

Seq(x, y, ...) is a Scala way to create sequence. Seq(x, y, ...)是一种创建序列的Scala方法。 Seq has it's companion object, which has apply method, which allows to not write new each time. Seq有它的伴随对象,该对象具有apply方法,该方法不允许每次都写new

It should be possible to write: 应该可以这样写:

import scala.collection.JavaConversions;
import scala.collection.Seq;

import static java.util.Arrays.asList;

Dataset<Row> result = Spark.getSparkSession().table("table_2").join(udp, JavaConversions.asScalaBuffer(asList("col_1","col_2")));`

Or you can create own small method: 或者您可以创建自己的小方法:

 public static <T> Seq<T> asSeq(T... values) {
        return JavaConversions.asScalaBuffer(asList(values));
    }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 是否可以在一个类中同时实现scala.collection.Seq [T]和java.util.List [T] - Is it possible to implement both scala.collection.Seq[T] and java.util.List[T] in one class 转换scala.collection.Seq的Java对象 <String> 到python列表 - Convert Java object of scala.collection.Seq<String> to python list 在Java代码中从scala.collection.Seq <String>转换为java.util.List <String> - Convert from scala.collection.Seq<String> to java.util.List<String> in Java code java.lang.ClassCastException: org.apache.spark.sql.Column cannot be cast to scala.collection.Seq - java.lang.ClassCastException: org.apache.spark.sql.Column cannot be cast to scala.collection.Seq 如何修复java.lang.ClassCastException:无法将scala.collection.immutable.List实例分配给字段类型scala.collection.Seq? - How to fix java.lang.ClassCastException: cannot assign instance of scala.collection.immutable.List to field type scala.collection.Seq? 如何修复 scala 中的不匹配错误,其中发现:Seq[scala.collection.immutable.Seq required: scala.collection.Seq? - How can I fix mismatch error in scala where the found : Seq[scala.collection.immutable.Seq required: scala.collection.Seq? 在Scala中将Scala.collection.immutable.List的类强制转换为异常到scala.collection.Seq - Getting class cast exception in spark ml for scala.collection.immutable.List to scala.collection.Seq 线程“main”中的异常 java.lang.NoSuchMethodError: &#39;void scala.util.matching.Regex。<init> (java.lang.String, scala.collection.Seq)&#39; - Exception in thread "main" java.lang.NoSuchMethodError: 'void scala.util.matching.Regex.<init>(java.lang.String, scala.collection.Seq)' 如何将Java Collection / List转换为Scala seq? - How to convert a Java Collection/List to a Scala seq? NoClassDefFoundError:标量/集合/序列 - NoClassDefFoundError: scala/collection/Seq
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM