Search in sources :

Example 16 with FunctionCall

use of io.confluent.ksql.execution.expression.tree.FunctionCall in project ksql by confluentinc.

the class AggregateAnalyzerTest method shouldThrowOnNestedSelectAggFunctions.

@Test
public void shouldThrowOnNestedSelectAggFunctions() {
    // Given:
    final FunctionCall nestedCall = new FunctionCall(FunctionName.of("MIN"), ImmutableList.of(AGG_FUNCTION_CALL, COL2));
    givenSelectExpression(nestedCall);
    // When:
    final KsqlException e = assertThrows(KsqlException.class, () -> analyzer.analyze(analysis, selects));
    // Then:
    assertThat(e.getMessage(), containsString("Aggregate functions can not be nested: MIN(MAX())"));
}
Also used : FunctionCall(io.confluent.ksql.execution.expression.tree.FunctionCall) KsqlException(io.confluent.ksql.util.KsqlException) Test(org.junit.Test)

Example 17 with FunctionCall

use of io.confluent.ksql.execution.expression.tree.FunctionCall in project ksql by confluentinc.

the class AggregateAnalyzerTest method shouldNotThrowOnNonAggregateFunctionArgumentsWhenNestedInsideAggFunction.

@Test
public void shouldNotThrowOnNonAggregateFunctionArgumentsWhenNestedInsideAggFunction() {
    // Given:
    final FunctionCall nonAggFunc = new FunctionCall(FunctionName.of("ROUND"), ImmutableList.of(COL3));
    final FunctionCall aggFuncWithNestedNonAgg = new FunctionCall(FunctionName.of("MAX"), ImmutableList.of(COL2, nonAggFunc));
    givenSelectExpression(aggFuncWithNestedNonAgg);
    // When:
    analyzer.analyze(analysis, selects);
// Then: did not throw.
}
Also used : FunctionCall(io.confluent.ksql.execution.expression.tree.FunctionCall) Test(org.junit.Test)

Example 18 with FunctionCall

use of io.confluent.ksql.execution.expression.tree.FunctionCall in project ksql by confluentinc.

the class AggregateAnalyzerTest method shouldCaptureDefaultFunctionArguments.

@Test
public void shouldCaptureDefaultFunctionArguments() {
    // Given:
    final FunctionCall emptyFunc = new FunctionCall(FunctionName.of("COUNT"), new ArrayList<>());
    givenSelectExpression(emptyFunc);
    // When:
    final AggregateAnalysisResult result = analyzer.analyze(analysis, selects);
    // Then:
    assertThat(result.getRequiredColumns(), hasItem(DEFAULT_ARGUMENT));
    assertThat(result.getAggregateFunctionArguments(), hasItem(DEFAULT_ARGUMENT));
}
Also used : FunctionCall(io.confluent.ksql.execution.expression.tree.FunctionCall) Test(org.junit.Test)

Example 19 with FunctionCall

use of io.confluent.ksql.execution.expression.tree.FunctionCall in project ksql by confluentinc.

the class AggregateAnalyzerTest method shouldThrowOnNestedHavingAggFunctions.

@Test
public void shouldThrowOnNestedHavingAggFunctions() {
    // Given:
    final FunctionCall nestedCall = new FunctionCall(FunctionName.of("MIN"), ImmutableList.of(AGG_FUNCTION_CALL, COL2));
    givenHavingExpression(nestedCall);
    // When:
    final KsqlException e = assertThrows(KsqlException.class, () -> analyzer.analyze(analysis, selects));
    // Then:
    assertThat(e.getMessage(), containsString("Aggregate functions can not be nested: MIN(MAX())"));
}
Also used : FunctionCall(io.confluent.ksql.execution.expression.tree.FunctionCall) KsqlException(io.confluent.ksql.util.KsqlException) Test(org.junit.Test)

Example 20 with FunctionCall

use of io.confluent.ksql.execution.expression.tree.FunctionCall in project ksql by confluentinc.

the class AggregateAnalyzerTest method shouldThrowOnNonAggFunctionCallWithColumnParamNotInGroupBy.

@Test
public void shouldThrowOnNonAggFunctionCallWithColumnParamNotInGroupBy() {
    // Given:
    givenSelectExpression(new FunctionCall(FunctionName.of("UCASE"), ImmutableList.of(COL2)));
    // When:
    final KsqlException e = assertThrows(KsqlException.class, () -> analyzer.analyze(analysis, selects));
    // Then:
    assertThat(e.getMessage(), containsString("Non-aggregate SELECT expression(s) not part of GROUP BY: UCASE(COL2)"));
}
Also used : FunctionCall(io.confluent.ksql.execution.expression.tree.FunctionCall) KsqlException(io.confluent.ksql.util.KsqlException) Test(org.junit.Test)

Aggregations

FunctionCall (io.confluent.ksql.execution.expression.tree.FunctionCall)52 Test (org.junit.Test)47 LambdaFunctionCall (io.confluent.ksql.execution.expression.tree.LambdaFunctionCall)34 ArithmeticBinaryExpression (io.confluent.ksql.execution.expression.tree.ArithmeticBinaryExpression)22 IntegerLiteral (io.confluent.ksql.execution.expression.tree.IntegerLiteral)22 Expression (io.confluent.ksql.execution.expression.tree.Expression)21 CreateArrayExpression (io.confluent.ksql.execution.expression.tree.CreateArrayExpression)17 CreateStructExpression (io.confluent.ksql.execution.expression.tree.CreateStructExpression)17 ComparisonExpression (io.confluent.ksql.execution.expression.tree.ComparisonExpression)16 CreateMapExpression (io.confluent.ksql.execution.expression.tree.CreateMapExpression)16 InListExpression (io.confluent.ksql.execution.expression.tree.InListExpression)16 SearchedCaseExpression (io.confluent.ksql.execution.expression.tree.SearchedCaseExpression)16 SimpleCaseExpression (io.confluent.ksql.execution.expression.tree.SimpleCaseExpression)16 SubscriptExpression (io.confluent.ksql.execution.expression.tree.SubscriptExpression)16 LambdaVariable (io.confluent.ksql.execution.expression.tree.LambdaVariable)15 KsqlScalarFunction (io.confluent.ksql.function.KsqlScalarFunction)13 UdfFactory (io.confluent.ksql.function.UdfFactory)13 DereferenceExpression (io.confluent.ksql.execution.expression.tree.DereferenceExpression)11 NotExpression (io.confluent.ksql.execution.expression.tree.NotExpression)11 StringLiteral (io.confluent.ksql.execution.expression.tree.StringLiteral)11