from typing import Tuple
import re


def clean_column_type(type: str) -> Tuple[str, str]:
    """
    Construct a string suitable for schema file from column type.
    :param type The column type as a string
    :return The cleaned column type string
    """
    type = type.lower()
    if type == "integer" or type == "float8" or type == "date":
        return type, ""
    if type.startswith("char"):
        # Slice off any width specifier for CHAR
        return type[: len("char")], ""
    if type.startswith("varchar"):
        # Slice off any width specifier for VARCHAR
        m = re.search("((\d+))", type)
        if m is None:
            raise RuntimeError(f"Malformed VARCHAR Type {type}")
        b, e = m.span()
        return f"{type[:len('varchar')]}", f"{type[b : e]}"
    raise RuntimeError(f"Unknown Type in DDL {type}")