You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flink.apache.org by lz...@apache.org on 2022/04/01 11:47:49 UTC
[flink-table-store] branch release-0.1 updated (9ed6038 -> b34cebb)
This is an automated email from the ASF dual-hosted git repository.
lzljs3620320 pushed a change to branch release-0.1
in repository https://gitbox.apache.org/repos/asf/flink-table-store.git.
from 9ed6038 [hotfix] Add docs.sh to build document
new 5be4b8e [FLINK-26877] Introduce auto type inference for filter push down
new 7efe80c [FLINK-26879] Fix that LogStartupMode.LATEST and LogStartupMode.FROM_TIMESTAMP don't work
new e157ebd [FLINK-26918] Add documentation build to Github Actions
new 295bb23 [hotfix] Add thread name to StoreSinkWriter compaction thread pool
new 2e3b425 [hotfix] Reset theme/book to Flink perfer version
new 686a17d [FLINK-26971] UniversalCompaction should pick by size ratio after picking by file num
new b58bd4c [FLINK-26857] Add ITCase for projection and filter predicate
new 716eb82 [FLINK-26898] Introduce creating table document for table store
new b34cebb [hotfix] Update document config.toml to release-0.1
The 9 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
{tools/ci => .github/workflows}/docs.sh | 12 +-
.github/workflows/docs.yml | 69 ++
docs/config.toml | 12 +-
.../{try-table-store => development}/_index.md | 7 +-
docs/content/docs/development/create-table.md | 153 +++
docs/content/docs/development/distribution.md | 107 ++
docs/content/docs/development/overview.md | 139 +++
docs/static/img/architecture.svg | 1 +
docs/themes/book | 2 +-
flink-table-store-connector/pom.xml | 8 +-
.../flink/table/store/connector/TableStore.java | 37 +-
.../store/connector/sink/StoreSinkWriter.java | 5 +-
.../store/connector/source/TableStoreSource.java | 5 +-
.../store/connector/ReadWriteTableITCase.java | 1224 ++++++++++++++++++--
.../mergetree/compact/UniversalCompaction.java | 20 +-
.../flink/table/store/file/predicate/And.java | 19 +
.../flink/table/store/file/predicate/Equal.java | 19 +
.../table/store/file/predicate/GreaterOrEqual.java | 19 +
.../table/store/file/predicate/GreaterThan.java | 19 +
.../table/store/file/predicate/IsNotNull.java | 19 +
.../flink/table/store/file/predicate/IsNull.java | 19 +
.../table/store/file/predicate/LessOrEqual.java | 19 +
.../flink/table/store/file/predicate/LessThan.java | 19 +
.../flink/table/store/file/predicate/Literal.java | 18 +
.../flink/table/store/file/predicate/NotEqual.java | 19 +
.../flink/table/store/file/predicate/Or.java | 19 +
.../store/file/predicate/PredicateConverter.java | 64 +-
.../mergetree/compact/UniversalCompactionTest.java | 3 +-
.../file/predicate/PredicateConverterTest.java | 148 +++
flink-table-store-kafka/pom.xml | 2 +-
.../store/kafka/KafkaLogDeserializationSchema.java | 12 +-
.../table/store/kafka/KafkaLogSourceProvider.java | 10 +-
.../table/store/kafka/KafkaLogStoreFactory.java | 6 +-
pom.xml | 1 +
34 files changed, 2080 insertions(+), 175 deletions(-)
copy {tools/ci => .github/workflows}/docs.sh (93%)
create mode 100644 .github/workflows/docs.yml
copy docs/content/docs/{try-table-store => development}/_index.md (87%)
create mode 100644 docs/content/docs/development/create-table.md
create mode 100644 docs/content/docs/development/distribution.md
create mode 100644 docs/content/docs/development/overview.md
create mode 100644 docs/static/img/architecture.svg
create mode 100644 flink-table-store-core/src/test/java/org/apache/flink/table/store/file/predicate/PredicateConverterTest.java
[flink-table-store] 02/09: [FLINK-26879] Fix that LogStartupMode.LATEST and LogStartupMode.FROM_TIMESTAMP don't work
Posted by lz...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
lzljs3620320 pushed a commit to branch release-0.1
in repository https://gitbox.apache.org/repos/asf/flink-table-store.git
commit 7efe80c25cd6b3ecd677a71714616411546a7604
Author: Jane Chan <55...@users.noreply.github.com>
AuthorDate: Wed Mar 30 14:43:42 2022 +0800
[FLINK-26879] Fix that LogStartupMode.LATEST and LogStartupMode.FROM_TIMESTAMP don't work
This closes #65
---
flink-table-store-connector/pom.xml | 8 +-
.../flink/table/store/connector/TableStore.java | 37 +-
.../store/connector/source/TableStoreSource.java | 1 -
.../store/connector/ReadWriteTableITCase.java | 427 +++++++++++++++++----
flink-table-store-kafka/pom.xml | 2 +-
.../table/store/kafka/KafkaLogSourceProvider.java | 10 +-
6 files changed, 380 insertions(+), 105 deletions(-)
diff --git a/flink-table-store-connector/pom.xml b/flink-table-store-connector/pom.xml
index f2e2022..cf4fb28 100644
--- a/flink-table-store-connector/pom.xml
+++ b/flink-table-store-connector/pom.xml
@@ -212,7 +212,7 @@ under the License.
<!-- include 2.0 server for tests -->
<groupId>org.apache.kafka</groupId>
<artifactId>kafka_${scala.binary.version}</artifactId>
- <version>2.4.1</version>
+ <version>2.8.1</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
@@ -239,6 +239,12 @@ under the License.
</dependency>
<dependency>
+ <groupId>org.apache.kafka</groupId>
+ <artifactId>kafka-clients</artifactId>
+ <version>2.8.1</version>
+ </dependency>
+
+ <dependency>
<groupId>org.testcontainers</groupId>
<artifactId>kafka</artifactId>
<version>${testcontainers.version}</version>
diff --git a/flink-table-store-connector/src/main/java/org/apache/flink/table/store/connector/TableStore.java b/flink-table-store-connector/src/main/java/org/apache/flink/table/store/connector/TableStore.java
index 9374933..d222018 100644
--- a/flink-table-store-connector/src/main/java/org/apache/flink/table/store/connector/TableStore.java
+++ b/flink-table-store-connector/src/main/java/org/apache/flink/table/store/connector/TableStore.java
@@ -227,8 +227,6 @@ public class TableStore {
private boolean isContinuous = false;
- private boolean isHybrid = true;
-
@Nullable private int[][] projectedFields;
@Nullable private Predicate partitionPredicate;
@@ -257,11 +255,6 @@ public class TableStore {
return this;
}
- public SourceBuilder withHybridMode(boolean isHybrid) {
- this.isHybrid = isHybrid;
- return this;
- }
-
public SourceBuilder withLogSourceProvider(LogSourceProvider logSourceProvider) {
this.logSourceProvider = logSourceProvider;
return this;
@@ -271,20 +264,14 @@ public class TableStore {
return options.get(CONTINUOUS_DISCOVERY_INTERVAL).toMillis();
}
- private FileStoreSource buildFileSource(boolean isContinuous) {
- FileStore fileStore = buildFileStore();
-
- boolean latestContinuous = false;
- if (isContinuous) {
- LogStartupMode startupMode = logOptions().get(SCAN);
- latestContinuous = startupMode == LogStartupMode.LATEST;
- }
+ private FileStoreSource buildFileSource(
+ boolean isContinuous, boolean continuousScanLatest) {
return new FileStoreSource(
- fileStore,
+ buildFileStore(),
primaryKeys.length == 0,
isContinuous,
discoveryIntervalMills(),
- latestContinuous,
+ continuousScanLatest,
projectedFields,
partitionPredicate,
fieldPredicate);
@@ -292,22 +279,22 @@ public class TableStore {
public Source<RowData, ?, ?> build() {
if (isContinuous) {
+ LogStartupMode startupMode = logOptions().get(SCAN);
if (logSourceProvider == null) {
- return buildFileSource(true);
- }
-
- if (isHybrid) {
+ return buildFileSource(true, startupMode == LogStartupMode.LATEST);
+ } else {
+ if (startupMode != LogStartupMode.FULL) {
+ return logSourceProvider.createSource(null);
+ }
return HybridSource.<RowData, StaticFileStoreSplitEnumerator>builder(
- buildFileSource(false))
+ buildFileSource(false, false))
.addSource(
new LogHybridSourceFactory(logSourceProvider),
Boundedness.CONTINUOUS_UNBOUNDED)
.build();
- } else {
- return logSourceProvider.createSource(null);
}
} else {
- return buildFileSource(false);
+ return buildFileSource(false, false);
}
}
diff --git a/flink-table-store-connector/src/main/java/org/apache/flink/table/store/connector/source/TableStoreSource.java b/flink-table-store-connector/src/main/java/org/apache/flink/table/store/connector/source/TableStoreSource.java
index 11da93e..8de30f6 100644
--- a/flink-table-store-connector/src/main/java/org/apache/flink/table/store/connector/source/TableStoreSource.java
+++ b/flink-table-store-connector/src/main/java/org/apache/flink/table/store/connector/source/TableStoreSource.java
@@ -135,7 +135,6 @@ public class TableStoreSource
tableStore
.sourceBuilder()
.withContinuousMode(streaming)
- .withHybridMode(streaming && logSourceProvider != null)
.withLogSourceProvider(logSourceProvider)
.withProjection(projectFields)
.withPartitionPredicate(PredicateConverter.convert(partitionFilters))
diff --git a/flink-table-store-connector/src/test/java/org/apache/flink/table/store/connector/ReadWriteTableITCase.java b/flink-table-store-connector/src/test/java/org/apache/flink/table/store/connector/ReadWriteTableITCase.java
index 86ec5dc..3458529 100644
--- a/flink-table-store-connector/src/test/java/org/apache/flink/table/store/connector/ReadWriteTableITCase.java
+++ b/flink-table-store-connector/src/test/java/org/apache/flink/table/store/connector/ReadWriteTableITCase.java
@@ -19,6 +19,7 @@
package org.apache.flink.table.store.connector;
import org.apache.flink.api.common.RuntimeExecutionMode;
+import org.apache.flink.api.java.tuple.Tuple2;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.table.api.EnvironmentSettings;
import org.apache.flink.table.api.TableResult;
@@ -29,6 +30,7 @@ import org.apache.flink.table.catalog.ObjectPath;
import org.apache.flink.table.store.file.FileStoreOptions;
import org.apache.flink.table.store.file.utils.BlockingIterator;
import org.apache.flink.table.store.kafka.KafkaTableTestBase;
+import org.apache.flink.table.store.log.LogOptions;
import org.apache.flink.types.Row;
import org.junit.Test;
@@ -58,8 +60,6 @@ public class ReadWriteTableITCase extends KafkaTableTestBase {
@Test
public void testBatchWriteWithPartitionedRecordsWithPk() throws Exception {
- String managedTable = prepareEnvAndWrite(false, false, true, true);
-
// input is dailyRates()
List<Row> expectedRecords =
Arrays.asList(
@@ -70,7 +70,7 @@ public class ReadWriteTableITCase extends KafkaTableTestBase {
// part = 2022-01-02
changelogRow("+I", "Euro", 119L, "2022-01-02"));
// test batch read
- collectAndCheck(tEnv, managedTable, Collections.emptyMap(), expectedRecords).close();
+ String managedTable = collectAndCheckBatchReadWrite(true, true, expectedRecords);
checkFileStorePath(tEnv, managedTable);
// test streaming read
@@ -91,22 +91,27 @@ public class ReadWriteTableITCase extends KafkaTableTestBase {
assertNoMoreRecords(streamIter);
// batch read to check partition refresh
- expectedRecords = new ArrayList<>(expectedRecords);
- expectedRecords.remove(3);
- expectedRecords.add(changelogRow("+I", "Euro", 100L, "2022-01-02"));
- expectedRecords.add(changelogRow("+I", "Yen", 1L, "2022-01-02"));
- collectAndCheck(tEnv, managedTable, Collections.emptyMap(), expectedRecords).close();
+ collectAndCheck(
+ tEnv,
+ managedTable,
+ Collections.emptyMap(),
+ Arrays.asList(
+ // part = 2022-01-01
+ changelogRow("+I", "US Dollar", 102L, "2022-01-01"),
+ changelogRow("+I", "Yen", 1L, "2022-01-01"),
+ changelogRow("+I", "Euro", 114L, "2022-01-01"),
+ // part = 2022-01-02
+ changelogRow("+I", "Euro", 100L, "2022-01-02"),
+ changelogRow("+I", "Yen", 1L, "2022-01-02")))
+ .close();
}
@Test
public void testBatchWriteWithPartitionedRecordsWithoutPk() throws Exception {
- String managedTable = prepareEnvAndWrite(false, false, true, false);
-
// input is dailyRates()
- List<Row> expectedRecords = dailyRates();
// test batch read
- collectAndCheck(tEnv, managedTable, Collections.emptyMap(), expectedRecords).close();
+ String managedTable = collectAndCheckBatchReadWrite(true, false, dailyRates());
checkFileStorePath(tEnv, managedTable);
// overwrite dynamic partition
@@ -135,15 +140,15 @@ public class ReadWriteTableITCase extends KafkaTableTestBase {
@Test
public void testBatchWriteWithNonPartitionedRecordsWithPk() throws Exception {
- String managedTable = prepareEnvAndWrite(false, false, false, true);
-
// input is rates()
- List<Row> expectedRecords =
- Arrays.asList(
- changelogRow("+I", "US Dollar", 102L),
- changelogRow("+I", "Yen", 1L),
- changelogRow("+I", "Euro", 119L));
- collectAndCheck(tEnv, managedTable, Collections.emptyMap(), expectedRecords).close();
+ String managedTable =
+ collectAndCheckBatchReadWrite(
+ false,
+ true,
+ Arrays.asList(
+ changelogRow("+I", "US Dollar", 102L),
+ changelogRow("+I", "Yen", 1L),
+ changelogRow("+I", "Euro", 119L)));
checkFileStorePath(tEnv, managedTable);
// overwrite the whole table
@@ -151,37 +156,35 @@ public class ReadWriteTableITCase extends KafkaTableTestBase {
managedTable,
Collections.emptyMap(),
Collections.singletonList(new String[] {"'Euro'", "100"}));
- expectedRecords = new ArrayList<>(expectedRecords);
- expectedRecords.clear();
- expectedRecords.add(changelogRow("+I", "Euro", 100L));
- collectAndCheck(tEnv, managedTable, Collections.emptyMap(), expectedRecords).close();
+ collectAndCheck(
+ tEnv,
+ managedTable,
+ Collections.emptyMap(),
+ Collections.singletonList(changelogRow("+I", "Euro", 100L)));
}
@Test
public void testBatchWriteNonPartitionedRecordsWithoutPk() throws Exception {
- String managedTable = prepareEnvAndWrite(false, false, false, false);
-
// input is rates()
- List<Row> expectedRecords = rates();
- collectAndCheck(tEnv, managedTable, Collections.emptyMap(), expectedRecords).close();
+ String managedTable = collectAndCheckBatchReadWrite(false, false, rates());
checkFileStorePath(tEnv, managedTable);
}
@Test
public void testEnableLogAndStreamingReadWritePartitionedRecordsWithPk() throws Exception {
- String managedTable = prepareEnvAndWrite(true, true, true, true);
-
// input is dailyRatesChangelogWithoutUB()
// test hybrid read
- List<Row> expectedRecords =
- Arrays.asList(
- // part = 2022-01-01
- changelogRow("+I", "US Dollar", 102L, "2022-01-01"),
- // part = 2022-01-02
- changelogRow("+I", "Euro", 119L, "2022-01-02"));
- BlockingIterator<Row, Row> streamIter =
- collectAndCheck(tEnv, managedTable, Collections.emptyMap(), expectedRecords);
+ Tuple2<String, BlockingIterator<Row, Row>> tuple =
+ collectAndCheckStreamingReadWriteWithoutClose(
+ Collections.emptyMap(),
+ Arrays.asList(
+ // part = 2022-01-01
+ changelogRow("+I", "US Dollar", 102L, "2022-01-01"),
+ // part = 2022-01-02
+ changelogRow("+I", "Euro", 119L, "2022-01-02")));
+ String managedTable = tuple.f0;
checkFileStorePath(tEnv, managedTable);
+ BlockingIterator<Row, Row> streamIter = tuple.f1;
// overwrite partition 2022-01-02
prepareEnvAndOverwrite(
@@ -210,64 +213,324 @@ public class ReadWriteTableITCase extends KafkaTableTestBase {
@Test
public void testDisableLogAndStreamingReadWritePartitionedRecordsWithPk() throws Exception {
- String managedTable = prepareEnvAndWrite(true, false, true, true);
-
// input is dailyRatesChangelogWithoutUB()
// file store continuous read
// will not merge, at least collect two records
- List<Row> expectedRecords =
+ checkFileStorePath(
+ tEnv,
+ collectAndCheckStreamingReadWriteWithClose(
+ false,
+ true,
+ true,
+ Collections.emptyMap(),
+ Arrays.asList(
+ // part = 2022-01-01
+ changelogRow("+I", "US Dollar", 102L, "2022-01-01"),
+ // part = 2022-01-02
+ changelogRow("+I", "Euro", 119L, "2022-01-02"))));
+ }
+
+ @Test
+ public void testStreamingReadWritePartitionedRecordsWithoutPk() throws Exception {
+ // input is dailyRatesChangelogWithUB()
+ // enable log store, file store bounded read with merge
+ checkFileStorePath(
+ tEnv,
+ collectAndCheckStreamingReadWriteWithClose(
+ true,
+ true,
+ false,
+ Collections.emptyMap(),
+ Arrays.asList(
+ // part = 2022-01-01
+ changelogRow("+I", "US Dollar", 102L, "2022-01-01"),
+ // part = 2022-01-02
+ changelogRow("+I", "Euro", 115L, "2022-01-02"))));
+ }
+
+ @Test
+ public void testStreamingReadWriteNonPartitionedRecordsWithPk() throws Exception {
+ // input is ratesChangelogWithoutUB()
+ // enable log store, file store bounded read with merge
+ checkFileStorePath(
+ tEnv,
+ collectAndCheckStreamingReadWriteWithClose(
+ true,
+ false,
+ true,
+ Collections.emptyMap(),
+ Arrays.asList(
+ changelogRow("+I", "US Dollar", 102L),
+ changelogRow("+I", "Euro", 119L))));
+ }
+
+ @Test
+ public void testStreamingReadWriteNonPartitionedRecordsWithoutPk() throws Exception {
+ // input is ratesChangelogWithUB()
+ // enable log store, with default full scan mode, will merge
+ checkFileStorePath(
+ tEnv,
+ collectAndCheckStreamingReadWriteWithClose(
+ true,
+ false,
+ false,
+ Collections.emptyMap(),
+ Arrays.asList(
+ changelogRow("+I", "US Dollar", 102L),
+ changelogRow("+I", "Euro", 119L))));
+ }
+
+ @Test
+ public void testReadLatestChangelogOfPartitionedRecordsWithPk() throws Exception {
+ // input is dailyRatesChangelogWithoutUB()
+ collectLatestLogAndCheck(
+ false,
+ true,
+ true,
Arrays.asList(
// part = 2022-01-01
changelogRow("+I", "US Dollar", 102L, "2022-01-01"),
+ changelogRow("+I", "Euro", 114L, "2022-01-01"),
+ changelogRow("+I", "Yen", 1L, "2022-01-01"),
+ changelogRow("-U", "Euro", 114L, "2022-01-01"),
+ changelogRow("+U", "Euro", 116L, "2022-01-01"),
+ changelogRow("-D", "Yen", 1L, "2022-01-01"),
+ changelogRow("-D", "Euro", 116L, "2022-01-01"),
// part = 2022-01-02
- changelogRow("+I", "Euro", 119L, "2022-01-02"));
- collectAndCheck(tEnv, managedTable, Collections.emptyMap(), expectedRecords).close();
+ changelogRow("+I", "Euro", 119L, "2022-01-02")));
}
@Test
- public void testStreamingReadWritePartitionedRecordsWithoutPk() throws Exception {
- String managedTable = prepareEnvAndWrite(true, true, true, false);
-
+ public void testReadLatestChangelogOfPartitionedRecordsWithoutPk() throws Exception {
// input is dailyRatesChangelogWithUB()
- // enable log store, file store bounded read with merge
- List<Row> expectedRecords =
+ collectLatestLogAndCheck(
+ false,
+ true,
+ false,
Arrays.asList(
// part = 2022-01-01
changelogRow("+I", "US Dollar", 102L, "2022-01-01"),
+ changelogRow("+I", "Euro", 116L, "2022-01-01"),
+ changelogRow("-D", "Euro", 116L, "2022-01-01"),
+ changelogRow("+I", "Yen", 1L, "2022-01-01"),
+ changelogRow("-D", "Yen", 1L, "2022-01-01"),
// part = 2022-01-02
- changelogRow("+I", "Euro", 115L, "2022-01-02"));
- collectAndCheck(tEnv, managedTable, Collections.emptyMap(), expectedRecords).close();
+ changelogRow("+I", "Euro", 114L, "2022-01-02"),
+ changelogRow("-D", "Euro", 114L, "2022-01-02"),
+ changelogRow("+I", "Euro", 119L, "2022-01-02"),
+ changelogRow("-D", "Euro", 119L, "2022-01-02"),
+ changelogRow("+I", "Euro", 115L, "2022-01-02")));
}
@Test
- public void testStreamingReadWriteNonPartitionedRecordsWithPk() throws Exception {
- String managedTable = prepareEnvAndWrite(true, true, false, true);
-
+ public void testReadLatestChangelogOfNonPartitionedRecordsWithPk() throws Exception {
// input is ratesChangelogWithoutUB()
- // enable log store, file store bounded read with merge
- List<Row> expectedRecords =
+ collectLatestLogAndCheck(
+ false,
+ false,
+ true,
Arrays.asList(
- changelogRow("+I", "US Dollar", 102L), changelogRow("+I", "Euro", 119L));
- collectAndCheck(tEnv, managedTable, Collections.emptyMap(), expectedRecords).close();
+ changelogRow("+I", "US Dollar", 102L),
+ changelogRow("+I", "Euro", 114L),
+ changelogRow("+I", "Yen", 1L),
+ changelogRow("-U", "Euro", 114L),
+ changelogRow("+U", "Euro", 116L),
+ changelogRow("-D", "Euro", 116L),
+ changelogRow("+I", "Euro", 119L),
+ changelogRow("-D", "Yen", 1L)));
}
@Test
- public void testStreamingReadWriteNonPartitionedRecordsWithoutPk() throws Exception {
- String managedTable = prepareEnvAndWrite(true, true, false, false);
-
+ public void testReadLatestChangelogOfNonPartitionedRecordsWithoutPk() throws Exception {
// input is ratesChangelogWithUB()
- // enable log store, with default full scan mode, will merge
- List<Row> expectedRecords =
+ collectLatestLogAndCheck(
+ false,
+ false,
+ false,
+ Arrays.asList(
+ changelogRow("+I", "US Dollar", 102L),
+ changelogRow("+I", "Euro", 114L),
+ changelogRow("+I", "Yen", 1L),
+ changelogRow("-D", "Euro", 114L),
+ changelogRow("+I", "Euro", 116L),
+ changelogRow("-D", "Euro", 116L),
+ changelogRow("+I", "Euro", 119L),
+ changelogRow("-D", "Euro", 119L),
+ changelogRow("+I", "Euro", 119L),
+ changelogRow("-D", "Yen", 1L)));
+ }
+
+ @Test
+ public void testReadLatestChangelogOfInsertOnlyRecords() throws Exception {
+ // input is rates()
+ List<Row> expected =
+ Arrays.asList(
+ changelogRow("+I", "US Dollar", 102L),
+ changelogRow("+I", "Euro", 114L),
+ changelogRow("+I", "Yen", 1L),
+ changelogRow("-U", "Euro", 114L),
+ changelogRow("+U", "Euro", 119L));
+
+ // currency as pk
+ collectLatestLogAndCheck(true, false, true, expected);
+
+ // without pk
+ collectLatestLogAndCheck(true, false, true, expected);
+ }
+
+ @Test
+ public void testReadInsertOnlyChangelogFromTimestamp() throws Exception {
+ // input is dailyRates()
+ collectChangelogFromTimestampAndCheck(
+ true,
+ true,
+ true,
+ 0,
+ Arrays.asList(
+ // part = 2022-01-01
+ changelogRow("+I", "US Dollar", 102L, "2022-01-01"),
+ changelogRow("+I", "Yen", 1L, "2022-01-01"),
+ changelogRow("+I", "Euro", 114L, "2022-01-01"),
+ // part = 2022-01-02
+ changelogRow("+I", "Euro", 119L, "2022-01-02")));
+
+ collectChangelogFromTimestampAndCheck(true, true, false, 0, dailyRates());
+
+ // input is rates()
+ collectChangelogFromTimestampAndCheck(
+ true,
+ false,
+ true,
+ 0,
+ Arrays.asList(
+ changelogRow("+I", "US Dollar", 102L),
+ changelogRow("+I", "Euro", 114L),
+ changelogRow("+I", "Yen", 1L),
+ changelogRow("-U", "Euro", 114L),
+ changelogRow("+U", "Euro", 119L)));
+
+ collectChangelogFromTimestampAndCheck(true, false, false, 0, rates());
+
+ collectChangelogFromTimestampAndCheck(
+ true, false, false, Long.MAX_VALUE - 1, Collections.emptyList());
+ }
+
+ @Test
+ public void testReadRetractChangelogFromTimestamp() throws Exception {
+ // input is dailyRatesChangelogWithUB()
+ collectChangelogFromTimestampAndCheck(
+ false,
+ true,
+ false,
+ 0,
Arrays.asList(
- changelogRow("+I", "US Dollar", 102L), changelogRow("+I", "Euro", 119L));
+ // part = 2022-01-01
+ changelogRow("+I", "US Dollar", 102L, "2022-01-01"),
+ changelogRow("+I", "Euro", 116L, "2022-01-01"),
+ changelogRow("-D", "Euro", 116L, "2022-01-01"),
+ changelogRow("+I", "Yen", 1L, "2022-01-01"),
+ changelogRow("-D", "Yen", 1L, "2022-01-01"),
+ // part = 2022-01-02
+ changelogRow("+I", "Euro", 114L, "2022-01-02"),
+ changelogRow("-D", "Euro", 114L, "2022-01-02"),
+ changelogRow("+I", "Euro", 119L, "2022-01-02"),
+ changelogRow("-D", "Euro", 119L, "2022-01-02"),
+ changelogRow("+I", "Euro", 115L, "2022-01-02")));
- collectAndCheck(tEnv, managedTable, Collections.emptyMap(), expectedRecords).close();
+ // input is dailyRatesChangelogWithoutUB()
+ collectChangelogFromTimestampAndCheck(
+ false,
+ true,
+ true,
+ 0,
+ Arrays.asList(
+ // part = 2022-01-01
+ changelogRow("+I", "US Dollar", 102L, "2022-01-01"),
+ changelogRow("+I", "Euro", 114L, "2022-01-01"),
+ changelogRow("+I", "Yen", 1L, "2022-01-01"),
+ changelogRow("-U", "Euro", 114L, "2022-01-01"),
+ changelogRow("+U", "Euro", 116L, "2022-01-01"),
+ changelogRow("-D", "Yen", 1L, "2022-01-01"),
+ changelogRow("-D", "Euro", 116L, "2022-01-01"),
+ // part = 2022-01-02
+ changelogRow("+I", "Euro", 119L, "2022-01-02")));
}
// ------------------------ Tools ----------------------------------
- private String prepareEnvAndWrite(
- boolean streaming, boolean enableLogStore, boolean partitioned, boolean hasPk)
+ private String collectAndCheckBatchReadWrite(
+ boolean partitioned, boolean hasPk, List<Row> expected) throws Exception {
+ return collectAndCheckUnderSameEnv(
+ false,
+ false,
+ true,
+ partitioned,
+ hasPk,
+ true,
+ Collections.emptyMap(),
+ expected)
+ .f0;
+ }
+
+ private String collectAndCheckStreamingReadWriteWithClose(
+ boolean enableLogStore,
+ boolean partitioned,
+ boolean hasPk,
+ Map<String, String> readHints,
+ List<Row> expected)
+ throws Exception {
+ Tuple2<String, BlockingIterator<Row, Row>> tuple =
+ collectAndCheckUnderSameEnv(
+ true, enableLogStore, false, partitioned, hasPk, true, readHints, expected);
+ tuple.f1.close();
+ return tuple.f0;
+ }
+
+ private Tuple2<String, BlockingIterator<Row, Row>>
+ collectAndCheckStreamingReadWriteWithoutClose(
+ Map<String, String> readHints, List<Row> expected) throws Exception {
+ return collectAndCheckUnderSameEnv(
+ true, true, false, true, true, true, readHints, expected);
+ }
+
+ private void collectLatestLogAndCheck(
+ boolean insertOnly, boolean partitioned, boolean hasPk, List<Row> expected)
+ throws Exception {
+ Map<String, String> hints = new HashMap<>();
+ hints.put(
+ LOG_PREFIX + LogOptions.SCAN.key(),
+ LogOptions.LogStartupMode.LATEST.name().toLowerCase());
+ collectAndCheckUnderSameEnv(
+ true, true, insertOnly, partitioned, hasPk, false, hints, expected)
+ .f1
+ .close();
+ }
+
+ private void collectChangelogFromTimestampAndCheck(
+ boolean insertOnly,
+ boolean partitioned,
+ boolean hasPk,
+ long timestamp,
+ List<Row> expected)
+ throws Exception {
+ Map<String, String> hints = new HashMap<>();
+ hints.put(LOG_PREFIX + LogOptions.SCAN.key(), "from-timestamp");
+ hints.put(LOG_PREFIX + LogOptions.SCAN_TIMESTAMP_MILLS.key(), String.valueOf(timestamp));
+ collectAndCheckUnderSameEnv(
+ true, true, insertOnly, partitioned, hasPk, true, hints, expected)
+ .f1
+ .close();
+ }
+
+ private Tuple2<String, BlockingIterator<Row, Row>> collectAndCheckUnderSameEnv(
+ boolean streaming,
+ boolean enableLogStore,
+ boolean insertOnly,
+ boolean partitioned,
+ boolean hasPk,
+ boolean writeFirst,
+ Map<String, String> readHints,
+ List<Row> expected)
throws Exception {
Map<String, String> tableOptions = new HashMap<>();
rootPath = TEMPORARY_FOLDER.newFolder().getPath();
@@ -282,7 +545,11 @@ public class ReadWriteTableITCase extends KafkaTableTestBase {
String helperTableDdl;
if (streaming) {
helperTableDdl =
- prepareHelperSourceWithChangelogRecords(sourceTable, partitioned, hasPk);
+ insertOnly
+ ? prepareHelperSourceWithInsertOnlyRecords(
+ sourceTable, partitioned, hasPk)
+ : prepareHelperSourceWithChangelogRecords(
+ sourceTable, partitioned, hasPk);
env = buildStreamEnv();
builder.inStreamingMode();
} else {
@@ -292,13 +559,29 @@ public class ReadWriteTableITCase extends KafkaTableTestBase {
builder.inBatchMode();
}
String managedTableDdl = prepareManagedTableDdl(sourceTable, managedTable, tableOptions);
- String insertQuery = prepareInsertIntoQuery(sourceTable, managedTable);
tEnv = StreamTableEnvironment.create(env, builder.build());
tEnv.executeSql(helperTableDdl);
tEnv.executeSql(managedTableDdl);
- tEnv.executeSql(insertQuery).await();
- return managedTable;
+
+ String insertQuery = prepareInsertIntoQuery(sourceTable, managedTable);
+ String selectQuery = prepareSimpleSelectQuery(managedTable, readHints);
+
+ BlockingIterator<Row, Row> iterator;
+ if (writeFirst) {
+ tEnv.executeSql(insertQuery).await();
+ iterator = BlockingIterator.of(tEnv.executeSql(selectQuery).collect());
+ } else {
+ iterator = BlockingIterator.of(tEnv.executeSql(selectQuery).collect());
+ tEnv.executeSql(insertQuery).await();
+ }
+ if (expected.isEmpty()) {
+ assertNoMoreRecords(iterator);
+ } else {
+ assertThat(iterator.collect(expected.size(), 10, TimeUnit.SECONDS))
+ .containsExactlyInAnyOrderElementsOf(expected);
+ }
+ return Tuple2.of(managedTable, iterator);
}
private void prepareEnvAndOverwrite(
@@ -465,7 +748,7 @@ public class ReadWriteTableITCase extends KafkaTableTestBase {
private static String buildHints(Map<String, String> hints) {
if (hints.size() > 0) {
- StringBuilder hintsBuilder = new StringBuilder("/* + OPTIONS (");
+ StringBuilder hintsBuilder = new StringBuilder("/*+ OPTIONS (");
hints.forEach(
(k, v) -> {
hintsBuilder.append(String.format("'%s'", k));
@@ -473,7 +756,7 @@ public class ReadWriteTableITCase extends KafkaTableTestBase {
hintsBuilder.append(String.format("'%s', ", v));
});
int len = hintsBuilder.length();
- hintsBuilder.deleteCharAt(len - 1);
+ hintsBuilder.deleteCharAt(len - 2);
hintsBuilder.append(") */");
return hintsBuilder.toString();
}
diff --git a/flink-table-store-kafka/pom.xml b/flink-table-store-kafka/pom.xml
index bb8633f..17491e2 100644
--- a/flink-table-store-kafka/pom.xml
+++ b/flink-table-store-kafka/pom.xml
@@ -110,7 +110,7 @@ under the License.
<!-- include 2.0 server for tests -->
<groupId>org.apache.kafka</groupId>
<artifactId>kafka_${scala.binary.version}</artifactId>
- <version>2.4.1</version>
+ <version>2.8.1</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
diff --git a/flink-table-store-kafka/src/main/java/org/apache/flink/table/store/kafka/KafkaLogSourceProvider.java b/flink-table-store-kafka/src/main/java/org/apache/flink/table/store/kafka/KafkaLogSourceProvider.java
index d504802..60308a0 100644
--- a/flink-table-store-kafka/src/main/java/org/apache/flink/table/store/kafka/KafkaLogSourceProvider.java
+++ b/flink-table-store-kafka/src/main/java/org/apache/flink/table/store/kafka/KafkaLogSourceProvider.java
@@ -52,7 +52,7 @@ public class KafkaLogSourceProvider implements LogSourceProvider {
private final int[] primaryKey;
- @Nullable private final DeserializationSchema<RowData> keyDeserializer;
+ @Nullable private final DeserializationSchema<RowData> primaryKeyDeserializer;
private final DeserializationSchema<RowData> valueDeserializer;
@@ -69,7 +69,7 @@ public class KafkaLogSourceProvider implements LogSourceProvider {
Properties properties,
DataType physicalType,
int[] primaryKey,
- @Nullable DeserializationSchema<RowData> keyDeserializer,
+ @Nullable DeserializationSchema<RowData> primaryKeyDeserializer,
DeserializationSchema<RowData> valueDeserializer,
@Nullable int[][] projectFields,
LogConsistency consistency,
@@ -79,7 +79,7 @@ public class KafkaLogSourceProvider implements LogSourceProvider {
this.properties = properties;
this.physicalType = physicalType;
this.primaryKey = primaryKey;
- this.keyDeserializer = keyDeserializer;
+ this.primaryKeyDeserializer = primaryKeyDeserializer;
this.valueDeserializer = valueDeserializer;
this.projectFields = projectFields;
this.consistency = consistency;
@@ -95,7 +95,7 @@ public class KafkaLogSourceProvider implements LogSourceProvider {
properties.setProperty(ISOLATION_LEVEL_CONFIG, "read_committed");
break;
case EVENTUAL:
- if (keyDeserializer == null) {
+ if (primaryKeyDeserializer == null) {
throw new IllegalArgumentException(
"Can not use EVENTUAL consistency mode for non-pk table.");
}
@@ -117,7 +117,7 @@ public class KafkaLogSourceProvider implements LogSourceProvider {
new KafkaLogDeserializationSchema(
physicalType,
primaryKey,
- keyDeserializer,
+ primaryKeyDeserializer,
valueDeserializer,
projectFields));
}
[flink-table-store] 03/09: [FLINK-26918] Add documentation build to Github Actions
Posted by lz...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
lzljs3620320 pushed a commit to branch release-0.1
in repository https://gitbox.apache.org/repos/asf/flink-table-store.git
commit e157ebdd37669c5bdc836436a496dabf87ba5266
Author: Jingsong Lee <ji...@gmail.com>
AuthorDate: Wed Mar 30 16:01:53 2022 +0800
[FLINK-26918] Add documentation build to Github Actions
This closes #68
---
.github/workflows/docs.sh | 39 ++++++++++++++++++++++++++
.github/workflows/docs.yml | 69 ++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 108 insertions(+)
diff --git a/.github/workflows/docs.sh b/.github/workflows/docs.sh
new file mode 100755
index 0000000..c677a31
--- /dev/null
+++ b/.github/workflows/docs.sh
@@ -0,0 +1,39 @@
+#!/usr/bin/env bash
+################################################################################
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+################################################################################
+set -e
+
+mvn --version
+java -version
+javadoc -J-version
+
+# setup hugo
+HUGO_REPO=https://github.com/gohugoio/hugo/releases/download/v0.80.0/hugo_extended_0.80.0_Linux-64bit.tar.gz
+HUGO_ARTIFACT=hugo_extended_0.80.0_Linux-64bit.tar.gz
+if ! curl --fail -OL $HUGO_REPO ; then
+ echo "Failed to download Hugo binary"
+ exit 1
+fi
+tar -zxvf $HUGO_ARTIFACT
+git submodule update --init --recursive
+# generate docs into docs/target
+./hugo -v --source docs --destination target
+if [ $? -ne 0 ]; then
+ echo "Error building the docs"
+ exit 1
+fi
diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml
new file mode 100644
index 0000000..8f9cd37
--- /dev/null
+++ b/.github/workflows/docs.yml
@@ -0,0 +1,69 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (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.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+name: "Build documentation"
+on:
+ schedule:
+ - cron: '0 0 * * *' # Deploy every day
+
+jobs:
+ build-documentation:
+ if: github.repository == 'apache/flink-table-store'
+ runs-on: ubuntu-latest
+ strategy:
+ max-parallel: 1
+ matrix:
+ branch:
+ - master
+ - release-0.1
+ steps:
+ - uses: actions/checkout@v3
+ with:
+ ref: ${{ matrix.branch }}
+ - name: Set branch environment variable
+ run: |
+ currentBranch=$(git branch --show-current)
+
+ echo "flink_table_store_branch=${currentBranch}" >> ${GITHUB_ENV}
+
+ if [ "${currentBranch}" = "master" ]; then
+ echo "flink_table_store_alias=release-0.2" >> ${GITHUB_ENV}
+ elif [ "${currentBranch}" = "release-0.1" ]; then
+ echo "flink_table_store_alias=stable" >> ${GITHUB_ENV}
+ fi
+ - name: Build documentation
+ run: |
+ docker run --rm --volume "$PWD:/root/flink-table-store" chesnay/flink-ci:java_8_11 bash -c "cd /root/flink-table-store && ./.github/workflows/docs.sh"
+ - name: Upload documentation
+ uses: burnett01/rsync-deployments@5.2
+ with:
+ switches: --archive --compress
+ path: docs/target/
+ remote_path: ${{ secrets.NIGHTLIES_RSYNC_PATH }}/flink/flink-table-store-docs-${{ env.flink_table_store_branch }}/
+ remote_host: ${{ secrets.NIGHTLIES_RSYNC_HOST }}
+ remote_port: ${{ secrets.NIGHTLIES_RSYNC_PORT }}
+ remote_user: ${{ secrets.NIGHTLIES_RSYNC_USER }}
+ remote_key: ${{ secrets.NIGHTLIES_RSYNC_KEY }}
+ - name: Upload documentation alias
+ if: env.flink_table_store_alias != ''
+ uses: burnett01/rsync-deployments@5.2
+ with:
+ switches: --archive --compress
+ path: docs/target/
+ remote_path: ${{ secrets.NIGHTLIES_RSYNC_PATH }}/flink/flink-table-store-docs-${{ env.flink_table_store_alias }}/
+ remote_host: ${{ secrets.NIGHTLIES_RSYNC_HOST }}
+ remote_port: ${{ secrets.NIGHTLIES_RSYNC_PORT }}
+ remote_user: ${{ secrets.NIGHTLIES_RSYNC_USER }}
+ remote_key: ${{ secrets.NIGHTLIES_RSYNC_KEY }}
[flink-table-store] 05/09: [hotfix] Reset theme/book to Flink perfer version
Posted by lz...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
lzljs3620320 pushed a commit to branch release-0.1
in repository https://gitbox.apache.org/repos/asf/flink-table-store.git
commit 2e3b425e4604509fe32b9667d74dc54897333267
Author: JingsongLi <lz...@aliyun.com>
AuthorDate: Fri Apr 1 16:43:05 2022 +0800
[hotfix] Reset theme/book to Flink perfer version
---
docs/themes/book | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/docs/themes/book b/docs/themes/book
index 98d19b8..a486adf 160000
--- a/docs/themes/book
+++ b/docs/themes/book
@@ -1 +1 @@
-Subproject commit 98d19b8e95019534622fd4c5eae707423730df2c
+Subproject commit a486adf8462c0abfc9034436ddd72927d6656809
[flink-table-store] 08/09: [FLINK-26898] Introduce creating table document for table store
Posted by lz...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
lzljs3620320 pushed a commit to branch release-0.1
in repository https://gitbox.apache.org/repos/asf/flink-table-store.git
commit 716eb827b4f8487d9feff4c9dc3bebb10d443de3
Author: Jingsong Lee <ji...@gmail.com>
AuthorDate: Fri Apr 1 19:39:45 2022 +0800
[FLINK-26898] Introduce creating table document for table store
This closes #66
---
docs/config.toml | 1 +
docs/content/docs/development/_index.md | 26 +++++
docs/content/docs/development/create-table.md | 153 ++++++++++++++++++++++++++
docs/content/docs/development/distribution.md | 107 ++++++++++++++++++
docs/content/docs/development/overview.md | 139 +++++++++++++++++++++++
docs/static/img/architecture.svg | 1 +
pom.xml | 1 +
7 files changed, 428 insertions(+)
diff --git a/docs/config.toml b/docs/config.toml
index 1119806..274144d 100644
--- a/docs/config.toml
+++ b/docs/config.toml
@@ -61,6 +61,7 @@ pygmentsUseClasses = true
]
PreviousDocs = [
+ ["0.1", "https://nightlies.apache.org/flink/flink-table-store-docs-release-0.1"],
]
[markup]
diff --git a/docs/content/docs/development/_index.md b/docs/content/docs/development/_index.md
new file mode 100644
index 0000000..3229296
--- /dev/null
+++ b/docs/content/docs/development/_index.md
@@ -0,0 +1,26 @@
+---
+title: Development
+icon: <i class="fa fa-code title maindish" aria-hidden="true"></i>
+bold: true
+sectionBreak: true
+bookCollapseSection: true
+weight: 2
+---
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
diff --git a/docs/content/docs/development/create-table.md b/docs/content/docs/development/create-table.md
new file mode 100644
index 0000000..01185f6
--- /dev/null
+++ b/docs/content/docs/development/create-table.md
@@ -0,0 +1,153 @@
+---
+title: "Create Table"
+weight: 2
+type: docs
+aliases:
+- /development/create-table.html
+---
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+
+# CREATE statement
+
+```sql
+CREATE TABLE [IF NOT EXISTS] [catalog_name.][db_name.]table_name
+ (
+ { <physical_column_definition> | <computed_column_definition> }[ , ...n]
+ [ <watermark_definition> ]
+ [ <table_constraint> ][ , ...n]
+ )
+ [PARTITIONED BY (partition_column_name1, partition_column_name2, ...)]
+ WITH (key1=val1, key2=val2, ...)
+
+<physical_column_definition>:
+ column_name column_type [ <column_constraint> ] [COMMENT column_comment]
+
+<column_constraint>:
+ [CONSTRAINT constraint_name] PRIMARY KEY NOT ENFORCED
+
+<table_constraint>:
+ [CONSTRAINT constraint_name] PRIMARY KEY (column_name, ...) NOT ENFORCED
+
+<computed_column_definition>:
+ column_name AS computed_column_expression [COMMENT column_comment]
+
+<watermark_definition>:
+ WATERMARK FOR rowtime_column_name AS watermark_strategy_expression
+```
+
+{{< hint info >}}
+__Note:__ To ensure the uniqueness of the primary key, the
+primary key must contain the partition field.
+{{< /hint >}}
+
+{{< hint info >}}
+__Note:__ Metadata column is not supported yet.
+{{< /hint >}}
+
+Table options that do not contain the 'connector' key and value
+represent a managed table. Creating a table will create the
+corresponding physical storage.
+
+When the corresponding physical storage already exists,
+such as a file directory or kafka topic:
+- If you want to reuse it, use `CREATE TABLE IF NOT EXISTS`
+- If you don't want to reuse it, `DROP TABLE IF EXISTS`
+ or delete it yourself.
+
+It is recommended that you use a persistent catalog, such as
+`HiveCatalog`, otherwise make sure you create the table with
+the same options each time.
+
+## Session Options
+
+To create a managed table, you need to set the required
+session options in advance. Session options are only valid
+when creating a table, not interfering with reading or
+writing the table.
+
+You can set session options in the following two ways:
+- Edit `flink-conf.yaml`.
+- Via `TableEnvironment.getConfig().set`.
+
+The difference between session options and table options
+is that the session option needs to be prefixed with
+`table-store`. Take `bucket` option for example:
+- set as session level: `SET 'table-store.bucket' = '4';`
+- set as per table level: `CREATE TABLE ... WITH ('bucket' = '4')`
+
+Important options include the following:
+
+<table class="table table-bordered">
+ <thead>
+ <tr>
+ <th class="text-left" style="width: 20%">Option</th>
+ <th class="text-center" style="width: 5%">Required</th>
+ <th class="text-center" style="width: 5%">Default</th>
+ <th class="text-center" style="width: 10%">Type</th>
+ <th class="text-center" style="width: 60%">Description</th>
+ </tr>
+ </thead>
+ <tbody>
+ <tr>
+ <td><h5>file.path</h5></td>
+ <td>Yes</td>
+ <td style="word-wrap: break-word;">(none)</td>
+ <td>String</td>
+ <td>The root file path of the table store in the filesystem.</td>
+ </tr>
+ <tr>
+ <td><h5>bucket</h5></td>
+ <td>Yes</td>
+ <td style="word-wrap: break-word;">1</td>
+ <td>Integer</td>
+ <td>The bucket number for table store.</td>
+ </tr>
+ <tr>
+ <td><h5>log.system</h5></td>
+ <td>No</td>
+ <td style="word-wrap: break-word;">(none)</td>
+ <td>String</td>
+ <td>The log system used to keep changes of the table, supports 'kafka'.</td>
+ </tr>
+ <tr>
+ <td><h5>log.kafka.bootstrap.servers</h5></td>
+ <td>No</td>
+ <td style="word-wrap: break-word;">(none)</td>
+ <td>String</td>
+ <td>Required Kafka server connection string for log store.</td>
+ </tr>
+ <tr>
+ <td><h5>log.retention</h5></td>
+ <td>No</td>
+ <td style="word-wrap: break-word;">(none)</td>
+ <td>Duration</td>
+ <td>The duration to keep a log file before deleting it. The default value is from the log system cluster.</td>
+ </tr>
+ </tbody>
+</table>
+
+## Physical storage
+
+Creating a table will create the corresponding physical storage:
+- The table's FileStore directory will be created under:
+ `${file.path}/${catalog_name}.catalog/${database_name}.db/${table_name}`
+- If `log.system` is configured as Kafka, a Topic named
+ "${catalog_name}.${database_name}.${table_name}" will be created
+ automatically when the table is created.
diff --git a/docs/content/docs/development/distribution.md b/docs/content/docs/development/distribution.md
new file mode 100644
index 0000000..c09901f
--- /dev/null
+++ b/docs/content/docs/development/distribution.md
@@ -0,0 +1,107 @@
+---
+title: "Distribution"
+weight: 3
+type: docs
+aliases:
+- /development/distribution.html
+---
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+
+# Distribution
+
+The data distribution of Table Store consists of three concepts:
+Partition, Bucket, and Primary Key.
+
+```sql
+CREATE TABLE MyTable (
+ user_id BIGINT,
+ item_id BIGINT,
+ behavior STRING,
+ dt STRING,
+ PRIMARY KEY (dt, user_id) NOT ENFORCED
+) PARTITION BY (dt) WITH (
+ 'bucket' = '4'
+);
+```
+
+For example, the `MyTable` table above has its data distribution
+in the following order:
+- Partition: isolating different data based on partition fields.
+- Bucket: Within a single partition, distributed into 4 different
+ buckets based on the hash value of the primary key.
+- Primary key: Within a single bucket, sorted by primary key to
+ build LSM structure.
+
+## Partition
+
+Table Store adopts the same partitioning concept as Apache Hive to
+separate data, and thus various operations can be managed by partition
+as a management unit.
+
+Partitioned filtering is the most effective way to improve performance,
+your query statements should contain partition filtering conditions
+as much as possible.
+
+## Bucket
+
+The record is hashed into different buckets according to the
+primary key or the whole row (without primary key).
+
+The number of buckets is very important as it determines the
+worst-case maximum processing parallelism. But it should not be
+too big, otherwise, the system will create a lot of small files.
+
+In general, the desired file size is 128 MB, the recommended data
+to be kept on disk in each sub-bucket is about 1 GB.
+
+## Primary Key
+
+The primary key is unique and is indexed.
+
+Flink Table Store imposes an ordering of data, which means the system
+will sort the primary key within each bucket. All fields will be used
+to sort if no primary key is defined. Using this feature, you can
+achieve high performance by adding filter conditions on the primary key.
+
+The primary key's choice is critical, especially when setting the composite
+primary key. A rule of thumb is to put the most frequently queried field in
+the front. For example:
+
+```sql
+CREATE TABLE MyTable (
+ catalog_id BIGINT,
+ user_id BIGINT,
+ item_id BIGINT,
+ behavior STRING,
+ dt STRING,
+ ......
+);
+```
+
+For this table, assuming that the composite primary keys are
+the `catalog_id` and `user_id` fields, there are two ways to
+set the primary key:
+1. PRIMARY KEY (user_id, catalog_id)
+2. PRIMARY KEY (catalog_id, user_id)
+
+The two methods do not behave in the same way when querying.
+Use approach 1 if you have a large number of filtered queries
+with only `user_id`, and use approach 2 if you have a large
+number of filtered queries with only `catalog_id`.
diff --git a/docs/content/docs/development/overview.md b/docs/content/docs/development/overview.md
new file mode 100644
index 0000000..ffbef5e
--- /dev/null
+++ b/docs/content/docs/development/overview.md
@@ -0,0 +1,139 @@
+---
+title: "Overview"
+weight: 1
+type: docs
+aliases:
+- /development/overview.html
+---
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+
+# Overview
+
+Flink Table Store is a unified streaming and batch store for building dynamic
+tables on Apache Flink. Flink Table Store serves as the storage engine behind
+Flink SQL Managed Table.
+
+## Managed Table
+
+The typical usage of Flink SQL DDL is to specify the 'connector' and fill in
+the complex connection information in 'with'. The DDL just establishes an implicit
+relationship with the external system. We call such Table as external table.
+
+```sql
+-- an external table ddl
+CREATE TABLE KafkaTable (
+ `user_id` BIGINT,
+ `item_id` BIGINT,
+ `behavior` STRING
+) WITH (
+ 'connector' = 'kafka',
+ 'topic' = 'user_behavior',
+ 'properties.bootstrap.servers' = 'localhost:9092',
+ 'properties.group.id' = 'testGroup',
+ 'scan.startup.mode' = 'earliest-offset',
+ 'format' = 'csv'
+);
+```
+
+The managed table is different, the connection information is already
+filled in the session environment, the user only needs to focus on the
+business logic when writing the table creation DDL. The DDL is no longer
+just an implicit relationship; creating a table will create the corresponding
+physical storage, and dropping a table will delete the corresponding
+physical storage.
+
+```sql
+-- a managed table ddl
+CREATE TABLE MyTable (
+ `user_id` BIGINT,
+ `item_id` BIGINT,
+ `behavior` STRING
+);
+```
+
+## Unify Streaming and Batch
+
+There are three types of connectors in Flink SQL.
+- Message queue, such as Apache Kafka, it is used in both source and
+ intermediate stages in this pipeline, to guarantee the latency stay
+ within seconds.
+- OLAP system, such as Clickhouse, it receives processed data in
+ streaming fashion and serving user’s ad-hoc queries.
+- Batch storage, such as Apache Hive, it supports various operations
+ of the traditional batch processing, including `INSERT OVERWRITE`.
+
+Flink Table Store provides table abstraction. It is used in a way that
+does not differ from the traditional database:
+- In Flink `batch` execution mode, it acts like a Hive table and
+ supports various operations of Batch SQL. Query it to see the
+ latest snapshot.
+- In Flink `streaming` execution mode, it acts like a message queue.
+ Query it acts like querying a stream changelog from a message queue
+ where historical data never expires.
+
+Different `log.scan` mode will result in different consuming behavior under streaming mode.
+<table class="table table-bordered">
+ <thead>
+ <tr>
+ <th class="text-left" style="width: 20%">Scan Mode</th>
+ <th class="text-center" style="width: 5%">Default</th>
+ <th class="text-center" style="width: 60%">Description</th>
+ </tr>
+ </thead>
+ <tbody>
+ <tr>
+ <td><h5>FULL</h5></td>
+ <td>Yes</td>
+ <td>FULL scan mode performs a hybrid reading with a snapshot scan and the continuous incremental scan.</td>
+ </tr>
+ <tr>
+ <td><h5>LATEST</h5></td>
+ <td>No</td>
+ <td>LATEST scan mode only reads incremental data from the latest offset.</td>
+ </tr>
+ </tbody>
+</table>
+
+## Architecture
+
+Flink Table Store consists of two parts, LogStore and FileStore. The
+LogStore would serve the need of message systems, while FileStore will
+play the role of file systems with columnar formats. At each point in time,
+LogStore and FileStore will store exactly the same data for the latest
+written data (LogStore has TTL), but with different physical layouts.
+Flink Table Store aims to bridge the storage layout gap between the
+batch table and streaming changelog, to provide a unified experience
+as Flink SQL:
+- LogStore: Store the latest data, support second level streaming incremental
+consumption, use Kafka by default.
+- FileStore: Store latest data + historical data, provide batch Ad-Hoc analysis.
+
+{{< img src="/img/architecture.svg" alt="Flink Table Store Architecture" >}}
+
+The manifest file is used to record changes to the SST file, and multiple
+manifest files make up a snapshot.
+
+The data in the FileStore is divided into buckets, each bucket is a
+separate LSM (log structured merge tree).
+
+The file inside LSM is called SST (Sorted Strings Table). By default, files
+are stored in columnar format (Apache ORC) for high performance of analysis
+and compression of storage.
+
diff --git a/docs/static/img/architecture.svg b/docs/static/img/architecture.svg
new file mode 100644
index 0000000..d6351f9
--- /dev/null
+++ b/docs/static/img/architecture.svg
@@ -0,0 +1 @@
+<svg version="1.1" viewBox="0.0 0.0 960.0 540.0" fill="none" stroke="none" stroke-linecap="square" stroke-miterlimit="10" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns="http://www.w3.org/2000/svg"><clipPath id="g120690087d7_0_0.0"><path d="m0 0l960.0 0l0 540.0l-960.0 0l0 -540.0z" clip-rule="nonzero"/></clipPath><g clip-path="url(#g120690087d7_0_0.0)"><path fill="#ffffff" d="m0 0l960.0 0l0 540.0l-960.0 0z" fill-rule="evenodd"/><g filter="url(#shadowFilter-g120690087d7_0_0.1)"><use xlin [...]
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index 3f21f49..4dbcc41 100644
--- a/pom.xml
+++ b/pom.xml
@@ -339,6 +339,7 @@ under the License.
<exclude>docs/themes/book/**</exclude>
<exclude>docs/assets/github.css</exclude>
<exclude>docs/static/js/anchor.min.js</exclude>
+ <exclude>**/*.svg</exclude>
<!-- Bundled license files -->
<exclude>**/LICENSE*</exclude>
<!-- artifacts created during release process -->
[flink-table-store] 09/09: [hotfix] Update document config.toml to release-0.1
Posted by lz...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
lzljs3620320 pushed a commit to branch release-0.1
in repository https://gitbox.apache.org/repos/asf/flink-table-store.git
commit b34cebbcc8337b2a061374644e0d184df13d31e3
Author: JingsongLi <lz...@aliyun.com>
AuthorDate: Fri Apr 1 19:47:37 2022 +0800
[hotfix] Update document config.toml to release-0.1
---
docs/config.toml | 13 ++++++-------
1 file changed, 6 insertions(+), 7 deletions(-)
diff --git a/docs/config.toml b/docs/config.toml
index 274144d..bf5ef0c 100644
--- a/docs/config.toml
+++ b/docs/config.toml
@@ -14,7 +14,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-baseURL = '//nightlies.apache.org/flink/flink-table-store-docs-master'
+baseURL = '//nightlies.apache.org/flink/flink-table-store-docs-release-0.1'
languageCode = 'en-us'
title = 'Apache Flink Table Store'
enableGitInfo = false
@@ -24,7 +24,7 @@ pygmentsUseClasses = true
[params]
# Flag whether this is a stable version or not.
# Used for the quickstart page.
- IsStable = false
+ IsStable = true
# Flag to indicate whether an outdated warning should be shown.
ShowOutDatedWarning = false
@@ -34,14 +34,14 @@ pygmentsUseClasses = true
# we change the version for the complete docs when forking of a release branch
# etc.
# The full version string as referenced in Maven (e.g. 1.2.1)
- Version = "0.1-SNAPSHOT"
+ Version = "0.1"
# For stable releases, leave the bugfix version out (e.g. 1.2). For snapshot
# release this should be the same as the regular version
- VersionTitle = "0.1-SNAPSHOT"
+ VersionTitle = "0.1"
# The branch for this version of Apache Flink Table Store
- Branch = "master"
+ Branch = "release-0.1"
# The github repository for Apache Flink Table Store
Repo = "//github.com/apache/flink-table-store"
@@ -57,11 +57,10 @@ pygmentsUseClasses = true
# of the menu
MenuLinks = [
["Project Homepage", "//flink.apache.org"],
- ["JavaDocs", "//nightlies.apache.org/flink/flink-table-store-docs-master/api/java/"],
+ ["JavaDocs", "//nightlies.apache.org/flink/flink-table-store-docs-release-0.1/api/java/"],
]
PreviousDocs = [
- ["0.1", "https://nightlies.apache.org/flink/flink-table-store-docs-release-0.1"],
]
[markup]
[flink-table-store] 01/09: [FLINK-26877] Introduce auto type inference for filter push down
Posted by lz...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
lzljs3620320 pushed a commit to branch release-0.1
in repository https://gitbox.apache.org/repos/asf/flink-table-store.git
commit 5be4b8ebcf17700fc372fe0a69c4007ee932cf6b
Author: Jane Chan <55...@users.noreply.github.com>
AuthorDate: Mon Mar 28 14:49:12 2022 +0800
[FLINK-26877] Introduce auto type inference for filter push down
This closes #64
---
.../flink/table/store/file/predicate/And.java | 19 +++
.../flink/table/store/file/predicate/Equal.java | 19 +++
.../table/store/file/predicate/GreaterOrEqual.java | 19 +++
.../table/store/file/predicate/GreaterThan.java | 19 +++
.../table/store/file/predicate/IsNotNull.java | 19 +++
.../flink/table/store/file/predicate/IsNull.java | 19 +++
.../table/store/file/predicate/LessOrEqual.java | 19 +++
.../flink/table/store/file/predicate/LessThan.java | 19 +++
.../flink/table/store/file/predicate/Literal.java | 18 +++
.../flink/table/store/file/predicate/NotEqual.java | 19 +++
.../flink/table/store/file/predicate/Or.java | 19 +++
.../store/file/predicate/PredicateConverter.java | 64 +++++----
.../file/predicate/PredicateConverterTest.java | 148 +++++++++++++++++++++
13 files changed, 396 insertions(+), 24 deletions(-)
diff --git a/flink-table-store-core/src/main/java/org/apache/flink/table/store/file/predicate/And.java b/flink-table-store-core/src/main/java/org/apache/flink/table/store/file/predicate/And.java
index 5c2817a..8744df9 100644
--- a/flink-table-store-core/src/main/java/org/apache/flink/table/store/file/predicate/And.java
+++ b/flink-table-store-core/src/main/java/org/apache/flink/table/store/file/predicate/And.java
@@ -20,6 +20,8 @@ package org.apache.flink.table.store.file.predicate;
import org.apache.flink.table.store.file.stats.FieldStats;
+import java.util.Objects;
+
/** A {@link Predicate} to eval and. */
public class And implements Predicate {
@@ -42,4 +44,21 @@ public class And implements Predicate {
public boolean test(long rowCount, FieldStats[] fieldStats) {
return predicate1.test(rowCount, fieldStats) && predicate2.test(rowCount, fieldStats);
}
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (!(o instanceof And)) {
+ return false;
+ }
+ And and = (And) o;
+ return predicate1.equals(and.predicate1) && predicate2.equals(and.predicate2);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(predicate1, predicate2);
+ }
}
diff --git a/flink-table-store-core/src/main/java/org/apache/flink/table/store/file/predicate/Equal.java b/flink-table-store-core/src/main/java/org/apache/flink/table/store/file/predicate/Equal.java
index 56fc91d..489fab0 100644
--- a/flink-table-store-core/src/main/java/org/apache/flink/table/store/file/predicate/Equal.java
+++ b/flink-table-store-core/src/main/java/org/apache/flink/table/store/file/predicate/Equal.java
@@ -20,6 +20,8 @@ package org.apache.flink.table.store.file.predicate;
import org.apache.flink.table.store.file.stats.FieldStats;
+import java.util.Objects;
+
import static org.apache.flink.util.Preconditions.checkNotNull;
/** A {@link Predicate} to eval equal. */
@@ -51,4 +53,21 @@ public class Equal implements Predicate {
return literal.compareValueTo(stats.minValue()) >= 0
&& literal.compareValueTo(stats.maxValue()) <= 0;
}
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (!(o instanceof Equal)) {
+ return false;
+ }
+ Equal equal = (Equal) o;
+ return index == equal.index && literal.equals(equal.literal);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(index, literal);
+ }
}
diff --git a/flink-table-store-core/src/main/java/org/apache/flink/table/store/file/predicate/GreaterOrEqual.java b/flink-table-store-core/src/main/java/org/apache/flink/table/store/file/predicate/GreaterOrEqual.java
index 79a0cdc..4812476 100644
--- a/flink-table-store-core/src/main/java/org/apache/flink/table/store/file/predicate/GreaterOrEqual.java
+++ b/flink-table-store-core/src/main/java/org/apache/flink/table/store/file/predicate/GreaterOrEqual.java
@@ -20,6 +20,8 @@ package org.apache.flink.table.store.file.predicate;
import org.apache.flink.table.store.file.stats.FieldStats;
+import java.util.Objects;
+
import static org.apache.flink.util.Preconditions.checkNotNull;
/** A {@link Predicate} to eval greater or equal. */
@@ -50,4 +52,21 @@ public class GreaterOrEqual implements Predicate {
}
return literal.compareValueTo(stats.maxValue()) <= 0;
}
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (!(o instanceof GreaterOrEqual)) {
+ return false;
+ }
+ GreaterOrEqual that = (GreaterOrEqual) o;
+ return index == that.index && literal.equals(that.literal);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(index, literal);
+ }
}
diff --git a/flink-table-store-core/src/main/java/org/apache/flink/table/store/file/predicate/GreaterThan.java b/flink-table-store-core/src/main/java/org/apache/flink/table/store/file/predicate/GreaterThan.java
index 81ddc26..535cbc5 100644
--- a/flink-table-store-core/src/main/java/org/apache/flink/table/store/file/predicate/GreaterThan.java
+++ b/flink-table-store-core/src/main/java/org/apache/flink/table/store/file/predicate/GreaterThan.java
@@ -20,6 +20,8 @@ package org.apache.flink.table.store.file.predicate;
import org.apache.flink.table.store.file.stats.FieldStats;
+import java.util.Objects;
+
import static org.apache.flink.util.Preconditions.checkNotNull;
/** A {@link Predicate} to eval greater. */
@@ -50,4 +52,21 @@ public class GreaterThan implements Predicate {
}
return literal.compareValueTo(stats.maxValue()) < 0;
}
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (!(o instanceof GreaterThan)) {
+ return false;
+ }
+ GreaterThan that = (GreaterThan) o;
+ return index == that.index && literal.equals(that.literal);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(index, literal);
+ }
}
diff --git a/flink-table-store-core/src/main/java/org/apache/flink/table/store/file/predicate/IsNotNull.java b/flink-table-store-core/src/main/java/org/apache/flink/table/store/file/predicate/IsNotNull.java
index 9de7d5b..3d53724 100644
--- a/flink-table-store-core/src/main/java/org/apache/flink/table/store/file/predicate/IsNotNull.java
+++ b/flink-table-store-core/src/main/java/org/apache/flink/table/store/file/predicate/IsNotNull.java
@@ -20,6 +20,8 @@ package org.apache.flink.table.store.file.predicate;
import org.apache.flink.table.store.file.stats.FieldStats;
+import java.util.Objects;
+
/** A {@link Predicate} to eval is not null. */
public class IsNotNull implements Predicate {
@@ -40,4 +42,21 @@ public class IsNotNull implements Predicate {
public boolean test(long rowCount, FieldStats[] fieldStats) {
return fieldStats[index].nullCount() < rowCount;
}
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (!(o instanceof IsNotNull)) {
+ return false;
+ }
+ IsNotNull isNotNull = (IsNotNull) o;
+ return index == isNotNull.index;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(index);
+ }
}
diff --git a/flink-table-store-core/src/main/java/org/apache/flink/table/store/file/predicate/IsNull.java b/flink-table-store-core/src/main/java/org/apache/flink/table/store/file/predicate/IsNull.java
index 5e9461a..b863682 100644
--- a/flink-table-store-core/src/main/java/org/apache/flink/table/store/file/predicate/IsNull.java
+++ b/flink-table-store-core/src/main/java/org/apache/flink/table/store/file/predicate/IsNull.java
@@ -20,6 +20,8 @@ package org.apache.flink.table.store.file.predicate;
import org.apache.flink.table.store.file.stats.FieldStats;
+import java.util.Objects;
+
/** A {@link Predicate} to eval is null. */
public class IsNull implements Predicate {
@@ -40,4 +42,21 @@ public class IsNull implements Predicate {
public boolean test(long rowCount, FieldStats[] fieldStats) {
return fieldStats[index].nullCount() > 0;
}
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (!(o instanceof IsNull)) {
+ return false;
+ }
+ IsNull isNull = (IsNull) o;
+ return index == isNull.index;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(index);
+ }
}
diff --git a/flink-table-store-core/src/main/java/org/apache/flink/table/store/file/predicate/LessOrEqual.java b/flink-table-store-core/src/main/java/org/apache/flink/table/store/file/predicate/LessOrEqual.java
index 9a94190..98e24d5 100644
--- a/flink-table-store-core/src/main/java/org/apache/flink/table/store/file/predicate/LessOrEqual.java
+++ b/flink-table-store-core/src/main/java/org/apache/flink/table/store/file/predicate/LessOrEqual.java
@@ -20,6 +20,8 @@ package org.apache.flink.table.store.file.predicate;
import org.apache.flink.table.store.file.stats.FieldStats;
+import java.util.Objects;
+
import static org.apache.flink.util.Preconditions.checkNotNull;
/** A {@link Predicate} to eval less or equal. */
@@ -50,4 +52,21 @@ public class LessOrEqual implements Predicate {
}
return literal.compareValueTo(stats.minValue()) >= 0;
}
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (!(o instanceof LessOrEqual)) {
+ return false;
+ }
+ LessOrEqual that = (LessOrEqual) o;
+ return index == that.index && literal.equals(that.literal);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(index, literal);
+ }
}
diff --git a/flink-table-store-core/src/main/java/org/apache/flink/table/store/file/predicate/LessThan.java b/flink-table-store-core/src/main/java/org/apache/flink/table/store/file/predicate/LessThan.java
index f8fda69..b950dd7 100644
--- a/flink-table-store-core/src/main/java/org/apache/flink/table/store/file/predicate/LessThan.java
+++ b/flink-table-store-core/src/main/java/org/apache/flink/table/store/file/predicate/LessThan.java
@@ -20,6 +20,8 @@ package org.apache.flink.table.store.file.predicate;
import org.apache.flink.table.store.file.stats.FieldStats;
+import java.util.Objects;
+
import static org.apache.flink.util.Preconditions.checkNotNull;
/** A {@link Predicate} to eval less. */
@@ -50,4 +52,21 @@ public class LessThan implements Predicate {
}
return literal.compareValueTo(stats.minValue()) > 0;
}
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (!(o instanceof LessThan)) {
+ return false;
+ }
+ LessThan lessThan = (LessThan) o;
+ return index == lessThan.index && literal.equals(lessThan.literal);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(index, literal);
+ }
}
diff --git a/flink-table-store-core/src/main/java/org/apache/flink/table/store/file/predicate/Literal.java b/flink-table-store-core/src/main/java/org/apache/flink/table/store/file/predicate/Literal.java
index eed1b82..686107e 100644
--- a/flink-table-store-core/src/main/java/org/apache/flink/table/store/file/predicate/Literal.java
+++ b/flink-table-store-core/src/main/java/org/apache/flink/table/store/file/predicate/Literal.java
@@ -28,6 +28,7 @@ import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
+import java.util.Objects;
/** A serializable literal class. */
public class Literal implements Serializable {
@@ -73,4 +74,21 @@ public class Literal implements Serializable {
in.defaultReadObject();
value = InternalSerializers.create(type).deserialize(new DataInputViewStreamWrapper(in));
}
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (!(o instanceof Literal)) {
+ return false;
+ }
+ Literal literal = (Literal) o;
+ return type.equals(literal.type) && value.equals(literal.value);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(type, value);
+ }
}
diff --git a/flink-table-store-core/src/main/java/org/apache/flink/table/store/file/predicate/NotEqual.java b/flink-table-store-core/src/main/java/org/apache/flink/table/store/file/predicate/NotEqual.java
index 2c2136a..4d6a924 100644
--- a/flink-table-store-core/src/main/java/org/apache/flink/table/store/file/predicate/NotEqual.java
+++ b/flink-table-store-core/src/main/java/org/apache/flink/table/store/file/predicate/NotEqual.java
@@ -20,6 +20,8 @@ package org.apache.flink.table.store.file.predicate;
import org.apache.flink.table.store.file.stats.FieldStats;
+import java.util.Objects;
+
import static org.apache.flink.util.Preconditions.checkNotNull;
/** A {@link Predicate} to eval not equal. */
@@ -48,4 +50,21 @@ public class NotEqual implements Predicate {
return literal.compareValueTo(stats.minValue()) != 0
|| literal.compareValueTo(stats.maxValue()) != 0;
}
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (!(o instanceof NotEqual)) {
+ return false;
+ }
+ NotEqual notEqual = (NotEqual) o;
+ return index == notEqual.index && literal.equals(notEqual.literal);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(index, literal);
+ }
}
diff --git a/flink-table-store-core/src/main/java/org/apache/flink/table/store/file/predicate/Or.java b/flink-table-store-core/src/main/java/org/apache/flink/table/store/file/predicate/Or.java
index 02a79b1..5a5f3d2 100644
--- a/flink-table-store-core/src/main/java/org/apache/flink/table/store/file/predicate/Or.java
+++ b/flink-table-store-core/src/main/java/org/apache/flink/table/store/file/predicate/Or.java
@@ -20,6 +20,8 @@ package org.apache.flink.table.store.file.predicate;
import org.apache.flink.table.store.file.stats.FieldStats;
+import java.util.Objects;
+
/** A {@link Predicate} to eval or. */
public class Or implements Predicate {
@@ -42,4 +44,21 @@ public class Or implements Predicate {
public boolean test(long rowCount, FieldStats[] fieldStats) {
return predicate1.test(rowCount, fieldStats) || predicate2.test(rowCount, fieldStats);
}
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (!(o instanceof Or)) {
+ return false;
+ }
+ Or or = (Or) o;
+ return predicate1.equals(or.predicate1) && predicate2.equals(or.predicate2);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(predicate1, predicate2);
+ }
}
diff --git a/flink-table-store-core/src/main/java/org/apache/flink/table/store/file/predicate/PredicateConverter.java b/flink-table-store-core/src/main/java/org/apache/flink/table/store/file/predicate/PredicateConverter.java
index e625552..f845dec 100644
--- a/flink-table-store-core/src/main/java/org/apache/flink/table/store/file/predicate/PredicateConverter.java
+++ b/flink-table-store-core/src/main/java/org/apache/flink/table/store/file/predicate/PredicateConverter.java
@@ -40,6 +40,7 @@ import java.util.Optional;
import java.util.function.BiFunction;
import static org.apache.flink.table.data.conversion.DataStructureConverters.getConverter;
+import static org.apache.flink.table.types.logical.utils.LogicalTypeCasts.supportsImplicitCast;
/** Convert {@link Expression} to {@link Predicate}. */
public class PredicateConverter implements ExpressionVisitor<Predicate> {
@@ -86,10 +87,12 @@ public class PredicateConverter implements ExpressionVisitor<Predicate> {
return visitBiFunction(children, LessOrEqual::new, GreaterOrEqual::new);
} else if (func == BuiltInFunctionDefinitions.IS_NULL) {
return extractFieldReference(children.get(0))
+ .map(FieldReferenceExpression::getFieldIndex)
.map(IsNull::new)
.orElseThrow(UnsupportedExpression::new);
} else if (func == BuiltInFunctionDefinitions.IS_NOT_NULL) {
return extractFieldReference(children.get(0))
+ .map(FieldReferenceExpression::getFieldIndex)
.map(IsNotNull::new)
.orElseThrow(UnsupportedExpression::new);
}
@@ -103,19 +106,19 @@ public class PredicateConverter implements ExpressionVisitor<Predicate> {
List<Expression> children,
BiFunction<Integer, Literal, Predicate> visit1,
BiFunction<Integer, Literal, Predicate> visit2) {
- Optional<Integer> field = extractFieldReference(children.get(0));
+ Optional<FieldReferenceExpression> fieldRefExpr = extractFieldReference(children.get(0));
Optional<Literal> literal;
- if (field.isPresent()) {
- literal = extractLiteral(children.get(1));
+ if (fieldRefExpr.isPresent()) {
+ literal = extractLiteral(fieldRefExpr.get().getOutputDataType(), children.get(1));
if (literal.isPresent()) {
- return visit1.apply(field.get(), literal.get());
+ return visit1.apply(fieldRefExpr.get().getFieldIndex(), literal.get());
}
} else {
- field = extractFieldReference(children.get(1));
- if (field.isPresent()) {
- literal = extractLiteral(children.get(0));
+ fieldRefExpr = extractFieldReference(children.get(1));
+ if (fieldRefExpr.isPresent()) {
+ literal = extractLiteral(fieldRefExpr.get().getOutputDataType(), children.get(0));
if (literal.isPresent()) {
- return visit2.apply(field.get(), literal.get());
+ return visit2.apply(fieldRefExpr.get().getFieldIndex(), literal.get());
}
}
}
@@ -123,30 +126,43 @@ public class PredicateConverter implements ExpressionVisitor<Predicate> {
throw new UnsupportedExpression();
}
- private Optional<Integer> extractFieldReference(Expression expression) {
+ private Optional<FieldReferenceExpression> extractFieldReference(Expression expression) {
if (expression instanceof FieldReferenceExpression) {
- int reference = ((FieldReferenceExpression) expression).getFieldIndex();
- return Optional.of(reference);
+ return Optional.of((FieldReferenceExpression) expression);
}
return Optional.empty();
}
- private Optional<Literal> extractLiteral(Expression expression) {
+ private Optional<Literal> extractLiteral(DataType expectedType, Expression expression) {
+ LogicalType expectedLogicalType = expectedType.getLogicalType();
+ if (!supportsPredicate(expectedLogicalType)) {
+ return Optional.empty();
+ }
+ Literal literal = null;
if (expression instanceof ValueLiteralExpression) {
ValueLiteralExpression valueExpression = (ValueLiteralExpression) expression;
- DataType type = valueExpression.getOutputDataType();
- return supportsPredicate(type.getLogicalType())
- ? Optional.of(
- new Literal(
- type.getLogicalType(),
- getConverter(type)
- .toInternalOrNull(
- valueExpression
- .getValueAs(type.getConversionClass())
- .get())))
- : Optional.empty();
+ DataType actualType = valueExpression.getOutputDataType();
+ LogicalType actualLogicalType = actualType.getLogicalType();
+ Optional<?> valueOpt = valueExpression.getValueAs(actualType.getConversionClass());
+ if (!valueOpt.isPresent()) {
+ return Optional.empty();
+ }
+ Object value = valueOpt.get();
+ if (actualLogicalType.getTypeRoot().equals(expectedLogicalType.getTypeRoot())) {
+ literal =
+ new Literal(
+ expectedLogicalType,
+ getConverter(expectedType).toInternalOrNull(value));
+ } else if (supportsImplicitCast(actualLogicalType, expectedLogicalType)) {
+ try {
+ value = TypeUtils.castFromString(value.toString(), expectedLogicalType);
+ literal = new Literal(expectedLogicalType, value);
+ } catch (Exception ignored) {
+ // ignore here, let #visit throw UnsupportedExpression
+ }
+ }
}
- return Optional.empty();
+ return literal == null ? Optional.empty() : Optional.of(literal);
}
private boolean supportsPredicate(LogicalType type) {
diff --git a/flink-table-store-core/src/test/java/org/apache/flink/table/store/file/predicate/PredicateConverterTest.java b/flink-table-store-core/src/test/java/org/apache/flink/table/store/file/predicate/PredicateConverterTest.java
new file mode 100644
index 0000000..8cd5717
--- /dev/null
+++ b/flink-table-store-core/src/test/java/org/apache/flink/table/store/file/predicate/PredicateConverterTest.java
@@ -0,0 +1,148 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.table.store.file.predicate;
+
+import org.apache.flink.table.api.DataTypes;
+import org.apache.flink.table.expressions.CallExpression;
+import org.apache.flink.table.expressions.FieldReferenceExpression;
+import org.apache.flink.table.expressions.ResolvedExpression;
+import org.apache.flink.table.expressions.ValueLiteralExpression;
+import org.apache.flink.table.functions.BuiltInFunctionDefinitions;
+
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.Arguments;
+import org.junit.jupiter.params.provider.MethodSource;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.stream.Stream;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+/** Test for {@link PredicateConverter}. */
+public class PredicateConverterTest {
+
+ private static final PredicateConverter CONVERTER = new PredicateConverter();
+
+ @MethodSource("provideResolvedExpression")
+ @ParameterizedTest
+ public void testVisitAndAutoTypeInference(ResolvedExpression expression, Predicate expected) {
+ if (expression instanceof CallExpression) {
+ assertThat(CONVERTER.visit((CallExpression) expression)).isEqualTo(expected);
+ } else {
+ assertThatThrownBy(() -> CONVERTER.visit(expression))
+ .isInstanceOf(RuntimeException.class)
+ .hasMessageContaining("Unsupported expression");
+ }
+ }
+
+ public static Stream<Arguments> provideResolvedExpression() {
+ FieldReferenceExpression longRefExpr =
+ new FieldReferenceExpression("long1", DataTypes.BIGINT(), 0, 0);
+ ValueLiteralExpression intLitExpr = new ValueLiteralExpression(10);
+ Literal longLit = new Literal(DataTypes.BIGINT().getLogicalType(), 10L);
+
+ FieldReferenceExpression doubleRefExpr =
+ new FieldReferenceExpression("double1", DataTypes.DOUBLE(), 0, 1);
+ ValueLiteralExpression floatLitExpr = new ValueLiteralExpression(3.14f);
+ Literal doubleLit = new Literal(DataTypes.DOUBLE().getLogicalType(), 3.14d);
+
+ return Stream.of(
+ Arguments.of(longRefExpr, null),
+ Arguments.of(intLitExpr, null),
+ Arguments.of(
+ CallExpression.permanent(
+ BuiltInFunctionDefinitions.IS_NULL,
+ Collections.singletonList(longRefExpr),
+ DataTypes.BOOLEAN()),
+ new IsNull(0)),
+ Arguments.of(
+ CallExpression.permanent(
+ BuiltInFunctionDefinitions.IS_NOT_NULL,
+ Collections.singletonList(doubleRefExpr),
+ DataTypes.BOOLEAN()),
+ new IsNotNull(1)),
+ Arguments.of(
+ CallExpression.permanent(
+ BuiltInFunctionDefinitions.EQUALS,
+ // test literal on left
+ Arrays.asList(intLitExpr, longRefExpr),
+ DataTypes.BOOLEAN()),
+ new Equal(0, longLit)),
+ Arguments.of(
+ CallExpression.permanent(
+ BuiltInFunctionDefinitions.NOT_EQUALS,
+ Arrays.asList(longRefExpr, intLitExpr),
+ DataTypes.BOOLEAN()),
+ new NotEqual(0, longLit)),
+ Arguments.of(
+ CallExpression.permanent(
+ BuiltInFunctionDefinitions.GREATER_THAN,
+ Arrays.asList(longRefExpr, intLitExpr),
+ DataTypes.BOOLEAN()),
+ new GreaterThan(0, longLit)),
+ Arguments.of(
+ CallExpression.permanent(
+ BuiltInFunctionDefinitions.GREATER_THAN_OR_EQUAL,
+ Arrays.asList(longRefExpr, intLitExpr),
+ DataTypes.BOOLEAN()),
+ new GreaterOrEqual(0, longLit)),
+ Arguments.of(
+ CallExpression.permanent(
+ BuiltInFunctionDefinitions.LESS_THAN,
+ Arrays.asList(longRefExpr, intLitExpr),
+ DataTypes.BOOLEAN()),
+ new LessThan(0, longLit)),
+ Arguments.of(
+ CallExpression.permanent(
+ BuiltInFunctionDefinitions.LESS_THAN_OR_EQUAL,
+ Arrays.asList(longRefExpr, intLitExpr),
+ DataTypes.BOOLEAN()),
+ new LessOrEqual(0, longLit)),
+ Arguments.of(
+ CallExpression.permanent(
+ BuiltInFunctionDefinitions.AND,
+ Arrays.asList(
+ CallExpression.permanent(
+ BuiltInFunctionDefinitions.LESS_THAN_OR_EQUAL,
+ Arrays.asList(longRefExpr, intLitExpr),
+ DataTypes.BOOLEAN()),
+ CallExpression.permanent(
+ BuiltInFunctionDefinitions.EQUALS,
+ Arrays.asList(doubleRefExpr, floatLitExpr),
+ DataTypes.BOOLEAN())),
+ DataTypes.BOOLEAN()),
+ new And(new LessOrEqual(0, longLit), new Equal(1, doubleLit))),
+ Arguments.of(
+ CallExpression.permanent(
+ BuiltInFunctionDefinitions.OR,
+ Arrays.asList(
+ CallExpression.permanent(
+ BuiltInFunctionDefinitions.NOT_EQUALS,
+ Arrays.asList(longRefExpr, intLitExpr),
+ DataTypes.BOOLEAN()),
+ CallExpression.permanent(
+ BuiltInFunctionDefinitions.EQUALS,
+ Arrays.asList(doubleRefExpr, floatLitExpr),
+ DataTypes.BOOLEAN())),
+ DataTypes.BOOLEAN()),
+ new Or(new NotEqual(0, longLit), new Equal(1, doubleLit))));
+ }
+}
[flink-table-store] 06/09: [FLINK-26971] UniversalCompaction should pick by size ratio after picking by file num
Posted by lz...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
lzljs3620320 pushed a commit to branch release-0.1
in repository https://gitbox.apache.org/repos/asf/flink-table-store.git
commit 686a17dd7a12606289000159b5a894b952e3247b
Author: Jingsong Lee <ji...@gmail.com>
AuthorDate: Fri Apr 1 18:27:23 2022 +0800
[FLINK-26971] UniversalCompaction should pick by size ratio after picking by file num
This closes #70
---
.../file/mergetree/compact/UniversalCompaction.java | 20 ++++++++++++++++----
.../mergetree/compact/UniversalCompactionTest.java | 3 ++-
2 files changed, 18 insertions(+), 5 deletions(-)
diff --git a/flink-table-store-core/src/main/java/org/apache/flink/table/store/file/mergetree/compact/UniversalCompaction.java b/flink-table-store-core/src/main/java/org/apache/flink/table/store/file/mergetree/compact/UniversalCompaction.java
index a590085..d37c899 100644
--- a/flink-table-store-core/src/main/java/org/apache/flink/table/store/file/mergetree/compact/UniversalCompaction.java
+++ b/flink-table-store-core/src/main/java/org/apache/flink/table/store/file/mergetree/compact/UniversalCompaction.java
@@ -63,7 +63,8 @@ public class UniversalCompaction implements CompactStrategy {
// 3 checking for file num
if (runs.size() > maxRunNum) {
// compacting for file num
- return Optional.of(createUnit(runs, maxLevel, runs.size() - maxRunNum + 1));
+ int candidateCount = runs.size() - maxRunNum + 1;
+ return Optional.ofNullable(pickForSizeRatio(maxLevel, runs, candidateCount));
}
return Optional.empty();
@@ -97,10 +98,13 @@ public class UniversalCompaction implements CompactStrategy {
return null;
}
- int candidateCount = 1;
- long candidateSize = runs.get(0).run().totalSize();
+ return pickForSizeRatio(maxLevel, runs, 1);
+ }
- for (int i = 1; i < runs.size(); i++) {
+ private CompactUnit pickForSizeRatio(
+ int maxLevel, List<LevelSortedRun> runs, int candidateCount) {
+ long candidateSize = candidateSize(runs, candidateCount);
+ for (int i = candidateCount; i < runs.size(); i++) {
LevelSortedRun next = runs.get(i);
if (candidateSize * (100.0 + sizeRatio) / 100.0 < next.run().totalSize()) {
break;
@@ -117,6 +121,14 @@ public class UniversalCompaction implements CompactStrategy {
return null;
}
+ private long candidateSize(List<LevelSortedRun> runs, int candidateCount) {
+ long size = 0;
+ for (int i = 0; i < candidateCount; i++) {
+ size += runs.get(i).run().totalSize();
+ }
+ return size;
+ }
+
@VisibleForTesting
static CompactUnit createUnit(List<LevelSortedRun> runs, int maxLevel, int runCount) {
int outputLevel;
diff --git a/flink-table-store-core/src/test/java/org/apache/flink/table/store/file/mergetree/compact/UniversalCompactionTest.java b/flink-table-store-core/src/test/java/org/apache/flink/table/store/file/mergetree/compact/UniversalCompactionTest.java
index c7678d7..14af8ad 100644
--- a/flink-table-store-core/src/test/java/org/apache/flink/table/store/file/mergetree/compact/UniversalCompactionTest.java
+++ b/flink-table-store-core/src/test/java/org/apache/flink/table/store/file/mergetree/compact/UniversalCompactionTest.java
@@ -64,7 +64,8 @@ public class UniversalCompactionTest {
pick = compaction.pick(3, level0(1, 2, 3, 50));
assertThat(pick.isPresent()).isTrue();
results = pick.get().files().stream().mapToLong(SstFileMeta::fileSize).toArray();
- assertThat(results).isEqualTo(new long[] {1, 2});
+ // 3 should be in the candidate, by size ratio after picking by file num
+ assertThat(results).isEqualTo(new long[] {1, 2, 3});
}
@Test
[flink-table-store] 07/09: [FLINK-26857] Add ITCase for projection and filter predicate
Posted by lz...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
lzljs3620320 pushed a commit to branch release-0.1
in repository https://gitbox.apache.org/repos/asf/flink-table-store.git
commit b58bd4cc5a94297765e4c150046801233c587fcf
Author: Jane Chan <55...@users.noreply.github.com>
AuthorDate: Fri Apr 1 18:34:20 2022 +0800
[FLINK-26857] Add ITCase for projection and filter predicate
This closes #69
---
.../store/connector/source/TableStoreSource.java | 4 +-
.../store/connector/ReadWriteTableITCase.java | 835 ++++++++++++++++++++-
.../store/kafka/KafkaLogDeserializationSchema.java | 12 +-
.../table/store/kafka/KafkaLogStoreFactory.java | 6 +-
4 files changed, 813 insertions(+), 44 deletions(-)
diff --git a/flink-table-store-connector/src/main/java/org/apache/flink/table/store/connector/source/TableStoreSource.java b/flink-table-store-connector/src/main/java/org/apache/flink/table/store/connector/source/TableStoreSource.java
index 8de30f6..e1681fe 100644
--- a/flink-table-store-connector/src/main/java/org/apache/flink/table/store/connector/source/TableStoreSource.java
+++ b/flink-table-store-connector/src/main/java/org/apache/flink/table/store/connector/source/TableStoreSource.java
@@ -44,7 +44,6 @@ import org.apache.flink.table.types.logical.LogicalType;
import javax.annotation.Nullable;
import java.util.ArrayList;
-import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
@@ -165,8 +164,7 @@ public class TableStoreSource
fieldFilters = filters;
}
return Result.of(
- new ArrayList<>(filters),
- fieldFilters == null ? Collections.emptyList() : fieldFilters);
+ filters, streaming && logStoreTableFactory != null ? filters : fieldFilters);
}
@Override
diff --git a/flink-table-store-connector/src/test/java/org/apache/flink/table/store/connector/ReadWriteTableITCase.java b/flink-table-store-connector/src/test/java/org/apache/flink/table/store/connector/ReadWriteTableITCase.java
index 3458529..6ea0367 100644
--- a/flink-table-store-connector/src/test/java/org/apache/flink/table/store/connector/ReadWriteTableITCase.java
+++ b/flink-table-store-connector/src/test/java/org/apache/flink/table/store/connector/ReadWriteTableITCase.java
@@ -35,6 +35,8 @@ import org.apache.flink.types.Row;
import org.junit.Test;
+import javax.annotation.Nullable;
+
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
@@ -64,13 +66,15 @@ public class ReadWriteTableITCase extends KafkaTableTestBase {
List<Row> expectedRecords =
Arrays.asList(
// part = 2022-01-01
- changelogRow("+I", "US Dollar", 102L, "2022-01-01"),
+ changelogRow("+I", "US Dollar", 114L, "2022-01-01"),
changelogRow("+I", "Yen", 1L, "2022-01-01"),
changelogRow("+I", "Euro", 114L, "2022-01-01"),
// part = 2022-01-02
changelogRow("+I", "Euro", 119L, "2022-01-02"));
// test batch read
- String managedTable = collectAndCheckBatchReadWrite(true, true, expectedRecords);
+ String managedTable =
+ collectAndCheckBatchReadWrite(
+ true, true, null, Collections.emptyList(), expectedRecords);
checkFileStorePath(tEnv, managedTable);
// test streaming read
@@ -97,13 +101,80 @@ public class ReadWriteTableITCase extends KafkaTableTestBase {
Collections.emptyMap(),
Arrays.asList(
// part = 2022-01-01
- changelogRow("+I", "US Dollar", 102L, "2022-01-01"),
+ changelogRow("+I", "US Dollar", 114L, "2022-01-01"),
changelogRow("+I", "Yen", 1L, "2022-01-01"),
changelogRow("+I", "Euro", 114L, "2022-01-01"),
// part = 2022-01-02
changelogRow("+I", "Euro", 100L, "2022-01-02"),
changelogRow("+I", "Yen", 1L, "2022-01-02")))
.close();
+
+ // test partition filter
+ List<Row> expected =
+ Arrays.asList(
+ changelogRow("+I", "Yen", 1L, "2022-01-01"),
+ changelogRow("+I", "Euro", 114L, "2022-01-01"),
+ changelogRow("+I", "US Dollar", 114L, "2022-01-01"));
+ collectAndCheckBatchReadWrite(
+ true, true, "dt <> '2022-01-02'", Collections.emptyList(), expected);
+
+ collectAndCheckBatchReadWrite(
+ true, true, "dt = '2022-01-01'", Collections.emptyList(), expected);
+
+ // test field filter
+ collectAndCheckBatchReadWrite(
+ true,
+ true,
+ "rate >= 100",
+ Collections.emptyList(),
+ Arrays.asList(
+ // part = 2022-01-01
+ changelogRow("+I", "US Dollar", 114L, "2022-01-01"),
+ changelogRow("+I", "Euro", 114L, "2022-01-01"),
+ // part = 2022-01-02
+ changelogRow("+I", "Euro", 119L, "2022-01-02")));
+
+ // test partition and field filter
+ collectAndCheckBatchReadWrite(
+ true,
+ true,
+ "rate >= 100 AND dt = '2022-01-02'",
+ Collections.emptyList(),
+ Collections.singletonList(changelogRow("+I", "Euro", 119L, "2022-01-02")));
+
+ // test projection
+ collectAndCheckBatchReadWrite(
+ true,
+ true,
+ null,
+ Collections.singletonList("dt"),
+ Arrays.asList(
+ changelogRow("+I", "2022-01-01"), // US Dollar
+ changelogRow("+I", "2022-01-01"), // Yen
+ changelogRow("+I", "2022-01-01"), // Euro
+ changelogRow("+I", "2022-01-02"))); // Euro
+
+ collectAndCheckBatchReadWrite(
+ true,
+ true,
+ null,
+ Collections.singletonList("dt, currency, rate"),
+ Arrays.asList(
+ changelogRow("+I", "2022-01-01", "US Dollar", 114L), // US Dollar
+ changelogRow("+I", "2022-01-01", "Yen", 1L), // Yen
+ changelogRow("+I", "2022-01-01", "Euro", 114L), // Euro
+ changelogRow("+I", "2022-01-02", "Euro", 119L))); // Euro
+
+ // test projection and filter
+ collectAndCheckBatchReadWrite(
+ true,
+ true,
+ "rate = 114",
+ Collections.singletonList("rate"),
+ Arrays.asList(
+ changelogRow("+I", 114L), // US Dollar
+ changelogRow("+I", 114L) // Euro
+ ));
}
@Test
@@ -111,7 +182,9 @@ public class ReadWriteTableITCase extends KafkaTableTestBase {
// input is dailyRates()
// test batch read
- String managedTable = collectAndCheckBatchReadWrite(true, false, dailyRates());
+ String managedTable =
+ collectAndCheckBatchReadWrite(
+ true, false, null, Collections.emptyList(), dailyRates());
checkFileStorePath(tEnv, managedTable);
// overwrite dynamic partition
@@ -136,6 +209,52 @@ public class ReadWriteTableITCase extends KafkaTableTestBase {
// part = 2022-01-02
changelogRow("+I", "Yen", 2L, "2022-01-02")))
.close();
+
+ // test partition filter
+ collectAndCheckBatchReadWrite(
+ true, false, "dt >= '2022-01-01'", Collections.emptyList(), dailyRates());
+
+ // test field filter
+ collectAndCheckBatchReadWrite(
+ true,
+ false,
+ "currency = 'US Dollar'",
+ Collections.emptyList(),
+ Arrays.asList(
+ // part = 2022-01-01
+ changelogRow("+I", "US Dollar", 102L, "2022-01-01"),
+ // part = 2022-01-01
+ changelogRow("+I", "US Dollar", 114L, "2022-01-01")));
+
+ // test partition and field filter
+ collectAndCheckBatchReadWrite(
+ true,
+ false,
+ "dt = '2022-01-01' OR rate > 115",
+ Collections.emptyList(),
+ dailyRates());
+
+ // test projection
+ collectAndCheckBatchReadWrite(
+ true,
+ false,
+ null,
+ Collections.singletonList("currency"),
+ Arrays.asList(
+ changelogRow("+I", "US Dollar"),
+ changelogRow("+I", "US Dollar"),
+ changelogRow("+I", "Yen"),
+ changelogRow("+I", "Euro"),
+ changelogRow("+I", "Euro"),
+ changelogRow("+I", "Euro")));
+
+ // test projection and filter
+ collectAndCheckBatchReadWrite(
+ true,
+ false,
+ "rate = 119",
+ Arrays.asList("currency", "dt"),
+ Collections.singletonList(changelogRow("+I", "Euro", "2022-01-02")));
}
@Test
@@ -145,6 +264,8 @@ public class ReadWriteTableITCase extends KafkaTableTestBase {
collectAndCheckBatchReadWrite(
false,
true,
+ null,
+ Collections.emptyList(),
Arrays.asList(
changelogRow("+I", "US Dollar", 102L),
changelogRow("+I", "Yen", 1L),
@@ -161,13 +282,87 @@ public class ReadWriteTableITCase extends KafkaTableTestBase {
managedTable,
Collections.emptyMap(),
Collections.singletonList(changelogRow("+I", "Euro", 100L)));
+
+ // test field filter
+ collectAndCheckBatchReadWrite(
+ false,
+ true,
+ "currency = 'Euro'",
+ Collections.emptyList(),
+ Collections.singletonList(changelogRow("+I", "Euro", 119L)));
+
+ collectAndCheckBatchReadWrite(
+ false,
+ true,
+ "119 >= rate AND 102 < rate",
+ Collections.emptyList(),
+ Collections.singletonList(changelogRow("+I", "Euro", 119L)));
+
+ // test projection
+ collectAndCheckBatchReadWrite(
+ false,
+ true,
+ null,
+ Arrays.asList("rate", "currency"),
+ Arrays.asList(
+ changelogRow("+I", 102L, "US Dollar"),
+ changelogRow("+I", 1L, "Yen"),
+ changelogRow("+I", 119L, "Euro")));
+
+ // test projection and filter
+ collectAndCheckBatchReadWrite(
+ false,
+ true,
+ "currency = 'Yen'",
+ Collections.singletonList("rate"),
+ Collections.singletonList(changelogRow("+I", 1L)));
}
@Test
public void testBatchWriteNonPartitionedRecordsWithoutPk() throws Exception {
// input is rates()
- String managedTable = collectAndCheckBatchReadWrite(false, false, rates());
+ String managedTable =
+ collectAndCheckBatchReadWrite(false, false, null, Collections.emptyList(), rates());
checkFileStorePath(tEnv, managedTable);
+
+ // test field filter
+ collectAndCheckBatchReadWrite(
+ false,
+ false,
+ "currency = 'Euro'",
+ Collections.emptyList(),
+ Arrays.asList(
+ changelogRow("+I", "Euro", 114L),
+ changelogRow("+I", "Euro", 114L),
+ changelogRow("+I", "Euro", 119L)));
+
+ collectAndCheckBatchReadWrite(false, false, "rate >= 1", Collections.emptyList(), rates());
+
+ // test projection
+ collectAndCheckBatchReadWrite(
+ false,
+ false,
+ null,
+ Collections.singletonList("currency"),
+ Arrays.asList(
+ changelogRow("+I", "Euro"),
+ changelogRow("+I", "Euro"),
+ changelogRow("+I", "Euro"),
+ changelogRow("+I", "Yen"),
+ changelogRow("+I", "US Dollar")));
+
+ // test projection and filter
+ collectAndCheckBatchReadWrite(
+ false,
+ false,
+ "rate > 100 OR currency = 'Yen'",
+ Collections.singletonList("currency"),
+ Arrays.asList(
+ changelogRow("+I", "Euro"),
+ changelogRow("+I", "Euro"),
+ changelogRow("+I", "Euro"),
+ changelogRow("+I", "Yen"),
+ changelogRow("+I", "US Dollar")));
}
@Test
@@ -177,6 +372,8 @@ public class ReadWriteTableITCase extends KafkaTableTestBase {
Tuple2<String, BlockingIterator<Row, Row>> tuple =
collectAndCheckStreamingReadWriteWithoutClose(
Collections.emptyMap(),
+ "dt >= '2022-01-01' AND dt <= '2022-01-03' OR currency = 'HK Dollar'",
+ Collections.emptyList(),
Arrays.asList(
// part = 2022-01-01
changelogRow("+I", "US Dollar", 102L, "2022-01-01"),
@@ -186,6 +383,27 @@ public class ReadWriteTableITCase extends KafkaTableTestBase {
checkFileStorePath(tEnv, managedTable);
BlockingIterator<Row, Row> streamIter = tuple.f1;
+ // test log store in hybrid mode accepts all filters
+ tEnv.executeSql(
+ String.format(
+ "INSERT INTO `%s` PARTITION (dt = '2022-01-03')\n"
+ + "VALUES('HK Dollar', 100), ('Yen', 20)\n",
+ managedTable))
+ .await();
+
+ tEnv.executeSql(
+ String.format(
+ "INSERT INTO `%s` PARTITION (dt = '2022-01-04')\n"
+ + "VALUES('Yen', 20)\n",
+ managedTable))
+ .await();
+
+ assertThat(streamIter.collect(2, 10, TimeUnit.SECONDS))
+ .containsExactlyInAnyOrderElementsOf(
+ Arrays.asList(
+ changelogRow("+I", "HK Dollar", 100L, "2022-01-03"),
+ changelogRow("+I", "Yen", 20L, "2022-01-03")));
+
// overwrite partition 2022-01-02
prepareEnvAndOverwrite(
managedTable,
@@ -205,10 +423,55 @@ public class ReadWriteTableITCase extends KafkaTableTestBase {
changelogRow("+I", "US Dollar", 102L, "2022-01-01"),
// part = 2022-01-02
changelogRow("+I", "Euro", 100L, "2022-01-02"),
- changelogRow("+I", "Yen", 1L, "2022-01-02")));
+ changelogRow("+I", "Yen", 1L, "2022-01-02"),
+ // part = 2022-01-03
+ changelogRow("+I", "HK Dollar", 100L, "2022-01-03"),
+ changelogRow("+I", "Yen", 20L, "2022-01-03"),
+ // part = 2022-01-04
+ changelogRow("+I", "Yen", 20L, "2022-01-04")));
// check no changelog generated for streaming read
assertNoMoreRecords(streamIter);
+
+ // filter on partition
+ collectAndCheckStreamingReadWriteWithClose(
+ true,
+ true,
+ true,
+ Collections.emptyMap(),
+ "dt = '2022-01-01'",
+ Collections.emptyList(),
+ Collections.singletonList(changelogRow("+I", "US Dollar", 102L, "2022-01-01")));
+
+ // test field filter
+ collectAndCheckStreamingReadWriteWithClose(
+ true,
+ true,
+ true,
+ Collections.emptyMap(),
+ "currency = 'US Dollar'",
+ Collections.emptyList(),
+ Collections.singletonList(changelogRow("+I", "US Dollar", 102L, "2022-01-01")));
+
+ // test partition and field filter
+ collectAndCheckStreamingReadWriteWithClose(
+ true,
+ true,
+ true,
+ Collections.emptyMap(),
+ "dt = '2022-01-01' AND rate = 1",
+ Collections.emptyList(),
+ Collections.emptyList());
+
+ // test projection and filter
+ collectAndCheckStreamingReadWriteWithClose(
+ true,
+ true,
+ true,
+ Collections.emptyMap(),
+ "dt = '2022-01-02' AND currency = 'Euro'",
+ Arrays.asList("rate", "dt", "currency"),
+ Collections.singletonList(changelogRow("+I", 119L, "2022-01-02", "Euro")));
}
@Test
@@ -223,11 +486,61 @@ public class ReadWriteTableITCase extends KafkaTableTestBase {
true,
true,
Collections.emptyMap(),
+ null,
+ Collections.emptyList(),
Arrays.asList(
// part = 2022-01-01
changelogRow("+I", "US Dollar", 102L, "2022-01-01"),
// part = 2022-01-02
changelogRow("+I", "Euro", 119L, "2022-01-02"))));
+
+ // test partition filter
+ collectAndCheckStreamingReadWriteWithClose(
+ false,
+ true,
+ true,
+ Collections.emptyMap(),
+ "dt < '2022-01-02'",
+ Collections.emptyList(),
+ Collections.singletonList(
+ // part = 2022-01-01
+ changelogRow("+I", "US Dollar", 102L, "2022-01-01")));
+
+ // test field filter
+ collectAndCheckStreamingReadWriteWithClose(
+ false,
+ true,
+ true,
+ Collections.emptyMap(),
+ "rate = 102",
+ Collections.emptyList(),
+ Collections.singletonList(
+ // part = 2022-01-01
+ changelogRow("+I", "US Dollar", 102L, "2022-01-01")));
+
+ // test partition and field filter
+ collectAndCheckStreamingReadWriteWithClose(
+ false,
+ true,
+ true,
+ Collections.emptyMap(),
+ "rate = 102 or dt < '2022-01-02'",
+ Collections.emptyList(),
+ Collections.singletonList(
+ // part = 2022-01-01
+ changelogRow("+I", "US Dollar", 102L, "2022-01-01")));
+
+ // test projection and filter
+ collectAndCheckStreamingReadWriteWithClose(
+ false,
+ true,
+ true,
+ Collections.emptyMap(),
+ "rate = 102 or dt < '2022-01-02'",
+ Collections.singletonList("currency"),
+ Collections.singletonList(
+ // part = 2022-01-01
+ changelogRow("+I", "US Dollar")));
}
@Test
@@ -241,11 +554,86 @@ public class ReadWriteTableITCase extends KafkaTableTestBase {
true,
false,
Collections.emptyMap(),
+ null,
+ Collections.emptyList(),
Arrays.asList(
// part = 2022-01-01
changelogRow("+I", "US Dollar", 102L, "2022-01-01"),
// part = 2022-01-02
changelogRow("+I", "Euro", 115L, "2022-01-02"))));
+
+ // test partition filter
+ collectAndCheckStreamingReadWriteWithClose(
+ true,
+ true,
+ false,
+ Collections.emptyMap(),
+ "dt IS NOT NULL",
+ Collections.emptyList(),
+ Arrays.asList(
+ // part = 2022-01-01
+ changelogRow("+I", "US Dollar", 102L, "2022-01-01"),
+ // part = 2022-01-02
+ changelogRow("+I", "Euro", 115L, "2022-01-02")));
+
+ collectAndCheckStreamingReadWriteWithClose(
+ true,
+ true,
+ false,
+ Collections.emptyMap(),
+ "dt IS NULL",
+ Collections.emptyList(),
+ Collections.emptyList());
+
+ // test field filter
+ collectAndCheckStreamingReadWriteWithClose(
+ true,
+ true,
+ false,
+ Collections.emptyMap(),
+ "currency = 'US Dollar' OR rate = 115",
+ Collections.emptyList(),
+ Arrays.asList(
+ // part = 2022-01-01
+ changelogRow("+I", "US Dollar", 102L, "2022-01-01"),
+ // part = 2022-01-02
+ changelogRow("+I", "Euro", 115L, "2022-01-02")));
+
+ // test partition and field filter
+ collectAndCheckStreamingReadWriteWithClose(
+ true,
+ true,
+ false,
+ Collections.emptyMap(),
+ "(dt = '2022-01-02' AND currency = 'US Dollar') OR (dt = '2022-01-01' AND rate = 115)",
+ Collections.emptyList(),
+ Collections.emptyList());
+
+ // test projection
+ collectAndCheckStreamingReadWriteWithClose(
+ true,
+ true,
+ false,
+ Collections.emptyMap(),
+ null,
+ Collections.singletonList("rate"),
+ Arrays.asList(
+ // part = 2022-01-01
+ changelogRow("+I", 102L),
+ // part = 2022-01-02
+ changelogRow("+I", 115L)));
+
+ // test projection and filter
+ collectAndCheckStreamingReadWriteWithClose(
+ true,
+ true,
+ false,
+ Collections.emptyMap(),
+ "dt <> '2022-01-01'",
+ Collections.singletonList("rate"),
+ Collections.singletonList(
+ // part = 2022-01-02, Euro
+ changelogRow("+I", 115L)));
}
@Test
@@ -259,9 +647,41 @@ public class ReadWriteTableITCase extends KafkaTableTestBase {
false,
true,
Collections.emptyMap(),
+ null,
+ Collections.emptyList(),
Arrays.asList(
changelogRow("+I", "US Dollar", 102L),
changelogRow("+I", "Euro", 119L))));
+
+ // test field filter
+ collectAndCheckStreamingReadWriteWithClose(
+ true,
+ false,
+ true,
+ Collections.emptyMap(),
+ "currency = 'Yen'",
+ Collections.emptyList(),
+ Collections.emptyList());
+
+ // test projection
+ collectAndCheckStreamingReadWriteWithClose(
+ true,
+ false,
+ true,
+ Collections.emptyMap(),
+ null,
+ Collections.singletonList("currency"),
+ Arrays.asList(changelogRow("+I", "US Dollar"), changelogRow("+I", "Euro")));
+
+ // test projection and filter
+ collectAndCheckStreamingReadWriteWithClose(
+ true,
+ false,
+ true,
+ Collections.emptyMap(),
+ "rate = 102",
+ Collections.singletonList("currency"),
+ Collections.singletonList(changelogRow("+I", "US Dollar")));
}
@Test
@@ -275,9 +695,51 @@ public class ReadWriteTableITCase extends KafkaTableTestBase {
false,
false,
Collections.emptyMap(),
+ null,
+ Collections.emptyList(),
Arrays.asList(
changelogRow("+I", "US Dollar", 102L),
- changelogRow("+I", "Euro", 119L))));
+ changelogRow("+I", "Euro", 119L),
+ changelogRow("+I", null, 100L),
+ changelogRow("+I", "HK Dollar", null))));
+
+ // test field filter
+ collectAndCheckStreamingReadWriteWithClose(
+ true,
+ false,
+ false,
+ Collections.emptyMap(),
+ "currency IS NOT NULL",
+ Collections.emptyList(),
+ Arrays.asList(
+ changelogRow("+I", "US Dollar", 102L),
+ changelogRow("+I", "Euro", 119L),
+ changelogRow("+I", "HK Dollar", null)));
+
+ collectAndCheckStreamingReadWriteWithClose(
+ true,
+ false,
+ false,
+ Collections.emptyMap(),
+ "rate IS NOT NULL",
+ Collections.emptyList(),
+ Arrays.asList(
+ changelogRow("+I", "US Dollar", 102L),
+ changelogRow("+I", "Euro", 119L),
+ changelogRow("+I", null, 100L)));
+
+ // test projection and filter
+ collectAndCheckStreamingReadWriteWithClose(
+ true,
+ false,
+ false,
+ Collections.emptyMap(),
+ "currency IS NOT NULL AND rate is NOT NULL",
+ Collections.singletonList("rate"),
+ Arrays.asList(
+ changelogRow("+I", 102L), // US Dollar
+ changelogRow("+I", 119L)) // Euro
+ );
}
@Test
@@ -287,6 +749,8 @@ public class ReadWriteTableITCase extends KafkaTableTestBase {
false,
true,
true,
+ null,
+ Collections.emptyList(),
Arrays.asList(
// part = 2022-01-01
changelogRow("+I", "US Dollar", 102L, "2022-01-01"),
@@ -298,6 +762,86 @@ public class ReadWriteTableITCase extends KafkaTableTestBase {
changelogRow("-D", "Euro", 116L, "2022-01-01"),
// part = 2022-01-02
changelogRow("+I", "Euro", 119L, "2022-01-02")));
+
+ // test partition filter
+ collectLatestLogAndCheck(
+ false,
+ true,
+ true,
+ "dt = '2022-01-01'",
+ Collections.emptyList(),
+ Arrays.asList(
+ // part = 2022-01-01
+ changelogRow("+I", "US Dollar", 102L, "2022-01-01"),
+ changelogRow("+I", "Euro", 114L, "2022-01-01"),
+ changelogRow("+I", "Yen", 1L, "2022-01-01"),
+ changelogRow("-U", "Euro", 114L, "2022-01-01"),
+ changelogRow("+U", "Euro", 116L, "2022-01-01"),
+ changelogRow("-D", "Yen", 1L, "2022-01-01"),
+ changelogRow("-D", "Euro", 116L, "2022-01-01")));
+
+ // test field filter
+ collectLatestLogAndCheck(
+ false,
+ true,
+ true,
+ "currency = 'Yen'",
+ Collections.emptyList(),
+ Arrays.asList(
+ // part = 2022-01-01
+ changelogRow("+I", "Yen", 1L, "2022-01-01"),
+ changelogRow("-D", "Yen", 1L, "2022-01-01")));
+
+ collectLatestLogAndCheck(
+ false,
+ true,
+ true,
+ "rate = 114",
+ Collections.emptyList(),
+ Arrays.asList(
+ // part = 2022-01-01
+ changelogRow("+I", "Euro", 114L, "2022-01-01"),
+ changelogRow("-U", "Euro", 114L, "2022-01-01")));
+
+ // test partition and field filter
+ collectLatestLogAndCheck(
+ false,
+ true,
+ true,
+ "rate = 114 AND dt = '2022-01-02'",
+ Collections.emptyList(),
+ Collections.emptyList());
+
+ // test projection
+ collectLatestLogAndCheck(
+ false,
+ true,
+ true,
+ null,
+ Collections.singletonList("rate"),
+ Arrays.asList(
+ // part = 2022-01-01
+ changelogRow("+I", 102L), // US Dollar
+ changelogRow("+I", 114L), // Euro
+ changelogRow("+I", 1L), // Yen
+ changelogRow("-U", 114L), // Euro
+ changelogRow("+U", 116L), // Euro
+ changelogRow("-D", 1L), // Yen
+ changelogRow("-D", 116L), // Euro
+ // part = 2022-01-02
+ changelogRow("+I", 119L) // Euro
+ ));
+
+ // test projection and filter
+ collectLatestLogAndCheck(
+ false,
+ true,
+ true,
+ "dt = '2022-01-02'",
+ Collections.singletonList("rate"),
+ Collections.singletonList(
+ // part = 2022-01-02, Euro
+ changelogRow("+I", 119L)));
}
@Test
@@ -307,6 +851,8 @@ public class ReadWriteTableITCase extends KafkaTableTestBase {
false,
true,
false,
+ null,
+ Collections.emptyList(),
Arrays.asList(
// part = 2022-01-01
changelogRow("+I", "US Dollar", 102L, "2022-01-01"),
@@ -329,6 +875,8 @@ public class ReadWriteTableITCase extends KafkaTableTestBase {
false,
false,
true,
+ null,
+ Collections.emptyList(),
Arrays.asList(
changelogRow("+I", "US Dollar", 102L),
changelogRow("+I", "Euro", 114L),
@@ -338,6 +886,49 @@ public class ReadWriteTableITCase extends KafkaTableTestBase {
changelogRow("-D", "Euro", 116L),
changelogRow("+I", "Euro", 119L),
changelogRow("-D", "Yen", 1L)));
+
+ // test field filter
+ collectLatestLogAndCheck(
+ false,
+ false,
+ true,
+ "currency = 'Euro'",
+ Collections.emptyList(),
+ Arrays.asList(
+ changelogRow("+I", "Euro", 114L),
+ changelogRow("-U", "Euro", 114L),
+ changelogRow("+U", "Euro", 116L),
+ changelogRow("-D", "Euro", 116L),
+ changelogRow("+I", "Euro", 119L)));
+
+ // test projection
+ collectLatestLogAndCheck(
+ false,
+ false,
+ true,
+ null,
+ Collections.singletonList("currency"),
+ Arrays.asList(
+ changelogRow("+I", "US Dollar"),
+ changelogRow("+I", "Euro"),
+ changelogRow("+I", "Yen"),
+ changelogRow("-D", "Euro"),
+ changelogRow("+I", "Euro"),
+ changelogRow("-D", "Yen")));
+
+ // test projection and filter
+ collectLatestLogAndCheck(
+ false,
+ false,
+ true,
+ "currency = 'Euro'",
+ Collections.singletonList("rate"),
+ Arrays.asList(
+ changelogRow("+I", 114L),
+ changelogRow("-U", 114L),
+ changelogRow("+U", 116L),
+ changelogRow("-D", 116L),
+ changelogRow("+I", 119L)));
}
@Test
@@ -347,6 +938,8 @@ public class ReadWriteTableITCase extends KafkaTableTestBase {
false,
false,
false,
+ null,
+ Collections.emptyList(),
Arrays.asList(
changelogRow("+I", "US Dollar", 102L),
changelogRow("+I", "Euro", 114L),
@@ -357,7 +950,77 @@ public class ReadWriteTableITCase extends KafkaTableTestBase {
changelogRow("+I", "Euro", 119L),
changelogRow("-D", "Euro", 119L),
changelogRow("+I", "Euro", 119L),
- changelogRow("-D", "Yen", 1L)));
+ changelogRow("-D", "Yen", 1L),
+ changelogRow("+I", null, 100L),
+ changelogRow("+I", "HK Dollar", null)));
+
+ // test field filter
+ collectLatestLogAndCheck(
+ false,
+ false,
+ false,
+ "currency = 'Euro'",
+ Collections.emptyList(),
+ Arrays.asList(
+ changelogRow("+I", "Euro", 114L),
+ changelogRow("-D", "Euro", 114L),
+ changelogRow("+I", "Euro", 116L),
+ changelogRow("-D", "Euro", 116L),
+ changelogRow("+I", "Euro", 119L),
+ changelogRow("-D", "Euro", 119L),
+ changelogRow("+I", "Euro", 119L)));
+
+ // test projection
+ collectLatestLogAndCheck(
+ false,
+ false,
+ false,
+ null,
+ Arrays.asList("currency", "rate"),
+ Arrays.asList(
+ changelogRow("+I", "US Dollar", 102L),
+ changelogRow("+I", "Euro", 114L),
+ changelogRow("+I", "Yen", 1L),
+ changelogRow("-D", "Euro", 114L),
+ changelogRow("+I", "Euro", 116L),
+ changelogRow("-D", "Euro", 116L),
+ changelogRow("+I", "Euro", 119L),
+ changelogRow("-D", "Euro", 119L),
+ changelogRow("+I", "Euro", 119L),
+ changelogRow("-D", "Yen", 1L),
+ changelogRow("+I", null, 100L),
+ changelogRow("+I", "HK Dollar", null)));
+
+ // test projection and filter
+ collectLatestLogAndCheck(
+ false,
+ false,
+ false,
+ "currency IS NOT NULL",
+ Collections.singletonList("currency"),
+ Arrays.asList(
+ changelogRow("+I", "US Dollar"),
+ changelogRow("+I", "Euro"),
+ changelogRow("+I", "Yen"),
+ changelogRow("-D", "Euro"),
+ changelogRow("+I", "Euro"),
+ changelogRow("-D", "Euro"),
+ changelogRow("+I", "Euro"),
+ changelogRow("-D", "Euro"),
+ changelogRow("+I", "Euro"),
+ changelogRow("-D", "Yen"),
+ changelogRow("+I", "HK Dollar")));
+
+ collectLatestLogAndCheck(
+ false,
+ false,
+ false,
+ "rate = 119",
+ Collections.singletonList("currency"),
+ Arrays.asList(
+ changelogRow("+I", "Euro"),
+ changelogRow("-D", "Euro"),
+ changelogRow("+I", "Euro")));
}
@Test
@@ -372,10 +1035,42 @@ public class ReadWriteTableITCase extends KafkaTableTestBase {
changelogRow("+U", "Euro", 119L));
// currency as pk
- collectLatestLogAndCheck(true, false, true, expected);
+ collectLatestLogAndCheck(true, false, true, null, Collections.emptyList(), expected);
// without pk
- collectLatestLogAndCheck(true, false, true, expected);
+ collectLatestLogAndCheck(true, false, true, null, Collections.emptyList(), expected);
+
+ // test field filter
+ collectLatestLogAndCheck(
+ true,
+ false,
+ true,
+ "rate = 114",
+ Collections.emptyList(),
+ Arrays.asList(changelogRow("+I", "Euro", 114L), changelogRow("-U", "Euro", 114L)));
+
+ // test projection
+ collectLatestLogAndCheck(
+ true,
+ false,
+ true,
+ null,
+ Collections.singletonList("rate"),
+ Arrays.asList(
+ changelogRow("+I", 102L),
+ changelogRow("+I", 114L),
+ changelogRow("+I", 1L),
+ changelogRow("-U", 114L),
+ changelogRow("+U", 119L)));
+
+ // test projection and filter
+ collectLatestLogAndCheck(
+ true,
+ false,
+ true,
+ "rate = 114",
+ Collections.singletonList("currency"),
+ Arrays.asList(changelogRow("+I", "Euro"), changelogRow("-U", "Euro")));
}
@Test
@@ -391,6 +1086,8 @@ public class ReadWriteTableITCase extends KafkaTableTestBase {
changelogRow("+I", "US Dollar", 102L, "2022-01-01"),
changelogRow("+I", "Yen", 1L, "2022-01-01"),
changelogRow("+I", "Euro", 114L, "2022-01-01"),
+ changelogRow("-U", "US Dollar", 102L, "2022-01-01"),
+ changelogRow("+U", "US Dollar", 114L, "2022-01-01"),
// part = 2022-01-02
changelogRow("+I", "Euro", 119L, "2022-01-02")));
@@ -456,10 +1153,13 @@ public class ReadWriteTableITCase extends KafkaTableTestBase {
changelogRow("+I", "Euro", 119L, "2022-01-02")));
}
- // ------------------------ Tools ----------------------------------
-
private String collectAndCheckBatchReadWrite(
- boolean partitioned, boolean hasPk, List<Row> expected) throws Exception {
+ boolean partitioned,
+ boolean hasPk,
+ @Nullable String filter,
+ List<String> projection,
+ List<Row> expected)
+ throws Exception {
return collectAndCheckUnderSameEnv(
false,
false,
@@ -468,6 +1168,8 @@ public class ReadWriteTableITCase extends KafkaTableTestBase {
hasPk,
true,
Collections.emptyMap(),
+ filter,
+ projection,
expected)
.f0;
}
@@ -477,31 +1179,60 @@ public class ReadWriteTableITCase extends KafkaTableTestBase {
boolean partitioned,
boolean hasPk,
Map<String, String> readHints,
+ @Nullable String filter,
+ List<String> projection,
List<Row> expected)
throws Exception {
Tuple2<String, BlockingIterator<Row, Row>> tuple =
collectAndCheckUnderSameEnv(
- true, enableLogStore, false, partitioned, hasPk, true, readHints, expected);
+ true,
+ enableLogStore,
+ false,
+ partitioned,
+ hasPk,
+ true,
+ readHints,
+ filter,
+ projection,
+ expected);
tuple.f1.close();
return tuple.f0;
}
private Tuple2<String, BlockingIterator<Row, Row>>
collectAndCheckStreamingReadWriteWithoutClose(
- Map<String, String> readHints, List<Row> expected) throws Exception {
+ Map<String, String> readHints,
+ @Nullable String filter,
+ List<String> projection,
+ List<Row> expected)
+ throws Exception {
return collectAndCheckUnderSameEnv(
- true, true, false, true, true, true, readHints, expected);
+ true, true, false, true, true, true, readHints, filter, projection, expected);
}
private void collectLatestLogAndCheck(
- boolean insertOnly, boolean partitioned, boolean hasPk, List<Row> expected)
+ boolean insertOnly,
+ boolean partitioned,
+ boolean hasPk,
+ @Nullable String filter,
+ List<String> projection,
+ List<Row> expected)
throws Exception {
Map<String, String> hints = new HashMap<>();
hints.put(
LOG_PREFIX + LogOptions.SCAN.key(),
LogOptions.LogStartupMode.LATEST.name().toLowerCase());
collectAndCheckUnderSameEnv(
- true, true, insertOnly, partitioned, hasPk, false, hints, expected)
+ true,
+ true,
+ insertOnly,
+ partitioned,
+ hasPk,
+ false,
+ hints,
+ filter,
+ projection,
+ expected)
.f1
.close();
}
@@ -517,7 +1248,16 @@ public class ReadWriteTableITCase extends KafkaTableTestBase {
hints.put(LOG_PREFIX + LogOptions.SCAN.key(), "from-timestamp");
hints.put(LOG_PREFIX + LogOptions.SCAN_TIMESTAMP_MILLS.key(), String.valueOf(timestamp));
collectAndCheckUnderSameEnv(
- true, true, insertOnly, partitioned, hasPk, true, hints, expected)
+ true,
+ true,
+ insertOnly,
+ partitioned,
+ hasPk,
+ true,
+ hints,
+ null,
+ Collections.emptyList(),
+ expected)
.f1
.close();
}
@@ -530,6 +1270,8 @@ public class ReadWriteTableITCase extends KafkaTableTestBase {
boolean hasPk,
boolean writeFirst,
Map<String, String> readHints,
+ @Nullable String filter,
+ List<String> projection,
List<Row> expected)
throws Exception {
Map<String, String> tableOptions = new HashMap<>();
@@ -565,7 +1307,7 @@ public class ReadWriteTableITCase extends KafkaTableTestBase {
tEnv.executeSql(managedTableDdl);
String insertQuery = prepareInsertIntoQuery(sourceTable, managedTable);
- String selectQuery = prepareSimpleSelectQuery(managedTable, readHints);
+ String selectQuery = prepareSelectQuery(managedTable, readHints, filter, projection);
BlockingIterator<Row, Row> iterator;
if (writeFirst) {
@@ -621,11 +1363,13 @@ public class ReadWriteTableITCase extends KafkaTableTestBase {
Map<String, String> hints,
List<Row> expectedRecords)
throws Exception {
- String selectQuery = prepareSimpleSelectQuery(managedTable, hints);
List<Row> actual = new ArrayList<>();
BlockingIterator<Row, Row> iterator =
- collect(tEnv, selectQuery, expectedRecords.size(), actual);
-
+ collect(
+ tEnv,
+ prepareSimpleSelectQuery(managedTable, hints),
+ expectedRecords.size(),
+ actual);
assertThat(actual).containsExactlyInAnyOrderElementsOf(expectedRecords);
return iterator;
}
@@ -659,20 +1403,26 @@ public class ReadWriteTableITCase extends KafkaTableTestBase {
StringBuilder ddl =
new StringBuilder("CREATE TABLE IF NOT EXISTS ")
.append(String.format("`%s`", managedTableName));
+ ddl.append(prepareOptions(tableOptions))
+ .append(String.format(" LIKE `%s` (EXCLUDING OPTIONS)\n", sourceTableName));
+ return ddl.toString();
+ }
+
+ private static String prepareOptions(Map<String, String> tableOptions) {
+ StringBuilder with = new StringBuilder();
if (tableOptions.size() > 0) {
- ddl.append(" WITH (\n");
+ with.append(" WITH (\n");
tableOptions.forEach(
(k, v) ->
- ddl.append(" ")
+ with.append(" ")
.append(String.format("'%s'", k))
.append(" = ")
.append(String.format("'%s',\n", v)));
- int len = ddl.length();
- ddl.delete(len - 2, len);
- ddl.append(")");
+ int len = with.length();
+ with.delete(len - 2, len);
+ with.append(")");
}
- ddl.append(String.format(" LIKE `%s` (EXCLUDING OPTIONS)\n", sourceTableName));
- return ddl.toString();
+ return with.toString();
}
private static String prepareInsertIntoQuery(String sourceTableName, String managedTableName) {
@@ -743,7 +1493,25 @@ public class ReadWriteTableITCase extends KafkaTableTestBase {
}
private static String prepareSimpleSelectQuery(String tableName, Map<String, String> hints) {
- return String.format("SELECT * FROM `%s` %s", tableName, buildHints(hints));
+ return prepareSelectQuery(tableName, hints, null, Collections.emptyList());
+ }
+
+ private static String prepareSelectQuery(
+ String tableName,
+ Map<String, String> hints,
+ @Nullable String filter,
+ List<String> projections) {
+ StringBuilder queryBuilder =
+ new StringBuilder(
+ String.format(
+ "SELECT %s FROM `%s` %s",
+ projections.isEmpty() ? "*" : String.join(", ", projections),
+ tableName,
+ buildHints(hints)));
+ if (filter != null) {
+ queryBuilder.append("\nWHERE ").append(filter);
+ }
+ return queryBuilder.toString();
}
private static String buildHints(Map<String, String> hints) {
@@ -868,6 +1636,7 @@ public class ReadWriteTableITCase extends KafkaTableTestBase {
changelogRow("+I", "Euro", 114L, "2022-01-01"),
changelogRow("+I", "Yen", 1L, "2022-01-01"),
changelogRow("+I", "Euro", 114L, "2022-01-01"),
+ changelogRow("+I", "US Dollar", 114L, "2022-01-01"),
// part = 2022-01-02
changelogRow("+I", "Euro", 119L, "2022-01-02"));
}
@@ -909,7 +1678,9 @@ public class ReadWriteTableITCase extends KafkaTableTestBase {
changelogRow("+I", "Euro", 119L),
changelogRow("-U", "Euro", 119L),
changelogRow("+U", "Euro", 119L),
- changelogRow("-D", "Yen", 1L));
+ changelogRow("-D", "Yen", 1L),
+ changelogRow("+I", null, 100L),
+ changelogRow("+I", "HK Dollar", null));
}
private static List<Row> dailyRatesChangelogWithUB() {
diff --git a/flink-table-store-kafka/src/main/java/org/apache/flink/table/store/kafka/KafkaLogDeserializationSchema.java b/flink-table-store-kafka/src/main/java/org/apache/flink/table/store/kafka/KafkaLogDeserializationSchema.java
index e17699f..7a51ce4 100644
--- a/flink-table-store-kafka/src/main/java/org/apache/flink/table/store/kafka/KafkaLogDeserializationSchema.java
+++ b/flink-table-store-kafka/src/main/java/org/apache/flink/table/store/kafka/KafkaLogDeserializationSchema.java
@@ -44,7 +44,7 @@ public class KafkaLogDeserializationSchema implements KafkaDeserializationSchema
private final TypeInformation<RowData> producedType;
private final int fieldCount;
private final int[] primaryKey;
- @Nullable private final DeserializationSchema<RowData> keyDeserializer;
+ @Nullable private final DeserializationSchema<RowData> primaryKeyDeserializer;
private final DeserializationSchema<RowData> valueDeserializer;
private final RowData.FieldGetter[] keyFieldGetters;
@Nullable private final int[][] projectFields;
@@ -54,11 +54,11 @@ public class KafkaLogDeserializationSchema implements KafkaDeserializationSchema
public KafkaLogDeserializationSchema(
DataType physicalType,
int[] primaryKey,
- @Nullable DeserializationSchema<RowData> keyDeserializer,
+ @Nullable DeserializationSchema<RowData> primaryKeyDeserializer,
DeserializationSchema<RowData> valueDeserializer,
@Nullable int[][] projectFields) {
this.primaryKey = primaryKey;
- this.keyDeserializer = keyDeserializer;
+ this.primaryKeyDeserializer = primaryKeyDeserializer;
this.valueDeserializer = valueDeserializer;
DataType projectedType =
projectFields == null
@@ -82,8 +82,8 @@ public class KafkaLogDeserializationSchema implements KafkaDeserializationSchema
@Override
public void open(DeserializationSchema.InitializationContext context) throws Exception {
- if (keyDeserializer != null) {
- keyDeserializer.open(context);
+ if (primaryKeyDeserializer != null) {
+ primaryKeyDeserializer.open(context);
}
valueDeserializer.open(context);
projectCollector = new ProjectCollector();
@@ -107,7 +107,7 @@ public class KafkaLogDeserializationSchema implements KafkaDeserializationSchema
Collector<RowData> collector = projectCollector.project(underCollector);
if (primaryKey.length > 0 && record.value() == null) {
- RowData key = keyDeserializer.deserialize(record.key());
+ RowData key = primaryKeyDeserializer.deserialize(record.key());
GenericRowData value = new GenericRowData(RowKind.DELETE, fieldCount);
for (int i = 0; i < primaryKey.length; i++) {
value.setField(primaryKey[i], keyFieldGetters[i].getFieldOrNull(key));
diff --git a/flink-table-store-kafka/src/main/java/org/apache/flink/table/store/kafka/KafkaLogStoreFactory.java b/flink-table-store-kafka/src/main/java/org/apache/flink/table/store/kafka/KafkaLogStoreFactory.java
index a5e787b..9904934 100644
--- a/flink-table-store-kafka/src/main/java/org/apache/flink/table/store/kafka/KafkaLogStoreFactory.java
+++ b/flink-table-store-kafka/src/main/java/org/apache/flink/table/store/kafka/KafkaLogStoreFactory.java
@@ -167,11 +167,11 @@ public class KafkaLogStoreFactory implements LogStoreTableFactory {
FactoryUtil.TableFactoryHelper helper = createTableFactoryHelper(this, context);
ResolvedSchema schema = context.getCatalogTable().getResolvedSchema();
DataType physicalType = schema.toPhysicalRowDataType();
- DeserializationSchema<RowData> keyDeserializer = null;
+ DeserializationSchema<RowData> primaryKeyDeserializer = null;
int[] primaryKey = schema.getPrimaryKeyIndexes();
if (primaryKey.length > 0) {
DataType keyType = DataTypeUtils.projectRow(physicalType, primaryKey);
- keyDeserializer =
+ primaryKeyDeserializer =
LogStoreTableFactory.getKeyDecodingFormat(helper)
.createRuntimeDecoder(sourceContext, keyType);
}
@@ -183,7 +183,7 @@ public class KafkaLogStoreFactory implements LogStoreTableFactory {
toKafkaProperties(helper.getOptions()),
physicalType,
primaryKey,
- keyDeserializer,
+ primaryKeyDeserializer,
valueDeserializer,
projectFields,
helper.getOptions().get(CONSISTENCY),
[flink-table-store] 04/09: [hotfix] Add thread name to StoreSinkWriter compaction thread pool
Posted by lz...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
lzljs3620320 pushed a commit to branch release-0.1
in repository https://gitbox.apache.org/repos/asf/flink-table-store.git
commit 295bb237439673520f23e8e2efc3d6de00aa61c0
Author: JingsongLi <lz...@aliyun.com>
AuthorDate: Thu Mar 31 10:07:52 2022 +0800
[hotfix] Add thread name to StoreSinkWriter compaction thread pool
---
.../org/apache/flink/table/store/connector/sink/StoreSinkWriter.java | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/flink-table-store-connector/src/main/java/org/apache/flink/table/store/connector/sink/StoreSinkWriter.java b/flink-table-store-connector/src/main/java/org/apache/flink/table/store/connector/sink/StoreSinkWriter.java
index 6a568a6..2995b74 100644
--- a/flink-table-store-connector/src/main/java/org/apache/flink/table/store/connector/sink/StoreSinkWriter.java
+++ b/flink-table-store-connector/src/main/java/org/apache/flink/table/store/connector/sink/StoreSinkWriter.java
@@ -31,6 +31,7 @@ import org.apache.flink.table.store.file.utils.RecordWriter;
import org.apache.flink.table.store.log.LogWriteCallback;
import org.apache.flink.table.store.sink.SinkRecord;
import org.apache.flink.table.store.sink.SinkRecordConverter;
+import org.apache.flink.util.concurrent.ExecutorThreadFactory;
import javax.annotation.Nullable;
@@ -76,7 +77,9 @@ public class StoreSinkWriter<WriterStateT>
this.overwrite = overwrite;
this.logWriter = logWriter;
this.logCallback = logCallback;
- this.compactExecutor = Executors.newSingleThreadScheduledExecutor();
+ this.compactExecutor =
+ Executors.newSingleThreadScheduledExecutor(
+ new ExecutorThreadFactory("compaction-thread"));
this.writers = new HashMap<>();
}