use of io.confluent.ksql.parser.tree.DereferenceExpression in project ksql by confluentinc.
the class SchemaKStreamTest method testGroupByMultipleColumns.
@Test
public void testGroupByMultipleColumns() {
String selectQuery = "SELECT col0, col1 FROM test1 WHERE col0 > 100;";
PlanNode logicalPlan = planBuilder.buildLogicalPlan(selectQuery);
initialSchemaKStream = new SchemaKStream(logicalPlan.getTheSourceNode().getSchema(), kStream, ksqlStream.getKeyField(), new ArrayList<>(), SchemaKStream.Type.SOURCE, functionRegistry, new MockSchemaRegistryClient());
Expression col0Expression = new DereferenceExpression(new QualifiedNameReference(QualifiedName.of("TEST1")), "COL0");
Expression col1Expression = new DereferenceExpression(new QualifiedNameReference(QualifiedName.of("TEST1")), "COL1");
KsqlTopicSerDe ksqlTopicSerDe = new KsqlJsonTopicSerDe();
Serde<GenericRow> rowSerde = ksqlTopicSerDe.getGenericRowSerde(initialSchemaKStream.getSchema(), null, false, null);
List<Expression> groupByExpressions = Arrays.asList(col1Expression, col0Expression);
SchemaKGroupedStream groupedSchemaKStream = initialSchemaKStream.groupBy(Serdes.String(), rowSerde, groupByExpressions);
Assert.assertEquals(groupedSchemaKStream.getKeyField().name(), "TEST1.COL1|+|TEST1.COL0");
}
use of io.confluent.ksql.parser.tree.DereferenceExpression in project ksql by confluentinc.
the class AstBuilder method visitDereference.
@Override
public Node visitDereference(SqlBaseParser.DereferenceContext context) {
String fieldName = getIdentifierText(context.identifier());
Expression baseExpression;
QualifiedName tableName = QualifiedName.of(context.primaryExpression().getText().toUpperCase());
baseExpression = new QualifiedNameReference(getLocation(context.primaryExpression()), tableName);
DereferenceExpression dereferenceExpression = new DereferenceExpression(getLocation(context), baseExpression, fieldName);
return dereferenceExpression;
}
use of io.confluent.ksql.parser.tree.DereferenceExpression in project ksql by confluentinc.
the class QueryAnalyzerTest method shouldCreateAnalysisForSimpleQuery.
@Test
public void shouldCreateAnalysisForSimpleQuery() {
final List<Statement> statements = ksqlParser.buildAst("select orderid from orders;", metaStore);
final Analysis analysis = queryAnalyzer.analyze("sqlExpression", (Query) statements.get(0));
final Pair<StructuredDataSource, String> fromDataSource = analysis.getFromDataSource(0);
assertThat(analysis.getSelectExpressions(), equalTo(Collections.singletonList(new DereferenceExpression(new QualifiedNameReference(QualifiedName.of("ORDERS")), "ORDERID"))));
assertThat(analysis.getFromDataSources().size(), equalTo(1));
assertThat(fromDataSource.left, instanceOf(KsqlStream.class));
assertThat(fromDataSource.right, equalTo("ORDERS"));
}
Aggregations