use of io.confluent.ksql.planner.plan.StructuredDataSourceNode in project ksql by confluentinc.
the class Analyzer method visitJoin.
@Override
protected Node visitJoin(final Join node, final AnalysisContext context) {
AliasedRelation left = (AliasedRelation) process(node.getLeft(), context);
AliasedRelation right = (AliasedRelation) process(node.getRight(), context);
String leftSideName = ((Table) left.getRelation()).getName().getSuffix();
StructuredDataSource leftDataSource = metaStore.getSource(leftSideName);
if (leftDataSource == null) {
throw new KsqlException(format("Resource %s does not exist.", leftSideName));
}
leftDataSource = timestampColumn(left, leftDataSource);
String rightSideName = ((Table) right.getRelation()).getName().getSuffix();
StructuredDataSource rightDataSource = metaStore.getSource(rightSideName);
if (rightDataSource == null) {
throw new KsqlException(format("Resource %s does not exist.", rightSideName));
}
rightDataSource = timestampColumn(right, rightDataSource);
String leftAlias = left.getAlias();
String rightAlias = right.getAlias();
JoinNode.Type joinType = getJoinType(node);
if (!node.getCriteria().isPresent()) {
throw new KsqlException(String.format("%s Join criteria is not set.", node.getLocation().isPresent() ? node.getLocation().get().toString() : ""));
}
JoinOn joinOn = (JoinOn) (node.getCriteria().get());
ComparisonExpression comparisonExpression = (ComparisonExpression) joinOn.getExpression();
Pair<String, String> leftSide = fetchKeyFieldName(comparisonExpression, leftAlias, leftDataSource.getSchema());
Pair<String, String> rightSide = fetchKeyFieldName(comparisonExpression, rightAlias, rightDataSource.getSchema());
String leftKeyFieldName = leftSide.getRight();
String rightKeyFieldName = rightSide.getRight();
if (comparisonExpression.getType() != ComparisonExpression.Type.EQUAL) {
throw new KsqlException("Only equality join criteria is supported.");
}
StructuredDataSourceNode leftSourceKafkaTopicNode = new StructuredDataSourceNode(new PlanNodeId("KafkaTopic_Left"), leftDataSource, leftDataSource.getSchema());
StructuredDataSourceNode rightSourceKafkaTopicNode = new StructuredDataSourceNode(new PlanNodeId("KafkaTopic_Right"), rightDataSource, rightDataSource.getSchema());
JoinNode joinNode = new JoinNode(new PlanNodeId("Join"), joinType, leftSourceKafkaTopicNode, rightSourceKafkaTopicNode, leftKeyFieldName, rightKeyFieldName, leftAlias, rightAlias);
analysis.setJoin(joinNode);
return null;
}
use of io.confluent.ksql.planner.plan.StructuredDataSourceNode in project ksql by confluentinc.
the class LogicalPlanner method buildSourceNode.
private StructuredDataSourceNode buildSourceNode() {
Pair<StructuredDataSource, String> dataSource = analysis.getFromDataSource(0);
Schema fromSchema = SchemaUtil.buildSchemaWithAlias(dataSource.left.getSchema(), dataSource.right);
if (dataSource.left instanceof KsqlStream || dataSource.left instanceof KsqlTable) {
return new StructuredDataSourceNode(new PlanNodeId("KsqlTopic"), dataSource.left, fromSchema);
}
throw new RuntimeException("Data source is not supported yet.");
}
use of io.confluent.ksql.planner.plan.StructuredDataSourceNode in project ksql by confluentinc.
the class LogicalPlannerTest method shouldCreatePlanWithTableAsSource.
@Test
public void shouldCreatePlanWithTableAsSource() {
PlanNode planNode = buildLogicalPlan("select col0 from TEST2 limit 5;");
assertThat(planNode.getSources().size(), equalTo(1));
StructuredDataSource structuredDataSource = ((StructuredDataSourceNode) planNode.getSources().get(0).getSources().get(0)).getStructuredDataSource();
assertThat(structuredDataSource.getDataSourceType(), equalTo(DataSource.DataSourceType.KTABLE));
assertThat(structuredDataSource.getName(), equalTo("TEST2"));
}
Aggregations