Search in sources :

Example 36 with IntegerLiteral

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

the class ParserUtil method visitIntegerLiteral.

public static Literal visitIntegerLiteral(final IntegerLiteralContext context) {
    final Optional<NodeLocation> location = getLocation(context);
    final long valueAsLong;
    try {
        valueAsLong = Long.parseLong(context.getText());
    } catch (final NumberFormatException e) {
        throw new ParsingException("Invalid numeric literal: " + context.getText(), location);
    }
    if (valueAsLong <= Integer.MAX_VALUE && valueAsLong >= Integer.MIN_VALUE) {
        return new IntegerLiteral(location, (int) valueAsLong);
    } else {
        return new LongLiteral(location, valueAsLong);
    }
}
Also used : NodeLocation(io.confluent.ksql.parser.NodeLocation) LongLiteral(io.confluent.ksql.execution.expression.tree.LongLiteral) ParsingException(io.confluent.ksql.parser.ParsingException) IntegerLiteral(io.confluent.ksql.execution.expression.tree.IntegerLiteral)

Example 37 with IntegerLiteral

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

the class CreateSourceProperties method withPartitions.

public CreateSourceProperties withPartitions(final int partitions) {
    final Map<String, Literal> originals = props.copyOfOriginalLiterals();
    originals.put(CommonCreateConfigs.SOURCE_NUMBER_OF_PARTITIONS, new IntegerLiteral(partitions));
    return new CreateSourceProperties(originals, durationParser);
}
Also used : StringLiteral(io.confluent.ksql.execution.expression.tree.StringLiteral) IntegerLiteral(io.confluent.ksql.execution.expression.tree.IntegerLiteral) Literal(io.confluent.ksql.execution.expression.tree.Literal) IntegerLiteral(io.confluent.ksql.execution.expression.tree.IntegerLiteral)

Example 38 with IntegerLiteral

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

the class GenericExpressionResolverTest method shouldThrowIfCannotCoerce.

@Test
public void shouldThrowIfCannotCoerce() {
    // Given:
    final SqlType type = SqlTypes.array(SqlTypes.INTEGER);
    final Expression exp = new IntegerLiteral(1);
    // When:
    final KsqlException e = assertThrows(KsqlException.class, () -> new GenericExpressionResolver(type, FIELD_NAME, registry, config, "insert value", false).resolve(exp));
    // Then:
    assertThat(e.getMessage(), containsString("Expected type ARRAY<INTEGER> for field `FOO` but got INTEGER(1)"));
}
Also used : CreateStructExpression(io.confluent.ksql.execution.expression.tree.CreateStructExpression) Expression(io.confluent.ksql.execution.expression.tree.Expression) SqlType(io.confluent.ksql.schema.ksql.types.SqlType) KsqlException(io.confluent.ksql.util.KsqlException) IntegerLiteral(io.confluent.ksql.execution.expression.tree.IntegerLiteral) Test(org.junit.Test)

Example 39 with IntegerLiteral

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

the class AstSanitizerTest method shouldAllowDuplicateLambdaArgumentInSeparateExpression.

@Test
public void shouldAllowDuplicateLambdaArgumentInSeparateExpression() {
    // Given:
    final Statement stmt = givenQuery("SELECT TRANSFORM_ARRAY(Col4, X => X + 5, (X,Y) => Y + 5) FROM TEST1;");
    // When:
    final Query result = (Query) AstSanitizer.sanitize(stmt, META_STORE, true);
    // Then:
    assertThat(result.getSelect(), is(new Select(ImmutableList.of(new SingleColumn(new FunctionCall(FunctionName.of("TRANSFORM_ARRAY"), ImmutableList.of(column(TEST1_NAME, "COL4"), new LambdaFunctionCall(ImmutableList.of("X"), new ArithmeticBinaryExpression(Operator.ADD, new LambdaVariable("X"), new IntegerLiteral(5))), new LambdaFunctionCall(ImmutableList.of("X", "Y"), new ArithmeticBinaryExpression(Operator.ADD, new LambdaVariable("Y"), new IntegerLiteral(5))))), Optional.of(ColumnName.of("KSQL_COL_0")))))));
}
Also used : ArithmeticBinaryExpression(io.confluent.ksql.execution.expression.tree.ArithmeticBinaryExpression) Query(io.confluent.ksql.parser.tree.Query) ParsedStatement(io.confluent.ksql.parser.KsqlParser.ParsedStatement) Statement(io.confluent.ksql.parser.tree.Statement) LambdaFunctionCall(io.confluent.ksql.execution.expression.tree.LambdaFunctionCall) Select(io.confluent.ksql.parser.tree.Select) LambdaVariable(io.confluent.ksql.execution.expression.tree.LambdaVariable) SingleColumn(io.confluent.ksql.parser.tree.SingleColumn) LambdaFunctionCall(io.confluent.ksql.execution.expression.tree.LambdaFunctionCall) FunctionCall(io.confluent.ksql.execution.expression.tree.FunctionCall) IntegerLiteral(io.confluent.ksql.execution.expression.tree.IntegerLiteral) Test(org.junit.Test)

Example 40 with IntegerLiteral

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

the class DefaultSchemaInjectorTest method shouldThrowIfCtasKeyTableElementsNotCompatibleExtraKey.

@Test
public void shouldThrowIfCtasKeyTableElementsNotCompatibleExtraKey() {
    // Given:
    givenFormatsAndProps("protobuf", null, ImmutableMap.of("KEY_SCHEMA_ID", new IntegerLiteral(42)));
    givenDDLSchemaAndFormats(LOGICAL_SCHEMA_EXTRA_KEY, "protobuf", "avro", SerdeFeature.WRAP_SINGLES, SerdeFeature.UNWRAP_SINGLES);
    // When:
    final Exception e = assertThrows(KsqlException.class, () -> injector.inject(ctasStatement));
    // Then:
    // Then:
    assertThat(e.getMessage(), containsString("The following key columns are changed, missing or reordered: " + "[`key1` STRING KEY]. Schema from schema registry is [`key` STRING KEY]"));
}
Also used : IntegerLiteral(io.confluent.ksql.execution.expression.tree.IntegerLiteral) KsqlException(io.confluent.ksql.util.KsqlException) Test(org.junit.Test)

Aggregations

IntegerLiteral (io.confluent.ksql.execution.expression.tree.IntegerLiteral)150 Test (org.junit.Test)146 Expression (io.confluent.ksql.execution.expression.tree.Expression)111 ComparisonExpression (io.confluent.ksql.execution.expression.tree.ComparisonExpression)85 InListExpression (io.confluent.ksql.execution.expression.tree.InListExpression)81 ArithmeticUnaryExpression (io.confluent.ksql.execution.expression.tree.ArithmeticUnaryExpression)66 LogicalBinaryExpression (io.confluent.ksql.execution.expression.tree.LogicalBinaryExpression)62 CreateArrayExpression (io.confluent.ksql.execution.expression.tree.CreateArrayExpression)61 CreateStructExpression (io.confluent.ksql.execution.expression.tree.CreateStructExpression)61 CreateMapExpression (io.confluent.ksql.execution.expression.tree.CreateMapExpression)60 UnqualifiedColumnReferenceExp (io.confluent.ksql.execution.expression.tree.UnqualifiedColumnReferenceExp)46 KsqlException (io.confluent.ksql.util.KsqlException)46 StringLiteral (io.confluent.ksql.execution.expression.tree.StringLiteral)45 ArithmeticBinaryExpression (io.confluent.ksql.execution.expression.tree.ArithmeticBinaryExpression)42 SearchedCaseExpression (io.confluent.ksql.execution.expression.tree.SearchedCaseExpression)38 SubscriptExpression (io.confluent.ksql.execution.expression.tree.SubscriptExpression)38 DereferenceExpression (io.confluent.ksql.execution.expression.tree.DereferenceExpression)30 LambdaFunctionCall (io.confluent.ksql.execution.expression.tree.LambdaFunctionCall)24 FunctionCall (io.confluent.ksql.execution.expression.tree.FunctionCall)23 SimpleCaseExpression (io.confluent.ksql.execution.expression.tree.SimpleCaseExpression)23