Search in sources :

Example 1 with StringLiteral

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

the class CommandFactoriesTest method shouldFailCreateTableIfKeyNameIsIncorrect.

@Test
public void shouldFailCreateTableIfKeyNameIsIncorrect() {
    HashMap<String, Expression> tableProperties = new HashMap<>();
    tableProperties.putAll(properties);
    tableProperties.put(DdlConfig.KEY_NAME_PROPERTY, new StringLiteral("COL3"));
    try {
        final DdlCommand result = commandFactories.create(sqlExpression, new CreateTable(QualifiedName.of("foo"), Arrays.asList(new TableElement("COL1", "BIGINT"), new TableElement("COL2", "VARCHAR")), true, tableProperties), Collections.emptyMap());
    } catch (KsqlException e) {
        assertThat(e.getMessage(), equalTo("No column with the provided key column name in the " + "WITH clause, COL3, exists in the defined schema."));
    }
}
Also used : StringLiteral(io.confluent.ksql.parser.tree.StringLiteral) Expression(io.confluent.ksql.parser.tree.Expression) HashMap(java.util.HashMap) CreateTable(io.confluent.ksql.parser.tree.CreateTable) EasyMock.anyString(org.easymock.EasyMock.anyString) KsqlException(io.confluent.ksql.util.KsqlException) TableElement(io.confluent.ksql.parser.tree.TableElement) Test(org.junit.Test)

Example 2 with StringLiteral

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

the class CommandFactoriesTest method before.

@Before
public void before() {
    properties.put(DdlConfig.VALUE_FORMAT_PROPERTY, new StringLiteral("JSON"));
    properties.put(DdlConfig.KAFKA_TOPIC_NAME_PROPERTY, new StringLiteral("topic"));
    EasyMock.expect(topicClient.isTopicExists(anyString())).andReturn(true);
    EasyMock.replay(topicClient);
}
Also used : StringLiteral(io.confluent.ksql.parser.tree.StringLiteral) Before(org.junit.Before)

Example 3 with StringLiteral

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

the class CommandFactoriesTest method shouldCreateCommandForCreateTable.

@Test
public void shouldCreateCommandForCreateTable() {
    HashMap<String, Expression> tableProperties = new HashMap<>();
    tableProperties.putAll(properties);
    tableProperties.put(DdlConfig.KEY_NAME_PROPERTY, new StringLiteral("COL1"));
    final DdlCommand result = commandFactories.create(sqlExpression, new CreateTable(QualifiedName.of("foo"), Arrays.asList(new TableElement("COL1", "BIGINT"), new TableElement("COL2", "VARCHAR")), true, tableProperties), Collections.emptyMap());
    assertThat(result, instanceOf(CreateTableCommand.class));
}
Also used : StringLiteral(io.confluent.ksql.parser.tree.StringLiteral) Expression(io.confluent.ksql.parser.tree.Expression) HashMap(java.util.HashMap) CreateTable(io.confluent.ksql.parser.tree.CreateTable) EasyMock.anyString(org.easymock.EasyMock.anyString) TableElement(io.confluent.ksql.parser.tree.TableElement) Test(org.junit.Test)

Example 4 with StringLiteral

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

the class AvroUtil method addAvroFields.

private AbstractStreamCreateStatement addAvroFields(final AbstractStreamCreateStatement abstractStreamCreateStatement, final Schema schema, int schemaId) {
    List<TableElement> elements = new ArrayList<>();
    for (Field field : schema.fields()) {
        TableElement tableElement = new TableElement(field.name().toUpperCase(), SchemaUtil.getSqlTypeName(field.schema()));
        elements.add(tableElement);
    }
    StringLiteral schemaIdLiteral = new StringLiteral(String.format("%d", schemaId));
    Map<String, Expression> properties = new HashMap<>(abstractStreamCreateStatement.getProperties());
    if (!abstractStreamCreateStatement.getProperties().containsKey(KsqlConstants.AVRO_SCHEMA_ID)) {
        properties.put(KsqlConstants.AVRO_SCHEMA_ID, schemaIdLiteral);
    }
    return abstractStreamCreateStatement.copyWith(elements, properties);
}
Also used : Field(org.apache.kafka.connect.data.Field) StringLiteral(io.confluent.ksql.parser.tree.StringLiteral) Expression(io.confluent.ksql.parser.tree.Expression) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) TableElement(io.confluent.ksql.parser.tree.TableElement)

Example 5 with StringLiteral

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

the class ExpressionFormatterTest method shouldFormatBetweenPredicate.

@Test
public void shouldFormatBetweenPredicate() {
    final BetweenPredicate predicate = new BetweenPredicate(new StringLiteral("blah"), new LongLiteral("5"), new LongLiteral("10"));
    assertThat(ExpressionFormatter.formatExpression(predicate), equalTo("('blah' BETWEEN 5 AND 10)"));
}
Also used : BetweenPredicate(io.confluent.ksql.parser.tree.BetweenPredicate) StringLiteral(io.confluent.ksql.parser.tree.StringLiteral) LongLiteral(io.confluent.ksql.parser.tree.LongLiteral) Test(org.junit.Test)

Aggregations

StringLiteral (io.confluent.ksql.parser.tree.StringLiteral)21 Test (org.junit.Test)16 Expression (io.confluent.ksql.parser.tree.Expression)8 HashMap (java.util.HashMap)7 LongLiteral (io.confluent.ksql.parser.tree.LongLiteral)5 TableElement (io.confluent.ksql.parser.tree.TableElement)5 CreateTable (io.confluent.ksql.parser.tree.CreateTable)4 FunctionCall (io.confluent.ksql.parser.tree.FunctionCall)4 WhenClause (io.confluent.ksql.parser.tree.WhenClause)4 KsqlException (io.confluent.ksql.util.KsqlException)4 SearchedCaseExpression (io.confluent.ksql.parser.tree.SearchedCaseExpression)3 SimpleCaseExpression (io.confluent.ksql.parser.tree.SimpleCaseExpression)3 CreateStream (io.confluent.ksql.parser.tree.CreateStream)2 HoppingWindowExpression (io.confluent.ksql.parser.tree.HoppingWindowExpression)2 LambdaExpression (io.confluent.ksql.parser.tree.LambdaExpression)2 LogicalBinaryExpression (io.confluent.ksql.parser.tree.LogicalBinaryExpression)2 NodeLocation (io.confluent.ksql.parser.tree.NodeLocation)2 RegisterTopic (io.confluent.ksql.parser.tree.RegisterTopic)2 TumblingWindowExpression (io.confluent.ksql.parser.tree.TumblingWindowExpression)2 WindowExpression (io.confluent.ksql.parser.tree.WindowExpression)2