Search in sources :

Example 6 with DereferenceExpression

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");
}
Also used : DereferenceExpression(io.confluent.ksql.parser.tree.DereferenceExpression) MockSchemaRegistryClient(io.confluent.kafka.schemaregistry.client.MockSchemaRegistryClient) ArrayList(java.util.ArrayList) GenericRow(io.confluent.ksql.GenericRow) PlanNode(io.confluent.ksql.planner.plan.PlanNode) DereferenceExpression(io.confluent.ksql.parser.tree.DereferenceExpression) Expression(io.confluent.ksql.parser.tree.Expression) KsqlTopicSerDe(io.confluent.ksql.serde.KsqlTopicSerDe) KsqlJsonTopicSerDe(io.confluent.ksql.serde.json.KsqlJsonTopicSerDe) QualifiedNameReference(io.confluent.ksql.parser.tree.QualifiedNameReference) Test(org.junit.Test)

Example 7 with DereferenceExpression

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;
}
Also used : DereferenceExpression(io.confluent.ksql.parser.tree.DereferenceExpression) InListExpression(io.confluent.ksql.parser.tree.InListExpression) NullIfExpression(io.confluent.ksql.parser.tree.NullIfExpression) SimpleCaseExpression(io.confluent.ksql.parser.tree.SimpleCaseExpression) ComparisonExpression(io.confluent.ksql.parser.tree.ComparisonExpression) DereferenceExpression(io.confluent.ksql.parser.tree.DereferenceExpression) Expression(io.confluent.ksql.parser.tree.Expression) LogicalBinaryExpression(io.confluent.ksql.parser.tree.LogicalBinaryExpression) TumblingWindowExpression(io.confluent.ksql.parser.tree.TumblingWindowExpression) ArithmeticBinaryExpression(io.confluent.ksql.parser.tree.ArithmeticBinaryExpression) NotExpression(io.confluent.ksql.parser.tree.NotExpression) HoppingWindowExpression(io.confluent.ksql.parser.tree.HoppingWindowExpression) SubscriptExpression(io.confluent.ksql.parser.tree.SubscriptExpression) SessionWindowExpression(io.confluent.ksql.parser.tree.SessionWindowExpression) SearchedCaseExpression(io.confluent.ksql.parser.tree.SearchedCaseExpression) LambdaExpression(io.confluent.ksql.parser.tree.LambdaExpression) SubqueryExpression(io.confluent.ksql.parser.tree.SubqueryExpression) WindowExpression(io.confluent.ksql.parser.tree.WindowExpression) ArithmeticUnaryExpression(io.confluent.ksql.parser.tree.ArithmeticUnaryExpression) QualifiedName(io.confluent.ksql.parser.tree.QualifiedName) QualifiedNameReference(io.confluent.ksql.parser.tree.QualifiedNameReference)

Example 8 with 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"));
}
Also used : StructuredDataSource(io.confluent.ksql.metastore.StructuredDataSource) KsqlStream(io.confluent.ksql.metastore.KsqlStream) DereferenceExpression(io.confluent.ksql.parser.tree.DereferenceExpression) Statement(io.confluent.ksql.parser.tree.Statement) QualifiedNameReference(io.confluent.ksql.parser.tree.QualifiedNameReference) Test(org.junit.Test)

Aggregations

DereferenceExpression (io.confluent.ksql.parser.tree.DereferenceExpression)8 QualifiedNameReference (io.confluent.ksql.parser.tree.QualifiedNameReference)8 Expression (io.confluent.ksql.parser.tree.Expression)6 Test (org.junit.Test)4 ComparisonExpression (io.confluent.ksql.parser.tree.ComparisonExpression)3 MockSchemaRegistryClient (io.confluent.kafka.schemaregistry.client.MockSchemaRegistryClient)2 GenericRow (io.confluent.ksql.GenericRow)2 ArithmeticBinaryExpression (io.confluent.ksql.parser.tree.ArithmeticBinaryExpression)2 ArithmeticUnaryExpression (io.confluent.ksql.parser.tree.ArithmeticUnaryExpression)2 HoppingWindowExpression (io.confluent.ksql.parser.tree.HoppingWindowExpression)2 InListExpression (io.confluent.ksql.parser.tree.InListExpression)2 LambdaExpression (io.confluent.ksql.parser.tree.LambdaExpression)2 LogicalBinaryExpression (io.confluent.ksql.parser.tree.LogicalBinaryExpression)2 NotExpression (io.confluent.ksql.parser.tree.NotExpression)2 NullIfExpression (io.confluent.ksql.parser.tree.NullIfExpression)2 SearchedCaseExpression (io.confluent.ksql.parser.tree.SearchedCaseExpression)2 SessionWindowExpression (io.confluent.ksql.parser.tree.SessionWindowExpression)2 SimpleCaseExpression (io.confluent.ksql.parser.tree.SimpleCaseExpression)2 Statement (io.confluent.ksql.parser.tree.Statement)2 SubqueryExpression (io.confluent.ksql.parser.tree.SubqueryExpression)2