yaooqinn commented on issue #26410: [SPARK-29387][SQL][FOLLOWUP] Fix issues of the multiply and divide for intervals URL: https://github.com/apache/spark/pull/26410#issuecomment-550285253 Put the code gen diff here in case we may find the root cause. ```sql explain codegen select cast(k as interval) / v from VALUES ('2 seconds', 0) t(k, v) ``` # without ```java /* 001 */ public Object generate(Object[] references) { /* 002 */ return new GeneratedIteratorForCodegenStage1(references); /* 003 */ } /* 004 */ /* 005 */ // codegenStageId=1 /* 006 */ final class GeneratedIteratorForCodegenStage1 extends org.apache.spark.sql.execution.BufferedRowIterator { /* 007 */ private Object[] references; /* 008 */ private scala.collection.Iterator[] inputs; /* 009 */ private scala.collection.Iterator localtablescan_input_0; /* 010 */ private org.apache.spark.sql.catalyst.expressions.codegen.UnsafeRowWriter[] project_mutableStateArray_0 = new org.apache.spark.sql.catalyst.expressions.codegen.UnsafeRowWriter[1]; /* 011 */ /* 012 */ public GeneratedIteratorForCodegenStage1(Object[] references) { /* 013 */ this.references = references; /* 014 */ } /* 015 */ /* 016 */ public void init(int index, scala.collection.Iterator[] inputs) { /* 017 */ partitionIndex = index; /* 018 */ this.inputs = inputs; /* 019 */ localtablescan_input_0 = inputs[0]; /* 020 */ project_mutableStateArray_0[0] = new org.apache.spark.sql.catalyst.expressions.codegen.UnsafeRowWriter(1, 32); /* 021 */ /* 022 */ } /* 023 */ /* 024 */ protected void processNext() throws java.io.IOException { /* 025 */ while ( localtablescan_input_0.hasNext()) { /* 026 */ InternalRow localtablescan_row_0 = (InternalRow) localtablescan_input_0.next(); /* 027 */ ((org.apache.spark.sql.execution.metric.SQLMetric) references[0] /* numOutputRows */).add(1); /* 028 */ boolean project_isNull_0 = true; /* 029 */ CalendarInterval project_value_0 = null; /* 030 */ UTF8String localtablescan_value_0 = localtablescan_row_0.getUTF8String(0); /* 031 */ boolean project_isNull_1 = false; /* 032 */ CalendarInterval project_value_1 = null; /* 033 */ if (!false) { /* 034 */ project_value_1 = org.apache.spark.sql.catalyst.util.IntervalUtils.safeFromString(localtablescan_value_0.toString()); /* 035 */ if(project_value_1 == null) { /* 036 */ project_isNull_1 = true; /* 037 */ } /* 038 */ } /* 039 */ if (!project_isNull_1) { /* 040 */ int localtablescan_value_1 = localtablescan_row_0.getInt(1); /* 041 */ boolean project_isNull_3 = false; /* 042 */ double project_value_3 = -1.0; /* 043 */ if (!false) { /* 044 */ project_value_3 = (double) localtablescan_value_1; /* 045 */ } /* 046 */ /* 047 */ project_isNull_0 = false; // resultCode could change nullability. /* 048 */ /* 049 */ try { /* 050 */ project_value_0 = org.apache.spark.sql.catalyst.util.IntervalUtils.divide(project_value_1, project_value_3); /* 051 */ } catch (java.lang.ArithmeticException e) { /* 052 */ project_isNull_0 = true; /* 053 */ } /* 054 */ /* 055 */ } /* 056 */ project_mutableStateArray_0[0].reset(); /* 057 */ /* 058 */ project_mutableStateArray_0[0].zeroOutNullBytes(); /* 059 */ /* 060 */ if (project_isNull_0) { /* 061 */ project_mutableStateArray_0[0].setNullAt(0); /* 062 */ } else { /* 063 */ project_mutableStateArray_0[0].write(0, project_value_0); /* 064 */ } /* 065 */ append((project_mutableStateArray_0[0].getRow())); /* 066 */ if (shouldStop()) return; /* 067 */ } /* 068 */ } /* 069 */ /* 070 */ } ``` # with patch ```java /* 001 */ public Object generate(Object[] references) { /* 002 */ return new GeneratedIteratorForCodegenStage1(references); /* 003 */ } /* 004 */ /* 005 */ // codegenStageId=1 /* 006 */ final class GeneratedIteratorForCodegenStage1 extends org.apache.spark.sql.execution.BufferedRowIterator { /* 007 */ private Object[] references; /* 008 */ private scala.collection.Iterator[] inputs; /* 009 */ private scala.collection.Iterator localtablescan_input_0; /* 010 */ private org.apache.spark.sql.catalyst.expressions.codegen.UnsafeRowWriter[] project_mutableStateArray_0 = new org.apache.spark.sql.catalyst.expressions.codegen.UnsafeRowWriter[1]; /* 011 */ /* 012 */ public GeneratedIteratorForCodegenStage1(Object[] references) { /* 013 */ this.references = references; /* 014 */ } /* 015 */ /* 016 */ public void init(int index, scala.collection.Iterator[] inputs) { /* 017 */ partitionIndex = index; /* 018 */ this.inputs = inputs; /* 019 */ localtablescan_input_0 = inputs[0]; /* 020 */ project_mutableStateArray_0[0] = new org.apache.spark.sql.catalyst.expressions.codegen.UnsafeRowWriter(1, 32); /* 021 */ /* 022 */ } /* 023 */ /* 024 */ protected void processNext() throws java.io.IOException { /* 025 */ while ( localtablescan_input_0.hasNext()) { /* 026 */ InternalRow localtablescan_row_0 = (InternalRow) localtablescan_input_0.next(); /* 027 */ ((org.apache.spark.sql.execution.metric.SQLMetric) references[0] /* numOutputRows */).add(1); /* 028 */ boolean project_isNull_0 = true; /* 029 */ CalendarInterval project_value_0 = null; /* 030 */ UTF8String localtablescan_value_0 = localtablescan_row_0.getUTF8String(0); /* 031 */ boolean project_isNull_1 = false; /* 032 */ CalendarInterval project_value_1 = null; /* 033 */ if (!false) { /* 034 */ project_value_1 = org.apache.spark.sql.catalyst.util.IntervalUtils.safeFromString(localtablescan_value_0.toString()); /* 035 */ if(project_value_1 == null) { /* 036 */ project_isNull_1 = true; /* 037 */ } /* 038 */ } /* 039 */ if (!project_isNull_1) { /* 040 */ int localtablescan_value_1 = localtablescan_row_0.getInt(1); /* 041 */ boolean project_isNull_3 = false; /* 042 */ double project_value_3 = -1.0; /* 043 */ if (!false) { /* 044 */ project_value_3 = (double) localtablescan_value_1; /* 045 */ } /* 046 */ /* 047 */ project_isNull_0 = false; // resultCode could change nullability. /* 048 */ /* 049 */ try { /* 050 */ project_value_0 = org.apache.spark.sql.catalyst.util.IntervalUtils.divide(project_value_1, project_value_3); /* 051 */ if (project_value_0 == null) { /* 052 */ project_isNull_0 = true; /* 053 */ } /* 054 */ } catch (java.lang.ArithmeticException e) { /* 055 */ project_isNull_0 = true; /* 056 */ } /* 057 */ /* 058 */ } /* 059 */ project_mutableStateArray_0[0].reset(); /* 060 */ /* 061 */ project_mutableStateArray_0[0].zeroOutNullBytes(); /* 062 */ /* 063 */ if (project_isNull_0) { /* 064 */ project_mutableStateArray_0[0].setNullAt(0); /* 065 */ } else { /* 066 */ project_mutableStateArray_0[0].write(0, project_value_0); /* 067 */ } /* 068 */ append((project_mutableStateArray_0[0].getRow())); /* 069 */ if (shouldStop()) return; /* 070 */ } /* 071 */ } /* 072 */ /* 073 */ } ```
---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected] With regards, Apache Git Services --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
