use of io.trino.spi.predicate.NullableValue in project trino by trinodb.
the class TestInformationSchemaMetadata method testConstraint.
/**
* @see #testConstraintColumns()
*/
private static boolean testConstraint(Map<ColumnHandle, NullableValue> bindings) {
// test_schema has a table named "another_table" and we filter that out in this predicate
// Note: the columns inspected here must be in sync with testConstraintColumns()
NullableValue catalog = bindings.get(new InformationSchemaColumnHandle("table_catalog"));
NullableValue schema = bindings.get(new InformationSchemaColumnHandle("table_schema"));
NullableValue table = bindings.get(new InformationSchemaColumnHandle("table_name"));
boolean isValid = true;
if (catalog != null) {
isValid = ((Slice) catalog.getValue()).toStringUtf8().equals("test_catalog");
}
if (schema != null) {
isValid &= ((Slice) schema.getValue()).toStringUtf8().equals("test_schema");
}
if (table != null) {
isValid &= ((Slice) table.getValue()).toStringUtf8().equals("test_view");
}
return isValid;
}
use of io.trino.spi.predicate.NullableValue in project trino by trinodb.
the class TestPartitionedOutputOperator method testOutputForSimplePageWithPartitionConstantAndHashBlock.
@Test
public void testOutputForSimplePageWithPartitionConstantAndHashBlock() {
PartitionedOutputOperator partitionedOutputOperator = partitionedOutputOperator(BIGINT).withPartitionConstants(ImmutableList.of(Optional.empty(), Optional.of(new NullableValue(BIGINT, 1L)))).withPartitionChannels(0, // use first block and constant block at index 1 as input to partitionFunction
-1).withHashChannels(0, // use both channels to calculate partition (a+b) mod 2
1).build();
Page page = new Page(createLongsBlock(0L, 1L, 2L, 3L));
processPages(partitionedOutputOperator, page);
List<Object> partition0 = readLongs(outputBuffer.getEnqueuedDeserialized(0), 0);
assertThat(partition0).containsExactly(1L, 3L);
List<Object> partition1 = readLongs(outputBuffer.getEnqueuedDeserialized(1), 0);
assertThat(partition1).containsExactly(0L, 2L);
}
use of io.trino.spi.predicate.NullableValue in project trino by trinodb.
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 TrinoException(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 io.trino.spi.predicate.NullableValue in project trino by trinodb.
the class IcebergMetadata method getTableProperties.
@Override
public ConnectorTableProperties getTableProperties(ConnectorSession session, ConnectorTableHandle tableHandle) {
IcebergTableHandle table = (IcebergTableHandle) tableHandle;
if (table.getSnapshotId().isEmpty()) {
// TupleDomain.none() as the predicate
return new ConnectorTableProperties(TupleDomain.none(), Optional.empty(), Optional.empty(), Optional.empty(), ImmutableList.of());
}
Table icebergTable = catalog.loadTable(session, table.getSchemaTableName());
// Extract identity partition fields that are present in all partition specs, for creating the discrete predicates.
Set<Integer> partitionSourceIds = identityPartitionColumnsInAllSpecs(icebergTable);
TupleDomain<IcebergColumnHandle> enforcedPredicate = table.getEnforcedPredicate();
DiscretePredicates discretePredicates = null;
if (!partitionSourceIds.isEmpty()) {
// Extract identity partition columns
Map<Integer, IcebergColumnHandle> columns = getColumns(icebergTable.schema(), typeManager).stream().filter(column -> partitionSourceIds.contains(column.getId())).collect(toImmutableMap(IcebergColumnHandle::getId, Function.identity()));
Supplier<List<FileScanTask>> lazyFiles = Suppliers.memoize(() -> {
TableScan tableScan = icebergTable.newScan().useSnapshot(table.getSnapshotId().get()).filter(toIcebergExpression(enforcedPredicate)).includeColumnStats();
try (CloseableIterable<FileScanTask> iterator = tableScan.planFiles()) {
return ImmutableList.copyOf(iterator);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
});
Iterable<FileScanTask> files = () -> lazyFiles.get().iterator();
Iterable<TupleDomain<ColumnHandle>> discreteTupleDomain = Iterables.transform(files, fileScan -> {
// Extract partition values in the data file
Map<Integer, Optional<String>> partitionColumnValueStrings = getPartitionKeys(fileScan);
Map<ColumnHandle, NullableValue> partitionValues = partitionSourceIds.stream().filter(partitionColumnValueStrings::containsKey).collect(toImmutableMap(columns::get, columnId -> {
IcebergColumnHandle column = columns.get(columnId);
Object prestoValue = deserializePartitionValue(column.getType(), partitionColumnValueStrings.get(columnId).orElse(null), column.getName());
return NullableValue.of(column.getType(), prestoValue);
}));
return TupleDomain.fromFixedValues(partitionValues);
});
discretePredicates = new DiscretePredicates(columns.values().stream().map(ColumnHandle.class::cast).collect(toImmutableList()), discreteTupleDomain);
}
return new ConnectorTableProperties(// over all tableScan.planFiles() and caching partition values in table handle.
enforcedPredicate.transformKeys(ColumnHandle.class::cast), // TODO: implement table partitioning
Optional.empty(), Optional.empty(), Optional.ofNullable(discretePredicates), ImmutableList.of());
}
use of io.trino.spi.predicate.NullableValue in project trino by trinodb.
the class AbstractTestHive method testBucketedTableDoubleFloat.
@Test
public void testBucketedTableDoubleFloat() throws Exception {
try (Transaction transaction = newTransaction()) {
ConnectorMetadata metadata = transaction.getMetadata();
ConnectorSession session = newSession();
metadata.beginQuery(session);
ConnectorTableHandle tableHandle = getTableHandle(metadata, tableBucketedDoubleFloat);
List<ColumnHandle> columnHandles = ImmutableList.copyOf(metadata.getColumnHandles(session, tableHandle).values());
Map<String, Integer> columnIndex = indexColumns(columnHandles);
assertTableIsBucketed(tableHandle, transaction, session);
ImmutableMap<ColumnHandle, NullableValue> bindings = ImmutableMap.<ColumnHandle, NullableValue>builder().put(columnHandles.get(columnIndex.get("t_float")), NullableValue.of(REAL, (long) floatToRawIntBits(87.1f))).put(columnHandles.get(columnIndex.get("t_double")), NullableValue.of(DOUBLE, 88.2)).buildOrThrow();
// floats and doubles are not supported, so we should see all splits
MaterializedResult result = readTable(transaction, tableHandle, columnHandles, session, TupleDomain.fromFixedValues(bindings), OptionalInt.of(32), Optional.empty());
assertEquals(result.getRowCount(), 100);
}
}
Aggregations