| 121 | |
| 122 | // Start analysis |
| 123 | const loadStats = async () => { |
| 124 | loadingRef.current = true; |
| 125 | setIsLoading(true); |
| 126 | setError(null); |
| 127 | |
| 128 | try { |
| 129 | console.log('[useColumnStats] Starting analysis for:', file.fileName, `(${fileSizeMB.toFixed(2)}MB)`); |
| 130 | |
| 131 | const tableName = file.tableName; |
| 132 | if (!tableName) { |
| 133 | throw new Error('Table name not found for file'); |
| 134 | } |
| 135 | |
| 136 | await analyzeFile(currentFileId, tableName); |
| 137 | |
| 138 | console.log('[useColumnStats] Analysis completed successfully'); |
| 139 | } catch (err) { |
| 140 | console.error('[useColumnStats] Analysis failed:', err); |
| 141 | setError(err instanceof Error ? err.message : 'Failed to load column statistics'); |
| 142 | } finally { |
| 143 | loadingRef.current = false; |
| 144 | setIsLoading(false); |
| 145 | } |
| 146 | }; |
| 147 | |
| 148 | // Add a small delay to avoid immediate analysis on mount |
| 149 | const timeoutId = setTimeout(() => { |