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))));
}
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))));
}
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))));
}
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));
}
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);
}
Aggregations