use of io.confluent.ksql.execution.expression.tree.UnqualifiedColumnReferenceExp in project ksql by confluentinc.
the class GroupByParamsFactoryTest method shouldSetKeyNameFromFieldName.
@Test
public void shouldSetKeyNameFromFieldName() {
// Given:
when(groupBy0.getExpression()).thenReturn(new DereferenceExpression(Optional.empty(), new UnqualifiedColumnReferenceExp(COL3), "someField"));
// When:
final LogicalSchema schema = GroupByParamsFactory.buildSchema(SOURCE_SCHEMA, ImmutableList.of(groupBy0, groupBy1));
// Then:
assertThat(schema, is(LogicalSchema.builder().keyColumn(ColumnName.of("someField"), SqlTypes.INTEGER).keyColumn(ColumnName.of("K1"), SqlTypes.INTEGER).valueColumns(SOURCE_SCHEMA.value()).build()));
}
use of io.confluent.ksql.execution.expression.tree.UnqualifiedColumnReferenceExp in project ksql by confluentinc.
the class FilterTypeValidatorTest method shouldThrowOnBadTypeComparison.
@Test
public void shouldThrowOnBadTypeComparison() {
// Given:
final Expression left = new UnqualifiedColumnReferenceExp(COLUMN1);
final Expression right = new IntegerLiteral(10);
final Expression comparision = new ComparisonExpression(Type.EQUAL, left, right);
when(schema.findValueColumn(any())).thenReturn(Optional.of(Column.of(COLUMN1, STRING, VALUE, 10)));
// When:
assertThrows("Error in WHERE expression: " + "Cannot compare col1 (STRING) to 10 (INTEGER) with EQUAL.", KsqlException.class, () -> validator.validateFilterExpression(comparision));
}
use of io.confluent.ksql.execution.expression.tree.UnqualifiedColumnReferenceExp in project ksql by confluentinc.
the class FilterTypeValidatorTest method shouldThrowOnBadTypeCompoundComparison_leftError.
@Test
public void shouldThrowOnBadTypeCompoundComparison_leftError() {
// Given:
final Expression left1 = new UnqualifiedColumnReferenceExp(COLUMN1);
final Expression right1 = new UnqualifiedColumnReferenceExp(COLUMN2);
final Expression comparision1 = new ComparisonExpression(Type.EQUAL, left1, right1);
final Expression left2 = new UnqualifiedColumnReferenceExp(COLUMN1);
final Expression right2 = new StringLiteral("foo");
final Expression comparision2 = new ComparisonExpression(Type.EQUAL, left2, right2);
final Expression expression = new LogicalBinaryExpression(LogicalBinaryExpression.Type.AND, comparision1, comparision2);
when(schema.findValueColumn(COLUMN1)).thenReturn(Optional.of(Column.of(COLUMN1, STRING, VALUE, 10)));
when(schema.findValueColumn(COLUMN2)).thenReturn(Optional.of(Column.of(COLUMN2, INTEGER, VALUE, 10)));
// When:
assertThrows("Error in WHERE expression: " + "Cannot compare col1 (STRING) to col2 (INTEGER) with EQUAL.", KsqlException.class, () -> validator.validateFilterExpression(expression));
}
use of io.confluent.ksql.execution.expression.tree.UnqualifiedColumnReferenceExp in project ksql by confluentinc.
the class ColumnReferenceValidatorTest method shouldThrowOnNoSources.
@Test
public void shouldThrowOnNoSources() {
// Given:
final Expression expression = new UnqualifiedColumnReferenceExp(ColumnName.of("just-name"));
when(sourceSchemas.sourcesWithField(any(), any())).thenReturn(ImmutableSet.of());
// When:
final Exception e = assertThrows(UnknownColumnException.class, () -> analyzer.analyzeExpression(expression, CLAUSE_TYPE));
// Then:
assertThat(e.getMessage(), containsString(CLAUSE_TYPE + " column 'just-name' cannot be resolved."));
}
use of io.confluent.ksql.execution.expression.tree.UnqualifiedColumnReferenceExp in project ksql by confluentinc.
the class ColumnReferenceValidatorTest method shouldIncludeLocationInErrorIfKnown.
@Test
public void shouldIncludeLocationInErrorIfKnown() {
// Given:
final Expression expression = new UnqualifiedColumnReferenceExp(Optional.of(new NodeLocation(10, 23)), ColumnName.of("just-name"));
when(sourceSchemas.sourcesWithField(any(), any())).thenReturn(ImmutableSet.of());
// When:
final Exception e = assertThrows(UnknownColumnException.class, () -> analyzer.analyzeExpression(expression, CLAUSE_TYPE));
// Then:
assertThat(e.getMessage(), containsString("Line: 10, Col: 24: " + CLAUSE_TYPE));
}
Aggregations