'Returns the type of a statement.
The returned value is a string holding an upper-cased reprint of
the first DML or DDL keyword. If the first token in this group
isn\'t a DML or DDL keyword "UNKNOWN" is returned.
Whitespaces and comments at the beginning of the statement
are ignored.'

def get_type(self):

    first_token = self.token_first(skip_cm=True)
    if (first_token is None):
        return 'UNKNOWN'
    elif (first_token.ttype in (T.Keyword.DML, T.Keyword.DDL)):
        return first_token.normalized
    elif (first_token.ttype == T.Keyword.CTE):
        fidx = self.token_index(first_token)
        (tidx, token) = self.token_next(fidx, skip_ws=True)
        if isinstance(token, (Identifier, IdentifierList)):
            (_, dml_keyword) = self.token_next(tidx, skip_ws=True)
            if (dml_keyword.ttype == T.Keyword.DML):
                return dml_keyword.normalized
    return 'UNKNOWN'
