def size(
        self,
        dataset_rows: "DataTable",
        node: Union[Node, dict[str, Any]],
        count_files: bool = False,
    ) -> tuple[int, int]:
        """
        Calculates size of some node (and subtree below node).
        Returns size in bytes as int and total files as int
        """
        if isinstance(node, dict):
            is_dir = node.get("is_dir", node["dir_type"] in DirTypeGroup.SUBOBJ_DIR)
            node_size = node["size"]
            path = node["path"]
        else:
            is_dir = node.is_container
            node_size = node.size
            path = node.path
        if not is_dir:
            # Return node size if this is not a directory
            return node_size, 1

        sub_glob = posixpath.join(path, "*")
        dr = dataset_rows
        selections: list[sa.ColumnElement] = [
            sa.func.sum(dr.c("size")),
        ]
        if count_files:
            selections.append(sa.func.count())
        results = next(
            self.db.execute(
                dr.select(*selections).where(
                    (dr.c("path").op("GLOB")(sub_glob)) & (dr.c("is_latest") == true())
                )
            ),
            (0, 0),
        )
        if count_files:
            return results[0] or 0, results[1] or 0
        return results[0] or 0, 0

        Calculates size of some node (and subtree below node).
        Returns size in bytes as int and total files as int
        
src/datachain/data_storage/warehouse.py