Skip to content

Commit

Permalink
fix: Make Select * avoid code gen for projections
Browse files Browse the repository at this point in the history
  • Loading branch information
AlanConfluent committed Jan 8, 2021
1 parent cb0e6f2 commit aad067b
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import io.confluent.ksql.schema.ksql.types.SqlTypes;
import io.confluent.ksql.util.KsqlConfig;
import io.confluent.ksql.util.KsqlException;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
Expand Down Expand Up @@ -86,7 +87,9 @@ public PullProjectNode(
this.addAdditionalColumnsToIntermediateSchema = shouldAddAdditionalColumnsInSchema();
this.outputSchema = buildOutputSchema(metaStore);
this.intermediateSchema = buildIntermediateSchema();
this.compiledSelectExpressions = selectExpressions
this.compiledSelectExpressions = isSelectStar
? Collections.emptyList()
: selectExpressions
.stream()
.map(selectExpression -> CodeGenRunner.compileExpression(
selectExpression.getExpression(),
Expand All @@ -96,7 +99,6 @@ public PullProjectNode(
metaStore
))
.collect(ImmutableList.toImmutableList());

}

@Override
Expand All @@ -110,6 +112,9 @@ public List<SelectExpression> getSelectExpressions() {
}

public List<ExpressionMetadata> getCompiledSelectExpressions() {
if (isSelectStar) {
throw new IllegalStateException("Select expressions aren't compiled for select star");
}
return compiledSelectExpressions;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertThrows;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.Mockito.when;
Expand All @@ -31,6 +32,8 @@
import io.confluent.ksql.metastore.model.DataSource;
import io.confluent.ksql.metastore.model.DataSource.DataSourceType;
import io.confluent.ksql.name.ColumnName;
import io.confluent.ksql.name.SourceName;
import io.confluent.ksql.parser.tree.AllColumns;
import io.confluent.ksql.parser.tree.SelectItem;
import io.confluent.ksql.parser.tree.SingleColumn;
import io.confluent.ksql.schema.ksql.LogicalSchema;
Expand All @@ -53,6 +56,7 @@ public class PullProjectNodeTest {
private static final ColumnName K = ColumnName.of("K");
private static final ColumnName COL0 = ColumnName.of("COL0");
private static final ColumnName ALIAS = ColumnName.of("GRACE");
private static final SourceName SOURCE_NAME = SourceName.of("SOURCE");

private static final UnqualifiedColumnReferenceExp K_REF =
new UnqualifiedColumnReferenceExp(K);
Expand Down Expand Up @@ -256,4 +260,30 @@ public void shouldBuildPullQueryOutputSchemaSelectValueAndWindowBounds() {
assertThat(expected, is(projectNode.getSchema()));
}

@Test
public void shouldBuildPullQueryOutputSchemaSelectStar() {
// Given:
selects = ImmutableList.of(new AllColumns(Optional.of(SOURCE_NAME)));
when(keyFormat.isWindowed()).thenReturn(false);
when(analysis.getSelectColumnNames()).thenReturn(ImmutableSet.of());

// When:
final PullProjectNode projectNode = new PullProjectNode(
NODE_ID,
source,
selects,
metaStore,
ksqlConfig,
analysis
);

// Then:
final LogicalSchema expectedSchema = INPUT_SCHEMA;
assertThat(expectedSchema, is(projectNode.getIntermediateSchema()));
assertThat(expectedSchema.withoutPseudoAndKeyColsInValue(), is(projectNode.getSchema()));
assertThrows(
IllegalStateException.class,
projectNode::getCompiledSelectExpressions
);
}
}

0 comments on commit aad067b

Please sign in to comment.