Search in sources :

Example 1 with SqlCommand

use of io.confluent.ksql.tools.migrations.util.CommandParser.SqlCommand in project ksql by confluentinc.

the class CommandParserTest method shouldParseInsertNullValuesStatement.

@Test
public void shouldParseInsertNullValuesStatement() {
    // When:
    List<SqlCommand> commands = parse("INSERT INTO FOO VALUES (NULL);");
    // Then:
    assertThat(commands.size(), is(1));
    assertThat(commands.get(0), instanceOf(SqlInsertValues.class));
    final SqlInsertValues insertValues = (SqlInsertValues) commands.get(0);
    assertThat(insertValues.getSourceName(), is("`FOO`"));
    assertThat(insertValues.getColumns(), is(Collections.emptyList()));
    assertThat(insertValues.getValues().size(), is(1));
    assertNull(toFieldType(insertValues.getValues().get(0)));
}
Also used : SqlInsertValues(io.confluent.ksql.tools.migrations.util.CommandParser.SqlInsertValues) SqlCommand(io.confluent.ksql.tools.migrations.util.CommandParser.SqlCommand) Test(org.junit.Test)

Example 2 with SqlCommand

use of io.confluent.ksql.tools.migrations.util.CommandParser.SqlCommand in project ksql by confluentinc.

the class CommandParserTest method shouldDefineStatementWithVariable.

@Test
public void shouldDefineStatementWithVariable() {
    // Given:
    final String defineVar = "DEFiNe word = 'walk${suffix}';";
    // When:
    List<SqlCommand> commands = parse(defineVar, ImmutableMap.of("suffix", "ing"));
    // Then:
    assertThat(commands.size(), is(1));
    assertThat(commands.get(0), instanceOf(SqlDefineVariableCommand.class));
    assertThat(((SqlDefineVariableCommand) commands.get(0)).getVariable(), is("word"));
    assertThat(((SqlDefineVariableCommand) commands.get(0)).getValue(), is("walking"));
}
Also used : Matchers.containsString(org.hamcrest.Matchers.containsString) SqlDefineVariableCommand(io.confluent.ksql.tools.migrations.util.CommandParser.SqlDefineVariableCommand) SqlCommand(io.confluent.ksql.tools.migrations.util.CommandParser.SqlCommand) Test(org.junit.Test)

Example 3 with SqlCommand

use of io.confluent.ksql.tools.migrations.util.CommandParser.SqlCommand in project ksql by confluentinc.

the class CommandParserTest method shouldParseInsertValuesStatementWithExplicitFields.

@Test
public void shouldParseInsertValuesStatementWithExplicitFields() {
    // When:
    List<SqlCommand> commands = parse("INSERT INTO `foo` (col1, col2) VALUES (55, '40');");
    // Then:
    assertThat(commands.size(), is(1));
    assertThat(commands.get(0), instanceOf(SqlInsertValues.class));
    final SqlInsertValues insertValues = (SqlInsertValues) commands.get(0);
    assertThat(insertValues.getSourceName(), is("`foo`"));
    assertThat(insertValues.getColumns(), is(ImmutableList.of("COL1", "COL2")));
    assertThat(insertValues.getValues().size(), is(2));
    assertThat(toFieldType(insertValues.getValues().get(0)), is(55));
    assertThat(toFieldType(insertValues.getValues().get(1)), is("40"));
}
Also used : SqlInsertValues(io.confluent.ksql.tools.migrations.util.CommandParser.SqlInsertValues) SqlCommand(io.confluent.ksql.tools.migrations.util.CommandParser.SqlCommand) Test(org.junit.Test)

Example 4 with SqlCommand

use of io.confluent.ksql.tools.migrations.util.CommandParser.SqlCommand in project ksql by confluentinc.

the class CommandParserTest method shouldParseInsertValuesStatementWithVariables.

@Test
public void shouldParseInsertValuesStatementWithVariables() {
    // When:
    List<SqlCommand> commands = parse("INSERT INTO ${stream} VALUES (${num});", ImmutableMap.of("stream", "FOO", "num", "55"));
    // Then:
    assertThat(commands.size(), is(1));
    assertThat(commands.get(0), instanceOf(SqlInsertValues.class));
    final SqlInsertValues insertValues = (SqlInsertValues) commands.get(0);
    assertThat(insertValues.getSourceName(), is("`FOO`"));
    assertThat(insertValues.getColumns().size(), is(0));
    assertThat(insertValues.getValues().size(), is(1));
    assertThat(toFieldType(insertValues.getValues().get(0)), is(55));
}
Also used : SqlInsertValues(io.confluent.ksql.tools.migrations.util.CommandParser.SqlInsertValues) SqlCommand(io.confluent.ksql.tools.migrations.util.CommandParser.SqlCommand) Test(org.junit.Test)

Example 5 with SqlCommand

use of io.confluent.ksql.tools.migrations.util.CommandParser.SqlCommand in project ksql by confluentinc.

the class CommandParserTest method shouldParseDropConnectorStatement.

@Test
public void shouldParseDropConnectorStatement() {
    // Given:
    // The space at the end is to make sure that the regex doesn't capture it as a part of the name
    final String dropConnector = "DRoP CONNEcTOR `jdbc-connector` ;";
    // When:
    List<SqlCommand> commands = parse(dropConnector);
    // Then:
    assertThat(commands.size(), is(1));
    assertThat(commands.get(0).getCommand(), is(dropConnector));
    assertThat(commands.get(0), instanceOf(SqlDropConnectorStatement.class));
    assertThat(commands.get(0).getCommand(), is(dropConnector));
    assertThat(((SqlDropConnectorStatement) commands.get(0)).getName(), is("`jdbc-connector`"));
}
Also used : SqlDropConnectorStatement(io.confluent.ksql.tools.migrations.util.CommandParser.SqlDropConnectorStatement) Matchers.containsString(org.hamcrest.Matchers.containsString) SqlCommand(io.confluent.ksql.tools.migrations.util.CommandParser.SqlCommand) Test(org.junit.Test)

Aggregations

SqlCommand (io.confluent.ksql.tools.migrations.util.CommandParser.SqlCommand)11 Test (org.junit.Test)11 Matchers.containsString (org.hamcrest.Matchers.containsString)6 SqlInsertValues (io.confluent.ksql.tools.migrations.util.CommandParser.SqlInsertValues)5 SqlCreateConnectorStatement (io.confluent.ksql.tools.migrations.util.CommandParser.SqlCreateConnectorStatement)2 SqlDefineVariableCommand (io.confluent.ksql.tools.migrations.util.CommandParser.SqlDefineVariableCommand)2 SqlDropConnectorStatement (io.confluent.ksql.tools.migrations.util.CommandParser.SqlDropConnectorStatement)1 SqlUndefineVariableCommand (io.confluent.ksql.tools.migrations.util.CommandParser.SqlUndefineVariableCommand)1