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;
}
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());
}
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;
}
Aggregations