use of io.confluent.ksql.util.Pair in project ksql by confluentinc.
the class StatementExecutorTest method shouldHandlePriorStatement.
@Test
public void shouldHandlePriorStatement() throws Exception {
TestUtils testUtils = new TestUtils();
List<Pair<CommandId, Command>> priorCommands = testUtils.getAllPriorCommandRecords();
final RestoreCommands restoreCommands = new RestoreCommands();
priorCommands.forEach(pair -> restoreCommands.addCommand(pair.left, pair.right));
CommandId topicCommandId = new CommandId(CommandId.Type.TOPIC, "_CSASTopicGen", CommandId.Action.CREATE);
CommandId csCommandId = new CommandId(CommandId.Type.STREAM, "_CSASStreamGen", CommandId.Action.CREATE);
CommandId csasCommandId = new CommandId(CommandId.Type.STREAM, "_CSASGen", CommandId.Action.CREATE);
CommandId ctasCommandId = new CommandId(CommandId.Type.TABLE, "_CTASGen", CommandId.Action.CREATE);
statementExecutor.handleRestoration(restoreCommands);
Map<CommandId, CommandStatus> statusStore = statementExecutor.getStatuses();
Assert.assertNotNull(statusStore);
Assert.assertEquals(4, statusStore.size());
Assert.assertEquals(CommandStatus.Status.SUCCESS, statusStore.get(topicCommandId).getStatus());
Assert.assertEquals(CommandStatus.Status.SUCCESS, statusStore.get(csCommandId).getStatus());
Assert.assertEquals(CommandStatus.Status.SUCCESS, statusStore.get(csasCommandId).getStatus());
Assert.assertEquals(CommandStatus.Status.ERROR, statusStore.get(ctasCommandId).getStatus());
}
use of io.confluent.ksql.util.Pair in project ksql by confluentinc.
the class SelectValueMapperTest method createMapper.
private SelectValueMapper createMapper(final String query) throws Exception {
final PlanNode planNode = planBuilder.buildLogicalPlan(query);
final ProjectNode projectNode = (ProjectNode) planNode.getSources().get(0);
final Schema schema = planNode.getTheSourceNode().getSchema();
final List<Pair<String, Expression>> expressionPairList = projectNode.getProjectNameExpressionPairList();
final List<ExpressionMetadata> metadata = createExpressionMetadata(expressionPairList, schema);
return new SelectValueMapper(new GenericRowValueTypeEnforcer(schema), expressionPairList, metadata);
}
use of io.confluent.ksql.util.Pair in project ksql by confluentinc.
the class ProjectNodeTest method shouldCreateProjectionWithFieldNameExpressionPairs.
@Test
public void shouldCreateProjectionWithFieldNameExpressionPairs() {
mockSourceNode();
final BooleanLiteral trueExpression = new BooleanLiteral("true");
final BooleanLiteral falseExpression = new BooleanLiteral("false");
EasyMock.expect(stream.select(Arrays.asList(new Pair<>("field1", trueExpression), new Pair<>("field2", falseExpression)))).andReturn(stream);
EasyMock.replay(source, stream);
final ProjectNode node = new ProjectNode(new PlanNodeId("1"), source, SchemaBuilder.struct().field("field1", Schema.STRING_SCHEMA).field("field2", Schema.STRING_SCHEMA).build(), Arrays.asList(trueExpression, falseExpression));
node.buildStream(builder, ksqlConfig, kafkaTopicClient, functionRegistry, props, new MockSchemaRegistryClient());
EasyMock.verify(stream);
}
use of io.confluent.ksql.util.Pair in project ksql by confluentinc.
the class KsqlEngine method buildSingleQueryAst.
private Pair<String, Statement> buildSingleQueryAst(final Statement statement, final String statementString, final MetaStore tempMetaStore, final MetaStore tempMetaStoreForParser, final Map<String, Object> overriddenProperties) {
log.info("Building AST for {}.", statementString);
if (statement instanceof Query) {
return new Pair<>(statementString, statement);
} else if (statement instanceof CreateAsSelect) {
CreateAsSelect createAsSelect = (CreateAsSelect) statement;
QuerySpecification querySpecification = (QuerySpecification) createAsSelect.getQuery().getQueryBody();
Query query = addInto(createAsSelect.getQuery(), querySpecification, createAsSelect.getName().getSuffix(), createAsSelect.getProperties(), createAsSelect.getPartitionByColumn());
tempMetaStoreForParser.putSource(queryEngine.getResultDatasource(querySpecification.getSelect(), createAsSelect.getName().getSuffix()).cloneWithTimeKeyColumns());
return new Pair<>(statementString, query);
} else if (statement instanceof RegisterTopic) {
ddlCommandExec.tryExecute(new RegisterTopicCommand((RegisterTopic) statement), tempMetaStoreForParser);
ddlCommandExec.tryExecute(new RegisterTopicCommand((RegisterTopic) statement), tempMetaStore);
return new Pair<>(statementString, statement);
} else if (statement instanceof CreateStream) {
ddlCommandExec.tryExecute(new CreateStreamCommand(statementString, (CreateStream) statement, overriddenProperties, topicClient, false), tempMetaStoreForParser);
ddlCommandExec.tryExecute(new CreateStreamCommand(statementString, (CreateStream) statement, overriddenProperties, topicClient, false), tempMetaStore);
return new Pair<>(statementString, statement);
} else if (statement instanceof CreateTable) {
ddlCommandExec.tryExecute(new CreateTableCommand(statementString, (CreateTable) statement, overriddenProperties, topicClient, false), tempMetaStoreForParser);
ddlCommandExec.tryExecute(new CreateTableCommand(statementString, (CreateTable) statement, overriddenProperties, topicClient, false), tempMetaStore);
return new Pair<>(statementString, statement);
} else if (statement instanceof DropStream) {
ddlCommandExec.tryExecute(new DropSourceCommand((DropStream) statement, DataSource.DataSourceType.KSTREAM, this), tempMetaStore);
ddlCommandExec.tryExecute(new DropSourceCommand((DropStream) statement, DataSource.DataSourceType.KSTREAM, this), tempMetaStoreForParser);
return new Pair<>(statementString, statement);
} else if (statement instanceof DropTable) {
ddlCommandExec.tryExecute(new DropSourceCommand((DropTable) statement, DataSource.DataSourceType.KTABLE, this), tempMetaStore);
ddlCommandExec.tryExecute(new DropSourceCommand((DropTable) statement, DataSource.DataSourceType.KTABLE, this), tempMetaStoreForParser);
return new Pair<>(statementString, statement);
} else if (statement instanceof DropTopic) {
ddlCommandExec.tryExecute(new DropTopicCommand((DropTopic) statement), tempMetaStore);
ddlCommandExec.tryExecute(new DropTopicCommand((DropTopic) statement), tempMetaStoreForParser);
return new Pair<>(statementString, statement);
} else if (statement instanceof SetProperty) {
return new Pair<>(statementString, statement);
}
return null;
}
use of io.confluent.ksql.util.Pair in project ksql by confluentinc.
the class QueryEngine method maybeAddFieldsFromSchemaRegistry.
private Pair<DdlStatement, String> maybeAddFieldsFromSchemaRegistry(AbstractStreamCreateStatement streamCreateStatement) {
if (streamCreateStatement.getProperties().containsKey(DdlConfig.TOPIC_NAME_PROPERTY)) {
String ksqlRegisteredTopicName = StringUtil.cleanQuotes(streamCreateStatement.getProperties().get(DdlConfig.TOPIC_NAME_PROPERTY).toString().toUpperCase());
KsqlTopic ksqlTopic = ksqlEngine.getMetaStore().getTopic(ksqlRegisteredTopicName);
if (ksqlTopic == null) {
throw new KsqlException(String.format("Could not find %s topic in the metastore.", ksqlRegisteredTopicName));
}
Map<String, Expression> newProperties = new HashMap<>();
newProperties.put(DdlConfig.KAFKA_TOPIC_NAME_PROPERTY, new StringLiteral(ksqlTopic.getKafkaTopicName()));
newProperties.put(DdlConfig.VALUE_FORMAT_PROPERTY, new StringLiteral(ksqlTopic.getKsqlTopicSerDe().getSerDe().toString()));
streamCreateStatement = streamCreateStatement.copyWith(streamCreateStatement.getElements(), newProperties);
}
Pair<AbstractStreamCreateStatement, String> avroCheckResult = new AvroUtil().checkAndSetAvroSchema(streamCreateStatement, new HashMap<>(), ksqlEngine.getSchemaRegistryClient());
if (avroCheckResult.getRight() != null) {
if (avroCheckResult.getLeft() instanceof CreateStream) {
return new Pair<>((CreateStream) avroCheckResult.getLeft(), avroCheckResult.getRight());
} else if (avroCheckResult.getLeft() instanceof CreateTable) {
return new Pair<>((CreateTable) avroCheckResult.getLeft(), avroCheckResult.getRight());
}
}
return new Pair<>(null, null);
}
Aggregations