use of io.confluent.ksql.parser.tree.Statement in project ksql by confluentinc.
the class KsqlResource method handleKsqlStatements.
@POST
public Response handleKsqlStatements(KsqlRequest request) throws Exception {
KsqlEntityList result = new KsqlEntityList();
try {
List<Statement> parsedStatements = ksqlEngine.getStatements(request.getKsql());
List<String> statementStrings = getStatementStrings(request.getKsql());
Map<String, Object> streamsProperties = request.getStreamsProperties();
if (parsedStatements.size() != statementStrings.size()) {
throw new Exception(String.format("Size of parsed statements and statement strings differ; %d vs. %d, respectively", parsedStatements.size(), statementStrings.size()));
}
for (int i = 0; i < parsedStatements.size(); i++) {
String statementText = statementStrings.get(i);
result.add(executeStatement(statementText, parsedStatements.get(i), streamsProperties));
}
} catch (Exception exception) {
log.error("Failed to handle POST:" + request, exception);
result.add(new ErrorMessageEntity(request.getKsql(), exception));
}
return Response.ok(result).build();
}
use of io.confluent.ksql.parser.tree.Statement in project ksql by confluentinc.
the class KsqlParserTest method testRegisterTopic.
@Test
public void testRegisterTopic() throws Exception {
String queryStr = "REGISTER TOPIC orders_topic WITH (value_format = 'avro', " + "avroschemafile='/Users/hojjat/avro_order_schema.avro',kafka_topic='orders_topic');";
Statement statement = KSQL_PARSER.buildAst(queryStr, metaStore).get(0);
Assert.assertTrue("testRegisterTopic failed.", statement instanceof RegisterTopic);
RegisterTopic registerTopic = (RegisterTopic) statement;
Assert.assertTrue("testRegisterTopic failed.", registerTopic.getName().toString().equalsIgnoreCase("ORDERS_TOPIC"));
Assert.assertTrue("testRegisterTopic failed.", registerTopic.getProperties().size() == 3);
Assert.assertTrue("testRegisterTopic failed.", registerTopic.getProperties().get(DdlConfig.VALUE_FORMAT_PROPERTY).toString().equalsIgnoreCase("'avro'"));
}
use of io.confluent.ksql.parser.tree.Statement in project ksql by confluentinc.
the class KsqlParserTest method testCreateTopicFormatWithoutQuotes.
@Test
/*
TODO: Handle so-called identifier expressions as values in table properties (right now, the lack of single quotes
around in the variables <format> and <kafkaTopic> cause things to break).
*/
@Ignore
public void testCreateTopicFormatWithoutQuotes() throws Exception {
String ksqlTopic = "unquoted_topic";
String format = "json";
String kafkaTopic = "case_insensitive_kafka_topic";
String queryStr = String.format("REGISTER TOPIC %s WITH (value_format = %s, kafka_topic = %s);", ksqlTopic, format, kafkaTopic);
Statement statement = KSQL_PARSER.buildAst(queryStr, metaStore).get(0);
Assert.assertTrue(statement instanceof RegisterTopic);
RegisterTopic registerTopic = (RegisterTopic) statement;
Assert.assertTrue(registerTopic.getName().toString().equalsIgnoreCase(ksqlTopic));
Assert.assertTrue(registerTopic.getProperties().size() == 2);
Assert.assertTrue(registerTopic.getProperties().get(DdlConfig.VALUE_FORMAT_PROPERTY).toString().equalsIgnoreCase(format));
Assert.assertTrue(registerTopic.getProperties().get(DdlConfig.KAFKA_TOPIC_NAME_PROPERTY).toString().equalsIgnoreCase(kafkaTopic));
}
use of io.confluent.ksql.parser.tree.Statement in project ksql by confluentinc.
the class KsqlParserTest method testProjectFilter.
@Test
public void testProjectFilter() throws Exception {
String queryStr = "SELECT col0, col2, col3 FROM test1 WHERE col0 > 100;";
Statement statement = KSQL_PARSER.buildAst(queryStr, metaStore).get(0);
Assert.assertTrue("testSimpleQuery fails", statement instanceof Query);
Query query = (Query) statement;
Assert.assertTrue("testProjectFilter fails", query.getQueryBody() instanceof QuerySpecification);
QuerySpecification querySpecification = (QuerySpecification) query.getQueryBody();
Assert.assertTrue("testProjectFilter fails", querySpecification.getWhere().get() instanceof ComparisonExpression);
ComparisonExpression comparisonExpression = (ComparisonExpression) querySpecification.getWhere().get();
Assert.assertTrue("testProjectFilter fails", comparisonExpression.toString().equalsIgnoreCase("(TEST1.COL0 > 100)"));
Assert.assertTrue("testProjectFilter fails", querySpecification.getSelect().getSelectItems().size() == 3);
}
use of io.confluent.ksql.parser.tree.Statement in project ksql by confluentinc.
the class KsqlParserTest method testShowTables.
@Test
public void testShowTables() throws Exception {
String simpleQuery = "SHOW TABLES;";
Statement statement = KSQL_PARSER.buildAst(simpleQuery, metaStore).get(0);
Assert.assertTrue(statement instanceof ListTables);
ListTables listTables = (ListTables) statement;
Assert.assertTrue(listTables.toString().equalsIgnoreCase("ListTables{}"));
}
Aggregations