Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.trino.spi.predicate;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import io.trino.spi.TrinoException;
import io.trino.spi.block.Block;
import io.trino.spi.connector.ConnectorSession;
import io.trino.spi.type.Type;
import java.lang.invoke.MethodHandle;
import java.util.Objects;
import java.util.Optional;
import java.util.StringJoiner;
import static io.trino.spi.StandardErrorCode.GENERIC_INTERNAL_ERROR;
import static io.trino.spi.function.InvocationConvention.InvocationArgumentConvention.BLOCK_POSITION;
import static io.trino.spi.function.InvocationConvention.InvocationReturnConvention.FAIL_ON_NULL;
import static io.trino.spi.function.InvocationConvention.InvocationReturnConvention.NULLABLE_RETURN;
import static io.trino.spi.function.InvocationConvention.simpleConvention;
import static io.trino.spi.predicate.Utils.TUPLE_DOMAIN_TYPE_OPERATORS;
import static io.trino.spi.predicate.Utils.blockToNativeValue;
import static io.trino.spi.predicate.Utils.handleThrowable;
import static io.trino.spi.predicate.Utils.nativeValueToBlock;
import static io.trino.spi.type.TypeUtils.isFloatingPointNaN;
import static java.lang.String.format;
import static java.util.Objects.requireNonNull;
/**
* A point on the continuous space defined by the specified type.
* Each point may be just below, exact, or just above the specified value according to the Bound.
*/
public final class Marker
implements Comparable
{
public enum Bound
{
BELOW, // lower than the value, but infinitesimally close to the value
EXACTLY, // exactly the value
ABOVE // higher than the value, but infinitesimally close to the value
}
private final Type type;
private final MethodHandle comparisonOperator;
private final Optional valueBlock;
private final Bound bound;
private final MethodHandle equalOperator;
private final MethodHandle hashCodeOperator;
/**
* LOWER UNBOUNDED is specified with an empty value and a ABOVE bound
* UPPER UNBOUNDED is specified with an empty value and a BELOW bound
*/
@JsonCreator
public Marker(
@JsonProperty("type") Type type,
@JsonProperty("valueBlock") Optional valueBlock,
@JsonProperty("bound") Bound bound)
{
requireNonNull(type, "type is null");
requireNonNull(valueBlock, "valueBlock is null");
requireNonNull(bound, "bound is null");
if (!type.isOrderable()) {
throw new IllegalArgumentException("type must be orderable");
}
if (valueBlock.isEmpty() && bound == Bound.EXACTLY) {
throw new IllegalArgumentException("Cannot be equal to unbounded");
}
if (valueBlock.isPresent() && valueBlock.get().getPositionCount() != 1) {
throw new IllegalArgumentException("value block should only have one position");
}
if (valueBlock.isPresent() && isFloatingPointNaN(type, blockToNativeValue(type, valueBlock.get()))) {
throw new IllegalArgumentException("cannot use NaN as range bound");
}
this.type = type;
this.comparisonOperator = TUPLE_DOMAIN_TYPE_OPERATORS.getComparisonOperator(type, simpleConvention(FAIL_ON_NULL, BLOCK_POSITION, BLOCK_POSITION));
this.valueBlock = valueBlock;
this.bound = bound;
this.equalOperator = TUPLE_DOMAIN_TYPE_OPERATORS.getEqualOperator(type, simpleConvention(NULLABLE_RETURN, BLOCK_POSITION, BLOCK_POSITION));
this.hashCodeOperator = TUPLE_DOMAIN_TYPE_OPERATORS.getHashCodeOperator(type, simpleConvention(FAIL_ON_NULL, BLOCK_POSITION));
}
private static Marker create(Type type, Optional