use of io.confluent.ksql.parser.tree.SingleColumn in project ksql by confluentinc.
the class KsqlParserTest method testBinaryExpression.
@Test
public void testBinaryExpression() throws Exception {
String queryStr = "SELECT col0+10, col2, col3-col1 FROM test1;";
Statement statement = KSQL_PARSER.buildAst(queryStr, metaStore).get(0);
Assert.assertTrue("testBinaryExpression fails", statement instanceof Query);
Query query = (Query) statement;
Assert.assertTrue("testBinaryExpression fails", query.getQueryBody() instanceof QuerySpecification);
QuerySpecification querySpecification = (QuerySpecification) query.getQueryBody();
SingleColumn column0 = (SingleColumn) querySpecification.getSelect().getSelectItems().get(0);
Assert.assertTrue("testBinaryExpression fails", column0.getAlias().get().equalsIgnoreCase("KSQL_COL_0"));
Assert.assertTrue("testBinaryExpression fails", column0.getExpression().toString().equalsIgnoreCase("(TEST1.COL0 + 10)"));
}
use of io.confluent.ksql.parser.tree.SingleColumn in project ksql by confluentinc.
the class KsqlParserTest method testBooleanLogicalExpression.
@Test
public void testBooleanLogicalExpression() throws Exception {
String queryStr = "SELECT 10, col2, 'test', 2.5, true, -5 FROM test1 WHERE col1 = 10 AND col2 LIKE 'val' OR col4 > 2.6 ;";
Statement statement = KSQL_PARSER.buildAst(queryStr, metaStore).get(0);
Assert.assertTrue("testSimpleQuery fails", statement instanceof Query);
Query query = (Query) statement;
Assert.assertTrue("testProjection fails", query.getQueryBody() instanceof QuerySpecification);
QuerySpecification querySpecification = (QuerySpecification) query.getQueryBody();
SingleColumn column0 = (SingleColumn) querySpecification.getSelect().getSelectItems().get(0);
Assert.assertTrue("testProjection fails", column0.getAlias().get().equalsIgnoreCase("KSQL_COL_0"));
Assert.assertTrue("testProjection fails", column0.getExpression().toString().equalsIgnoreCase("10"));
SingleColumn column1 = (SingleColumn) querySpecification.getSelect().getSelectItems().get(1);
Assert.assertTrue("testProjection fails", column1.getAlias().get().equalsIgnoreCase("COL2"));
Assert.assertTrue("testProjection fails", column1.getExpression().toString().equalsIgnoreCase("TEST1.COL2"));
SingleColumn column2 = (SingleColumn) querySpecification.getSelect().getSelectItems().get(2);
Assert.assertTrue("testProjection fails", column2.getAlias().get().equalsIgnoreCase("KSQL_COL_2"));
Assert.assertTrue("testProjection fails", column2.getExpression().toString().equalsIgnoreCase("'test'"));
}
use of io.confluent.ksql.parser.tree.SingleColumn in project ksql by confluentinc.
the class KsqlParserTest method testUDF.
@Test
public void testUDF() throws Exception {
String queryStr = "SELECT lcase(col1), concat(col2,'hello'), floor(abs(col3)) FROM test1 t1;";
Statement statement = KSQL_PARSER.buildAst(queryStr, metaStore).get(0);
Assert.assertTrue("testSelectAll fails", statement instanceof Query);
Query query = (Query) statement;
Assert.assertTrue("testSelectAll fails", query.getQueryBody() instanceof QuerySpecification);
QuerySpecification querySpecification = (QuerySpecification) query.getQueryBody();
SingleColumn column0 = (SingleColumn) querySpecification.getSelect().getSelectItems().get(0);
Assert.assertTrue("testProjection fails", column0.getAlias().get().equalsIgnoreCase("KSQL_COL_0"));
Assert.assertTrue("testProjection fails", column0.getExpression().toString().equalsIgnoreCase("LCASE(T1.COL1)"));
SingleColumn column1 = (SingleColumn) querySpecification.getSelect().getSelectItems().get(1);
Assert.assertTrue("testProjection fails", column1.getAlias().get().equalsIgnoreCase("KSQL_COL_1"));
Assert.assertTrue("testProjection fails", column1.getExpression().toString().equalsIgnoreCase("CONCAT(T1.COL2, 'hello')"));
SingleColumn column2 = (SingleColumn) querySpecification.getSelect().getSelectItems().get(2);
Assert.assertTrue("testProjection fails", column2.getAlias().get().equalsIgnoreCase("KSQL_COL_2"));
Assert.assertTrue("testProjection fails", column2.getExpression().toString().equalsIgnoreCase("FLOOR(ABS(T1.COL3))"));
}
use of io.confluent.ksql.parser.tree.SingleColumn in project ksql by confluentinc.
the class KsqlParserTest method testBooleanExpression.
@Test
public void testBooleanExpression() throws Exception {
String queryStr = "SELECT col0 = 10, col2, col3 > col1 FROM test1;";
Statement statement = KSQL_PARSER.buildAst(queryStr, metaStore).get(0);
Assert.assertTrue("testBooleanExpression fails", statement instanceof Query);
Query query = (Query) statement;
Assert.assertTrue("testProjection fails", query.getQueryBody() instanceof QuerySpecification);
QuerySpecification querySpecification = (QuerySpecification) query.getQueryBody();
SingleColumn column0 = (SingleColumn) querySpecification.getSelect().getSelectItems().get(0);
Assert.assertTrue("testBooleanExpression fails", column0.getAlias().get().equalsIgnoreCase("KSQL_COL_0"));
Assert.assertTrue("testBooleanExpression fails", column0.getExpression().toString().equalsIgnoreCase("(TEST1.COL0 = 10)"));
}
use of io.confluent.ksql.parser.tree.SingleColumn in project ksql by confluentinc.
the class AstBuilder method getResultDatasource.
private StructuredDataSource getResultDatasource(Select select, Table into) {
SchemaBuilder dataSource = SchemaBuilder.struct().name(into.toString());
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(into.getName().toString(), into.getName().toString(), null);
StructuredDataSource resultStream = new KsqlStream("AstBuilder-Into", into.getName().toString(), dataSource.schema(), dataSource.fields().get(0), null, ksqlTopic);
return resultStream;
}
Aggregations