You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@paimon.apache.org by "JingsongLi (via GitHub)" <gi...@apache.org> on 2025/09/03 03:16:14 UTC
Re: [PR] [core]support format table read [paimon]
JingsongLi commented on code in PR #6095:
URL: https://github.com/apache/paimon/pull/6095#discussion_r2317652013
##########
paimon-core/src/main/java/org/apache/paimon/table/format/FormatReadBuilder.java:
##########
@@ -0,0 +1,203 @@
+/*
+ * 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.paimon.table.format;
+
+import org.apache.paimon.CoreOptions;
+import org.apache.paimon.data.InternalRow;
+import org.apache.paimon.format.FileFormatDiscover;
+import org.apache.paimon.format.FormatReaderContext;
+import org.apache.paimon.format.FormatReaderFactory;
+import org.apache.paimon.fs.Path;
+import org.apache.paimon.io.DataFileRecordReader;
+import org.apache.paimon.partition.PartitionPredicate;
+import org.apache.paimon.partition.PartitionUtils;
+import org.apache.paimon.predicate.Predicate;
+import org.apache.paimon.predicate.PredicateBuilder;
+import org.apache.paimon.predicate.TopN;
+import org.apache.paimon.reader.FileRecordReader;
+import org.apache.paimon.reader.RecordReader;
+import org.apache.paimon.table.FormatTable;
+import org.apache.paimon.table.source.ReadBuilder;
+import org.apache.paimon.table.source.StreamTableScan;
+import org.apache.paimon.table.source.TableRead;
+import org.apache.paimon.table.source.TableScan;
+import org.apache.paimon.types.RowType;
+import org.apache.paimon.utils.Filter;
+import org.apache.paimon.utils.Pair;
+
+import javax.annotation.Nullable;
+
+import java.io.IOException;
+import java.util.Collections;
+import java.util.Map;
+
+import static org.apache.paimon.partition.PartitionPredicate.createPartitionPredicate;
+import static org.apache.paimon.partition.PartitionPredicate.fromPredicate;
+
+/** {@link ReadBuilder} for {@link FormatTable}. */
+public class FormatReadBuilder implements ReadBuilder {
+
+ private static final long serialVersionUID = 1L;
+
+ private CoreOptions options;
+ private FormatTable table;
+ private RowType readType;
+
+ private final FileFormatDiscover formatDiscover;
+
+ @Nullable private Predicate filter;
+ @Nullable private PartitionPredicate partitionFilter;
+
+ public FormatReadBuilder(FormatTable table) {
+ this.table = table;
+ this.readType = this.table.rowType();
+ this.options = new CoreOptions(table.options());
+ this.formatDiscover = FileFormatDiscover.of(this.options);
+ }
+
+ @Override
+ public String tableName() {
+ return this.table.name();
+ }
+
+ @Override
+ public RowType readType() {
+ return this.readType;
+ }
+
+ @Override
+ public ReadBuilder withFilter(Predicate predicate) {
+ if (this.filter == null) {
+ this.filter = predicate;
+ } else {
+ this.filter = PredicateBuilder.and(this.filter, predicate);
+ }
+ return this;
+ }
+
+ @Override
+ public ReadBuilder withPartitionFilter(Map<String, String> partitionSpec) {
+ if (partitionSpec != null) {
+ RowType partitionType = table.rowType().project(table.partitionKeys());
+ PartitionPredicate partitionPredicate =
+ fromPredicate(
+ partitionType,
+ createPartitionPredicate(
+ partitionSpec, partitionType, table.defaultPartName()));
+ withPartitionFilter(partitionPredicate);
+ }
+ return this;
+ }
+
+ @Override
+ public ReadBuilder withPartitionFilter(PartitionPredicate partitionPredicate) {
+ this.partitionFilter = partitionPredicate;
+ return this;
+ }
+
+ @Override
+ public ReadBuilder withReadType(RowType readType) {
+ this.readType = readType;
+ return this;
+ }
+
+ @Override
+ public ReadBuilder withProjection(int[] projection) {
+ if (projection == null) {
+ return this;
+ }
+ return withReadType(readType().project(projection));
+ }
+
+ @Override
+ public TableScan newScan() {
+ return new FormatTableScan(table, partitionFilter);
+ }
+
+ @Override
+ public TableRead newRead() {
+ return new FormatTableRead(readType(), this, filter);
+ }
+
+ protected RecordReader<InternalRow> createReader(FormatDataSplit dataSplit) throws IOException {
+ Path filePath = dataSplit.dataPath();
+ FormatReaderContext formatReaderContext =
+ new FormatReaderContext(table.fileIO(), filePath, dataSplit.length(), null);
+
+ FormatReaderFactory readerFactory =
+ formatDiscover
+ .discover(options.formatType())
+ .createReaderFactory(
+ table.rowType(), readType(), PredicateBuilder.splitAnd(filter));
+
+ Pair<int[], RowType> partitionMapping =
+ PartitionUtils.getPartitionMapping(
+ table.partitionKeys(), readType().getFields(), table.partitionType());
+
+ FileRecordReader<InternalRow> fileRecordReader =
+ new DataFileRecordReader(
+ readType(),
+ readerFactory,
+ formatReaderContext,
+ null,
+ null,
+ PartitionUtils.create(partitionMapping, dataSplit.partition()),
+ false,
+ null,
+ 0,
+ Collections.emptyMap());
+ return fileRecordReader;
+ }
+
+ // ===================== Unsupported ===============================
+ @Override
+ public ReadBuilder withLimit(int limit) {
+ throw new UnsupportedOperationException("limit is not supported for FormatTable.");
Review Comment:
`return this;` is ok.
##########
paimon-core/src/main/java/org/apache/paimon/table/format/FormatReadBuilder.java:
##########
@@ -0,0 +1,203 @@
+/*
+ * 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.paimon.table.format;
+
+import org.apache.paimon.CoreOptions;
+import org.apache.paimon.data.InternalRow;
+import org.apache.paimon.format.FileFormatDiscover;
+import org.apache.paimon.format.FormatReaderContext;
+import org.apache.paimon.format.FormatReaderFactory;
+import org.apache.paimon.fs.Path;
+import org.apache.paimon.io.DataFileRecordReader;
+import org.apache.paimon.partition.PartitionPredicate;
+import org.apache.paimon.partition.PartitionUtils;
+import org.apache.paimon.predicate.Predicate;
+import org.apache.paimon.predicate.PredicateBuilder;
+import org.apache.paimon.predicate.TopN;
+import org.apache.paimon.reader.FileRecordReader;
+import org.apache.paimon.reader.RecordReader;
+import org.apache.paimon.table.FormatTable;
+import org.apache.paimon.table.source.ReadBuilder;
+import org.apache.paimon.table.source.StreamTableScan;
+import org.apache.paimon.table.source.TableRead;
+import org.apache.paimon.table.source.TableScan;
+import org.apache.paimon.types.RowType;
+import org.apache.paimon.utils.Filter;
+import org.apache.paimon.utils.Pair;
+
+import javax.annotation.Nullable;
+
+import java.io.IOException;
+import java.util.Collections;
+import java.util.Map;
+
+import static org.apache.paimon.partition.PartitionPredicate.createPartitionPredicate;
+import static org.apache.paimon.partition.PartitionPredicate.fromPredicate;
+
+/** {@link ReadBuilder} for {@link FormatTable}. */
+public class FormatReadBuilder implements ReadBuilder {
+
+ private static final long serialVersionUID = 1L;
+
+ private CoreOptions options;
+ private FormatTable table;
+ private RowType readType;
+
+ private final FileFormatDiscover formatDiscover;
+
+ @Nullable private Predicate filter;
+ @Nullable private PartitionPredicate partitionFilter;
+
+ public FormatReadBuilder(FormatTable table) {
+ this.table = table;
+ this.readType = this.table.rowType();
+ this.options = new CoreOptions(table.options());
+ this.formatDiscover = FileFormatDiscover.of(this.options);
+ }
+
+ @Override
+ public String tableName() {
+ return this.table.name();
+ }
+
+ @Override
+ public RowType readType() {
+ return this.readType;
+ }
+
+ @Override
+ public ReadBuilder withFilter(Predicate predicate) {
+ if (this.filter == null) {
+ this.filter = predicate;
+ } else {
+ this.filter = PredicateBuilder.and(this.filter, predicate);
+ }
+ return this;
+ }
+
+ @Override
+ public ReadBuilder withPartitionFilter(Map<String, String> partitionSpec) {
+ if (partitionSpec != null) {
+ RowType partitionType = table.rowType().project(table.partitionKeys());
+ PartitionPredicate partitionPredicate =
+ fromPredicate(
+ partitionType,
+ createPartitionPredicate(
+ partitionSpec, partitionType, table.defaultPartName()));
+ withPartitionFilter(partitionPredicate);
+ }
+ return this;
+ }
+
+ @Override
+ public ReadBuilder withPartitionFilter(PartitionPredicate partitionPredicate) {
+ this.partitionFilter = partitionPredicate;
+ return this;
+ }
+
+ @Override
+ public ReadBuilder withReadType(RowType readType) {
+ this.readType = readType;
+ return this;
+ }
+
+ @Override
+ public ReadBuilder withProjection(int[] projection) {
+ if (projection == null) {
+ return this;
+ }
+ return withReadType(readType().project(projection));
+ }
+
+ @Override
+ public TableScan newScan() {
+ return new FormatTableScan(table, partitionFilter);
+ }
+
+ @Override
+ public TableRead newRead() {
+ return new FormatTableRead(readType(), this, filter);
+ }
+
+ protected RecordReader<InternalRow> createReader(FormatDataSplit dataSplit) throws IOException {
+ Path filePath = dataSplit.dataPath();
+ FormatReaderContext formatReaderContext =
+ new FormatReaderContext(table.fileIO(), filePath, dataSplit.length(), null);
+
+ FormatReaderFactory readerFactory =
+ formatDiscover
+ .discover(options.formatType())
+ .createReaderFactory(
+ table.rowType(), readType(), PredicateBuilder.splitAnd(filter));
+
+ Pair<int[], RowType> partitionMapping =
+ PartitionUtils.getPartitionMapping(
+ table.partitionKeys(), readType().getFields(), table.partitionType());
+
+ FileRecordReader<InternalRow> fileRecordReader =
+ new DataFileRecordReader(
+ readType(),
+ readerFactory,
+ formatReaderContext,
+ null,
+ null,
+ PartitionUtils.create(partitionMapping, dataSplit.partition()),
+ false,
+ null,
+ 0,
+ Collections.emptyMap());
+ return fileRecordReader;
+ }
+
+ // ===================== Unsupported ===============================
+ @Override
+ public ReadBuilder withLimit(int limit) {
+ throw new UnsupportedOperationException("limit is not supported for FormatTable.");
+ }
+
+ @Override
+ public ReadBuilder withTopN(TopN topN) {
+ throw new UnsupportedOperationException("TopN is not supported for FormatTable.");
Review Comment:
`return this;` is ok.
##########
paimon-core/src/main/java/org/apache/paimon/table/format/FormatReadBuilder.java:
##########
@@ -0,0 +1,203 @@
+/*
+ * 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.paimon.table.format;
+
+import org.apache.paimon.CoreOptions;
+import org.apache.paimon.data.InternalRow;
+import org.apache.paimon.format.FileFormatDiscover;
+import org.apache.paimon.format.FormatReaderContext;
+import org.apache.paimon.format.FormatReaderFactory;
+import org.apache.paimon.fs.Path;
+import org.apache.paimon.io.DataFileRecordReader;
+import org.apache.paimon.partition.PartitionPredicate;
+import org.apache.paimon.partition.PartitionUtils;
+import org.apache.paimon.predicate.Predicate;
+import org.apache.paimon.predicate.PredicateBuilder;
+import org.apache.paimon.predicate.TopN;
+import org.apache.paimon.reader.FileRecordReader;
+import org.apache.paimon.reader.RecordReader;
+import org.apache.paimon.table.FormatTable;
+import org.apache.paimon.table.source.ReadBuilder;
+import org.apache.paimon.table.source.StreamTableScan;
+import org.apache.paimon.table.source.TableRead;
+import org.apache.paimon.table.source.TableScan;
+import org.apache.paimon.types.RowType;
+import org.apache.paimon.utils.Filter;
+import org.apache.paimon.utils.Pair;
+
+import javax.annotation.Nullable;
+
+import java.io.IOException;
+import java.util.Collections;
+import java.util.Map;
+
+import static org.apache.paimon.partition.PartitionPredicate.createPartitionPredicate;
+import static org.apache.paimon.partition.PartitionPredicate.fromPredicate;
+
+/** {@link ReadBuilder} for {@link FormatTable}. */
+public class FormatReadBuilder implements ReadBuilder {
+
+ private static final long serialVersionUID = 1L;
+
+ private CoreOptions options;
+ private FormatTable table;
+ private RowType readType;
+
+ private final FileFormatDiscover formatDiscover;
+
+ @Nullable private Predicate filter;
+ @Nullable private PartitionPredicate partitionFilter;
+
+ public FormatReadBuilder(FormatTable table) {
+ this.table = table;
+ this.readType = this.table.rowType();
+ this.options = new CoreOptions(table.options());
+ this.formatDiscover = FileFormatDiscover.of(this.options);
+ }
+
+ @Override
+ public String tableName() {
+ return this.table.name();
+ }
+
+ @Override
+ public RowType readType() {
+ return this.readType;
+ }
+
+ @Override
+ public ReadBuilder withFilter(Predicate predicate) {
+ if (this.filter == null) {
+ this.filter = predicate;
+ } else {
+ this.filter = PredicateBuilder.and(this.filter, predicate);
+ }
+ return this;
+ }
+
+ @Override
+ public ReadBuilder withPartitionFilter(Map<String, String> partitionSpec) {
+ if (partitionSpec != null) {
+ RowType partitionType = table.rowType().project(table.partitionKeys());
+ PartitionPredicate partitionPredicate =
+ fromPredicate(
+ partitionType,
+ createPartitionPredicate(
+ partitionSpec, partitionType, table.defaultPartName()));
+ withPartitionFilter(partitionPredicate);
+ }
+ return this;
+ }
+
+ @Override
+ public ReadBuilder withPartitionFilter(PartitionPredicate partitionPredicate) {
+ this.partitionFilter = partitionPredicate;
+ return this;
+ }
+
+ @Override
+ public ReadBuilder withReadType(RowType readType) {
+ this.readType = readType;
+ return this;
+ }
+
+ @Override
+ public ReadBuilder withProjection(int[] projection) {
+ if (projection == null) {
+ return this;
+ }
+ return withReadType(readType().project(projection));
+ }
+
+ @Override
+ public TableScan newScan() {
+ return new FormatTableScan(table, partitionFilter);
+ }
+
+ @Override
+ public TableRead newRead() {
+ return new FormatTableRead(readType(), this, filter);
+ }
+
+ protected RecordReader<InternalRow> createReader(FormatDataSplit dataSplit) throws IOException {
+ Path filePath = dataSplit.dataPath();
+ FormatReaderContext formatReaderContext =
+ new FormatReaderContext(table.fileIO(), filePath, dataSplit.length(), null);
+
+ FormatReaderFactory readerFactory =
+ formatDiscover
+ .discover(options.formatType())
+ .createReaderFactory(
+ table.rowType(), readType(), PredicateBuilder.splitAnd(filter));
+
+ Pair<int[], RowType> partitionMapping =
+ PartitionUtils.getPartitionMapping(
+ table.partitionKeys(), readType().getFields(), table.partitionType());
+
+ FileRecordReader<InternalRow> fileRecordReader =
+ new DataFileRecordReader(
+ readType(),
+ readerFactory,
+ formatReaderContext,
+ null,
+ null,
+ PartitionUtils.create(partitionMapping, dataSplit.partition()),
+ false,
+ null,
+ 0,
+ Collections.emptyMap());
+ return fileRecordReader;
+ }
+
+ // ===================== Unsupported ===============================
+ @Override
+ public ReadBuilder withLimit(int limit) {
+ throw new UnsupportedOperationException("limit is not supported for FormatTable.");
+ }
+
+ @Override
+ public ReadBuilder withTopN(TopN topN) {
+ throw new UnsupportedOperationException("TopN is not supported for FormatTable.");
+ }
+
+ @Override
+ public ReadBuilder dropStats() {
+ throw new UnsupportedOperationException("Format Table does not support dropStats.");
Review Comment:
`return this;` is ok.
--
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@paimon.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org