Uploaded image for project: 'Apache Drill'
  1. Apache Drill
  2. DRILL-5070

Code gen: create methods in fixed order to allow test verification



    • Bug
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 1.8.0
    • 1.10.0
    • None
    • None


      A handy technique in testing is to compare generated code against a "golden" copy that defines the expected results. However, at present, Drill generates code using the method order returned by Class.getDeclaredMethods, but this method makes no guarantee about the order of the methods. The order varies from one run to the next. There is some evidence this link that order can vary even within a single run, though a quick test was unable to reproduce this case.

      If method order does indeed vary within a single run, then the order can impact the Drill code cache since it compares the sources from two different generation events to detect duplicate code.

      This issue appeared when attempting to modify tests to capture generated code for comparison to future results. Even a simple generated case from ExpressionTest.testBasicExpression() that generates if(true) then 1 else 0 end (all constants) produced methods in different orders on each test run.

      The fix is simple, in the SignatureHolder constructor, sort methods by name after retrieving them from the class. The sort ensures that method order is deterministic. Fortunately, the number of methods is small, so the sort step adds little cost.


        Issue Links



              paul-rogers Paul Rogers
              paul-rogers Paul Rogers
              Karthikeyan Manivannan Karthikeyan Manivannan
              0 Vote for this issue
              4 Start watching this issue