'Fetches metadata for that datasource and merges the Superset db'

@classmethod
def sync_to_db(cls, name, cluster, merge):

    logging.info('Syncing    Druid    datasource    [{}]'.format(name))
    session = get_session()
    datasource = session.query(cls).filter_by(datasource_name=name).first()
    if (not datasource):
        datasource = cls(datasource_name=name)
        session.add(datasource)
        flasher('Adding    new    datasource    [{}]'.format(name), 'success')
    else:
        flasher('Refreshing    datasource    [{}]'.format(name), 'info')
    session.flush()
    datasource.cluster = cluster
    datasource.merge_flag = merge
    session.flush()
    cols = datasource.latest_metadata()
    if (not cols):
        logging.error('Failed    at    fetching    the    latest    segment')
        return
    for col in cols:
        if (col == '__time'):
            continue
        col_obj = session.query(DruidColumn).filter_by(datasource_name=name, column_name=col).first()
        datatype = cols[col]['type']
        if (not col_obj):
            col_obj = DruidColumn(datasource_name=name, column_name=col)
            session.add(col_obj)
        if (datatype == 'STRING'):
            col_obj.groupby = True
            col_obj.filterable = True
        if ((datatype == 'hyperUnique') or (datatype == 'thetaSketch')):
            col_obj.count_distinct = True
        if ((datatype == 'LONG') or (datatype == 'DOUBLE')):
            col_obj.sum = True
            col_obj.min = True
            col_obj.max = True
        if col_obj:
            col_obj.type = cols[col]['type']
        session.flush()
        col_obj.datasource = datasource
        col_obj.generate_metrics()
        session.flush()
