@@ -2861,102 +2861,6 @@ function timeColumnSignal(
28612861 } ;
28622862}
28632863
2864- function detectDimensionColumnCandidates (
2865- rows : unknown [ ] ,
2866- config : ObConfig ,
2867- schema : string | undefined ,
2868- table : string ,
2869- maxColumns : number
2870- ) {
2871- return rows
2872- . map ( ( row , index ) => {
2873- const metadata = profileColumnMetadata ( row , config . compatibility ) ;
2874- if ( ! metadata ) {
2875- return undefined ;
2876- }
2877- const signal = dimensionColumnSignal ( metadata . name , metadata . dataType , metadata . comment ) ;
2878- if ( signal . confidence < 0.35 ) {
2879- return undefined ;
2880- }
2881- return {
2882- column : metadata . name ,
2883- kind : signal . kind ,
2884- confidence : signal . confidence ,
2885- evidence : signal . evidence ,
2886- dataType : metadata . dataType ,
2887- typeCategory : profileColumnTypeCategory ( metadata . dataType ) ,
2888- nullable : metadata . nullable ,
2889- comment : metadata . comment ,
2890- masked : shouldMaskColumnValue ( metadata . name , config , schema , table ) ,
2891- ordinalPosition : numberRecordValue ( row as Record < string , unknown > , "ordinal_position" , "ORDINAL_POSITION" , "column_id" , "COLUMN_ID" ) ?? index + 1
2892- } ;
2893- } )
2894- . filter ( ( item ) : item is NonNullable < typeof item > => Boolean ( item ) )
2895- . sort ( ( left , right ) => right . confidence - left . confidence || left . ordinalPosition - right . ordinalPosition )
2896- . slice ( 0 , Math . max ( 1 , Math . min ( maxColumns , 50 ) ) ) ;
2897- }
2898-
2899- function dimensionColumnSignal (
2900- columnName : string ,
2901- dataType : string | undefined ,
2902- comment : string | undefined
2903- ) : { kind : string ; confidence : number ; evidence : string [ ] } {
2904- const normalized = columnName . trim ( ) . toLowerCase ( ) ;
2905- const commentText = ( comment ?? "" ) . trim ( ) . toLowerCase ( ) ;
2906- const typeCategory = profileColumnTypeCategory ( dataType ) ;
2907- const evidence : string [ ] = [ ] ;
2908- let confidence = 0 ;
2909- let kind = "generic_dimension" ;
2910-
2911- const namedKind = dimensionKindFromName ( normalized ) ;
2912- if ( namedKind ) {
2913- kind = namedKind ;
2914- confidence += 0.55 ;
2915- evidence . push ( `Column name matches common ${ namedKind . replace ( / _ / g, " " ) } naming.` ) ;
2916- }
2917- if ( [ "enum" , "boolean" ] . includes ( typeCategory ) ) {
2918- confidence += 0.3 ;
2919- evidence . push ( `Type category is ${ typeCategory } .` ) ;
2920- } else if ( typeCategory === "string" && / ( c h a r | v a r c h a r | t e x t | s t r i n g ) / i. test ( dataType ?? "" ) ) {
2921- confidence += 0.15 ;
2922- evidence . push ( "String type can represent a categorical value." ) ;
2923- } else if ( typeCategory === "numeric" && / ( t i n y i n t | s m a l l i n t | n u m b e r \( 1 | i n t \( 1 ) / i. test ( dataType ?? "" ) ) {
2924- confidence += 0.15 ;
2925- evidence . push ( "Small numeric type can represent a code or flag." ) ;
2926- }
2927- if ( / ( s t a t u s | s t a t e | t y p e | c a t e g o r y | c h a n n e l | r e g i o n | c i t y | p r o v i n c e | c o u n t r y | s o u r c e | p l a t f o r m | f l a g | l e v e l | k i n d | g e n d e r ) / . test ( commentText ) ) {
2928- confidence += 0.15 ;
2929- evidence . push ( "Column comment contains dimension-related wording." ) ;
2930- }
2931- return {
2932- kind,
2933- confidence : Math . min ( 0.98 , Number ( confidence . toFixed ( 2 ) ) ) ,
2934- evidence
2935- } ;
2936- }
2937-
2938- function dimensionKindFromName ( name : string ) : string | undefined {
2939- if ( / ( ^ | _ ) ( s t a t u s | s t a t e ) ( _ | $ ) / . test ( name ) ) {
2940- return "status" ;
2941- }
2942- if ( / ( ^ | _ ) ( t y p e | c a t e g o r y | k i n d | l e v e l ) ( _ | $ ) / . test ( name ) ) {
2943- return "type" ;
2944- }
2945- if ( / ( ^ | _ ) ( c h a n n e l | s o u r c e | p l a t f o r m | s c e n e ) ( _ | $ ) / . test ( name ) ) {
2946- return "channel" ;
2947- }
2948- if ( / ( ^ | _ ) ( r e g i o n | c i t y | p r o v i n c e | c o u n t r y | a r e a ) ( _ | $ ) / . test ( name ) ) {
2949- return "region" ;
2950- }
2951- if ( / ( ^ | _ ) ( f l a g | e n a b l e d | d i s a b l e d | d e l e t e d | a c t i v e | v a l i d ) ( _ | $ ) / . test ( name ) ) {
2952- return "flag" ;
2953- }
2954- if ( / ( ^ | _ ) ( g e n d e r | g r a d e | s e g m e n t | b u c k e t | g r o u p ) ( _ | $ ) / . test ( name ) ) {
2955- return "category" ;
2956- }
2957- return undefined ;
2958- }
2959-
29602864function resolveRecentRowsTimeColumn (
29612865 rows : unknown [ ] ,
29622866 config : ObConfig ,
0 commit comments