Search in sources :

Example 16 with OptionalLong

use of java.util.OptionalLong in project presto by prestodb.

the class TableMetadataSystemTable method buildPages.

private static List<Page> buildPages(MetadataDao dao, ConnectorTableMetadata tableMetadata, TupleDomain<Integer> tupleDomain) {
    Map<Integer, NullableValue> domainValues = extractFixedValues(tupleDomain).orElse(ImmutableMap.of());
    String schemaName = getStringValue(domainValues.get(getColumnIndex(tableMetadata, SCHEMA_NAME)));
    String tableName = getStringValue(domainValues.get(getColumnIndex(tableMetadata, TABLE_NAME)));
    PageListBuilder pageBuilder = new PageListBuilder(tableMetadata.getColumns().stream().map(ColumnMetadata::getType).collect(toList()));
    List<TableMetadataRow> tableRows = dao.getTableMetadataRows(schemaName, tableName);
    PeekingIterator<ColumnMetadataRow> columnRowIterator = peekingIterator(dao.getColumnMetadataRows(schemaName, tableName).iterator());
    for (TableMetadataRow tableRow : tableRows) {
        while (columnRowIterator.hasNext() && columnRowIterator.peek().getTableId() < tableRow.getTableId()) {
            columnRowIterator.next();
        }
        String temporalColumnName = null;
        SortedMap<Integer, String> sortColumnNames = new TreeMap<>();
        SortedMap<Integer, String> bucketColumnNames = new TreeMap<>();
        OptionalLong temporalColumnId = tableRow.getTemporalColumnId();
        while (columnRowIterator.hasNext() && columnRowIterator.peek().getTableId() == tableRow.getTableId()) {
            ColumnMetadataRow columnRow = columnRowIterator.next();
            if (temporalColumnId.isPresent() && columnRow.getColumnId() == temporalColumnId.getAsLong()) {
                temporalColumnName = columnRow.getColumnName();
            }
            OptionalInt sortOrdinalPosition = columnRow.getSortOrdinalPosition();
            if (sortOrdinalPosition.isPresent()) {
                sortColumnNames.put(sortOrdinalPosition.getAsInt(), columnRow.getColumnName());
            }
            OptionalInt bucketOrdinalPosition = columnRow.getBucketOrdinalPosition();
            if (bucketOrdinalPosition.isPresent()) {
                bucketColumnNames.put(bucketOrdinalPosition.getAsInt(), columnRow.getColumnName());
            }
        }
        pageBuilder.beginRow();
        // schema_name, table_name
        VARCHAR.writeSlice(pageBuilder.nextBlockBuilder(), utf8Slice(tableRow.getSchemaName()));
        VARCHAR.writeSlice(pageBuilder.nextBlockBuilder(), utf8Slice(tableRow.getTableName()));
        // temporal_column
        if (temporalColumnId.isPresent()) {
            if (temporalColumnName == null) {
                throw new PrestoException(RAPTOR_CORRUPT_METADATA, format("Table ID %s has corrupt metadata (invalid temporal column ID)", tableRow.getTableId()));
            }
            VARCHAR.writeSlice(pageBuilder.nextBlockBuilder(), utf8Slice(temporalColumnName));
        } else {
            pageBuilder.nextBlockBuilder().appendNull();
        }
        // ordering_columns
        writeArray(pageBuilder.nextBlockBuilder(), sortColumnNames.values());
        // distribution_name
        Optional<String> distributionName = tableRow.getDistributionName();
        if (distributionName.isPresent()) {
            VARCHAR.writeSlice(pageBuilder.nextBlockBuilder(), utf8Slice(distributionName.get()));
        } else {
            pageBuilder.nextBlockBuilder().appendNull();
        }
        // bucket_count
        OptionalInt bucketCount = tableRow.getBucketCount();
        if (bucketCount.isPresent()) {
            BIGINT.writeLong(pageBuilder.nextBlockBuilder(), bucketCount.getAsInt());
        } else {
            pageBuilder.nextBlockBuilder().appendNull();
        }
        // bucketing_columns
        writeArray(pageBuilder.nextBlockBuilder(), bucketColumnNames.values());
        // organized
        BOOLEAN.writeBoolean(pageBuilder.nextBlockBuilder(), tableRow.isOrganized());
    }
    return pageBuilder.build();
}
Also used : ColumnMetadata(com.facebook.presto.spi.ColumnMetadata) NullableValue(com.facebook.presto.spi.predicate.NullableValue) PrestoException(com.facebook.presto.spi.PrestoException) ColumnMetadataRow(com.facebook.presto.raptor.metadata.ColumnMetadataRow) OptionalInt(java.util.OptionalInt) TreeMap(java.util.TreeMap) OptionalLong(java.util.OptionalLong) TableMetadataRow(com.facebook.presto.raptor.metadata.TableMetadataRow)

Example 17 with OptionalLong

use of java.util.OptionalLong in project spring-framework by spring-projects.

the class ResourceRegionHttpMessageWriter method writeSingleResourceRegionHeaders.

private void writeSingleResourceRegionHeaders(ResourceRegion region, MediaType contentType, ReactiveHttpOutputMessage outputMessage) {
    OptionalLong resourceLength = contentLength(region.getResource());
    resourceLength.ifPresent(length -> {
        long start = region.getPosition();
        long end = start + region.getCount() - 1;
        end = Math.min(end, length - 1);
        outputMessage.getHeaders().add("Content-Range", "bytes " + start + '-' + end + '/' + length);
        outputMessage.getHeaders().setContentLength(end - start + 1);
    });
    outputMessage.getHeaders().setContentType(contentType);
}
Also used : OptionalLong(java.util.OptionalLong)

Example 18 with OptionalLong

use of java.util.OptionalLong in project fastjson by alibaba.

the class OptionalTest method test_optionalLong.

public void test_optionalLong() throws Exception {
    OptionalLong val = OptionalLong.of(3);
    String text = JSON.toJSONString(val);
    Assert.assertEquals("3", text);
    OptionalLong val2 = JSON.parseObject(text, OptionalLong.class);
    Assert.assertEquals(val.getAsLong(), val2.getAsLong());
}
Also used : OptionalLong(java.util.OptionalLong)

Example 19 with OptionalLong

use of java.util.OptionalLong in project spring-framework by spring-projects.

the class HeadersWrapperTests method contentLength.

@Test
public void contentLength() throws Exception {
    OptionalLong contentLength = OptionalLong.of(42L);
    when(mockHeaders.contentLength()).thenReturn(contentLength);
    assertSame(contentLength, wrapper.contentLength());
}
Also used : OptionalLong(java.util.OptionalLong) Test(org.junit.Test)

Example 20 with OptionalLong

use of java.util.OptionalLong in project spring-framework by spring-projects.

the class ResourceRegionEncoder method getContentRangeHeader.

private byte[] getContentRangeHeader(ResourceRegion region) {
    long start = region.getPosition();
    long end = start + region.getCount() - 1;
    OptionalLong contentLength = contentLength(region.getResource());
    if (contentLength.isPresent()) {
        return getAsciiBytes("Content-Range: bytes " + start + '-' + end + '/' + contentLength.getAsLong() + "\r\n\r\n");
    } else {
        return getAsciiBytes("Content-Range: bytes " + start + '-' + end + "\r\n\r\n");
    }
}
Also used : OptionalLong(java.util.OptionalLong)

Aggregations

OptionalLong (java.util.OptionalLong)23 Test (org.testng.annotations.Test)7 OptionalInt (java.util.OptionalInt)5 MetadataDao (com.facebook.presto.raptor.metadata.MetadataDao)3 Type (com.facebook.presto.spi.type.Type)3 List (java.util.List)3 ColumnInfo (com.facebook.presto.raptor.metadata.ColumnInfo)2 ShardManager (com.facebook.presto.raptor.metadata.ShardManager)2 Table (com.facebook.presto.raptor.metadata.Table)2 TableColumn (com.facebook.presto.raptor.metadata.TableColumn)2 ColumnMetadata (com.facebook.presto.spi.ColumnMetadata)2 PrestoException (com.facebook.presto.spi.PrestoException)2 Objects.requireNonNull (java.util.Objects.requireNonNull)2 TreeMap (java.util.TreeMap)2 UUID (java.util.UUID)2 Inject (javax.inject.Inject)2 JSONException (com.alibaba.fastjson.JSONException)1 ErrorCode (com.eightkdata.mongowp.ErrorCode)1 Status (com.eightkdata.mongowp.Status)1 BsonDocument (com.eightkdata.mongowp.bson.BsonDocument)1