use of io.confluent.ksql.metastore.model.KsqlTable in project ksql by confluentinc.
the class DataSourceNodeTest method shouldBuildSchemaKTableWhenKTableSource.
@Test
public void shouldBuildSchemaKTableWhenKTableSource() {
// Given:
final KsqlTable<String> table = new KsqlTable<>("sqlExpression", SourceName.of("datasource"), REAL_SCHEMA, Optional.of(TIMESTAMP_COLUMN), false, new KsqlTopic("topic2", KeyFormat.nonWindowed(FormatInfo.of(FormatFactory.KAFKA.name()), SerdeFeatures.of()), ValueFormat.of(FormatInfo.of(FormatFactory.JSON.name()), SerdeFeatures.of())), false);
node = new DataSourceNode(PLAN_NODE_ID, table, table.getName(), false, ksqlConfig);
// When:
final SchemaKStream<?> result = buildStream(node);
// Then:
assertThat(result.getClass(), equalTo(SchemaKTable.class));
}
use of io.confluent.ksql.metastore.model.KsqlTable in project ksql by confluentinc.
the class SqlFormatterTest method setUp.
@Before
public void setUp() {
final Table left = new Table(SourceName.of("left"));
final Table right = new Table(SourceName.of("right"));
final Table right2 = new Table(SourceName.of("right2"));
leftAlias = new AliasedRelation(left, SourceName.of("L"));
rightAlias = new AliasedRelation(right, SourceName.of("R"));
right2Alias = new AliasedRelation(right2, SourceName.of("R2"));
criteria = new JoinOn(new ComparisonExpression(ComparisonExpression.Type.EQUAL, new StringLiteral("left.col0"), new StringLiteral("right.col0")));
criteria2 = new JoinOn(new ComparisonExpression(ComparisonExpression.Type.EQUAL, new StringLiteral("left.col0"), new StringLiteral("right2.col0")));
metaStore = MetaStoreFixture.getNewMetaStore(mock(FunctionRegistry.class));
final KsqlTopic ksqlTopicOrders = new KsqlTopic("orders_topic", KeyFormat.nonWindowed(FormatInfo.of(FormatFactory.KAFKA.name()), SerdeFeatures.of()), ValueFormat.of(FormatInfo.of(FormatFactory.JSON.name()), SerdeFeatures.of()));
final KsqlStream<?> ksqlStreamOrders = new KsqlStream<>("sqlexpression", SourceName.of("ADDRESS"), ORDERS_SCHEMA, Optional.empty(), false, ksqlTopicOrders, false);
metaStore.putSource(ksqlStreamOrders, false);
final KsqlTopic ksqlTopicItems = new KsqlTopic("item_topic", KeyFormat.nonWindowed(FormatInfo.of(FormatFactory.KAFKA.name()), SerdeFeatures.of()), ValueFormat.of(FormatInfo.of(FormatFactory.JSON.name()), SerdeFeatures.of()));
final KsqlTable<String> ksqlTableOrders = new KsqlTable<>("sqlexpression", SourceName.of("ITEMID"), ITEM_INFO_SCHEMA, Optional.empty(), false, ksqlTopicItems, false);
metaStore.putSource(ksqlTableOrders, false);
final KsqlTable<String> ksqlTableTable = new KsqlTable<>("sqlexpression", SourceName.of("TABLE"), TABLE_SCHEMA, Optional.empty(), false, ksqlTopicItems, false);
metaStore.putSource(ksqlTableTable, false);
}
use of io.confluent.ksql.metastore.model.KsqlTable in project ksql by confluentinc.
the class ListSourceExecutor method describeTables.
public static StatementExecutorResponse describeTables(final ConfiguredStatement<DescribeTables> statement, final SessionProperties sessionProperties, final KsqlExecutionContext executionContext, final ServiceContext serviceContext) {
final List<KsqlTable<?>> ksqlTables = getSpecificTables(executionContext);
final DescribeTables describeTables = statement.getStatement();
return StatementExecutorResponse.handled(sourceDescriptionList(statement, sessionProperties, executionContext, serviceContext, ksqlTables, describeTables.getShowExtended()));
}
use of io.confluent.ksql.metastore.model.KsqlTable in project ksql by confluentinc.
the class EngineExecutor method sourceTablePlan.
@SuppressFBWarnings(value = "NP_NULL_PARAM_DEREF_NONVIRTUAL")
private KsqlPlan sourceTablePlan(final ConfiguredStatement<?> statement) {
final CreateTable createTable = (CreateTable) statement.getStatement();
final CreateTableCommand ddlCommand = (CreateTableCommand) engineContext.createDdlCommand(statement.getStatementText(), (ExecutableDdlStatement) statement.getStatement(), config);
final Relation from = new AliasedRelation(new Table(createTable.getName()), createTable.getName());
// Only VALUE or HEADER columns must be selected from the source table. When running a
// pull query, the keys are added if selecting all columns.
final Select select = new Select(createTable.getElements().stream().filter(column -> !column.getConstraints().isKey() && !column.getConstraints().isPrimaryKey()).map(column -> new SingleColumn(new UnqualifiedColumnReferenceExp(column.getName()), Optional.of(column.getName()))).collect(Collectors.toList()));
// Source table need to keep emitting changes so every new record is materialized for
// pull query availability.
final RefinementInfo refinementInfo = RefinementInfo.of(OutputRefinement.CHANGES);
// This is a plan for a `select * from <source-table> emit changes` statement,
// without a sink topic to write the results. The query is just made to materialize the
// source table.
final Query query = new Query(Optional.empty(), select, from, Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.of(refinementInfo), false, OptionalInt.empty());
// The source table does not exist in the current metastore, so a temporary metastore that
// contains only the source table is created here. This metastore is used later to create
// ExecutorsPlan.
final MutableMetaStore tempMetastore = new MetaStoreImpl(new InternalFunctionRegistry());
final Formats formats = ddlCommand.getFormats();
tempMetastore.putSource(new KsqlTable<>(statement.getStatementText(), createTable.getName(), ddlCommand.getSchema(), Optional.empty(), false, new KsqlTopic(ddlCommand.getTopicName(), KeyFormat.of(formats.getKeyFormat(), formats.getKeyFeatures(), Optional.empty()), ValueFormat.of(formats.getValueFormat(), formats.getValueFeatures())), true), false);
final ExecutorPlans plans = planQuery(statement, query, Optional.empty(), Optional.empty(), tempMetastore);
final KsqlBareOutputNode outputNode = (KsqlBareOutputNode) plans.logicalPlan.getNode().get();
final QueryPlan queryPlan = new QueryPlan(getSourceNames(outputNode), Optional.empty(), plans.physicalPlan.getPhysicalPlan(), plans.physicalPlan.getQueryId(), getApplicationId(plans.physicalPlan.getQueryId(), getSourceNames(outputNode)));
engineContext.createQueryValidator().validateQuery(config, plans.physicalPlan, engineContext.getQueryRegistry().getAllLiveQueries());
return KsqlPlan.queryPlanCurrent(statement.getStatementText(), Optional.of(ddlCommand), queryPlan);
}
use of io.confluent.ksql.metastore.model.KsqlTable in project ksql by confluentinc.
the class DdlCommandExecTest method shouldAddSourceTable.
@Test
public void shouldAddSourceTable() {
// Given:
final CreateTableCommand cmd = buildCreateTable(TABLE_NAME, false, true);
// When:
cmdExec.execute(SQL_TEXT, cmd, true, ImmutableSet.of(TABLE_NAME));
// Then:
final KsqlTable ksqlTable = (KsqlTable) metaStore.getSource(TABLE_NAME);
assertThat(ksqlTable.isSource(), is(true));
// Check query source was not added as constraints for source tables
assertThat(metaStore.getSourceConstraints(TABLE_NAME), is(NO_QUERY_SOURCES));
}
Aggregations