use of io.confluent.ksql.util.KsqlException in project ksql by confluentinc.
the class SchemaKStream method createSelectValueMapperAndSchema.
Pair<Schema, SelectValueMapper> createSelectValueMapperAndSchema(final List<Pair<String, Expression>> expressionPairList) {
try {
final CodeGenRunner codeGenRunner = new CodeGenRunner(schema, functionRegistry);
final SchemaBuilder schemaBuilder = SchemaBuilder.struct();
final List<ExpressionMetadata> expressionEvaluators = new ArrayList<>();
for (Pair<String, Expression> expressionPair : expressionPairList) {
final ExpressionMetadata expressionEvaluator = codeGenRunner.buildCodeGenFromParseTree(expressionPair.getRight());
schemaBuilder.field(expressionPair.getLeft(), expressionEvaluator.getExpressionType());
expressionEvaluators.add(expressionEvaluator);
}
return new Pair<>(schemaBuilder.build(), new SelectValueMapper(genericRowValueTypeEnforcer, expressionPairList, expressionEvaluators));
} catch (Exception e) {
throw new KsqlException("Code generation failed for SelectValueMapper", e);
}
}
use of io.confluent.ksql.util.KsqlException in project ksql by confluentinc.
the class QueryAnalyzerTest method shouldThrowExceptionIfNonAggregateSelectsDontMatchGroupBySize.
@Test
public void shouldThrowExceptionIfNonAggregateSelectsDontMatchGroupBySize() {
final List<Statement> statements = ksqlParser.buildAst("select itemid, orderid, sum(orderunits) from orders window TUMBLING ( size 30 second) " + "where orderunits > 5 group by itemid;", metaStore);
final Query query = (Query) statements.get(0);
final Analysis analysis = queryAnalyzer.analyze("sqlExpression", query);
try {
queryAnalyzer.analyzeAggregate(query, analysis);
fail("should have thrown KsqlException as aggregate query doesn't have a groupby clause");
} catch (KsqlException e) {
// ok
}
}
use of io.confluent.ksql.util.KsqlException in project ksql by confluentinc.
the class QueryAnalyzerTest method shouldFailWithIncorrectJoinCriteria.
@Test
public void shouldFailWithIncorrectJoinCriteria() {
final List<Statement> statements = ksqlParser.buildAst("select * from test1 join test2 on test1.col1 = test2.coll;", metaStore);
final Query query = (Query) statements.get(0);
try {
queryAnalyzer.analyze("sqlExpression", query);
} catch (KsqlException ex) {
assertThat(ex.getMessage().trim(), equalTo("Line: 1, Col: 46 : Invalid join criteria (TEST1.COL1 = TEST2.COLL). Key for TEST2 is not set correctly."));
}
}
use of io.confluent.ksql.util.KsqlException in project ksql by confluentinc.
the class QueryAnalyzerTest method shouldThrowExceptionIfAggregateAnalysisDoesntHaveGroupBy.
@Test
public void shouldThrowExceptionIfAggregateAnalysisDoesntHaveGroupBy() {
final List<Statement> statements = ksqlParser.buildAst("select itemid, sum(orderunits) from orders window TUMBLING ( size 30 second) " + "where orderunits > 5;", metaStore);
final Query query = (Query) statements.get(0);
final Analysis analysis = queryAnalyzer.analyze("sqlExpression", query);
try {
queryAnalyzer.analyzeAggregate(query, analysis);
fail("should have thrown KsqlException as aggregate query doesn't have a groupby clause");
} catch (KsqlException e) {
// ok
}
}
use of io.confluent.ksql.util.KsqlException in project ksql by confluentinc.
the class CommandFactoriesTest method shouldFailCreateTableIfTimestampColumnNameIsIncorrect.
@Test
public void shouldFailCreateTableIfTimestampColumnNameIsIncorrect() {
HashMap<String, Expression> tableProperties = new HashMap<>();
tableProperties.putAll(properties);
tableProperties.put(DdlConfig.TIMESTAMP_NAME_PROPERTY, new StringLiteral("COL3"));
try {
final DdlCommand result = commandFactories.create(sqlExpression, new CreateTable(QualifiedName.of("foo"), Arrays.asList(new TableElement("COL1", "BIGINT"), new TableElement("COL2", "VARCHAR")), true, tableProperties), Collections.emptyMap());
} catch (KsqlException e) {
assertThat(e.getMessage(), equalTo("No column with the provided timestamp column name in the WITH clause, COL3, exists in the defined schema."));
}
}
Aggregations