You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by "JingsongLi (via GitHub)" <gi...@apache.org> on 2023/03/12 05:15:03 UTC
[GitHub] [flink-table-store] JingsongLi opened a new pull request, #594: [core] Introduce LookupMergeFunction and ForceUpLevel0Compaction
JingsongLi opened a new pull request, #594:
URL: https://github.com/apache/flink-table-store/pull/594
### Introduce `LookupMergeFunction`
When Lookup Changelog producer is enabled, each merge will query the old merged record, so the latest high level record should be the final merged value.
### Introduce `ForceUpLevel0Compaction`
Because changelog is generated when level 0 is merged to a higher level, we need a compaction policy to ensure that changelog is generated each time.
### Introduce `LookupChangelogMergeFunctionWrapper`
Changelog records are generated in the process of the level-0 file participating in the compaction, if during the compaction processing:
- Without level-0 records, no changelog.
- With level-0 record, with level-x (x > 0) record, level-x record should be BEFORE, level-0 should be AFTER.
- With level-0 record, without level-x record, need to lookup the history value of the upper level as BEFORE.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [flink-table-store] SteNicholas commented on a diff in pull request #594: [core] Introduce LookupMergeFunction and ForceUpLevel0Compaction
Posted by "SteNicholas (via GitHub)" <gi...@apache.org>.
SteNicholas commented on code in PR #594:
URL: https://github.com/apache/flink-table-store/pull/594#discussion_r1134691216
##########
flink-table-store-core/src/main/java/org/apache/flink/table/store/file/mergetree/compact/LookupChangelogMergeFunctionWrapper.java:
##########
@@ -0,0 +1,142 @@
+/*
+ * 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.mergetree.compact;
+
+import org.apache.flink.table.store.data.InternalRow;
+import org.apache.flink.table.store.file.KeyValue;
+import org.apache.flink.table.store.types.RowKind;
+
+import java.util.function.Function;
+
+import static org.apache.flink.table.store.utils.Preconditions.checkArgument;
+
+/**
+ * Wrapper for {@link MergeFunction}s to produce changelog by lookup during the compaction involving
+ * level 0 files.
+ *
+ * <p>Changelog records are generated in the process of the level-0 file participating in the
+ * compaction, if during the compaction processing:
+ *
+ * <ul>
+ * <li>Without level-0 records, no changelog.
+ * <li>With level-0 record, with level-x (x > 0) record, level-x record should be BEFORE, level-0
+ * should be AFTER.
+ * <li>With level-0 record, without level-x record, need to lookup the history value of the upper
+ * level as BEFORE.
+ * </ul>
+ */
+public class LookupChangelogMergeFunctionWrapper implements MergeFunctionWrapper<ChangelogResult> {
+
+ private final LookupMergeFunction mergeFunction;
+ private final MergeFunction<KeyValue> mergeFunction2;
+ private final Function<InternalRow, KeyValue> lookup;
+
+ private final ChangelogResult reusedResult = new ChangelogResult();
+ private final KeyValue reusedBefore = new KeyValue();
+ private final KeyValue reusedAfter = new KeyValue();
+
+ public LookupChangelogMergeFunctionWrapper(
+ MergeFunctionFactory<KeyValue> mergeFunctionFactory,
+ Function<InternalRow, KeyValue> lookup) {
+ MergeFunction<KeyValue> mergeFunction = mergeFunctionFactory.create();
+ checkArgument(
+ mergeFunction instanceof LookupMergeFunction,
+ "Merge function should be a LookupMergeFunction, but is %s, there is a bug.",
Review Comment:
```suggestion
"Merge function should be a LookupMergeFunction, but is %s, there is a bug.",
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [flink-table-store] JingsongLi commented on a diff in pull request #594: [core] Introduce LookupMergeFunction and ForceUpLevel0Compaction
Posted by "JingsongLi (via GitHub)" <gi...@apache.org>.
JingsongLi commented on code in PR #594:
URL: https://github.com/apache/flink-table-store/pull/594#discussion_r1134784531
##########
flink-table-store-core/src/main/java/org/apache/flink/table/store/file/mergetree/compact/ForceUpLevel0Compaction.java:
##########
@@ -0,0 +1,59 @@
+/*
+ * 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.mergetree.compact;
+
+import org.apache.flink.table.store.file.compact.CompactUnit;
+import org.apache.flink.table.store.file.mergetree.LevelSortedRun;
+
+import java.util.List;
+import java.util.Optional;
+
+/** A {@link CompactStrategy} to force compacting level 0 files. */
+public class ForceUpLevel0Compaction implements CompactStrategy {
+
+ private final UniversalCompaction universalCompaction;
+
+ public ForceUpLevel0Compaction(UniversalCompaction universalCompaction) {
+ this.universalCompaction = universalCompaction;
+ }
+
+ @Override
+ public Optional<CompactUnit> pick(int numLevels, List<LevelSortedRun> runs) {
+ Optional<CompactUnit> pick = universalCompaction.pick(numLevels, runs);
+ if (pick.isPresent()) {
+ return pick;
+ }
+
+ if (runs.isEmpty() || runs.get(0).level() > 0) {
+ return Optional.empty();
+ }
+
+ // collect all level 0 files
+ int candidateCount = 1;
Review Comment:
I think we can finish this in one loop:
```
// collect all level 0 files
int candidateCount = 0;
for (int i = candidateCount; i < runs.size(); i++) {
if (runs.get(i).level() > 0) {
break;
}
candidateCount++;
}
return candidateCount == 0 ?
Optional.empty() :
Optional.of(universal.pickForSizeRatio(numLevels - 1, runs, candidateCount, true));
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [flink-table-store] SteNicholas commented on a diff in pull request #594: [core] Introduce LookupMergeFunction and ForceUpLevel0Compaction
Posted by "SteNicholas (via GitHub)" <gi...@apache.org>.
SteNicholas commented on code in PR #594:
URL: https://github.com/apache/flink-table-store/pull/594#discussion_r1134689986
##########
flink-table-store-core/src/main/java/org/apache/flink/table/store/file/mergetree/compact/ForceUpLevel0Compaction.java:
##########
@@ -0,0 +1,59 @@
+/*
+ * 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.mergetree.compact;
+
+import org.apache.flink.table.store.file.compact.CompactUnit;
+import org.apache.flink.table.store.file.mergetree.LevelSortedRun;
+
+import java.util.List;
+import java.util.Optional;
+
+/** A {@link CompactStrategy} to force compacting level 0 files. */
+public class ForceUpLevel0Compaction implements CompactStrategy {
+
+ private final UniversalCompaction universalCompaction;
+
+ public ForceUpLevel0Compaction(UniversalCompaction universalCompaction) {
+ this.universalCompaction = universalCompaction;
+ }
+
+ @Override
+ public Optional<CompactUnit> pick(int numLevels, List<LevelSortedRun> runs) {
+ Optional<CompactUnit> pick = universalCompaction.pick(numLevels, runs);
+ if (pick.isPresent()) {
+ return pick;
+ }
+
+ if (runs.isEmpty() || runs.get(0).level() > 0) {
+ return Optional.empty();
+ }
+
+ // collect all level 0 files
+ int candidateCount = 1;
Review Comment:
Why not `int candidateCount = runs.stream().filter(r->r.level()>0).count();`?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [flink-table-store] SteNicholas commented on a diff in pull request #594: [core] Introduce LookupMergeFunction and ForceUpLevel0Compaction
Posted by "SteNicholas (via GitHub)" <gi...@apache.org>.
SteNicholas commented on code in PR #594:
URL: https://github.com/apache/flink-table-store/pull/594#discussion_r1134689986
##########
flink-table-store-core/src/main/java/org/apache/flink/table/store/file/mergetree/compact/ForceUpLevel0Compaction.java:
##########
@@ -0,0 +1,59 @@
+/*
+ * 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.mergetree.compact;
+
+import org.apache.flink.table.store.file.compact.CompactUnit;
+import org.apache.flink.table.store.file.mergetree.LevelSortedRun;
+
+import java.util.List;
+import java.util.Optional;
+
+/** A {@link CompactStrategy} to force compacting level 0 files. */
+public class ForceUpLevel0Compaction implements CompactStrategy {
+
+ private final UniversalCompaction universalCompaction;
+
+ public ForceUpLevel0Compaction(UniversalCompaction universalCompaction) {
+ this.universalCompaction = universalCompaction;
+ }
+
+ @Override
+ public Optional<CompactUnit> pick(int numLevels, List<LevelSortedRun> runs) {
+ Optional<CompactUnit> pick = universalCompaction.pick(numLevels, runs);
+ if (pick.isPresent()) {
+ return pick;
+ }
+
+ if (runs.isEmpty() || runs.get(0).level() > 0) {
+ return Optional.empty();
+ }
+
+ // collect all level 0 files
+ int candidateCount = 1;
Review Comment:
Why not `int candidateCount = runs.stream().filter(r -> r.level() > 0).count();`?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [flink-table-store] JingsongLi commented on a diff in pull request #594: [core] Introduce LookupMergeFunction and ForceUpLevel0Compaction
Posted by "JingsongLi (via GitHub)" <gi...@apache.org>.
JingsongLi commented on code in PR #594:
URL: https://github.com/apache/flink-table-store/pull/594#discussion_r1134786122
##########
flink-table-store-core/src/main/java/org/apache/flink/table/store/file/mergetree/compact/aggregate/AggregateMergeFunction.java:
##########
@@ -172,10 +133,30 @@ public MergeFunction<KeyValue> create(@Nullable int[][] projection) {
fieldTypes = project.project(tableTypes);
}
- return new AggregateMergeFunction(
- createFieldGetters(fieldTypes),
- new AggregateMergeFunction.RowAggregator(
- conf, fieldNames, fieldTypes, primaryKeys));
+ FieldAggregator[] fieldAggregators = new FieldAggregator[fieldNames.size()];
+ for (int i = 0; i < fieldNames.size(); i++) {
+ String fieldName = fieldNames.get(i);
+ DataType fieldType = fieldTypes.get(i);
+ // aggregate by primary keys, so they do not aggregate
+ boolean isPrimaryKey = primaryKeys.contains(fieldName);
+ String strAggFunc =
+ conf.get(
+ key(FIELDS + "." + fieldName + "." + AGG_FUNCTION)
+ .stringType()
+ .noDefaultValue()
+ .withDescription(
+ "Get " + fieldName + "'s aggregate function"));
+ boolean ignoreRetract =
+ conf.get(
+ key(FIELDS + "." + fieldName + "." + IGNORE_RETRACT)
+ .booleanType()
+ .defaultValue(false));
Review Comment:
I delete description of `AGG_FUNCTION`, here the description is useless, it can not be see by users.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [flink-table-store] SteNicholas commented on a diff in pull request #594: [core] Introduce LookupMergeFunction and ForceUpLevel0Compaction
Posted by "SteNicholas (via GitHub)" <gi...@apache.org>.
SteNicholas commented on code in PR #594:
URL: https://github.com/apache/flink-table-store/pull/594#discussion_r1134693522
##########
flink-table-store-core/src/main/java/org/apache/flink/table/store/file/mergetree/compact/LookupMergeFunction.java:
##########
@@ -0,0 +1,99 @@
+/*
+ * 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.mergetree.compact;
+
+import org.apache.flink.table.store.file.KeyValue;
+
+import javax.annotation.Nullable;
+
+import java.util.Iterator;
+import java.util.LinkedList;
+
+/**
+ * A {@link MergeFunction} for lookup, this wrapper only consider the latest high level record,
Review Comment:
```suggestion
* A {@link MergeFunction} for lookup, this wrapper only considers the latest high level record,
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [flink-table-store] SteNicholas commented on a diff in pull request #594: [core] Introduce LookupMergeFunction and ForceUpLevel0Compaction
Posted by "SteNicholas (via GitHub)" <gi...@apache.org>.
SteNicholas commented on code in PR #594:
URL: https://github.com/apache/flink-table-store/pull/594#discussion_r1134698287
##########
flink-table-store-core/src/main/java/org/apache/flink/table/store/file/mergetree/compact/aggregate/AggregateMergeFunction.java:
##########
@@ -172,10 +133,30 @@ public MergeFunction<KeyValue> create(@Nullable int[][] projection) {
fieldTypes = project.project(tableTypes);
}
- return new AggregateMergeFunction(
- createFieldGetters(fieldTypes),
- new AggregateMergeFunction.RowAggregator(
- conf, fieldNames, fieldTypes, primaryKeys));
+ FieldAggregator[] fieldAggregators = new FieldAggregator[fieldNames.size()];
+ for (int i = 0; i < fieldNames.size(); i++) {
+ String fieldName = fieldNames.get(i);
+ DataType fieldType = fieldTypes.get(i);
+ // aggregate by primary keys, so they do not aggregate
+ boolean isPrimaryKey = primaryKeys.contains(fieldName);
+ String strAggFunc =
+ conf.get(
+ key(FIELDS + "." + fieldName + "." + AGG_FUNCTION)
+ .stringType()
+ .noDefaultValue()
+ .withDescription(
+ "Get " + fieldName + "'s aggregate function"));
+ boolean ignoreRetract =
+ conf.get(
+ key(FIELDS + "." + fieldName + "." + IGNORE_RETRACT)
+ .booleanType()
+ .defaultValue(false));
Review Comment:
Adds the description?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [flink-table-store] JingsongLi merged pull request #594: [core] Introduce LookupMergeFunction and ForceUpLevel0Compaction
Posted by "JingsongLi (via GitHub)" <gi...@apache.org>.
JingsongLi merged PR #594:
URL: https://github.com/apache/flink-table-store/pull/594
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org