diff --git a/presto-main/src/main/java/com/facebook/presto/metadata/PolymorphicScalarFunction.java b/presto-main/src/main/java/com/facebook/presto/metadata/PolymorphicScalarFunction.java index d8ef8cb8c95d..08d92bf5bf52 100644 --- a/presto-main/src/main/java/com/facebook/presto/metadata/PolymorphicScalarFunction.java +++ b/presto-main/src/main/java/com/facebook/presto/metadata/PolymorphicScalarFunction.java @@ -34,7 +34,6 @@ import static com.facebook.presto.operator.scalar.ScalarFunctionImplementation.NullConvention.USE_BOXED_TYPE; import static com.facebook.presto.operator.scalar.ScalarFunctionImplementation.NullConvention.USE_NULL_FLAG; import static com.facebook.presto.type.TypeUtils.resolveTypes; -import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkState; import static java.util.Collections.emptyList; import static java.util.Objects.requireNonNull; @@ -186,7 +185,6 @@ private static Class getNullAwareContainerType(Class clazz, boolean nullab if (nullable) { return Primitives.wrap(clazz); } - checkArgument(clazz != void.class); return clazz; } } diff --git a/presto-main/src/main/java/com/facebook/presto/operator/aggregation/AbstractMinMaxAggregationFunction.java b/presto-main/src/main/java/com/facebook/presto/operator/aggregation/AbstractMinMaxAggregationFunction.java index 996d99b92586..722b3697ee9a 100644 --- a/presto-main/src/main/java/com/facebook/presto/operator/aggregation/AbstractMinMaxAggregationFunction.java +++ b/presto-main/src/main/java/com/facebook/presto/operator/aggregation/AbstractMinMaxAggregationFunction.java @@ -55,20 +55,17 @@ public abstract class AbstractMinMaxAggregationFunction extends SqlAggregationFunction { - private static final MethodHandle UNKNOWN_INPUT_FUNCTION = methodHandle(AbstractMinMaxAggregationFunction.class, "input", AccumulatorState.class, Block.class, int.class); private static final MethodHandle LONG_INPUT_FUNCTION = methodHandle(AbstractMinMaxAggregationFunction.class, "input", MethodHandle.class, NullableLongState.class, long.class); private static final MethodHandle DOUBLE_INPUT_FUNCTION = methodHandle(AbstractMinMaxAggregationFunction.class, "input", MethodHandle.class, NullableDoubleState.class, double.class); private static final MethodHandle BOOLEAN_INPUT_FUNCTION = methodHandle(AbstractMinMaxAggregationFunction.class, "input", MethodHandle.class, NullableBooleanState.class, boolean.class); private static final MethodHandle BLOCK_POSITION_MIN_INPUT_FUNCTION = methodHandle(AbstractMinMaxAggregationFunction.class, "minInput", Type.class, BlockPositionState.class, Block.class, int.class); private static final MethodHandle BLOCK_POSITION_MAX_INPUT_FUNCTION = methodHandle(AbstractMinMaxAggregationFunction.class, "maxInput", Type.class, BlockPositionState.class, Block.class, int.class); - private static final MethodHandle UNKNOWN_OUTPUT_FUNCTION = methodHandle(AbstractMinMaxAggregationFunction.class, "writeNull", AccumulatorState.class, BlockBuilder.class); private static final MethodHandle LONG_OUTPUT_FUNCTION = methodHandle(NullableLongState.class, "write", Type.class, NullableLongState.class, BlockBuilder.class); private static final MethodHandle DOUBLE_OUTPUT_FUNCTION = methodHandle(NullableDoubleState.class, "write", Type.class, NullableDoubleState.class, BlockBuilder.class); private static final MethodHandle BOOLEAN_OUTPUT_FUNCTION = methodHandle(NullableBooleanState.class, "write", Type.class, NullableBooleanState.class, BlockBuilder.class); private static final MethodHandle BLOCK_POSITION_OUTPUT_FUNCTION = methodHandle(BlockPositionState.class, "write", Type.class, BlockPositionState.class, BlockBuilder.class); - private static final MethodHandle UNKNOWN_COMBINE_FUNCTION = methodHandle(AbstractMinMaxAggregationFunction.class, "combine", AccumulatorState.class, AccumulatorState.class); private static final MethodHandle LONG_COMBINE_FUNCTION = methodHandle(AbstractMinMaxAggregationFunction.class, "combine", MethodHandle.class, NullableLongState.class, NullableLongState.class); private static final MethodHandle DOUBLE_COMBINE_FUNCTION = methodHandle(AbstractMinMaxAggregationFunction.class, "combine", MethodHandle.class, NullableDoubleState.class, NullableDoubleState.class); private static final MethodHandle BOOLEAN_COMBINE_FUNCTION = methodHandle(AbstractMinMaxAggregationFunction.class, "combine", MethodHandle.class, NullableBooleanState.class, NullableBooleanState.class); @@ -109,14 +106,7 @@ protected InternalAggregationFunction generateAggregation(Type type, MethodHandl Class stateInterface; AccumulatorStateSerializer stateSerializer; - if (type.getJavaType() == void.class) { - stateInterface = AccumulatorState.class; - stateSerializer = StateCompiler.generateStateSerializer(stateInterface, classLoader); - inputFunction = UNKNOWN_INPUT_FUNCTION; - combineFunction = UNKNOWN_COMBINE_FUNCTION; - outputFunction = UNKNOWN_OUTPUT_FUNCTION; - } - else if (type.getJavaType() == long.class) { + if (type.getJavaType() == long.class) { stateInterface = NullableLongState.class; stateSerializer = StateCompiler.generateStateSerializer(stateInterface, classLoader); inputFunction = LONG_INPUT_FUNCTION.bindTo(compareMethodHandle); @@ -166,7 +156,7 @@ else if (type.getJavaType() == boolean.class) { private static List createParameterMetadata(Type type) { - if (type.getJavaType().isPrimitive() && type.getJavaType() != void.class) { + if (type.getJavaType().isPrimitive()) { return ImmutableList.of( new ParameterMetadata(STATE), new ParameterMetadata(INPUT_CHANNEL, type)); @@ -179,11 +169,6 @@ private static List createParameterMetadata(Type type) } } - public static void input(AccumulatorState state, Block block, int position) - { - // Do nothing - } - public static void input(MethodHandle methodHandle, NullableDoubleState state, double value) { compareAndUpdateState(methodHandle, state, value); @@ -215,11 +200,6 @@ public static void maxInput(Type type, BlockPositionState state, Block block, in } } - public static void combine(AccumulatorState state, AccumulatorState otherState) - { - // Do nothing - } - public static void combine(MethodHandle methodHandle, NullableLongState state, NullableLongState otherState) { compareAndUpdateState(methodHandle, state, otherState.getLong()); @@ -251,11 +231,6 @@ public static void maxCombine(Type type, BlockPositionState state, BlockPosition } } - public static void writeNull(AccumulatorState state, BlockBuilder out) - { - out.appendNull(); - } - private static void compareAndUpdateState(MethodHandle methodHandle, NullableLongState state, long value) { if (state.isNull()) { diff --git a/presto-main/src/main/java/com/facebook/presto/operator/aggregation/minmaxby/BlockUnknownState.java b/presto-main/src/main/java/com/facebook/presto/operator/aggregation/minmaxby/BlockUnknownState.java deleted file mode 100644 index 149fcdf2bc2d..000000000000 --- a/presto-main/src/main/java/com/facebook/presto/operator/aggregation/minmaxby/BlockUnknownState.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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 com.facebook.presto.operator.aggregation.minmaxby; - -import com.facebook.presto.spi.block.Block; - -public interface BlockUnknownState - extends TwoNullableValueState -{ - Block getFirst(); - - void setFirst(Block first); - - // Second state is void and will always be null -} diff --git a/presto-main/src/main/java/com/facebook/presto/operator/aggregation/minmaxby/BooleanUnknownState.java b/presto-main/src/main/java/com/facebook/presto/operator/aggregation/minmaxby/BooleanUnknownState.java deleted file mode 100644 index c2b095032eda..000000000000 --- a/presto-main/src/main/java/com/facebook/presto/operator/aggregation/minmaxby/BooleanUnknownState.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * 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 com.facebook.presto.operator.aggregation.minmaxby; - -public interface BooleanUnknownState - extends TwoNullableValueState -{ - boolean getFirst(); - - void setFirst(boolean first); - - // Second state is void and will always be null -} diff --git a/presto-main/src/main/java/com/facebook/presto/operator/aggregation/minmaxby/DoubleUnknownState.java b/presto-main/src/main/java/com/facebook/presto/operator/aggregation/minmaxby/DoubleUnknownState.java deleted file mode 100644 index 348359c2ebf3..000000000000 --- a/presto-main/src/main/java/com/facebook/presto/operator/aggregation/minmaxby/DoubleUnknownState.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * 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 com.facebook.presto.operator.aggregation.minmaxby; - -public interface DoubleUnknownState - extends TwoNullableValueState -{ - double getFirst(); - - void setFirst(double first); - - // Second state is void and will always be null -} diff --git a/presto-main/src/main/java/com/facebook/presto/operator/aggregation/minmaxby/LongUnknownState.java b/presto-main/src/main/java/com/facebook/presto/operator/aggregation/minmaxby/LongUnknownState.java deleted file mode 100644 index e1a613148bfb..000000000000 --- a/presto-main/src/main/java/com/facebook/presto/operator/aggregation/minmaxby/LongUnknownState.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * 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 com.facebook.presto.operator.aggregation.minmaxby; - -public interface LongUnknownState - extends TwoNullableValueState -{ - long getFirst(); - - void setFirst(long first); - - // Second state is void and will always be null -} diff --git a/presto-main/src/main/java/com/facebook/presto/operator/aggregation/minmaxby/SliceUnknownState.java b/presto-main/src/main/java/com/facebook/presto/operator/aggregation/minmaxby/SliceUnknownState.java deleted file mode 100644 index 373a2894bc39..000000000000 --- a/presto-main/src/main/java/com/facebook/presto/operator/aggregation/minmaxby/SliceUnknownState.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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 com.facebook.presto.operator.aggregation.minmaxby; - -import io.airlift.slice.Slice; - -public interface SliceUnknownState - extends TwoNullableValueState -{ - Slice getFirst(); - - void setFirst(Slice first); - - // Second state is void and will always be null -} diff --git a/presto-main/src/main/java/com/facebook/presto/operator/aggregation/minmaxby/TwoNullableValueStateMapping.java b/presto-main/src/main/java/com/facebook/presto/operator/aggregation/minmaxby/TwoNullableValueStateMapping.java index 37d401433cfe..3cc061402bd0 100644 --- a/presto-main/src/main/java/com/facebook/presto/operator/aggregation/minmaxby/TwoNullableValueStateMapping.java +++ b/presto-main/src/main/java/com/facebook/presto/operator/aggregation/minmaxby/TwoNullableValueStateMapping.java @@ -40,37 +40,26 @@ private TwoNullableValueStateMapping() {} .put(ImmutableList.of(boolean.class, double.class), BooleanDoubleState.class) .put(ImmutableList.of(boolean.class, long.class), BooleanLongState.class) .put(ImmutableList.of(boolean.class, Slice.class), BooleanAndBlockPositionValueState.class) - .put(ImmutableList.of(boolean.class, void.class), BooleanUnknownState.class) .put(ImmutableList.of(double.class, boolean.class), DoubleBooleanState.class) .put(ImmutableList.of(double.class, Block.class), DoubleAndBlockPositionValueState.class) .put(ImmutableList.of(double.class, double.class), DoubleDoubleState.class) .put(ImmutableList.of(double.class, long.class), DoubleLongState.class) .put(ImmutableList.of(double.class, Slice.class), DoubleAndBlockPositionValueState.class) - .put(ImmutableList.of(double.class, void.class), DoubleUnknownState.class) .put(ImmutableList.of(long.class, Block.class), LongAndBlockPositionValueState.class) .put(ImmutableList.of(long.class, boolean.class), LongBooleanState.class) .put(ImmutableList.of(long.class, double.class), LongDoubleState.class) .put(ImmutableList.of(long.class, long.class), LongLongState.class) .put(ImmutableList.of(long.class, Slice.class), LongAndBlockPositionValueState.class) - .put(ImmutableList.of(long.class, void.class), LongUnknownState.class) .put(ImmutableList.of(Slice.class, boolean.class), SliceBooleanState.class) .put(ImmutableList.of(Slice.class, Block.class), SliceAndBlockPositionValueState.class) .put(ImmutableList.of(Slice.class, double.class), SliceDoubleState.class) .put(ImmutableList.of(Slice.class, long.class), SliceLongState.class) .put(ImmutableList.of(Slice.class, Slice.class), SliceAndBlockPositionValueState.class) - .put(ImmutableList.of(Slice.class, void.class), SliceUnknownState.class) .put(ImmutableList.of(Block.class, boolean.class), BlockBooleanState.class) .put(ImmutableList.of(Block.class, Block.class), BlockAndBlockPositionValueState.class) .put(ImmutableList.of(Block.class, double.class), BlockDoubleState.class) .put(ImmutableList.of(Block.class, long.class), BlockLongState.class) .put(ImmutableList.of(Block.class, Slice.class), BlockAndBlockPositionValueState.class) - .put(ImmutableList.of(Block.class, void.class), BlockUnknownState.class) - .put(ImmutableList.of(void.class, void.class), TwoNullableValueState.class) - .put(ImmutableList.of(void.class, Block.class), KeyAndBlockPositionValueState.class) // no need to specify the first field if it is unknown - .put(ImmutableList.of(void.class, boolean.class), UnknownBooleanState.class) - .put(ImmutableList.of(void.class, double.class), UnknownDoubleState.class) - .put(ImmutableList.of(void.class, long.class), UnknownLongState.class) - .put(ImmutableList.of(void.class, Slice.class), KeyAndBlockPositionValueState.class) // no need to specify the first field if it is unknown .build(); } @@ -105,9 +94,6 @@ public static AccumulatorStateSerializer getStateSerializer(Type firstType, T if (firstJavaType == Block.class) { return new BlockAndBlockPositionStateSerializer(firstType, secondType); } - if (firstJavaType == void.class) { - return new UnknownAndBlockPositionStateSerializer(firstType, secondType); - } throw new IllegalArgumentException(format("Unsupported state type combination: (%s, %s)", firstJavaType.getName(), secondJavaType.getName())); } } diff --git a/presto-main/src/main/java/com/facebook/presto/operator/aggregation/minmaxby/UnknownAndBlockPositionStateSerializer.java b/presto-main/src/main/java/com/facebook/presto/operator/aggregation/minmaxby/UnknownAndBlockPositionStateSerializer.java deleted file mode 100644 index 955907faa599..000000000000 --- a/presto-main/src/main/java/com/facebook/presto/operator/aggregation/minmaxby/UnknownAndBlockPositionStateSerializer.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * 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 com.facebook.presto.operator.aggregation.minmaxby; - -import com.facebook.presto.spi.block.Block; -import com.facebook.presto.spi.block.BlockBuilder; -import com.facebook.presto.spi.type.Type; - -class UnknownAndBlockPositionStateSerializer - extends KeyAndBlockPositionValueStateSerializer -{ - UnknownAndBlockPositionStateSerializer(Type firstType, Type secondType) - { - super(firstType, secondType); - } - - @Override - void readFirstField(Block block, int position, KeyAndBlockPositionValueState state) - { - throw new UnsupportedOperationException("UnknownAndBlockPositionStateSerializer does not support readFirstField"); - } - - @Override - void writeFirstField(BlockBuilder out, KeyAndBlockPositionValueState state) - { - throw new UnsupportedOperationException("UnknownAndBlockPositionStateSerializer does not support writeFirstField"); - } -} diff --git a/presto-main/src/main/java/com/facebook/presto/operator/aggregation/minmaxby/UnknownBooleanState.java b/presto-main/src/main/java/com/facebook/presto/operator/aggregation/minmaxby/UnknownBooleanState.java deleted file mode 100644 index 0c303e4959da..000000000000 --- a/presto-main/src/main/java/com/facebook/presto/operator/aggregation/minmaxby/UnknownBooleanState.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * 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 com.facebook.presto.operator.aggregation.minmaxby; - -public interface UnknownBooleanState - extends TwoNullableValueState -{ - // First state is void and will always be null - - boolean getSecond(); - - void setSecond(boolean second); -} diff --git a/presto-main/src/main/java/com/facebook/presto/operator/aggregation/minmaxby/UnknownDoubleState.java b/presto-main/src/main/java/com/facebook/presto/operator/aggregation/minmaxby/UnknownDoubleState.java deleted file mode 100644 index e20a0d253e72..000000000000 --- a/presto-main/src/main/java/com/facebook/presto/operator/aggregation/minmaxby/UnknownDoubleState.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * 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 com.facebook.presto.operator.aggregation.minmaxby; - -public interface UnknownDoubleState - extends TwoNullableValueState -{ - // First state is void and will always be null - - double getSecond(); - - void setSecond(double second); -} diff --git a/presto-main/src/main/java/com/facebook/presto/operator/aggregation/minmaxby/UnknownLongState.java b/presto-main/src/main/java/com/facebook/presto/operator/aggregation/minmaxby/UnknownLongState.java deleted file mode 100644 index 0e18dbbc081f..000000000000 --- a/presto-main/src/main/java/com/facebook/presto/operator/aggregation/minmaxby/UnknownLongState.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * 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 com.facebook.presto.operator.aggregation.minmaxby; - -public interface UnknownLongState - extends TwoNullableValueState -{ - // First state is void and will always be null - - long getSecond(); - - void setSecond(long second); -} diff --git a/presto-main/src/main/java/com/facebook/presto/operator/scalar/ArrayConstructor.java b/presto-main/src/main/java/com/facebook/presto/operator/scalar/ArrayConstructor.java index 97e2d4c19a2f..067e5829d640 100644 --- a/presto-main/src/main/java/com/facebook/presto/operator/scalar/ArrayConstructor.java +++ b/presto-main/src/main/java/com/facebook/presto/operator/scalar/ArrayConstructor.java @@ -167,17 +167,12 @@ private static Class generateArrayConstructor(List> stackTypes, Type body.append(createBlockBuilder); for (int i = 0; i < stackTypes.size(); i++) { - if (elementType.getJavaType() == void.class) { - body.append(blockBuilderVariable.invoke("appendNull", BlockBuilder.class)); - } - else { - Variable argument = scope.getVariable("arg" + i); - IfStatement ifStatement = new IfStatement() - .condition(equal(argument, constantNull(stackTypes.get(i)))) - .ifTrue(blockBuilderVariable.invoke("appendNull", BlockBuilder.class).pop()) - .ifFalse(constantType(binder, elementType).writeValue(blockBuilderVariable, argument.cast(elementType.getJavaType()))); - body.append(ifStatement); - } + Variable argument = scope.getVariable("arg" + i); + IfStatement ifStatement = new IfStatement() + .condition(equal(argument, constantNull(stackTypes.get(i)))) + .ifTrue(blockBuilderVariable.invoke("appendNull", BlockBuilder.class).pop()) + .ifFalse(constantType(binder, elementType).writeValue(blockBuilderVariable, argument.cast(elementType.getJavaType()))); + body.append(ifStatement); } body.append(blockBuilderVariable.invoke("build", Block.class).ret()); diff --git a/presto-main/src/main/java/com/facebook/presto/operator/scalar/ArrayContains.java b/presto-main/src/main/java/com/facebook/presto/operator/scalar/ArrayContains.java index 28df3028d9ff..6fb0062334e0 100644 --- a/presto-main/src/main/java/com/facebook/presto/operator/scalar/ArrayContains.java +++ b/presto-main/src/main/java/com/facebook/presto/operator/scalar/ArrayContains.java @@ -35,13 +35,6 @@ public final class ArrayContains { private ArrayContains() {} - @SqlType(StandardTypes.BOOLEAN) - @SqlNullable - public static Boolean arrayWithUnknownType(@SqlType("array(unknown)") Block arrayBlock, @SqlNullable @SqlType("unknown") Void value) - { - return null; - } - @TypeParameter("T") @SqlType(StandardTypes.BOOLEAN) @SqlNullable diff --git a/presto-main/src/main/java/com/facebook/presto/operator/scalar/ArrayElementAtFunction.java b/presto-main/src/main/java/com/facebook/presto/operator/scalar/ArrayElementAtFunction.java index dabc7b82dd92..55274614e45c 100644 --- a/presto-main/src/main/java/com/facebook/presto/operator/scalar/ArrayElementAtFunction.java +++ b/presto-main/src/main/java/com/facebook/presto/operator/scalar/ArrayElementAtFunction.java @@ -32,15 +32,6 @@ public final class ArrayElementAtFunction { private ArrayElementAtFunction() {} - @TypeParameter("E") - @SqlNullable - @SqlType("E") - public static Void voidElementAt(@SqlType("array(E)") Block array, @SqlType("bigint") long index) - { - checkedIndexToBlockPosition(array, index); - return null; - } - @TypeParameter("E") @SqlNullable @SqlType("E") diff --git a/presto-main/src/main/java/com/facebook/presto/operator/scalar/ArrayFilterFunction.java b/presto-main/src/main/java/com/facebook/presto/operator/scalar/ArrayFilterFunction.java index 3af0bdf92cc6..e2507d9cd0e9 100644 --- a/presto-main/src/main/java/com/facebook/presto/operator/scalar/ArrayFilterFunction.java +++ b/presto-main/src/main/java/com/facebook/presto/operator/scalar/ArrayFilterFunction.java @@ -152,25 +152,6 @@ public static Block filterBlock( return resultBuilder.build(); } - @TypeParameter("T") - @TypeParameterSpecialization(name = "T", nativeContainerType = void.class) - @SqlType("array(T)") - public static Block filterVoid( - @TypeParameter("T") Type elementType, - @SqlType("array(T)") Block arrayBlock, - @SqlType("function(T, boolean)") FilterVoidLambda function) - { - int positionCount = arrayBlock.getPositionCount(); - BlockBuilder resultBuilder = elementType.createBlockBuilder(null, positionCount); - for (int position = 0; position < positionCount; position++) { - Boolean keep = function.apply(null); - if (TRUE.equals(keep)) { - resultBuilder.appendNull(); - } - } - return resultBuilder.build(); - } - @FunctionalInterface public interface FilterLongLambda extends LambdaFunctionInterface diff --git a/presto-main/src/main/java/com/facebook/presto/operator/scalar/ArrayMaxFunction.java b/presto-main/src/main/java/com/facebook/presto/operator/scalar/ArrayMaxFunction.java index 14018ad53acf..5dff5eb634ca 100644 --- a/presto-main/src/main/java/com/facebook/presto/operator/scalar/ArrayMaxFunction.java +++ b/presto-main/src/main/java/com/facebook/presto/operator/scalar/ArrayMaxFunction.java @@ -39,16 +39,6 @@ public final class ArrayMaxFunction { private ArrayMaxFunction() {} - @TypeParameter("T") - @SqlType("T") - @SqlNullable - public static Void arrayWithUnknownType( - @OperatorDependency(operator = GREATER_THAN, returnType = StandardTypes.BOOLEAN, argumentTypes = {"T", "T"}) MethodHandle compareMethodHandle, - @SqlType("array(T)") Block block) - { - return null; - } - @TypeParameter("T") @SqlType("T") @SqlNullable diff --git a/presto-main/src/main/java/com/facebook/presto/operator/scalar/ArrayMinFunction.java b/presto-main/src/main/java/com/facebook/presto/operator/scalar/ArrayMinFunction.java index f606d640c3f9..e3bb12be369c 100644 --- a/presto-main/src/main/java/com/facebook/presto/operator/scalar/ArrayMinFunction.java +++ b/presto-main/src/main/java/com/facebook/presto/operator/scalar/ArrayMinFunction.java @@ -39,16 +39,6 @@ public final class ArrayMinFunction { private ArrayMinFunction() {} - @TypeParameter("T") - @SqlType("T") - @SqlNullable - public static Void arrayWithUnknownType( - @OperatorDependency(operator = LESS_THAN, returnType = StandardTypes.BOOLEAN, argumentTypes = {"T", "T"}) MethodHandle compareMethodHandle, - @SqlType("array(T)") Block block) - { - return null; - } - @TypeParameter("T") @SqlType("T") @SqlNullable diff --git a/presto-main/src/main/java/com/facebook/presto/operator/scalar/ArrayPositionFunction.java b/presto-main/src/main/java/com/facebook/presto/operator/scalar/ArrayPositionFunction.java index 38b4fba2e170..94fa7f955589 100644 --- a/presto-main/src/main/java/com/facebook/presto/operator/scalar/ArrayPositionFunction.java +++ b/presto-main/src/main/java/com/facebook/presto/operator/scalar/ArrayPositionFunction.java @@ -17,7 +17,6 @@ import com.facebook.presto.spi.function.Description; import com.facebook.presto.spi.function.OperatorDependency; import com.facebook.presto.spi.function.ScalarFunction; -import com.facebook.presto.spi.function.SqlNullable; import com.facebook.presto.spi.function.SqlType; import com.facebook.presto.spi.function.TypeParameter; import com.facebook.presto.spi.type.StandardTypes; @@ -159,11 +158,4 @@ public static long arrayPosition( } return 0; } - - @SqlType(StandardTypes.BIGINT) - @SqlNullable - public static Long arrayPosition(@SqlType("array(unknown)") Block array, @SqlNullable @SqlType("unknown") Void element) - { - return null; - } } diff --git a/presto-main/src/main/java/com/facebook/presto/operator/scalar/ArraySubscriptOperator.java b/presto-main/src/main/java/com/facebook/presto/operator/scalar/ArraySubscriptOperator.java index c4c68b12ec98..8de352cadb8c 100644 --- a/presto-main/src/main/java/com/facebook/presto/operator/scalar/ArraySubscriptOperator.java +++ b/presto-main/src/main/java/com/facebook/presto/operator/scalar/ArraySubscriptOperator.java @@ -42,7 +42,6 @@ public class ArraySubscriptOperator { public static final ArraySubscriptOperator ARRAY_SUBSCRIPT = new ArraySubscriptOperator(); - private static final MethodHandle METHOD_HANDLE_UNKNOWN = methodHandle(ArraySubscriptOperator.class, "arrayWithUnknownType", Type.class, Block.class, long.class); private static final MethodHandle METHOD_HANDLE_BOOLEAN = methodHandle(ArraySubscriptOperator.class, "booleanSubscript", Type.class, Block.class, long.class); private static final MethodHandle METHOD_HANDLE_LONG = methodHandle(ArraySubscriptOperator.class, "longSubscript", Type.class, Block.class, long.class); private static final MethodHandle METHOD_HANDLE_DOUBLE = methodHandle(ArraySubscriptOperator.class, "doubleSubscript", Type.class, Block.class, long.class); @@ -65,10 +64,7 @@ public ScalarFunctionImplementation specialize(BoundVariables boundVariables, in Type elementType = boundVariables.getTypeVariable("E"); MethodHandle methodHandle; - if (elementType.getJavaType() == void.class) { - methodHandle = METHOD_HANDLE_UNKNOWN; - } - else if (elementType.getJavaType() == boolean.class) { + if (elementType.getJavaType() == boolean.class) { methodHandle = METHOD_HANDLE_BOOLEAN; } else if (elementType.getJavaType() == long.class) { @@ -94,12 +90,6 @@ else if (elementType.getJavaType() == Slice.class) { isDeterministic()); } - @UsedByGeneratedCode - public static void arrayWithUnknownType(Type elementType, Block array, long index) - { - checkIndex(array, index); - } - @UsedByGeneratedCode public static Long longSubscript(Type elementType, Block array, long index) { diff --git a/presto-main/src/main/java/com/facebook/presto/operator/scalar/CastFromUnknownOperator.java b/presto-main/src/main/java/com/facebook/presto/operator/scalar/CastFromUnknownOperator.java index fee26165b60a..fe9362e317c3 100644 --- a/presto-main/src/main/java/com/facebook/presto/operator/scalar/CastFromUnknownOperator.java +++ b/presto-main/src/main/java/com/facebook/presto/operator/scalar/CastFromUnknownOperator.java @@ -20,13 +20,12 @@ import com.facebook.presto.spi.type.Type; import com.facebook.presto.spi.type.TypeManager; import com.google.common.collect.ImmutableList; -import io.airlift.slice.Slice; import java.lang.invoke.MethodHandle; import static com.facebook.presto.metadata.Signature.typeVariable; import static com.facebook.presto.operator.scalar.ScalarFunctionImplementation.ArgumentProperty.valueTypeArgumentProperty; -import static com.facebook.presto.operator.scalar.ScalarFunctionImplementation.NullConvention.USE_BOXED_TYPE; +import static com.facebook.presto.operator.scalar.ScalarFunctionImplementation.NullConvention.RETURN_NULL_ON_NULL; import static com.facebook.presto.spi.function.OperatorType.CAST; import static com.facebook.presto.spi.type.TypeSignature.parseTypeSignature; import static com.facebook.presto.util.Reflection.methodHandle; @@ -35,11 +34,7 @@ public final class CastFromUnknownOperator extends SqlOperator { public static final CastFromUnknownOperator CAST_FROM_UNKNOWN = new CastFromUnknownOperator(); - private static final MethodHandle METHOD_HANDLE_LONG = methodHandle(CastFromUnknownOperator.class, "toLong", Void.class); - private static final MethodHandle METHOD_HANDLE_DOUBLE = methodHandle(CastFromUnknownOperator.class, "toDouble", Void.class); - private static final MethodHandle METHOD_HANDLE_BOOLEAN = methodHandle(CastFromUnknownOperator.class, "toBoolean", Void.class); - private static final MethodHandle METHOD_HANDLE_SLICE = methodHandle(CastFromUnknownOperator.class, "toSlice", Void.class); - private static final MethodHandle METHOD_HANDLE_OBJECT = methodHandle(CastFromUnknownOperator.class, "toObject", Void.class); + private static final MethodHandle METHOD_HANDLE_NON_NULL = methodHandle(CastFromUnknownOperator.class, "handleNonNull", boolean.class); public CastFromUnknownOperator() { @@ -56,56 +51,17 @@ public ScalarFunctionImplementation specialize( FunctionRegistry functionRegistry) { Type toType = boundVariables.getTypeVariable("E"); - MethodHandle methodHandle; - if (toType.getJavaType() == long.class) { - methodHandle = METHOD_HANDLE_LONG; - } - else if (toType.getJavaType() == double.class) { - methodHandle = METHOD_HANDLE_DOUBLE; - } - else if (toType.getJavaType() == boolean.class) { - methodHandle = METHOD_HANDLE_BOOLEAN; - } - else if (toType.getJavaType() == Slice.class) { - methodHandle = METHOD_HANDLE_SLICE; - } - else { - methodHandle = METHOD_HANDLE_OBJECT.asType(METHOD_HANDLE_OBJECT.type().changeReturnType(toType.getJavaType())); - } + MethodHandle methodHandle = METHOD_HANDLE_NON_NULL.asType(METHOD_HANDLE_NON_NULL.type().changeReturnType(toType.getJavaType())); return new ScalarFunctionImplementation( - true, - ImmutableList.of(valueTypeArgumentProperty(USE_BOXED_TYPE)), + false, + ImmutableList.of(valueTypeArgumentProperty(RETURN_NULL_ON_NULL)), methodHandle, isDeterministic()); } @UsedByGeneratedCode - public static Long toLong(Void arg) + public static Object handleNonNull(boolean arg) { - return null; - } - - @UsedByGeneratedCode - public static Double toDouble(Void arg) - { - return null; - } - - @UsedByGeneratedCode - public static Boolean toBoolean(Void arg) - { - return null; - } - - @UsedByGeneratedCode - public static Slice toSlice(Void arg) - { - return null; - } - - @UsedByGeneratedCode - public static Object toObject(Void arg) - { - return null; + throw new IllegalArgumentException("value of unknown type should always be null"); } } diff --git a/presto-main/src/main/java/com/facebook/presto/operator/scalar/FailureFunction.java b/presto-main/src/main/java/com/facebook/presto/operator/scalar/FailureFunction.java index 238800285000..4d84e45a346b 100644 --- a/presto-main/src/main/java/com/facebook/presto/operator/scalar/FailureFunction.java +++ b/presto-main/src/main/java/com/facebook/presto/operator/scalar/FailureFunction.java @@ -33,7 +33,7 @@ private FailureFunction() {} @Description("Decodes json to an exception and throws it") @ScalarFunction(value = "fail", hidden = true) @SqlType("unknown") - public static void failWithException(@SqlType(StandardTypes.JSON) Slice failureInfoSlice) + public static boolean failWithException(@SqlType(StandardTypes.JSON) Slice failureInfoSlice) { FailureInfo failureInfo = JSON_CODEC.fromJson(failureInfoSlice.getBytes()); // wrap the failure in a new exception to append the current stack trace @@ -43,7 +43,7 @@ public static void failWithException(@SqlType(StandardTypes.JSON) Slice failureI @Description("Throws an exception with a given message") @ScalarFunction(value = "fail", hidden = true) @SqlType("unknown") - public static void fail(@SqlType(StandardTypes.VARCHAR) Slice message) + public static boolean fail(@SqlType(StandardTypes.VARCHAR) Slice message) { throw new PrestoException(StandardErrorCode.GENERIC_USER_ERROR, message.toStringUtf8()); } @@ -51,7 +51,7 @@ public static void fail(@SqlType(StandardTypes.VARCHAR) Slice message) @Description("Throws an exception with a given error code and message") @ScalarFunction(value = "fail", hidden = true) @SqlType("unknown") - public static void fail( + public static boolean fail( @SqlType(StandardTypes.INTEGER) long errorCode, @SqlType(StandardTypes.VARCHAR) Slice message) { diff --git a/presto-main/src/main/java/com/facebook/presto/operator/scalar/MapElementAtFunction.java b/presto-main/src/main/java/com/facebook/presto/operator/scalar/MapElementAtFunction.java index cd0d410f2796..31c69be6cbc9 100644 --- a/presto-main/src/main/java/com/facebook/presto/operator/scalar/MapElementAtFunction.java +++ b/presto-main/src/main/java/com/facebook/presto/operator/scalar/MapElementAtFunction.java @@ -105,14 +105,7 @@ else if (keyType.getJavaType() == Slice.class) { methodHandle = METHOD_HANDLE_OBJECT; } methodHandle = methodHandle.bindTo(keyEqualsMethod).bindTo(keyType).bindTo(valueType); - - // this casting is necessary because otherwise presto byte code generator will generate illegal byte code - if (valueType.getJavaType() == void.class) { - methodHandle = methodHandle.asType(methodHandle.type().changeReturnType(void.class)); - } - else { - methodHandle = methodHandle.asType(methodHandle.type().changeReturnType(Primitives.wrap(valueType.getJavaType()))); - } + methodHandle = methodHandle.asType(methodHandle.type().changeReturnType(Primitives.wrap(valueType.getJavaType()))); return new ScalarFunctionImplementation( true, diff --git a/presto-main/src/main/java/com/facebook/presto/operator/scalar/MapSubscriptOperator.java b/presto-main/src/main/java/com/facebook/presto/operator/scalar/MapSubscriptOperator.java index 34d4af76fc50..2edf06a94efb 100644 --- a/presto-main/src/main/java/com/facebook/presto/operator/scalar/MapSubscriptOperator.java +++ b/presto-main/src/main/java/com/facebook/presto/operator/scalar/MapSubscriptOperator.java @@ -89,14 +89,7 @@ else if (keyType.getJavaType() == Slice.class) { methodHandle = MethodHandles.insertArguments(methodHandle, 0, legacyMissingKey); FunctionInvoker functionInvoker = new FunctionInvoker(functionRegistry); methodHandle = methodHandle.bindTo(functionInvoker).bindTo(keyType).bindTo(valueType); - - // this casting is necessary because otherwise presto byte code generator will generate illegal byte code - if (valueType.getJavaType() == void.class) { - methodHandle = methodHandle.asType(methodHandle.type().changeReturnType(void.class)); - } - else { - methodHandle = methodHandle.asType(methodHandle.type().changeReturnType(Primitives.wrap(valueType.getJavaType()))); - } + methodHandle = methodHandle.asType(methodHandle.type().changeReturnType(Primitives.wrap(valueType.getJavaType()))); return new ScalarFunctionImplementation( true, diff --git a/presto-main/src/main/java/com/facebook/presto/operator/scalar/RepeatFunction.java b/presto-main/src/main/java/com/facebook/presto/operator/scalar/RepeatFunction.java index 22d9222dd12e..5dc6272cad83 100644 --- a/presto-main/src/main/java/com/facebook/presto/operator/scalar/RepeatFunction.java +++ b/presto-main/src/main/java/com/facebook/presto/operator/scalar/RepeatFunction.java @@ -40,7 +40,7 @@ private RepeatFunction() {} @SqlType("array(unknown)") public static Block repeat( - @SqlNullable @SqlType("unknown") Void element, + @SqlNullable @SqlType("unknown") Boolean element, @SqlType(StandardTypes.INTEGER) long count) { checkCondition(element == null, INVALID_FUNCTION_ARGUMENT, "expect null values"); diff --git a/presto-main/src/main/java/com/facebook/presto/operator/scalar/TryCastFunction.java b/presto-main/src/main/java/com/facebook/presto/operator/scalar/TryCastFunction.java index 840fb418c758..4b18339fa093 100644 --- a/presto-main/src/main/java/com/facebook/presto/operator/scalar/TryCastFunction.java +++ b/presto-main/src/main/java/com/facebook/presto/operator/scalar/TryCastFunction.java @@ -28,10 +28,7 @@ import java.util.List; import static com.facebook.presto.metadata.Signature.typeVariable; -import static com.facebook.presto.operator.scalar.ScalarFunctionImplementation.ArgumentProperty.valueTypeArgumentProperty; -import static com.facebook.presto.operator.scalar.ScalarFunctionImplementation.NullConvention.USE_BOXED_TYPE; import static com.facebook.presto.spi.type.TypeSignature.parseTypeSignature; -import static com.facebook.presto.type.UnknownType.UNKNOWN; import static java.lang.invoke.MethodHandles.catchException; import static java.lang.invoke.MethodHandles.constant; import static java.lang.invoke.MethodHandles.dropArguments; @@ -82,21 +79,15 @@ public ScalarFunctionImplementation specialize(BoundVariables boundVariables, in List argumentProperties; MethodHandle tryCastHandle; - if (fromType.equals(UNKNOWN)) { - argumentProperties = ImmutableList.of(valueTypeArgumentProperty(USE_BOXED_TYPE)); - tryCastHandle = dropArguments(constant(returnType, null), 0, Void.class); - } - else { - // the resulting method needs to return a boxed type - Signature signature = functionRegistry.getCoercion(fromType, toType); - ScalarFunctionImplementation implementation = functionRegistry.getScalarFunctionImplementation(signature); - argumentProperties = ImmutableList.of(implementation.getArgumentProperty(0)); - MethodHandle coercion = implementation.getMethodHandle(); - coercion = coercion.asType(methodType(returnType, coercion.type())); + // the resulting method needs to return a boxed type + Signature signature = functionRegistry.getCoercion(fromType, toType); + ScalarFunctionImplementation implementation = functionRegistry.getScalarFunctionImplementation(signature); + argumentProperties = ImmutableList.of(implementation.getArgumentProperty(0)); + MethodHandle coercion = implementation.getMethodHandle(); + coercion = coercion.asType(methodType(returnType, coercion.type())); - MethodHandle exceptionHandler = dropArguments(constant(returnType, null), 0, RuntimeException.class); - tryCastHandle = catchException(coercion, RuntimeException.class, exceptionHandler); - } + MethodHandle exceptionHandler = dropArguments(constant(returnType, null), 0, RuntimeException.class); + tryCastHandle = catchException(coercion, RuntimeException.class, exceptionHandler); return new ScalarFunctionImplementation(true, argumentProperties, tryCastHandle, isDeterministic()); } diff --git a/presto-main/src/main/java/com/facebook/presto/operator/scalar/TryFunction.java b/presto-main/src/main/java/com/facebook/presto/operator/scalar/TryFunction.java index aa632870f46a..87df5165ce67 100644 --- a/presto-main/src/main/java/com/facebook/presto/operator/scalar/TryFunction.java +++ b/presto-main/src/main/java/com/facebook/presto/operator/scalar/TryFunction.java @@ -110,21 +110,6 @@ public static Block tryBlock(@SqlType("function(T)") TryBlockLambda function) } } - @TypeParameter("T") - @TypeParameterSpecialization(name = "T", nativeContainerType = void.class) - @SqlNullable - @SqlType("T") - public static Void tryVoid(@SqlType("function(T)") TryVoidLambda function) - { - try { - return function.apply(); - } - catch (PrestoException e) { - propagateIfUnhandled(e); - return null; - } - } - @FunctionalInterface public interface TryLongLambda extends LambdaFunctionInterface @@ -160,13 +145,6 @@ public interface TryBlockLambda Block apply(); } - @FunctionalInterface - public interface TryVoidLambda - extends LambdaFunctionInterface - { - Void apply(); - } - private static void propagateIfUnhandled(PrestoException e) throws PrestoException { diff --git a/presto-main/src/main/java/com/facebook/presto/operator/scalar/TypeOfFunction.java b/presto-main/src/main/java/com/facebook/presto/operator/scalar/TypeOfFunction.java index b0549199ccfb..323cacbe607f 100644 --- a/presto-main/src/main/java/com/facebook/presto/operator/scalar/TypeOfFunction.java +++ b/presto-main/src/main/java/com/facebook/presto/operator/scalar/TypeOfFunction.java @@ -65,13 +65,4 @@ public static Slice typeof( { return typeof(type, (Object) value); } - - @TypeParameter("T") - @SqlType(StandardTypes.VARCHAR) - public static Slice typeof( - @TypeParameter("T") Type type, - @SqlNullable @SqlType("T") Void value) - { - return typeof(type, (Object) value); - } } diff --git a/presto-main/src/main/java/com/facebook/presto/sql/gen/BytecodeUtils.java b/presto-main/src/main/java/com/facebook/presto/sql/gen/BytecodeUtils.java index ffd6a28a26e3..decbdad5d144 100644 --- a/presto-main/src/main/java/com/facebook/presto/sql/gen/BytecodeUtils.java +++ b/presto-main/src/main/java/com/facebook/presto/sql/gen/BytecodeUtils.java @@ -41,7 +41,6 @@ import java.util.List; import java.util.Optional; -import static com.facebook.presto.operator.scalar.ScalarFunctionImplementation.ArgumentType.FUNCTION_TYPE; import static com.facebook.presto.operator.scalar.ScalarFunctionImplementation.ArgumentType.VALUE_TYPE; import static com.facebook.presto.sql.gen.Bootstrap.BOOTSTRAP_METHOD; import static com.google.common.base.Preconditions.checkArgument; @@ -98,9 +97,7 @@ public static BytecodeNode handleNullValue(Scope scope, isNull.pushJavaDefault(returnType); String loadDefaultComment = null; - if (returnType != void.class) { - loadDefaultComment = format("loadJavaDefault(%s)", returnType.getName()); - } + loadDefaultComment = format("loadJavaDefault(%s)", returnType.getName()); isNull.gotoLabel(label); @@ -230,9 +227,6 @@ else if (type == ConnectorSession.class) { block.append(ifWasNullPopAndGoto(scope, end, unboxedReturnType, Lists.reverse(stackTypes))); break; case USE_NULL_FLAG: - if (type == Void.class) { - block.append(boxPrimitiveIfNecessary(scope, type)); - } block.append(arguments.get(realParameterIndex)); block.append(scope.getVariable("wasNull")); block.append(scope.getVariable("wasNull").set(constantFalse())); @@ -281,11 +275,7 @@ public static BytecodeBlock unboxPrimitiveIfNecessary(Scope scope, Class boxe Class unboxedType = Primitives.unwrap(boxedType); Variable wasNull = scope.getVariable("wasNull"); - if (unboxedType == void.class) { - block.pop(boxedType) - .append(wasNull.set(constantTrue())); - } - else if (unboxedType.isPrimitive()) { + if (unboxedType.isPrimitive()) { LabelNode notNull = new LabelNode("notNull"); block.dup(boxedType) .ifNotNullGoto(notNull) @@ -327,11 +317,6 @@ else if (type == Boolean.class) { notNull.invokeStatic(Boolean.class, "valueOf", Boolean.class, boolean.class); expectedCurrentStackType = boolean.class; } - else if (type == Void.class) { - notNull.pushNull() - .checkCast(Void.class); - return notNull; - } else { throw new UnsupportedOperationException("not yet implemented: " + type); } @@ -361,12 +346,6 @@ public static BytecodeExpression invoke(Binding binding, Signature signature) public static BytecodeNode generateWrite(CallSiteBinder callSiteBinder, Scope scope, Variable wasNullVariable, Type type) { - if (type.getJavaType() == void.class) { - return new BytecodeBlock().comment("output.appendNull();") - .invokeInterface(BlockBuilder.class, "appendNull", BlockBuilder.class) - .pop(); - } - Class valueJavaType = type.getJavaType(); if (!valueJavaType.isPrimitive() && valueJavaType != Slice.class) { valueJavaType = Object.class; diff --git a/presto-main/src/main/java/com/facebook/presto/sql/gen/NullIfCodeGenerator.java b/presto-main/src/main/java/com/facebook/presto/sql/gen/NullIfCodeGenerator.java index fb27917c6a58..885b71a204c8 100644 --- a/presto-main/src/main/java/com/facebook/presto/sql/gen/NullIfCodeGenerator.java +++ b/presto-main/src/main/java/com/facebook/presto/sql/gen/NullIfCodeGenerator.java @@ -43,12 +43,6 @@ public BytecodeNode generateExpression(Signature signature, BytecodeGeneratorCon RowExpression first = arguments.get(0); RowExpression second = arguments.get(1); - if (first.getType().getJavaType() == void.class) { - return new BytecodeBlock() - .comment("NULLIF(NULL, *) = NULL") - .append(generatorContext.generate(first)); - } - LabelNode notMatch = new LabelNode("notMatch"); // push first arg on the stack diff --git a/presto-main/src/main/java/com/facebook/presto/sql/gen/RowConstructorCodeGenerator.java b/presto-main/src/main/java/com/facebook/presto/sql/gen/RowConstructorCodeGenerator.java index 4ad0dcd4834e..1ed85d55734b 100644 --- a/presto-main/src/main/java/com/facebook/presto/sql/gen/RowConstructorCodeGenerator.java +++ b/presto-main/src/main/java/com/facebook/presto/sql/gen/RowConstructorCodeGenerator.java @@ -56,22 +56,15 @@ public BytecodeNode generateExpression(Signature signature, BytecodeGeneratorCon for (int i = 0; i < arguments.size(); ++i) { Type fieldType = types.get(i); - Class javaType = fieldType.getJavaType(); - if (javaType == void.class) { - block.comment(i + "-th field type of row is undefined"); - block.append(singleRowBlockWriter.invoke("appendNull", BlockBuilder.class).pop()); - } - else { - Variable field = scope.createTempVariable(javaType); - block.comment("Clean wasNull and Generate + " + i + "-th field of row"); - block.append(context.wasNull().set(constantFalse())); - block.append(context.generate(arguments.get(i))); - block.putVariable(field); - block.append(new IfStatement() - .condition(context.wasNull()) - .ifTrue(singleRowBlockWriter.invoke("appendNull", BlockBuilder.class).pop()) - .ifFalse(constantType(binder, fieldType).writeValue(singleRowBlockWriter, field).pop())); - } + Variable field = scope.createTempVariable(fieldType.getJavaType()); + block.comment("Clean wasNull and Generate + " + i + "-th field of row"); + block.append(context.wasNull().set(constantFalse())); + block.append(context.generate(arguments.get(i))); + block.putVariable(field); + block.append(new IfStatement() + .condition(context.wasNull()) + .ifTrue(singleRowBlockWriter.invoke("appendNull", BlockBuilder.class).pop()) + .ifFalse(constantType(binder, fieldType).writeValue(singleRowBlockWriter, field).pop())); } block.comment("closeEntry; slice the SingleRowBlock; wasNull = false;"); block.append(blockBuilder.invoke("closeEntry", BlockBuilder.class).pop()); diff --git a/presto-main/src/main/java/com/facebook/presto/sql/gen/RowExpressionCompiler.java b/presto-main/src/main/java/com/facebook/presto/sql/gen/RowExpressionCompiler.java index ea3a4cfaf361..bd01331648dd 100644 --- a/presto-main/src/main/java/com/facebook/presto/sql/gen/RowExpressionCompiler.java +++ b/presto-main/src/main/java/com/facebook/presto/sql/gen/RowExpressionCompiler.java @@ -183,9 +183,6 @@ public BytecodeNode visitConstant(ConstantExpression constant, Context context) if (javaType == String.class) { return block.append(loadString((String) value)); } - if (javaType == void.class) { - return block; - } // bind constant object directly into the call-site using invoke dynamic Binding binding = callSiteBinder.bind(value, constant.getType().getJavaType()); diff --git a/presto-main/src/main/java/com/facebook/presto/type/UnknownOperators.java b/presto-main/src/main/java/com/facebook/presto/type/UnknownOperators.java index 94744e3abf90..32241a65ad96 100644 --- a/presto-main/src/main/java/com/facebook/presto/type/UnknownOperators.java +++ b/presto-main/src/main/java/com/facebook/presto/type/UnknownOperators.java @@ -37,75 +37,67 @@ private UnknownOperators() } @ScalarOperator(EQUAL) - @SqlNullable @SqlType(StandardTypes.BOOLEAN) - public static Boolean equal(@SqlType("unknown") @SqlNullable Void left, @SqlType("unknown") @SqlNullable Void right) + public static boolean equal(@SqlType("unknown") boolean left, @SqlType("unknown") boolean right) { - return null; + throw new AssertionError("value of unknown type should all be NULL"); } @ScalarOperator(NOT_EQUAL) - @SqlNullable @SqlType(StandardTypes.BOOLEAN) - public static Boolean notEqual(@SqlType("unknown") @SqlNullable Void left, @SqlType("unknown") @SqlNullable Void right) + public static boolean notEqual(@SqlType("unknown") boolean left, @SqlType("unknown") boolean right) { - return null; + throw new AssertionError("value of unknown type should all be NULL"); } @ScalarOperator(LESS_THAN) - @SqlNullable @SqlType(StandardTypes.BOOLEAN) - public static Boolean lessThan(@SqlType("unknown") @SqlNullable Void left, @SqlType("unknown") @SqlNullable Void right) + public static boolean lessThan(@SqlType("unknown") boolean left, @SqlType("unknown") boolean right) { - return null; + throw new AssertionError("value of unknown type should all be NULL"); } @ScalarOperator(LESS_THAN_OR_EQUAL) - @SqlNullable @SqlType(StandardTypes.BOOLEAN) - public static Boolean lessThanOrEqual(@SqlType("unknown") @SqlNullable Void left, @SqlType("unknown") @SqlNullable Void right) + public static boolean lessThanOrEqual(@SqlType("unknown") boolean left, @SqlType("unknown") boolean right) { - return null; + throw new AssertionError("value of unknown type should all be NULL"); } @ScalarOperator(GREATER_THAN) - @SqlNullable @SqlType(StandardTypes.BOOLEAN) - public static Boolean greaterThan(@SqlType("unknown") @SqlNullable Void left, @SqlType("unknown") @SqlNullable Void right) + public static boolean greaterThan(@SqlType("unknown") boolean left, @SqlType("unknown") boolean right) { - return null; + throw new AssertionError("value of unknown type should all be NULL"); } @ScalarOperator(GREATER_THAN_OR_EQUAL) - @SqlNullable @SqlType(StandardTypes.BOOLEAN) - public static Boolean greaterThanOrEqual(@SqlType("unknown") @SqlNullable Void left, @SqlType("unknown") @SqlNullable Void right) + public static boolean greaterThanOrEqual(@SqlType("unknown") boolean left, @SqlType("unknown") boolean right) { - return null; + throw new AssertionError("value of unknown type should all be NULL"); } @ScalarOperator(BETWEEN) - @SqlNullable @SqlType(StandardTypes.BOOLEAN) - public static Boolean between(@SqlType("unknown") @SqlNullable Void value, @SqlType("unknown") @SqlNullable Void min, @SqlType("unknown") @SqlNullable Void max) + public static boolean between(@SqlType("unknown") boolean value, @SqlType("unknown") boolean min, @SqlType("unknown") boolean max) { - return null; + throw new AssertionError("value of unknown type should all be NULL"); } @ScalarOperator(HASH_CODE) - @SqlNullable @SqlType(StandardTypes.BIGINT) - public static Long hashCode(@SqlType("unknown") @SqlNullable Void value) + public static long hashCode(@SqlType("unknown") boolean value) { - return null; + throw new AssertionError("value of unknown type should all be NULL"); } @ScalarOperator(IS_DISTINCT_FROM) @SqlType(StandardTypes.BOOLEAN) public static boolean isDistinctFrom( - @SqlType("unknown") Void left, + @SqlType("unknown") boolean left, @IsNull boolean leftNull, - @SqlType("unknown") Void right, + @SqlType("unknown") boolean right, @IsNull boolean rightNull) { return false; @@ -113,7 +105,7 @@ public static boolean isDistinctFrom( @ScalarOperator(INDETERMINATE) @SqlType(StandardTypes.BOOLEAN) - public static boolean indeterminate(@SqlType("unknown") @SqlNullable Void value) + public static boolean indeterminate(@SqlType("unknown") @SqlNullable Boolean value) { return true; } diff --git a/presto-main/src/main/java/com/facebook/presto/type/UnknownType.java b/presto-main/src/main/java/com/facebook/presto/type/UnknownType.java index 37329e4069d6..514bd38f9a04 100644 --- a/presto-main/src/main/java/com/facebook/presto/type/UnknownType.java +++ b/presto-main/src/main/java/com/facebook/presto/type/UnknownType.java @@ -29,7 +29,10 @@ public final class UnknownType private UnknownType() { - super(new TypeSignature(NAME), void.class, 0); + // We never access the native container for UNKNOWN because its null check is always true. + // The actual native container type does not matter here. + // We choose boolean to represent UNKNOWN because it's the smallest primitive type. + super(new TypeSignature(NAME), boolean.class, 1); } @Override @@ -83,4 +86,13 @@ public void appendTo(Block block, int position, BlockBuilder blockBuilder) { blockBuilder.appendNull(); } + + @Override + public boolean getBoolean(Block block, int position) + { + // Ideally, this function should never be invoked for unknown type. + // However, some logic rely on having a default value before the null check. + checkArgument(block.isNull(position)); + return false; + } } diff --git a/presto-main/src/test/java/com/facebook/presto/operator/scalar/TestIsNullAnnotation.java b/presto-main/src/test/java/com/facebook/presto/operator/scalar/TestIsNullAnnotation.java index e3ad98a8a338..833d45263c99 100644 --- a/presto-main/src/test/java/com/facebook/presto/operator/scalar/TestIsNullAnnotation.java +++ b/presto-main/src/test/java/com/facebook/presto/operator/scalar/TestIsNullAnnotation.java @@ -86,7 +86,7 @@ public static Slice testIsNull( @ScalarFunction("test_is_null_void") @SqlType(StandardTypes.BOOLEAN) - public static boolean testIsNullVoid(@SqlType("unknown") Void value, @IsNull boolean isNull) + public static boolean testIsNullVoid(@SqlType("unknown") boolean value, @IsNull boolean isNull) { return isNull; } diff --git a/presto-main/src/test/java/com/facebook/presto/type/AbstractTestType.java b/presto-main/src/test/java/com/facebook/presto/type/AbstractTestType.java index f2b5373bfed1..fe43321a1024 100644 --- a/presto-main/src/test/java/com/facebook/presto/type/AbstractTestType.java +++ b/presto-main/src/test/java/com/facebook/presto/type/AbstractTestType.java @@ -45,6 +45,7 @@ import static com.facebook.presto.type.TypeUtils.positionEqualsPosition; import static com.facebook.presto.util.StructuralTestUtil.arrayBlockOf; import static com.facebook.presto.util.StructuralTestUtil.mapBlockOf; +import static com.google.common.base.Preconditions.checkState; import static io.airlift.testing.Assertions.assertInstanceOf; import static java.util.Collections.unmodifiableSortedMap; import static java.util.Objects.requireNonNull; @@ -84,7 +85,8 @@ private Block createAlternatingNullsBlock(Block testBlock) { BlockBuilder nullsBlockBuilder = type.createBlockBuilder(null, testBlock.getPositionCount()); for (int position = 0; position < testBlock.getPositionCount(); position++) { - if (type.getJavaType() == void.class) { + if (testBlock.isNull(position)) { + checkState(type instanceof UnknownType); nullsBlockBuilder.appendNull(); } else if (type.getJavaType() == boolean.class) { @@ -184,7 +186,7 @@ private void assertPositionValue(Block block, int position, Object expectedStack verifyInvalidPositionHandling(block); if (block.isNull(position)) { - if (type.isOrderable() && type.getJavaType() != void.class) { + if (type.isOrderable() && !(type instanceof UnknownType)) { Block nonNullValue = toBlock(getNonNullValue()); assertTrue(ASC_NULLS_FIRST.compareBlockValue(type, block, position, nonNullValue, 0) < 0); assertTrue(ASC_NULLS_LAST.compareBlockValue(type, block, position, nonNullValue, 0) > 0); @@ -353,7 +355,7 @@ private void verifyInvalidPositionHandling(Block block) catch (RuntimeException expected) { } - if (type.isComparable() && type.getJavaType() != void.class) { + if (type.isComparable() && !(type instanceof UnknownType)) { Block other = toBlock(getNonNullValue()); try { type.equalTo(block, -1, other, 0); @@ -369,7 +371,7 @@ private void verifyInvalidPositionHandling(Block block) } } - if (type.isOrderable() && type.getJavaType() != void.class) { + if (type.isOrderable() && !(type instanceof UnknownType)) { Block other = toBlock(getNonNullValue()); try { ASC_NULLS_FIRST.compareBlockValue(type, block, -1, other, 0); diff --git a/presto-main/src/test/java/com/facebook/presto/type/TestUnknownOperators.java b/presto-main/src/test/java/com/facebook/presto/type/TestUnknownOperators.java index 42ce40cb1524..84c78564eb7b 100644 --- a/presto-main/src/test/java/com/facebook/presto/type/TestUnknownOperators.java +++ b/presto-main/src/test/java/com/facebook/presto/type/TestUnknownOperators.java @@ -39,7 +39,7 @@ public void setUp() @ScalarFunction(value = "null_function", deterministic = false) @SqlNullable @SqlType("unknown") - public static Void nullFunction() + public static Boolean nullFunction() { return null; } diff --git a/presto-main/src/test/java/com/facebook/presto/type/TestUnknownType.java b/presto-main/src/test/java/com/facebook/presto/type/TestUnknownType.java index 623a8cd0fdb5..ba8c8a0667c2 100644 --- a/presto-main/src/test/java/com/facebook/presto/type/TestUnknownType.java +++ b/presto-main/src/test/java/com/facebook/presto/type/TestUnknownType.java @@ -21,7 +21,7 @@ public class TestUnknownType public TestUnknownType() { super(UNKNOWN, - void.class, + boolean.class, UNKNOWN.createBlockBuilder(null, 3) .appendNull() .appendNull() diff --git a/presto-spi/src/main/java/com/facebook/presto/spi/block/MethodHandleUtil.java b/presto-spi/src/main/java/com/facebook/presto/spi/block/MethodHandleUtil.java index 8ba7b2659d51..2f97d52783b8 100644 --- a/presto-spi/src/main/java/com/facebook/presto/spi/block/MethodHandleUtil.java +++ b/presto-spi/src/main/java/com/facebook/presto/spi/block/MethodHandleUtil.java @@ -33,7 +33,6 @@ public final class MethodHandleUtil private static final MethodHandle GET_BOOLEAN = methodHandle(Type.class, "getBoolean", Block.class, int.class); private static final MethodHandle GET_SLICE = methodHandle(Type.class, "getSlice", Block.class, int.class); private static final MethodHandle GET_BLOCK = methodHandle(Type.class, "getObject", Block.class, int.class).asType(methodType(Block.class, Type.class, Block.class, int.class)); - private static final MethodHandle GET_UNKNOWN = methodHandle(MethodHandleUtil.class, "unknownGetter", Type.class, Block.class, int.class); private static final MethodHandle WRITE_LONG = methodHandle(Type.class, "writeLong", BlockBuilder.class, long.class); private static final MethodHandle WRITE_DOUBLE = methodHandle(Type.class, "writeDouble", BlockBuilder.class, double.class); @@ -146,9 +145,6 @@ else if (javaType == Slice.class) { else if (javaType == Block.class) { methodHandle = GET_BLOCK; } - else if (javaType == void.class) { - methodHandle = GET_UNKNOWN; - } else { throw new IllegalArgumentException("Unknown java type " + javaType + " from type " + type); } @@ -182,9 +178,4 @@ else if (javaType == Block.class) { return methodHandle.bindTo(type); } - - public static Void unknownGetter(Type type, Block block, int position) - { - throw new IllegalArgumentException("For UNKNOWN type, getter should never be invoked on Block"); - } } diff --git a/presto-spi/src/main/java/com/facebook/presto/spi/predicate/Primitives.java b/presto-spi/src/main/java/com/facebook/presto/spi/predicate/Primitives.java index 031f99572881..074b19a1d2d4 100644 --- a/presto-spi/src/main/java/com/facebook/presto/spi/predicate/Primitives.java +++ b/presto-spi/src/main/java/com/facebook/presto/spi/predicate/Primitives.java @@ -58,7 +58,6 @@ private Primitives() {} add(primToWrap, wrapToPrim, int.class, Integer.class); add(primToWrap, wrapToPrim, long.class, Long.class); add(primToWrap, wrapToPrim, short.class, Short.class); - add(primToWrap, wrapToPrim, void.class, Void.class); PRIMITIVE_TO_WRAPPER_TYPE = Collections.unmodifiableMap(primToWrap); WRAPPER_TO_PRIMITIVE_TYPE = Collections.unmodifiableMap(wrapToPrim); @@ -84,8 +83,7 @@ public static Set> allPrimitiveTypes() } /** - * Returns an immutable set of all nine primitive-wrapper types (including - * {@link Void}). + * Returns an immutable set of all eight primitive-wrapper types * * @since 3.0 */