@@ -18,6 +18,7 @@ import { SparkSQL, SparkSQLs, SqlStatus } from "../interfaces/SparkSQLs";
1818import { NodesMetrics } from "../interfaces/SqlMetrics" ;
1919import {
2020 calculatePercentage ,
21+ capitalizeWords ,
2122 timeStrToEpocTime ,
2223 timeStringToMilliseconds ,
2324} from "../utils/FormatUtils" ;
@@ -222,7 +223,7 @@ function calculateSql(
222223 rddScopeId : nodePlan ?. rddScopeId ,
223224 type : type ,
224225 parsedPlan : parsedPlan ,
225- enrichedName : nodeEnrichedNameBuilder ( node . nodeName , parsedPlan ) ,
226+ enrichedName : capitalizeWords ( nodeEnrichedNameBuilder ( node . nodeName , parsedPlan ) ) ,
226227 isCodegenNode : isCodegenNode ,
227228 wholeStageCodegenId : isCodegenNode
228229 ? extractCodegenId ( )
@@ -702,6 +703,36 @@ function updateParsedPlan(
702703 return node . parsedPlan ;
703704}
704705
706+ function addGenerateMetrics (
707+ node : EnrichedSqlNode ,
708+ updatedMetrics : EnrichedSqlMetric [ ] ,
709+ graph : Graph ,
710+ allNodes : EnrichedSqlNode [ ] ,
711+ ) : EnrichedSqlMetric | null {
712+ if ( node . nodeName === "Generate" ) {
713+ const inputNode = findLastNodeWithInputRows ( node , graph , allNodes ) ;
714+ if ( ! inputNode ) {
715+ return null ;
716+ }
717+
718+ const inputRows = getRowsFromMetrics ( inputNode . metrics ) ;
719+ if ( inputRows === null || inputRows === 0 ) {
720+ return null ;
721+ }
722+
723+ const outputRows = getRowsFromMetrics ( updatedMetrics ) ;
724+ if ( outputRows === null ) {
725+ return null ;
726+ }
727+
728+ const ratio = outputRows / inputRows ;
729+ const ratioFormatted = ratio . toFixed ( 2 ) ;
730+
731+ return { name : `${ node . enrichedName } Ratio` , value : `${ ratioFormatted } X` } ;
732+ }
733+ return null ;
734+ }
735+
705736function updateNodeMetrics (
706737 node : EnrichedSqlNode ,
707738 metrics : EnrichedSqlMetric [ ] ,
@@ -712,6 +743,7 @@ function updateNodeMetrics(
712743 const filterRatio = addFilterRatioMetric ( node , updatedOriginalMetrics , graph , allNodes ) ;
713744 const crossJoinFilterRatio = addCrossJoinFilterRatioMetric ( node , updatedOriginalMetrics , graph , allNodes ) ;
714745 const joinMetrics = addJoinMetrics ( node , updatedOriginalMetrics , graph , allNodes ) ;
746+ const generateMetrics = addGenerateMetrics ( node , updatedOriginalMetrics , graph , allNodes ) ;
715747 return [
716748 ...updatedOriginalMetrics ,
717749 ...( filterRatio !== null
@@ -723,6 +755,9 @@ function updateNodeMetrics(
723755 ...( joinMetrics !== null
724756 ? joinMetrics
725757 : [ ] ) ,
758+ ...( generateMetrics !== null
759+ ? [ generateMetrics ]
760+ : [ ] ) ,
726761 ] ;
727762}
728763
0 commit comments