use of com.facebook.presto.common.type.BooleanType.BOOLEAN in project presto by prestodb.
the class TupleDomainFilterUtils method toFilter.
public static TupleDomainFilter toFilter(Domain domain) {
ValueSet values = domain.getValues();
boolean nullAllowed = domain.isNullAllowed();
if (values.isAll()) {
checkArgument(!nullAllowed, "Unexpected allways-true filter");
return IS_NOT_NULL;
}
if (values.isNone()) {
checkArgument(nullAllowed, "Unexpected allways-false filter");
return IS_NULL;
}
checkArgument(values instanceof SortedRangeSet, "Unexpected domain type: " + values.getClass().getSimpleName());
List<Range> ranges = ((SortedRangeSet) values).getOrderedRanges();
if (ranges.isEmpty() && nullAllowed) {
return IS_NULL;
}
Type type = domain.getType();
if (ranges.size() == 1) {
return createRangeFilter(type, ranges.get(0), nullAllowed);
}
if (type == BOOLEAN) {
return createBooleanFilter(ranges, nullAllowed);
}
List<TupleDomainFilter> rangeFilters = ranges.stream().map(range -> createRangeFilter(type, range, false)).filter(rangeFilter -> !rangeFilter.equals(ALWAYS_FALSE)).collect(toList());
if (rangeFilters.isEmpty()) {
return nullAllowed ? IS_NULL : ALWAYS_FALSE;
}
TupleDomainFilter firstRangeFilter = rangeFilters.get(0);
if (firstRangeFilter instanceof BigintRange) {
List<BigintRange> bigintRanges = rangeFilters.stream().map(BigintRange.class::cast).collect(toList());
if (bigintRanges.stream().allMatch(BigintRange::isSingleValue)) {
return toBigintValues(bigintRanges.stream().mapToLong(BigintRange::getLower).toArray(), nullAllowed);
}
return BigintMultiRange.of(bigintRanges, nullAllowed);
}
if (firstRangeFilter instanceof BytesRange) {
List<BytesRange> bytesRanges = rangeFilters.stream().map(BytesRange.class::cast).collect(toList());
if (bytesRanges.stream().allMatch(BytesRange::isSingleValue)) {
return BytesValues.of(bytesRanges.stream().map(BytesRange::getLower).toArray(byte[][]::new), nullAllowed);
}
if (isNotIn(ranges)) {
return BytesValuesExclusive.of(bytesRanges.stream().map(BytesRange::getLower).filter(Objects::nonNull).toArray(byte[][]::new), nullAllowed);
}
}
if (firstRangeFilter instanceof DoubleRange || firstRangeFilter instanceof FloatRange) {
// != and NOT IN filters should return true when applied to NaN
// E.g. NaN != 1.0 as well as NaN NOT IN (1.0, 2.5, 3.6) should return true; otherwise false.
boolean nanAllowed = isNotIn(ranges);
return MultiRange.of(rangeFilters, nullAllowed, nanAllowed);
}
return MultiRange.of(rangeFilters, nullAllowed, false);
}
use of com.facebook.presto.common.type.BooleanType.BOOLEAN in project presto by prestodb.
the class TestPageProcessor method testPartialFilterAsList.
private void testPartialFilterAsList(Type type, int positionCount, float primitiveNullRate, float nestedNullRate, boolean useBlockView, List<BlockAssertions.Encoding> wrappings) {
int[] positions = IntStream.range(0, positionCount / 2).map(x -> x * 2).toArray();
PageProcessor pageProcessor = new PageProcessor(Optional.of(new TestingPageFilter(positionsList(positions, 0, positionCount / 2))), ImmutableList.of(createInputPageProjectionWithOutputs(0, BIGINT, 0)), OptionalInt.of(MAX_BATCH_SIZE));
Page inputPage = createPageWithRandomData(ImmutableList.of(type), positionCount, false, false, primitiveNullRate, nestedNullRate, useBlockView, wrappings);
Iterator<Optional<Page>> output = processAndAssertRetainedPageSize(pageProcessor, inputPage);
List<Optional<Page>> outputPages = ImmutableList.copyOf(output);
assertEquals(outputPages.size(), 1);
assertPageEquals(ImmutableList.of(type), outputPages.get(0).orElse(null), new Page(inputPage.getBlock(0).copyPositions(positions, 0, positionCount / 2)));
}
use of com.facebook.presto.common.type.BooleanType.BOOLEAN in project presto by prestodb.
the class TestBlockEncodingBuffers method buildMapBlockStatus.
private BlockStatus buildMapBlockStatus(MapType mapType, int positionCount, boolean isView, Optional<boolean[]> isNull, int[] offsets, float primitiveNullRate, float nestedNullRate, List<Encoding> wrappings) {
BlockStatus blockStatus;
BlockStatus keyBlockStatus = buildBlockStatusWithType(mapType.getKeyType(), offsets[positionCount], isView, 0.0f, 0.0f, wrappings);
BlockStatus valueBlockStatus = buildBlockStatusWithType(mapType.getValueType(), offsets[positionCount], isView, primitiveNullRate, nestedNullRate, wrappings);
int[] expectedKeySizes = keyBlockStatus.expectedRowSizes;
int[] expectedValueSizes = valueBlockStatus.expectedRowSizes;
// Use expectedKeySizes for the total size for both key and values
Arrays.setAll(expectedKeySizes, i -> expectedKeySizes[i] + expectedValueSizes[i]);
int[] expectedRowSizes = IntStream.range(0, positionCount).map(i -> MapBlockEncodingBuffer.POSITION_SIZE + Arrays.stream(expectedKeySizes, offsets[i], offsets[i + 1]).sum()).toArray();
Type keyType = mapType.getKeyType();
blockStatus = new BlockStatus(fromKeyValueBlock(positionCount, isNull, offsets, keyBlockStatus.block, valueBlockStatus.block), expectedRowSizes);
return blockStatus;
}
use of com.facebook.presto.common.type.BooleanType.BOOLEAN in project presto by prestodb.
the class HiveMetadata method beginInsertInternal.
private HiveInsertTableHandle beginInsertInternal(ConnectorSession session, ConnectorTableHandle tableHandle) {
verifyJvmTimeZone();
MetastoreContext metastoreContext = getMetastoreContext(session);
SchemaTableName tableName = ((HiveTableHandle) tableHandle).getSchemaTableName();
Table table = metastore.getTable(metastoreContext, tableName.getSchemaName(), tableName.getTableName()).orElseThrow(() -> new TableNotFoundException(tableName));
checkTableIsWritable(table, writesToNonManagedTablesEnabled);
for (Column column : table.getDataColumns()) {
if (!isWritableType(column.getType())) {
throw new PrestoException(NOT_SUPPORTED, format("Inserting into Hive table %s with column type %s not supported", tableName, column.getType()));
}
}
List<HiveColumnHandle> handles = hiveColumnHandles(table).stream().filter(columnHandle -> !columnHandle.isHidden()).collect(toList());
HiveStorageFormat tableStorageFormat = extractHiveStorageFormat(table);
LocationHandle locationHandle;
boolean isTemporaryTable = table.getTableType().equals(TEMPORARY_TABLE);
boolean tempPathRequired = isTempPathRequired(session, table.getStorage().getBucketProperty(), decodePreferredOrderingColumnsFromStorage(table.getStorage()));
if (isTemporaryTable) {
locationHandle = locationService.forTemporaryTable(metastore, session, table, tempPathRequired);
} else {
locationHandle = locationService.forExistingTable(metastore, session, table, tempPathRequired);
}
Optional<? extends TableEncryptionProperties> tableEncryptionProperties = getTableEncryptionPropertiesFromHiveProperties(table.getParameters(), tableStorageFormat);
HiveStorageFormat partitionStorageFormat = isRespectTableFormat(session) ? tableStorageFormat : getHiveStorageFormat(session);
HiveStorageFormat actualStorageFormat = table.getPartitionColumns().isEmpty() ? tableStorageFormat : partitionStorageFormat;
if (tableEncryptionProperties.isPresent() && actualStorageFormat != tableStorageFormat) {
throw new PrestoException(INVALID_TABLE_PROPERTY, format("For encrypted tables, partition format (%s) should match table format (%s). Using the session property %s or appropriately setting %s can help with ensuring this", actualStorageFormat.name(), tableStorageFormat.name(), RESPECT_TABLE_FORMAT, HIVE_STORAGE_FORMAT));
}
HiveInsertTableHandle result = new HiveInsertTableHandle(tableName.getSchemaName(), tableName.getTableName(), handles, metastore.generatePageSinkMetadata(metastoreContext, tableName), locationHandle, table.getStorage().getBucketProperty(), decodePreferredOrderingColumnsFromStorage(table.getStorage()), tableStorageFormat, partitionStorageFormat, actualStorageFormat, getHiveCompressionCodec(session, isTemporaryTable, actualStorageFormat), encryptionInformationProvider.getWriteEncryptionInformation(session, tableEncryptionProperties.map(identity()), tableName.getSchemaName(), tableName.getTableName()));
WriteInfo writeInfo = locationService.getQueryWriteInfo(locationHandle);
metastore.declareIntentionToWrite(new HdfsContext(session, tableName.getSchemaName(), tableName.getTableName(), table.getStorage().getLocation(), false), metastoreContext, writeInfo.getWriteMode(), writeInfo.getWritePath(), writeInfo.getTempPath(), tableName, isTemporaryTable);
return result;
}
use of com.facebook.presto.common.type.BooleanType.BOOLEAN in project presto by prestodb.
the class TestHistogram method testManyValuesInducingRehash.
private void testManyValuesInducingRehash(InternalAggregationFunction aggregationFunction) {
double distinctFraction = 0.1f;
int numGroups = 50000;
int itemCount = 30;
Random random = new Random();
GroupedAccumulator groupedAccumulator = createGroupedAccumulator(aggregationFunction);
for (int j = 0; j < numGroups; j++) {
Map<String, Long> expectedValues = new HashMap<>();
List<String> valueList = new ArrayList<>();
for (int i = 0; i < itemCount; i++) {
String str = String.valueOf(i % 10);
String item = IntStream.range(0, itemCount).mapToObj(x -> str).collect(Collectors.joining());
boolean distinctValue = random.nextDouble() < distinctFraction;
if (distinctValue) {
// produce a unique value for the histogram
item = j + "-" + item;
valueList.add(item);
} else {
valueList.add(item);
}
expectedValues.compute(item, (k, v) -> v == null ? 1L : ++v);
}
Block block = createStringsBlock(valueList);
AggregationTestInputBuilder testInputBuilder = new AggregationTestInputBuilder(new Block[] { block }, aggregationFunction);
AggregationTestInput test1 = testInputBuilder.build();
test1.runPagesOnAccumulatorWithAssertion(j, groupedAccumulator, new AggregationTestOutput(expectedValues));
}
}
Aggregations