use of io.confluent.ksql.parser.tree.SingleColumn in project ksql by confluentinc.
the class KsqlParserTest method testLiterals.
@Test
public void testLiterals() throws Exception {
String queryStr = "SELECT 10, col2, 'test', 2.5, true, -5 FROM test1;";
Statement statement = KSQL_PARSER.buildAst(queryStr, metaStore).get(0);
Assert.assertTrue("testLiterals fails", statement instanceof Query);
Query query = (Query) statement;
Assert.assertTrue("testLiterals fails", query.getQueryBody() instanceof QuerySpecification);
QuerySpecification querySpecification = (QuerySpecification) query.getQueryBody();
SingleColumn column0 = (SingleColumn) querySpecification.getSelect().getSelectItems().get(0);
Assert.assertTrue("testLiterals fails", column0.getAlias().get().equalsIgnoreCase("KSQL_COL_0"));
Assert.assertTrue("testLiterals fails", column0.getExpression().toString().equalsIgnoreCase("10"));
SingleColumn column1 = (SingleColumn) querySpecification.getSelect().getSelectItems().get(1);
Assert.assertTrue("testLiterals fails", column1.getAlias().get().equalsIgnoreCase("COL2"));
Assert.assertTrue("testLiterals fails", column1.getExpression().toString().equalsIgnoreCase("TEST1.COL2"));
SingleColumn column2 = (SingleColumn) querySpecification.getSelect().getSelectItems().get(2);
Assert.assertTrue("testLiterals fails", column2.getAlias().get().equalsIgnoreCase("KSQL_COL_2"));
Assert.assertTrue("testLiterals fails", column2.getExpression().toString().equalsIgnoreCase("'test'"));
SingleColumn column3 = (SingleColumn) querySpecification.getSelect().getSelectItems().get(3);
Assert.assertTrue("testLiterals fails", column3.getAlias().get().equalsIgnoreCase("KSQL_COL_3"));
Assert.assertTrue("testLiterals fails", column3.getExpression().toString().equalsIgnoreCase("2.5"));
SingleColumn column4 = (SingleColumn) querySpecification.getSelect().getSelectItems().get(4);
Assert.assertTrue("testLiterals fails", column4.getAlias().get().equalsIgnoreCase("KSQL_COL_4"));
Assert.assertTrue("testLiterals fails", column4.getExpression().toString().equalsIgnoreCase("true"));
SingleColumn column5 = (SingleColumn) querySpecification.getSelect().getSelectItems().get(5);
Assert.assertTrue("testLiterals fails", column5.getAlias().get().equalsIgnoreCase("KSQL_COL_5"));
Assert.assertTrue("testLiterals fails", column5.getExpression().toString().equalsIgnoreCase("-5"));
}
use of io.confluent.ksql.parser.tree.SingleColumn in project ksql by confluentinc.
the class QueryEngine method getResultDatasource.
StructuredDataSource getResultDatasource(final Select select, final String name) {
SchemaBuilder dataSource = SchemaBuilder.struct().name(name);
for (SelectItem selectItem : select.getSelectItems()) {
if (selectItem instanceof SingleColumn) {
SingleColumn singleColumn = (SingleColumn) selectItem;
String fieldName = singleColumn.getAlias().get();
dataSource = dataSource.field(fieldName, Schema.BOOLEAN_SCHEMA);
}
}
KsqlTopic ksqlTopic = new KsqlTopic(name, name, null);
return new KsqlStream("QueryEngine-DDLCommand-Not-Needed", name, dataSource.schema(), null, null, ksqlTopic);
}
Aggregations