use of io.confluent.ksql.parser.tree.InsertInto in project ksql by confluentinc.
the class DistributingExecutorTest method shouldThrowExceptionWhenInsertIntoSourceWithHeaders.
@Test
public void shouldThrowExceptionWhenInsertIntoSourceWithHeaders() {
// Given
final PreparedStatement<Statement> preparedStatement = PreparedStatement.of("", new InsertInto(SourceName.of("s1"), mock(Query.class)));
final ConfiguredStatement<Statement> configured = ConfiguredStatement.of(preparedStatement, SessionConfig.of(KSQL_CONFIG, ImmutableMap.of()));
final DataSource dataSource = mock(DataSource.class);
final LogicalSchema schema = mock(LogicalSchema.class);
doReturn(dataSource).when(metaStore).getSource(SourceName.of("s1"));
doReturn(schema).when(dataSource).getSchema();
doReturn(ImmutableList.of(ColumnName.of("a"))).when(schema).headers();
when(dataSource.getKafkaTopicName()).thenReturn("topic");
// When:
final Exception e = assertThrows(KsqlException.class, () -> distributor.execute(configured, executionContext, mock(KsqlSecurityContext.class)));
// Then:
assertThat(e.getMessage(), is("Cannot insert into s1 because it has header columns"));
}
use of io.confluent.ksql.parser.tree.InsertInto in project ksql by confluentinc.
the class StatementRewriterTest method shouldRewriteInsertIntoWithPartitionBy.
@Test
public void shouldRewriteInsertIntoWithPartitionBy() {
// Given:
final InsertInto ii = new InsertInto(location, sourceName, query, insertIntoProperties);
when(mockRewriter.apply(query, context)).thenReturn(rewrittenQuery);
when(expressionRewriter.apply(expression, context)).thenReturn(rewrittenExpression);
// When:
final AstNode rewritten = rewriter.rewrite(ii, context);
// Then:
assertThat(rewritten, equalTo(new InsertInto(location, sourceName, rewrittenQuery, insertIntoProperties)));
}
use of io.confluent.ksql.parser.tree.InsertInto in project ksql by confluentinc.
the class StatementRewriterTest method shouldRewriteInsertInto.
@Test
public void shouldRewriteInsertInto() {
// Given:
final InsertInto ii = new InsertInto(location, sourceName, query, insertIntoProperties);
when(mockRewriter.apply(query, context)).thenReturn(rewrittenQuery);
// When:
final AstNode rewritten = rewriter.rewrite(ii, context);
// Then:
assertThat(rewritten, equalTo(new InsertInto(location, sourceName, rewrittenQuery, insertIntoProperties)));
}
use of io.confluent.ksql.parser.tree.InsertInto in project ksql by confluentinc.
the class RequestValidator method validate.
/**
* @return the number of persistent queries that were validated
*
* @throws KsqlStatementException if the statement cannot be validated
*/
@SuppressWarnings("unchecked")
private <T extends Statement> int validate(final ServiceContext serviceContext, final ConfiguredStatement<T> configured, final SessionProperties sessionProperties, final KsqlExecutionContext executionContext, final Injector injector) throws KsqlStatementException {
final Statement statement = configured.getStatement();
final Class<? extends Statement> statementClass = statement.getClass();
final StatementValidator<T> customValidator = (StatementValidator<T>) customValidators.get(statementClass);
if (customValidator != null) {
customValidator.validate(configured, sessionProperties, executionContext, serviceContext);
} else if (KsqlEngine.isExecutableStatement(configured.getStatement()) || configured.getStatement() instanceof TerminateQuery) {
final ConfiguredStatement<?> statementInjected = injector.inject(configured);
distributedStatementValidator.create(statementInjected, serviceContext, executionContext);
} else {
throw new KsqlStatementException("Do not know how to validate statement of type: " + statementClass + " Known types: " + customValidators.keySet(), configured.getStatementText());
}
return (statement instanceof CreateAsSelect || statement instanceof InsertInto) ? 1 : 0;
}
use of io.confluent.ksql.parser.tree.InsertInto in project ksql by confluentinc.
the class KsqlParserTest method testInsertInto.
@Test
public void testInsertInto() {
final String insertIntoString = "INSERT INTO test0 " + "SELECT col0, col2, col3 FROM test1 WHERE col0 > 100;";
final Statement statement = KsqlParserTestUtil.buildSingleAst(insertIntoString, metaStore).getStatement();
assertThat(statement, instanceOf(InsertInto.class));
final InsertInto insertInto = (InsertInto) statement;
assertThat(insertInto.getTarget(), equalTo(SourceName.of("TEST0")));
final Query query = insertInto.getQuery();
assertThat(query.getSelect().getSelectItems(), hasSize(3));
assertThat(query.getFrom(), not(nullValue()));
assertThat(query.getWhere().isPresent(), equalTo(true));
assertThat(query.getWhere().get(), instanceOf(ComparisonExpression.class));
final ComparisonExpression comparisonExpression = (ComparisonExpression) query.getWhere().get();
assertThat(comparisonExpression.getType().getValue(), equalTo(">"));
}
Aggregations