Search in sources :

Example 16 with StringLiteral

use of io.confluent.ksql.parser.tree.StringLiteral in project ksql by confluentinc.

the class ExpressionFormatterTest method shouldFormatFunctionCallWithCount.

@Test
public void shouldFormatFunctionCallWithCount() {
    final FunctionCall functionCall = new FunctionCall(QualifiedName.of("function", "COUNT"), Collections.singletonList(new StringLiteral("name")));
    assertThat(ExpressionFormatter.formatExpression(functionCall), equalTo("function.COUNT('name')"));
}
Also used : StringLiteral(io.confluent.ksql.parser.tree.StringLiteral) FunctionCall(io.confluent.ksql.parser.tree.FunctionCall) Test(org.junit.Test)

Example 17 with StringLiteral

use of io.confluent.ksql.parser.tree.StringLiteral in project ksql by confluentinc.

the class ExpressionFormatterTest method shouldFormatFunctionCallWithWindow.

@Test
public void shouldFormatFunctionCallWithWindow() {
    final FunctionCall functionCall = new FunctionCall(new NodeLocation(1, 1), QualifiedName.of("function"), Optional.of(new Window("window", new WindowExpression("blah", new TumblingWindowExpression(1L, TimeUnit.SECONDS)))), false, Collections.singletonList(new StringLiteral("name")));
    assertThat(ExpressionFormatter.formatExpression(functionCall), equalTo("function('name') OVER  WINDOW  WINDOW blah  TUMBLING ( SIZE 1 SECONDS ) "));
}
Also used : Window(io.confluent.ksql.parser.tree.Window) NodeLocation(io.confluent.ksql.parser.tree.NodeLocation) StringLiteral(io.confluent.ksql.parser.tree.StringLiteral) WindowExpression(io.confluent.ksql.parser.tree.WindowExpression) TumblingWindowExpression(io.confluent.ksql.parser.tree.TumblingWindowExpression) HoppingWindowExpression(io.confluent.ksql.parser.tree.HoppingWindowExpression) FunctionCall(io.confluent.ksql.parser.tree.FunctionCall) TumblingWindowExpression(io.confluent.ksql.parser.tree.TumblingWindowExpression) Test(org.junit.Test)

Example 18 with StringLiteral

use of io.confluent.ksql.parser.tree.StringLiteral in project ksql by confluentinc.

the class AstBuilder method visitNormalize.

@Override
public Node visitNormalize(SqlBaseParser.NormalizeContext context) {
    Expression str = (Expression) visit(context.valueExpression());
    String normalForm = Optional.ofNullable(context.normalForm()).map(ParserRuleContext::getText).orElse("NFC");
    return new FunctionCall(getLocation(context), QualifiedName.of("NORMALIZE"), ImmutableList.of(str, new StringLiteral(getLocation(context), normalForm)));
}
Also used : StringLiteral(io.confluent.ksql.parser.tree.StringLiteral) InListExpression(io.confluent.ksql.parser.tree.InListExpression) NullIfExpression(io.confluent.ksql.parser.tree.NullIfExpression) SimpleCaseExpression(io.confluent.ksql.parser.tree.SimpleCaseExpression) ComparisonExpression(io.confluent.ksql.parser.tree.ComparisonExpression) DereferenceExpression(io.confluent.ksql.parser.tree.DereferenceExpression) Expression(io.confluent.ksql.parser.tree.Expression) LogicalBinaryExpression(io.confluent.ksql.parser.tree.LogicalBinaryExpression) TumblingWindowExpression(io.confluent.ksql.parser.tree.TumblingWindowExpression) ArithmeticBinaryExpression(io.confluent.ksql.parser.tree.ArithmeticBinaryExpression) NotExpression(io.confluent.ksql.parser.tree.NotExpression) HoppingWindowExpression(io.confluent.ksql.parser.tree.HoppingWindowExpression) SubscriptExpression(io.confluent.ksql.parser.tree.SubscriptExpression) SessionWindowExpression(io.confluent.ksql.parser.tree.SessionWindowExpression) SearchedCaseExpression(io.confluent.ksql.parser.tree.SearchedCaseExpression) LambdaExpression(io.confluent.ksql.parser.tree.LambdaExpression) SubqueryExpression(io.confluent.ksql.parser.tree.SubqueryExpression) WindowExpression(io.confluent.ksql.parser.tree.WindowExpression) ArithmeticUnaryExpression(io.confluent.ksql.parser.tree.ArithmeticUnaryExpression) FunctionCall(io.confluent.ksql.parser.tree.FunctionCall)

Example 19 with StringLiteral

use of io.confluent.ksql.parser.tree.StringLiteral in project ksql by confluentinc.

the class QueryEngine method maybeAddFieldsFromSchemaRegistry.

private Pair<DdlStatement, String> maybeAddFieldsFromSchemaRegistry(AbstractStreamCreateStatement streamCreateStatement) {
    if (streamCreateStatement.getProperties().containsKey(DdlConfig.TOPIC_NAME_PROPERTY)) {
        String ksqlRegisteredTopicName = StringUtil.cleanQuotes(streamCreateStatement.getProperties().get(DdlConfig.TOPIC_NAME_PROPERTY).toString().toUpperCase());
        KsqlTopic ksqlTopic = ksqlEngine.getMetaStore().getTopic(ksqlRegisteredTopicName);
        if (ksqlTopic == null) {
            throw new KsqlException(String.format("Could not find %s topic in the metastore.", ksqlRegisteredTopicName));
        }
        Map<String, Expression> newProperties = new HashMap<>();
        newProperties.put(DdlConfig.KAFKA_TOPIC_NAME_PROPERTY, new StringLiteral(ksqlTopic.getKafkaTopicName()));
        newProperties.put(DdlConfig.VALUE_FORMAT_PROPERTY, new StringLiteral(ksqlTopic.getKsqlTopicSerDe().getSerDe().toString()));
        streamCreateStatement = streamCreateStatement.copyWith(streamCreateStatement.getElements(), newProperties);
    }
    Pair<AbstractStreamCreateStatement, String> avroCheckResult = new AvroUtil().checkAndSetAvroSchema(streamCreateStatement, new HashMap<>(), ksqlEngine.getSchemaRegistryClient());
    if (avroCheckResult.getRight() != null) {
        if (avroCheckResult.getLeft() instanceof CreateStream) {
            return new Pair<>((CreateStream) avroCheckResult.getLeft(), avroCheckResult.getRight());
        } else if (avroCheckResult.getLeft() instanceof CreateTable) {
            return new Pair<>((CreateTable) avroCheckResult.getLeft(), avroCheckResult.getRight());
        }
    }
    return new Pair<>(null, null);
}
Also used : HashMap(java.util.HashMap) CreateTable(io.confluent.ksql.parser.tree.CreateTable) CreateStream(io.confluent.ksql.parser.tree.CreateStream) AbstractStreamCreateStatement(io.confluent.ksql.parser.tree.AbstractStreamCreateStatement) KsqlException(io.confluent.ksql.util.KsqlException) AvroUtil(io.confluent.ksql.util.AvroUtil) StringLiteral(io.confluent.ksql.parser.tree.StringLiteral) Expression(io.confluent.ksql.parser.tree.Expression) KsqlTopic(io.confluent.ksql.metastore.KsqlTopic) Pair(io.confluent.ksql.util.Pair)

Example 20 with StringLiteral

use of io.confluent.ksql.parser.tree.StringLiteral in project ksql by confluentinc.

the class CommandFactoriesTest method shouldFailCreateTableIfTimestampColumnNameIsIncorrect.

@Test
public void shouldFailCreateTableIfTimestampColumnNameIsIncorrect() {
    HashMap<String, Expression> tableProperties = new HashMap<>();
    tableProperties.putAll(properties);
    tableProperties.put(DdlConfig.TIMESTAMP_NAME_PROPERTY, new StringLiteral("COL3"));
    try {
        final DdlCommand result = commandFactories.create(sqlExpression, new CreateTable(QualifiedName.of("foo"), Arrays.asList(new TableElement("COL1", "BIGINT"), new TableElement("COL2", "VARCHAR")), true, tableProperties), Collections.emptyMap());
    } catch (KsqlException e) {
        assertThat(e.getMessage(), equalTo("No column with the provided timestamp column name in the WITH clause, COL3, exists in the defined schema."));
    }
}
Also used : StringLiteral(io.confluent.ksql.parser.tree.StringLiteral) Expression(io.confluent.ksql.parser.tree.Expression) HashMap(java.util.HashMap) CreateTable(io.confluent.ksql.parser.tree.CreateTable) EasyMock.anyString(org.easymock.EasyMock.anyString) KsqlException(io.confluent.ksql.util.KsqlException) TableElement(io.confluent.ksql.parser.tree.TableElement) Test(org.junit.Test)

Aggregations

StringLiteral (io.confluent.ksql.parser.tree.StringLiteral)21 Test (org.junit.Test)16 Expression (io.confluent.ksql.parser.tree.Expression)8 HashMap (java.util.HashMap)7 LongLiteral (io.confluent.ksql.parser.tree.LongLiteral)5 TableElement (io.confluent.ksql.parser.tree.TableElement)5 CreateTable (io.confluent.ksql.parser.tree.CreateTable)4 FunctionCall (io.confluent.ksql.parser.tree.FunctionCall)4 WhenClause (io.confluent.ksql.parser.tree.WhenClause)4 KsqlException (io.confluent.ksql.util.KsqlException)4 SearchedCaseExpression (io.confluent.ksql.parser.tree.SearchedCaseExpression)3 SimpleCaseExpression (io.confluent.ksql.parser.tree.SimpleCaseExpression)3 CreateStream (io.confluent.ksql.parser.tree.CreateStream)2 HoppingWindowExpression (io.confluent.ksql.parser.tree.HoppingWindowExpression)2 LambdaExpression (io.confluent.ksql.parser.tree.LambdaExpression)2 LogicalBinaryExpression (io.confluent.ksql.parser.tree.LogicalBinaryExpression)2 NodeLocation (io.confluent.ksql.parser.tree.NodeLocation)2 RegisterTopic (io.confluent.ksql.parser.tree.RegisterTopic)2 TumblingWindowExpression (io.confluent.ksql.parser.tree.TumblingWindowExpression)2 WindowExpression (io.confluent.ksql.parser.tree.WindowExpression)2