Search in sources :

Example 6 with DefaultKsqlParser

use of io.confluent.ksql.parser.DefaultKsqlParser in project ksql by confluentinc.

the class ExpressionParseTestUtil method parseExpression.

public static Expression parseExpression(final String asText, final MetaStore metaStore) {
    final KsqlParser parser = new DefaultKsqlParser();
    final String ksql = String.format("SELECT %s FROM test1;", asText);
    final ParsedStatement parsedStatement = parser.parse(ksql).get(0);
    final PreparedStatement preparedStatement = parser.prepare(parsedStatement, metaStore);
    final SingleColumn singleColumn = (SingleColumn) ((Query) preparedStatement.getStatement()).getSelect().getSelectItems().get(0);
    return singleColumn.getExpression();
}
Also used : DefaultKsqlParser(io.confluent.ksql.parser.DefaultKsqlParser) KsqlParser(io.confluent.ksql.parser.KsqlParser) ParsedStatement(io.confluent.ksql.parser.KsqlParser.ParsedStatement) PreparedStatement(io.confluent.ksql.parser.KsqlParser.PreparedStatement) SingleColumn(io.confluent.ksql.parser.tree.SingleColumn) DefaultKsqlParser(io.confluent.ksql.parser.DefaultKsqlParser)

Example 7 with DefaultKsqlParser

use of io.confluent.ksql.parser.DefaultKsqlParser in project ksql by confluentinc.

the class TopicCreateInjectorTest method setUp.

@Before
public void setUp() {
    parser = new DefaultKsqlParser();
    metaStore = new MetaStoreImpl(new InternalFunctionRegistry());
    overrides = new HashMap<>();
    config = new KsqlConfig(new HashMap<>());
    injector = new TopicCreateInjector(topicClient, metaStore);
    final KsqlTopic sourceTopic = new KsqlTopic("source", KeyFormat.nonWindowed(FormatInfo.of(FormatFactory.KAFKA.name()), SerdeFeatures.of()), ValueFormat.of(FormatInfo.of(FormatFactory.JSON.name()), SerdeFeatures.of()));
    final KsqlStream<?> source = new KsqlStream<>("", SourceName.of("SOURCE"), SCHEMA, Optional.empty(), false, sourceTopic, false);
    metaStore.putSource(source, false);
    final KsqlTopic joinTopic = new KsqlTopic("jSource", KeyFormat.nonWindowed(FormatInfo.of(FormatFactory.KAFKA.name()), SerdeFeatures.of()), ValueFormat.of(FormatInfo.of(FormatFactory.JSON.name()), SerdeFeatures.of()));
    final KsqlStream<?> joinSource = new KsqlStream<>("", SourceName.of("J_SOURCE"), SCHEMA, Optional.empty(), false, joinTopic, false);
    metaStore.putSource(joinSource, false);
    when(topicClient.describeTopic("source")).thenReturn(sourceDescription);
    when(topicClient.isTopicExists("source")).thenReturn(true);
    when(builder.withName(any())).thenReturn(builder);
    when(builder.withWithClause(any(), any(), any())).thenReturn(builder);
    when(builder.withSource(any())).thenReturn(builder);
    when(builder.build()).thenReturn(new TopicProperties("name", 1, (short) 1));
}
Also used : KsqlStream(io.confluent.ksql.metastore.model.KsqlStream) HashMap(java.util.HashMap) MetaStoreImpl(io.confluent.ksql.metastore.MetaStoreImpl) KsqlConfig(io.confluent.ksql.util.KsqlConfig) InternalFunctionRegistry(io.confluent.ksql.function.InternalFunctionRegistry) DefaultKsqlParser(io.confluent.ksql.parser.DefaultKsqlParser) KsqlTopic(io.confluent.ksql.execution.ddl.commands.KsqlTopic) Before(org.junit.Before)

Aggregations

DefaultKsqlParser (io.confluent.ksql.parser.DefaultKsqlParser)7 ParsedStatement (io.confluent.ksql.parser.KsqlParser.ParsedStatement)5 KsqlParser (io.confluent.ksql.parser.KsqlParser)3 AstBuilder (io.confluent.ksql.parser.AstBuilder)2 IOException (java.io.IOException)2 KsqlTopic (io.confluent.ksql.execution.ddl.commands.KsqlTopic)1 DefaultFormatInjector (io.confluent.ksql.format.DefaultFormatInjector)1 InternalFunctionRegistry (io.confluent.ksql.function.InternalFunctionRegistry)1 MetaStoreImpl (io.confluent.ksql.metastore.MetaStoreImpl)1 KsqlStream (io.confluent.ksql.metastore.model.KsqlStream)1 PreparedStatement (io.confluent.ksql.parser.KsqlParser.PreparedStatement)1 ParseFailedException (io.confluent.ksql.parser.exception.ParseFailedException)1 CreateSourceProperties (io.confluent.ksql.parser.properties.with.CreateSourceProperties)1 CreateSource (io.confluent.ksql.parser.tree.CreateSource)1 SingleColumn (io.confluent.ksql.parser.tree.SingleColumn)1 LogicalSchema (io.confluent.ksql.schema.ksql.LogicalSchema)1 Format (io.confluent.ksql.serde.Format)1 FormatInfo (io.confluent.ksql.serde.FormatInfo)1 SerdeFeatures (io.confluent.ksql.serde.SerdeFeatures)1 ConfiguredStatement (io.confluent.ksql.statement.ConfiguredStatement)1