Repository: pingcap/tidb
File: pkg/executor/importer/import.go (Go)

Code before:
				totalSize += size
				return nil
			}); err != nil {
			return exeerrors.ErrLoadDataCantRead.GenWithStackByArgs(GetMsgFromBRError(err), "failed to walk dir")
		}

		var err error
		if dataFiles, err = mydump.ParallelProcess(ctx, allFiles, e.ThreadCnt*2,
			func(ctx context.Context, f mydump.RawFile) (*mydump.SourceFileMeta, error) {
				path, size := f.Path, f.Size
				compressTp := mydump.ParseCompressionOnFileExtension(path)
				fileMeta := mydump.SourceFileMeta{
					Path:        path,
					FileSize:    size,
					Compression: compressTp,
					Type:        sourceType,
				}
				fileMeta.RealSize = mydump.EstimateRealSizeForFile(ctx, fileMeta, s)
				return &fileMeta, nil
			}); err != nil {
			return err
		}
	}
	if err2 = e.checkNonCSVFormatOptions(isDataFormatAuto); err2 != nil {
		return err2
	}

	e.dataFiles = dataFiles
	e.TotalFileSize = totalSize
	return nil
}

// update format of the validated file by its extension.
func (e *LoadDataController) detectAndUpdateFormat(path string) {
	if e.Format == DataFormatAuto {
		e.Format = parseFileType(path)
		e.logger.Info("detect and update import plan format based on file extension", zap.String("file", path), zap.String("detected format", e.Format))
		e.Parameters.Format = e.Format
	}
}

func parseFileType(path string) string {
	path = strings.ToLower(path)
	ext := filepath.Ext(path)
	// avoid duplicate compress extension
	for ext == ".gz" || ext == ".gzip" || ext == ".zstd" || ext == ".zst" || ext == ".snappy" {
		path = strings.TrimSuffix(path, ext)
		ext = filepath.Ext(path)
	}
	switch ext {
	case ".sql":

Review comment (suggestion):
```suggestion
	if isDataFormatAuto && e.Format != DataFormatCSV {
		if err2 = e.checkNonCSVFormatOptions(); err2 != nil {
			return err2
		}
	}
```

Code after:
				totalSize += size
				return nil
			}); err != nil {
			return exeerrors.ErrLoadDataCantRead.GenWithStackByArgs(GetMsgFromBRError(err), "failed to walk dir")
		}

		var err error
		if dataFiles, err = mydump.ParallelProcess(ctx, allFiles, e.ThreadCnt*2,
			func(ctx context.Context, f mydump.RawFile) (*mydump.SourceFileMeta, error) {
				path, size := f.Path, f.Size
				compressTp := mydump.ParseCompressionOnFileExtension(path)
				fileMeta := mydump.SourceFileMeta{
					Path:        path,
					FileSize:    size,
					Compression: compressTp,
					Type:        sourceType,
				}
				fileMeta.RealSize = mydump.EstimateRealSizeForFile(ctx, fileMeta, s)
				return &fileMeta, nil
			}); err != nil {
			return err
		}
	}
	if e.InImportInto && isAutoDetectingFormat && e.Format != DataFormatCSV {
		if err2 = e.checkNonCSVFormatOptions(); err2 != nil {
			return err2
		}
	}

	e.dataFiles = dataFiles
	e.TotalFileSize = totalSize
	return nil
}

// update format of the validated file by its extension.
func (e *LoadDataController) detectAndUpdateFormat(path string) {
	if e.Format == DataFormatAuto {
		e.Format = parseFileType(path)
		e.logger.Info("detect and update import plan format based on file extension",
			zap.String("file", path), zap.String("detected format", e.Format))
		e.Parameters.Format = e.Format
	}
}

func parseFileType(path string) string {
	path = strings.ToLower(path)
	ext := filepath.Ext(path)
	// avoid duplicate compress extension
	if ext == ".gz" || ext == ".gzip" || ext == ".zstd" || ext == ".zst" || ext == ".snappy" {
		path = strings.TrimSuffix(path, ext)
		ext = filepath.Ext(path)