Spark 踩坑记录

Encoders.bean(Person.class) 调用报异常

  • 异常信息

    Exception in thread "main" java.lang.UnsupportedOperationException: Cannot infer type for class personal.leo.spark.Person because it is not bean-compliant
  • 原因: Bean的 getter,setter,不能使用 Builder 模式,否则会出现该错误

  • 例子

    • 正常代码

      public class Person implements Serializable {
          private String name;
          private int age;
      
          public String getName() {
              return name;
          }
      
          public void setName(String name) {
              this.name = name;
          }
      
          public int getAge() {
              return age;
          }
      
          public void setAge(int age) {
              this.age = age;
          }
      }
    • 异常代码

      public class Person implements Serializable {
          private String name;
          private int age;
      
          public String getName() {
              return name;
          }
      
          public Person setName(String name) {
              this.name = name;
              return this;
          }
      
          public int getAge() {
              return age;
          }
      
          public Person setAge(int age) {
              return this;
              this.age = age;
          }
      }

你可能感兴趣的:(13.2.Big,Data,&,OLAP,--13.2.4.Spark)