static List<DataSegment> getDataSegmentList(final SQLMetadataConnector connector,
      final MetadataStorageTablesConfig metadataStorageTablesConfig,
      final String dataSource) {
    return connector.retryTransaction((handle, status) -> handle.createQuery(String.format(
        "SELECT payload FROM %s WHERE dataSource = :dataSource",
        metadataStorageTablesConfig.getSegmentsTable()))
        .setFetchSize(getStreamingFetchSize(connector))
        .bind("dataSource", dataSource)
        .map(ByteArrayMapper.FIRST)
        .fold(new ArrayList<>(), (Folder3<List<DataSegment>, byte[]>) (accumulator, payload, control, ctx) -> {
          try {
            final DataSegment segment = DATA_SEGMENT_INTERNER.intern(JSON_MAPPER.readValue(payload, DataSegment.class));

            accumulator.add(segment);
            return accumulator;
          } catch (Exception e) {
            throw new SQLException(e.toString());
          }
        }), 3, DEFAULT_MAX_TRIES);
  }
@param connector                   SQL connector to metadata
@param metadataStorageTablesConfig Tables configuration
@param dataSource                  Name of data source
@return List of all data segments part of the given data source
druid-handler/src/java/org/apache/hadoop/hive/druid/DruidStorageHandlerUtils.java