Search in sources :

Example 16 with Signature

use of io.prestosql.spi.function.Signature in project hetu-core by openlookeng.

the class TestSignatureBinder method testBindVarchar.

@Test
public void testBindVarchar() {
    Signature function = functionSignature().returnType(parseTypeSignature("varchar(42)")).argumentTypes(parseTypeSignature("varchar(42)")).build();
    assertThat(function).boundTo(ImmutableList.of("varchar(1)"), "varchar(1)").fails();
    assertThat(function).boundTo(ImmutableList.of("varchar(1)"), "varchar(1)").withCoercion().fails();
    assertThat(function).boundTo(ImmutableList.of("varchar(1)"), "varchar(42)").withCoercion().succeeds();
    assertThat(function).boundTo(ImmutableList.of("varchar(44)"), "varchar(44)").withCoercion().fails();
}
Also used : TypeSignature.parseTypeSignature(io.prestosql.spi.type.TypeSignature.parseTypeSignature) Signature(io.prestosql.spi.function.Signature) TypeSignature(io.prestosql.spi.type.TypeSignature) Test(org.testng.annotations.Test)

Example 17 with Signature

use of io.prestosql.spi.function.Signature in project hetu-core by openlookeng.

the class TestHashAggregationOperator method testHashAggregationMemoryReservation.

@Test(dataProvider = "hashEnabledAndMemoryLimitForMergeValues")
public void testHashAggregationMemoryReservation(boolean hashEnabled, boolean spillEnabled, boolean revokeMemoryWhenAddingPages, long memoryLimitForMerge, long memoryLimitForMergeWithMemory) {
    Metadata localMetadata = createTestMetadataManager();
    InternalAggregationFunction arrayAggColumn = localMetadata.getFunctionAndTypeManager().getAggregateFunctionImplementation(new Signature(QualifiedObjectName.valueOfDefaultFunction("array_agg"), AGGREGATE, parseTypeSignature("array(bigint)"), parseTypeSignature(StandardTypes.BIGINT)));
    List<Integer> hashChannels = Ints.asList(1);
    RowPagesBuilder rowPagesBuilder = rowPagesBuilder(hashEnabled, hashChannels, BIGINT, BIGINT);
    List<Page> input = rowPagesBuilder.addSequencePage(10, 100, 0).addSequencePage(10, 200, 0).addSequencePage(10, 300, 0).build();
    DriverContext driverContext = createTaskContext(executor, scheduledExecutor, TEST_SESSION, new DataSize(10, Unit.MEGABYTE)).addPipelineContext(0, true, true, false).addDriverContext();
    HashAggregationOperatorFactory operatorFactory = new HashAggregationOperatorFactory(0, new PlanNodeId("test"), ImmutableList.of(BIGINT), hashChannels, ImmutableList.of(), Step.SINGLE, true, ImmutableList.of(arrayAggColumn.bind(ImmutableList.of(0), Optional.empty())), rowPagesBuilder.getHashChannel(), Optional.empty(), 100_000, Optional.of(new DataSize(16, MEGABYTE)), spillEnabled, succinctBytes(memoryLimitForMerge), succinctBytes(memoryLimitForMergeWithMemory), spillerFactory, joinCompiler, false);
    Operator operator = operatorFactory.createOperator(driverContext);
    toPages(operator, input.iterator(), revokeMemoryWhenAddingPages);
    assertEquals(operator.getOperatorContext().getOperatorStats().getUserMemoryReservation().toBytes(), 0);
}
Also used : RowPagesBuilder(io.prestosql.RowPagesBuilder) Metadata(io.prestosql.metadata.Metadata) Page(io.prestosql.spi.Page) InternalAggregationFunction(io.prestosql.operator.aggregation.InternalAggregationFunction) PlanNodeId(io.prestosql.spi.plan.PlanNodeId) TypeSignature.parseTypeSignature(io.prestosql.spi.type.TypeSignature.parseTypeSignature) Signature(io.prestosql.spi.function.Signature) DataSize(io.airlift.units.DataSize) HashAggregationOperatorFactory(io.prestosql.operator.HashAggregationOperator.HashAggregationOperatorFactory) Test(org.testng.annotations.Test)

Example 18 with Signature

use of io.prestosql.spi.function.Signature in project hetu-core by openlookeng.

the class TestHashAggregationOperator method testMemoryLimit.

@Test(dataProvider = "hashEnabled", expectedExceptions = ExceededMemoryLimitException.class, expectedExceptionsMessageRegExp = "Query exceeded per-node user memory limit of 10B.*")
public void testMemoryLimit(boolean hashEnabled) {
    Metadata localMetadata = createTestMetadataManager();
    InternalAggregationFunction maxVarcharColumn = localMetadata.getFunctionAndTypeManager().getAggregateFunctionImplementation(new Signature(QualifiedObjectName.valueOfDefaultFunction("max"), AGGREGATE, parseTypeSignature(StandardTypes.VARCHAR), parseTypeSignature(StandardTypes.VARCHAR)));
    List<Integer> hashChannels = Ints.asList(1);
    RowPagesBuilder rowPagesBuilder = rowPagesBuilder(hashEnabled, hashChannels, VARCHAR, BIGINT, VARCHAR, BIGINT);
    List<Page> input = rowPagesBuilder.addSequencePage(10, 100, 0, 100, 0).addSequencePage(10, 100, 0, 200, 0).addSequencePage(10, 100, 0, 300, 0).build();
    DriverContext driverContext = createTaskContext(executor, scheduledExecutor, TEST_SESSION, new DataSize(10, Unit.BYTE)).addPipelineContext(0, true, true, false).addDriverContext();
    HashAggregationOperatorFactory operatorFactory = new HashAggregationOperatorFactory(0, new PlanNodeId("test"), ImmutableList.of(BIGINT), hashChannels, ImmutableList.of(), Step.SINGLE, ImmutableList.of(COUNT.bind(ImmutableList.of(0), Optional.empty()), LONG_SUM.bind(ImmutableList.of(3), Optional.empty()), LONG_AVERAGE.bind(ImmutableList.of(3), Optional.empty()), maxVarcharColumn.bind(ImmutableList.of(2), Optional.empty())), rowPagesBuilder.getHashChannel(), Optional.empty(), 100_000, Optional.of(new DataSize(16, MEGABYTE)), joinCompiler, false);
    toPages(operatorFactory, driverContext, input);
}
Also used : PlanNodeId(io.prestosql.spi.plan.PlanNodeId) RowPagesBuilder(io.prestosql.RowPagesBuilder) TypeSignature.parseTypeSignature(io.prestosql.spi.type.TypeSignature.parseTypeSignature) Signature(io.prestosql.spi.function.Signature) DataSize(io.airlift.units.DataSize) Metadata(io.prestosql.metadata.Metadata) Page(io.prestosql.spi.Page) InternalAggregationFunction(io.prestosql.operator.aggregation.InternalAggregationFunction) HashAggregationOperatorFactory(io.prestosql.operator.HashAggregationOperator.HashAggregationOperatorFactory) Test(org.testng.annotations.Test)

Example 19 with Signature

use of io.prestosql.spi.function.Signature in project hetu-core by openlookeng.

the class TestAnnotationEngineForAggregates method testSimpleGenericAggregationFunctionParse.

@Test
public void testSimpleGenericAggregationFunctionParse() {
    Signature expectedSignature = new Signature(QualifiedObjectName.valueOfDefaultFunction("simple_generic_implementations"), FunctionKind.AGGREGATE, ImmutableList.of(typeVariable("T")), ImmutableList.of(), parseTypeSignature("T"), ImmutableList.of(parseTypeSignature("T")), false);
    ParametricAggregation aggregation = parseFunctionDefinition(GenericAggregationFunction.class);
    assertEquals(aggregation.getDescription(), "Simple aggregate with two generic implementations");
    assertTrue(aggregation.isDeterministic());
    assertEquals(aggregation.getSignature(), expectedSignature);
    ParametricImplementationsGroup<AggregationImplementation> implementations = aggregation.getImplementations();
    assertImplementationCount(implementations, 0, 0, 2);
    AggregationImplementation implementationDouble = implementations.getGenericImplementations().stream().filter(impl -> impl.getStateClass() == NullableDoubleState.class).collect(toImmutableList()).get(0);
    assertFalse(implementationDouble.getStateSerializerFactory().isPresent());
    assertEquals(implementationDouble.getDefinitionClass(), GenericAggregationFunction.class);
    assertDependencyCount(implementationDouble, 0, 0, 0);
    assertFalse(implementationDouble.hasSpecializedTypeParameters());
    List<AggregationMetadata.ParameterMetadata.ParameterType> expectedMetadataTypes = ImmutableList.of(AggregationMetadata.ParameterMetadata.ParameterType.STATE, AggregationMetadata.ParameterMetadata.ParameterType.INPUT_CHANNEL);
    assertTrue(implementationDouble.getInputParameterMetadataTypes().equals(expectedMetadataTypes));
    assertEquals(implementationDouble.getStateClass(), NullableDoubleState.class);
    AggregationImplementation implementationLong = implementations.getGenericImplementations().stream().filter(impl -> impl.getStateClass() == NullableLongState.class).collect(toImmutableList()).get(0);
    assertFalse(implementationLong.getStateSerializerFactory().isPresent());
    assertEquals(implementationLong.getDefinitionClass(), GenericAggregationFunction.class);
    assertDependencyCount(implementationLong, 0, 0, 0);
    assertFalse(implementationLong.hasSpecializedTypeParameters());
    assertTrue(implementationLong.getInputParameterMetadataTypes().equals(expectedMetadataTypes));
    assertEquals(implementationLong.getStateClass(), NullableLongState.class);
    InternalAggregationFunction specialized = aggregation.specialize(BoundVariables.builder().setTypeVariable("T", DoubleType.DOUBLE).build(), 1, METADATA.getFunctionAndTypeManager());
    assertEquals(specialized.getFinalType(), DoubleType.DOUBLE);
    assertTrue(specialized.getParameterTypes().equals(ImmutableList.of(DoubleType.DOUBLE)));
    assertTrue(specialized.isDecomposable());
    assertEquals(specialized.name(), "simple_generic_implementations");
}
Also used : AggregationImplementation(io.prestosql.operator.aggregation.AggregationImplementation) NullableLongState(io.prestosql.operator.aggregation.state.NullableLongState) TypeSignature.parseTypeSignature(io.prestosql.spi.type.TypeSignature.parseTypeSignature) TypeSignature(io.prestosql.spi.type.TypeSignature) Signature(io.prestosql.spi.function.Signature) AggregationMetadata(io.prestosql.operator.aggregation.AggregationMetadata) ParametricAggregation(io.prestosql.operator.aggregation.ParametricAggregation) NullableDoubleState(io.prestosql.operator.aggregation.state.NullableDoubleState) InternalAggregationFunction(io.prestosql.operator.aggregation.InternalAggregationFunction) Test(org.testng.annotations.Test)

Example 20 with Signature

use of io.prestosql.spi.function.Signature in project hetu-core by openlookeng.

the class TestAnnotationEngineForAggregates method testInjectLiteralAggregateParse.

@Test
public void testInjectLiteralAggregateParse() {
    Signature expectedSignature = new Signature(QualifiedObjectName.valueOfDefaultFunction("inject_literal_aggregate"), FunctionKind.AGGREGATE, parseTypeSignature("varchar(x)", ImmutableSet.of("x")), ImmutableList.of(parseTypeSignature("varchar(x)", ImmutableSet.of("x"))));
    ParametricAggregation aggregation = parseFunctionDefinition(InjectLiteralAggregateFunction.class);
    assertEquals(aggregation.getDescription(), "Simple aggregate with type literal");
    assertTrue(aggregation.isDeterministic());
    assertEquals(aggregation.getSignature(), expectedSignature);
    ParametricImplementationsGroup<AggregationImplementation> implementations = aggregation.getImplementations();
    assertEquals(implementations.getGenericImplementations().size(), 1);
    AggregationImplementation implementation = implementations.getGenericImplementations().get(0);
    assertTrue(implementation.getStateSerializerFactory().isPresent());
    assertEquals(implementation.getDefinitionClass(), InjectLiteralAggregateFunction.class);
    assertDependencyCount(implementation, 1, 1, 1);
    assertEquals(implementation.getStateSerializerFactoryDependencies().size(), 1);
    assertTrue(implementation.getInputDependencies().get(0) instanceof LiteralImplementationDependency);
    assertTrue(implementation.getCombineDependencies().get(0) instanceof LiteralImplementationDependency);
    assertTrue(implementation.getOutputDependencies().get(0) instanceof LiteralImplementationDependency);
    assertTrue(implementation.getStateSerializerFactoryDependencies().get(0) instanceof LiteralImplementationDependency);
    assertFalse(implementation.hasSpecializedTypeParameters());
    List<AggregationMetadata.ParameterMetadata.ParameterType> expectedMetadataTypes = ImmutableList.of(AggregationMetadata.ParameterMetadata.ParameterType.STATE, AggregationMetadata.ParameterMetadata.ParameterType.INPUT_CHANNEL);
    assertTrue(implementation.getInputParameterMetadataTypes().equals(expectedMetadataTypes));
    InternalAggregationFunction specialized = aggregation.specialize(BoundVariables.builder().setLongVariable("x", 17L).build(), 1, METADATA.getFunctionAndTypeManager());
    assertEquals(specialized.getFinalType(), VarcharType.createVarcharType(17));
    assertTrue(specialized.isDecomposable());
    assertEquals(specialized.name(), "inject_literal_aggregate");
}
Also used : AggregationImplementation(io.prestosql.operator.aggregation.AggregationImplementation) LiteralImplementationDependency(io.prestosql.operator.annotations.LiteralImplementationDependency) TypeSignature.parseTypeSignature(io.prestosql.spi.type.TypeSignature.parseTypeSignature) TypeSignature(io.prestosql.spi.type.TypeSignature) Signature(io.prestosql.spi.function.Signature) AggregationMetadata(io.prestosql.operator.aggregation.AggregationMetadata) ParametricAggregation(io.prestosql.operator.aggregation.ParametricAggregation) InternalAggregationFunction(io.prestosql.operator.aggregation.InternalAggregationFunction) Test(org.testng.annotations.Test)

Aggregations

Signature (io.prestosql.spi.function.Signature)230 Test (org.testng.annotations.Test)186 TypeSignature.parseTypeSignature (io.prestosql.spi.type.TypeSignature.parseTypeSignature)184 TypeSignature (io.prestosql.spi.type.TypeSignature)93 InternalAggregationFunction (io.prestosql.operator.aggregation.InternalAggregationFunction)69 BuiltInFunctionHandle (io.prestosql.spi.function.BuiltInFunctionHandle)41 CallExpression (io.prestosql.spi.relation.CallExpression)35 Type (io.prestosql.spi.type.Type)23 RowExpression (io.prestosql.spi.relation.RowExpression)20 Block (io.prestosql.spi.block.Block)18 ArrayList (java.util.ArrayList)17 ImmutableList (com.google.common.collect.ImmutableList)15 SqlScalarFunction (io.prestosql.metadata.SqlScalarFunction)15 MapType (io.prestosql.spi.type.MapType)14 ImmutableSet (com.google.common.collect.ImmutableSet)12 Slice (io.airlift.slice.Slice)12 ParametricAggregation (io.prestosql.operator.aggregation.ParametricAggregation)11 BuiltInScalarFunctionImplementation (io.prestosql.spi.function.BuiltInScalarFunctionImplementation)11 AggregationImplementation (io.prestosql.operator.aggregation.AggregationImplementation)10 AggregationMetadata (io.prestosql.operator.aggregation.AggregationMetadata)10