Uploaded image for project: 'Calcite'
  1. Calcite
  2. CALCITE-6244

Improve `Expressions#constant` to allow Java records

    XMLWordPrintableJSON

Details

    Description

      To use Expressions#constant with complex models, it's required to pass a model with public fields, as can be seen in this test.

      i.e. to successfully pass an instance of `Employee`, it must be defined as follows:

      public static class Employee {
          public final int empno;
          public final String name;
          public final int deptno;    public Employee(int empno, String name, int deptno) {
            this.empno = empno;
            this.name = name;
            this.deptno = deptno;
          }    public String toString() {
            return "Employee(name: " + name + ", deptno:" + deptno + ")";
          }    @Override public int hashCode() {
            final int prime = 31;
            int result = 1;
            result = prime * result + deptno;
            result = prime * result + empno;
            result = prime * result + ((name == null) ? 0 : name.hashCode());
            return result;
          }    @Override public boolean equals(Object obj) {
            if (this == obj) {
              return true;
            }
            if (obj == null) {
              return false;
            }
            if (getClass() != obj.getClass()) {
              return false;
            }
            Employee other = (Employee) obj;
            if (deptno != other.deptno) {
              return false;
            }
            if (empno != other.empno) {
              return false;
            }
            if (name == null) {
              if (other.name != null) {
                return false;
              }
            } else if (!name.equals(other.name)) {
              return false;
            }
            return true;
          }
        } 

      This makes it difficult to use generated classes e.g. Java records or immutables, or even encapsulated POJOs to pass through Linq4j.

      This is caused by the logic to explore and create the model constructor; which depends on:

      value.getClass().getFields() 

      which only accesses public fields.

      Proposed solution: Access fields using reflection, by accessing their getter methods.

      Attachments

        Issue Links

          Activity

            People

              wegdanghazi Wegdan Ghazi
              wegdanghazi Wegdan Ghazi
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: