Search in sources :

Example 1 with QualifiedName

use of com.facebook.presto.sql.tree.QualifiedName in project presto by prestodb.

the class FunctionRegistry method resolveFunction.

public Signature resolveFunction(QualifiedName name, List<TypeSignatureProvider> parameterTypes) {
    Collection<SqlFunction> allCandidates = functions.get(name);
    List<SqlFunction> exactCandidates = allCandidates.stream().filter(function -> function.getSignature().getTypeVariableConstraints().isEmpty()).collect(Collectors.toList());
    Optional<Signature> match = matchFunctionExact(exactCandidates, parameterTypes);
    if (match.isPresent()) {
        return match.get();
    }
    List<SqlFunction> genericCandidates = allCandidates.stream().filter(function -> !function.getSignature().getTypeVariableConstraints().isEmpty()).collect(Collectors.toList());
    match = matchFunctionExact(genericCandidates, parameterTypes);
    if (match.isPresent()) {
        return match.get();
    }
    match = matchFunctionWithCoercion(allCandidates, parameterTypes);
    if (match.isPresent()) {
        return match.get();
    }
    List<String> expectedParameters = new ArrayList<>();
    for (SqlFunction function : allCandidates) {
        expectedParameters.add(format("%s(%s) %s", name, Joiner.on(", ").join(function.getSignature().getArgumentTypes()), Joiner.on(", ").join(function.getSignature().getTypeVariableConstraints())));
    }
    String parameters = Joiner.on(", ").join(parameterTypes);
    String message = format("Function %s not registered", name);
    if (!expectedParameters.isEmpty()) {
        String expected = Joiner.on(", ").join(expectedParameters);
        message = format("Unexpected parameters (%s) for function %s. Expected: %s", parameters, name, expected);
    }
    if (name.getSuffix().startsWith(MAGIC_LITERAL_FUNCTION_PREFIX)) {
        // extract type from function name
        String typeName = name.getSuffix().substring(MAGIC_LITERAL_FUNCTION_PREFIX.length());
        // lookup the type
        Type type = typeManager.getType(parseTypeSignature(typeName));
        requireNonNull(type, format("Type %s not registered", typeName));
        // verify we have one parameter of the proper type
        checkArgument(parameterTypes.size() == 1, "Expected one argument to literal function, but got %s", parameterTypes);
        Type parameterType = typeManager.getType(parameterTypes.get(0).getTypeSignature());
        requireNonNull(parameterType, format("Type %s not found", parameterTypes.get(0)));
        return getMagicLiteralFunctionSignature(type);
    }
    throw new PrestoException(FUNCTION_NOT_FOUND, message);
}
Also used : INTEGER_TO_DECIMAL_CAST(com.facebook.presto.type.DecimalCasts.INTEGER_TO_DECIMAL_CAST) ApproximateDoublePercentileArrayAggregations(com.facebook.presto.operator.aggregation.ApproximateDoublePercentileArrayAggregations) DECIMAL_TO_SMALLINT_SATURATED_FLOOR_CAST(com.facebook.presto.type.DecimalSaturatedFloorCasts.DECIMAL_TO_SMALLINT_SATURATED_FLOOR_CAST) MapEqualOperator(com.facebook.presto.operator.scalar.MapEqualOperator) DECIMAL_SUBTRACT_OPERATOR(com.facebook.presto.type.DecimalOperators.DECIMAL_SUBTRACT_OPERATOR) TimeOperators(com.facebook.presto.type.TimeOperators) JsonFunctions(com.facebook.presto.operator.scalar.JsonFunctions) NTileFunction(com.facebook.presto.operator.window.NTileFunction) TimestampWithTimeZoneOperators(com.facebook.presto.type.TimestampWithTimeZoneOperators) ArrayContains(com.facebook.presto.operator.scalar.ArrayContains) DECIMAL_LESS_THAN_OR_EQUAL_OPERATOR(com.facebook.presto.type.DecimalInequalityOperators.DECIMAL_LESS_THAN_OR_EQUAL_OPERATOR) BOOLEAN(com.facebook.presto.spi.type.BooleanType.BOOLEAN) AverageAggregations(com.facebook.presto.operator.aggregation.AverageAggregations) Map(java.util.Map) MathFunctions(com.facebook.presto.operator.scalar.MathFunctions) ImmutableCollectors.toImmutableList(com.facebook.presto.util.ImmutableCollectors.toImmutableList) MAP_FILTER_FUNCTION(com.facebook.presto.operator.scalar.MapFilterFunction.MAP_FILTER_FUNCTION) CONCAT(com.facebook.presto.operator.scalar.ConcatFunction.CONCAT) SignatureBinder.applyBoundVariables(com.facebook.presto.metadata.SignatureBinder.applyBoundVariables) HyperLogLogOperators(com.facebook.presto.type.HyperLogLogOperators) WINDOW(com.facebook.presto.metadata.FunctionKind.WINDOW) InternalAggregationFunction(com.facebook.presto.operator.aggregation.InternalAggregationFunction) MAP_ELEMENT_AT(com.facebook.presto.operator.scalar.MapElementAtFunction.MAP_ELEMENT_AT) OperatorType(com.facebook.presto.spi.function.OperatorType) ArrayFunctions(com.facebook.presto.operator.scalar.ArrayFunctions) PercentRankFunction(com.facebook.presto.operator.window.PercentRankFunction) DECIMAL_MULTIPLY_OPERATOR(com.facebook.presto.type.DecimalOperators.DECIMAL_MULTIPLY_OPERATOR) Joiner(com.google.common.base.Joiner) MethodHandle(java.lang.invoke.MethodHandle) LagFunction(com.facebook.presto.operator.window.LagFunction) ApproximateCountDistinctAggregations(com.facebook.presto.operator.aggregation.ApproximateCountDistinctAggregations) ColorFunctions(com.facebook.presto.operator.scalar.ColorFunctions) DECIMAL_SUM_AGGREGATION(com.facebook.presto.operator.aggregation.DecimalSumAggregation.DECIMAL_SUM_AGGREGATION) VarbinaryOperators(com.facebook.presto.type.VarbinaryOperators) MAP_UNION(com.facebook.presto.operator.aggregation.MapUnionAggregation.MAP_UNION) ARRAY_TO_ARRAY_CAST(com.facebook.presto.operator.scalar.ArrayToArrayCast.ARRAY_TO_ARRAY_CAST) TimestampOperators(com.facebook.presto.type.TimestampOperators) ArrayPositionFunction(com.facebook.presto.operator.scalar.ArrayPositionFunction) CHECKSUM_AGGREGATION(com.facebook.presto.operator.aggregation.ChecksumAggregationFunction.CHECKSUM_AGGREGATION) DecimalOperators(com.facebook.presto.type.DecimalOperators) Type(com.facebook.presto.spi.type.Type) ARRAY_FLATTEN_FUNCTION(com.facebook.presto.operator.scalar.ArrayFlattenFunction.ARRAY_FLATTEN_FUNCTION) TRY_CAST(com.facebook.presto.operator.scalar.TryCastFunction.TRY_CAST) ArrayEqualOperator(com.facebook.presto.operator.scalar.ArrayEqualOperator) JoniRegexpFunctions(com.facebook.presto.operator.scalar.JoniRegexpFunctions) BitwiseAndAggregation(com.facebook.presto.operator.aggregation.BitwiseAndAggregation) ELEMENT_TO_ARRAY_CONCAT_FUNCTION(com.facebook.presto.operator.scalar.ElementToArrayConcatFunction.ELEMENT_TO_ARRAY_CONCAT_FUNCTION) AMBIGUOUS_FUNCTION_CALL(com.facebook.presto.spi.StandardErrorCode.AMBIGUOUS_FUNCTION_CALL) DECIMAL_GREATER_THAN_OPERATOR(com.facebook.presto.type.DecimalInequalityOperators.DECIMAL_GREATER_THAN_OPERATOR) ApproximateRealPercentileAggregations(com.facebook.presto.operator.aggregation.ApproximateRealPercentileAggregations) DECIMAL_TO_BIGINT_SATURATED_FLOOR_CAST(com.facebook.presto.type.DecimalSaturatedFloorCasts.DECIMAL_TO_BIGINT_SATURATED_FLOOR_CAST) BIGINT_TO_DECIMAL_CAST(com.facebook.presto.type.DecimalCasts.BIGINT_TO_DECIMAL_CAST) Throwables(com.google.common.base.Throwables) MAP_AGG(com.facebook.presto.operator.aggregation.MapAggregationFunction.MAP_AGG) GREATEST(com.facebook.presto.operator.scalar.Greatest.GREATEST) IDENTITY_CAST(com.facebook.presto.operator.scalar.IdentityCast.IDENTITY_CAST) Iterables.getOnlyElement(com.google.common.collect.Iterables.getOnlyElement) ColorOperators(com.facebook.presto.type.ColorOperators) HISTOGRAM(com.facebook.presto.operator.aggregation.Histogram.HISTOGRAM) ArrayExceptFunction(com.facebook.presto.operator.scalar.ArrayExceptFunction) ARRAY_TO_ELEMENT_CONCAT_FUNCTION(com.facebook.presto.operator.scalar.ArrayToElementConcatFunction.ARRAY_TO_ELEMENT_CONCAT_FUNCTION) TINYINT_TO_DECIMAL_SATURATED_FLOOR_CAST(com.facebook.presto.type.DecimalSaturatedFloorCasts.TINYINT_TO_DECIMAL_SATURATED_FLOOR_CAST) DoubleCovarianceAggregation(com.facebook.presto.operator.aggregation.DoubleCovarianceAggregation) CountIfAggregation(com.facebook.presto.operator.aggregation.CountIfAggregation) JSON_TO_DECIMAL_CAST(com.facebook.presto.type.DecimalCasts.JSON_TO_DECIMAL_CAST) VarcharType(com.facebook.presto.spi.type.VarcharType) DECIMAL_DISTINCT_FROM_OPERATOR(com.facebook.presto.type.DecimalInequalityOperators.DECIMAL_DISTINCT_FROM_OPERATOR) TypeSignature.parseTypeSignature(com.facebook.presto.spi.type.TypeSignature.parseTypeSignature) DoubleRegressionAggregation(com.facebook.presto.operator.aggregation.DoubleRegressionAggregation) MAX_BY(com.facebook.presto.operator.aggregation.MaxBy.MAX_BY) DoubleSumAggregation(com.facebook.presto.operator.aggregation.DoubleSumAggregation) DECIMAL_NOT_EQUAL_OPERATOR(com.facebook.presto.type.DecimalInequalityOperators.DECIMAL_NOT_EQUAL_OPERATOR) IntegerOperators(com.facebook.presto.type.IntegerOperators) ArrayReverseFunction(com.facebook.presto.operator.scalar.ArrayReverseFunction) LastValueFunction(com.facebook.presto.operator.window.LastValueFunction) Block(com.facebook.presto.spi.block.Block) MAP_HASH_CODE(com.facebook.presto.operator.scalar.MapHashCodeOperator.MAP_HASH_CODE) RealGeometricMeanAggregations(com.facebook.presto.operator.aggregation.RealGeometricMeanAggregations) FUNCTION_NOT_FOUND(com.facebook.presto.spi.StandardErrorCode.FUNCTION_NOT_FOUND) ARBITRARY_AGGREGATION(com.facebook.presto.operator.aggregation.ArbitraryAggregationFunction.ARBITRARY_AGGREGATION) JSON_TO_ARRAY(com.facebook.presto.operator.scalar.JsonToArrayCast.JSON_TO_ARRAY) ARRAY_CONCAT_FUNCTION(com.facebook.presto.operator.scalar.ArrayConcatFunction.ARRAY_CONCAT_FUNCTION) Re2JCastToRegexpFunction.castCharToRe2JRegexp(com.facebook.presto.operator.scalar.Re2JCastToRegexpFunction.castCharToRe2JRegexp) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) BooleanAndAggregation(com.facebook.presto.operator.aggregation.BooleanAndAggregation) DateTimeOperators(com.facebook.presto.type.DateTimeOperators) MIN_BY(com.facebook.presto.operator.aggregation.MinBy.MIN_BY) ARRAY_TO_JSON(com.facebook.presto.operator.scalar.ArrayToJsonCast.ARRAY_TO_JSON) UNKNOWN(com.facebook.presto.type.UnknownType.UNKNOWN) RankFunction(com.facebook.presto.operator.window.RankFunction) MAP_TRANSFORM_VALUE_FUNCTION(com.facebook.presto.operator.scalar.MapTransformValueFunction.MAP_TRANSFORM_VALUE_FUNCTION) ArrayDistinctFunction(com.facebook.presto.operator.scalar.ArrayDistinctFunction) DECIMAL_MOD_FUNCTION(com.facebook.presto.operator.scalar.MathFunctions.DECIMAL_MOD_FUNCTION) NthValueFunction(com.facebook.presto.operator.window.NthValueFunction) MAX_BY_N_AGGREGATION(com.facebook.presto.operator.aggregation.MaxByNAggregationFunction.MAX_BY_N_AGGREGATION) ImmutableSet(com.google.common.collect.ImmutableSet) DECIMAL_LESS_THAN_OPERATOR(com.facebook.presto.type.DecimalInequalityOperators.DECIMAL_LESS_THAN_OPERATOR) Collection(java.util.Collection) CountAggregation(com.facebook.presto.operator.aggregation.CountAggregation) Collectors(java.util.stream.Collectors) ARRAY_REDUCE_FUNCTION(com.facebook.presto.operator.scalar.ArrayReduceFunction.ARRAY_REDUCE_FUNCTION) CacheLoader(com.google.common.cache.CacheLoader) DECIMAL_TO_BIGINT_CAST(com.facebook.presto.type.DecimalCasts.DECIMAL_TO_BIGINT_CAST) Re2JCastToRegexpFunction.castVarcharToRe2JRegexp(com.facebook.presto.operator.scalar.Re2JCastToRegexpFunction.castVarcharToRe2JRegexp) DECIMAL_TO_DECIMAL_CAST(com.facebook.presto.type.DecimalToDecimalCasts.DECIMAL_TO_DECIMAL_CAST) WindowFunctionSupplier(com.facebook.presto.operator.window.WindowFunctionSupplier) AggregateWindowFunction.supplier(com.facebook.presto.operator.window.AggregateWindowFunction.supplier) QualifiedName(com.facebook.presto.sql.tree.QualifiedName) DECIMAL_ADD_OPERATOR(com.facebook.presto.type.DecimalOperators.DECIMAL_ADD_OPERATOR) DoubleHistogramAggregation(com.facebook.presto.operator.aggregation.DoubleHistogramAggregation) ROW_HASH_CODE(com.facebook.presto.operator.scalar.RowHashCodeOperator.ROW_HASH_CODE) JoniRegexpCasts(com.facebook.presto.operator.scalar.JoniRegexpCasts) UnknownOperators(com.facebook.presto.type.UnknownOperators) ArrayDistinctFromOperator(com.facebook.presto.operator.scalar.ArrayDistinctFromOperator) BooleanOperators(com.facebook.presto.type.BooleanOperators) BlockEncodingSerde(com.facebook.presto.spi.block.BlockEncodingSerde) Re2JRegexpFunctions(com.facebook.presto.operator.scalar.Re2JRegexpFunctions) ImmutableList(com.google.common.collect.ImmutableList) UncheckedExecutionException(com.google.common.util.concurrent.UncheckedExecutionException) INTEGER_TO_DECIMAL_SATURATED_FLOOR_CAST(com.facebook.presto.type.DecimalSaturatedFloorCasts.INTEGER_TO_DECIMAL_SATURATED_FLOOR_CAST) ArrayLessThanOperator(com.facebook.presto.operator.scalar.ArrayLessThanOperator) JsonOperators(com.facebook.presto.operator.scalar.JsonOperators) VARBINARY(com.facebook.presto.spi.type.VarbinaryType.VARBINARY) ArrayGreaterThanOrEqualOperator(com.facebook.presto.operator.scalar.ArrayGreaterThanOrEqualOperator) MAX_N_AGGREGATION(com.facebook.presto.operator.aggregation.MaxNAggregationFunction.MAX_N_AGGREGATION) DECIMAL_TO_INTEGER_SATURATED_FLOOR_CAST(com.facebook.presto.type.DecimalSaturatedFloorCasts.DECIMAL_TO_INTEGER_SATURATED_FLOOR_CAST) RealCorrelationAggregation(com.facebook.presto.operator.aggregation.RealCorrelationAggregation) ArraySortFunction(com.facebook.presto.operator.scalar.ArraySortFunction) ArraySliceFunction(com.facebook.presto.operator.scalar.ArraySliceFunction) MAP_TO_JSON(com.facebook.presto.operator.scalar.MapToJsonCast.MAP_TO_JSON) HyperLogLogFunctions(com.facebook.presto.operator.scalar.HyperLogLogFunctions) RowNumberFunction(com.facebook.presto.operator.window.RowNumberFunction) JSON_TO_MAP(com.facebook.presto.operator.scalar.JsonToMapCast.JSON_TO_MAP) MAP_TRANSFORM_KEY_FUNCTION(com.facebook.presto.operator.scalar.MapTransformKeyFunction.MAP_TRANSFORM_KEY_FUNCTION) Ordering(com.google.common.collect.Ordering) ARRAY_SUBSCRIPT(com.facebook.presto.operator.scalar.ArraySubscriptOperator.ARRAY_SUBSCRIPT) BitwiseOrAggregation(com.facebook.presto.operator.aggregation.BitwiseOrAggregation) DECIMAL_TO_JSON_CAST(com.facebook.presto.type.DecimalCasts.DECIMAL_TO_JSON_CAST) EmptyMapConstructor(com.facebook.presto.operator.scalar.EmptyMapConstructor) ARRAY_JOIN(com.facebook.presto.operator.scalar.ArrayJoin.ARRAY_JOIN) DECIMAL_TO_VARCHAR_CAST(com.facebook.presto.type.DecimalCasts.DECIMAL_TO_VARCHAR_CAST) Arrays(java.util.Arrays) DECIMAL_TO_BOOLEAN_CAST(com.facebook.presto.type.DecimalCasts.DECIMAL_TO_BOOLEAN_CAST) LoadingCache(com.google.common.cache.LoadingCache) TypeManager(com.facebook.presto.spi.type.TypeManager) MapKeys(com.facebook.presto.operator.scalar.MapKeys) BIGINT_TO_DECIMAL_SATURATED_FLOOR_CAST(com.facebook.presto.type.DecimalSaturatedFloorCasts.BIGINT_TO_DECIMAL_SATURATED_FLOOR_CAST) AGGREGATE(com.facebook.presto.metadata.FunctionKind.AGGREGATE) REAL_TO_DECIMAL_SATURATED_FLOOR_CAST(com.facebook.presto.type.DecimalSaturatedFloorCasts.REAL_TO_DECIMAL_SATURATED_FLOOR_CAST) ROW_NOT_EQUAL(com.facebook.presto.operator.scalar.RowNotEqualOperator.ROW_NOT_EQUAL) BIGINT(com.facebook.presto.spi.type.BigintType.BIGINT) SmallintOperators(com.facebook.presto.type.SmallintOperators) ApproximateRealPercentileArrayAggregations(com.facebook.presto.operator.aggregation.ApproximateRealPercentileArrayAggregations) SqlWindowFunction(com.facebook.presto.operator.window.SqlWindowFunction) CharOperators(com.facebook.presto.type.CharOperators) MAP_CONSTRUCTOR(com.facebook.presto.operator.scalar.MapConstructor.MAP_CONSTRUCTOR) ArrayAggregationFunction(com.facebook.presto.operator.aggregation.ArrayAggregationFunction) MapCardinalityFunction(com.facebook.presto.operator.scalar.MapCardinalityFunction) LongSumAggregation(com.facebook.presto.operator.aggregation.LongSumAggregation) MapNotEqualOperator(com.facebook.presto.operator.scalar.MapNotEqualOperator) ROW_GREATER_THAN_OR_EQUAL(com.facebook.presto.operator.scalar.RowGreaterThanOrEqualOperator.ROW_GREATER_THAN_OR_EQUAL) LikeFunctions(com.facebook.presto.type.LikeFunctions) MethodHandles(java.lang.invoke.MethodHandles) TypeOfFunction(com.facebook.presto.operator.scalar.TypeOfFunction) Set(java.util.Set) RealSumAggregation(com.facebook.presto.operator.aggregation.RealSumAggregation) ThreadSafe(javax.annotation.concurrent.ThreadSafe) DECIMAL_TO_DOUBLE_CAST(com.facebook.presto.type.DecimalCasts.DECIMAL_TO_DOUBLE_CAST) ArrayGreaterThanOperator(com.facebook.presto.operator.scalar.ArrayGreaterThanOperator) FeaturesConfig(com.facebook.presto.sql.analyzer.FeaturesConfig) MIN_AGGREGATION(com.facebook.presto.operator.aggregation.MinAggregationFunction.MIN_AGGREGATION) LEAST(com.facebook.presto.operator.scalar.Least.LEAST) DECIMAL_TO_INTEGER_CAST(com.facebook.presto.type.DecimalCasts.DECIMAL_TO_INTEGER_CAST) ApproximateLongPercentileArrayAggregations(com.facebook.presto.operator.aggregation.ApproximateLongPercentileArrayAggregations) DECIMAL_TO_TINYINT_CAST(com.facebook.presto.type.DecimalCasts.DECIMAL_TO_TINYINT_CAST) MergeHyperLogLogAggregation(com.facebook.presto.operator.aggregation.MergeHyperLogLogAggregation) IntervalYearMonthOperators(com.facebook.presto.type.IntervalYearMonthOperators) FUNCTION_IMPLEMENTATION_MISSING(com.facebook.presto.spi.StandardErrorCode.FUNCTION_IMPLEMENTATION_MISSING) ImmutableListMultimap(com.google.common.collect.ImmutableListMultimap) ArrayElementAtFunction(com.facebook.presto.operator.scalar.ArrayElementAtFunction) ROW_EQUAL(com.facebook.presto.operator.scalar.RowEqualOperator.ROW_EQUAL) BitwiseFunctions(com.facebook.presto.operator.scalar.BitwiseFunctions) RealOperators(com.facebook.presto.type.RealOperators) VarcharOperators(com.facebook.presto.type.VarcharOperators) MoreObjects.toStringHelper(com.google.common.base.MoreObjects.toStringHelper) SMALLINT_TO_DECIMAL_SATURATED_FLOOR_CAST(com.facebook.presto.type.DecimalSaturatedFloorCasts.SMALLINT_TO_DECIMAL_SATURATED_FLOOR_CAST) Iterables(com.google.common.collect.Iterables) DOUBLE(com.facebook.presto.spi.type.DoubleType.DOUBLE) Slice(io.airlift.slice.Slice) ApproximateSetAggregation(com.facebook.presto.operator.aggregation.ApproximateSetAggregation) DoubleOperators(com.facebook.presto.type.DoubleOperators) MAX_AGGREGATION(com.facebook.presto.operator.aggregation.MaxAggregationFunction.MAX_AGGREGATION) DECIMAL_MODULUS_OPERATOR(com.facebook.presto.type.DecimalOperators.DECIMAL_MODULUS_OPERATOR) TypeSignatureProvider.fromTypes(com.facebook.presto.sql.analyzer.TypeSignatureProvider.fromTypes) DECIMAL_AVERAGE_AGGREGATION(com.facebook.presto.operator.aggregation.DecimalAverageAggregation.DECIMAL_AVERAGE_AGGREGATION) Multimaps(com.google.common.collect.Multimaps) ArrayList(java.util.ArrayList) MIN_N_AGGREGATION(com.facebook.presto.operator.aggregation.MinNAggregationFunction.MIN_N_AGGREGATION) REAL_TO_DECIMAL_CAST(com.facebook.presto.type.DecimalCasts.REAL_TO_DECIMAL_CAST) RealAverageAggregation(com.facebook.presto.operator.aggregation.RealAverageAggregation) ArrayNotEqualOperator(com.facebook.presto.operator.scalar.ArrayNotEqualOperator) TimeWithTimeZoneOperators(com.facebook.presto.type.TimeWithTimeZoneOperators) DECIMAL_EQUAL_OPERATOR(com.facebook.presto.type.DecimalInequalityOperators.DECIMAL_EQUAL_OPERATOR) DECIMAL_DIVIDE_OPERATOR(com.facebook.presto.type.DecimalOperators.DECIMAL_DIVIDE_OPERATOR) ApproximateDoublePercentileAggregations(com.facebook.presto.operator.aggregation.ApproximateDoublePercentileAggregations) MIN_BY_N_AGGREGATION(com.facebook.presto.operator.aggregation.MinByNAggregationFunction.MIN_BY_N_AGGREGATION) DECIMAL_GREATER_THAN_OR_EQUAL_OPERATOR(com.facebook.presto.type.DecimalInequalityOperators.DECIMAL_GREATER_THAN_OR_EQUAL_OPERATOR) CAST_FROM_UNKNOWN(com.facebook.presto.operator.scalar.CastFromUnknownOperator.CAST_FROM_UNKNOWN) DenseRankFunction(com.facebook.presto.operator.window.DenseRankFunction) DECIMAL_TO_DECIMAL_SATURATED_FLOOR_CAST(com.facebook.presto.type.DecimalSaturatedFloorCasts.DECIMAL_TO_DECIMAL_SATURATED_FLOOR_CAST) ArrayMaxFunction(com.facebook.presto.operator.scalar.ArrayMaxFunction) RealCovarianceAggregation(com.facebook.presto.operator.aggregation.RealCovarianceAggregation) ArrayLessThanOrEqualOperator(com.facebook.presto.operator.scalar.ArrayLessThanOrEqualOperator) BlockSerdeUtil(com.facebook.presto.block.BlockSerdeUtil) ArrayUnionFunction(com.facebook.presto.operator.scalar.ArrayUnionFunction) CumulativeDistributionFunction(com.facebook.presto.operator.window.CumulativeDistributionFunction) ARRAY_TRANSFORM_FUNCTION(com.facebook.presto.operator.scalar.ArrayTransformFunction.ARRAY_TRANSFORM_FUNCTION) SequenceFunction(com.facebook.presto.operator.scalar.SequenceFunction) RealRegressionAggregation(com.facebook.presto.operator.aggregation.RealRegressionAggregation) FailureFunction(com.facebook.presto.operator.scalar.FailureFunction) MapSubscriptOperator(com.facebook.presto.operator.scalar.MapSubscriptOperator) MULTIMAP_AGG(com.facebook.presto.operator.aggregation.MultimapAggregationFunction.MULTIMAP_AGG) BigintOperators(com.facebook.presto.type.BigintOperators) ARRAY_CONSTRUCTOR(com.facebook.presto.operator.scalar.ArrayConstructor.ARRAY_CONSTRUCTOR) ArraysOverlapFunction(com.facebook.presto.operator.scalar.ArraysOverlapFunction) ROW_GREATER_THAN(com.facebook.presto.operator.scalar.RowGreaterThanOperator.ROW_GREATER_THAN) GeometricMeanAggregations(com.facebook.presto.operator.aggregation.GeometricMeanAggregations) RealHistogramAggregation(com.facebook.presto.operator.aggregation.RealHistogramAggregation) BOOLEAN_TO_DECIMAL_CAST(com.facebook.presto.type.DecimalCasts.BOOLEAN_TO_DECIMAL_CAST) ImmutableCollectors.toImmutableSet(com.facebook.presto.util.ImmutableCollectors.toImmutableSet) DECIMAL_BETWEEN_OPERATOR(com.facebook.presto.type.DecimalInequalityOperators.DECIMAL_BETWEEN_OPERATOR) DateTimeFunctions(com.facebook.presto.operator.scalar.DateTimeFunctions) BooleanOrAggregation(com.facebook.presto.operator.aggregation.BooleanOrAggregation) DOUBLE_TO_DECIMAL_SATURATED_FLOOR_CAST(com.facebook.presto.type.DecimalSaturatedFloorCasts.DOUBLE_TO_DECIMAL_SATURATED_FLOOR_CAST) CharacterStringCasts(com.facebook.presto.operator.scalar.CharacterStringCasts) ZIP_FUNCTIONS(com.facebook.presto.operator.scalar.ZipFunction.ZIP_FUNCTIONS) IntervalDayTimeOperators(com.facebook.presto.type.IntervalDayTimeOperators) ApproximateLongPercentileAggregations(com.facebook.presto.operator.aggregation.ApproximateLongPercentileAggregations) MapDistinctFromOperator(com.facebook.presto.operator.scalar.MapDistinctFromOperator) FirstValueFunction(com.facebook.presto.operator.window.FirstValueFunction) String.format(java.lang.String.format) TypeUtils.resolveTypes(com.facebook.presto.type.TypeUtils.resolveTypes) Preconditions.checkState(com.google.common.base.Preconditions.checkState) TINYINT_TO_DECIMAL_CAST(com.facebook.presto.type.DecimalCasts.TINYINT_TO_DECIMAL_CAST) List(java.util.List) ArrayShuffleFunction(com.facebook.presto.operator.scalar.ArrayShuffleFunction) ArrayIntersectFunction(com.facebook.presto.operator.scalar.ArrayIntersectFunction) ROW_TO_JSON(com.facebook.presto.operator.scalar.RowToJsonCast.ROW_TO_JSON) TypeSignatureProvider(com.facebook.presto.sql.analyzer.TypeSignatureProvider) Optional(java.util.Optional) MapToMapCast(com.facebook.presto.operator.scalar.MapToMapCast) CacheBuilder(com.google.common.cache.CacheBuilder) TypeSignature(com.facebook.presto.spi.type.TypeSignature) DOUBLE_TO_DECIMAL_CAST(com.facebook.presto.type.DecimalCasts.DOUBLE_TO_DECIMAL_CAST) SMALLINT_TO_DECIMAL_CAST(com.facebook.presto.type.DecimalCasts.SMALLINT_TO_DECIMAL_CAST) ScalarFunctionImplementation(com.facebook.presto.operator.scalar.ScalarFunctionImplementation) DateOperators(com.facebook.presto.type.DateOperators) PrestoException(com.facebook.presto.spi.PrestoException) Multimap(com.google.common.collect.Multimap) ZIP_WITH_FUNCTION(com.facebook.presto.operator.scalar.ZipWithFunction.ZIP_WITH_FUNCTION) StringFunctions(com.facebook.presto.operator.scalar.StringFunctions) DECIMAL_TO_TINYINT_SATURATED_FLOOR_CAST(com.facebook.presto.type.DecimalSaturatedFloorCasts.DECIMAL_TO_TINYINT_SATURATED_FLOOR_CAST) SCALAR(com.facebook.presto.metadata.FunctionKind.SCALAR) ROW_TO_ROW_CAST(com.facebook.presto.operator.scalar.RowToRowCast.ROW_TO_ROW_CAST) CombineHashFunction(com.facebook.presto.operator.scalar.CombineHashFunction) Objects.requireNonNull(java.util.Objects.requireNonNull) TypeSignatureProvider.fromTypeSignatures(com.facebook.presto.sql.analyzer.TypeSignatureProvider.fromTypeSignatures) COUNT_COLUMN(com.facebook.presto.operator.aggregation.CountColumn.COUNT_COLUMN) LeadFunction(com.facebook.presto.operator.window.LeadFunction) DoubleCorrelationAggregation(com.facebook.presto.operator.aggregation.DoubleCorrelationAggregation) DECIMAL_TO_REAL_CAST(com.facebook.presto.type.DecimalCasts.DECIMAL_TO_REAL_CAST) ArrayFilterFunction(com.facebook.presto.operator.scalar.ArrayFilterFunction) MapValues(com.facebook.presto.operator.scalar.MapValues) TinyintOperators(com.facebook.presto.type.TinyintOperators) Signature.internalOperator(com.facebook.presto.metadata.Signature.internalOperator) ArrayCardinalityFunction(com.facebook.presto.operator.scalar.ArrayCardinalityFunction) VarbinaryFunctions(com.facebook.presto.operator.scalar.VarbinaryFunctions) UrlFunctions(com.facebook.presto.operator.scalar.UrlFunctions) ARRAY_JOIN_WITH_NULL_REPLACEMENT(com.facebook.presto.operator.scalar.ArrayJoin.ARRAY_JOIN_WITH_NULL_REPLACEMENT) DECIMAL_TO_SMALLINT_CAST(com.facebook.presto.type.DecimalCasts.DECIMAL_TO_SMALLINT_CAST) VARCHAR_TO_DECIMAL_CAST(com.facebook.presto.type.DecimalCasts.VARCHAR_TO_DECIMAL_CAST) Primitives(com.google.common.primitives.Primitives) VarianceAggregation(com.facebook.presto.operator.aggregation.VarianceAggregation) ArrayRemoveFunction(com.facebook.presto.operator.scalar.ArrayRemoveFunction) MAP_CONCAT_FUNCTION(com.facebook.presto.operator.scalar.MapConcatFunction.MAP_CONCAT_FUNCTION) ROW_LESS_THAN_OR_EQUAL(com.facebook.presto.operator.scalar.RowLessThanOrEqualOperator.ROW_LESS_THAN_OR_EQUAL) ArrayHashCodeOperator(com.facebook.presto.operator.scalar.ArrayHashCodeOperator) ArrayMinFunction(com.facebook.presto.operator.scalar.ArrayMinFunction) VisibleForTesting(com.google.common.annotations.VisibleForTesting) ROW_DISTINCT_FROM(com.facebook.presto.operator.scalar.RowDistinctFromOperator.ROW_DISTINCT_FROM) ROW_LESS_THAN(com.facebook.presto.operator.scalar.RowLessThanOperator.ROW_LESS_THAN) OperatorType(com.facebook.presto.spi.function.OperatorType) Type(com.facebook.presto.spi.type.Type) VarcharType(com.facebook.presto.spi.type.VarcharType) TypeSignature.parseTypeSignature(com.facebook.presto.spi.type.TypeSignature.parseTypeSignature) TypeSignature(com.facebook.presto.spi.type.TypeSignature) ArrayList(java.util.ArrayList) PrestoException(com.facebook.presto.spi.PrestoException)

Example 2 with QualifiedName

use of com.facebook.presto.sql.tree.QualifiedName in project presto by prestodb.

the class QueryRewriter method rewriteCreateTableAsSelect.

private Query rewriteCreateTableAsSelect(Connection connection, Query query, CreateTableAsSelect statement) throws SQLException {
    List<String> parts = new ArrayList<>();
    int originalSize = statement.getName().getOriginalParts().size();
    int prefixSize = rewritePrefix.getOriginalParts().size();
    if (originalSize > prefixSize) {
        parts.addAll(statement.getName().getOriginalParts().subList(0, originalSize - prefixSize));
    }
    parts.addAll(rewritePrefix.getOriginalParts());
    parts.set(parts.size() - 1, createTemporaryTableName());
    QualifiedName temporaryTableName = QualifiedName.of(parts);
    Statement rewritten = new CreateTableAsSelect(temporaryTableName, statement.getQuery(), statement.isNotExists(), statement.getProperties(), statement.isWithData());
    String createTableAsSql = formatSql(rewritten, Optional.empty());
    String checksumSql = checksumSql(getColumns(connection, statement), temporaryTableName);
    String dropTableSql = dropTableSql(temporaryTableName);
    return new Query(query.getCatalog(), query.getSchema(), ImmutableList.of(createTableAsSql), checksumSql, ImmutableList.of(dropTableSql), query.getUsername(), query.getPassword(), query.getSessionProperties());
}
Also used : Statement(com.facebook.presto.sql.tree.Statement) QualifiedName(com.facebook.presto.sql.tree.QualifiedName) CreateTableAsSelect(com.facebook.presto.sql.tree.CreateTableAsSelect) ArrayList(java.util.ArrayList)

Example 3 with QualifiedName

use of com.facebook.presto.sql.tree.QualifiedName in project presto by prestodb.

the class AstBuilder method visitFunctionCall.

@Override
public Node visitFunctionCall(SqlBaseParser.FunctionCallContext context) {
    Optional<Expression> filter = visitIfPresent(context.filter(), Expression.class);
    Optional<Window> window = visitIfPresent(context.over(), Window.class);
    Optional<OrderBy> orderBy = Optional.empty();
    if (context.ORDER() != null) {
        orderBy = Optional.of(new OrderBy(visit(context.sortItem(), SortItem.class)));
    }
    QualifiedName name = getQualifiedName(context.qualifiedName());
    boolean distinct = isDistinct(context.setQuantifier());
    boolean ignoreNulls = context.nullTreatment() != null && context.nullTreatment().IGNORE() != null;
    if (name.toString().equalsIgnoreCase("if")) {
        check(context.expression().size() == 2 || context.expression().size() == 3, "Invalid number of arguments for 'if' function", context);
        check(!window.isPresent(), "OVER clause not valid for 'if' function", context);
        check(!distinct, "DISTINCT not valid for 'if' function", context);
        check(!filter.isPresent(), "FILTER not valid for 'if' function", context);
        Expression elseExpression = null;
        if (context.expression().size() == 3) {
            elseExpression = (Expression) visit(context.expression(2));
        }
        return new IfExpression(getLocation(context), (Expression) visit(context.expression(0)), (Expression) visit(context.expression(1)), elseExpression);
    }
    if (name.toString().equalsIgnoreCase("nullif")) {
        check(context.expression().size() == 2, "Invalid number of arguments for 'nullif' function", context);
        check(!window.isPresent(), "OVER clause not valid for 'nullif' function", context);
        check(!distinct, "DISTINCT not valid for 'nullif' function", context);
        check(!filter.isPresent(), "FILTER not valid for 'nullif' function", context);
        return new NullIfExpression(getLocation(context), (Expression) visit(context.expression(0)), (Expression) visit(context.expression(1)));
    }
    if (name.toString().equalsIgnoreCase("coalesce")) {
        check(context.expression().size() >= 2, "The 'coalesce' function must have at least two arguments", context);
        check(!window.isPresent(), "OVER clause not valid for 'coalesce' function", context);
        check(!distinct, "DISTINCT not valid for 'coalesce' function", context);
        check(!filter.isPresent(), "FILTER not valid for 'coalesce' function", context);
        return new CoalesceExpression(getLocation(context), visit(context.expression(), Expression.class));
    }
    if (name.toString().equalsIgnoreCase("try")) {
        check(context.expression().size() == 1, "The 'try' function must have exactly one argument", context);
        check(!window.isPresent(), "OVER clause not valid for 'try' function", context);
        check(!distinct, "DISTINCT not valid for 'try' function", context);
        check(!filter.isPresent(), "FILTER not valid for 'try' function", context);
        return new TryExpression(getLocation(context), (Expression) visit(getOnlyElement(context.expression())));
    }
    if (name.toString().equalsIgnoreCase("$internal$bind")) {
        check(context.expression().size() >= 1, "The '$internal$bind' function must have at least one arguments", context);
        check(!window.isPresent(), "OVER clause not valid for '$internal$bind' function", context);
        check(!distinct, "DISTINCT not valid for '$internal$bind' function", context);
        check(!filter.isPresent(), "FILTER not valid for '$internal$bind' function", context);
        int numValues = context.expression().size() - 1;
        List<Expression> arguments = context.expression().stream().map(this::visit).map(Expression.class::cast).collect(toImmutableList());
        return new BindExpression(getLocation(context), arguments.subList(0, numValues), arguments.get(numValues));
    }
    return new FunctionCall(getLocation(context), getQualifiedName(context.qualifiedName()), window, filter, orderBy, distinct, ignoreNulls, visit(context.expression(), Expression.class));
}
Also used : Window(com.facebook.presto.sql.tree.Window) OrderBy(com.facebook.presto.sql.tree.OrderBy) IfExpression(com.facebook.presto.sql.tree.IfExpression) NullIfExpression(com.facebook.presto.sql.tree.NullIfExpression) QualifiedName(com.facebook.presto.sql.tree.QualifiedName) TryExpression(com.facebook.presto.sql.tree.TryExpression) SortItem(com.facebook.presto.sql.tree.SortItem) SubqueryExpression(com.facebook.presto.sql.tree.SubqueryExpression) SubscriptExpression(com.facebook.presto.sql.tree.SubscriptExpression) LogicalBinaryExpression(com.facebook.presto.sql.tree.LogicalBinaryExpression) SearchedCaseExpression(com.facebook.presto.sql.tree.SearchedCaseExpression) CoalesceExpression(com.facebook.presto.sql.tree.CoalesceExpression) SimpleCaseExpression(com.facebook.presto.sql.tree.SimpleCaseExpression) NotExpression(com.facebook.presto.sql.tree.NotExpression) LambdaExpression(com.facebook.presto.sql.tree.LambdaExpression) IfExpression(com.facebook.presto.sql.tree.IfExpression) BindExpression(com.facebook.presto.sql.tree.BindExpression) QuantifiedComparisonExpression(com.facebook.presto.sql.tree.QuantifiedComparisonExpression) InListExpression(com.facebook.presto.sql.tree.InListExpression) TryExpression(com.facebook.presto.sql.tree.TryExpression) ArithmeticUnaryExpression(com.facebook.presto.sql.tree.ArithmeticUnaryExpression) DereferenceExpression(com.facebook.presto.sql.tree.DereferenceExpression) NullIfExpression(com.facebook.presto.sql.tree.NullIfExpression) ComparisonExpression(com.facebook.presto.sql.tree.ComparisonExpression) Expression(com.facebook.presto.sql.tree.Expression) ArithmeticBinaryExpression(com.facebook.presto.sql.tree.ArithmeticBinaryExpression) BindExpression(com.facebook.presto.sql.tree.BindExpression) NullIfExpression(com.facebook.presto.sql.tree.NullIfExpression) FunctionCall(com.facebook.presto.sql.tree.FunctionCall) CoalesceExpression(com.facebook.presto.sql.tree.CoalesceExpression)

Example 4 with QualifiedName

use of com.facebook.presto.sql.tree.QualifiedName in project presto by prestodb.

the class TestSqlParser method testCreateTableAsSelect.

@Test
public void testCreateTableAsSelect() {
    Query query = simpleQuery(selectList(new AllColumns()), table(QualifiedName.of("t")));
    Query querySelectColumn = simpleQuery(selectList(new Identifier("a")), table(QualifiedName.of("t")));
    Query querySelectColumns = simpleQuery(selectList(new Identifier("a"), new Identifier("b")), table(QualifiedName.of("t")));
    QualifiedName table = QualifiedName.of("foo");
    assertStatement("CREATE TABLE foo AS SELECT * FROM t", new CreateTableAsSelect(table, query, false, ImmutableList.of(), true, Optional.empty(), Optional.empty()));
    assertStatement("CREATE TABLE foo(x) AS SELECT a FROM t", new CreateTableAsSelect(table, querySelectColumn, false, ImmutableList.of(), true, Optional.of(ImmutableList.of(new Identifier("x"))), Optional.empty()));
    assertStatement("CREATE TABLE foo(x,y) AS SELECT a,b FROM t", new CreateTableAsSelect(table, querySelectColumns, false, ImmutableList.of(), true, Optional.of(ImmutableList.of(new Identifier("x"), new Identifier("y"))), Optional.empty()));
    assertStatement("CREATE TABLE IF NOT EXISTS foo AS SELECT * FROM t", new CreateTableAsSelect(table, query, true, ImmutableList.of(), true, Optional.empty(), Optional.empty()));
    assertStatement("CREATE TABLE IF NOT EXISTS foo(x) AS SELECT a FROM t", new CreateTableAsSelect(table, querySelectColumn, true, ImmutableList.of(), true, Optional.of(ImmutableList.of(new Identifier("x"))), Optional.empty()));
    assertStatement("CREATE TABLE IF NOT EXISTS foo(x,y) AS SELECT a,b FROM t", new CreateTableAsSelect(table, querySelectColumns, true, ImmutableList.of(), true, Optional.of(ImmutableList.of(new Identifier("x"), new Identifier("y"))), Optional.empty()));
    assertStatement("CREATE TABLE foo AS SELECT * FROM t WITH NO DATA", new CreateTableAsSelect(table, query, false, ImmutableList.of(), false, Optional.empty(), Optional.empty()));
    assertStatement("CREATE TABLE foo(x) AS SELECT a FROM t WITH NO DATA", new CreateTableAsSelect(table, querySelectColumn, false, ImmutableList.of(), false, Optional.of(ImmutableList.of(new Identifier("x"))), Optional.empty()));
    assertStatement("CREATE TABLE foo(x,y) AS SELECT a,b FROM t WITH NO DATA", new CreateTableAsSelect(table, querySelectColumns, false, ImmutableList.of(), false, Optional.of(ImmutableList.of(new Identifier("x"), new Identifier("y"))), Optional.empty()));
    List<Property> properties = ImmutableList.of(new Property(new Identifier("string"), new StringLiteral("bar")), new Property(new Identifier("long"), new LongLiteral("42")), new Property(new Identifier("computed"), new FunctionCall(QualifiedName.of("concat"), ImmutableList.of(new StringLiteral("ban"), new StringLiteral("ana")))), new Property(new Identifier("a"), new ArrayConstructor(ImmutableList.of(new StringLiteral("v1"), new StringLiteral("v2")))));
    assertStatement("CREATE TABLE foo " + "WITH ( string = 'bar', long = 42, computed = 'ban' || 'ana', a  = ARRAY[ 'v1', 'v2' ] ) " + "AS " + "SELECT * FROM t", new CreateTableAsSelect(table, query, false, properties, true, Optional.empty(), Optional.empty()));
    assertStatement("CREATE TABLE foo(x) " + "WITH ( string = 'bar', long = 42, computed = 'ban' || 'ana', a  = ARRAY[ 'v1', 'v2' ] ) " + "AS " + "SELECT a FROM t", new CreateTableAsSelect(table, querySelectColumn, false, properties, true, Optional.of(ImmutableList.of(new Identifier("x"))), Optional.empty()));
    assertStatement("CREATE TABLE foo(x,y) " + "WITH ( string = 'bar', long = 42, computed = 'ban' || 'ana', a  = ARRAY[ 'v1', 'v2' ] ) " + "AS " + "SELECT a,b FROM t", new CreateTableAsSelect(table, querySelectColumns, false, properties, true, Optional.of(ImmutableList.of(new Identifier("x"), new Identifier("y"))), Optional.empty()));
    assertStatement("CREATE TABLE foo " + "WITH ( string = 'bar', long = 42, computed = 'ban' || 'ana', a  = ARRAY[ 'v1', 'v2' ] ) " + "AS " + "SELECT * FROM t " + "WITH NO DATA", new CreateTableAsSelect(table, query, false, properties, false, Optional.empty(), Optional.empty()));
    assertStatement("CREATE TABLE foo(x) " + "WITH ( string = 'bar', long = 42, computed = 'ban' || 'ana', a  = ARRAY[ 'v1', 'v2' ] ) " + "AS " + "SELECT a FROM t " + "WITH NO DATA", new CreateTableAsSelect(table, querySelectColumn, false, properties, false, Optional.of(ImmutableList.of(new Identifier("x"))), Optional.empty()));
    assertStatement("CREATE TABLE foo(x,y) " + "WITH ( string = 'bar', long = 42, computed = 'ban' || 'ana', a  = ARRAY[ 'v1', 'v2' ] ) " + "AS " + "SELECT a,b FROM t " + "WITH NO DATA", new CreateTableAsSelect(table, querySelectColumns, false, properties, false, Optional.of(ImmutableList.of(new Identifier("x"), new Identifier("y"))), Optional.empty()));
    assertStatement("CREATE TABLE foo COMMENT 'test'" + "WITH ( string = 'bar', long = 42, computed = 'ban' || 'ana', a  = ARRAY[ 'v1', 'v2' ] ) " + "AS " + "SELECT * FROM t " + "WITH NO DATA", new CreateTableAsSelect(table, query, false, properties, false, Optional.empty(), Optional.of("test")));
    assertStatement("CREATE TABLE foo(x) COMMENT 'test'" + "WITH ( string = 'bar', long = 42, computed = 'ban' || 'ana', a  = ARRAY[ 'v1', 'v2' ] ) " + "AS " + "SELECT a FROM t " + "WITH NO DATA", new CreateTableAsSelect(table, querySelectColumn, false, properties, false, Optional.of(ImmutableList.of(new Identifier("x"))), Optional.of("test")));
    assertStatement("CREATE TABLE foo(x,y) COMMENT 'test'" + "WITH ( string = 'bar', long = 42, computed = 'ban' || 'ana', a  = ARRAY[ 'v1', 'v2' ] ) " + "AS " + "SELECT a,b FROM t " + "WITH NO DATA", new CreateTableAsSelect(table, querySelectColumns, false, properties, false, Optional.of(ImmutableList.of(new Identifier("x"), new Identifier("y"))), Optional.of("test")));
    assertStatement("CREATE TABLE foo(x,y) COMMENT 'test'" + "WITH ( \"string\" = 'bar', \"long\" = 42, computed = 'ban' || 'ana', a = ARRAY[ 'v1', 'v2' ] ) " + "AS " + "SELECT a,b FROM t " + "WITH NO DATA", new CreateTableAsSelect(table, querySelectColumns, false, properties, false, Optional.of(ImmutableList.of(new Identifier("x"), new Identifier("y"))), Optional.of("test")));
}
Also used : Identifier(com.facebook.presto.sql.tree.Identifier) QueryUtil.quotedIdentifier(com.facebook.presto.sql.QueryUtil.quotedIdentifier) Query(com.facebook.presto.sql.tree.Query) QueryUtil.simpleQuery(com.facebook.presto.sql.QueryUtil.simpleQuery) WithQuery(com.facebook.presto.sql.tree.WithQuery) StringLiteral(com.facebook.presto.sql.tree.StringLiteral) LongLiteral(com.facebook.presto.sql.tree.LongLiteral) QualifiedName(com.facebook.presto.sql.tree.QualifiedName) CreateTableAsSelect(com.facebook.presto.sql.tree.CreateTableAsSelect) ArrayConstructor(com.facebook.presto.sql.tree.ArrayConstructor) AllColumns(com.facebook.presto.sql.tree.AllColumns) FunctionCall(com.facebook.presto.sql.tree.FunctionCall) Property(com.facebook.presto.sql.tree.Property) Test(org.testng.annotations.Test)

Example 5 with QualifiedName

use of com.facebook.presto.sql.tree.QualifiedName in project presto by prestodb.

the class TestSqlParser method testShowStatsForQuery.

@Test
public void testShowStatsForQuery() {
    final String[] tableNames = { "t", "s.t", "c.s.t" };
    for (String fullName : tableNames) {
        QualifiedName qualifiedName = makeQualifiedName(fullName);
        assertStatement(format("SHOW STATS FOR (SELECT * FROM %s)", qualifiedName), createShowStats(qualifiedName, ImmutableList.of(new AllColumns()), Optional.empty()));
        assertStatement(format("SHOW STATS FOR (SELECT * FROM %s WHERE field > 0)", qualifiedName), createShowStats(qualifiedName, ImmutableList.of(new AllColumns()), Optional.of(new ComparisonExpression(GREATER_THAN, new Identifier("field"), new LongLiteral("0")))));
        assertStatement(format("SHOW STATS FOR (SELECT * FROM %s WHERE field > 0 or field < 0)", qualifiedName), createShowStats(qualifiedName, ImmutableList.of(new AllColumns()), Optional.of(new LogicalBinaryExpression(LogicalBinaryExpression.Operator.OR, new ComparisonExpression(GREATER_THAN, new Identifier("field"), new LongLiteral("0")), new ComparisonExpression(LESS_THAN, new Identifier("field"), new LongLiteral("0"))))));
    }
}
Also used : LogicalBinaryExpression(com.facebook.presto.sql.tree.LogicalBinaryExpression) QuantifiedComparisonExpression(com.facebook.presto.sql.tree.QuantifiedComparisonExpression) ComparisonExpression(com.facebook.presto.sql.tree.ComparisonExpression) Identifier(com.facebook.presto.sql.tree.Identifier) QueryUtil.quotedIdentifier(com.facebook.presto.sql.QueryUtil.quotedIdentifier) LongLiteral(com.facebook.presto.sql.tree.LongLiteral) QualifiedName(com.facebook.presto.sql.tree.QualifiedName) AllColumns(com.facebook.presto.sql.tree.AllColumns) Test(org.testng.annotations.Test)

Aggregations

QualifiedName (com.facebook.presto.sql.tree.QualifiedName)17 Identifier (com.facebook.presto.sql.tree.Identifier)7 Test (org.testng.annotations.Test)7 LongLiteral (com.facebook.presto.sql.tree.LongLiteral)5 QueryUtil.quotedIdentifier (com.facebook.presto.sql.QueryUtil.quotedIdentifier)4 AllColumns (com.facebook.presto.sql.tree.AllColumns)4 ComparisonExpression (com.facebook.presto.sql.tree.ComparisonExpression)4 CreateTableAsSelect (com.facebook.presto.sql.tree.CreateTableAsSelect)4 Query (com.facebook.presto.sql.tree.Query)4 CreateTable (com.facebook.presto.sql.tree.CreateTable)3 DropTable (com.facebook.presto.sql.tree.DropTable)3 FunctionCall (com.facebook.presto.sql.tree.FunctionCall)3 Table (com.facebook.presto.sql.tree.Table)3 ArrayList (java.util.ArrayList)3 QueryUtil.simpleQuery (com.facebook.presto.sql.QueryUtil.simpleQuery)2 ArrayConstructor (com.facebook.presto.sql.tree.ArrayConstructor)2 DereferenceExpression (com.facebook.presto.sql.tree.DereferenceExpression)2 Expression (com.facebook.presto.sql.tree.Expression)2 InPredicate (com.facebook.presto.sql.tree.InPredicate)2 Insert (com.facebook.presto.sql.tree.Insert)2