use of io.confluent.ksql.name.ColumnName in project ksql by confluentinc.
the class CreateSourceFactory method buildTimestampColumn.
private static Optional<TimestampColumn> buildTimestampColumn(final KsqlConfig ksqlConfig, final CreateSourceProperties properties, final LogicalSchema schema) {
final Optional<ColumnName> timestampName = properties.getTimestampColumnName();
final Optional<TimestampColumn> timestampColumn = timestampName.map(n -> new TimestampColumn(n, properties.getTimestampFormat()));
// create the final extraction policy to validate that the ref/format are OK
TimestampExtractionPolicyFactory.validateTimestampColumn(ksqlConfig, schema, timestampColumn);
return timestampColumn;
}
use of io.confluent.ksql.name.ColumnName in project ksql by confluentinc.
the class SchemaKGroupedTable method aggregate.
@Override
public SchemaKTable<GenericKey> aggregate(final List<ColumnName> nonAggregateColumns, final List<FunctionCall> aggregations, final Optional<WindowExpression> windowExpression, final FormatInfo valueFormat, final Stacker contextStacker) {
if (windowExpression.isPresent()) {
throw new KsqlException("Windowing not supported for table aggregations.");
}
final List<String> unsupportedFunctionNames = aggregations.stream().map(call -> UdafUtil.resolveAggregateFunction(functionRegistry, call, schema, ksqlConfig)).filter(function -> !(function instanceof TableAggregationFunction)).map(KsqlAggregateFunction::name).map(FunctionName::text).distinct().collect(Collectors.toList());
if (!unsupportedFunctionNames.isEmpty()) {
final String postfix = unsupportedFunctionNames.size() == 1 ? "" : "s";
throw new KsqlException("The aggregation function" + postfix + " " + GrammaticalJoiner.and().join(unsupportedFunctionNames) + " cannot be applied to a table source, only to a stream source.");
}
final TableAggregate step = ExecutionStepFactory.tableAggregate(contextStacker, sourceTableStep, InternalFormats.of(keyFormat, valueFormat), nonAggregateColumns, aggregations);
return new SchemaKTable<>(step, resolveSchema(step), keyFormat, ksqlConfig, functionRegistry);
}
use of io.confluent.ksql.name.ColumnName in project ksql by confluentinc.
the class AggregateAnalyzerTest method shouldNotCaptureWindowStartAsRequiredColumn.
@Test
public void shouldNotCaptureWindowStartAsRequiredColumn() {
// Given:
givenWindowExpression();
givenSelectExpression(new UnqualifiedColumnReferenceExp(SystemColumns.WINDOWSTART_NAME));
// When:
final AggregateAnalysisResult result = analyzer.analyze(analysis, selects);
// Then:
final List<ColumnName> requiredColumnNames = result.getRequiredColumns().stream().map(ColumnReferenceExp::getColumnName).collect(Collectors.toList());
assertThat(requiredColumnNames, not(hasItem(SystemColumns.WINDOWSTART_NAME)));
}
use of io.confluent.ksql.name.ColumnName in project ksql by confluentinc.
the class Repartitioning method repartitionNeeded.
/**
* Determine if a repartition is needed.
*
* <p>A repartition is only not required if partitioning by the existing key columns.
*
* @param schema the schema of the data before any repartition
* @param partitionBy the expressions to partition by
* @return {@code true} if a repartition is needed.
*/
public static boolean repartitionNeeded(final LogicalSchema schema, final List<Expression> partitionBy) {
if (schema.key().isEmpty()) {
// No current key, so repartition needed:
return true;
}
// do end up supporting this (we'll have to change the logic here)
if (schema.key().size() != 1) {
return true;
}
if (partitionBy.size() != schema.key().size()) {
// Different number of expressions to keys means it must be a repartition:
return true;
}
final Expression expression = partitionBy.get(0);
if (!(expression instanceof ColumnReferenceExp)) {
// If expression is not a column reference then the key will be changing
return true;
}
final ColumnName newKeyColName = ((ColumnReferenceExp) expression).getColumnName();
return !newKeyColName.equals(schema.key().get(0).name());
}
use of io.confluent.ksql.name.ColumnName in project ksql by confluentinc.
the class AggregateAnalyzerTest method shouldNotCaptureWindowEndAsRequiredColumn.
@Test
public void shouldNotCaptureWindowEndAsRequiredColumn() {
// Given:
givenWindowExpression();
givenSelectExpression(new UnqualifiedColumnReferenceExp(SystemColumns.WINDOWEND_NAME));
// When:
final AggregateAnalysisResult result = analyzer.analyze(analysis, selects);
// Then:
final List<ColumnName> requiredColumnNames = result.getRequiredColumns().stream().map(ColumnReferenceExp::getColumnName).collect(Collectors.toList());
assertThat(requiredColumnNames, not(hasItem(SystemColumns.WINDOWEND_NAME)));
}
Aggregations