Search in sources :

Example 1 with SqlInsertValues

use of io.confluent.ksql.tools.migrations.util.CommandParser.SqlInsertValues 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 SqlInsertValues

use of io.confluent.ksql.tools.migrations.util.CommandParser.SqlInsertValues 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 3 with SqlInsertValues

use of io.confluent.ksql.tools.migrations.util.CommandParser.SqlInsertValues 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 4 with SqlInsertValues

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

the class CommandParserTest method shouldParseInsertValuesStatementWithExplicitQuoting.

@Test
public void shouldParseInsertValuesStatementWithExplicitQuoting() {
    // When:
    List<SqlCommand> commands = parse("INSERT INTO `foo` (`col1`) VALUES (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(), is(ImmutableList.of("col1")));
    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 SqlInsertValues

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

the class CommandParserTest method shouldParseInsertValuesStatement.

@Test
public void shouldParseInsertValuesStatement() {
    // When:
    List<SqlCommand> commands = parse("INSERT INTO FOO VALUES (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(), is(Collections.emptyList()));
    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)

Aggregations

SqlCommand (io.confluent.ksql.tools.migrations.util.CommandParser.SqlCommand)5 SqlInsertValues (io.confluent.ksql.tools.migrations.util.CommandParser.SqlInsertValues)5 Test (org.junit.Test)5