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;
        }
    }