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();
}
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);
}
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());
}
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());
}
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");
}
}
Aggregations