Search in sources :

Example 11 with TableElements

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

the class SchemaParserTest method shouldParseQuotedMixedCase.

@Test
public void shouldParseQuotedMixedCase() {
    // Given:
    final String schema = "`End` VARCHAR";
    // When:
    final TableElements elements = parser.parse(schema);
    // Then:
    assertThat(elements, hasItem(new TableElement(ColumnName.of("End"), new Type(SqlTypes.STRING))));
}
Also used : Type(io.confluent.ksql.execution.expression.tree.Type) TableElements(io.confluent.ksql.parser.tree.TableElements) Matchers.containsString(org.hamcrest.Matchers.containsString) TableElement(io.confluent.ksql.parser.tree.TableElement) Test(org.junit.Test)

Example 12 with TableElements

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

the class SchemaParserTest method shouldParseValidSchemaWithKeyField.

@Test
public void shouldParseValidSchemaWithKeyField() {
    // Given:
    final String schema = "K STRING KEY, bar INT";
    // When:
    final TableElements elements = parser.parse(schema);
    // Then:
    assertThat(elements, contains(new TableElement(ColumnName.of("K"), new Type(SqlTypes.STRING), KEY_CONSTRAINT), new TableElement(BAR, new Type(SqlTypes.INTEGER))));
}
Also used : Type(io.confluent.ksql.execution.expression.tree.Type) TableElements(io.confluent.ksql.parser.tree.TableElements) Matchers.containsString(org.hamcrest.Matchers.containsString) TableElement(io.confluent.ksql.parser.tree.TableElement) Test(org.junit.Test)

Example 13 with TableElements

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

the class SchemaParserTest method shouldParseValidSchemaWithHeaderField.

@Test
public void shouldParseValidSchemaWithHeaderField() {
    // Given:
    final String schema = "K STRING HEADERS, bar INT";
    // When:
    final TableElements elements = parser.parse(schema);
    // Then:
    assertThat(elements, contains(new TableElement(ColumnName.of("K"), new Type(SqlTypes.STRING), HEADERS_CONSTRAINT), new TableElement(BAR, new Type(SqlTypes.INTEGER))));
}
Also used : Type(io.confluent.ksql.execution.expression.tree.Type) TableElements(io.confluent.ksql.parser.tree.TableElements) Matchers.containsString(org.hamcrest.Matchers.containsString) TableElement(io.confluent.ksql.parser.tree.TableElement) Test(org.junit.Test)

Example 14 with TableElements

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

the class KsqlParserTest method shouldParseCustomTypesInCreateSource.

@Test
public void shouldParseCustomTypesInCreateSource() {
    // Given:
    final SqlStruct cookie = SqlStruct.builder().field("type", SqlTypes.STRING).build();
    metaStore.registerType("cookie", cookie);
    // When:
    final PreparedStatement<CreateSource> createSource = KsqlParserTestUtil.buildSingleAst("CREATE STREAM foo (cookie COOKIE) WITH (KAFKA_TOPIC='foo', VALUE_FORMAT='AVRO');", metaStore);
    // Then:
    final TableElements elements = createSource.getStatement().getElements();
    assertThat(Iterables.size(elements), is(1));
    final TableElement element = elements.iterator().next();
    assertThat(element.getType().getSqlType(), is(cookie));
}
Also used : SqlStruct(io.confluent.ksql.schema.ksql.types.SqlStruct) TableElements(io.confluent.ksql.parser.tree.TableElements) CreateSource(io.confluent.ksql.parser.tree.CreateSource) TableElement(io.confluent.ksql.parser.tree.TableElement) Test(org.junit.Test)

Example 15 with TableElements

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

the class SqlFormatterTest method shouldFormatTableElementsNamedAfterReservedWords.

@Test
public void shouldFormatTableElementsNamedAfterReservedWords() {
    // Given:
    final TableElements tableElements = TableElements.of(new TableElement(ColumnName.of("GROUP"), new Type(SqlTypes.STRING)), new TableElement(ColumnName.of("Having"), new Type(SqlTypes.STRING)));
    final CreateStream createStream = new CreateStream(TEST, tableElements, false, false, SOME_WITH_PROPS, false);
    // When:
    final String sql = SqlFormatter.formatSql(createStream);
    // Then:
    assertThat("literal escaping failure", sql, containsString("`GROUP` STRING"));
    assertThat("lowercase literal escaping failure", sql, containsString("`Having` STRING"));
    assertValidSql(sql);
}
Also used : SqlType(io.confluent.ksql.schema.ksql.types.SqlType) Type(io.confluent.ksql.execution.expression.tree.Type) TableElements(io.confluent.ksql.parser.tree.TableElements) CreateStream(io.confluent.ksql.parser.tree.CreateStream) StringContains.containsString(org.hamcrest.core.StringContains.containsString) TableElement(io.confluent.ksql.parser.tree.TableElement) Test(org.junit.Test)

Aggregations

TableElements (io.confluent.ksql.parser.tree.TableElements)15 TableElement (io.confluent.ksql.parser.tree.TableElement)11 Test (org.junit.Test)11 Type (io.confluent.ksql.execution.expression.tree.Type)9 Matchers.containsString (org.hamcrest.Matchers.containsString)8 CreateSource (io.confluent.ksql.parser.tree.CreateSource)3 KsqlException (io.confluent.ksql.util.KsqlException)3 CreateSourceProperties (io.confluent.ksql.parser.properties.with.CreateSourceProperties)2 CreateStream (io.confluent.ksql.parser.tree.CreateStream)2 CreateTable (io.confluent.ksql.parser.tree.CreateTable)2 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 Sets (com.google.common.collect.Sets)1 SetView (com.google.common.collect.Sets.SetView)1 KsqlExecutionContext (io.confluent.ksql.KsqlExecutionContext)1 CreateSourceCommand (io.confluent.ksql.execution.ddl.commands.CreateSourceCommand)1 TypeRegistry (io.confluent.ksql.metastore.TypeRegistry)1 ColumnName (io.confluent.ksql.name.ColumnName)1