use of java.util.OptionalInt in project presto by prestodb.
the class HivePageSinkProvider method createPageSink.
private ConnectorPageSink createPageSink(HiveWritableTableHandle handle, boolean isCreateTable, ConnectorSession session) {
OptionalInt bucketCount = handle.getBucketProperty().isPresent() ? OptionalInt.of(handle.getBucketProperty().get().getBucketCount()) : OptionalInt.empty();
HiveWriterFactory writerFactory = new HiveWriterFactory(fileWriterFactories, handle.getSchemaName(), handle.getTableName(), isCreateTable, handle.getInputColumns(), handle.getTableStorageFormat(), handle.getPartitionStorageFormat(), bucketCount, handle.getLocationHandle(), locationService, handle.getFilePrefix(), new HivePageSinkMetadataProvider(handle.getPageSinkMetadata(), metastore), typeManager, hdfsEnvironment, immutablePartitions, session);
return new HivePageSink(writerFactory, handle.getInputColumns(), handle.getBucketProperty(), pageIndexerFactory, typeManager, hdfsEnvironment, maxOpenPartitions, writeVerificationExecutor, partitionUpdateCodec, session);
}
use of java.util.OptionalInt in project presto by prestodb.
the class HivePageSourceProvider method createHivePageSource.
public static Optional<ConnectorPageSource> createHivePageSource(Set<HiveRecordCursorProvider> cursorProviders, Set<HivePageSourceFactory> pageSourceFactories, String clientId, Configuration configuration, ConnectorSession session, Path path, OptionalInt bucketNumber, long start, long length, Properties schema, TupleDomain<HiveColumnHandle> effectivePredicate, List<HiveColumnHandle> hiveColumns, List<HivePartitionKey> partitionKeys, DateTimeZone hiveStorageTimeZone, TypeManager typeManager, Map<Integer, HiveType> columnCoercions) {
List<ColumnMapping> columnMappings = ColumnMapping.buildColumnMappings(partitionKeys, hiveColumns, columnCoercions, path, bucketNumber);
List<ColumnMapping> regularColumnMappings = ColumnMapping.extractRegularColumnMappings(columnMappings);
for (HivePageSourceFactory pageSourceFactory : pageSourceFactories) {
Optional<? extends ConnectorPageSource> pageSource = pageSourceFactory.createPageSource(configuration, session, path, start, length, schema, extractRegularColumnHandles(regularColumnMappings, true), effectivePredicate, hiveStorageTimeZone);
if (pageSource.isPresent()) {
return Optional.of(new HivePageSource(columnMappings, hiveStorageTimeZone, typeManager, pageSource.get()));
}
}
for (HiveRecordCursorProvider provider : cursorProviders) {
// GenericHiveRecordCursor will automatically do the coercion without HiveCoercionRecordCursor
boolean doCoercion = !(provider instanceof GenericHiveRecordCursorProvider);
Optional<RecordCursor> cursor = provider.createRecordCursor(clientId, configuration, session, path, start, length, schema, extractRegularColumnHandles(regularColumnMappings, doCoercion), effectivePredicate, hiveStorageTimeZone, typeManager);
if (cursor.isPresent()) {
RecordCursor delegate = cursor.get();
// Need to wrap RcText and RcBinary into a wrapper, which will do the coercion for mismatch columns
if (doCoercion) {
delegate = new HiveCoercionRecordCursor(regularColumnMappings, typeManager, delegate);
}
HiveRecordCursor hiveRecordCursor = new HiveRecordCursor(columnMappings, hiveStorageTimeZone, typeManager, delegate);
List<Type> columnTypes = hiveColumns.stream().map(input -> typeManager.getType(input.getTypeSignature())).collect(toList());
return Optional.of(new RecordPageSource(columnTypes, hiveRecordCursor));
}
}
return Optional.empty();
}
use of java.util.OptionalInt in project presto by prestodb.
the class ShardIterator method compute.
/**
* Compute split-per-shard (separate split for each shard).
*/
private BucketShards compute() throws SQLException {
if (!resultSet.next()) {
return endOfData();
}
UUID shardUuid = uuidFromBytes(resultSet.getBytes("shard_uuid"));
Set<String> nodeIdentifiers;
OptionalInt bucketNumber = OptionalInt.empty();
if (bucketToNode != null) {
int bucket = resultSet.getInt("bucket_number");
bucketNumber = OptionalInt.of(bucket);
nodeIdentifiers = ImmutableSet.of(getBucketNode(bucket));
} else {
List<Integer> nodeIds = intArrayFromBytes(resultSet.getBytes("node_ids"));
nodeIdentifiers = getNodeIdentifiers(nodeIds, shardUuid);
}
ShardNodes shard = new ShardNodes(shardUuid, nodeIdentifiers);
return new BucketShards(bucketNumber, ImmutableSet.of(shard));
}
use of java.util.OptionalInt 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.OptionalInt in project android by JetBrains.
the class StringResourceTable method setModel.
@Override
public void setModel(@NotNull TableModel model) {
super.setModel(model);
OptionalInt optionalWidth = getKeyColumnPreferredWidth();
if (optionalWidth.isPresent()) {
columnModel.getColumn(KEY_COLUMN).setPreferredWidth(optionalWidth.getAsInt());
}
if (tableHeader == null) {
return;
}
setLocaleColumnHeaderRenderers();
optionalWidth = getDefaultValueAndLocaleColumnPreferredWidths();
if (optionalWidth.isPresent()) {
int width = optionalWidth.getAsInt();
IntStream.range(DEFAULT_VALUE_COLUMN, getColumnCount()).mapToObj(columnModel::getColumn).forEach(column -> column.setPreferredWidth(width));
}
}
Aggregations