Search in sources :

Example 6 with SqlCommand

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

the class CommandParserTest method shouldParseUndefineStatement.

@Test
public void shouldParseUndefineStatement() {
    // Given:
    final String undefineVar = "UNDEFINE var;";
    // When:
    List<SqlCommand> commands = parse(undefineVar);
    // Then:
    assertThat(commands.size(), is(1));
    assertThat(commands.get(0).getCommand(), is(undefineVar));
    assertThat(commands.get(0), instanceOf(SqlUndefineVariableCommand.class));
    assertThat(((SqlUndefineVariableCommand) commands.get(0)).getVariable(), is("var"));
}
Also used : SqlUndefineVariableCommand(io.confluent.ksql.tools.migrations.util.CommandParser.SqlUndefineVariableCommand) Matchers.containsString(org.hamcrest.Matchers.containsString) SqlCommand(io.confluent.ksql.tools.migrations.util.CommandParser.SqlCommand) Test(org.junit.Test)

Example 7 with SqlCommand

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

the class CommandParserTest method shouldParseDefineStatement.

@Test
public void shouldParseDefineStatement() {
    // Given:
    final String defineVar = "DEFINE var = 'foo';";
    // When:
    List<SqlCommand> commands = parse(defineVar);
    // Then:
    assertThat(commands.size(), is(1));
    assertThat(commands.get(0).getCommand(), is(defineVar));
    assertThat(commands.get(0), instanceOf(SqlDefineVariableCommand.class));
    assertThat(((SqlDefineVariableCommand) commands.get(0)).getVariable(), is("var"));
    assertThat(((SqlDefineVariableCommand) commands.get(0)).getValue(), is("foo"));
}
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 8 with SqlCommand

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

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

Example 10 with SqlCommand

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

the class CommandParserTest method shouldParseCreateConnectorStatementWithVariables.

@Test
public void shouldParseCreateConnectorStatementWithVariables() {
    // Given:
    final String createConnector = "CREATE SOURCE CONNECTOR ${name} WITH(\n" + "    \"connector.class\"='io.confluent.connect.jdbc.JdbcSourceConnector',\n" + "    \"connection.url\"=${url},\n" + "    \"mode\"='bulk',\n" + "    \"topic.prefix\"='jdbc-',\n" + "    \"table.whitelist\"='users',\n" + "    \"key\"='username');";
    // When:
    List<SqlCommand> commands = parse(createConnector, ImmutableMap.of("url", "'jdbc:postgresql://localhost:5432/my.db'", "name", "`jdbc_connector`"));
    // Then:
    assertThat(commands.size(), is(1));
    assertThat(commands.get(0), instanceOf(SqlCreateConnectorStatement.class));
    assertThat(commands.get(0).getCommand(), is(createConnector));
    assertThat(((SqlCreateConnectorStatement) commands.get(0)).getName(), is("`jdbc_connector`"));
    assertThat(((SqlCreateConnectorStatement) commands.get(0)).isSource(), is(true));
    assertThat(((SqlCreateConnectorStatement) commands.get(0)).getProperties().size(), is(6));
    assertThat(((SqlCreateConnectorStatement) commands.get(0)).getProperties().get("connector.class"), is("io.confluent.connect.jdbc.JdbcSourceConnector"));
    assertThat(((SqlCreateConnectorStatement) commands.get(0)).getProperties().get("connection.url"), is("jdbc:postgresql://localhost:5432/my.db"));
    assertThat(((SqlCreateConnectorStatement) commands.get(0)).getProperties().get("mode"), is("bulk"));
    assertThat(((SqlCreateConnectorStatement) commands.get(0)).getProperties().get("topic.prefix"), is("jdbc-"));
    assertThat(((SqlCreateConnectorStatement) commands.get(0)).getProperties().get("table.whitelist"), is("users"));
    assertThat(((SqlCreateConnectorStatement) commands.get(0)).getProperties().get("key"), is("username"));
}
Also used : Matchers.containsString(org.hamcrest.Matchers.containsString) SqlCreateConnectorStatement(io.confluent.ksql.tools.migrations.util.CommandParser.SqlCreateConnectorStatement) 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