Search in sources :

Example 11 with Type

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

the class ExpressionFormatterTest method shouldFormatStructWithColumnWithReservedWordName.

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

Example 12 with Type

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

the class SqlTypeParser method getType.

public Type getType(final SqlBaseParser.TypeContext type) {
    final Optional<NodeLocation> location = ParserUtil.getLocation(type);
    final SqlType sqlType = getSqlType(type);
    return new Type(location, sqlType);
}
Also used : Type(io.confluent.ksql.execution.expression.tree.Type) SqlPrimitiveType(io.confluent.ksql.schema.ksql.types.SqlPrimitiveType) SqlType(io.confluent.ksql.schema.ksql.types.SqlType) NodeLocation(io.confluent.ksql.parser.NodeLocation) SqlType(io.confluent.ksql.schema.ksql.types.SqlType)

Example 13 with Type

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

the class ExpressionTreeRewriterTest method shouldRewriteType.

@Test
public void shouldRewriteType() {
    // Given:
    final Type type = new Type(SqlPrimitiveType.of("INTEGER"));
    // When:
    final Expression rewritten = expressionRewriter.rewrite(type, context);
    // Then:
    assertThat(rewritten, is(type));
}
Also used : SqlPrimitiveType(io.confluent.ksql.schema.ksql.types.SqlPrimitiveType) Type(io.confluent.ksql.execution.expression.tree.Type) ArithmeticBinaryExpression(io.confluent.ksql.execution.expression.tree.ArithmeticBinaryExpression) LogicalBinaryExpression(io.confluent.ksql.execution.expression.tree.LogicalBinaryExpression) Expression(io.confluent.ksql.execution.expression.tree.Expression) CreateMapExpression(io.confluent.ksql.execution.expression.tree.CreateMapExpression) DereferenceExpression(io.confluent.ksql.execution.expression.tree.DereferenceExpression) ArithmeticUnaryExpression(io.confluent.ksql.execution.expression.tree.ArithmeticUnaryExpression) CreateArrayExpression(io.confluent.ksql.execution.expression.tree.CreateArrayExpression) CreateStructExpression(io.confluent.ksql.execution.expression.tree.CreateStructExpression) NotExpression(io.confluent.ksql.execution.expression.tree.NotExpression) SimpleCaseExpression(io.confluent.ksql.execution.expression.tree.SimpleCaseExpression) SubscriptExpression(io.confluent.ksql.execution.expression.tree.SubscriptExpression) InListExpression(io.confluent.ksql.execution.expression.tree.InListExpression) ComparisonExpression(io.confluent.ksql.execution.expression.tree.ComparisonExpression) SearchedCaseExpression(io.confluent.ksql.execution.expression.tree.SearchedCaseExpression) Test(org.junit.Test)

Example 14 with Type

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

the class CreateSourceFactoryTest method shouldThrowInCreateTableOrReplaceSource.

@Test
public void shouldThrowInCreateTableOrReplaceSource() {
    // Given:
    final CreateTable ddlStatement = new CreateTable(TABLE_NAME, TableElements.of(tableElement("COL1", new Type(BIGINT), PRIMARY_KEY_CONSTRAINT), tableElement("COL2", new Type(SqlTypes.STRING))), true, false, withProperties, true);
    // When:
    final Exception e = assertThrows(KsqlException.class, () -> createSourceFactory.createTableCommand(ddlStatement, ksqlConfig));
    // Then:
    assertThat(e.getMessage(), containsString("Cannot add table 'table_bob': CREATE OR REPLACE is not supported on " + "source tables."));
}
Also used : DataSourceType(io.confluent.ksql.metastore.model.DataSource.DataSourceType) Type(io.confluent.ksql.execution.expression.tree.Type) CreateTable(io.confluent.ksql.parser.tree.CreateTable) KsqlException(io.confluent.ksql.util.KsqlException) Test(org.junit.Test)

Example 15 with Type

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

the class CreateSourceFactoryTest method shouldThrowOnWindowEndValueColumn.

@Test
public void shouldThrowOnWindowEndValueColumn() {
    // Given:
    final CreateStream statement = new CreateStream(SOME_NAME, TableElements.of(tableElement(WINDOWEND_NAME.text(), new Type(BIGINT))), false, true, withProperties, false);
    // When:
    final Exception e = assertThrows(KsqlException.class, () -> createSourceFactory.createStreamCommand(statement, ksqlConfig));
    // Then:
    assertThat(e.getMessage(), containsString("'WINDOWEND' is a reserved column name."));
}
Also used : DataSourceType(io.confluent.ksql.metastore.model.DataSource.DataSourceType) Type(io.confluent.ksql.execution.expression.tree.Type) CreateStream(io.confluent.ksql.parser.tree.CreateStream) KsqlException(io.confluent.ksql.util.KsqlException) 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