def dataset_stats(
        self, dataset: DatasetRecord, version: str
    ) -> tuple[Optional[int], Optional[int]]:
        """
        Returns tuple with dataset stats: total number of rows and total dataset size.
        """
        if not (self.db.has_table(self.dataset_table_name(dataset.name, version))):
            return None, None

        file_signals = list(
            SignalSchema.deserialize(dataset.feature_schema).get_signals(File)
        )

        dr = self.dataset_rows(dataset, version)
        table = dr.get_table()
        expressions: tuple[_ColumnsClauseArgument[Any], ...] = (
            sa.func.count(table.c.sys__id),
        )
        size_column_names = [s.replace(".", "__") + "__size" for s in file_signals]
        size_columns = [c for c in table.columns if c.name in size_column_names]

        if size_columns:
            expressions = (*expressions, sa.func.sum(sum(size_columns)))
        query = sa.select(*expressions)
        ((nrows, *rest),) = self.db.execute(query)
        return nrows, rest[0] if rest else 0

        Returns tuple with dataset stats: total number of rows and total dataset size.
        
src/datachain/data_storage/warehouse.py