from pathlib import Path


def table_path_split(path):
    """ Splits a table path into a (root, table, subtable) tuple """
    if not isinstance(path, Path):
        path = Path(path)

    root = path.parent
    parts = path.name.split("::", 1)

    if len(parts) == 1:
        table_name = parts[0]
        subtable = ""
    elif len(parts) == 2:
        table_name, subtable = parts
    else:
        raise RuntimeError("len(parts) not in (1, 2)")

    return root, table_name, subtable