Search in sources :

Example 56 with Type

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

the class ExpressionFormatterTest method shouldFormatCast.

@Test
public void shouldFormatCast() {
    // Given:
    final Cast cast = new Cast(new LongLiteral(1), new Type(SqlTypes.DOUBLE));
    // When:
    final String result = ExpressionFormatter.formatExpression(cast);
    // Then:
    assertThat(result, equalTo("CAST(1 AS DOUBLE)"));
}
Also used : Cast(io.confluent.ksql.execution.expression.tree.Cast) Type(io.confluent.ksql.execution.expression.tree.Type) LongLiteral(io.confluent.ksql.execution.expression.tree.LongLiteral) Test(org.junit.Test)

Example 57 with Type

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

the class ExpressionFormatterTest method shouldFormatStruct.

@Test
public void shouldFormatStruct() {
    final SqlStruct struct = SqlStruct.builder().field("field1", SqlTypes.INTEGER).field("field2", SqlTypes.STRING).build();
    assertThat(ExpressionFormatter.formatExpression(new Type(struct)), equalTo("STRUCT<field1 INTEGER, field2 STRING>"));
}
Also used : Type(io.confluent.ksql.execution.expression.tree.Type) SqlStruct(io.confluent.ksql.schema.ksql.types.SqlStruct) Test(org.junit.Test)

Example 58 with Type

use of io.confluent.ksql.execution.expression.tree.Type 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)

Example 59 with Type

use of io.confluent.ksql.execution.expression.tree.Type 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 60 with Type

use of io.confluent.ksql.execution.expression.tree.Type 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)

Aggregations

Type (io.confluent.ksql.execution.expression.tree.Type)73 Test (org.junit.Test)71 SqlPrimitiveType (io.confluent.ksql.schema.ksql.types.SqlPrimitiveType)23 DataSourceType (io.confluent.ksql.metastore.model.DataSource.DataSourceType)19 Matchers.containsString (org.hamcrest.Matchers.containsString)16 Cast (io.confluent.ksql.execution.expression.tree.Cast)13 CreateStream (io.confluent.ksql.parser.tree.CreateStream)13 ArithmeticBinaryExpression (io.confluent.ksql.execution.expression.tree.ArithmeticBinaryExpression)12 ArithmeticUnaryExpression (io.confluent.ksql.execution.expression.tree.ArithmeticUnaryExpression)12 ComparisonExpression (io.confluent.ksql.execution.expression.tree.ComparisonExpression)12 CreateArrayExpression (io.confluent.ksql.execution.expression.tree.CreateArrayExpression)12 CreateMapExpression (io.confluent.ksql.execution.expression.tree.CreateMapExpression)12 CreateStructExpression (io.confluent.ksql.execution.expression.tree.CreateStructExpression)12 DereferenceExpression (io.confluent.ksql.execution.expression.tree.DereferenceExpression)12 Expression (io.confluent.ksql.execution.expression.tree.Expression)12 InListExpression (io.confluent.ksql.execution.expression.tree.InListExpression)12 LogicalBinaryExpression (io.confluent.ksql.execution.expression.tree.LogicalBinaryExpression)12 SearchedCaseExpression (io.confluent.ksql.execution.expression.tree.SearchedCaseExpression)12 StringLiteral (io.confluent.ksql.execution.expression.tree.StringLiteral)12 SubscriptExpression (io.confluent.ksql.execution.expression.tree.SubscriptExpression)12