Search in sources :

Example 31 with Bind

use of org.skife.jdbi.v2.sqlobject.Bind in project hive by apache.

the class DruidStorageHandlerUtils method getDataSegmentList.

/**
 * @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
 */
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);
}
Also used : SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) Folder3(org.skife.jdbi.v2.Folder3) DataSegment(org.apache.druid.timeline.DataSegment) SQLException(java.sql.SQLException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) ExecutionException(java.util.concurrent.ExecutionException) HiveException(org.apache.hadoop.hive.ql.metadata.HiveException) MalformedURLException(java.net.MalformedURLException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) CallbackFailedException(org.skife.jdbi.v2.exceptions.CallbackFailedException)

Aggregations

Handle (org.skife.jdbi.v2.Handle)23 IOException (java.io.IOException)12 SQLException (java.sql.SQLException)7 ArrayList (java.util.ArrayList)7 Map (java.util.Map)7 List (java.util.List)6 DataSegment (org.apache.druid.timeline.DataSegment)5 CallbackFailedException (org.skife.jdbi.v2.exceptions.CallbackFailedException)5 Test (org.junit.Test)4 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)3 ImmutableList (com.google.common.collect.ImmutableList)3 ResultSet (java.sql.ResultSet)3 Interval (org.joda.time.Interval)3 DBI (org.skife.jdbi.v2.DBI)3 IDBI (org.skife.jdbi.v2.IDBI)3 Query (org.skife.jdbi.v2.Query)3 StatementContext (org.skife.jdbi.v2.StatementContext)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 AbstractModule (com.google.inject.AbstractModule)2