-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: partition-by primitive key support (#4098)
* chore: partition-by primitive key support Fixes: #4092 WIP: This commit gets `PARTITION BY` clauses working with primitive key types. However, it does disable a couple of join until #4094 has been completed. BREAKING CHANGE: A `PARTITION BY` now changes the SQL type of `ROWKEY` in the output schema of a query. For example, consider: ```sql CREATE STREAM INPUT (ROWKEY STRING KEY, ID INT) WITH (...); CREATE STREAM OUTPUT AS SELECT ROWKEY AS NAME FROM INPUT PARTITION BY ID; ``` Previously, the above would have resulted in an output schema of `ROWKEY STRING KEY, NAME STRING`, where `ROWKEY` would have stored the string representation of the integer from the `ID` column. With this commit the output schema will be `ROWKEY INT KEY, NAME STRING`.
- Loading branch information
1 parent
6c80941
commit 7addf88
Showing
13 changed files
with
381 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
ksql-execution/src/test/java/io/confluent/ksql/execution/util/StructKeyUtilTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/* | ||
* Copyright 2019 Confluent Inc. | ||
* | ||
* Licensed under the Confluent Community License (the "License"); you may not use | ||
* this file except in compliance with the License. You may obtain a copy of the | ||
* License at | ||
* | ||
* http://www.confluent.io/confluent-community-license | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OF ANY KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations under the License. | ||
*/ | ||
|
||
package io.confluent.ksql.execution.util; | ||
|
||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.is; | ||
import static org.hamcrest.Matchers.nullValue; | ||
|
||
import io.confluent.ksql.execution.util.StructKeyUtil.KeyBuilder; | ||
import io.confluent.ksql.name.ColumnName; | ||
import io.confluent.ksql.schema.ksql.LogicalSchema; | ||
import io.confluent.ksql.schema.ksql.types.SqlTypes; | ||
import org.apache.kafka.connect.data.Schema; | ||
import org.apache.kafka.connect.data.SchemaBuilder; | ||
import org.apache.kafka.connect.data.Struct; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
public class StructKeyUtilTest { | ||
|
||
private static final LogicalSchema LOGICAL_SCHEMA = LogicalSchema.builder() | ||
.keyColumn(ColumnName.of("BOB"), SqlTypes.INTEGER) | ||
.valueColumn(ColumnName.of("DOES_NOT_MATTER"), SqlTypes.STRING) | ||
.build(); | ||
private KeyBuilder builder; | ||
|
||
@Before | ||
public void setUp() { | ||
builder = StructKeyUtil.keySchema(LOGICAL_SCHEMA); | ||
} | ||
|
||
@Test(expected = UnsupportedOperationException.class) | ||
public void shouldThrowOnMultipleKeyColumns() { | ||
// Only single key columns initially supported | ||
StructKeyUtil.keySchema(LogicalSchema.builder() | ||
.keyColumn(ColumnName.of("BOB"), SqlTypes.STRING) | ||
.keyColumn(ColumnName.of("JOHN"), SqlTypes.STRING) | ||
.build()); | ||
} | ||
|
||
@Test | ||
public void shouldBuildCorrectSchema() { | ||
// When: | ||
final Struct result = builder.build(1); | ||
|
||
// Then: | ||
assertThat(result.schema(), is(SchemaBuilder.struct() | ||
.field("ROWKEY", Schema.OPTIONAL_INT32_SCHEMA) | ||
.build())); | ||
} | ||
|
||
@Test | ||
public void shouldHandleValue() { | ||
// When: | ||
final Struct result = builder.build(1); | ||
|
||
// Then: | ||
assertThat(result.getInt32("ROWKEY"), is(1)); | ||
} | ||
|
||
@Test | ||
public void shouldHandleNulls() { | ||
// When: | ||
final Struct result = builder.build(null); | ||
|
||
// Then: | ||
assertThat(result.getInt32("ROWKEY"), is(nullValue())); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.