Search in sources :

Example 11 with QualifiedNameReference

use of io.confluent.ksql.parser.tree.QualifiedNameReference in project ksql by confluentinc.

the class ExpressionFormatterTest method shouldFormatRow.

@Test
public void shouldFormatRow() {
    final String result = ExpressionFormatter.formatExpression(new Row(Arrays.asList(new LongLiteral("1"), new QualifiedNameReference(QualifiedName.of(Arrays.asList("a", "b"))))));
    assertThat(result, equalTo("ROW (1, a.b)"));
}
Also used : LongLiteral(io.confluent.ksql.parser.tree.LongLiteral) Row(io.confluent.ksql.parser.tree.Row) QualifiedNameReference(io.confluent.ksql.parser.tree.QualifiedNameReference) Test(org.junit.Test)

Example 12 with QualifiedNameReference

use of io.confluent.ksql.parser.tree.QualifiedNameReference 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 13 with QualifiedNameReference

use of io.confluent.ksql.parser.tree.QualifiedNameReference 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

QualifiedNameReference (io.confluent.ksql.parser.tree.QualifiedNameReference)13 DereferenceExpression (io.confluent.ksql.parser.tree.DereferenceExpression)9 Expression (io.confluent.ksql.parser.tree.Expression)8 Test (org.junit.Test)6 ComparisonExpression (io.confluent.ksql.parser.tree.ComparisonExpression)4 ArrayList (java.util.ArrayList)4 SingleColumn (io.confluent.ksql.parser.tree.SingleColumn)3 Statement (io.confluent.ksql.parser.tree.Statement)3 MockSchemaRegistryClient (io.confluent.kafka.schemaregistry.client.MockSchemaRegistryClient)2 GenericRow (io.confluent.ksql.GenericRow)2 StructuredDataSource (io.confluent.ksql.metastore.StructuredDataSource)2 AllColumns (io.confluent.ksql.parser.tree.AllColumns)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 LongLiteral (io.confluent.ksql.parser.tree.LongLiteral)2 NotExpression (io.confluent.ksql.parser.tree.NotExpression)2