Search in sources :

Example 6 with Table

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

the class DataSourceExtractor method visitJoinRelation.

@Override
public Node visitJoinRelation(final SqlBaseParser.JoinRelationContext context) {
    this.isJoin = true;
    AliasedRelation left = (AliasedRelation) visit(context.left);
    AliasedRelation right;
    if (context.CROSS() != null) {
        right = (AliasedRelation) visit(context.right);
    } else {
        if (context.NATURAL() != null) {
            right = (AliasedRelation) visit(context.right);
        } else {
            right = (AliasedRelation) visit(context.rightRelation);
        }
    }
    this.leftAlias = left.getAlias();
    StructuredDataSource leftDataSource = metaStore.getSource(((Table) left.getRelation()).getName().getSuffix());
    if (leftDataSource == null) {
        throw new KsqlException(((Table) left.getRelation()).getName().getSuffix() + " does not " + "exist.");
    }
    this.joinLeftSchema = leftDataSource.getSchema();
    this.rightAlias = right.getAlias();
    StructuredDataSource rightDataSource = metaStore.getSource(((Table) right.getRelation()).getName().getSuffix());
    if (rightDataSource == null) {
        throw new KsqlException(((Table) right.getRelation()).getName().getSuffix() + " does not " + "exist.");
    }
    this.joinRightSchema = rightDataSource.getSchema();
    return null;
}
Also used : StructuredDataSource(io.confluent.ksql.metastore.StructuredDataSource) Table(io.confluent.ksql.parser.tree.Table) AliasedRelation(io.confluent.ksql.parser.tree.AliasedRelation)

Example 7 with Table

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

the class KsqlEngine method addInto.

public Query addInto(final Query query, final QuerySpecification querySpecification, final String intoName, final Map<String, Expression> intoProperties, final Optional<Expression> partitionByExpression) {
    Table intoTable = new Table(QualifiedName.of(intoName));
    if (partitionByExpression.isPresent()) {
        Map<String, Expression> newIntoProperties = new HashMap<>();
        newIntoProperties.putAll(intoProperties);
        newIntoProperties.put(DdlConfig.PARTITION_BY_PROPERTY, partitionByExpression.get());
        intoTable.setProperties(newIntoProperties);
    } else {
        intoTable.setProperties(intoProperties);
    }
    QuerySpecification newQuerySpecification = new QuerySpecification(querySpecification.getSelect(), intoTable, querySpecification.getFrom(), querySpecification.getWindowExpression(), querySpecification.getWhere(), querySpecification.getGroupBy(), querySpecification.getHaving(), querySpecification.getLimit());
    return new Query(newQuerySpecification, query.getLimit());
}
Also used : QuerySpecification(io.confluent.ksql.parser.tree.QuerySpecification) CreateTable(io.confluent.ksql.parser.tree.CreateTable) DropTable(io.confluent.ksql.parser.tree.DropTable) Table(io.confluent.ksql.parser.tree.Table) Query(io.confluent.ksql.parser.tree.Query) Expression(io.confluent.ksql.parser.tree.Expression) HashMap(java.util.HashMap)

Example 8 with Table

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

the class Analyzer method visitAliasedRelation.

@Override
protected Node visitAliasedRelation(AliasedRelation node, AnalysisContext context) {
    String structuredDataSourceName = ((Table) node.getRelation()).getName().getSuffix();
    if (metaStore.getSource(structuredDataSourceName) == null) {
        throw new KsqlException(structuredDataSourceName + " does not exist.");
    }
    StructuredDataSource structuredDataSource = metaStore.getSource(structuredDataSourceName);
    if (((Table) node.getRelation()).getProperties() != null) {
        if (((Table) node.getRelation()).getProperties().get(DdlConfig.TIMESTAMP_NAME_PROPERTY) != null) {
            String timestampFieldName = ((Table) node.getRelation()).getProperties().get(DdlConfig.TIMESTAMP_NAME_PROPERTY).toString().toUpperCase();
            if (!timestampFieldName.startsWith("'") && !timestampFieldName.endsWith("'")) {
                throw new KsqlException("Property name should be String with single qoute.");
            }
            timestampFieldName = timestampFieldName.substring(1, timestampFieldName.length() - 1);
            structuredDataSource = structuredDataSource.cloneWithTimeField(timestampFieldName);
        }
    }
    Pair<StructuredDataSource, String> fromDataSource = new Pair<>(structuredDataSource, node.getAlias());
    analysis.addDataSource(fromDataSource);
    return node;
}
Also used : StructuredDataSource(io.confluent.ksql.metastore.StructuredDataSource) Table(io.confluent.ksql.parser.tree.Table) KsqlException(io.confluent.ksql.util.KsqlException) Pair(io.confluent.ksql.util.Pair)

Aggregations

Table (io.confluent.ksql.parser.tree.Table)8 AliasedRelation (io.confluent.ksql.parser.tree.AliasedRelation)5 StructuredDataSource (io.confluent.ksql.metastore.StructuredDataSource)4 CreateTable (io.confluent.ksql.parser.tree.CreateTable)4 DropTable (io.confluent.ksql.parser.tree.DropTable)4 QuerySpecification (io.confluent.ksql.parser.tree.QuerySpecification)3 Relation (io.confluent.ksql.parser.tree.Relation)3 Expression (io.confluent.ksql.parser.tree.Expression)2 SelectItem (io.confluent.ksql.parser.tree.SelectItem)2 KsqlException (io.confluent.ksql.util.KsqlException)2 AllColumns (io.confluent.ksql.parser.tree.AllColumns)1 ArithmeticBinaryExpression (io.confluent.ksql.parser.tree.ArithmeticBinaryExpression)1 ArithmeticUnaryExpression (io.confluent.ksql.parser.tree.ArithmeticUnaryExpression)1 ComparisonExpression (io.confluent.ksql.parser.tree.ComparisonExpression)1 CreateStreamAsSelect (io.confluent.ksql.parser.tree.CreateStreamAsSelect)1 CreateTableAsSelect (io.confluent.ksql.parser.tree.CreateTableAsSelect)1 DereferenceExpression (io.confluent.ksql.parser.tree.DereferenceExpression)1 GroupBy (io.confluent.ksql.parser.tree.GroupBy)1 HoppingWindowExpression (io.confluent.ksql.parser.tree.HoppingWindowExpression)1 InListExpression (io.confluent.ksql.parser.tree.InListExpression)1