def create_hive_table_from_hbase_table(hive_connection, table_hive, table_hbase, key, columns, id_task=None):
    """
    Creates a hive table linked to an hbase table
    :param hive_connection: The connection to hive
    :param table_hive: the hive table to be created
    :param table_hbase: the hbase table with the data
    :param key: a list of tuples (hbase_key_name, type) of the hbase key
    :param columns: a list of tuples (hive_column_name, type, "<hbase_column_family>:<hbase_column_name>") of the hbase columns
    :param id_task: The id of the task to generate unique tables
    :return: the name of the hive table
    """
    if id_task:
        table_hive = table_hive + '_' + id_task
    sentence = "CREATE EXTERNAL TABLE IF NOT EXISTS \
             {table_hive}( key struct<{hive_key}>, {hive_columns} ) \
             ROW FORMAT DELIMITED \
             COLLECTION ITEMS TERMINATED BY '~' \
             STORED BY \
             'org.apache.hadoop.hive.hbase.HBaseStorageHandler' \
              WITH SERDEPROPERTIES \
              ('hbase.columns.mapping' = ':key, {hbase_columns}') \
              TBLPROPERTIES \
              ('hbase.table.name' = '{table_hbase}')"
    sentence = sentence.format(table_hive=table_hive,
                    hive_key=",".join(["{}:{}".format(k[0],k[1]) for k in key]),
                    hive_columns=",".join(["{} {}".format(c[0],c[1]) for c in columns]),
                    hbase_columns=",".join([c[2] for c in columns]),
                    table_hbase=table_hbase)

    try:
        hive_connection.execute(sentence)
    except Exception as e:
        raise Exception('Failed to create HIVE table {}: {}'.format(table_hive, e))
    return table_hive